xref: /AOO41X/main/xmloff/source/text/XMLIndexUserSourceContext.cxx (revision 63bba73cc51e0afb45f8a8d578158724bb5afee8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 
28 #include "XMLIndexUserSourceContext.hxx"
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/container/XIndexReplace.hpp>
31 #include "XMLIndexTemplateContext.hxx"
32 #include "XMLIndexTitleTemplateContext.hxx"
33 #include "XMLIndexTOCStylesContext.hxx"
34 #include <xmloff/xmlictxt.hxx>
35 #include <xmloff/xmlimp.hxx>
36 #include <xmloff/txtimp.hxx>
37 #include "xmloff/xmlnmspe.hxx"
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/xmluconv.hxx>
41 #include <tools/debug.hxx>
42 #include <rtl/ustring.hxx>
43 
44 
45 using ::rtl::OUString;
46 using ::com::sun::star::beans::XPropertySet;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::uno::Any;
49 using ::com::sun::star::xml::sax::XAttributeList;
50 using ::xmloff::token::IsXMLToken;
51 using ::xmloff::token::XML_USER_INDEX_ENTRY_TEMPLATE;
52 using ::xmloff::token::XML_OUTLINE_LEVEL;
53 
54 
55 const sal_Char sAPI_CreateFromEmbeddedObjects[] = "CreateFromEmbeddedObjects";
56 const sal_Char sAPI_CreateFromGraphicObjects[] = "CreateFromGraphicObjects";
57 const sal_Char sAPI_CreateFromMarks[] = "CreateFromMarks";
58 const sal_Char sAPI_CreateFromTables[] = "CreateFromTables";
59 const sal_Char sAPI_CreateFromTextFrames[] = "CreateFromTextFrames";
60 const sal_Char sAPI_UseLevelFromSource[] = "UseLevelFromSource";
61 const sal_Char sAPI_CreateFromLevelParagraphStyles[] = "CreateFromLevelParagraphStyles";
62 const sal_Char sAPI_UserIndexName[] = "UserIndexName";
63 
64 
65 TYPEINIT1(XMLIndexUserSourceContext, XMLIndexSourceBaseContext);
66 
67 
XMLIndexUserSourceContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,Reference<XPropertySet> & rPropSet)68 XMLIndexUserSourceContext::XMLIndexUserSourceContext(
69     SvXMLImport& rImport,
70     sal_uInt16 nPrfx,
71     const OUString& rLocalName,
72     Reference<XPropertySet> & rPropSet) :
73         XMLIndexSourceBaseContext(rImport, nPrfx, rLocalName,
74                                   rPropSet, sal_True),
75         sCreateFromEmbeddedObjects(RTL_CONSTASCII_USTRINGPARAM(
76             sAPI_CreateFromEmbeddedObjects)),
77         sCreateFromGraphicObjects(RTL_CONSTASCII_USTRINGPARAM(
78             sAPI_CreateFromGraphicObjects)),
79         sCreateFromMarks(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromMarks)),
80         sCreateFromTables(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromTables)),
81         sCreateFromTextFrames(RTL_CONSTASCII_USTRINGPARAM(
82             sAPI_CreateFromTextFrames)),
83         sUseLevelFromSource(RTL_CONSTASCII_USTRINGPARAM(
84             sAPI_UseLevelFromSource)),
85         sCreateFromLevelParagraphStyles(RTL_CONSTASCII_USTRINGPARAM(
86             sAPI_CreateFromLevelParagraphStyles)),
87         sUserIndexName(RTL_CONSTASCII_USTRINGPARAM(sAPI_UserIndexName)),
88         bUseObjects(sal_False),
89         bUseGraphic(sal_False),
90         bUseMarks(sal_False),
91         bUseTables(sal_False),
92         bUseFrames(sal_False),
93         bUseLevelFromSource(sal_False),
94         bUseLevelParagraphStyles(sal_False)
95 {
96 }
97 
~XMLIndexUserSourceContext()98 XMLIndexUserSourceContext::~XMLIndexUserSourceContext()
99 {
100 }
101 
ProcessAttribute(enum IndexSourceParamEnum eParam,const OUString & rValue)102 void XMLIndexUserSourceContext::ProcessAttribute(
103     enum IndexSourceParamEnum eParam,
104     const OUString& rValue)
105 {
106     sal_Bool bTmp;
107 
108     switch (eParam)
109     {
110         case XML_TOK_INDEXSOURCE_USE_INDEX_MARKS:
111             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
112             {
113                 bUseMarks = bTmp;
114             }
115             break;
116 
117         case XML_TOK_INDEXSOURCE_USE_OBJECTS:
118             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
119             {
120                 bUseObjects = bTmp;
121             }
122             break;
123 
124         case XML_TOK_INDEXSOURCE_USE_GRAPHICS:
125             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
126             {
127                 bUseGraphic = bTmp;
128             }
129             break;
130 
131         case XML_TOK_INDEXSOURCE_USE_TABLES:
132             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
133             {
134                 bUseTables = bTmp;
135             }
136             break;
137 
138         case XML_TOK_INDEXSOURCE_USE_FRAMES:
139             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
140             {
141                 bUseFrames = bTmp;
142             }
143             break;
144 
145         case XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS:
146             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
147             {
148                 bUseLevelFromSource = bTmp;
149             }
150             break;
151 
152         case XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES:
153             if (SvXMLUnitConverter::convertBool(bTmp, rValue))
154             {
155                 bUseLevelParagraphStyles = bTmp;
156             }
157             break;
158 
159         case XML_TOK_INDEXSOURCE_USER_INDEX_NAME:
160             sIndexName = rValue;
161             break;
162 
163         default:
164             XMLIndexSourceBaseContext::ProcessAttribute(eParam, rValue);
165             break;
166     }
167 }
168 
169 
EndElement()170 void XMLIndexUserSourceContext::EndElement()
171 {
172     Any aAny;
173 
174     aAny.setValue(&bUseObjects, ::getBooleanCppuType());
175     rIndexPropertySet->setPropertyValue(sCreateFromEmbeddedObjects, aAny);
176 
177     aAny.setValue(&bUseGraphic, ::getBooleanCppuType());
178     rIndexPropertySet->setPropertyValue(sCreateFromGraphicObjects, aAny);
179 
180     aAny.setValue(&bUseLevelFromSource, ::getBooleanCppuType());
181     rIndexPropertySet->setPropertyValue(sUseLevelFromSource, aAny);
182 
183     aAny.setValue(&bUseMarks, ::getBooleanCppuType());
184     rIndexPropertySet->setPropertyValue(sCreateFromMarks, aAny);
185 
186     aAny.setValue(&bUseTables, ::getBooleanCppuType());
187     rIndexPropertySet->setPropertyValue(sCreateFromTables, aAny);
188 
189     aAny.setValue(&bUseFrames, ::getBooleanCppuType());
190     rIndexPropertySet->setPropertyValue(sCreateFromTextFrames, aAny);
191 
192     aAny.setValue(&bUseLevelParagraphStyles, ::getBooleanCppuType());
193     rIndexPropertySet->setPropertyValue(sCreateFromLevelParagraphStyles, aAny);
194 
195     if( sIndexName.getLength() > 0 )
196     {
197         aAny <<= sIndexName;
198         rIndexPropertySet->setPropertyValue(sUserIndexName, aAny);
199     }
200 
201     XMLIndexSourceBaseContext::EndElement();
202 }
203 
204 
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)205 SvXMLImportContext* XMLIndexUserSourceContext::CreateChildContext(
206     sal_uInt16 nPrefix,
207     const OUString& rLocalName,
208     const Reference<XAttributeList> & xAttrList )
209 {
210     if ( (XML_NAMESPACE_TEXT == nPrefix) &&
211          (IsXMLToken(rLocalName, XML_USER_INDEX_ENTRY_TEMPLATE)) )
212     {
213         return new XMLIndexTemplateContext(GetImport(), rIndexPropertySet,
214                                            nPrefix, rLocalName,
215                                            aLevelNameTOCMap,
216                                            XML_OUTLINE_LEVEL,
217                                            aLevelStylePropNameTOCMap,
218                                            aAllowedTokenTypesUser);
219     }
220     else
221     {
222         return XMLIndexSourceBaseContext::CreateChildContext(nPrefix,
223                                                              rLocalName,
224                                                              xAttrList);
225     }
226 
227 }
228