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 "XMLIndexSourceBaseContext.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
46 using namespace ::xmloff::token;
47
48 using ::rtl::OUString;
49 using ::com::sun::star::beans::XPropertySet;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::uno::Any;
52 using ::com::sun::star::xml::sax::XAttributeList;
53
54 const sal_Char sAPI_CreateFromChapter[] = "CreateFromChapter";
55 const sal_Char sAPI_IsRelativeTabstops[] = "IsRelativeTabstops";
56
57 static __FAR_DATA SvXMLTokenMapEntry aIndexSourceTokenMap[] =
58 {
59 { XML_NAMESPACE_TEXT,
60 XML_OUTLINE_LEVEL,
61 XML_TOK_INDEXSOURCE_OUTLINE_LEVEL},
62 { XML_NAMESPACE_TEXT,
63 XML_USE_INDEX_MARKS,
64 XML_TOK_INDEXSOURCE_USE_INDEX_MARKS },
65 { XML_NAMESPACE_TEXT,
66 XML_INDEX_SCOPE,
67 XML_TOK_INDEXSOURCE_INDEX_SCOPE },
68 { XML_NAMESPACE_TEXT,
69 XML_RELATIVE_TAB_STOP_POSITION,
70 XML_TOK_INDEXSOURCE_RELATIVE_TABS } ,
71 { XML_NAMESPACE_TEXT,
72 XML_USE_OTHER_OBJECTS,
73 XML_TOK_INDEXSOURCE_USE_OTHER_OBJECTS },
74 { XML_NAMESPACE_TEXT,
75 XML_USE_SPREADSHEET_OBJECTS,
76 XML_TOK_INDEXSOURCE_USE_SHEET },
77 { XML_NAMESPACE_TEXT,
78 XML_USE_CHART_OBJECTS,
79 XML_TOK_INDEXSOURCE_USE_CHART },
80 { XML_NAMESPACE_TEXT,
81 XML_USE_DRAW_OBJECTS,
82 XML_TOK_INDEXSOURCE_USE_DRAW },
83 { XML_NAMESPACE_TEXT,
84 XML_USE_IMAGE_OBJECTS,
85 XML_TOK_INDEXSOURCE_USE_IMAGE },
86 { XML_NAMESPACE_TEXT,
87 XML_USE_MATH_OBJECTS,
88 XML_TOK_INDEXSOURCE_USE_MATH },
89 { XML_NAMESPACE_TEXT,
90 XML_MAIN_ENTRY_STYLE_NAME,
91 XML_TOK_INDEXSOURCE_MAIN_ENTRY_STYLE },
92 { XML_NAMESPACE_TEXT,
93 XML_IGNORE_CASE,
94 XML_TOK_INDEXSOURCE_IGNORE_CASE },
95 { XML_NAMESPACE_TEXT,
96 XML_ALPHABETICAL_SEPARATORS,
97 XML_TOK_INDEXSOURCE_SEPARATORS },
98 { XML_NAMESPACE_TEXT,
99 XML_COMBINE_ENTRIES,
100 XML_TOK_INDEXSOURCE_COMBINE_ENTRIES },
101 { XML_NAMESPACE_TEXT,
102 XML_COMBINE_ENTRIES_WITH_DASH,
103 XML_TOK_INDEXSOURCE_COMBINE_WITH_DASH },
104 { XML_NAMESPACE_TEXT,
105 XML_USE_KEYS_AS_ENTRIES,
106 XML_TOK_INDEXSOURCE_KEYS_AS_ENTRIES },
107 { XML_NAMESPACE_TEXT,
108 XML_COMBINE_ENTRIES_WITH_PP,
109 XML_TOK_INDEXSOURCE_COMBINE_WITH_PP },
110 { XML_NAMESPACE_TEXT,
111 XML_CAPITALIZE_ENTRIES,
112 XML_TOK_INDEXSOURCE_CAPITALIZE },
113 { XML_NAMESPACE_TEXT,
114 XML_USE_OBJECTS,
115 XML_TOK_INDEXSOURCE_USE_OBJECTS },
116 { XML_NAMESPACE_TEXT,
117 XML_USE_GRAPHICS,
118 XML_TOK_INDEXSOURCE_USE_GRAPHICS },
119 { XML_NAMESPACE_TEXT,
120 XML_USE_TABLES,
121 XML_TOK_INDEXSOURCE_USE_TABLES },
122 { XML_NAMESPACE_TEXT,
123 XML_USE_FLOATING_FRAMES,
124 XML_TOK_INDEXSOURCE_USE_FRAMES },
125 { XML_NAMESPACE_TEXT,
126 XML_COPY_OUTLINE_LEVELS,
127 XML_TOK_INDEXSOURCE_COPY_OUTLINE_LEVELS },
128 { XML_NAMESPACE_TEXT,
129 XML_USE_CAPTION,
130 XML_TOK_INDEXSOURCE_USE_CAPTION },
131 { XML_NAMESPACE_TEXT,
132 XML_CAPTION_SEQUENCE_NAME,
133 XML_TOK_INDEXSOURCE_SEQUENCE_NAME },
134 { XML_NAMESPACE_TEXT,
135 XML_CAPTION_SEQUENCE_FORMAT,
136 XML_TOK_INDEXSOURCE_SEQUENCE_FORMAT },
137 { XML_NAMESPACE_TEXT,
138 XML_COMMA_SEPARATED,
139 XML_TOK_INDEXSOURCE_COMMA_SEPARATED },
140 { XML_NAMESPACE_TEXT,
141 XML_USE_INDEX_SOURCE_STYLES,
142 XML_TOK_INDEXSOURCE_USE_INDEX_SOURCE_STYLES },
143 { XML_NAMESPACE_TEXT, XML_SORT_ALGORITHM,
144 XML_TOK_INDEXSOURCE_SORT_ALGORITHM },
145 { XML_NAMESPACE_FO, XML_LANGUAGE, XML_TOK_INDEXSOURCE_LANGUAGE },
146 { XML_NAMESPACE_FO, XML_COUNTRY, XML_TOK_INDEXSOURCE_COUNTRY },
147 { XML_NAMESPACE_TEXT, XML_INDEX_NAME, XML_TOK_INDEXSOURCE_USER_INDEX_NAME },
148 { XML_NAMESPACE_TEXT,
149 XML_USE_OUTLINE_LEVEL,
150 XML_TOK_INDEXSOURCE_USE_OUTLINE_LEVEL},
151
152 XML_TOKEN_MAP_END
153 };
154
155
156 TYPEINIT1( XMLIndexSourceBaseContext, SvXMLImportContext );
157
XMLIndexSourceBaseContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLocalName,Reference<XPropertySet> & rPropSet,sal_Bool bLevelFormats)158 XMLIndexSourceBaseContext::XMLIndexSourceBaseContext(
159 SvXMLImport& rImport,
160 sal_uInt16 nPrfx,
161 const OUString& rLocalName,
162 Reference<XPropertySet> & rPropSet,
163 sal_Bool bLevelFormats)
164 : SvXMLImportContext(rImport, nPrfx, rLocalName)
165 , sCreateFromChapter(RTL_CONSTASCII_USTRINGPARAM(sAPI_CreateFromChapter))
166 , sIsRelativeTabstops(RTL_CONSTASCII_USTRINGPARAM(sAPI_IsRelativeTabstops))
167 , bUseLevelFormats(bLevelFormats)
168 , bChapterIndex(sal_False)
169 , bRelativeTabs(sal_True)
170 , rIndexPropertySet(rPropSet)
171 {
172 }
173
~XMLIndexSourceBaseContext()174 XMLIndexSourceBaseContext::~XMLIndexSourceBaseContext()
175 {
176 }
177
StartElement(const Reference<XAttributeList> & xAttrList)178 void XMLIndexSourceBaseContext::StartElement(
179 const Reference<XAttributeList> & xAttrList)
180 {
181 SvXMLTokenMap aTokenMap(aIndexSourceTokenMap);
182
183 // process attributes
184 sal_Int16 nLength = xAttrList->getLength();
185 for(sal_Int16 i=0; i<nLength; i++)
186 {
187 // map to IndexSourceParamEnum
188 OUString sLocalName;
189 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
190 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
191 sal_uInt16 nToken = aTokenMap.Get(nPrefix, sLocalName);
192
193 // process attribute
194 ProcessAttribute((enum IndexSourceParamEnum)nToken,
195 xAttrList->getValueByIndex(i));
196 }
197 }
198
ProcessAttribute(enum IndexSourceParamEnum eParam,const OUString & rValue)199 void XMLIndexSourceBaseContext::ProcessAttribute(
200 enum IndexSourceParamEnum eParam,
201 const OUString& rValue)
202 {
203 switch (eParam)
204 {
205 case XML_TOK_INDEXSOURCE_INDEX_SCOPE:
206 if ( IsXMLToken( rValue, XML_CHAPTER ) )
207 {
208 bChapterIndex = sal_True;
209 }
210 break;
211
212 case XML_TOK_INDEXSOURCE_RELATIVE_TABS:
213 {
214 sal_Bool bTmp;
215 if (SvXMLUnitConverter::convertBool(bTmp, rValue))
216 {
217 bRelativeTabs = bTmp;
218 }
219 break;
220 }
221
222 default:
223 // unknown attribute -> ignore
224 break;
225 }
226 }
227
EndElement()228 void XMLIndexSourceBaseContext::EndElement()
229 {
230 Any aAny;
231
232 aAny.setValue(&bRelativeTabs, ::getBooleanCppuType());
233 rIndexPropertySet->setPropertyValue(sIsRelativeTabstops, aAny);
234
235 aAny.setValue(&bChapterIndex, ::getBooleanCppuType());
236 rIndexPropertySet->setPropertyValue(sCreateFromChapter, aAny);
237 }
238
CreateChildContext(sal_uInt16 nPrefix,const OUString & rLocalName,const Reference<XAttributeList> & xAttrList)239 SvXMLImportContext* XMLIndexSourceBaseContext::CreateChildContext(
240 sal_uInt16 nPrefix,
241 const OUString& rLocalName,
242 const Reference<XAttributeList> & xAttrList )
243 {
244 SvXMLImportContext* pContext = NULL;
245
246 if (XML_NAMESPACE_TEXT == nPrefix)
247 {
248 if ( IsXMLToken( rLocalName, XML_INDEX_TITLE_TEMPLATE ) )
249 {
250 pContext = new XMLIndexTitleTemplateContext(GetImport(),
251 rIndexPropertySet,
252 nPrefix, rLocalName);
253 }
254 else if ( bUseLevelFormats &&
255 IsXMLToken( rLocalName, XML_INDEX_SOURCE_STYLES ) )
256 {
257 pContext = new XMLIndexTOCStylesContext(GetImport(),
258 rIndexPropertySet,
259 nPrefix, rLocalName);
260 }
261 // else: unknown element in text namespace -> ignore
262 }
263 // else: unknown namespace -> ignore
264
265 // use default context
266 if (pContext == NULL)
267 {
268 pContext = SvXMLImportContext::CreateChildContext(nPrefix, rLocalName,
269 xAttrList);
270 }
271
272 return pContext;
273 }
274