/src/libreoffice/xmloff/source/text/txtfldi.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | |
21 | | /** @#file |
22 | | * |
23 | | * Import of all text fields except those from txtvfldi.cxx |
24 | | * (variable related text fields and database display fields) |
25 | | */ |
26 | | |
27 | | #include <sal/config.h> |
28 | | |
29 | | #include <cassert> |
30 | | |
31 | | #include <txtfld.hxx> |
32 | | #include <txtfldi.hxx> |
33 | | #include <txtvfldi.hxx> |
34 | | #include <utility> |
35 | | #include <xmloff/xmlimp.hxx> |
36 | | #include <xmloff/txtimp.hxx> |
37 | | #include <xmloff/xmlnamespace.hxx> |
38 | | #include <xmloff/namespacemap.hxx> |
39 | | #include <xmloff/xmltoken.hxx> |
40 | | #include <xmloff/xmluconv.hxx> |
41 | | #include <xmloff/xmlement.hxx> |
42 | | #include <XMLStringBufferImportContext.hxx> |
43 | | #include <xmloff/XMLEventsImportContext.hxx> |
44 | | #include <com/sun/star/frame/XModel.hpp> |
45 | | #include <com/sun/star/text/UserDataPart.hpp> |
46 | | #include <com/sun/star/style/NumberingType.hpp> |
47 | | #include <com/sun/star/text/PlaceholderType.hpp> |
48 | | #include <com/sun/star/text/ReferenceFieldPart.hpp> |
49 | | #include <com/sun/star/text/ReferenceFieldSource.hpp> |
50 | | #include <com/sun/star/text/XTextContent.hpp> |
51 | | #include <com/sun/star/beans/XPropertySet.hpp> |
52 | | #include <com/sun/star/beans/XPropertySetInfo.hpp> |
53 | | #include <com/sun/star/lang/XMultiServiceFactory.hpp> |
54 | | #include <com/sun/star/text/XTextFieldsSupplier.hpp> |
55 | | #include <com/sun/star/text/XDependentTextField.hpp> |
56 | | #include <com/sun/star/text/FilenameDisplayFormat.hpp> |
57 | | #include <com/sun/star/text/ChapterFormat.hpp> |
58 | | #include <com/sun/star/text/TemplateDisplayFormat.hpp> |
59 | | #include <com/sun/star/beans/PropertyValue.hpp> |
60 | | #include <com/sun/star/text/BibliographyDataType.hpp> |
61 | | #include <com/sun/star/util/XUpdatable.hpp> |
62 | | #include <com/sun/star/sdb/CommandType.hpp> |
63 | | #include <com/sun/star/container/XIndexReplace.hpp> |
64 | | #include <com/sun/star/container/XUniqueIDAccess.hpp> |
65 | | |
66 | | #include <sax/tools/converter.hxx> |
67 | | |
68 | | #include <rtl/ustring.hxx> |
69 | | #include <rtl/ustrbuf.hxx> |
70 | | #include <sal/log.hxx> |
71 | | #include <rtl/math.hxx> |
72 | | #include <tools/debug.hxx> |
73 | | #include <osl/diagnose.h> |
74 | | #include <comphelper/diagnose_ex.hxx> |
75 | | |
76 | | using namespace ::com::sun::star; |
77 | | using namespace ::com::sun::star::uno; |
78 | | using namespace ::com::sun::star::text; |
79 | | using namespace ::com::sun::star::lang; |
80 | | using namespace ::com::sun::star::beans; |
81 | | using namespace ::com::sun::star::document; |
82 | | using namespace ::com::sun::star::util; |
83 | | using namespace ::com::sun::star::xml::sax; |
84 | | using namespace ::xmloff::token; |
85 | | |
86 | | |
87 | | // SO API string constants |
88 | | |
89 | | |
90 | | // service prefix and service names |
91 | | constexpr OUString sAPI_textfield_prefix = u"com.sun.star.text.TextField."_ustr; |
92 | | constexpr char16_t sAPI_fieldmaster_prefix[] = u"com.sun.star.text.FieldMaster."; |
93 | | constexpr OUString sAPI_presentation_prefix = u"com.sun.star.presentation.TextField."_ustr; |
94 | | |
95 | | constexpr OUString sAPI_date_time = u"DateTime"_ustr; |
96 | | constexpr OUString sAPI_page_number = u"PageNumber"_ustr; |
97 | | constexpr OUString sAPI_docinfo_change_date_time = u"DocInfo.ChangeDateTime"_ustr; |
98 | | constexpr OUString sAPI_docinfo_create_date_time = u"DocInfo.CreateDateTime"_ustr; |
99 | | constexpr OUString sAPI_docinfo_custom = u"DocInfo.Custom"_ustr; |
100 | | constexpr OUString sAPI_docinfo_print_date_time = u"DocInfo.PrintDateTime"_ustr; |
101 | | constexpr OUString sAPI_dde = u"DDE"_ustr; |
102 | | constexpr OUString sAPI_url = u"URL"_ustr; |
103 | | |
104 | | // property names |
105 | | constexpr OUString sAPI_is_fixed = u"IsFixed"_ustr; |
106 | | constexpr OUString sAPI_content = u"Content"_ustr; |
107 | | constexpr OUString sAPI_author = u"Author"_ustr; |
108 | | constexpr OUString sAPI_hint = u"Hint"_ustr; |
109 | | constexpr OUString sAPI_name = u"Name"_ustr; |
110 | | constexpr OUStringLiteral sAPI_parent_name = u"ParentName"; |
111 | | constexpr OUString sAPI_sub_type = u"SubType"_ustr; |
112 | | constexpr OUString sAPI_date_time_value = u"DateTimeValue"_ustr; |
113 | | constexpr OUString sAPI_number_format = u"NumberFormat"_ustr; |
114 | | constexpr OUString sAPI_numbering_type = u"NumberingType"_ustr; |
115 | | constexpr OUString sAPI_offset = u"Offset"_ustr; |
116 | | constexpr OUString sAPI_condition = u"Condition"_ustr; |
117 | | constexpr OUString sAPI_set_number = u"SetNumber"_ustr; |
118 | | constexpr OUString sAPI_file_format = u"FileFormat"_ustr; |
119 | | constexpr OUString sAPI_is_date = u"IsDate"_ustr; |
120 | | constexpr OUString sAPI_current_presentation = u"CurrentPresentation"_ustr; |
121 | | constexpr OUString sAPI_is_hidden = u"IsHidden"_ustr; |
122 | | constexpr OUString sAPI_is_fixed_language = u"IsFixedLanguage"_ustr; |
123 | | |
124 | | constexpr OUString sAPI_true = u"TRUE"_ustr; |
125 | | |
126 | | |
127 | | XMLTextFieldImportContext::XMLTextFieldImportContext( |
128 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, |
129 | | OUString aService) |
130 | 75.3k | : SvXMLImportContext( rImport ) |
131 | 75.3k | , sServiceName(std::move(aService)) |
132 | 75.3k | , rTextImportHelper(rHlp) |
133 | 75.3k | , sServicePrefix(sAPI_textfield_prefix) |
134 | 75.3k | , bValid(false) |
135 | 75.3k | { |
136 | 75.3k | } |
137 | | |
138 | | void XMLTextFieldImportContext::startFastElement( |
139 | | sal_Int32 /*nElement*/, |
140 | | const Reference<XFastAttributeList> & xAttrList) |
141 | 75.0k | { |
142 | | // process attributes |
143 | 75.0k | for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) ) |
144 | 15.1k | ProcessAttribute(aIter.getToken(), aIter.toView() ); |
145 | 75.0k | } |
146 | | |
147 | | OUString const & XMLTextFieldImportContext::GetContent() |
148 | 3.79k | { |
149 | 3.79k | if (sContent.isEmpty()) |
150 | 3.04k | { |
151 | 3.04k | sContent = sContentBuffer.makeStringAndClear(); |
152 | 3.04k | } |
153 | | |
154 | 3.79k | return sContent; |
155 | 3.79k | } |
156 | | |
157 | | void XMLTextFieldImportContext::endFastElement(sal_Int32 ) |
158 | 74.0k | { |
159 | 74.0k | if (bValid) |
160 | 72.9k | { |
161 | | |
162 | | // create field/Service |
163 | 72.9k | Reference<XPropertySet> xPropSet; |
164 | 72.9k | if (CreateField(xPropSet, sServicePrefix + GetServiceName())) |
165 | 72.1k | { |
166 | | // set field properties |
167 | 72.1k | PrepareField(xPropSet); |
168 | | |
169 | | // attach field to document |
170 | 72.1k | Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY); |
171 | | |
172 | | // workaround for #80606# |
173 | 72.1k | try |
174 | 72.1k | { |
175 | 72.1k | rTextImportHelper.InsertTextContent(xTextContent); |
176 | 72.1k | } |
177 | 72.1k | catch (const lang::IllegalArgumentException&) |
178 | 72.1k | { |
179 | | // ignore |
180 | 214 | } |
181 | 72.1k | return; |
182 | 72.1k | } |
183 | 72.9k | } |
184 | | |
185 | | // in case of error: write element content |
186 | 1.84k | rTextImportHelper.InsertString(GetContent()); |
187 | 1.84k | } |
188 | | |
189 | | void XMLTextFieldImportContext::characters(const OUString& rContent) |
190 | 48.5k | { |
191 | 48.5k | sContentBuffer.append(rContent); |
192 | 48.5k | } |
193 | | |
194 | | bool XMLTextFieldImportContext::CreateField( |
195 | | Reference<XPropertySet> & xField, |
196 | | const OUString& rServiceName) |
197 | 74.3k | { |
198 | | // instantiate new XTextField: |
199 | | // ask import for model, model is factory, ask factory to create service |
200 | | |
201 | 74.3k | Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY); |
202 | 74.3k | if( xFactory.is() ) |
203 | 74.3k | { |
204 | 74.3k | Reference<XInterface> xIfc = xFactory->createInstance(rServiceName); |
205 | 74.3k | if( xIfc.is() ) |
206 | 73.5k | { |
207 | 73.5k | xField.set(xIfc, UNO_QUERY); |
208 | 73.5k | } else { |
209 | 822 | return false; // can't create instance |
210 | 822 | } |
211 | 74.3k | } else { |
212 | 0 | return false; // can't get MultiServiceFactory |
213 | 0 | } |
214 | | |
215 | 73.5k | return true; |
216 | 74.3k | } |
217 | | |
218 | | /// create the appropriate field context from |
219 | | XMLTextFieldImportContext* |
220 | | XMLTextFieldImportContext::CreateTextFieldImportContext( |
221 | | SvXMLImport& rImport, |
222 | | XMLTextImportHelper& rHlp, |
223 | | sal_Int32 nToken) |
224 | 121k | { |
225 | 121k | XMLTextFieldImportContext* pContext = nullptr; |
226 | | |
227 | 121k | switch (nToken) |
228 | 121k | { |
229 | 1 | case XML_ELEMENT(TEXT, XML_SENDER_FIRSTNAME): |
230 | 1 | case XML_ELEMENT(TEXT, XML_SENDER_LASTNAME): |
231 | 1 | case XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS): |
232 | 21 | case XML_ELEMENT(TEXT, XML_SENDER_INITIALS): |
233 | 25 | case XML_ELEMENT(TEXT, XML_SENDER_TITLE): |
234 | 25 | case XML_ELEMENT(TEXT, XML_SENDER_POSITION): |
235 | 25 | case XML_ELEMENT(TEXT, XML_SENDER_EMAIL): |
236 | 26 | case XML_ELEMENT(TEXT, XML_SENDER_PHONE_PRIVATE): |
237 | | |
238 | 304 | case XML_ELEMENT(TEXT, XML_SENDER_FAX): |
239 | 305 | case XML_ELEMENT(TEXT, XML_SENDER_COMPANY): |
240 | 598 | case XML_ELEMENT(TEXT, XML_SENDER_PHONE_WORK): |
241 | 598 | case XML_ELEMENT(TEXT, XML_SENDER_STREET): |
242 | 598 | case XML_ELEMENT(TEXT, XML_SENDER_CITY): |
243 | 635 | case XML_ELEMENT(TEXT, XML_SENDER_POSTAL_CODE): |
244 | 638 | case XML_ELEMENT(TEXT, XML_SENDER_COUNTRY): |
245 | 638 | case XML_ELEMENT(TEXT, XML_SENDER_STATE_OR_PROVINCE): |
246 | 638 | pContext = |
247 | 638 | new XMLSenderFieldImportContext( rImport, rHlp ); |
248 | 638 | break; |
249 | | |
250 | 0 | case XML_ELEMENT(TEXT, XML_AUTHOR_NAME): |
251 | 0 | case XML_ELEMENT(TEXT, XML_AUTHOR_INITIALS): |
252 | 0 | pContext = |
253 | 0 | new XMLAuthorFieldImportContext( rImport, rHlp ); |
254 | 0 | break; |
255 | | |
256 | 0 | case XML_ELEMENT(TEXT, XML_PLACEHOLDER): |
257 | 0 | pContext = |
258 | 0 | new XMLPlaceholderFieldImportContext( rImport, rHlp); |
259 | 0 | break; |
260 | 693 | case XML_ELEMENT(TEXT, XML_SEQUENCE): |
261 | 693 | pContext = |
262 | 693 | new XMLSequenceFieldImportContext( rImport, rHlp ); |
263 | 693 | break; |
264 | 1 | case XML_ELEMENT(TEXT, XML_TEXT_INPUT): |
265 | 1 | pContext = |
266 | 1 | new XMLTextInputFieldImportContext( rImport, rHlp ); |
267 | 1 | break; |
268 | 1 | case XML_ELEMENT(TEXT, XML_EXPRESSION): |
269 | 1 | pContext = |
270 | 1 | new XMLExpressionFieldImportContext( rImport, rHlp ); |
271 | 1 | break; |
272 | 0 | case XML_ELEMENT(TEXT, XML_VARIABLE_SET): |
273 | 0 | pContext = |
274 | 0 | new XMLVariableSetFieldImportContext( rImport, rHlp ); |
275 | 0 | break; |
276 | 0 | case XML_ELEMENT(TEXT, XML_VARIABLE_INPUT): |
277 | 0 | pContext = |
278 | 0 | new XMLVariableInputFieldImportContext( rImport, rHlp ); |
279 | 0 | break; |
280 | 0 | case XML_ELEMENT(TEXT, XML_VARIABLE_GET): |
281 | 0 | pContext = |
282 | 0 | new XMLVariableGetFieldImportContext( rImport, rHlp ); |
283 | 0 | break; |
284 | 0 | case XML_ELEMENT(TEXT, XML_USER_FIELD_GET): |
285 | 0 | pContext = new XMLUserFieldImportContext( rImport, rHlp ); |
286 | 0 | break; |
287 | 0 | case XML_ELEMENT(TEXT, XML_USER_FIELD_INPUT): |
288 | 0 | pContext = new XMLUserFieldInputImportContext( rImport, rHlp ); |
289 | 0 | break; |
290 | 14.4k | case XML_ELEMENT(TEXT, XML_TIME): |
291 | 14.4k | pContext = new XMLTimeFieldImportContext( rImport, rHlp ); |
292 | 14.4k | break; |
293 | 0 | case XML_ELEMENT(TEXT, XML_PAGE_CONTINUATION_STRING): |
294 | 0 | case XML_ELEMENT(TEXT, XML_PAGE_CONTINUATION): |
295 | 0 | pContext = new XMLPageContinuationImportContext( rImport, rHlp ); |
296 | 0 | break; |
297 | | |
298 | 27.7k | case XML_ELEMENT(TEXT, XML_PAGE_NUMBER): |
299 | 27.7k | pContext = new XMLPageNumberImportContext( rImport, rHlp ); |
300 | 27.7k | break; |
301 | | |
302 | 12.9k | case XML_ELEMENT(TEXT, XML_DATE): |
303 | 12.9k | pContext = new XMLDateFieldImportContext( rImport, rHlp ); |
304 | 12.9k | break; |
305 | | |
306 | 0 | case XML_ELEMENT(TEXT, XML_DATABASE_NAME): |
307 | 0 | pContext = new XMLDatabaseNameImportContext( rImport, rHlp ); |
308 | 0 | break; |
309 | 0 | case XML_ELEMENT(TEXT, XML_DATABASE_NEXT): |
310 | 0 | pContext = new XMLDatabaseNextImportContext( rImport, rHlp ); |
311 | 0 | break; |
312 | 1 | case XML_ELEMENT(TEXT, XML_DATABASE_ROW_SELECT): |
313 | 1 | pContext = new XMLDatabaseSelectImportContext( rImport, rHlp ); |
314 | 1 | break; |
315 | 6 | case XML_ELEMENT(TEXT, XML_DATABASE_ROW_NUMBER): |
316 | 6 | pContext = new XMLDatabaseNumberImportContext( rImport, rHlp ); |
317 | 6 | break; |
318 | 396 | case XML_ELEMENT(TEXT, XML_DATABASE_DISPLAY): |
319 | 396 | pContext = new XMLDatabaseDisplayImportContext( rImport, rHlp ); |
320 | 396 | break; |
321 | 1 | case XML_ELEMENT(TEXT, XML_CONDITIONAL_TEXT): |
322 | 1 | pContext = new XMLConditionalTextImportContext( rImport, rHlp ); |
323 | 1 | break; |
324 | 0 | case XML_ELEMENT(TEXT, XML_HIDDEN_TEXT): |
325 | 0 | pContext = new XMLHiddenTextImportContext( rImport, rHlp ); |
326 | 0 | break; |
327 | 0 | case XML_ELEMENT(TEXT, XML_HIDDEN_PARAGRAPH): |
328 | 0 | pContext = new XMLHiddenParagraphImportContext( rImport, rHlp ); |
329 | 0 | break; |
330 | 0 | case XML_ELEMENT(TEXT, XML_DESCRIPTION): |
331 | 440 | case XML_ELEMENT(TEXT, XML_TITLE): |
332 | 440 | case XML_ELEMENT(TEXT, XML_SUBJECT): |
333 | 440 | case XML_ELEMENT(TEXT, XML_KEYWORDS): |
334 | 440 | pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp, |
335 | 440 | nToken, true, |
336 | 440 | false ); |
337 | 440 | break; |
338 | 0 | case XML_ELEMENT(TEXT, XML_INITIAL_CREATOR): |
339 | 0 | case XML_ELEMENT(TEXT, XML_PRINTED_BY): |
340 | 0 | case XML_ELEMENT(TEXT, XML_CREATOR): |
341 | 0 | pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp, |
342 | 0 | nToken, false, |
343 | 0 | true ); |
344 | 0 | break; |
345 | | |
346 | 0 | case XML_ELEMENT(TEXT, XML_CREATION_DATE): |
347 | 0 | case XML_ELEMENT(TEXT, XML_CREATION_TIME): |
348 | 129 | case XML_ELEMENT(TEXT, XML_PRINT_DATE): |
349 | 136 | case XML_ELEMENT(TEXT, XML_PRINT_TIME): |
350 | 136 | case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE): |
351 | 307 | case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME): |
352 | 307 | case XML_ELEMENT(TEXT, XML_EDITING_DURATION): |
353 | 307 | pContext = new XMLDateTimeDocInfoImportContext( rImport, rHlp, |
354 | 307 | nToken ); |
355 | 307 | break; |
356 | | |
357 | 0 | case XML_ELEMENT(TEXT, XML_EDITING_CYCLES): |
358 | 0 | pContext = new XMLRevisionDocInfoImportContext( rImport, rHlp, |
359 | 0 | nToken ); |
360 | 0 | break; |
361 | | |
362 | 0 | case XML_ELEMENT(TEXT, XML_USER_DEFINED): |
363 | 0 | pContext = new XMLUserDocInfoImportContext( rImport, rHlp, |
364 | 0 | nToken ); |
365 | 0 | break; |
366 | | |
367 | 316 | case XML_ELEMENT(TEXT, XML_FILE_NAME): |
368 | 316 | pContext = new XMLFileNameImportContext( rImport, rHlp ); |
369 | 316 | break; |
370 | | |
371 | 1 | case XML_ELEMENT(TEXT, XML_CHAPTER): |
372 | 1 | pContext = new XMLChapterImportContext( rImport, rHlp ); |
373 | 1 | break; |
374 | | |
375 | 0 | case XML_ELEMENT(TEXT, XML_TEMPLATE_NAME): |
376 | 0 | pContext = new XMLTemplateNameImportContext( rImport, rHlp ); |
377 | 0 | break; |
378 | | |
379 | 0 | case XML_ELEMENT(TEXT, XML_WORD_COUNT): |
380 | 0 | case XML_ELEMENT(TEXT, XML_PARAGRAPH_COUNT): |
381 | 0 | case XML_ELEMENT(TEXT, XML_TABLE_COUNT): |
382 | 0 | case XML_ELEMENT(TEXT, XML_CHARACTER_COUNT): |
383 | 0 | case XML_ELEMENT(TEXT, XML_IMAGE_COUNT): |
384 | 0 | case XML_ELEMENT(TEXT, XML_OBJECT_COUNT): |
385 | 10.8k | case XML_ELEMENT(TEXT, XML_PAGE_COUNT): |
386 | 10.8k | case XML_ELEMENT(LO_EXT, XML_PAGE_COUNT_RANGE): |
387 | 10.8k | pContext = new XMLCountFieldImportContext( rImport, rHlp, nToken); |
388 | 10.8k | break; |
389 | | |
390 | 0 | case XML_ELEMENT(TEXT, XML_PAGE_VARIABLE_GET): |
391 | 0 | pContext = new XMLPageVarGetFieldImportContext( rImport, rHlp ); |
392 | 0 | break; |
393 | | |
394 | 0 | case XML_ELEMENT(TEXT, XML_PAGE_VARIABLE_SET): |
395 | 0 | pContext = new XMLPageVarSetFieldImportContext( rImport, rHlp ); |
396 | 0 | break; |
397 | | |
398 | 3 | case XML_ELEMENT(TEXT, XML_EXECUTE_MACRO): |
399 | 3 | pContext = new XMLMacroFieldImportContext( rImport, rHlp ); |
400 | 3 | break; |
401 | | |
402 | 1 | case XML_ELEMENT(TEXT, XML_DDE_CONNECTION): |
403 | 1 | pContext = new XMLDdeFieldImportContext( rImport, rHlp ); |
404 | 1 | break; |
405 | | |
406 | 0 | case XML_ELEMENT(TEXT, XML_REFERENCE_REF): |
407 | 0 | case XML_ELEMENT(TEXT, XML_BOOKMARK_REF): |
408 | 0 | case XML_ELEMENT(TEXT, XML_NOTE_REF): |
409 | 1 | case XML_ELEMENT(TEXT, XML_SEQUENCE_REF): |
410 | 1 | case XML_ELEMENT(TEXT, XML_STYLE_REF): |
411 | 1 | case XML_ELEMENT(LO_EXT, XML_STYLE_REF): |
412 | 1 | pContext = new XMLReferenceFieldImportContext( rImport, rHlp, nToken ); |
413 | 1 | break; |
414 | | |
415 | 4.19k | case XML_ELEMENT(TEXT, XML_SHEET_NAME): |
416 | 4.19k | pContext = new XMLSheetNameImportContext( rImport, rHlp ); |
417 | 4.19k | break; |
418 | | |
419 | 0 | case XML_ELEMENT(TEXT, XML_PAGE_NAME): |
420 | 0 | case XML_ELEMENT(LO_EXT, XML_PAGE_NAME): |
421 | 0 | pContext = new XMLPageNameFieldImportContext( rImport, rHlp ); |
422 | 0 | break; |
423 | | |
424 | 268 | case XML_ELEMENT(TEXT, XML_BIBLIOGRAPHY_MARK): |
425 | 268 | pContext = new XMLBibliographyFieldImportContext( rImport, rHlp ); |
426 | 268 | break; |
427 | | |
428 | 0 | case XML_ELEMENT(OFFICE, XML_ANNOTATION): |
429 | 43 | case XML_ELEMENT(OFFICE, XML_ANNOTATION_END): |
430 | 43 | pContext = new XMLAnnotationImportContext( rImport, rHlp, nToken); |
431 | 43 | break; |
432 | | |
433 | 1 | case XML_ELEMENT(TEXT, XML_SCRIPT): |
434 | 1 | pContext = new XMLScriptImportContext( rImport, rHlp); |
435 | 1 | break; |
436 | | |
437 | 0 | case XML_ELEMENT(TEXT, XML_MEASURE): |
438 | 0 | pContext = new XMLMeasureFieldImportContext( rImport, rHlp ); |
439 | 0 | break; |
440 | | |
441 | 8 | case XML_ELEMENT(TEXT, XML_TABLE_FORMULA): |
442 | 8 | pContext = new XMLTableFormulaImportContext( rImport, rHlp ); |
443 | 8 | break; |
444 | 0 | case XML_ELEMENT(TEXT, XML_DROP_DOWN): |
445 | 0 | pContext = new XMLDropDownFieldImportContext( rImport, rHlp ); |
446 | 0 | break; |
447 | 290 | case XML_ELEMENT(PRESENTATION, XML_HEADER): |
448 | 290 | pContext = new XMLHeaderFieldImportContext( rImport, rHlp ); |
449 | 290 | break; |
450 | 335 | case XML_ELEMENT(PRESENTATION, XML_FOOTER): |
451 | 335 | pContext = new XMLFooterFieldImportContext( rImport, rHlp ); |
452 | 335 | break; |
453 | 362 | case XML_ELEMENT(PRESENTATION, XML_DATE_TIME): |
454 | 362 | pContext = new XMLDateTimeFieldImportContext( rImport, rHlp ); |
455 | 362 | break; |
456 | | |
457 | 47.5k | default: |
458 | | // ignore! May not even be a textfield. |
459 | | // (Reminder: This method is called inside default:-branch) |
460 | 47.5k | pContext = nullptr; |
461 | 47.5k | break; |
462 | 121k | } |
463 | | |
464 | 121k | return pContext; |
465 | 121k | } |
466 | | |
467 | | |
468 | | void XMLTextFieldImportContext::ForceUpdate( |
469 | | const Reference<XPropertySet> & rPropertySet) |
470 | 0 | { |
471 | | // force update |
472 | 0 | Reference<XUpdatable> xUpdate(rPropertySet, UNO_QUERY); |
473 | 0 | if (xUpdate.is()) |
474 | 0 | { |
475 | 0 | xUpdate->update(); |
476 | 0 | } |
477 | 0 | else |
478 | 0 | { |
479 | 0 | OSL_FAIL("Expected XUpdatable support!"); |
480 | 0 | } |
481 | 0 | } |
482 | | |
483 | | |
484 | | // XMLSenderFieldImportContext |
485 | | |
486 | | |
487 | | constexpr OUStringLiteral gsPropertyFieldSubType(u"UserDataType"); |
488 | | |
489 | | XMLSenderFieldImportContext::XMLSenderFieldImportContext( |
490 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) |
491 | 638 | : XMLTextFieldImportContext(rImport, rHlp, u"ExtendedUser"_ustr) |
492 | 638 | , nSubType(0) |
493 | 638 | , sPropertyFixed(sAPI_is_fixed) |
494 | 638 | , sPropertyContent(sAPI_content) |
495 | 638 | , bFixed(true) |
496 | 638 | { |
497 | 638 | } |
498 | | |
499 | | void XMLSenderFieldImportContext::startFastElement( |
500 | | sal_Int32 nElement, |
501 | | const Reference<XFastAttributeList> & xAttrList) |
502 | 638 | { |
503 | 638 | bValid = true; |
504 | 638 | switch (nElement) { |
505 | 1 | case XML_ELEMENT(TEXT, XML_SENDER_FIRSTNAME): |
506 | 1 | nSubType = UserDataPart::FIRSTNAME; |
507 | 1 | break; |
508 | 0 | case XML_ELEMENT(TEXT, XML_SENDER_LASTNAME): |
509 | 0 | nSubType = UserDataPart::NAME; |
510 | 0 | break; |
511 | 0 | case XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS): |
512 | 20 | case XML_ELEMENT(TEXT, XML_SENDER_INITIALS): |
513 | 20 | nSubType = UserDataPart::SHORTCUT; |
514 | 20 | break; |
515 | 4 | case XML_ELEMENT(TEXT, XML_SENDER_TITLE): |
516 | 4 | nSubType = UserDataPart::TITLE; |
517 | 4 | break; |
518 | 0 | case XML_ELEMENT(TEXT, XML_SENDER_POSITION): |
519 | 0 | nSubType = UserDataPart::POSITION; |
520 | 0 | break; |
521 | 0 | case XML_ELEMENT(TEXT, XML_SENDER_EMAIL): |
522 | 0 | nSubType = UserDataPart::EMAIL; |
523 | 0 | break; |
524 | 1 | case XML_ELEMENT(TEXT, XML_SENDER_PHONE_PRIVATE): |
525 | 1 | nSubType = UserDataPart::PHONE_PRIVATE; |
526 | 1 | break; |
527 | 278 | case XML_ELEMENT(TEXT, XML_SENDER_FAX): |
528 | 278 | nSubType = UserDataPart::FAX; |
529 | 278 | break; |
530 | 1 | case XML_ELEMENT(TEXT, XML_SENDER_COMPANY): |
531 | 1 | nSubType = UserDataPart::COMPANY; |
532 | 1 | break; |
533 | 293 | case XML_ELEMENT(TEXT, XML_SENDER_PHONE_WORK): |
534 | 293 | nSubType = UserDataPart::PHONE_COMPANY; |
535 | 293 | break; |
536 | 0 | case XML_ELEMENT(TEXT, XML_SENDER_STREET): |
537 | 0 | nSubType = UserDataPart::STREET; |
538 | 0 | break; |
539 | 0 | case XML_ELEMENT(TEXT, XML_SENDER_CITY): |
540 | 0 | nSubType = UserDataPart::CITY; |
541 | 0 | break; |
542 | 37 | case XML_ELEMENT(TEXT, XML_SENDER_POSTAL_CODE): |
543 | 37 | nSubType = UserDataPart::ZIP; |
544 | 37 | break; |
545 | 3 | case XML_ELEMENT(TEXT, XML_SENDER_COUNTRY): |
546 | 3 | nSubType = UserDataPart::COUNTRY; |
547 | 3 | break; |
548 | 0 | case XML_ELEMENT(TEXT, XML_SENDER_STATE_OR_PROVINCE): |
549 | 0 | nSubType = UserDataPart::STATE; |
550 | 0 | break; |
551 | 0 | default: |
552 | 0 | bValid = false; |
553 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
554 | 0 | break; |
555 | 638 | } |
556 | | |
557 | | // process Attributes |
558 | 638 | XMLTextFieldImportContext::startFastElement(nElement, xAttrList); |
559 | 638 | } |
560 | | |
561 | | void XMLSenderFieldImportContext::ProcessAttribute( |
562 | | sal_Int32 nAttrToken, |
563 | | std::string_view sAttrValue) |
564 | 0 | { |
565 | 0 | if (XML_ELEMENT(TEXT, XML_FIXED) == nAttrToken) { |
566 | | |
567 | | // set bVal |
568 | 0 | bool bVal(false); |
569 | 0 | bool const bRet = ::sax::Converter::convertBool(bVal, sAttrValue); |
570 | | |
571 | | // set bFixed if successful |
572 | 0 | if (bRet) { |
573 | 0 | bFixed = bVal; |
574 | 0 | } |
575 | 0 | } |
576 | 0 | else |
577 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
578 | 0 | } |
579 | | |
580 | | void XMLSenderFieldImportContext::PrepareField( |
581 | | const Reference<XPropertySet> & rPropSet) |
582 | 42 | { |
583 | | // set members |
584 | 42 | rPropSet->setPropertyValue(gsPropertyFieldSubType, Any(nSubType)); |
585 | | |
586 | | // set fixed |
587 | 42 | rPropSet->setPropertyValue(sPropertyFixed, Any(bFixed)); |
588 | | |
589 | | // set content if fixed |
590 | 42 | if (!bFixed) |
591 | 0 | return; |
592 | | |
593 | | // in organizer or styles-only mode: force update |
594 | 42 | if (GetImport().GetTextImport()->IsOrganizerMode() || |
595 | 42 | GetImport().GetTextImport()->IsStylesOnlyMode() ) |
596 | 0 | { |
597 | 0 | ForceUpdate(rPropSet); |
598 | 0 | } |
599 | 42 | else |
600 | 42 | { |
601 | 42 | rPropSet->setPropertyValue(sPropertyContent, Any(GetContent())); |
602 | 42 | } |
603 | 42 | } |
604 | | |
605 | | |
606 | | // XMLAuthorFieldImportContext |
607 | | |
608 | | constexpr OUStringLiteral gsPropertyAuthorFullName(u"FullName"); |
609 | | |
610 | | XMLAuthorFieldImportContext::XMLAuthorFieldImportContext( |
611 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) |
612 | 0 | : XMLSenderFieldImportContext(rImport, rHlp) |
613 | 0 | , bAuthorFullName(true) |
614 | 0 | , sPropertyFixed(sAPI_is_fixed) |
615 | 0 | , sPropertyContent(sAPI_content) |
616 | 0 | { |
617 | | // overwrite service name from XMLSenderFieldImportContext |
618 | 0 | SetServiceName(sAPI_author); |
619 | 0 | } |
620 | | |
621 | | void XMLAuthorFieldImportContext::startFastElement( |
622 | | sal_Int32 nElement, |
623 | | const Reference<XFastAttributeList> & xAttrList) |
624 | 0 | { |
625 | 0 | bAuthorFullName = ( XML_ELEMENT(TEXT, XML_AUTHOR_INITIALS) != nElement); |
626 | 0 | bValid = true; |
627 | | |
628 | | // process Attributes |
629 | 0 | XMLTextFieldImportContext::startFastElement(nElement, xAttrList); |
630 | 0 | } |
631 | | |
632 | | void XMLAuthorFieldImportContext::ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue) |
633 | 0 | { |
634 | 0 | if(nAttrToken == XML_ELEMENT(TEXT, XML_FIXED)) |
635 | 0 | { |
636 | 0 | bool bTmp(false); |
637 | 0 | if (::sax::Converter::convertBool(bTmp, sAttrValue)) |
638 | 0 | bFixed = bTmp; |
639 | 0 | } |
640 | 0 | else |
641 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
642 | 0 | } |
643 | | |
644 | | void XMLAuthorFieldImportContext::PrepareField( |
645 | | const Reference<XPropertySet> & rPropSet) |
646 | 0 | { |
647 | | // set members |
648 | 0 | Any aAny; |
649 | 0 | rPropSet->setPropertyValue(gsPropertyAuthorFullName, Any(bAuthorFullName)); |
650 | |
|
651 | 0 | rPropSet->setPropertyValue(sPropertyFixed, Any(bFixed)); |
652 | | |
653 | | // set content if fixed |
654 | 0 | if (!bFixed) |
655 | 0 | return; |
656 | | |
657 | | // organizer or styles-only mode: force update |
658 | 0 | if (GetImport().GetTextImport()->IsOrganizerMode() || |
659 | 0 | GetImport().GetTextImport()->IsStylesOnlyMode() ) |
660 | 0 | { |
661 | 0 | ForceUpdate(rPropSet); |
662 | 0 | } |
663 | 0 | else |
664 | 0 | { |
665 | 0 | aAny <<= GetContent(); |
666 | 0 | rPropSet->setPropertyValue(sPropertyContent, aAny); |
667 | 0 | } |
668 | 0 | } |
669 | | |
670 | | |
671 | | // page continuation string |
672 | | |
673 | | |
674 | | SvXMLEnumMapEntry<PageNumberType> const lcl_aSelectPageAttrMap[] = |
675 | | { |
676 | | { XML_PREVIOUS, PageNumberType_PREV }, |
677 | | { XML_CURRENT, PageNumberType_CURRENT }, |
678 | | { XML_NEXT, PageNumberType_NEXT }, |
679 | | { XML_TOKEN_INVALID, PageNumberType(0) }, |
680 | | }; |
681 | | |
682 | | constexpr OUStringLiteral gsPropertyUserText(u"UserText"); |
683 | | |
684 | | XMLPageContinuationImportContext::XMLPageContinuationImportContext( |
685 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) |
686 | 0 | : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number) |
687 | 0 | , sPropertySubType(sAPI_sub_type) |
688 | 0 | , sPropertyNumberingType(sAPI_numbering_type) |
689 | 0 | , eSelectPage(PageNumberType_CURRENT) |
690 | 0 | , sStringOK(false) |
691 | 0 | { |
692 | 0 | bValid = true; |
693 | 0 | } |
694 | | |
695 | | void XMLPageContinuationImportContext::ProcessAttribute( |
696 | | sal_Int32 nAttrToken, std::string_view sAttrValue ) |
697 | 0 | { |
698 | 0 | switch(nAttrToken) |
699 | 0 | { |
700 | 0 | case XML_ELEMENT(TEXT, XML_SELECT_PAGE): |
701 | 0 | { |
702 | 0 | PageNumberType nTmp; |
703 | 0 | if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, |
704 | 0 | lcl_aSelectPageAttrMap) |
705 | 0 | && (PageNumberType_CURRENT != nTmp) ) |
706 | 0 | { |
707 | 0 | eSelectPage = nTmp; |
708 | 0 | } |
709 | 0 | break; |
710 | 0 | } |
711 | 0 | case XML_ELEMENT(TEXT, XML_STRING_VALUE): |
712 | 0 | case XML_ELEMENT(OFFICE, XML_STRING_VALUE): |
713 | 0 | sString = OUString::fromUtf8(sAttrValue); |
714 | 0 | sStringOK = true; |
715 | 0 | break; |
716 | 0 | default: |
717 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
718 | 0 | } |
719 | 0 | } |
720 | | |
721 | | void XMLPageContinuationImportContext::PrepareField( |
722 | | const Reference<XPropertySet> & xPropertySet) |
723 | 0 | { |
724 | 0 | Any aAny; |
725 | |
|
726 | 0 | xPropertySet->setPropertyValue(sPropertySubType, Any(eSelectPage)); |
727 | |
|
728 | 0 | aAny <<= (sStringOK ? sString : GetContent()); |
729 | 0 | xPropertySet->setPropertyValue(gsPropertyUserText, aAny); |
730 | |
|
731 | 0 | aAny <<= style::NumberingType::CHAR_SPECIAL; |
732 | 0 | xPropertySet->setPropertyValue(sPropertyNumberingType, aAny); |
733 | 0 | } |
734 | | |
735 | | |
736 | | // page number field |
737 | | |
738 | | |
739 | | XMLPageNumberImportContext::XMLPageNumberImportContext( |
740 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) |
741 | 27.7k | : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number) |
742 | 27.7k | , sPropertySubType(sAPI_sub_type) |
743 | 27.7k | , sPropertyNumberingType(sAPI_numbering_type) |
744 | 27.7k | , sPropertyOffset(sAPI_offset) |
745 | 27.7k | , sNumberSync(GetXMLToken(XML_FALSE)) |
746 | 27.7k | , nPageAdjust(0) |
747 | 27.7k | , eSelectPage(PageNumberType_CURRENT) |
748 | 27.7k | , sNumberFormatOK(false) |
749 | 27.7k | { |
750 | 27.7k | bValid = true; |
751 | 27.7k | } |
752 | | |
753 | | void XMLPageNumberImportContext::ProcessAttribute( |
754 | | sal_Int32 nAttrToken, |
755 | | std::string_view sAttrValue ) |
756 | 486 | { |
757 | 486 | switch (nAttrToken) |
758 | 486 | { |
759 | 0 | case XML_ELEMENT(STYLE, XML_NUM_FORMAT): |
760 | 0 | sNumberFormat = OUString::fromUtf8(sAttrValue); |
761 | 0 | sNumberFormatOK = true; |
762 | 0 | break; |
763 | 0 | case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC): |
764 | 0 | sNumberSync = OUString::fromUtf8(sAttrValue); |
765 | 0 | break; |
766 | 486 | case XML_ELEMENT(TEXT, XML_SELECT_PAGE): |
767 | 486 | SvXMLUnitConverter::convertEnum(eSelectPage, sAttrValue, |
768 | 486 | lcl_aSelectPageAttrMap); |
769 | 486 | break; |
770 | 0 | case XML_ELEMENT(TEXT, XML_PAGE_ADJUST): |
771 | 0 | { |
772 | 0 | sal_Int32 nTmp; |
773 | 0 | if (::sax::Converter::convertNumber(nTmp, sAttrValue)) |
774 | 0 | { |
775 | 0 | nPageAdjust = static_cast<sal_Int16>(nTmp); |
776 | 0 | } |
777 | 0 | break; |
778 | 0 | } |
779 | 0 | default: |
780 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
781 | 486 | } |
782 | 486 | } |
783 | | |
784 | | void XMLPageNumberImportContext::PrepareField( |
785 | | const Reference<XPropertySet> & xPropertySet) |
786 | 27.7k | { |
787 | | // all properties are optional |
788 | 27.7k | Reference<XPropertySetInfo> xPropertySetInfo( |
789 | 27.7k | xPropertySet->getPropertySetInfo()); |
790 | | |
791 | 27.7k | if (xPropertySetInfo->hasPropertyByName(sPropertyNumberingType)) |
792 | 595 | { |
793 | 595 | sal_Int16 nNumType; |
794 | 595 | if( sNumberFormatOK ) |
795 | 0 | { |
796 | 0 | nNumType= style::NumberingType::ARABIC; |
797 | 0 | GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, |
798 | 0 | sNumberFormat, |
799 | 0 | sNumberSync ); |
800 | 0 | } |
801 | 595 | else |
802 | 595 | nNumType = style::NumberingType::PAGE_DESCRIPTOR; |
803 | | |
804 | 595 | xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType)); |
805 | 595 | } |
806 | | |
807 | 27.7k | if (xPropertySetInfo->hasPropertyByName(sPropertyOffset)) |
808 | 595 | { |
809 | | // adjust offset |
810 | 595 | switch (eSelectPage) |
811 | 595 | { |
812 | 0 | case PageNumberType_PREV: |
813 | 0 | nPageAdjust--; |
814 | 0 | break; |
815 | 595 | case PageNumberType_CURRENT: |
816 | 595 | break; |
817 | 0 | case PageNumberType_NEXT: |
818 | 0 | nPageAdjust++; |
819 | 0 | break; |
820 | 0 | default: |
821 | 0 | SAL_WARN("xmloff.text", "unknown page number type"); |
822 | 595 | } |
823 | 595 | xPropertySet->setPropertyValue(sPropertyOffset, Any(nPageAdjust)); |
824 | 595 | } |
825 | | |
826 | 27.7k | if (xPropertySetInfo->hasPropertyByName(sPropertySubType)) |
827 | 595 | { |
828 | 595 | xPropertySet->setPropertyValue(sPropertySubType, Any(eSelectPage)); |
829 | 595 | } |
830 | 27.7k | } |
831 | | |
832 | | |
833 | | // Placeholder |
834 | | |
835 | | |
836 | | constexpr OUStringLiteral gsPropertyPlaceholderType(u"PlaceHolderType"); |
837 | | constexpr OUStringLiteral gsPropertyPlaceholder(u"PlaceHolder"); |
838 | | |
839 | | XMLPlaceholderFieldImportContext::XMLPlaceholderFieldImportContext( |
840 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) |
841 | 0 | : XMLTextFieldImportContext(rImport, rHlp, u"JumpEdit"_ustr) |
842 | 0 | , sPropertyHint(sAPI_hint) |
843 | 0 | , nPlaceholderType(PlaceholderType::TEXT) |
844 | 0 | { |
845 | 0 | } |
846 | | |
847 | | /// process attribute values |
848 | | void XMLPlaceholderFieldImportContext::ProcessAttribute( |
849 | | sal_Int32 nAttrToken, std::string_view sAttrValue ) |
850 | 0 | { |
851 | 0 | switch (nAttrToken) { |
852 | 0 | case XML_ELEMENT(TEXT, XML_DESCRIPTION): |
853 | 0 | sDescription = OUString::fromUtf8(sAttrValue); |
854 | 0 | break; |
855 | | |
856 | 0 | case XML_ELEMENT(TEXT, XML_PLACEHOLDER_TYPE): |
857 | 0 | bValid = true; |
858 | 0 | if (IsXMLToken(sAttrValue, XML_TABLE)) |
859 | 0 | { |
860 | 0 | nPlaceholderType = PlaceholderType::TABLE; |
861 | 0 | } |
862 | 0 | else if (IsXMLToken(sAttrValue, XML_TEXT)) |
863 | 0 | { |
864 | 0 | nPlaceholderType = PlaceholderType::TEXT; |
865 | 0 | } |
866 | 0 | else if (IsXMLToken(sAttrValue, XML_TEXT_BOX)) |
867 | 0 | { |
868 | 0 | nPlaceholderType = PlaceholderType::TEXTFRAME; |
869 | 0 | } |
870 | 0 | else if (IsXMLToken(sAttrValue, XML_IMAGE)) |
871 | 0 | { |
872 | 0 | nPlaceholderType = PlaceholderType::GRAPHIC; |
873 | 0 | } |
874 | 0 | else if (IsXMLToken(sAttrValue, XML_OBJECT)) |
875 | 0 | { |
876 | 0 | nPlaceholderType = PlaceholderType::OBJECT; |
877 | 0 | } |
878 | 0 | else |
879 | 0 | { |
880 | 0 | bValid = false; |
881 | 0 | } |
882 | 0 | break; |
883 | | |
884 | 0 | default: |
885 | | // ignore |
886 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
887 | 0 | } |
888 | 0 | } |
889 | | |
890 | | void XMLPlaceholderFieldImportContext::PrepareField( |
891 | 0 | const Reference<XPropertySet> & xPropertySet) { |
892 | |
|
893 | 0 | Any aAny; |
894 | 0 | xPropertySet->setPropertyValue(sPropertyHint, Any(sDescription)); |
895 | | |
896 | | // remove <...> around content (if present) |
897 | 0 | OUString aContent = GetContent(); |
898 | 0 | sal_Int32 nStart = 0; |
899 | 0 | sal_Int32 nLength = aContent.getLength(); |
900 | 0 | if (aContent.startsWith("<")) |
901 | 0 | { |
902 | 0 | --nLength; |
903 | 0 | ++nStart; |
904 | 0 | } |
905 | 0 | if (aContent.endsWith(">")) |
906 | 0 | { |
907 | 0 | --nLength; |
908 | 0 | } |
909 | 0 | aAny <<= aContent.copy(nStart, nLength); |
910 | 0 | xPropertySet->setPropertyValue(gsPropertyPlaceholder, aAny); |
911 | |
|
912 | 0 | xPropertySet->setPropertyValue(gsPropertyPlaceholderType, Any(nPlaceholderType)); |
913 | 0 | } |
914 | | |
915 | | |
916 | | // time field |
917 | | |
918 | | constexpr OUString gsPropertyAdjust(u"Adjust"_ustr); |
919 | | |
920 | | XMLTimeFieldImportContext::XMLTimeFieldImportContext( |
921 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) |
922 | 27.3k | : XMLTextFieldImportContext(rImport, rHlp, sAPI_date_time) |
923 | 27.3k | , sPropertyNumberFormat(sAPI_number_format) |
924 | 27.3k | , sPropertyFixed(sAPI_is_fixed) |
925 | 27.3k | , sPropertyDateTimeValue(sAPI_date_time_value) |
926 | 27.3k | , sPropertyDateTime(sAPI_date_time) |
927 | 27.3k | , sPropertyIsDate(sAPI_is_date) |
928 | 27.3k | , sPropertyIsFixedLanguage(sAPI_is_fixed_language) |
929 | 27.3k | , nAdjust(0) |
930 | 27.3k | , nFormatKey(0) |
931 | 27.3k | , bTimeOK(false) |
932 | 27.3k | , bFormatOK(false) |
933 | 27.3k | , bFixed(false) |
934 | 27.3k | , bIsDate(false) |
935 | 27.3k | , bIsDefaultLanguage( true ) |
936 | 27.3k | { |
937 | 27.3k | bValid = true; // always valid! |
938 | 27.3k | } |
939 | | |
940 | | void XMLTimeFieldImportContext::ProcessAttribute( |
941 | | sal_Int32 nAttrToken, std::string_view sAttrValue ) |
942 | 6.73k | { |
943 | 6.73k | switch (nAttrToken) |
944 | 6.73k | { |
945 | 120 | case XML_ELEMENT(TEXT, XML_TIME_VALUE): |
946 | 120 | case XML_ELEMENT(OFFICE, XML_TIME_VALUE): |
947 | 120 | { |
948 | 120 | if (::sax::Converter::parseTimeOrDateTime(aDateTimeValue, sAttrValue)) |
949 | 93 | { |
950 | 93 | bTimeOK = true; |
951 | 93 | } |
952 | 120 | break; |
953 | 120 | } |
954 | 201 | case XML_ELEMENT(TEXT, XML_FIXED): |
955 | 201 | { |
956 | 201 | bool bTmp(false); |
957 | 201 | if (::sax::Converter::convertBool(bTmp, sAttrValue)) |
958 | 199 | { |
959 | 199 | bFixed = bTmp; |
960 | 199 | } |
961 | 201 | break; |
962 | 120 | } |
963 | 6.37k | case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME): |
964 | 6.37k | { |
965 | 6.37k | sal_Int32 nKey = GetImportHelper().GetDataStyleKey( |
966 | 6.37k | OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage); |
967 | 6.37k | if (-1 != nKey) |
968 | 197 | { |
969 | 197 | nFormatKey = nKey; |
970 | 197 | bFormatOK = true; |
971 | 197 | } |
972 | 6.37k | break; |
973 | 120 | } |
974 | 0 | case XML_ELEMENT(TEXT, XML_TIME_ADJUST): |
975 | 0 | { |
976 | 0 | double fTmp; |
977 | |
|
978 | 0 | if (::sax::Converter::convertDuration(fTmp, sAttrValue)) |
979 | 0 | { |
980 | | // convert to minutes |
981 | 0 | nAdjust = static_cast<sal_Int32>(::rtl::math::approxFloor(fTmp * 60 * 24)); |
982 | 0 | } |
983 | 0 | break; |
984 | 120 | } |
985 | 34 | default: |
986 | 34 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
987 | 6.73k | } |
988 | 6.73k | } |
989 | | |
990 | | void XMLTimeFieldImportContext::PrepareField( |
991 | | const Reference<XPropertySet> & rPropertySet) |
992 | 27.2k | { |
993 | | // all properties are optional (except IsDate) |
994 | 27.2k | Reference<XPropertySetInfo> xPropertySetInfo( |
995 | 27.2k | rPropertySet->getPropertySetInfo()); |
996 | | |
997 | 27.2k | if (xPropertySetInfo->hasPropertyByName(sPropertyFixed)) |
998 | 27.2k | { |
999 | 27.2k | rPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed)); |
1000 | 27.2k | } |
1001 | | |
1002 | 27.2k | rPropertySet->setPropertyValue(sPropertyIsDate, Any(bIsDate)); |
1003 | | |
1004 | 27.2k | if (xPropertySetInfo->hasPropertyByName(gsPropertyAdjust)) |
1005 | 3.43k | { |
1006 | 3.43k | rPropertySet->setPropertyValue(gsPropertyAdjust, Any(nAdjust)); |
1007 | 3.43k | } |
1008 | | |
1009 | | // set value |
1010 | 27.2k | if (bFixed) |
1011 | 198 | { |
1012 | | // organizer or styles-only mode: force update |
1013 | 198 | if (GetImport().GetTextImport()->IsOrganizerMode() || |
1014 | 198 | GetImport().GetTextImport()->IsStylesOnlyMode() ) |
1015 | 0 | { |
1016 | 0 | ForceUpdate(rPropertySet); |
1017 | 0 | } |
1018 | 198 | else |
1019 | 198 | { |
1020 | | // normal mode: set value (if present) |
1021 | 198 | if (bTimeOK) |
1022 | 160 | { |
1023 | 160 | if (xPropertySetInfo->hasPropertyByName(sPropertyDateTimeValue)) |
1024 | 160 | { |
1025 | 160 | rPropertySet->setPropertyValue(sPropertyDateTimeValue, Any(aDateTimeValue)); |
1026 | 160 | } |
1027 | 0 | else if (xPropertySetInfo->hasPropertyByName(sPropertyDateTime)) |
1028 | 0 | { |
1029 | 0 | rPropertySet->setPropertyValue(sPropertyDateTime, Any(aDateTimeValue)); |
1030 | 0 | } |
1031 | 160 | } |
1032 | 198 | } |
1033 | 198 | } |
1034 | | |
1035 | 27.2k | if (bFormatOK && |
1036 | 196 | xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat)) |
1037 | 196 | { |
1038 | 196 | rPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormatKey)); |
1039 | | |
1040 | 196 | if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) ) |
1041 | 167 | { |
1042 | 167 | bool bIsFixedLanguage = ! bIsDefaultLanguage; |
1043 | 167 | rPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) ); |
1044 | 167 | } |
1045 | 196 | } |
1046 | 27.2k | } |
1047 | | |
1048 | | |
1049 | | // date field |
1050 | | |
1051 | | |
1052 | | XMLDateFieldImportContext::XMLDateFieldImportContext( |
1053 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
1054 | 12.9k | XMLTimeFieldImportContext(rImport, rHlp) |
1055 | 12.9k | { |
1056 | 12.9k | bIsDate = true; // always a date! |
1057 | 12.9k | } |
1058 | | |
1059 | | void XMLDateFieldImportContext::ProcessAttribute( |
1060 | | sal_Int32 nAttrToken, |
1061 | | std::string_view sAttrValue ) |
1062 | 10.6k | { |
1063 | 10.6k | switch (nAttrToken) |
1064 | 10.6k | { |
1065 | 4.15k | case XML_ELEMENT(TEXT, XML_DATE_VALUE): |
1066 | 4.15k | case XML_ELEMENT(OFFICE, XML_DATE_VALUE): |
1067 | 4.15k | { |
1068 | 4.15k | if (::sax::Converter::parseDateTime(aDateTimeValue, sAttrValue)) |
1069 | 484 | { |
1070 | 484 | bTimeOK = true; |
1071 | 484 | } |
1072 | 4.15k | break; |
1073 | 4.15k | } |
1074 | 0 | case XML_ELEMENT(TEXT, XML_DATE_ADJUST): |
1075 | | // delegate to superclass, pretending it was a time-adjust attr. |
1076 | 0 | XMLTimeFieldImportContext::ProcessAttribute( |
1077 | 0 | XML_ELEMENT(TEXT, XML_TIME_ADJUST), |
1078 | 0 | sAttrValue); |
1079 | 0 | break; |
1080 | 1 | case XML_ELEMENT(TEXT, XML_TIME_VALUE): |
1081 | 1 | case XML_ELEMENT(OFFICE, XML_TIME_VALUE): |
1082 | 1 | case XML_ELEMENT(TEXT, XML_TIME_ADJUST): |
1083 | 1 | ; // ignore time-adjust and time-value attributes |
1084 | 1 | break; |
1085 | 6.49k | default: |
1086 | | // all others: delegate to super-class |
1087 | 6.49k | return XMLTimeFieldImportContext::ProcessAttribute(nAttrToken, |
1088 | 6.49k | sAttrValue); |
1089 | 0 | break; |
1090 | 10.6k | } |
1091 | 10.6k | } |
1092 | | |
1093 | | |
1094 | | // database field superclass |
1095 | | |
1096 | | |
1097 | | constexpr OUStringLiteral gsPropertyDataBaseName(u"DataBaseName"); |
1098 | | constexpr OUStringLiteral gsPropertyDataBaseURL(u"DataBaseURL"); |
1099 | | constexpr OUStringLiteral gsPropertyTableName(u"DataTableName"); |
1100 | | constexpr OUStringLiteral gsPropertyDataCommandType(u"DataCommandType"); |
1101 | | constexpr OUStringLiteral gsPropertyIsVisible(u"IsVisible"); |
1102 | | |
1103 | | XMLDatabaseFieldImportContext::XMLDatabaseFieldImportContext( |
1104 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, |
1105 | | const OUString& pServiceName, bool bUseDisplay) |
1106 | 403 | : XMLTextFieldImportContext(rImport, rHlp, pServiceName) |
1107 | 403 | , m_nCommandType( sdb::CommandType::TABLE ) |
1108 | 403 | , m_bCommandTypeOK(false) |
1109 | 403 | , m_bDisplay( true ) |
1110 | 403 | , m_bDisplayOK( false ) |
1111 | 403 | , m_bUseDisplay( bUseDisplay ) |
1112 | 403 | , m_bDatabaseOK(false) |
1113 | 403 | , m_bDatabaseNameOK(false) |
1114 | 403 | , m_bDatabaseURLOK(false) |
1115 | 403 | , m_bTableOK(false) |
1116 | 403 | { |
1117 | 403 | } |
1118 | | |
1119 | | void XMLDatabaseFieldImportContext::ProcessAttribute( |
1120 | | sal_Int32 nAttrToken, std::string_view sAttrValue ) |
1121 | 1.15k | { |
1122 | 1.15k | switch (nAttrToken) |
1123 | 1.15k | { |
1124 | 380 | case XML_ELEMENT(TEXT, XML_DATABASE_NAME): |
1125 | 380 | m_sDatabaseName = OUString::fromUtf8(sAttrValue); |
1126 | 380 | m_bDatabaseOK = true; |
1127 | 380 | m_bDatabaseNameOK = true; |
1128 | 380 | break; |
1129 | 385 | case XML_ELEMENT(TEXT, XML_TABLE_NAME): |
1130 | 385 | m_sTableName = OUString::fromUtf8(sAttrValue); |
1131 | 385 | m_bTableOK = true; |
1132 | 385 | break; |
1133 | 387 | case XML_ELEMENT(TEXT, XML_TABLE_TYPE): |
1134 | 387 | if( IsXMLToken( sAttrValue, XML_TABLE ) ) |
1135 | 385 | { |
1136 | 385 | m_nCommandType = sdb::CommandType::TABLE; |
1137 | 385 | m_bCommandTypeOK = true; |
1138 | 385 | } |
1139 | 2 | else if( IsXMLToken( sAttrValue, XML_QUERY ) ) |
1140 | 0 | { |
1141 | 0 | m_nCommandType = sdb::CommandType::QUERY; |
1142 | 0 | m_bCommandTypeOK = true; |
1143 | 0 | } |
1144 | 2 | else if( IsXMLToken( sAttrValue, XML_COMMAND ) ) |
1145 | 0 | { |
1146 | 0 | m_nCommandType = sdb::CommandType::COMMAND; |
1147 | 0 | m_bCommandTypeOK = true; |
1148 | 0 | } |
1149 | 387 | break; |
1150 | 0 | case XML_ELEMENT(TEXT, XML_DISPLAY): |
1151 | 0 | if( IsXMLToken( sAttrValue, XML_NONE ) ) |
1152 | 0 | { |
1153 | 0 | m_bDisplay = false; |
1154 | 0 | m_bDisplayOK = true; |
1155 | 0 | } |
1156 | 0 | else if( IsXMLToken( sAttrValue, XML_VALUE ) ) |
1157 | 0 | { |
1158 | 0 | m_bDisplay = true; |
1159 | 0 | m_bDisplayOK = true; |
1160 | 0 | } |
1161 | 0 | break; |
1162 | 0 | default: |
1163 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
1164 | 1.15k | } |
1165 | 1.15k | } |
1166 | | |
1167 | | css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDatabaseFieldImportContext::createFastChildContext( |
1168 | | sal_Int32 nElement, |
1169 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
1170 | 132 | { |
1171 | 132 | if (nElement == XML_ELEMENT(FORM, XML_CONNECTION_RESOURCE) ) |
1172 | 0 | { |
1173 | 0 | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
1174 | 0 | { |
1175 | 0 | switch (aIter.getToken()) |
1176 | 0 | { |
1177 | 0 | case XML_ELEMENT(XLINK, XML_HREF): |
1178 | 0 | { |
1179 | 0 | m_sDatabaseURL = aIter.toString(); |
1180 | 0 | m_bDatabaseOK = true; |
1181 | 0 | m_bDatabaseURLOK = true; |
1182 | 0 | } |
1183 | 0 | break; |
1184 | 0 | default:; |
1185 | 0 | } |
1186 | 0 | } |
1187 | | |
1188 | | // we call ProcessAttribute in order to set bValid appropriately |
1189 | 0 | ProcessAttribute( XML_TOKEN_INVALID, "" ); |
1190 | 0 | } |
1191 | 132 | else |
1192 | 132 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
1193 | | |
1194 | 132 | return nullptr; |
1195 | 132 | } |
1196 | | |
1197 | | |
1198 | | void XMLDatabaseFieldImportContext::PrepareField( |
1199 | | const Reference<XPropertySet> & xPropertySet) |
1200 | 351 | { |
1201 | 351 | xPropertySet->setPropertyValue(gsPropertyTableName, Any(m_sTableName)); |
1202 | | |
1203 | 351 | if( m_bDatabaseNameOK ) |
1204 | 351 | { |
1205 | 351 | xPropertySet->setPropertyValue(gsPropertyDataBaseName, Any(m_sDatabaseName)); |
1206 | 351 | } |
1207 | 0 | else if( m_bDatabaseURLOK ) |
1208 | 0 | { |
1209 | 0 | xPropertySet->setPropertyValue(gsPropertyDataBaseURL, Any(m_sDatabaseURL)); |
1210 | 0 | } |
1211 | | |
1212 | | // #99980# load/save command type for all fields; also load |
1213 | | // old documents without command type |
1214 | 351 | if( m_bCommandTypeOK ) |
1215 | 340 | { |
1216 | 340 | xPropertySet->setPropertyValue( gsPropertyDataCommandType, Any(m_nCommandType) ); |
1217 | 340 | } |
1218 | | |
1219 | 351 | if( m_bUseDisplay && m_bDisplayOK ) |
1220 | 0 | { |
1221 | 0 | xPropertySet->setPropertyValue( gsPropertyIsVisible, Any(m_bDisplay) ); |
1222 | 0 | } |
1223 | 351 | } |
1224 | | |
1225 | | |
1226 | | // database name field |
1227 | | |
1228 | | |
1229 | | XMLDatabaseNameImportContext::XMLDatabaseNameImportContext( |
1230 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
1231 | 0 | XMLDatabaseFieldImportContext(rImport, rHlp, u"DatabaseName"_ustr, true) |
1232 | 0 | { |
1233 | 0 | } |
1234 | | |
1235 | | void XMLDatabaseNameImportContext::ProcessAttribute( |
1236 | | sal_Int32 nAttrToken, std::string_view sAttrValue ) |
1237 | 0 | { |
1238 | | // delegate to superclass and check for success |
1239 | 0 | XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, sAttrValue); |
1240 | 0 | bValid = m_bDatabaseOK && m_bTableOK; |
1241 | 0 | } |
1242 | | |
1243 | | |
1244 | | // database next field |
1245 | | |
1246 | | |
1247 | | XMLDatabaseNextImportContext::XMLDatabaseNextImportContext( |
1248 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, |
1249 | | const OUString& pServiceName) : |
1250 | 1 | XMLDatabaseFieldImportContext(rImport, rHlp, pServiceName, false), |
1251 | 1 | sPropertyCondition(sAPI_condition), |
1252 | 1 | sTrue(sAPI_true), |
1253 | 1 | bConditionOK(false) |
1254 | 1 | { |
1255 | 1 | } |
1256 | | |
1257 | | XMLDatabaseNextImportContext::XMLDatabaseNextImportContext( |
1258 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) |
1259 | 0 | : XMLDatabaseFieldImportContext(rImport, rHlp, u"DatabaseNextSet"_ustr, false) |
1260 | 0 | , sPropertyCondition(sAPI_condition) |
1261 | 0 | , sTrue(sAPI_true) |
1262 | 0 | , bConditionOK(false) |
1263 | 0 | { |
1264 | 0 | } |
1265 | | |
1266 | | void XMLDatabaseNextImportContext::ProcessAttribute( |
1267 | | sal_Int32 nAttrToken, std::string_view sAttrValue ) |
1268 | 0 | { |
1269 | 0 | if (XML_ELEMENT(TEXT, XML_CONDITION) == nAttrToken) |
1270 | 0 | { |
1271 | 0 | OUString sTmp; |
1272 | 0 | sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrValueQName( |
1273 | 0 | OUString::fromUtf8(sAttrValue), &sTmp ); |
1274 | 0 | if( XML_NAMESPACE_OOOW == nPrefix ) |
1275 | 0 | { |
1276 | 0 | sCondition = sTmp; |
1277 | 0 | bConditionOK = true; |
1278 | 0 | } |
1279 | 0 | else |
1280 | 0 | sCondition = OUString::fromUtf8(sAttrValue); |
1281 | 0 | } |
1282 | 0 | else |
1283 | 0 | { |
1284 | 0 | XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, |
1285 | 0 | sAttrValue); |
1286 | 0 | } |
1287 | |
|
1288 | 0 | bValid = m_bDatabaseOK && m_bTableOK; |
1289 | 0 | } |
1290 | | |
1291 | | void XMLDatabaseNextImportContext::PrepareField( |
1292 | | const Reference<XPropertySet> & xPropertySet) |
1293 | 0 | { |
1294 | 0 | Any aAny; |
1295 | |
|
1296 | 0 | aAny <<= bConditionOK ? sCondition : sTrue; |
1297 | 0 | xPropertySet->setPropertyValue(sPropertyCondition, aAny); |
1298 | |
|
1299 | 0 | XMLDatabaseFieldImportContext::PrepareField(xPropertySet); |
1300 | 0 | } |
1301 | | |
1302 | | |
1303 | | // database select field |
1304 | | |
1305 | | |
1306 | | XMLDatabaseSelectImportContext::XMLDatabaseSelectImportContext( |
1307 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
1308 | 1 | XMLDatabaseNextImportContext(rImport, rHlp, u"DatabaseNumberOfSet"_ustr), |
1309 | 1 | sPropertySetNumber(sAPI_set_number), |
1310 | 1 | nNumber(0), |
1311 | 1 | bNumberOK(false) |
1312 | 1 | { |
1313 | 1 | } |
1314 | | |
1315 | | void XMLDatabaseSelectImportContext::ProcessAttribute( |
1316 | | sal_Int32 nAttrToken, |
1317 | | std::string_view sAttrValue ) |
1318 | 0 | { |
1319 | 0 | if (XML_ELEMENT(TEXT, XML_ROW_NUMBER) == nAttrToken) |
1320 | 0 | { |
1321 | 0 | sal_Int32 nTmp; |
1322 | 0 | if (::sax::Converter::convertNumber( nTmp, sAttrValue |
1323 | 0 | /* , nMin, nMax ??? */ )) |
1324 | 0 | { |
1325 | 0 | nNumber = nTmp; |
1326 | 0 | bNumberOK = true; |
1327 | 0 | } |
1328 | 0 | } |
1329 | 0 | else |
1330 | 0 | { |
1331 | 0 | XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken, sAttrValue); |
1332 | 0 | } |
1333 | |
|
1334 | 0 | bValid = m_bTableOK && m_bDatabaseOK && bNumberOK; |
1335 | 0 | } |
1336 | | |
1337 | | void XMLDatabaseSelectImportContext::PrepareField( |
1338 | | const Reference<XPropertySet> & xPropertySet) |
1339 | 0 | { |
1340 | 0 | xPropertySet->setPropertyValue(sPropertySetNumber, Any(nNumber)); |
1341 | |
|
1342 | 0 | XMLDatabaseNextImportContext::PrepareField(xPropertySet); |
1343 | 0 | } |
1344 | | |
1345 | | |
1346 | | // database display row number field |
1347 | | |
1348 | | |
1349 | | XMLDatabaseNumberImportContext::XMLDatabaseNumberImportContext( |
1350 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
1351 | 6 | XMLDatabaseFieldImportContext(rImport, rHlp, u"DatabaseSetNumber"_ustr, true), |
1352 | 6 | sPropertyNumberingType( |
1353 | 6 | sAPI_numbering_type), |
1354 | 6 | sPropertySetNumber(sAPI_set_number), |
1355 | 6 | sNumberFormat(u"1"_ustr), |
1356 | 6 | sNumberSync(GetXMLToken(XML_FALSE)), |
1357 | 6 | nValue(0), |
1358 | 6 | bValueOK(false) |
1359 | 6 | { |
1360 | 6 | } |
1361 | | |
1362 | | void XMLDatabaseNumberImportContext::ProcessAttribute( |
1363 | | sal_Int32 nAttrToken, |
1364 | | std::string_view sAttrValue ) |
1365 | 0 | { |
1366 | 0 | switch (nAttrToken) |
1367 | 0 | { |
1368 | 0 | case XML_ELEMENT(STYLE, XML_NUM_FORMAT): |
1369 | 0 | sNumberFormat = OUString::fromUtf8(sAttrValue); |
1370 | 0 | break; |
1371 | 0 | case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC): |
1372 | 0 | sNumberSync = OUString::fromUtf8(sAttrValue); |
1373 | 0 | break; |
1374 | 0 | case XML_ELEMENT(TEXT, XML_VALUE_TYPE): |
1375 | 0 | case XML_ELEMENT(OFFICE, XML_VALUE_TYPE): |
1376 | 0 | { |
1377 | 0 | sal_Int32 nTmp; |
1378 | 0 | if (::sax::Converter::convertNumber( nTmp, sAttrValue )) |
1379 | 0 | { |
1380 | 0 | nValue = nTmp; |
1381 | 0 | bValueOK = true; |
1382 | 0 | } |
1383 | 0 | break; |
1384 | 0 | } |
1385 | 0 | default: |
1386 | 0 | XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, |
1387 | 0 | sAttrValue); |
1388 | 0 | break; |
1389 | 0 | } |
1390 | | |
1391 | 0 | bValid = m_bTableOK && m_bDatabaseOK; |
1392 | 0 | } |
1393 | | |
1394 | | void XMLDatabaseNumberImportContext::PrepareField( |
1395 | | const Reference<XPropertySet> & xPropertySet) |
1396 | 0 | { |
1397 | 0 | sal_Int16 nNumType = style::NumberingType::ARABIC; |
1398 | 0 | GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, |
1399 | 0 | sNumberFormat, |
1400 | 0 | sNumberSync ); |
1401 | 0 | xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType)); |
1402 | |
|
1403 | 0 | if (bValueOK) |
1404 | 0 | { |
1405 | 0 | xPropertySet->setPropertyValue(sPropertySetNumber, Any(nValue)); |
1406 | 0 | } |
1407 | |
|
1408 | 0 | XMLDatabaseFieldImportContext::PrepareField(xPropertySet); |
1409 | 0 | } |
1410 | | |
1411 | | |
1412 | | // Simple doc info fields |
1413 | | |
1414 | | |
1415 | | XMLSimpleDocInfoImportContext::XMLSimpleDocInfoImportContext( |
1416 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, |
1417 | | sal_Int32 nElementToken, |
1418 | | bool bContent, bool bAuthor) |
1419 | 747 | : XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nElementToken) ) |
1420 | 747 | , sPropertyFixed(sAPI_is_fixed) |
1421 | 747 | , sPropertyContent(sAPI_content) |
1422 | 747 | , sPropertyAuthor(sAPI_author) |
1423 | 747 | , sPropertyCurrentPresentation(sAPI_current_presentation) |
1424 | 747 | , bFixed(false) |
1425 | 747 | , bHasAuthor(bAuthor) |
1426 | 747 | , bHasContent(bContent) |
1427 | 747 | { |
1428 | 747 | bValid = true; |
1429 | 747 | } |
1430 | | |
1431 | | void XMLSimpleDocInfoImportContext::ProcessAttribute( |
1432 | | sal_Int32 nAttrToken, |
1433 | | std::string_view sAttrValue ) |
1434 | 0 | { |
1435 | 0 | if (XML_ELEMENT(TEXT, XML_FIXED) == nAttrToken) |
1436 | 0 | { |
1437 | 0 | bool bTmp(false); |
1438 | 0 | if (::sax::Converter::convertBool(bTmp, sAttrValue)) |
1439 | 0 | { |
1440 | 0 | bFixed = bTmp; |
1441 | 0 | } |
1442 | 0 | } |
1443 | 0 | else |
1444 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
1445 | 0 | } |
1446 | | |
1447 | | void XMLSimpleDocInfoImportContext::PrepareField( |
1448 | | const Reference<XPropertySet> & rPropertySet) |
1449 | 566 | { |
1450 | | // title field in Calc has no Fixed property |
1451 | 566 | Reference<XPropertySetInfo> xPropertySetInfo(rPropertySet->getPropertySetInfo()); |
1452 | 566 | if (!xPropertySetInfo->hasPropertyByName(sPropertyFixed)) |
1453 | 437 | return; |
1454 | | |
1455 | 129 | Any aAny; |
1456 | 129 | rPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed)); |
1457 | | |
1458 | | // set Content and CurrentPresentation (if fixed) |
1459 | 129 | if (!bFixed) |
1460 | 129 | return; |
1461 | | |
1462 | | // in organizer-mode or styles-only-mode, only force update |
1463 | 0 | if (GetImport().GetTextImport()->IsOrganizerMode() || |
1464 | 0 | GetImport().GetTextImport()->IsStylesOnlyMode() ) |
1465 | 0 | { |
1466 | 0 | ForceUpdate(rPropertySet); |
1467 | 0 | } |
1468 | 0 | else |
1469 | 0 | { |
1470 | | // set content (author, if that's the name) and current |
1471 | | // presentation |
1472 | 0 | aAny <<= GetContent(); |
1473 | |
|
1474 | 0 | if (bFixed && bHasAuthor) |
1475 | 0 | { |
1476 | 0 | rPropertySet->setPropertyValue(sPropertyAuthor, aAny); |
1477 | 0 | } |
1478 | |
|
1479 | 0 | if (bFixed && bHasContent) |
1480 | 0 | { |
1481 | 0 | rPropertySet->setPropertyValue(sPropertyContent, aAny); |
1482 | 0 | } |
1483 | |
|
1484 | 0 | rPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny); |
1485 | 0 | } |
1486 | 0 | } |
1487 | | |
1488 | | OUString XMLSimpleDocInfoImportContext::MapTokenToServiceName( |
1489 | | sal_Int32 nElementToken) |
1490 | 747 | { |
1491 | 747 | OUString pServiceName; |
1492 | | |
1493 | 747 | switch(nElementToken) |
1494 | 747 | { |
1495 | 0 | case XML_ELEMENT(TEXT, XML_INITIAL_CREATOR): |
1496 | 0 | pServiceName = "DocInfo.CreateAuthor"; |
1497 | 0 | break; |
1498 | 0 | case XML_ELEMENT(TEXT, XML_CREATION_DATE): |
1499 | 0 | pServiceName = sAPI_docinfo_create_date_time; |
1500 | 0 | break; |
1501 | 0 | case XML_ELEMENT(TEXT, XML_CREATION_TIME): |
1502 | 0 | pServiceName = sAPI_docinfo_create_date_time; |
1503 | 0 | break; |
1504 | 0 | case XML_ELEMENT(TEXT, XML_DESCRIPTION): |
1505 | 0 | pServiceName = "DocInfo.Description"; |
1506 | 0 | break; |
1507 | 0 | case XML_ELEMENT(TEXT, XML_EDITING_DURATION): |
1508 | 0 | pServiceName = "DocInfo.EditTime"; |
1509 | 0 | break; |
1510 | 0 | case XML_ELEMENT(TEXT, XML_USER_DEFINED): |
1511 | 0 | pServiceName = sAPI_docinfo_custom; |
1512 | 0 | break; |
1513 | 0 | case XML_ELEMENT(TEXT, XML_PRINTED_BY): |
1514 | 0 | pServiceName = "DocInfo.PrintAuthor"; |
1515 | 0 | break; |
1516 | 129 | case XML_ELEMENT(TEXT, XML_PRINT_DATE): |
1517 | 129 | pServiceName = sAPI_docinfo_print_date_time; |
1518 | 129 | break; |
1519 | 7 | case XML_ELEMENT(TEXT, XML_PRINT_TIME): |
1520 | 7 | pServiceName = sAPI_docinfo_print_date_time; |
1521 | 7 | break; |
1522 | 0 | case XML_ELEMENT(TEXT, XML_KEYWORDS): |
1523 | 0 | pServiceName = "DocInfo.KeyWords"; |
1524 | 0 | break; |
1525 | 0 | case XML_ELEMENT(TEXT, XML_SUBJECT): |
1526 | 0 | pServiceName = "DocInfo.Subject"; |
1527 | 0 | break; |
1528 | 0 | case XML_ELEMENT(TEXT, XML_EDITING_CYCLES): |
1529 | 0 | pServiceName = "DocInfo.Revision"; |
1530 | 0 | break; |
1531 | 0 | case XML_ELEMENT(TEXT, XML_CREATOR): |
1532 | 0 | pServiceName = "DocInfo.ChangeAuthor"; |
1533 | 0 | break; |
1534 | 0 | case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE): |
1535 | 0 | pServiceName = sAPI_docinfo_change_date_time; |
1536 | 0 | break; |
1537 | 171 | case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME): |
1538 | 171 | pServiceName = sAPI_docinfo_change_date_time; |
1539 | 171 | break; |
1540 | 440 | case XML_ELEMENT(TEXT, XML_TITLE): |
1541 | 440 | pServiceName = "DocInfo.Title"; |
1542 | 440 | break; |
1543 | 0 | default: |
1544 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElementToken); |
1545 | 0 | assert(false); |
1546 | 747 | } |
1547 | | |
1548 | 747 | return pServiceName; |
1549 | 747 | } |
1550 | | |
1551 | | |
1552 | | // revision field |
1553 | | |
1554 | | constexpr OUStringLiteral sPropertyRevision(u"Revision"); |
1555 | | |
1556 | | XMLRevisionDocInfoImportContext::XMLRevisionDocInfoImportContext( |
1557 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_Int32 nElement) : |
1558 | 0 | XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false) |
1559 | 0 | { |
1560 | 0 | bValid = true; |
1561 | 0 | } |
1562 | | |
1563 | | void XMLRevisionDocInfoImportContext::PrepareField( |
1564 | | const Reference<XPropertySet> & rPropertySet) |
1565 | 0 | { |
1566 | 0 | XMLSimpleDocInfoImportContext::PrepareField(rPropertySet); |
1567 | | |
1568 | | // set revision number |
1569 | | // if fixed, if not in organizer-mode, if not in styles-only-mode |
1570 | 0 | if (!bFixed) |
1571 | 0 | return; |
1572 | | |
1573 | 0 | if ( GetImport().GetTextImport()->IsOrganizerMode() || |
1574 | 0 | GetImport().GetTextImport()->IsStylesOnlyMode() ) |
1575 | 0 | { |
1576 | 0 | ForceUpdate(rPropertySet); |
1577 | 0 | } |
1578 | 0 | else |
1579 | 0 | { |
1580 | 0 | sal_Int32 nTmp; |
1581 | 0 | if (::sax::Converter::convertNumber(nTmp, GetContent())) |
1582 | 0 | { |
1583 | 0 | rPropertySet->setPropertyValue(sPropertyRevision, Any(nTmp)); |
1584 | 0 | } |
1585 | 0 | } |
1586 | 0 | } |
1587 | | |
1588 | | |
1589 | | // DocInfo fields with date/time attributes |
1590 | | |
1591 | | |
1592 | | XMLDateTimeDocInfoImportContext::XMLDateTimeDocInfoImportContext( |
1593 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_Int32 nElement) |
1594 | 307 | : XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false) |
1595 | 307 | , sPropertyNumberFormat(sAPI_number_format) |
1596 | 307 | , sPropertyIsDate(sAPI_is_date) |
1597 | 307 | , sPropertyIsFixedLanguage(sAPI_is_fixed_language) |
1598 | 307 | , nFormat(0) |
1599 | 307 | , bFormatOK(false) |
1600 | 307 | , bIsDate(false) |
1601 | 307 | , bHasDateTime(false) |
1602 | 307 | , bIsDefaultLanguage(true) |
1603 | 307 | { |
1604 | | // we allow processing of EDIT_DURATION here, because import of actual |
1605 | | // is not supported anyway. If it was, we'd need an extra import class |
1606 | | // because times and time durations are presented differently! |
1607 | | |
1608 | 307 | bValid = true; |
1609 | 307 | switch (nElement) |
1610 | 307 | { |
1611 | 0 | case XML_ELEMENT(TEXT, XML_CREATION_DATE): |
1612 | 129 | case XML_ELEMENT(TEXT, XML_PRINT_DATE): |
1613 | 129 | case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE): |
1614 | 129 | bIsDate = true; |
1615 | 129 | bHasDateTime = true; |
1616 | 129 | break; |
1617 | 0 | case XML_ELEMENT(TEXT, XML_CREATION_TIME): |
1618 | 7 | case XML_ELEMENT(TEXT, XML_PRINT_TIME): |
1619 | 178 | case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME): |
1620 | 178 | bIsDate = false; |
1621 | 178 | bHasDateTime = true; |
1622 | 178 | break; |
1623 | 0 | case XML_ELEMENT(TEXT, XML_EDITING_DURATION): |
1624 | 0 | bIsDate = false; |
1625 | 0 | bHasDateTime = false; |
1626 | 0 | break; |
1627 | 0 | default: |
1628 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
1629 | 0 | OSL_FAIL("XMLDateTimeDocInfoImportContext needs date/time doc. fields"); |
1630 | 0 | bValid = false; |
1631 | 0 | break; |
1632 | 307 | } |
1633 | 307 | } |
1634 | | |
1635 | | void XMLDateTimeDocInfoImportContext::ProcessAttribute( |
1636 | | sal_Int32 nAttrToken, |
1637 | | std::string_view sAttrValue ) |
1638 | 127 | { |
1639 | 127 | switch (nAttrToken) |
1640 | 127 | { |
1641 | 127 | case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME): |
1642 | 127 | { |
1643 | 127 | sal_Int32 nKey = GetImportHelper().GetDataStyleKey( |
1644 | 127 | OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage); |
1645 | 127 | if (-1 != nKey) |
1646 | 123 | { |
1647 | 123 | nFormat = nKey; |
1648 | 123 | bFormatOK = true; |
1649 | 123 | } |
1650 | 127 | break; |
1651 | 0 | } |
1652 | 0 | case XML_ELEMENT(TEXT, XML_FIXED): |
1653 | 0 | XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken, |
1654 | 0 | sAttrValue); |
1655 | 0 | break; |
1656 | 0 | default: |
1657 | | // ignore -> we can't set date/time value anyway! |
1658 | 0 | break; |
1659 | 127 | } |
1660 | 127 | } |
1661 | | |
1662 | | void XMLDateTimeDocInfoImportContext::PrepareField( |
1663 | | const Reference<XPropertySet> & xPropertySet) |
1664 | 128 | { |
1665 | | // process fixed and presentation |
1666 | 128 | XMLSimpleDocInfoImportContext::PrepareField(xPropertySet); |
1667 | | |
1668 | 128 | if (bHasDateTime) |
1669 | 128 | { |
1670 | 128 | xPropertySet->setPropertyValue(sPropertyIsDate, Any(bIsDate)); |
1671 | 128 | } |
1672 | | |
1673 | 128 | if (bFormatOK) |
1674 | 123 | { |
1675 | 123 | xPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormat)); |
1676 | | |
1677 | 123 | if( xPropertySet->getPropertySetInfo()-> |
1678 | 123 | hasPropertyByName( sPropertyIsFixedLanguage ) ) |
1679 | 123 | { |
1680 | 123 | bool bIsFixedLanguage = ! bIsDefaultLanguage; |
1681 | 123 | xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) ); |
1682 | 123 | } |
1683 | 123 | } |
1684 | | |
1685 | | // can't set date/time/duration value! Sorry. |
1686 | 128 | } |
1687 | | |
1688 | | |
1689 | | // user defined docinfo fields |
1690 | | |
1691 | | |
1692 | | XMLUserDocInfoImportContext::XMLUserDocInfoImportContext( |
1693 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, |
1694 | | sal_Int32 nElement) : |
1695 | 0 | XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false) |
1696 | 0 | , sPropertyName(sAPI_name) |
1697 | 0 | , sPropertyNumberFormat(sAPI_number_format) |
1698 | 0 | , sPropertyIsFixedLanguage(sAPI_is_fixed_language) |
1699 | 0 | , nFormat(0) |
1700 | 0 | , bFormatOK(false) |
1701 | 0 | , bIsDefaultLanguage( true ) |
1702 | 0 | { |
1703 | 0 | bValid = false; |
1704 | 0 | } |
1705 | | |
1706 | | void XMLUserDocInfoImportContext::ProcessAttribute( |
1707 | | sal_Int32 nAttrToken, |
1708 | | std::string_view sAttrValue ) |
1709 | 0 | { |
1710 | 0 | switch (nAttrToken) |
1711 | 0 | { |
1712 | 0 | case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME): |
1713 | 0 | { |
1714 | 0 | sal_Int32 nKey = GetImportHelper().GetDataStyleKey( |
1715 | 0 | OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage); |
1716 | 0 | if (-1 != nKey) |
1717 | 0 | { |
1718 | 0 | nFormat = nKey; |
1719 | 0 | bFormatOK = true; |
1720 | 0 | } |
1721 | 0 | break; |
1722 | 0 | } |
1723 | 0 | case XML_ELEMENT(TEXT, XML_NAME): |
1724 | 0 | { |
1725 | 0 | if (!bValid) |
1726 | 0 | { |
1727 | 0 | SetServiceName(sAPI_docinfo_custom ); |
1728 | 0 | aName = OUString::fromUtf8(sAttrValue); |
1729 | 0 | bValid = true; |
1730 | 0 | } |
1731 | 0 | break; |
1732 | 0 | } |
1733 | | |
1734 | 0 | default: |
1735 | 0 | XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken, |
1736 | 0 | sAttrValue); |
1737 | 0 | break; |
1738 | 0 | } |
1739 | 0 | } |
1740 | | |
1741 | | void XMLUserDocInfoImportContext::PrepareField( |
1742 | | const css::uno::Reference<css::beans::XPropertySet> & xPropertySet) |
1743 | 0 | { |
1744 | 0 | if ( !aName.isEmpty() ) |
1745 | 0 | { |
1746 | 0 | xPropertySet->setPropertyValue(sPropertyName, Any(aName)); |
1747 | 0 | } |
1748 | 0 | Reference<XPropertySetInfo> xPropertySetInfo( |
1749 | 0 | xPropertySet->getPropertySetInfo()); |
1750 | 0 | if (bFormatOK && |
1751 | 0 | xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat)) |
1752 | 0 | { |
1753 | 0 | xPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormat)); |
1754 | |
|
1755 | 0 | if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) ) |
1756 | 0 | { |
1757 | 0 | bool bIsFixedLanguage = ! bIsDefaultLanguage; |
1758 | 0 | xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) ); |
1759 | 0 | } |
1760 | 0 | } |
1761 | | |
1762 | | // call superclass to handle "fixed" |
1763 | 0 | XMLSimpleDocInfoImportContext::PrepareField(xPropertySet); |
1764 | 0 | } |
1765 | | |
1766 | | |
1767 | | // import hidden paragraph fields |
1768 | | |
1769 | | |
1770 | | XMLHiddenParagraphImportContext::XMLHiddenParagraphImportContext( |
1771 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
1772 | 0 | XMLTextFieldImportContext(rImport, rHlp, u"HiddenParagraph"_ustr), |
1773 | 0 | sPropertyCondition(sAPI_condition), |
1774 | 0 | sPropertyIsHidden(sAPI_is_hidden), |
1775 | 0 | bIsHidden(false) |
1776 | 0 | { |
1777 | 0 | } |
1778 | | |
1779 | | void XMLHiddenParagraphImportContext::ProcessAttribute( |
1780 | | sal_Int32 nAttrToken, |
1781 | | std::string_view sAttrValue ) |
1782 | 0 | { |
1783 | 0 | if ( XML_ELEMENT(TEXT, XML_CONDITION) == nAttrToken) |
1784 | 0 | { |
1785 | 0 | OUString sTmp; |
1786 | 0 | sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrValueQName( |
1787 | 0 | OUString::fromUtf8(sAttrValue), &sTmp ); |
1788 | 0 | if( XML_NAMESPACE_OOOW == nPrefix ) |
1789 | 0 | { |
1790 | 0 | sCondition = sTmp; |
1791 | 0 | bValid = true; |
1792 | 0 | } |
1793 | 0 | else |
1794 | 0 | sCondition = OUString::fromUtf8(sAttrValue); |
1795 | 0 | } |
1796 | 0 | else if ( XML_ELEMENT(TEXT, XML_IS_HIDDEN) == nAttrToken) |
1797 | 0 | { |
1798 | 0 | bool bTmp(false); |
1799 | 0 | if (::sax::Converter::convertBool(bTmp, sAttrValue)) |
1800 | 0 | { |
1801 | 0 | bIsHidden = bTmp; |
1802 | 0 | } |
1803 | 0 | } |
1804 | 0 | else |
1805 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
1806 | 0 | } |
1807 | | |
1808 | | void XMLHiddenParagraphImportContext::PrepareField( |
1809 | | const Reference<XPropertySet> & xPropertySet) |
1810 | 0 | { |
1811 | 0 | xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition)); |
1812 | 0 | xPropertySet->setPropertyValue(sPropertyIsHidden, Any(bIsHidden)); |
1813 | 0 | } |
1814 | | |
1815 | | |
1816 | | // import conditional text (<text:conditional-text>) |
1817 | | |
1818 | | constexpr OUStringLiteral gsPropertyTrueContent(u"TrueContent"); |
1819 | | constexpr OUStringLiteral gsPropertyFalseContent(u"FalseContent"); |
1820 | | constexpr OUStringLiteral gsPropertyIsConditionTrue(u"IsConditionTrue"); |
1821 | | |
1822 | | XMLConditionalTextImportContext::XMLConditionalTextImportContext( |
1823 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
1824 | 1 | XMLTextFieldImportContext(rImport, rHlp, u"ConditionalText"_ustr), |
1825 | 1 | sPropertyCondition(sAPI_condition), |
1826 | 1 | sPropertyCurrentPresentation(sAPI_current_presentation), |
1827 | 1 | bConditionOK(false), |
1828 | 1 | bTrueOK(false), |
1829 | 1 | bFalseOK(false), |
1830 | 1 | bCurrentValue(false) |
1831 | 1 | { |
1832 | 1 | } |
1833 | | |
1834 | | void XMLConditionalTextImportContext::ProcessAttribute( |
1835 | | sal_Int32 nAttrToken, |
1836 | | std::string_view sAttrValue ) |
1837 | 0 | { |
1838 | 0 | switch (nAttrToken) |
1839 | 0 | { |
1840 | 0 | case XML_ELEMENT(TEXT, XML_CONDITION): |
1841 | 0 | { |
1842 | 0 | OUString sTmp; |
1843 | 0 | sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). |
1844 | 0 | GetKeyByAttrValueQName(OUString::fromUtf8(sAttrValue), &sTmp); |
1845 | 0 | if( XML_NAMESPACE_OOOW == nPrefix ) |
1846 | 0 | { |
1847 | 0 | sCondition = sTmp; |
1848 | 0 | bConditionOK = true; |
1849 | 0 | } |
1850 | 0 | else |
1851 | 0 | sCondition = OUString::fromUtf8(sAttrValue); |
1852 | 0 | } |
1853 | 0 | break; |
1854 | 0 | case XML_ELEMENT(TEXT, XML_STRING_VALUE_IF_FALSE): |
1855 | 0 | sFalseContent = OUString::fromUtf8(sAttrValue); |
1856 | 0 | bFalseOK = true; |
1857 | 0 | break; |
1858 | 0 | case XML_ELEMENT(TEXT, XML_STRING_VALUE_IF_TRUE): |
1859 | 0 | sTrueContent = OUString::fromUtf8(sAttrValue); |
1860 | 0 | bTrueOK = true; |
1861 | 0 | break; |
1862 | 0 | case XML_ELEMENT(TEXT, XML_CURRENT_VALUE): |
1863 | 0 | { |
1864 | 0 | bool bTmp(false); |
1865 | 0 | if (::sax::Converter::convertBool(bTmp, sAttrValue)) |
1866 | 0 | { |
1867 | 0 | bCurrentValue = bTmp; |
1868 | 0 | } |
1869 | 0 | break; |
1870 | 0 | } |
1871 | 0 | default: |
1872 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
1873 | 0 | } |
1874 | | |
1875 | 0 | bValid = bConditionOK && bFalseOK && bTrueOK; |
1876 | 0 | } |
1877 | | |
1878 | | void XMLConditionalTextImportContext::PrepareField( |
1879 | | const Reference<XPropertySet> & xPropertySet) |
1880 | 0 | { |
1881 | 0 | xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition)); |
1882 | 0 | xPropertySet->setPropertyValue(gsPropertyFalseContent, Any(sFalseContent)); |
1883 | 0 | xPropertySet->setPropertyValue(gsPropertyTrueContent, Any(sTrueContent)); |
1884 | 0 | xPropertySet->setPropertyValue(gsPropertyIsConditionTrue, Any(bCurrentValue)); |
1885 | 0 | xPropertySet->setPropertyValue(sPropertyCurrentPresentation, Any(GetContent())); |
1886 | 0 | } |
1887 | | |
1888 | | |
1889 | | // hidden text |
1890 | | |
1891 | | |
1892 | | XMLHiddenTextImportContext::XMLHiddenTextImportContext( |
1893 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
1894 | 0 | XMLTextFieldImportContext(rImport, rHlp, u"HiddenText"_ustr), |
1895 | 0 | sPropertyCondition(sAPI_condition), |
1896 | 0 | sPropertyContent(sAPI_content), |
1897 | 0 | sPropertyIsHidden(sAPI_is_hidden), |
1898 | 0 | bConditionOK(false), |
1899 | 0 | bStringOK(false), |
1900 | 0 | bIsHidden(false) |
1901 | 0 | { |
1902 | 0 | } |
1903 | | |
1904 | | void XMLHiddenTextImportContext::ProcessAttribute( |
1905 | | sal_Int32 nAttrToken, |
1906 | | std::string_view sAttrValue ) |
1907 | 0 | { |
1908 | 0 | switch (nAttrToken) |
1909 | 0 | { |
1910 | 0 | case XML_ELEMENT(TEXT, XML_CONDITION): |
1911 | 0 | { |
1912 | 0 | OUString sTmp; |
1913 | 0 | sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). |
1914 | 0 | GetKeyByAttrValueQName(OUString::fromUtf8(sAttrValue), &sTmp); |
1915 | 0 | if( XML_NAMESPACE_OOOW == nPrefix ) |
1916 | 0 | { |
1917 | 0 | sCondition = sTmp; |
1918 | 0 | bConditionOK = true; |
1919 | 0 | } |
1920 | 0 | else |
1921 | 0 | sCondition = OUString::fromUtf8(sAttrValue); |
1922 | 0 | } |
1923 | 0 | break; |
1924 | 0 | case XML_ELEMENT(TEXT, XML_STRING_VALUE): |
1925 | 0 | case XML_ELEMENT(OFFICE, XML_STRING_VALUE): |
1926 | 0 | sString = OUString::fromUtf8(sAttrValue); |
1927 | 0 | bStringOK = true; |
1928 | 0 | break; |
1929 | 0 | case XML_ELEMENT(TEXT, XML_IS_HIDDEN): |
1930 | 0 | { |
1931 | 0 | bool bTmp(false); |
1932 | 0 | if (::sax::Converter::convertBool(bTmp, sAttrValue)) |
1933 | 0 | { |
1934 | 0 | bIsHidden = bTmp; |
1935 | 0 | } |
1936 | 0 | break; |
1937 | 0 | } |
1938 | 0 | default: |
1939 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
1940 | 0 | } |
1941 | | |
1942 | 0 | bValid = bConditionOK && bStringOK; |
1943 | 0 | } |
1944 | | |
1945 | | void XMLHiddenTextImportContext::PrepareField( |
1946 | | const Reference<XPropertySet> & xPropertySet) |
1947 | 0 | { |
1948 | 0 | xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition)); |
1949 | 0 | xPropertySet->setPropertyValue(sPropertyContent, Any(sString)); |
1950 | 0 | xPropertySet->setPropertyValue(sPropertyIsHidden, Any(bIsHidden)); |
1951 | 0 | } |
1952 | | |
1953 | | |
1954 | | // file name fields |
1955 | | |
1956 | | |
1957 | | const SvXMLEnumMapEntry<sal_uInt16> aFilenameDisplayMap[] = |
1958 | | { |
1959 | | { XML_PATH, FilenameDisplayFormat::PATH }, |
1960 | | { XML_NAME, FilenameDisplayFormat::NAME }, |
1961 | | { XML_NAME_AND_EXTENSION, FilenameDisplayFormat::NAME_AND_EXT }, |
1962 | | { XML_FULL, FilenameDisplayFormat::FULL }, |
1963 | | { XML_TOKEN_INVALID, 0 } |
1964 | | }; |
1965 | | |
1966 | | XMLFileNameImportContext::XMLFileNameImportContext( |
1967 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
1968 | 316 | XMLTextFieldImportContext(rImport, rHlp, u"FileName"_ustr), |
1969 | 316 | sPropertyFixed(sAPI_is_fixed), |
1970 | 316 | sPropertyFileFormat(sAPI_file_format), |
1971 | 316 | sPropertyCurrentPresentation( |
1972 | 316 | sAPI_current_presentation), |
1973 | 316 | nFormat(FilenameDisplayFormat::FULL), |
1974 | 316 | bFixed(false) |
1975 | 316 | { |
1976 | 316 | bValid = true; |
1977 | 316 | } |
1978 | | |
1979 | | void XMLFileNameImportContext::ProcessAttribute( |
1980 | | sal_Int32 nAttrToken, |
1981 | | std::string_view sAttrValue ) |
1982 | 133 | { |
1983 | 133 | switch (nAttrToken) |
1984 | 133 | { |
1985 | 0 | case XML_ELEMENT(TEXT, XML_FIXED): |
1986 | 0 | { |
1987 | 0 | bool bTmp(false); |
1988 | 0 | if (::sax::Converter::convertBool(bTmp, sAttrValue)) |
1989 | 0 | { |
1990 | 0 | bFixed = bTmp; |
1991 | 0 | } |
1992 | 0 | break; |
1993 | 0 | } |
1994 | 133 | case XML_ELEMENT(TEXT, XML_DISPLAY): |
1995 | 133 | { |
1996 | 133 | sal_uInt16 nTmp; |
1997 | 133 | if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, |
1998 | 133 | aFilenameDisplayMap)) |
1999 | 132 | { |
2000 | 132 | nFormat = nTmp; |
2001 | 132 | } |
2002 | 133 | break; |
2003 | 0 | } |
2004 | 0 | default: |
2005 | | // unknown attribute: ignore |
2006 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2007 | 0 | break; |
2008 | 133 | } |
2009 | 133 | } |
2010 | | |
2011 | | void XMLFileNameImportContext::PrepareField( |
2012 | | const Reference<XPropertySet> & xPropertySet) |
2013 | 315 | { |
2014 | | // properties are optional |
2015 | 315 | Reference<XPropertySetInfo> xPropertySetInfo( |
2016 | 315 | xPropertySet->getPropertySetInfo()); |
2017 | | |
2018 | 315 | if (xPropertySetInfo->hasPropertyByName(sPropertyFixed)) |
2019 | 132 | { |
2020 | 132 | xPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed)); |
2021 | 132 | } |
2022 | | |
2023 | 315 | if (xPropertySetInfo->hasPropertyByName(sPropertyFileFormat)) |
2024 | 315 | { |
2025 | 315 | xPropertySet->setPropertyValue(sPropertyFileFormat, Any(nFormat)); |
2026 | 315 | } |
2027 | | |
2028 | 315 | if (xPropertySetInfo->hasPropertyByName(sPropertyCurrentPresentation)) |
2029 | 132 | { |
2030 | 132 | xPropertySet->setPropertyValue(sPropertyCurrentPresentation, Any(GetContent())); |
2031 | 132 | } |
2032 | 315 | } |
2033 | | |
2034 | | |
2035 | | // template name field |
2036 | | |
2037 | | |
2038 | | const SvXMLEnumMapEntry<sal_uInt16> aTemplateDisplayMap[] = |
2039 | | { |
2040 | | { XML_FULL, TemplateDisplayFormat::FULL }, |
2041 | | { XML_PATH, TemplateDisplayFormat::PATH }, |
2042 | | { XML_NAME, TemplateDisplayFormat::NAME }, |
2043 | | { XML_NAME_AND_EXTENSION, TemplateDisplayFormat::NAME_AND_EXT }, |
2044 | | { XML_AREA, TemplateDisplayFormat::AREA }, |
2045 | | { XML_TITLE, TemplateDisplayFormat::TITLE }, |
2046 | | { XML_TOKEN_INVALID, 0 } |
2047 | | }; |
2048 | | |
2049 | | |
2050 | | XMLTemplateNameImportContext::XMLTemplateNameImportContext( |
2051 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
2052 | 0 | XMLTextFieldImportContext(rImport, rHlp, u"TemplateName"_ustr), |
2053 | 0 | sPropertyFileFormat(sAPI_file_format), |
2054 | 0 | nFormat(TemplateDisplayFormat::FULL) |
2055 | 0 | { |
2056 | 0 | bValid = true; |
2057 | 0 | } |
2058 | | |
2059 | | void XMLTemplateNameImportContext::ProcessAttribute( |
2060 | | sal_Int32 nAttrToken, |
2061 | | std::string_view sAttrValue ) |
2062 | 0 | { |
2063 | 0 | switch (nAttrToken) |
2064 | 0 | { |
2065 | 0 | case XML_ELEMENT(TEXT, XML_DISPLAY): |
2066 | 0 | { |
2067 | 0 | sal_uInt16 nTmp; |
2068 | 0 | if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, |
2069 | 0 | aTemplateDisplayMap)) |
2070 | 0 | { |
2071 | 0 | nFormat = nTmp; |
2072 | 0 | } |
2073 | 0 | break; |
2074 | 0 | } |
2075 | 0 | default: |
2076 | | // unknown attribute: ignore |
2077 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2078 | 0 | break; |
2079 | 0 | } |
2080 | 0 | } |
2081 | | |
2082 | | void XMLTemplateNameImportContext::PrepareField( |
2083 | | const Reference<XPropertySet> & xPropertySet) |
2084 | 0 | { |
2085 | 0 | xPropertySet->setPropertyValue(sPropertyFileFormat, Any(nFormat)); |
2086 | 0 | } |
2087 | | |
2088 | | |
2089 | | // import chapter fields |
2090 | | |
2091 | | |
2092 | | const SvXMLEnumMapEntry<sal_uInt16> aChapterDisplayMap[] = |
2093 | | { |
2094 | | { XML_NAME, ChapterFormat::NAME }, |
2095 | | { XML_NUMBER, ChapterFormat::NUMBER }, |
2096 | | { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER }, |
2097 | | { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX }, |
2098 | | { XML_PLAIN_NUMBER, ChapterFormat::DIGIT }, |
2099 | | { XML_TOKEN_INVALID, 0 } |
2100 | | }; |
2101 | | |
2102 | | constexpr OUStringLiteral gsPropertyChapterFormat(u"ChapterFormat"); |
2103 | | constexpr OUStringLiteral gsPropertyLevel(u"Level"); |
2104 | | |
2105 | | XMLChapterImportContext::XMLChapterImportContext( |
2106 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
2107 | 1 | XMLTextFieldImportContext(rImport, rHlp, u"Chapter"_ustr), |
2108 | 1 | nFormat(ChapterFormat::NAME_NUMBER), |
2109 | 1 | nLevel(0) |
2110 | 1 | { |
2111 | 1 | bValid = true; |
2112 | 1 | } |
2113 | | |
2114 | | void XMLChapterImportContext::ProcessAttribute( |
2115 | | sal_Int32 nAttrToken, |
2116 | | std::string_view sAttrValue ) |
2117 | 0 | { |
2118 | 0 | switch (nAttrToken) |
2119 | 0 | { |
2120 | 0 | case XML_ELEMENT(TEXT, XML_DISPLAY): |
2121 | 0 | { |
2122 | 0 | sal_uInt16 nTmp; |
2123 | 0 | if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue, |
2124 | 0 | aChapterDisplayMap)) |
2125 | 0 | { |
2126 | 0 | nFormat = static_cast<sal_Int16>(nTmp); |
2127 | 0 | } |
2128 | 0 | break; |
2129 | 0 | } |
2130 | 0 | case XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL): |
2131 | 0 | { |
2132 | 0 | sal_Int32 nTmp; |
2133 | 0 | if (::sax::Converter::convertNumber( |
2134 | 0 | nTmp, sAttrValue, 1, |
2135 | 0 | GetImport().GetTextImport()->GetChapterNumbering()->getCount() |
2136 | 0 | )) |
2137 | 0 | { |
2138 | | // API numbers 0..9, we number 1..10 |
2139 | 0 | nLevel = static_cast<sal_Int8>(nTmp); |
2140 | 0 | nLevel--; |
2141 | 0 | } |
2142 | 0 | break; |
2143 | 0 | } |
2144 | 0 | default: |
2145 | | // unknown attribute: ignore |
2146 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2147 | 0 | break; |
2148 | 0 | } |
2149 | 0 | } |
2150 | | |
2151 | | void XMLChapterImportContext::PrepareField( |
2152 | | const Reference<XPropertySet> & xPropertySet) |
2153 | 0 | { |
2154 | 0 | xPropertySet->setPropertyValue(gsPropertyChapterFormat, Any(nFormat)); |
2155 | 0 | xPropertySet->setPropertyValue(gsPropertyLevel, Any(nLevel)); |
2156 | 0 | } |
2157 | | |
2158 | | |
2159 | | // counting fields |
2160 | | |
2161 | | |
2162 | | XMLCountFieldImportContext::XMLCountFieldImportContext( |
2163 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, |
2164 | | sal_Int32 nElement) : |
2165 | 10.8k | XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nElement)), |
2166 | 10.8k | sPropertyNumberingType( |
2167 | 10.8k | sAPI_numbering_type), |
2168 | 10.8k | bNumberFormatOK(false) |
2169 | 10.8k | { |
2170 | 10.8k | bValid = true; |
2171 | 10.8k | } |
2172 | | |
2173 | | void XMLCountFieldImportContext::ProcessAttribute( |
2174 | | sal_Int32 nAttrToken, |
2175 | | std::string_view sAttrValue ) |
2176 | 0 | { |
2177 | 0 | switch (nAttrToken) |
2178 | 0 | { |
2179 | 0 | case XML_ELEMENT(STYLE, XML_NUM_FORMAT): |
2180 | 0 | sNumberFormat = OUString::fromUtf8(sAttrValue); |
2181 | 0 | bNumberFormatOK = true; |
2182 | 0 | break; |
2183 | 0 | case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC): |
2184 | 0 | sLetterSync = OUString::fromUtf8(sAttrValue); |
2185 | 0 | break; |
2186 | 0 | default: |
2187 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2188 | 0 | } |
2189 | 0 | } |
2190 | | |
2191 | | void XMLCountFieldImportContext::PrepareField( |
2192 | | const Reference<XPropertySet> & xPropertySet) |
2193 | 10.7k | { |
2194 | | // properties optional |
2195 | | // (only page count, but do for all to save common implementation) |
2196 | | |
2197 | 10.7k | if (!xPropertySet->getPropertySetInfo()-> |
2198 | 10.7k | hasPropertyByName(sPropertyNumberingType)) |
2199 | 10.2k | return; |
2200 | | |
2201 | 525 | sal_Int16 nNumType; |
2202 | 525 | if( bNumberFormatOK ) |
2203 | 0 | { |
2204 | 0 | nNumType= style::NumberingType::ARABIC; |
2205 | 0 | GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, |
2206 | 0 | sNumberFormat, |
2207 | 0 | sLetterSync ); |
2208 | 0 | } |
2209 | 525 | else |
2210 | 525 | nNumType = style::NumberingType::PAGE_DESCRIPTOR; |
2211 | 525 | xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType)); |
2212 | 525 | } |
2213 | | |
2214 | | OUString XMLCountFieldImportContext::MapTokenToServiceName( |
2215 | | sal_Int32 nElement) |
2216 | 10.8k | { |
2217 | 10.8k | OUString pServiceName; |
2218 | | |
2219 | 10.8k | switch (nElement) |
2220 | 10.8k | { |
2221 | 0 | case XML_ELEMENT(TEXT, XML_WORD_COUNT): |
2222 | 0 | pServiceName = "WordCount"; |
2223 | 0 | break; |
2224 | 0 | case XML_ELEMENT(TEXT, XML_PARAGRAPH_COUNT): |
2225 | 0 | pServiceName = "ParagraphCount"; |
2226 | 0 | break; |
2227 | 0 | case XML_ELEMENT(TEXT, XML_TABLE_COUNT): |
2228 | 0 | pServiceName = "TableCount"; |
2229 | 0 | break; |
2230 | 0 | case XML_ELEMENT(TEXT, XML_CHARACTER_COUNT): |
2231 | 0 | pServiceName = "CharacterCount"; |
2232 | 0 | break; |
2233 | 0 | case XML_ELEMENT(TEXT, XML_IMAGE_COUNT): |
2234 | 0 | pServiceName = "GraphicObjectCount"; |
2235 | 0 | break; |
2236 | 0 | case XML_ELEMENT(TEXT, XML_OBJECT_COUNT): |
2237 | 0 | pServiceName = "EmbeddedObjectCount"; |
2238 | 0 | break; |
2239 | 10.8k | case XML_ELEMENT(TEXT, XML_PAGE_COUNT): |
2240 | 10.8k | pServiceName = "PageCount"; |
2241 | 10.8k | break; |
2242 | 0 | case XML_ELEMENT(LO_EXT, XML_PAGE_COUNT_RANGE): |
2243 | 0 | pServiceName = "PageCountRange"; |
2244 | 0 | break; |
2245 | 0 | default: |
2246 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
2247 | 0 | assert(false); |
2248 | 10.8k | } |
2249 | | |
2250 | 10.8k | return pServiceName; |
2251 | 10.8k | } |
2252 | | |
2253 | | |
2254 | | // page variable import |
2255 | | |
2256 | | |
2257 | | XMLPageVarGetFieldImportContext::XMLPageVarGetFieldImportContext( |
2258 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
2259 | 0 | XMLTextFieldImportContext(rImport, rHlp, u"ReferencePageGet"_ustr), |
2260 | 0 | bNumberFormatOK(false) |
2261 | 0 | { |
2262 | 0 | bValid = true; |
2263 | 0 | } |
2264 | | |
2265 | | void XMLPageVarGetFieldImportContext::ProcessAttribute( |
2266 | | sal_Int32 nAttrToken, |
2267 | | std::string_view sAttrValue ) |
2268 | 0 | { |
2269 | 0 | switch (nAttrToken) |
2270 | 0 | { |
2271 | 0 | case XML_ELEMENT(STYLE, XML_NUM_FORMAT): |
2272 | 0 | sNumberFormat = OUString::fromUtf8(sAttrValue); |
2273 | 0 | bNumberFormatOK = true; |
2274 | 0 | break; |
2275 | 0 | case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC): |
2276 | 0 | sLetterSync = OUString::fromUtf8(sAttrValue); |
2277 | 0 | break; |
2278 | 0 | default: |
2279 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2280 | 0 | } |
2281 | 0 | } |
2282 | | |
2283 | | void XMLPageVarGetFieldImportContext::PrepareField( |
2284 | | const Reference<XPropertySet> & xPropertySet) |
2285 | 0 | { |
2286 | 0 | sal_Int16 nNumType; |
2287 | 0 | if( bNumberFormatOK ) |
2288 | 0 | { |
2289 | 0 | nNumType= style::NumberingType::ARABIC; |
2290 | 0 | GetImport().GetMM100UnitConverter().convertNumFormat( nNumType, |
2291 | 0 | sNumberFormat, |
2292 | 0 | sLetterSync ); |
2293 | 0 | } |
2294 | 0 | else |
2295 | 0 | nNumType = style::NumberingType::PAGE_DESCRIPTOR; |
2296 | 0 | xPropertySet->setPropertyValue(sAPI_numbering_type, Any(nNumType)); |
2297 | | |
2298 | | // display old content (#96657#) |
2299 | 0 | xPropertySet->setPropertyValue( sAPI_current_presentation, Any(GetContent()) ); |
2300 | 0 | } |
2301 | | |
2302 | | |
2303 | | // page variable set fields |
2304 | | |
2305 | | |
2306 | | XMLPageVarSetFieldImportContext::XMLPageVarSetFieldImportContext( |
2307 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
2308 | 0 | XMLTextFieldImportContext(rImport, rHlp, u"ReferencePageSet"_ustr), |
2309 | 0 | nAdjust(0), |
2310 | 0 | bActive(true) |
2311 | 0 | { |
2312 | 0 | bValid = true; |
2313 | 0 | } |
2314 | | |
2315 | | void XMLPageVarSetFieldImportContext::ProcessAttribute( |
2316 | | sal_Int32 nAttrToken, |
2317 | | std::string_view sAttrValue ) |
2318 | 0 | { |
2319 | 0 | switch (nAttrToken) |
2320 | 0 | { |
2321 | 0 | case XML_ELEMENT(TEXT, XML_ACTIVE): |
2322 | 0 | { |
2323 | 0 | bool bTmp(false); |
2324 | 0 | if (::sax::Converter::convertBool(bTmp, sAttrValue)) |
2325 | 0 | { |
2326 | 0 | bActive = bTmp; |
2327 | 0 | } |
2328 | 0 | break; |
2329 | 0 | } |
2330 | 0 | case XML_ELEMENT(TEXT, XML_PAGE_ADJUST): |
2331 | 0 | { |
2332 | 0 | sal_Int32 nTmp(0); |
2333 | 0 | if (::sax::Converter::convertNumber(nTmp, sAttrValue)) |
2334 | 0 | { |
2335 | 0 | nAdjust = static_cast<sal_Int16>(nTmp); |
2336 | 0 | } |
2337 | 0 | break; |
2338 | 0 | } |
2339 | 0 | default: |
2340 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2341 | 0 | break; |
2342 | 0 | } |
2343 | 0 | } |
2344 | | |
2345 | | void XMLPageVarSetFieldImportContext::PrepareField( |
2346 | | const Reference<XPropertySet> & xPropertySet) |
2347 | 0 | { |
2348 | 0 | xPropertySet->setPropertyValue(u"On"_ustr, Any(bActive)); |
2349 | 0 | xPropertySet->setPropertyValue(sAPI_offset, Any(nAdjust)); |
2350 | 0 | } |
2351 | | |
2352 | | |
2353 | | // macro fields |
2354 | | |
2355 | | |
2356 | | XMLMacroFieldImportContext::XMLMacroFieldImportContext( |
2357 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
2358 | 3 | XMLTextFieldImportContext(rImport, rHlp, u"Macro"_ustr), |
2359 | 3 | bDescriptionOK(false) |
2360 | 3 | { |
2361 | 3 | } |
2362 | | |
2363 | | css::uno::Reference< css::xml::sax::XFastContextHandler > XMLMacroFieldImportContext::createFastChildContext( |
2364 | | sal_Int32 nElement, |
2365 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) |
2366 | 7 | { |
2367 | 7 | if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) ) |
2368 | 0 | { |
2369 | | // create events context and remember it! |
2370 | 0 | xEventContext = new XMLEventsImportContext( GetImport() ); |
2371 | 0 | bValid = true; |
2372 | 0 | return xEventContext; |
2373 | 0 | } |
2374 | 7 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
2375 | | |
2376 | 7 | return nullptr; |
2377 | 7 | } |
2378 | | |
2379 | | void XMLMacroFieldImportContext::ProcessAttribute( |
2380 | | sal_Int32 nAttrToken, |
2381 | | std::string_view sAttrValue ) |
2382 | 0 | { |
2383 | 0 | switch (nAttrToken) |
2384 | 0 | { |
2385 | 0 | case XML_ELEMENT(TEXT, XML_DESCRIPTION): |
2386 | 0 | sDescription = OUString::fromUtf8(sAttrValue); |
2387 | 0 | bDescriptionOK = true; |
2388 | 0 | break; |
2389 | 0 | case XML_ELEMENT(TEXT, XML_NAME): |
2390 | 0 | sMacro = OUString::fromUtf8(sAttrValue); |
2391 | 0 | bValid = true; |
2392 | 0 | break; |
2393 | 0 | default: |
2394 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2395 | 0 | } |
2396 | 0 | } |
2397 | | |
2398 | | void XMLMacroFieldImportContext::PrepareField( |
2399 | | const Reference<XPropertySet> & xPropertySet) |
2400 | 0 | { |
2401 | 0 | Any aAny; |
2402 | 0 | aAny <<= (bDescriptionOK ? sDescription : GetContent()); |
2403 | 0 | xPropertySet->setPropertyValue(sAPI_hint, aAny); |
2404 | | |
2405 | | // if we have an events child element, we'll look for the OnClick |
2406 | | // event if not, it may be an old (pre-638i) document. Then, we'll |
2407 | | // have to look at the name attribute. |
2408 | 0 | OUString sMacroName; |
2409 | 0 | OUString sLibraryName; |
2410 | 0 | OUString sScriptURL; |
2411 | |
|
2412 | 0 | if ( xEventContext.is() ) |
2413 | 0 | { |
2414 | | // get event sequence |
2415 | 0 | XMLEventsImportContext* pEvents = xEventContext.get(); |
2416 | 0 | Sequence<PropertyValue> aValues; |
2417 | 0 | pEvents->GetEventSequence( u"OnClick"_ustr, aValues ); |
2418 | |
|
2419 | 0 | for (const auto& rValue : aValues) |
2420 | 0 | { |
2421 | 0 | if ( rValue.Name == "ScriptType" ) |
2422 | 0 | { |
2423 | | // ignore ScriptType |
2424 | 0 | } |
2425 | 0 | else if ( rValue.Name == "Library" ) |
2426 | 0 | { |
2427 | 0 | rValue.Value >>= sLibraryName; |
2428 | 0 | } |
2429 | 0 | else if ( rValue.Name == "MacroName" ) |
2430 | 0 | { |
2431 | 0 | rValue.Value >>= sMacroName; |
2432 | 0 | } |
2433 | 0 | if ( rValue.Name == "Script" ) |
2434 | 0 | { |
2435 | 0 | rValue.Value >>= sScriptURL; |
2436 | 0 | } |
2437 | 0 | } |
2438 | 0 | } |
2439 | 0 | else |
2440 | 0 | { |
2441 | | // disassemble old-style macro-name: Everything before the |
2442 | | // third-last dot is the library |
2443 | 0 | sal_Int32 nPos = sMacro.getLength() + 1; // the loop starts with nPos-- |
2444 | 0 | const sal_Unicode* pBuf = sMacro.getStr(); |
2445 | 0 | for( sal_Int32 i = 0; (i < 3) && (nPos > 0); i++ ) |
2446 | 0 | { |
2447 | 0 | nPos--; |
2448 | 0 | while ( (pBuf[nPos] != '.') && (nPos > 0) ) |
2449 | 0 | nPos--; |
2450 | 0 | } |
2451 | |
|
2452 | 0 | if (nPos > 0) |
2453 | 0 | { |
2454 | 0 | sLibraryName = sMacro.copy(0, nPos); |
2455 | 0 | sMacroName = sMacro.copy(nPos+1); |
2456 | 0 | } |
2457 | 0 | else |
2458 | 0 | sMacroName = sMacro; |
2459 | 0 | } |
2460 | |
|
2461 | 0 | xPropertySet->setPropertyValue(u"ScriptURL"_ustr, Any(sScriptURL)); |
2462 | 0 | xPropertySet->setPropertyValue(u"MacroName"_ustr, Any(sMacroName)); |
2463 | 0 | xPropertySet->setPropertyValue(u"MacroLibrary"_ustr, Any(sLibraryName)); |
2464 | 0 | } |
2465 | | |
2466 | | |
2467 | | // reference field import |
2468 | | |
2469 | | |
2470 | | XMLReferenceFieldImportContext::XMLReferenceFieldImportContext( |
2471 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp, |
2472 | | sal_Int32 nToken) |
2473 | 1 | : XMLTextFieldImportContext(rImport, rHlp, u"GetReference"_ustr) |
2474 | 1 | , nElementToken(nToken) |
2475 | 1 | , nSource(0) |
2476 | 1 | , nType(ReferenceFieldPart::PAGE_DESC) |
2477 | 1 | , nFlags(0) |
2478 | 1 | , bNameOK(false) |
2479 | 1 | , bTypeOK(false) |
2480 | 1 | { |
2481 | 1 | } |
2482 | | |
2483 | | SvXMLEnumMapEntry<sal_uInt16> const lcl_aReferenceTypeTokenMap[] = |
2484 | | { |
2485 | | { XML_PAGE, ReferenceFieldPart::PAGE}, |
2486 | | { XML_CHAPTER, ReferenceFieldPart::CHAPTER }, |
2487 | | { XML_TEXT, ReferenceFieldPart::TEXT }, |
2488 | | { XML_DIRECTION, ReferenceFieldPart::UP_DOWN }, |
2489 | | { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER }, |
2490 | | { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION }, |
2491 | | { XML_VALUE, ReferenceFieldPart::ONLY_SEQUENCE_NUMBER }, |
2492 | | // Core implementation for direct cross-references (#i81002#) |
2493 | | { XML_NUMBER, ReferenceFieldPart::NUMBER }, |
2494 | | { XML_NUMBER_NO_SUPERIOR, ReferenceFieldPart::NUMBER_NO_CONTEXT }, |
2495 | | { XML_NUMBER_ALL_SUPERIOR, ReferenceFieldPart::NUMBER_FULL_CONTEXT }, |
2496 | | { XML_TOKEN_INVALID, 0 } |
2497 | | }; |
2498 | | |
2499 | | void XMLReferenceFieldImportContext::startFastElement( |
2500 | | sal_Int32 nElement, |
2501 | | const Reference<XFastAttributeList> & xAttrList) |
2502 | 1 | { |
2503 | 1 | bTypeOK = true; |
2504 | 1 | switch (nElementToken) |
2505 | 1 | { |
2506 | 0 | case XML_ELEMENT(TEXT, XML_REFERENCE_REF): |
2507 | 0 | nSource = ReferenceFieldSource::REFERENCE_MARK; |
2508 | 0 | break; |
2509 | 0 | case XML_ELEMENT(TEXT, XML_BOOKMARK_REF): |
2510 | 0 | nSource = ReferenceFieldSource::BOOKMARK; |
2511 | 0 | break; |
2512 | 0 | case XML_ELEMENT(TEXT, XML_NOTE_REF): |
2513 | 0 | nSource = ReferenceFieldSource::FOOTNOTE; |
2514 | 0 | break; |
2515 | 1 | case XML_ELEMENT(TEXT, XML_SEQUENCE_REF): |
2516 | 1 | nSource = ReferenceFieldSource::SEQUENCE_FIELD; |
2517 | 1 | break; |
2518 | 0 | case XML_ELEMENT(TEXT, XML_STYLE_REF): |
2519 | 0 | case XML_ELEMENT(LO_EXT, XML_STYLE_REF): |
2520 | 0 | nSource = ReferenceFieldSource::STYLE; |
2521 | 0 | break; |
2522 | 0 | default: |
2523 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElementToken); |
2524 | 0 | bTypeOK = false; |
2525 | 0 | break; |
2526 | 1 | } |
2527 | | |
2528 | 1 | XMLTextFieldImportContext::startFastElement(nElement, xAttrList); |
2529 | 1 | } |
2530 | | |
2531 | | |
2532 | | void XMLReferenceFieldImportContext::ProcessAttribute( |
2533 | | sal_Int32 nAttrToken, |
2534 | | std::string_view sAttrValue ) |
2535 | 0 | { |
2536 | 0 | switch (nAttrToken) |
2537 | 0 | { |
2538 | 0 | case XML_ELEMENT(TEXT, XML_NOTE_CLASS): |
2539 | 0 | if( IsXMLToken( sAttrValue, XML_ENDNOTE ) ) |
2540 | 0 | nSource = ReferenceFieldSource::ENDNOTE; |
2541 | 0 | break; |
2542 | 0 | case XML_ELEMENT(TEXT, XML_REF_NAME): |
2543 | 0 | sName = OUString::fromUtf8(sAttrValue); |
2544 | 0 | bNameOK = true; |
2545 | 0 | break; |
2546 | 0 | case XML_ELEMENT(TEXT, XML_REFERENCE_FORMAT): |
2547 | 0 | { |
2548 | 0 | sal_uInt16 nToken; |
2549 | 0 | if (SvXMLUnitConverter::convertEnum(nToken, sAttrValue, |
2550 | 0 | lcl_aReferenceTypeTokenMap)) |
2551 | 0 | { |
2552 | 0 | nType = nToken; |
2553 | 0 | } |
2554 | | |
2555 | | // check for sequence-only-attributes |
2556 | 0 | if ( (XML_ELEMENT(TEXT, XML_SEQUENCE_REF) != nElementToken) && |
2557 | 0 | ( (nType == ReferenceFieldPart::CATEGORY_AND_NUMBER) || |
2558 | 0 | (nType == ReferenceFieldPart::ONLY_CAPTION) || |
2559 | 0 | (nType == ReferenceFieldPart::ONLY_SEQUENCE_NUMBER) ) ) |
2560 | 0 | { |
2561 | 0 | nType = ReferenceFieldPart::PAGE_DESC; |
2562 | 0 | } |
2563 | |
|
2564 | 0 | break; |
2565 | 0 | } |
2566 | 0 | case XML_ELEMENT(LO_EXT, XML_REFERENCE_LANGUAGE): |
2567 | 0 | case XML_ELEMENT(TEXT, XML_REFERENCE_LANGUAGE): |
2568 | 0 | sLanguage = OUString::fromUtf8(sAttrValue); |
2569 | 0 | break; |
2570 | 0 | case XML_ELEMENT(LO_EXT, XML_REFERENCE_HIDE_NON_NUMERICAL): |
2571 | 0 | case XML_ELEMENT(TEXT, XML_REFERENCE_HIDE_NON_NUMERICAL): |
2572 | 0 | if (OUString::fromUtf8(sAttrValue).toBoolean()) |
2573 | 0 | nFlags |= REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL; |
2574 | 0 | break; |
2575 | 0 | case XML_ELEMENT(LO_EXT, XML_REFERENCE_FROM_BOTTOM): |
2576 | 0 | case XML_ELEMENT(TEXT, XML_REFERENCE_FROM_BOTTOM): |
2577 | 0 | if (OUString::fromUtf8(sAttrValue).toBoolean()) |
2578 | 0 | nFlags |= REFFLDFLAG_STYLE_FROM_BOTTOM; |
2579 | 0 | break; |
2580 | 0 | default: |
2581 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2582 | 0 | } |
2583 | | |
2584 | | // bValid: we need proper element type and name |
2585 | 0 | bValid = bTypeOK && bNameOK; |
2586 | 0 | } |
2587 | | |
2588 | | void XMLReferenceFieldImportContext::PrepareField( |
2589 | | const Reference<XPropertySet> & xPropertySet) |
2590 | 0 | { |
2591 | 0 | xPropertySet->setPropertyValue(u"ReferenceFieldPart"_ustr, Any(nType)); |
2592 | |
|
2593 | 0 | xPropertySet->setPropertyValue(u"ReferenceFieldSource"_ustr, Any(nSource)); |
2594 | |
|
2595 | 0 | xPropertySet->setPropertyValue(u"ReferenceFieldLanguage"_ustr, Any(sLanguage)); |
2596 | 0 | switch (nElementToken) |
2597 | 0 | { |
2598 | 0 | case XML_ELEMENT(TEXT, XML_REFERENCE_REF): |
2599 | 0 | case XML_ELEMENT(TEXT, XML_BOOKMARK_REF): |
2600 | 0 | case XML_ELEMENT(TEXT, XML_STYLE_REF): |
2601 | 0 | case XML_ELEMENT(LO_EXT, XML_STYLE_REF): |
2602 | 0 | xPropertySet->setPropertyValue(u"SourceName"_ustr, Any(sName)); |
2603 | 0 | xPropertySet->setPropertyValue(u"ReferenceFieldFlags"_ustr, Any(nFlags)); |
2604 | 0 | break; |
2605 | | |
2606 | 0 | case XML_ELEMENT(TEXT, XML_NOTE_REF): |
2607 | 0 | GetImportHelper().ProcessFootnoteReference(sName, xPropertySet); |
2608 | 0 | break; |
2609 | | |
2610 | 0 | case XML_ELEMENT(TEXT, XML_SEQUENCE_REF): |
2611 | 0 | GetImportHelper().ProcessSequenceReference(sName, xPropertySet); |
2612 | 0 | break; |
2613 | 0 | } |
2614 | | |
2615 | 0 | xPropertySet->setPropertyValue(sAPI_current_presentation, Any(GetContent())); |
2616 | 0 | } |
2617 | | |
2618 | | |
2619 | | // field declarations container |
2620 | | |
2621 | | XMLDdeFieldDeclsImportContext::XMLDdeFieldDeclsImportContext(SvXMLImport& rImport) : |
2622 | 0 | SvXMLImportContext(rImport) |
2623 | 0 | { |
2624 | 0 | } |
2625 | | |
2626 | | css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDdeFieldDeclsImportContext::createFastChildContext( |
2627 | | sal_Int32 nElement, |
2628 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) |
2629 | 0 | { |
2630 | 0 | if ( nElement == XML_ELEMENT(TEXT, XML_DDE_CONNECTION_DECL) ) |
2631 | 0 | { |
2632 | 0 | return new XMLDdeFieldDeclImportContext(GetImport()); |
2633 | 0 | } |
2634 | 0 | else |
2635 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
2636 | 0 | return nullptr; |
2637 | 0 | } |
2638 | | |
2639 | | |
2640 | | // import dde field declaration |
2641 | | |
2642 | | |
2643 | | XMLDdeFieldDeclImportContext::XMLDdeFieldDeclImportContext(SvXMLImport& rImport) |
2644 | 0 | : SvXMLImportContext(rImport) |
2645 | 0 | { |
2646 | 0 | } |
2647 | | |
2648 | | void XMLDdeFieldDeclImportContext::startFastElement( |
2649 | | sal_Int32 /*nElement*/, |
2650 | | const Reference<XFastAttributeList> & xAttrList) |
2651 | 0 | { |
2652 | 0 | OUString sName; |
2653 | 0 | OUString sCommandApplication; |
2654 | 0 | OUString sCommandTopic; |
2655 | 0 | OUString sCommandItem; |
2656 | |
|
2657 | 0 | bool bUpdate = false; |
2658 | 0 | bool bNameOK = false; |
2659 | 0 | bool bCommandApplicationOK = false; |
2660 | 0 | bool bCommandTopicOK = false; |
2661 | 0 | bool bCommandItemOK = false; |
2662 | | |
2663 | | // process attributes |
2664 | 0 | for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) ) |
2665 | 0 | { |
2666 | 0 | switch (aIter.getToken()) |
2667 | 0 | { |
2668 | 0 | case XML_ELEMENT(OFFICE, XML_NAME): |
2669 | 0 | sName = aIter.toString(); |
2670 | 0 | bNameOK = true; |
2671 | 0 | break; |
2672 | 0 | case XML_ELEMENT(OFFICE, XML_DDE_APPLICATION): |
2673 | 0 | sCommandApplication = aIter.toString(); |
2674 | 0 | bCommandApplicationOK = true; |
2675 | 0 | break; |
2676 | 0 | case XML_ELEMENT(OFFICE, XML_DDE_TOPIC): |
2677 | 0 | sCommandTopic = aIter.toString(); |
2678 | 0 | bCommandTopicOK = true; |
2679 | 0 | break; |
2680 | 0 | case XML_ELEMENT(OFFICE, XML_DDE_ITEM): |
2681 | 0 | sCommandItem = aIter.toString(); |
2682 | 0 | bCommandItemOK = true; |
2683 | 0 | break; |
2684 | 0 | case XML_ELEMENT(OFFICE, XML_AUTOMATIC_UPDATE): |
2685 | 0 | { |
2686 | 0 | bool bTmp(false); |
2687 | 0 | if (::sax::Converter::convertBool(bTmp, aIter.toView()) ) |
2688 | 0 | { |
2689 | 0 | bUpdate = bTmp; |
2690 | 0 | } |
2691 | 0 | break; |
2692 | 0 | } |
2693 | 0 | default: |
2694 | 0 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
2695 | 0 | } |
2696 | 0 | } |
2697 | | |
2698 | | // valid data? |
2699 | 0 | if (!(bNameOK && bCommandApplicationOK && bCommandTopicOK && bCommandItemOK)) |
2700 | 0 | return; |
2701 | | |
2702 | | // create DDE TextFieldMaster |
2703 | 0 | Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(), |
2704 | 0 | UNO_QUERY); |
2705 | 0 | if( !xFactory.is() ) |
2706 | 0 | return; |
2707 | | |
2708 | | /* #i6432# There might be multiple occurrences of one DDE |
2709 | | declaration if it is used in more than one of |
2710 | | header/footer/body. createInstance will throw an exception if we |
2711 | | try to create the second, third, etc. instance of such a |
2712 | | declaration. Thus we ignore the exception. Otherwise this will |
2713 | | lead to an unloadable document. */ |
2714 | 0 | try |
2715 | 0 | { |
2716 | 0 | Reference<XInterface> xIfc = |
2717 | 0 | xFactory->createInstance(OUString::Concat(sAPI_fieldmaster_prefix) + sAPI_dde); |
2718 | 0 | if( xIfc.is() ) |
2719 | 0 | { |
2720 | 0 | Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY ); |
2721 | 0 | if (xPropSet.is() && |
2722 | 0 | xPropSet->getPropertySetInfo()->hasPropertyByName( |
2723 | 0 | u"DDECommandType"_ustr)) |
2724 | 0 | { |
2725 | 0 | xPropSet->setPropertyValue(sAPI_name, Any(sName)); |
2726 | |
|
2727 | 0 | xPropSet->setPropertyValue(u"DDECommandType"_ustr, Any(sCommandApplication)); |
2728 | |
|
2729 | 0 | xPropSet->setPropertyValue(u"DDECommandFile"_ustr, Any(sCommandTopic)); |
2730 | |
|
2731 | 0 | xPropSet->setPropertyValue(u"DDECommandElement"_ustr, |
2732 | 0 | Any(sCommandItem)); |
2733 | |
|
2734 | 0 | xPropSet->setPropertyValue(u"IsAutomaticUpdate"_ustr, |
2735 | 0 | Any(bUpdate)); |
2736 | 0 | } |
2737 | | // else: ignore (can't get XPropertySet, or DDE |
2738 | | // properties are not supported) |
2739 | 0 | } |
2740 | | // else: ignore |
2741 | 0 | } |
2742 | 0 | catch (const Exception&) |
2743 | 0 | { |
2744 | | //ignore |
2745 | 0 | } |
2746 | | // else: ignore |
2747 | | // else: ignore |
2748 | 0 | } |
2749 | | |
2750 | | |
2751 | | // DDE field import |
2752 | | |
2753 | | |
2754 | | XMLDdeFieldImportContext::XMLDdeFieldImportContext( |
2755 | | SvXMLImport& rImport, XMLTextImportHelper& rHlp) : |
2756 | 1 | XMLTextFieldImportContext(rImport, rHlp, sAPI_dde), |
2757 | 1 | sPropertyContent(sAPI_content) |
2758 | 1 | { |
2759 | 1 | } |
2760 | | |
2761 | | void XMLDdeFieldImportContext::ProcessAttribute( |
2762 | | sal_Int32 nAttrToken, |
2763 | | std::string_view sAttrValue ) |
2764 | 0 | { |
2765 | 0 | if ( XML_ELEMENT(TEXT, XML_CONNECTION_NAME) == nAttrToken) |
2766 | 0 | { |
2767 | 0 | sName = OUString::fromUtf8(sAttrValue); |
2768 | 0 | bValid = true; |
2769 | 0 | } |
2770 | 0 | else |
2771 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2772 | 0 | } |
2773 | | |
2774 | | |
2775 | | void XMLDdeFieldImportContext::endFastElement(sal_Int32 ) |
2776 | 0 | { |
2777 | 0 | if (!bValid) |
2778 | 0 | return; |
2779 | | |
2780 | | // find master |
2781 | 0 | OUString sMasterName = OUString::Concat(sAPI_fieldmaster_prefix) + sAPI_dde + "." + sName; |
2782 | |
|
2783 | 0 | Reference<XTextFieldsSupplier> xTextFieldsSupp(GetImport().GetModel(), |
2784 | 0 | UNO_QUERY); |
2785 | 0 | Reference<container::XNameAccess> xFieldMasterNameAccess = |
2786 | 0 | xTextFieldsSupp->getTextFieldMasters(); |
2787 | |
|
2788 | 0 | if (!xFieldMasterNameAccess->hasByName(sMasterName)) |
2789 | 0 | return; |
2790 | | |
2791 | 0 | Reference<XPropertySet> xMaster; |
2792 | 0 | Any aAny = xFieldMasterNameAccess->getByName(sMasterName); |
2793 | 0 | aAny >>= xMaster; |
2794 | | //apply the content to the master |
2795 | 0 | xMaster->setPropertyValue( sPropertyContent, uno::Any( GetContent())); |
2796 | | // master exists: create text field and attach |
2797 | 0 | Reference<XPropertySet> xField; |
2798 | 0 | OUString sFieldName = OUString::Concat(sAPI_textfield_prefix) + sAPI_dde; |
2799 | 0 | if (!CreateField(xField, sFieldName)) |
2800 | 0 | return; |
2801 | | |
2802 | 0 | Reference<XDependentTextField> xDepTextField(xField,UNO_QUERY); |
2803 | 0 | xDepTextField->attachTextFieldMaster(xMaster); |
2804 | | |
2805 | | // attach field to document |
2806 | 0 | Reference<XTextContent> xTextContent(xField, UNO_QUERY); |
2807 | 0 | if (xTextContent.is()) |
2808 | 0 | { |
2809 | 0 | GetImportHelper().InsertTextContent(xTextContent); |
2810 | | |
2811 | | // we're lucky. nothing else to prepare. |
2812 | 0 | } |
2813 | | // else: fail, because text content could not be created |
2814 | | // else: fail, because field could not be created |
2815 | | // else: fail, because no master was found (faulty document?!) |
2816 | | // not valid: ignore |
2817 | 0 | } |
2818 | | |
2819 | | void XMLDdeFieldImportContext::PrepareField( |
2820 | | const Reference<XPropertySet> &) |
2821 | 0 | { |
2822 | | // empty, since not needed. |
2823 | 0 | } |
2824 | | |
2825 | | |
2826 | | // sheet name fields |
2827 | | |
2828 | | |
2829 | | XMLSheetNameImportContext::XMLSheetNameImportContext( |
2830 | | SvXMLImport& rImport, |
2831 | | XMLTextImportHelper& rHlp) : |
2832 | 4.19k | XMLTextFieldImportContext(rImport, rHlp, u"SheetName"_ustr) |
2833 | 4.19k | { |
2834 | 4.19k | bValid = true; // always valid! |
2835 | 4.19k | } |
2836 | | |
2837 | | void XMLSheetNameImportContext::ProcessAttribute( |
2838 | | sal_Int32 nAttrToken, |
2839 | | std::string_view sAttrValue) |
2840 | 0 | { |
2841 | | // no attributes -> nothing to be done |
2842 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2843 | 0 | } |
2844 | | |
2845 | | void XMLSheetNameImportContext::PrepareField( |
2846 | | const Reference<XPropertySet> &) |
2847 | 4.18k | { |
2848 | | // no attributes -> nothing to be done |
2849 | 4.18k | } |
2850 | | |
2851 | | /** import page|slide name fields (<text:page-name>) */ |
2852 | | |
2853 | | XMLPageNameFieldImportContext::XMLPageNameFieldImportContext( |
2854 | | SvXMLImport& rImport, /// XML Import |
2855 | | XMLTextImportHelper& rHlp) /// Text import helper |
2856 | 0 | : XMLTextFieldImportContext(rImport, rHlp, u"PageName"_ustr ) |
2857 | 0 | { |
2858 | 0 | bValid = true; |
2859 | 0 | } |
2860 | | |
2861 | | /// process attribute values |
2862 | | void XMLPageNameFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken, |
2863 | | std::string_view sAttrValue ) |
2864 | 0 | { |
2865 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2866 | 0 | } |
2867 | | |
2868 | | /// prepare XTextField for insertion into document |
2869 | | void XMLPageNameFieldImportContext::PrepareField( |
2870 | | const css::uno::Reference<css::beans::XPropertySet> &) |
2871 | 0 | { |
2872 | 0 | } |
2873 | | |
2874 | | |
2875 | | // URL fields (Calc, Impress, Draw) |
2876 | | |
2877 | | |
2878 | | XMLUrlFieldImportContext::XMLUrlFieldImportContext( |
2879 | | SvXMLImport& rImport, |
2880 | | XMLTextImportHelper& rHlp) : |
2881 | 1.06k | XMLTextFieldImportContext(rImport, rHlp, sAPI_url), |
2882 | 1.06k | bFrameOK(false) |
2883 | 1.06k | { |
2884 | 1.06k | } |
2885 | | |
2886 | | void XMLUrlFieldImportContext::ProcessAttribute( |
2887 | | sal_Int32 nAttrToken, |
2888 | | std::string_view sAttrValue ) |
2889 | 0 | { |
2890 | 0 | switch (nAttrToken) |
2891 | 0 | { |
2892 | 0 | case XML_ELEMENT(XLINK, XML_HREF): |
2893 | 0 | sURL = GetImport().GetAbsoluteReference( OUString::fromUtf8(sAttrValue) ); |
2894 | 0 | bValid = true; |
2895 | 0 | break; |
2896 | 0 | case XML_ELEMENT(OFFICE, XML_TARGET_FRAME_NAME): |
2897 | 0 | sFrame = OUString::fromUtf8(sAttrValue); |
2898 | 0 | bFrameOK = true; |
2899 | 0 | break; |
2900 | 0 | default: |
2901 | | // ignore |
2902 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
2903 | 0 | break; |
2904 | 0 | } |
2905 | 0 | } |
2906 | | |
2907 | | void XMLUrlFieldImportContext::PrepareField( |
2908 | | const Reference<XPropertySet> & xPropertySet) |
2909 | 0 | { |
2910 | 0 | xPropertySet->setPropertyValue(sAPI_url, Any(sURL)); |
2911 | |
|
2912 | 0 | if (bFrameOK) |
2913 | 0 | { |
2914 | 0 | xPropertySet->setPropertyValue(u"TargetFrame"_ustr, Any(sFrame)); |
2915 | 0 | } |
2916 | |
|
2917 | 0 | xPropertySet->setPropertyValue(u"Representation"_ustr, Any(GetContent())); |
2918 | 0 | } |
2919 | | |
2920 | | |
2921 | | XMLBibliographyFieldImportContext::XMLBibliographyFieldImportContext( |
2922 | | SvXMLImport& rImport, |
2923 | | XMLTextImportHelper& rHlp) : |
2924 | 268 | XMLTextFieldImportContext(rImport, rHlp, u"Bibliography"_ustr) |
2925 | 268 | { |
2926 | 268 | bValid = true; |
2927 | 268 | } |
2928 | | |
2929 | | // TODO: this is the same map as is used in the text field export |
2930 | | SvXMLEnumMapEntry<sal_uInt16> const aBibliographyDataTypeMap[] = |
2931 | | { |
2932 | | { XML_ARTICLE, BibliographyDataType::ARTICLE }, |
2933 | | { XML_BOOK, BibliographyDataType::BOOK }, |
2934 | | { XML_BOOKLET, BibliographyDataType::BOOKLET }, |
2935 | | { XML_CONFERENCE, BibliographyDataType::CONFERENCE }, |
2936 | | { XML_CUSTOM1, BibliographyDataType::CUSTOM1 }, |
2937 | | { XML_CUSTOM2, BibliographyDataType::CUSTOM2 }, |
2938 | | { XML_CUSTOM3, BibliographyDataType::CUSTOM3 }, |
2939 | | { XML_CUSTOM4, BibliographyDataType::CUSTOM4 }, |
2940 | | { XML_CUSTOM5, BibliographyDataType::CUSTOM5 }, |
2941 | | { XML_EMAIL, BibliographyDataType::EMAIL }, |
2942 | | { XML_INBOOK, BibliographyDataType::INBOOK }, |
2943 | | { XML_INCOLLECTION, BibliographyDataType::INCOLLECTION }, |
2944 | | { XML_INPROCEEDINGS, BibliographyDataType::INPROCEEDINGS }, |
2945 | | { XML_JOURNAL, BibliographyDataType::JOURNAL }, |
2946 | | { XML_MANUAL, BibliographyDataType::MANUAL }, |
2947 | | { XML_MASTERSTHESIS, BibliographyDataType::MASTERSTHESIS }, |
2948 | | { XML_MISC, BibliographyDataType::MISC }, |
2949 | | { XML_PHDTHESIS, BibliographyDataType::PHDTHESIS }, |
2950 | | { XML_PROCEEDINGS, BibliographyDataType::PROCEEDINGS }, |
2951 | | { XML_TECHREPORT, BibliographyDataType::TECHREPORT }, |
2952 | | { XML_UNPUBLISHED, BibliographyDataType::UNPUBLISHED }, |
2953 | | { XML_WWW, BibliographyDataType::WWW }, |
2954 | | { XML_TOKEN_INVALID, 0 } |
2955 | | }; |
2956 | | |
2957 | | |
2958 | | // we'll process attributes on our own and for fit the standard |
2959 | | // textfield mechanism, because our attributes have zero overlap with |
2960 | | // all the other textfields. |
2961 | | void XMLBibliographyFieldImportContext::startFastElement( |
2962 | | sal_Int32 /*nElement*/, |
2963 | | const Reference<XFastAttributeList> & xAttrList) |
2964 | 268 | { |
2965 | | // iterate over attributes |
2966 | 268 | for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) ) |
2967 | 128 | { |
2968 | 128 | if (IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_TEXT) |
2969 | 1 | || IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_LO_EXT)) |
2970 | 127 | { |
2971 | 127 | auto nToken = aIter.getToken() & TOKEN_MASK; |
2972 | 127 | PropertyValue aValue; |
2973 | 127 | aValue.Name = MapBibliographyFieldName(nToken); |
2974 | | |
2975 | | // special treatment for bibliography type |
2976 | | // biblio vs bibilio: #96658#; also read old documents |
2977 | 127 | if (nToken == XML_BIBILIOGRAPHIC_TYPE || |
2978 | 127 | nToken == XML_BIBLIOGRAPHY_TYPE ) |
2979 | 15 | { |
2980 | 15 | sal_uInt16 nTmp; |
2981 | 15 | if (SvXMLUnitConverter::convertEnum( |
2982 | 15 | nTmp, aIter.toView(), |
2983 | 15 | aBibliographyDataTypeMap)) |
2984 | 15 | { |
2985 | 15 | aValue.Value <<= static_cast<sal_Int16>(nTmp); |
2986 | | |
2987 | 15 | aValues.push_back(aValue); |
2988 | 15 | } |
2989 | 15 | } |
2990 | 112 | else |
2991 | 112 | { |
2992 | 112 | OUString aStringValue = aIter.toString(); |
2993 | 112 | if (nToken == XML_URL || nToken == XML_LOCAL_URL || nToken == XML_TARGET_URL) |
2994 | 0 | { |
2995 | 0 | aStringValue = GetImport().GetAbsoluteReference(aStringValue); |
2996 | 0 | } |
2997 | 112 | aValue.Value <<= aStringValue; |
2998 | | |
2999 | 112 | aValues.push_back(aValue); |
3000 | 112 | } |
3001 | 127 | } |
3002 | | // else: unknown namespace -> ignore |
3003 | 128 | } |
3004 | 268 | } |
3005 | | |
3006 | | void XMLBibliographyFieldImportContext::ProcessAttribute( |
3007 | | sal_Int32 , |
3008 | | std::string_view ) |
3009 | 0 | { |
3010 | | // attributes are handled in StartElement |
3011 | 0 | assert(false && "This should not have happened."); |
3012 | 0 | } |
3013 | | |
3014 | | |
3015 | | void XMLBibliographyFieldImportContext::PrepareField( |
3016 | | const Reference<XPropertySet> & xPropertySet) |
3017 | 265 | { |
3018 | | // convert vector into sequence |
3019 | 265 | sal_Int32 nCount = aValues.size(); |
3020 | 265 | Sequence<PropertyValue> aValueSequence(nCount); |
3021 | 265 | auto aValueSequenceRange = asNonConstRange(aValueSequence); |
3022 | 371 | for(sal_Int32 i = 0; i < nCount; i++) |
3023 | 106 | { |
3024 | 106 | aValueSequenceRange[i] = aValues[i]; |
3025 | 106 | } |
3026 | | |
3027 | | // set sequence |
3028 | 265 | xPropertySet->setPropertyValue(u"Fields"_ustr, Any(aValueSequence)); |
3029 | 265 | } |
3030 | | |
3031 | | OUString XMLBibliographyFieldImportContext::MapBibliographyFieldName( |
3032 | | sal_Int32 nElement) |
3033 | 127 | { |
3034 | 127 | OUString pName; |
3035 | | |
3036 | 127 | switch (nElement & TOKEN_MASK) |
3037 | 127 | { |
3038 | 15 | case XML_IDENTIFIER: |
3039 | 15 | pName = u"Identifier"_ustr; |
3040 | 15 | break; |
3041 | 0 | case XML_BIBILIOGRAPHIC_TYPE: |
3042 | 15 | case XML_BIBLIOGRAPHY_TYPE: |
3043 | | // biblio... vs bibilio...: #96658#: also read old documents |
3044 | 15 | pName = u"BibiliographicType"_ustr; |
3045 | 15 | break; |
3046 | 0 | case XML_ADDRESS: |
3047 | 0 | pName = u"Address"_ustr; |
3048 | 0 | break; |
3049 | 0 | case XML_ANNOTE: |
3050 | 0 | pName = u"Annote"_ustr; |
3051 | 0 | break; |
3052 | 15 | case XML_AUTHOR: |
3053 | 15 | pName = u"Author"_ustr; |
3054 | 15 | break; |
3055 | 0 | case XML_BOOKTITLE: |
3056 | 0 | pName = u"Booktitle"_ustr; |
3057 | 0 | break; |
3058 | 0 | case XML_CHAPTER: |
3059 | 0 | pName = u"Chapter"_ustr; |
3060 | 0 | break; |
3061 | 0 | case XML_EDITION: |
3062 | 0 | pName = u"Edition"_ustr; |
3063 | 0 | break; |
3064 | 0 | case XML_EDITOR: |
3065 | 0 | pName = u"Editor"_ustr; |
3066 | 0 | break; |
3067 | 0 | case XML_HOWPUBLISHED: |
3068 | 0 | pName = u"Howpublished"_ustr; |
3069 | 0 | break; |
3070 | 0 | case XML_INSTITUTION: |
3071 | 0 | pName = u"Institution"_ustr; |
3072 | 0 | break; |
3073 | 0 | case XML_JOURNAL: |
3074 | 0 | pName = u"Journal"_ustr; |
3075 | 0 | break; |
3076 | 0 | case XML_MONTH: |
3077 | 0 | pName = u"Month"_ustr; |
3078 | 0 | break; |
3079 | 0 | case XML_NOTE: |
3080 | 0 | pName = u"Note"_ustr; |
3081 | 0 | break; |
3082 | 0 | case XML_NUMBER: |
3083 | 0 | pName = u"Number"_ustr; |
3084 | 0 | break; |
3085 | 0 | case XML_ORGANIZATIONS: |
3086 | 0 | pName = u"Organizations"_ustr; |
3087 | 0 | break; |
3088 | 15 | case XML_PAGES: |
3089 | 15 | pName = u"Pages"_ustr; |
3090 | 15 | break; |
3091 | 14 | case XML_PUBLISHER: |
3092 | 14 | pName = u"Publisher"_ustr; |
3093 | 14 | break; |
3094 | 0 | case XML_SCHOOL: |
3095 | 0 | pName = u"School"_ustr; |
3096 | 0 | break; |
3097 | 0 | case XML_SERIES: |
3098 | 0 | pName = u"Series"_ustr; |
3099 | 0 | break; |
3100 | 14 | case XML_TITLE: |
3101 | 14 | pName = u"Title"_ustr; |
3102 | 14 | break; |
3103 | 0 | case XML_REPORT_TYPE: |
3104 | 0 | pName = u"Report_Type"_ustr; |
3105 | 0 | break; |
3106 | 0 | case XML_VOLUME: |
3107 | 0 | pName = u"Volume"_ustr; |
3108 | 0 | break; |
3109 | 14 | case XML_YEAR: |
3110 | 14 | pName = u"Year"_ustr; |
3111 | 14 | break; |
3112 | 0 | case XML_URL: |
3113 | 0 | pName = u"URL"_ustr; |
3114 | 0 | break; |
3115 | 13 | case XML_CUSTOM1: |
3116 | 13 | pName = u"Custom1"_ustr; |
3117 | 13 | break; |
3118 | 0 | case XML_CUSTOM2: |
3119 | 0 | pName = u"Custom2"_ustr; |
3120 | 0 | break; |
3121 | 0 | case XML_CUSTOM3: |
3122 | 0 | pName = u"Custom3"_ustr; |
3123 | 0 | break; |
3124 | 0 | case XML_CUSTOM4: |
3125 | 0 | pName = u"Custom4"_ustr; |
3126 | 0 | break; |
3127 | 0 | case XML_CUSTOM5: |
3128 | 0 | pName = u"Custom5"_ustr; |
3129 | 0 | break; |
3130 | 12 | case XML_ISBN: |
3131 | 12 | pName = u"ISBN"_ustr; |
3132 | 12 | break; |
3133 | 0 | case XML_LOCAL_URL: |
3134 | 0 | pName = u"LocalURL"_ustr; |
3135 | 0 | break; |
3136 | 0 | case XML_TARGET_TYPE: |
3137 | 0 | pName = u"TargetType"_ustr; |
3138 | 0 | break; |
3139 | 0 | case XML_TARGET_URL: |
3140 | 0 | pName = u"TargetURL"_ustr; |
3141 | 0 | break; |
3142 | 0 | default: |
3143 | 0 | assert(false && "Unknown bibliography info data"); |
3144 | 127 | } |
3145 | 127 | return pName; |
3146 | 127 | } |
3147 | | |
3148 | | // Annotation Field |
3149 | | |
3150 | | |
3151 | | XMLAnnotationImportContext::XMLAnnotationImportContext( |
3152 | | SvXMLImport& rImport, |
3153 | | XMLTextImportHelper& rHlp, |
3154 | | sal_Int32 nElement) : |
3155 | 43 | XMLTextFieldImportContext(rImport, rHlp, u"Annotation"_ustr), |
3156 | 43 | mnElement(nElement) |
3157 | 43 | { |
3158 | 43 | bValid = true; |
3159 | | |
3160 | | // remember old list item and block (#91964#) and reset them |
3161 | | // for the text frame |
3162 | | // do this in the constructor, not in CreateChildContext (#i93392#) |
3163 | 43 | GetImport().GetTextImport()->PushListContext(); |
3164 | 43 | } |
3165 | | |
3166 | | void XMLAnnotationImportContext::ProcessAttribute( |
3167 | | sal_Int32 nAttrToken, |
3168 | | std::string_view sAttrValue ) |
3169 | 44 | { |
3170 | 44 | if (nAttrToken == XML_ELEMENT(OFFICE, XML_NAME)) |
3171 | 0 | aName = OUString::fromUtf8(sAttrValue); |
3172 | 44 | else if (nAttrToken == XML_ELEMENT(LO_EXT, XML_RESOLVED)) |
3173 | 0 | aResolved = OUString::fromUtf8(sAttrValue); |
3174 | 44 | else if (nAttrToken == XML_ELEMENT(LO_EXT, XML_PARENT_NAME)) |
3175 | 0 | aParentName = OUString::fromUtf8(sAttrValue); |
3176 | 44 | else |
3177 | 44 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
3178 | 44 | } |
3179 | | |
3180 | | css::uno::Reference< css::xml::sax::XFastContextHandler > XMLAnnotationImportContext::createFastChildContext( |
3181 | | sal_Int32 nElement, |
3182 | | const uno::Reference< xml::sax::XFastAttributeList>& xAttrList ) |
3183 | 219 | { |
3184 | 219 | if( nElement == XML_ELEMENT(DC, XML_CREATOR) ) |
3185 | 0 | return new XMLStringBufferImportContext(GetImport(), aAuthorBuffer); |
3186 | 219 | else if( nElement == XML_ELEMENT(DC, XML_DATE) ) |
3187 | 0 | return new XMLStringBufferImportContext(GetImport(), aDateBuffer); |
3188 | 219 | else if (nElement == XML_ELEMENT(TEXT,XML_SENDER_INITIALS) || |
3189 | 219 | nElement == XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS) || |
3190 | 219 | nElement == XML_ELEMENT(META, XML_CREATOR_INITIALS)) |
3191 | 0 | return new XMLStringBufferImportContext(GetImport(), aInitialsBuffer); |
3192 | | |
3193 | 219 | try |
3194 | 219 | { |
3195 | 219 | bool bOK = true; |
3196 | 219 | if ( !mxField.is() ) |
3197 | 77 | bOK = CreateField( mxField, sServicePrefix + GetServiceName() ); |
3198 | 219 | if (bOK) |
3199 | 170 | { |
3200 | 170 | Any aAny = mxField->getPropertyValue( u"TextRange"_ustr ); |
3201 | 170 | Reference< XText > xText; |
3202 | 170 | aAny >>= xText; |
3203 | 170 | if( xText.is() ) |
3204 | 170 | { |
3205 | 170 | rtl::Reference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport(); |
3206 | 170 | if( !mxCursor.is() ) |
3207 | 28 | { |
3208 | 28 | mxOldCursor = xTxtImport->GetCursor(); |
3209 | 28 | mxCursor = xText->createTextCursor(); |
3210 | 28 | } |
3211 | | |
3212 | 170 | if( mxCursor.is() ) |
3213 | 170 | { |
3214 | 170 | xTxtImport->SetCursor( mxCursor ); |
3215 | 170 | return xTxtImport->CreateTextChildContext( GetImport(), nElement, xAttrList ); |
3216 | 170 | } |
3217 | 170 | } |
3218 | 170 | } |
3219 | 219 | } |
3220 | 219 | catch (const Exception&) |
3221 | 219 | { |
3222 | 0 | } |
3223 | | |
3224 | 49 | return new XMLStringBufferImportContext(GetImport(), aTextBuffer); |
3225 | 219 | } |
3226 | | |
3227 | | void XMLAnnotationImportContext::endFastElement(sal_Int32 /*nElement*/) |
3228 | 4 | { |
3229 | 4 | DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!"); |
3230 | 4 | if( mxCursor.is() ) |
3231 | 0 | { |
3232 | | // delete addition newline |
3233 | 0 | mxCursor->gotoEnd( false ); |
3234 | 0 | mxCursor->goLeft( 1, true ); |
3235 | 0 | mxCursor->setString( u""_ustr ); |
3236 | | |
3237 | | // reset cursor |
3238 | 0 | GetImport().GetTextImport()->ResetCursor(); |
3239 | 0 | } |
3240 | | |
3241 | 4 | if( mxOldCursor.is() ) |
3242 | 0 | GetImport().GetTextImport()->SetCursor( mxOldCursor ); |
3243 | | |
3244 | | // reinstall old list item #91964# |
3245 | 4 | GetImport().GetTextImport()->PopListContext(); |
3246 | | |
3247 | 4 | if (!bValid) |
3248 | 0 | { |
3249 | 0 | GetImportHelper().InsertString(GetContent()); |
3250 | 0 | return; |
3251 | 0 | } |
3252 | | |
3253 | 4 | if ( mnElement == XML_ELEMENT(OFFICE, XML_ANNOTATION_END) ) |
3254 | 4 | { |
3255 | | // Search for a previous annotation with the same name. |
3256 | 4 | uno::Reference< text::XTextContent > xPrevField; |
3257 | 4 | { |
3258 | 4 | Reference<XTextFieldsSupplier> xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY); |
3259 | 4 | if (!xTextFieldsSupplier) |
3260 | 2 | return; |
3261 | 2 | uno::Reference<container::XUniqueIDAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields(), UNO_QUERY_THROW); |
3262 | 2 | uno::Any aAny = xFieldsAccess->getByUniqueID(aName); |
3263 | 2 | aAny >>= xPrevField; |
3264 | 2 | } |
3265 | 2 | if ( xPrevField.is() ) |
3266 | 0 | { |
3267 | | // So we are ending a previous annotation, |
3268 | | // let's create a text range covering the old and the current position. |
3269 | 0 | uno::Reference<text::XText> xText = GetImportHelper().GetText(); |
3270 | 0 | uno::Reference<text::XTextCursor> xCursor = |
3271 | 0 | xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange()); |
3272 | 0 | try |
3273 | 0 | { |
3274 | 0 | xCursor->gotoRange(xPrevField->getAnchor(), true); |
3275 | 0 | } |
3276 | 0 | catch (const uno::RuntimeException&) |
3277 | 0 | { |
3278 | | // Losing the start of the anchor is better than not opening the document at |
3279 | | // all. |
3280 | 0 | TOOLS_WARN_EXCEPTION( |
3281 | 0 | "xmloff.text", |
3282 | 0 | "XMLAnnotationImportContext::endFastElement: gotoRange() failed: "); |
3283 | 0 | } |
3284 | | |
3285 | 0 | xText->insertTextContent(xCursor, xPrevField, !xCursor->isCollapsed()); |
3286 | 0 | } |
3287 | 2 | return; |
3288 | 2 | } |
3289 | | |
3290 | 0 | if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) ) |
3291 | 0 | { |
3292 | | // set field properties |
3293 | 0 | PrepareField( mxField ); |
3294 | | |
3295 | | // attach field to document |
3296 | 0 | Reference < XTextContent > xTextContent( mxField, UNO_QUERY ); |
3297 | | |
3298 | | // workaround for #80606# |
3299 | 0 | try |
3300 | 0 | { |
3301 | 0 | GetImportHelper().InsertTextContent( xTextContent ); |
3302 | 0 | } |
3303 | 0 | catch (const lang::IllegalArgumentException&) |
3304 | 0 | { |
3305 | | // ignore |
3306 | 0 | } |
3307 | 0 | } |
3308 | 0 | } |
3309 | | |
3310 | | void XMLAnnotationImportContext::PrepareField( |
3311 | | const Reference<XPropertySet> & xPropertySet ) |
3312 | 0 | { |
3313 | | // import (possibly empty) author |
3314 | 0 | OUString sAuthor( aAuthorBuffer.makeStringAndClear() ); |
3315 | 0 | xPropertySet->setPropertyValue(sAPI_author, Any(sAuthor)); |
3316 | | |
3317 | | // import (possibly empty) initials |
3318 | 0 | OUString sInitials( aInitialsBuffer.makeStringAndClear() ); |
3319 | 0 | xPropertySet->setPropertyValue(u"Initials"_ustr, Any(sInitials)); |
3320 | | |
3321 | | //import resolved flag |
3322 | 0 | bool bTmp(false); |
3323 | 0 | (void)::sax::Converter::convertBool(bTmp, aResolved); |
3324 | 0 | xPropertySet->setPropertyValue(u"Resolved"_ustr, Any(bTmp)); |
3325 | |
|
3326 | 0 | util::DateTime aDateTime; |
3327 | 0 | if (::sax::Converter::parseDateTime(aDateTime, aDateBuffer)) |
3328 | 0 | { |
3329 | | /* |
3330 | | Date aDate; |
3331 | | aDate.Year = aDateTime.Year; |
3332 | | aDate.Month = aDateTime.Month; |
3333 | | aDate.Day = aDateTime.Day; |
3334 | | xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDate)); |
3335 | | */ |
3336 | | // why is there no UNO_NAME_DATE_TIME, but only UNO_NAME_DATE_TIME_VALUE? |
3337 | 0 | xPropertySet->setPropertyValue(sAPI_date_time_value, Any(aDateTime)); |
3338 | 0 | } |
3339 | 0 | aDateBuffer.setLength(0); |
3340 | |
|
3341 | 0 | if ( aTextBuffer.getLength() ) |
3342 | 0 | { |
3343 | | // delete last paragraph mark (if necessary) |
3344 | 0 | if (char(0x0a) == aTextBuffer[aTextBuffer.getLength()-1]) |
3345 | 0 | aTextBuffer.setLength(aTextBuffer.getLength()-1); |
3346 | 0 | xPropertySet->setPropertyValue(sAPI_content, Any(aTextBuffer.makeStringAndClear())); |
3347 | 0 | } |
3348 | |
|
3349 | 0 | if (!aName.isEmpty()) |
3350 | 0 | xPropertySet->setPropertyValue(sAPI_name, Any(aName)); |
3351 | |
|
3352 | 0 | if (!aParentName.isEmpty()) |
3353 | 0 | xPropertySet->setPropertyValue(sAPI_parent_name, Any(aParentName)); |
3354 | 0 | } |
3355 | | |
3356 | | |
3357 | | // script field |
3358 | | |
3359 | | |
3360 | | XMLScriptImportContext::XMLScriptImportContext( |
3361 | | SvXMLImport& rImport, |
3362 | | XMLTextImportHelper& rHlp) |
3363 | 1 | : XMLTextFieldImportContext(rImport, rHlp, u"Script"_ustr) |
3364 | 1 | , bContentOK(false) |
3365 | 1 | { |
3366 | 1 | } |
3367 | | |
3368 | | void XMLScriptImportContext::ProcessAttribute( |
3369 | | sal_Int32 nAttrToken, |
3370 | | std::string_view sAttrValue ) |
3371 | 0 | { |
3372 | 0 | switch (nAttrToken) |
3373 | 0 | { |
3374 | 0 | case XML_ELEMENT(XLINK, XML_HREF): |
3375 | 0 | sContent = GetImport().GetAbsoluteReference( OUString::fromUtf8(sAttrValue) ); |
3376 | 0 | bContentOK = true; |
3377 | 0 | break; |
3378 | | |
3379 | 0 | case XML_ELEMENT(SCRIPT, XML_LANGUAGE): |
3380 | 0 | sScriptType = OUString::fromUtf8(sAttrValue); |
3381 | 0 | break; |
3382 | | |
3383 | 0 | default: |
3384 | | // ignore |
3385 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
3386 | 0 | break; |
3387 | 0 | } |
3388 | | |
3389 | | // always valid (even without ScriptType; cf- #96531#) |
3390 | 0 | bValid = true; |
3391 | 0 | } |
3392 | | |
3393 | | void XMLScriptImportContext::PrepareField( |
3394 | | const Reference<XPropertySet> & xPropertySet) |
3395 | 0 | { |
3396 | | // if href attribute was present, we use it. Else we use element content |
3397 | 0 | if (! bContentOK) |
3398 | 0 | { |
3399 | 0 | sContent = GetContent(); |
3400 | 0 | } |
3401 | 0 | xPropertySet->setPropertyValue(sAPI_content, Any(sContent)); |
3402 | | |
3403 | | // URL or script text? We use URL if we have an href-attribute |
3404 | 0 | xPropertySet->setPropertyValue(u"URLContent"_ustr, Any(bContentOK)); |
3405 | |
|
3406 | 0 | xPropertySet->setPropertyValue(u"ScriptType"_ustr, Any(sScriptType)); |
3407 | 0 | } |
3408 | | |
3409 | | |
3410 | | // measure field |
3411 | | |
3412 | | |
3413 | | XMLMeasureFieldImportContext::XMLMeasureFieldImportContext( |
3414 | | SvXMLImport& rImport, |
3415 | | XMLTextImportHelper& rHlp) : |
3416 | 0 | XMLTextFieldImportContext(rImport, rHlp, u"Measure"_ustr), |
3417 | 0 | mnKind( 0 ) |
3418 | 0 | { |
3419 | 0 | } |
3420 | | |
3421 | | void XMLMeasureFieldImportContext::ProcessAttribute( |
3422 | | sal_Int32 nAttrToken, |
3423 | | std::string_view sAttrValue ) |
3424 | 0 | { |
3425 | 0 | switch (nAttrToken) |
3426 | 0 | { |
3427 | 0 | case XML_ELEMENT(TEXT, XML_KIND): |
3428 | 0 | if( IsXMLToken( sAttrValue, XML_VALUE ) ) |
3429 | 0 | { |
3430 | 0 | mnKind = 0; bValid = true; |
3431 | 0 | } |
3432 | 0 | else if( IsXMLToken( sAttrValue, XML_UNIT ) ) |
3433 | 0 | { |
3434 | 0 | mnKind = 1; bValid = true; |
3435 | 0 | } |
3436 | 0 | else if( IsXMLToken( sAttrValue, XML_GAP ) ) |
3437 | 0 | { |
3438 | 0 | mnKind = 2; bValid = true; |
3439 | 0 | } |
3440 | 0 | break; |
3441 | 0 | default: |
3442 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
3443 | 0 | } |
3444 | 0 | } |
3445 | | |
3446 | | void XMLMeasureFieldImportContext::PrepareField( |
3447 | | const Reference<XPropertySet> & xPropertySet) |
3448 | 0 | { |
3449 | 0 | xPropertySet->setPropertyValue(u"Kind"_ustr, Any(mnKind)); |
3450 | 0 | } |
3451 | | |
3452 | | |
3453 | | // dropdown field |
3454 | | |
3455 | | |
3456 | | XMLDropDownFieldImportContext::XMLDropDownFieldImportContext( |
3457 | | SvXMLImport& rImport, |
3458 | | XMLTextImportHelper& rHlp) : |
3459 | 0 | XMLTextFieldImportContext( rImport, rHlp, u"DropDown"_ustr ), |
3460 | 0 | nSelected( -1 ), |
3461 | 0 | bNameOK( false ), |
3462 | 0 | bHelpOK(false), |
3463 | 0 | bHintOK(false) |
3464 | 0 | { |
3465 | 0 | bValid = true; |
3466 | 0 | } |
3467 | | |
3468 | | static bool lcl_ProcessLabel( |
3469 | | const Reference<XFastAttributeList>& xAttrList, |
3470 | | OUString& rLabel, |
3471 | | bool& rIsSelected ) |
3472 | 0 | { |
3473 | 0 | bool bValid = false; |
3474 | 0 | for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) |
3475 | 0 | { |
3476 | 0 | switch (aIter.getToken()) |
3477 | 0 | { |
3478 | 0 | case XML_ELEMENT(TEXT, XML_VALUE): |
3479 | 0 | { |
3480 | 0 | rLabel = aIter.toString(); |
3481 | 0 | bValid = true; |
3482 | 0 | break; |
3483 | 0 | } |
3484 | 0 | case XML_ELEMENT(TEXT, XML_CURRENT_SELECTED): |
3485 | 0 | { |
3486 | 0 | bool bTmp(false); |
3487 | 0 | if (::sax::Converter::convertBool( bTmp, aIter.toView() )) |
3488 | 0 | rIsSelected = bTmp; |
3489 | 0 | break; |
3490 | 0 | } |
3491 | 0 | default: |
3492 | 0 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
3493 | 0 | } |
3494 | 0 | } |
3495 | 0 | return bValid; |
3496 | 0 | } |
3497 | | |
3498 | | css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDropDownFieldImportContext::createFastChildContext( |
3499 | | sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
3500 | 0 | { |
3501 | 0 | if( nElement == XML_ELEMENT(TEXT, XML_LABEL) ) |
3502 | 0 | { |
3503 | 0 | OUString sLabel; |
3504 | 0 | bool bIsSelected = false; |
3505 | 0 | if( lcl_ProcessLabel( xAttrList, sLabel, bIsSelected ) ) |
3506 | 0 | { |
3507 | 0 | if( bIsSelected ) |
3508 | 0 | nSelected = static_cast<sal_Int32>( aLabels.size() ); |
3509 | 0 | aLabels.push_back( sLabel ); |
3510 | 0 | } |
3511 | 0 | } |
3512 | 0 | return new SvXMLImportContext( GetImport() ); |
3513 | 0 | } |
3514 | | |
3515 | | void XMLDropDownFieldImportContext::ProcessAttribute( |
3516 | | sal_Int32 nAttrToken, |
3517 | | std::string_view sAttrValue ) |
3518 | 0 | { |
3519 | 0 | if( nAttrToken == XML_ELEMENT(TEXT, XML_NAME)) |
3520 | 0 | { |
3521 | 0 | sName = OUString::fromUtf8(sAttrValue); |
3522 | 0 | bNameOK = true; |
3523 | 0 | } |
3524 | 0 | else if (nAttrToken == XML_ELEMENT(TEXT, XML_HELP)) |
3525 | 0 | { |
3526 | 0 | sHelp = OUString::fromUtf8(sAttrValue); |
3527 | 0 | bHelpOK = true; |
3528 | 0 | } |
3529 | 0 | else if (nAttrToken == XML_ELEMENT(TEXT, XML_HINT)) |
3530 | 0 | { |
3531 | 0 | sHint = OUString::fromUtf8(sAttrValue); |
3532 | 0 | bHintOK = true; |
3533 | 0 | } |
3534 | 0 | else |
3535 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
3536 | 0 | } |
3537 | | |
3538 | | void XMLDropDownFieldImportContext::PrepareField( |
3539 | | const Reference<XPropertySet>& xPropertySet) |
3540 | 0 | { |
3541 | | // create sequence |
3542 | 0 | sal_Int32 nLength = static_cast<sal_Int32>( aLabels.size() ); |
3543 | 0 | Sequence<OUString> aSequence( nLength ); |
3544 | 0 | OUString* pSequence = aSequence.getArray(); |
3545 | 0 | for( sal_Int32 n = 0; n < nLength; n++ ) |
3546 | 0 | pSequence[n] = aLabels[n]; |
3547 | | |
3548 | | // now set values: |
3549 | |
|
3550 | 0 | xPropertySet->setPropertyValue( u"Items"_ustr, Any(aSequence) ); |
3551 | |
|
3552 | 0 | if( nSelected >= 0 && nSelected < nLength ) |
3553 | 0 | { |
3554 | 0 | xPropertySet->setPropertyValue( u"SelectedItem"_ustr, Any(pSequence[nSelected]) ); |
3555 | 0 | } |
3556 | | |
3557 | | // set name |
3558 | 0 | if( bNameOK ) |
3559 | 0 | { |
3560 | 0 | xPropertySet->setPropertyValue( u"Name"_ustr, Any(sName) ); |
3561 | 0 | } |
3562 | | // set help |
3563 | 0 | if( bHelpOK ) |
3564 | 0 | { |
3565 | 0 | xPropertySet->setPropertyValue( u"Help"_ustr, Any(sHelp) ); |
3566 | 0 | } |
3567 | | // set hint |
3568 | 0 | if( bHintOK ) |
3569 | 0 | { |
3570 | 0 | xPropertySet->setPropertyValue( u"Tooltip"_ustr, Any(sHint) ); |
3571 | 0 | } |
3572 | |
|
3573 | 0 | } |
3574 | | |
3575 | | /** import header fields (<draw:header>) */ |
3576 | | |
3577 | | XMLHeaderFieldImportContext::XMLHeaderFieldImportContext( |
3578 | | SvXMLImport& rImport, /// XML Import |
3579 | | XMLTextImportHelper& rHlp) /// Text import helper |
3580 | 290 | : XMLTextFieldImportContext(rImport, rHlp, u"Header"_ustr ) |
3581 | 290 | { |
3582 | 290 | sServicePrefix = sAPI_presentation_prefix; |
3583 | 290 | bValid = true; |
3584 | 290 | } |
3585 | | |
3586 | | /// process attribute values |
3587 | | void XMLHeaderFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken, std::string_view sAttrValue ) |
3588 | 0 | { |
3589 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
3590 | 0 | } |
3591 | | |
3592 | | /// prepare XTextField for insertion into document |
3593 | | void XMLHeaderFieldImportContext::PrepareField(const Reference<XPropertySet> &) |
3594 | 290 | { |
3595 | 290 | } |
3596 | | |
3597 | | /** import footer fields (<draw:footer>) */ |
3598 | | |
3599 | | XMLFooterFieldImportContext::XMLFooterFieldImportContext( |
3600 | | SvXMLImport& rImport, /// XML Import |
3601 | | XMLTextImportHelper& rHlp) /// Text import helper |
3602 | 335 | : XMLTextFieldImportContext(rImport, rHlp, u"Footer"_ustr ) |
3603 | 335 | { |
3604 | 335 | sServicePrefix = sAPI_presentation_prefix; |
3605 | 335 | bValid = true; |
3606 | 335 | } |
3607 | | |
3608 | | /// process attribute values |
3609 | | void XMLFooterFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken, std::string_view sAttrValue) |
3610 | 0 | { |
3611 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
3612 | 0 | } |
3613 | | |
3614 | | /// prepare XTextField for insertion into document |
3615 | | void XMLFooterFieldImportContext::PrepareField(const Reference<XPropertySet> &) |
3616 | 335 | { |
3617 | 335 | } |
3618 | | |
3619 | | |
3620 | | /** import footer fields (<draw:date-and-time>) */ |
3621 | | |
3622 | | XMLDateTimeFieldImportContext::XMLDateTimeFieldImportContext( |
3623 | | SvXMLImport& rImport, /// XML Import |
3624 | | XMLTextImportHelper& rHlp) /// Text import helper |
3625 | 362 | : XMLTextFieldImportContext(rImport, rHlp, u"DateTime"_ustr ) |
3626 | 362 | { |
3627 | 362 | sServicePrefix = sAPI_presentation_prefix; |
3628 | 362 | bValid = true; |
3629 | 362 | } |
3630 | | |
3631 | | /// process attribute values |
3632 | | void XMLDateTimeFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken, |
3633 | | std::string_view sAttrValue ) |
3634 | 0 | { |
3635 | 0 | XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue); |
3636 | 0 | } |
3637 | | |
3638 | | /// prepare XTextField for insertion into document |
3639 | | void XMLDateTimeFieldImportContext::PrepareField( |
3640 | | const css::uno::Reference< |
3641 | | css::beans::XPropertySet> &) |
3642 | 362 | { |
3643 | 362 | } |
3644 | | |
3645 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |