xref: /trunk/main/xmloff/source/text/XMLIndexUserSourceContext.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 
32 #include "XMLIndexUserSourceContext.hxx"
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/container/XIndexReplace.hpp>
35 #include "XMLIndexTemplateContext.hxx"
36 #include "XMLIndexTitleTemplateContext.hxx"
37 #include "XMLIndexTOCStylesContext.hxx"
38 #include <xmloff/xmlictxt.hxx>
39 #include <xmloff/xmlimp.hxx>
40 #include <xmloff/txtimp.hxx>
41 #include "xmloff/xmlnmspe.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmltoken.hxx>
44 #include <xmloff/xmluconv.hxx>
45 #include <tools/debug.hxx>
46 #include <rtl/ustring.hxx>
47 
48 
49 using ::rtl::OUString;
50 using ::com::sun::star::beans::XPropertySet;
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::uno::Any;
53 using ::com::sun::star::xml::sax::XAttributeList;
54 using ::xmloff::token::IsXMLToken;
55 using ::xmloff::token::XML_USER_INDEX_ENTRY_TEMPLATE;
56 using ::xmloff::token::XML_OUTLINE_LEVEL;
57 
58 
59 const sal_Char sAPI_CreateFromEmbeddedObjects[] = "CreateFromEmbeddedObjects";
60 const sal_Char sAPI_CreateFromGraphicObjects[] = "CreateFromGraphicObjects";
61 const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
62 const sal_Char sAPI_CreateFromTables[] = "CreateFromTables";
63 const sal_Char sAPI_CreateFromTextFrames[] = "CreateFromTextFrames";
64 const sal_Char sAPI_UseLevelFromSource[] = "UseLevelFromSource";
65 const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
66 const sal_Char sAPI_UserIndexName[] = "UserIndexName";
67 
68 
69 TYPEINIT1(XMLIndexUserSourceContext, XMLIndexSourceBaseContext);
70 
71 
72 XMLIndexUserSourceContext::XMLIndexUserSourceContext(
73     SvXMLImport& rImport,
74     sal_uInt16 nPrfx,
75     const OUString& rLocalName,
76     Reference<XPropertySet> & rPropSet) :
77         XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
78                                   rPropSet, sal_True),
79         sCreateFromEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM(
80             sAPI_CreateFromEmbeddedObjects)),
81         sCreateFromGraphicObjects(RTL_CONSTASCII_USTRINGPARAM(
82             sAPI_CreateFromGraphicObjects)),
83         sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks)),
84         sCreateFromTables(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromTables)),
85         sCreateFromTextFrames(RTL_CONSTASCII_USTRINGPARAM(
86             sAPI_CreateFromTextFrames)),
87         sUseLevelFromSource(RTL_CONSTASCII_USTRINGPARAM(
88             sAPI_UseLevelFromSource)),
89         sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(
90             sAPI_CreateFromLevelParagraphStyles)),
91         sUserIndexName(RTL_CONSTASCII_USTRINGPARAM(sAPI_UserIndexName)),
92         bUseObjects(sal_False),
93         bUseGraphic(sal_False),
94         bUseMarks(sal_False),
95         bUseTables(sal_False),
96         bUseFrames(sal_False),
97         bUseLevelFromSource(sal_False),
98         bUseLevelParagraphStyles(sal_False)
99 {
100 }
101 
102 XMLIndexUserSourceContext::~XMLIndexUserSourceContext()
103 {
104 }
105 
106 void XMLIndexUserSourceContext::ProcessAttribute(
107     enum IndexSourceParamEnum eParam,
108     const OUString& rValue)
109 {
110     sal_Bool bTmp;
111 
112     switch (eParam)
113     {
114         case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
115             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
116             {
117                 bUseMarks = bTmp;
118             }
119             break;
120 
121         case XML_TOK_INDEXSOURCE_USE_OBJECTS:
122             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
123             {
124                 bUseObjects = bTmp;
125             }
126             break;
127 
128         case XML_TOK_INDEXSOURCE_USE_GRAPHICS:
129             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
130             {
131                 bUseGraphic = bTmp;
132             }
133             break;
134 
135         case XML_TOK_INDEXSOURCE_USE_TABLES:
136             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
137             {
138                 bUseTables = bTmp;
139             }
140             break;
141 
142         case XML_TOK_INDEXSOURCE_USE_FRAMES:
143             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
144             {
145                 bUseFrames = bTmp;
146             }
147             break;
148 
149         case XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS:
150             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
151             {
152                 bUseLevelFromSource = bTmp;
153             }
154             break;
155 
156         case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
157             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
158             {
159                 bUseLevelParagraphStyles = bTmp;
160             }
161             break;
162 
163         case XML_TOK_INDEXSOURCE_USER_INDEX_NAME:
164             sIndexName = rValue;
165             break;
166 
167         default:
168             XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
169             break;
170     }
171 }
172 
173 
174 void XMLIndexUserSourceContext::EndElement()
175 {
176     Any aAny;
177 
178     aAny.setValue(&bUseObjects, ::getBooleanCppuType());
179     rIndexPropertySet->setPropertyValue(sCreateFromEmbeddedObjects, aAny);
180 
181     aAny.setValue(&bUseGraphic, ::getBooleanCppuType());
182     rIndexPropertySet->setPropertyValue(sCreateFromGraphicObjects, aAny);
183 
184     aAny.setValue(&bUseLevelFromSource, ::getBooleanCppuType());
185     rIndexPropertySet->setPropertyValue(sUseLevelFromSource, aAny);
186 
187     aAny.setValue(&bUseMarks, ::getBooleanCppuType());
188     rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
189 
190     aAny.setValue(&bUseTables, ::getBooleanCppuType());
191     rIndexPropertySet->setPropertyValue(sCreateFromTables, aAny);
192 
193     aAny.setValue(&bUseFrames, ::getBooleanCppuType());
194     rIndexPropertySet->setPropertyValue(sCreateFromTextFrames, aAny);
195 
196     aAny.setValue(&bUseLevelParagraphStyles, ::getBooleanCppuType());
197     rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
198 
199     if( sIndexName.getLength() > 0 )
200     {
201         aAny <<= sIndexName;
202         rIndexPropertySet->setPropertyValue(sUserIndexName, aAny);
203     }
204 
205     XMLIndexSourceBaseContext::EndElement();
206 }
207 
208 
209 SvXMLImportContext* XMLIndexUserSourceContext::CreateChildContext(
210     sal_uInt16 nPrefix,
211     const OUString& rLocalName,
212     const Reference<XAttributeList> & xAttrList )
213 {
214     if ( (XML_NAMESPACE_TEXT == nPrefix) &&
215          (IsXMLToken(rLocalName, XML_USER_INDEX_ENTRY_TEMPLATE)) )
216     {
217         return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
218                                            nPrefix, rLocalName,
219                                            aLevelNameTOCMap,
220                                            XML_OUTLINE_LEVEL,
221                                            aLevelStylePropNameTOCMap,
222                                            aAllowedTokenTypesUser);
223     }
224     else
225     {
226         return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
227                                                              rLocalName,
228                                                              xAttrList);
229     }
230 
231 }
232