Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / text / txtfldi.cxx
blob1228e232d328aac5c0be16da1336f81dfd571d9c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 /** @#file
23 * Import of all text fields except those from txtvfldi.cxx
24 * (variable related text fields and database display fields)
27 #include <o3tl/safeint.hxx>
28 #include <sal/config.h>
30 #include <cassert>
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/xml/sax/XAttributeList.hpp>
46 #include <com/sun/star/text/UserDataPart.hpp>
47 #include <com/sun/star/style/NumberingType.hpp>
48 #include <com/sun/star/text/PlaceholderType.hpp>
49 #include <com/sun/star/text/ReferenceFieldPart.hpp>
50 #include <com/sun/star/text/ReferenceFieldSource.hpp>
51 #include <com/sun/star/text/XTextContent.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <com/sun/star/beans/XPropertySetInfo.hpp>
54 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
55 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
56 #include <com/sun/star/text/XDependentTextField.hpp>
57 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
58 #include <com/sun/star/text/ChapterFormat.hpp>
59 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
60 #include <com/sun/star/beans/PropertyValue.hpp>
61 #include <com/sun/star/text/BibliographyDataType.hpp>
62 #include <com/sun/star/util/XUpdatable.hpp>
63 #include <com/sun/star/sdb/CommandType.hpp>
64 #include <com/sun/star/container/XIndexReplace.hpp>
66 #include <sax/tools/converter.hxx>
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>
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;
87 // SO API string constants
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;
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;
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;
124 constexpr OUString sAPI_true = u"TRUE"_ustr;
127 XMLTextFieldImportContext::XMLTextFieldImportContext(
128 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
129 OUString aService)
130 : SvXMLImportContext( rImport )
131 , sServiceName(std::move(aService))
132 , rTextImportHelper(rHlp)
133 , sServicePrefix(sAPI_textfield_prefix)
134 , bValid(false)
138 void XMLTextFieldImportContext::startFastElement(
139 sal_Int32 /*nElement*/,
140 const Reference<XFastAttributeList> & xAttrList)
142 // process attributes
143 for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
144 ProcessAttribute(aIter.getToken(), aIter.toView() );
147 OUString const & XMLTextFieldImportContext::GetContent()
149 if (sContent.isEmpty())
151 sContent = sContentBuffer.makeStringAndClear();
154 return sContent;
157 void XMLTextFieldImportContext::endFastElement(sal_Int32 )
159 if (bValid)
162 // create field/Service
163 Reference<XPropertySet> xPropSet;
164 if (CreateField(xPropSet, sServicePrefix + GetServiceName()))
166 // set field properties
167 PrepareField(xPropSet);
169 // attach field to document
170 Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
172 // workaround for #80606#
175 rTextImportHelper.InsertTextContent(xTextContent);
177 catch (const lang::IllegalArgumentException&)
179 // ignore
181 return;
185 // in case of error: write element content
186 rTextImportHelper.InsertString(GetContent());
189 void XMLTextFieldImportContext::characters(const OUString& rContent)
191 sContentBuffer.append(rContent);
194 bool XMLTextFieldImportContext::CreateField(
195 Reference<XPropertySet> & xField,
196 const OUString& rServiceName)
198 // instantiate new XTextField:
199 // ask import for model, model is factory, ask factory to create service
201 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
202 if( xFactory.is() )
204 Reference<XInterface> xIfc = xFactory->createInstance(rServiceName);
205 if( xIfc.is() )
207 Reference<XPropertySet> xTmp( xIfc, UNO_QUERY );
209 xField = xTmp;
210 } else {
211 return false; // can't create instance
213 } else {
214 return false; // can't get MultiServiceFactory
217 return true;
220 /// create the appropriate field context from
221 XMLTextFieldImportContext*
222 XMLTextFieldImportContext::CreateTextFieldImportContext(
223 SvXMLImport& rImport,
224 XMLTextImportHelper& rHlp,
225 sal_Int32 nToken)
227 XMLTextFieldImportContext* pContext = nullptr;
229 switch (nToken)
231 case XML_ELEMENT(TEXT, XML_SENDER_FIRSTNAME):
232 case XML_ELEMENT(TEXT, XML_SENDER_LASTNAME):
233 case XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS):
234 case XML_ELEMENT(TEXT, XML_SENDER_INITIALS):
235 case XML_ELEMENT(TEXT, XML_SENDER_TITLE):
236 case XML_ELEMENT(TEXT, XML_SENDER_POSITION):
237 case XML_ELEMENT(TEXT, XML_SENDER_EMAIL):
238 case XML_ELEMENT(TEXT, XML_SENDER_PHONE_PRIVATE):
240 case XML_ELEMENT(TEXT, XML_SENDER_FAX):
241 case XML_ELEMENT(TEXT, XML_SENDER_COMPANY):
242 case XML_ELEMENT(TEXT, XML_SENDER_PHONE_WORK):
243 case XML_ELEMENT(TEXT, XML_SENDER_STREET):
244 case XML_ELEMENT(TEXT, XML_SENDER_CITY):
245 case XML_ELEMENT(TEXT, XML_SENDER_POSTAL_CODE):
246 case XML_ELEMENT(TEXT, XML_SENDER_COUNTRY):
247 case XML_ELEMENT(TEXT, XML_SENDER_STATE_OR_PROVINCE):
248 pContext =
249 new XMLSenderFieldImportContext( rImport, rHlp );
250 break;
252 case XML_ELEMENT(TEXT, XML_AUTHOR_NAME):
253 case XML_ELEMENT(TEXT, XML_AUTHOR_INITIALS):
254 pContext =
255 new XMLAuthorFieldImportContext( rImport, rHlp );
256 break;
258 case XML_ELEMENT(TEXT, XML_PLACEHOLDER):
259 pContext =
260 new XMLPlaceholderFieldImportContext( rImport, rHlp);
261 break;
262 case XML_ELEMENT(TEXT, XML_SEQUENCE):
263 pContext =
264 new XMLSequenceFieldImportContext( rImport, rHlp );
265 break;
266 case XML_ELEMENT(TEXT, XML_TEXT_INPUT):
267 pContext =
268 new XMLTextInputFieldImportContext( rImport, rHlp );
269 break;
270 case XML_ELEMENT(TEXT, XML_EXPRESSION):
271 pContext =
272 new XMLExpressionFieldImportContext( rImport, rHlp );
273 break;
274 case XML_ELEMENT(TEXT, XML_VARIABLE_SET):
275 pContext =
276 new XMLVariableSetFieldImportContext( rImport, rHlp );
277 break;
278 case XML_ELEMENT(TEXT, XML_VARIABLE_INPUT):
279 pContext =
280 new XMLVariableInputFieldImportContext( rImport, rHlp );
281 break;
282 case XML_ELEMENT(TEXT, XML_VARIABLE_GET):
283 pContext =
284 new XMLVariableGetFieldImportContext( rImport, rHlp );
285 break;
286 case XML_ELEMENT(TEXT, XML_USER_FIELD_GET):
287 pContext = new XMLUserFieldImportContext( rImport, rHlp );
288 break;
289 case XML_ELEMENT(TEXT, XML_USER_FIELD_INPUT):
290 pContext = new XMLUserFieldInputImportContext( rImport, rHlp );
291 break;
292 case XML_ELEMENT(TEXT, XML_TIME):
293 pContext = new XMLTimeFieldImportContext( rImport, rHlp );
294 break;
295 case XML_ELEMENT(TEXT, XML_PAGE_CONTINUATION_STRING):
296 case XML_ELEMENT(TEXT, XML_PAGE_CONTINUATION):
297 pContext = new XMLPageContinuationImportContext( rImport, rHlp );
298 break;
300 case XML_ELEMENT(TEXT, XML_PAGE_NUMBER):
301 pContext = new XMLPageNumberImportContext( rImport, rHlp );
302 break;
304 case XML_ELEMENT(TEXT, XML_DATE):
305 pContext = new XMLDateFieldImportContext( rImport, rHlp );
306 break;
308 case XML_ELEMENT(TEXT, XML_DATABASE_NAME):
309 pContext = new XMLDatabaseNameImportContext( rImport, rHlp );
310 break;
311 case XML_ELEMENT(TEXT, XML_DATABASE_NEXT):
312 pContext = new XMLDatabaseNextImportContext( rImport, rHlp );
313 break;
314 case XML_ELEMENT(TEXT, XML_DATABASE_ROW_SELECT):
315 pContext = new XMLDatabaseSelectImportContext( rImport, rHlp );
316 break;
317 case XML_ELEMENT(TEXT, XML_DATABASE_ROW_NUMBER):
318 pContext = new XMLDatabaseNumberImportContext( rImport, rHlp );
319 break;
320 case XML_ELEMENT(TEXT, XML_DATABASE_DISPLAY):
321 pContext = new XMLDatabaseDisplayImportContext( rImport, rHlp );
322 break;
323 case XML_ELEMENT(TEXT, XML_CONDITIONAL_TEXT):
324 pContext = new XMLConditionalTextImportContext( rImport, rHlp );
325 break;
326 case XML_ELEMENT(TEXT, XML_HIDDEN_TEXT):
327 pContext = new XMLHiddenTextImportContext( rImport, rHlp );
328 break;
329 case XML_ELEMENT(TEXT, XML_HIDDEN_PARAGRAPH):
330 pContext = new XMLHiddenParagraphImportContext( rImport, rHlp );
331 break;
332 case XML_ELEMENT(TEXT, XML_DESCRIPTION):
333 case XML_ELEMENT(TEXT, XML_TITLE):
334 case XML_ELEMENT(TEXT, XML_SUBJECT):
335 case XML_ELEMENT(TEXT, XML_KEYWORDS):
336 pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
337 nToken, true,
338 false );
339 break;
340 case XML_ELEMENT(TEXT, XML_INITIAL_CREATOR):
341 case XML_ELEMENT(TEXT, XML_PRINTED_BY):
342 case XML_ELEMENT(TEXT, XML_CREATOR):
343 pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
344 nToken, false,
345 true );
346 break;
348 case XML_ELEMENT(TEXT, XML_CREATION_DATE):
349 case XML_ELEMENT(TEXT, XML_CREATION_TIME):
350 case XML_ELEMENT(TEXT, XML_PRINT_DATE):
351 case XML_ELEMENT(TEXT, XML_PRINT_TIME):
352 case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE):
353 case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME):
354 case XML_ELEMENT(TEXT, XML_EDITING_DURATION):
355 pContext = new XMLDateTimeDocInfoImportContext( rImport, rHlp,
356 nToken );
357 break;
359 case XML_ELEMENT(TEXT, XML_EDITING_CYCLES):
360 pContext = new XMLRevisionDocInfoImportContext( rImport, rHlp,
361 nToken );
362 break;
364 case XML_ELEMENT(TEXT, XML_USER_DEFINED):
365 pContext = new XMLUserDocInfoImportContext( rImport, rHlp,
366 nToken );
367 break;
369 case XML_ELEMENT(TEXT, XML_FILE_NAME):
370 pContext = new XMLFileNameImportContext( rImport, rHlp );
371 break;
373 case XML_ELEMENT(TEXT, XML_CHAPTER):
374 pContext = new XMLChapterImportContext( rImport, rHlp );
375 break;
377 case XML_ELEMENT(TEXT, XML_TEMPLATE_NAME):
378 pContext = new XMLTemplateNameImportContext( rImport, rHlp );
379 break;
381 case XML_ELEMENT(TEXT, XML_WORD_COUNT):
382 case XML_ELEMENT(TEXT, XML_PARAGRAPH_COUNT):
383 case XML_ELEMENT(TEXT, XML_TABLE_COUNT):
384 case XML_ELEMENT(TEXT, XML_CHARACTER_COUNT):
385 case XML_ELEMENT(TEXT, XML_IMAGE_COUNT):
386 case XML_ELEMENT(TEXT, XML_OBJECT_COUNT):
387 case XML_ELEMENT(TEXT, XML_PAGE_COUNT):
388 pContext = new XMLCountFieldImportContext( rImport, rHlp, nToken);
389 break;
391 case XML_ELEMENT(TEXT, XML_PAGE_VARIABLE_GET):
392 pContext = new XMLPageVarGetFieldImportContext( rImport, rHlp );
393 break;
395 case XML_ELEMENT(TEXT, XML_PAGE_VARIABLE_SET):
396 pContext = new XMLPageVarSetFieldImportContext( rImport, rHlp );
397 break;
399 case XML_ELEMENT(TEXT, XML_EXECUTE_MACRO):
400 pContext = new XMLMacroFieldImportContext( rImport, rHlp );
401 break;
403 case XML_ELEMENT(TEXT, XML_DDE_CONNECTION):
404 pContext = new XMLDdeFieldImportContext( rImport, rHlp );
405 break;
407 case XML_ELEMENT(TEXT, XML_REFERENCE_REF):
408 case XML_ELEMENT(TEXT, XML_BOOKMARK_REF):
409 case XML_ELEMENT(TEXT, XML_NOTE_REF):
410 case XML_ELEMENT(TEXT, XML_SEQUENCE_REF):
411 case XML_ELEMENT(TEXT, XML_STYLE_REF):
412 case XML_ELEMENT(LO_EXT, XML_STYLE_REF):
413 pContext = new XMLReferenceFieldImportContext( rImport, rHlp, nToken );
414 break;
416 case XML_ELEMENT(TEXT, XML_SHEET_NAME):
417 pContext = new XMLSheetNameImportContext( rImport, rHlp );
418 break;
420 case XML_ELEMENT(TEXT, XML_PAGE_NAME):
421 case XML_ELEMENT(LO_EXT, XML_PAGE_NAME):
422 pContext = new XMLPageNameFieldImportContext( rImport, rHlp );
423 break;
425 case XML_ELEMENT(TEXT, XML_BIBLIOGRAPHY_MARK):
426 pContext = new XMLBibliographyFieldImportContext( rImport, rHlp );
427 break;
429 case XML_ELEMENT(OFFICE, XML_ANNOTATION):
430 case XML_ELEMENT(OFFICE, XML_ANNOTATION_END):
431 pContext = new XMLAnnotationImportContext( rImport, rHlp, nToken);
432 break;
434 case XML_ELEMENT(TEXT, XML_SCRIPT):
435 pContext = new XMLScriptImportContext( rImport, rHlp);
436 break;
438 case XML_ELEMENT(TEXT, XML_MEASURE):
439 pContext = new XMLMeasureFieldImportContext( rImport, rHlp );
440 break;
442 case XML_ELEMENT(TEXT, XML_TABLE_FORMULA):
443 pContext = new XMLTableFormulaImportContext( rImport, rHlp );
444 break;
445 case XML_ELEMENT(TEXT, XML_DROP_DOWN):
446 pContext = new XMLDropDownFieldImportContext( rImport, rHlp );
447 break;
448 case XML_ELEMENT(PRESENTATION, XML_HEADER):
449 pContext = new XMLHeaderFieldImportContext( rImport, rHlp );
450 break;
451 case XML_ELEMENT(PRESENTATION, XML_FOOTER):
452 pContext = new XMLFooterFieldImportContext( rImport, rHlp );
453 break;
454 case XML_ELEMENT(PRESENTATION, XML_DATE_TIME):
455 pContext = new XMLDateTimeFieldImportContext( rImport, rHlp );
456 break;
458 default:
459 // ignore! May not even be a textfield.
460 // (Reminder: This method is called inside default:-branch)
461 pContext = nullptr;
462 break;
465 return pContext;
469 void XMLTextFieldImportContext::ForceUpdate(
470 const Reference<XPropertySet> & rPropertySet)
472 // force update
473 Reference<XUpdatable> xUpdate(rPropertySet, UNO_QUERY);
474 if (xUpdate.is())
476 xUpdate->update();
478 else
480 OSL_FAIL("Expected XUpdatable support!");
485 // XMLSenderFieldImportContext
488 constexpr OUStringLiteral gsPropertyFieldSubType(u"UserDataType");
490 XMLSenderFieldImportContext::XMLSenderFieldImportContext(
491 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
492 : XMLTextFieldImportContext(rImport, rHlp, "ExtendedUser")
493 , nSubType(0)
494 , sPropertyFixed(sAPI_is_fixed)
495 , sPropertyContent(sAPI_content)
496 , bFixed(true)
500 void XMLSenderFieldImportContext::startFastElement(
501 sal_Int32 nElement,
502 const Reference<XFastAttributeList> & xAttrList)
504 bValid = true;
505 switch (nElement) {
506 case XML_ELEMENT(TEXT, XML_SENDER_FIRSTNAME):
507 nSubType = UserDataPart::FIRSTNAME;
508 break;
509 case XML_ELEMENT(TEXT, XML_SENDER_LASTNAME):
510 nSubType = UserDataPart::NAME;
511 break;
512 case XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS):
513 case XML_ELEMENT(TEXT, XML_SENDER_INITIALS):
514 nSubType = UserDataPart::SHORTCUT;
515 break;
516 case XML_ELEMENT(TEXT, XML_SENDER_TITLE):
517 nSubType = UserDataPart::TITLE;
518 break;
519 case XML_ELEMENT(TEXT, XML_SENDER_POSITION):
520 nSubType = UserDataPart::POSITION;
521 break;
522 case XML_ELEMENT(TEXT, XML_SENDER_EMAIL):
523 nSubType = UserDataPart::EMAIL;
524 break;
525 case XML_ELEMENT(TEXT, XML_SENDER_PHONE_PRIVATE):
526 nSubType = UserDataPart::PHONE_PRIVATE;
527 break;
528 case XML_ELEMENT(TEXT, XML_SENDER_FAX):
529 nSubType = UserDataPart::FAX;
530 break;
531 case XML_ELEMENT(TEXT, XML_SENDER_COMPANY):
532 nSubType = UserDataPart::COMPANY;
533 break;
534 case XML_ELEMENT(TEXT, XML_SENDER_PHONE_WORK):
535 nSubType = UserDataPart::PHONE_COMPANY;
536 break;
537 case XML_ELEMENT(TEXT, XML_SENDER_STREET):
538 nSubType = UserDataPart::STREET;
539 break;
540 case XML_ELEMENT(TEXT, XML_SENDER_CITY):
541 nSubType = UserDataPart::CITY;
542 break;
543 case XML_ELEMENT(TEXT, XML_SENDER_POSTAL_CODE):
544 nSubType = UserDataPart::ZIP;
545 break;
546 case XML_ELEMENT(TEXT, XML_SENDER_COUNTRY):
547 nSubType = UserDataPart::COUNTRY;
548 break;
549 case XML_ELEMENT(TEXT, XML_SENDER_STATE_OR_PROVINCE):
550 nSubType = UserDataPart::STATE;
551 break;
552 default:
553 bValid = false;
554 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
555 break;
558 // process Attributes
559 XMLTextFieldImportContext::startFastElement(nElement, xAttrList);
562 void XMLSenderFieldImportContext::ProcessAttribute(
563 sal_Int32 nAttrToken,
564 std::string_view sAttrValue)
566 if (XML_ELEMENT(TEXT, XML_FIXED) == nAttrToken) {
568 // set bVal
569 bool bVal(false);
570 bool const bRet = ::sax::Converter::convertBool(bVal, sAttrValue);
572 // set bFixed if successful
573 if (bRet) {
574 bFixed = bVal;
577 else
578 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
581 void XMLSenderFieldImportContext::PrepareField(
582 const Reference<XPropertySet> & rPropSet)
584 // set members
585 rPropSet->setPropertyValue(gsPropertyFieldSubType, Any(nSubType));
587 // set fixed
588 rPropSet->setPropertyValue(sPropertyFixed, Any(bFixed));
590 // set content if fixed
591 if (!bFixed)
592 return;
594 // in organizer or styles-only mode: force update
595 if (GetImport().GetTextImport()->IsOrganizerMode() ||
596 GetImport().GetTextImport()->IsStylesOnlyMode() )
598 ForceUpdate(rPropSet);
600 else
602 rPropSet->setPropertyValue(sPropertyContent, Any(GetContent()));
607 // XMLAuthorFieldImportContext
609 constexpr OUStringLiteral gsPropertyAuthorFullName(u"FullName");
611 XMLAuthorFieldImportContext::XMLAuthorFieldImportContext(
612 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
613 : XMLSenderFieldImportContext(rImport, rHlp)
614 , bAuthorFullName(true)
615 , sPropertyFixed(sAPI_is_fixed)
616 , sPropertyContent(sAPI_content)
618 // overwrite service name from XMLSenderFieldImportContext
619 SetServiceName(sAPI_author);
622 void XMLAuthorFieldImportContext::startFastElement(
623 sal_Int32 nElement,
624 const Reference<XFastAttributeList> & xAttrList)
626 bAuthorFullName = ( XML_ELEMENT(TEXT, XML_AUTHOR_INITIALS) != nElement);
627 bValid = true;
629 // process Attributes
630 XMLTextFieldImportContext::startFastElement(nElement, xAttrList);
633 void XMLAuthorFieldImportContext::ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue)
635 if(nAttrToken == XML_ELEMENT(TEXT, XML_FIXED))
637 bool bTmp(false);
638 if (::sax::Converter::convertBool(bTmp, sAttrValue))
639 bFixed = bTmp;
641 else
642 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
645 void XMLAuthorFieldImportContext::PrepareField(
646 const Reference<XPropertySet> & rPropSet)
648 // set members
649 Any aAny;
650 rPropSet->setPropertyValue(gsPropertyAuthorFullName, Any(bAuthorFullName));
652 rPropSet->setPropertyValue(sPropertyFixed, Any(bFixed));
654 // set content if fixed
655 if (!bFixed)
656 return;
658 // organizer or styles-only mode: force update
659 if (GetImport().GetTextImport()->IsOrganizerMode() ||
660 GetImport().GetTextImport()->IsStylesOnlyMode() )
662 ForceUpdate(rPropSet);
664 else
666 aAny <<= GetContent();
667 rPropSet->setPropertyValue(sPropertyContent, aAny);
672 // page continuation string
675 SvXMLEnumMapEntry<PageNumberType> const lcl_aSelectPageAttrMap[] =
677 { XML_PREVIOUS, PageNumberType_PREV },
678 { XML_CURRENT, PageNumberType_CURRENT },
679 { XML_NEXT, PageNumberType_NEXT },
680 { XML_TOKEN_INVALID, PageNumberType(0) },
683 constexpr OUStringLiteral gsPropertyUserText(u"UserText");
685 XMLPageContinuationImportContext::XMLPageContinuationImportContext(
686 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
687 : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number)
688 , sPropertySubType(sAPI_sub_type)
689 , sPropertyNumberingType(sAPI_numbering_type)
690 , eSelectPage(PageNumberType_CURRENT)
691 , sStringOK(false)
693 bValid = true;
696 void XMLPageContinuationImportContext::ProcessAttribute(
697 sal_Int32 nAttrToken, std::string_view sAttrValue )
699 switch(nAttrToken)
701 case XML_ELEMENT(TEXT, XML_SELECT_PAGE):
703 PageNumberType nTmp;
704 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
705 lcl_aSelectPageAttrMap)
706 && (PageNumberType_CURRENT != nTmp) )
708 eSelectPage = nTmp;
710 break;
712 case XML_ELEMENT(TEXT, XML_STRING_VALUE):
713 case XML_ELEMENT(OFFICE, XML_STRING_VALUE):
714 sString = OUString::fromUtf8(sAttrValue);
715 sStringOK = true;
716 break;
717 default:
718 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
722 void XMLPageContinuationImportContext::PrepareField(
723 const Reference<XPropertySet> & xPropertySet)
725 Any aAny;
727 xPropertySet->setPropertyValue(sPropertySubType, Any(eSelectPage));
729 aAny <<= (sStringOK ? sString : GetContent());
730 xPropertySet->setPropertyValue(gsPropertyUserText, aAny);
732 aAny <<= style::NumberingType::CHAR_SPECIAL;
733 xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
737 // page number field
740 XMLPageNumberImportContext::XMLPageNumberImportContext(
741 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
742 : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number)
743 , sPropertySubType(sAPI_sub_type)
744 , sPropertyNumberingType(sAPI_numbering_type)
745 , sPropertyOffset(sAPI_offset)
746 , sNumberSync(GetXMLToken(XML_FALSE))
747 , nPageAdjust(0)
748 , eSelectPage(PageNumberType_CURRENT)
749 , sNumberFormatOK(false)
751 bValid = true;
754 void XMLPageNumberImportContext::ProcessAttribute(
755 sal_Int32 nAttrToken,
756 std::string_view sAttrValue )
758 switch (nAttrToken)
760 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
761 sNumberFormat = OUString::fromUtf8(sAttrValue);
762 sNumberFormatOK = true;
763 break;
764 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
765 sNumberSync = OUString::fromUtf8(sAttrValue);
766 break;
767 case XML_ELEMENT(TEXT, XML_SELECT_PAGE):
768 SvXMLUnitConverter::convertEnum(eSelectPage, sAttrValue,
769 lcl_aSelectPageAttrMap);
770 break;
771 case XML_ELEMENT(TEXT, XML_PAGE_ADJUST):
773 sal_Int32 nTmp;
774 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
776 nPageAdjust = static_cast<sal_Int16>(nTmp);
778 break;
780 default:
781 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
785 void XMLPageNumberImportContext::PrepareField(
786 const Reference<XPropertySet> & xPropertySet)
788 // all properties are optional
789 Reference<XPropertySetInfo> xPropertySetInfo(
790 xPropertySet->getPropertySetInfo());
792 if (xPropertySetInfo->hasPropertyByName(sPropertyNumberingType))
794 sal_Int16 nNumType;
795 if( sNumberFormatOK )
797 nNumType= style::NumberingType::ARABIC;
798 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
799 sNumberFormat,
800 sNumberSync );
802 else
803 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
805 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
808 if (xPropertySetInfo->hasPropertyByName(sPropertyOffset))
810 // adjust offset
811 switch (eSelectPage)
813 case PageNumberType_PREV:
814 nPageAdjust--;
815 break;
816 case PageNumberType_CURRENT:
817 break;
818 case PageNumberType_NEXT:
819 nPageAdjust++;
820 break;
821 default:
822 SAL_WARN("xmloff.text", "unknown page number type");
824 xPropertySet->setPropertyValue(sPropertyOffset, Any(nPageAdjust));
827 if (xPropertySetInfo->hasPropertyByName(sPropertySubType))
829 xPropertySet->setPropertyValue(sPropertySubType, Any(eSelectPage));
834 // Placeholder
837 constexpr OUStringLiteral gsPropertyPlaceholderType(u"PlaceHolderType");
838 constexpr OUStringLiteral gsPropertyPlaceholder(u"PlaceHolder");
840 XMLPlaceholderFieldImportContext::XMLPlaceholderFieldImportContext(
841 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
842 : XMLTextFieldImportContext(rImport, rHlp, "JumpEdit")
843 , sPropertyHint(sAPI_hint)
844 , nPlaceholderType(PlaceholderType::TEXT)
848 /// process attribute values
849 void XMLPlaceholderFieldImportContext::ProcessAttribute(
850 sal_Int32 nAttrToken, std::string_view sAttrValue )
852 switch (nAttrToken) {
853 case XML_ELEMENT(TEXT, XML_DESCRIPTION):
854 sDescription = OUString::fromUtf8(sAttrValue);
855 break;
857 case XML_ELEMENT(TEXT, XML_PLACEHOLDER_TYPE):
858 bValid = true;
859 if (IsXMLToken(sAttrValue, XML_TABLE))
861 nPlaceholderType = PlaceholderType::TABLE;
863 else if (IsXMLToken(sAttrValue, XML_TEXT))
865 nPlaceholderType = PlaceholderType::TEXT;
867 else if (IsXMLToken(sAttrValue, XML_TEXT_BOX))
869 nPlaceholderType = PlaceholderType::TEXTFRAME;
871 else if (IsXMLToken(sAttrValue, XML_IMAGE))
873 nPlaceholderType = PlaceholderType::GRAPHIC;
875 else if (IsXMLToken(sAttrValue, XML_OBJECT))
877 nPlaceholderType = PlaceholderType::OBJECT;
879 else
881 bValid = false;
883 break;
885 default:
886 // ignore
887 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
891 void XMLPlaceholderFieldImportContext::PrepareField(
892 const Reference<XPropertySet> & xPropertySet) {
894 Any aAny;
895 xPropertySet->setPropertyValue(sPropertyHint, Any(sDescription));
897 // remove <...> around content (if present)
898 OUString aContent = GetContent();
899 sal_Int32 nStart = 0;
900 sal_Int32 nLength = aContent.getLength();
901 if (aContent.startsWith("<"))
903 --nLength;
904 ++nStart;
906 if (aContent.endsWith(">"))
908 --nLength;
910 aAny <<= aContent.copy(nStart, nLength);
911 xPropertySet->setPropertyValue(gsPropertyPlaceholder, aAny);
913 xPropertySet->setPropertyValue(gsPropertyPlaceholderType, Any(nPlaceholderType));
917 // time field
919 constexpr OUString gsPropertyAdjust(u"Adjust"_ustr);
921 XMLTimeFieldImportContext::XMLTimeFieldImportContext(
922 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
923 : XMLTextFieldImportContext(rImport, rHlp, sAPI_date_time)
924 , sPropertyNumberFormat(sAPI_number_format)
925 , sPropertyFixed(sAPI_is_fixed)
926 , sPropertyDateTimeValue(sAPI_date_time_value)
927 , sPropertyDateTime(sAPI_date_time)
928 , sPropertyIsDate(sAPI_is_date)
929 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
930 , nAdjust(0)
931 , nFormatKey(0)
932 , bTimeOK(false)
933 , bFormatOK(false)
934 , bFixed(false)
935 , bIsDate(false)
936 , bIsDefaultLanguage( true )
938 bValid = true; // always valid!
941 void XMLTimeFieldImportContext::ProcessAttribute(
942 sal_Int32 nAttrToken, std::string_view sAttrValue )
944 switch (nAttrToken)
946 case XML_ELEMENT(TEXT, XML_TIME_VALUE):
947 case XML_ELEMENT(OFFICE, XML_TIME_VALUE):
949 if (::sax::Converter::parseTimeOrDateTime(aDateTimeValue, sAttrValue))
951 bTimeOK = true;
953 break;
955 case XML_ELEMENT(TEXT, XML_FIXED):
957 bool bTmp(false);
958 if (::sax::Converter::convertBool(bTmp, sAttrValue))
960 bFixed = bTmp;
962 break;
964 case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME):
966 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
967 OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage);
968 if (-1 != nKey)
970 nFormatKey = nKey;
971 bFormatOK = true;
973 break;
975 case XML_ELEMENT(TEXT, XML_TIME_ADJUST):
977 double fTmp;
979 if (::sax::Converter::convertDuration(fTmp, sAttrValue))
981 // convert to minutes
982 nAdjust = static_cast<sal_Int32>(::rtl::math::approxFloor(fTmp * 60 * 24));
984 break;
986 default:
987 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
991 void XMLTimeFieldImportContext::PrepareField(
992 const Reference<XPropertySet> & rPropertySet)
994 // all properties are optional (except IsDate)
995 Reference<XPropertySetInfo> xPropertySetInfo(
996 rPropertySet->getPropertySetInfo());
998 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1000 rPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
1003 rPropertySet->setPropertyValue(sPropertyIsDate, Any(bIsDate));
1005 if (xPropertySetInfo->hasPropertyByName(gsPropertyAdjust))
1007 rPropertySet->setPropertyValue(gsPropertyAdjust, Any(nAdjust));
1010 // set value
1011 if (bFixed)
1013 // organizer or styles-only mode: force update
1014 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1015 GetImport().GetTextImport()->IsStylesOnlyMode() )
1017 ForceUpdate(rPropertySet);
1019 else
1021 // normal mode: set value (if present)
1022 if (bTimeOK)
1024 if (xPropertySetInfo->hasPropertyByName(sPropertyDateTimeValue))
1026 rPropertySet->setPropertyValue(sPropertyDateTimeValue, Any(aDateTimeValue));
1028 else if (xPropertySetInfo->hasPropertyByName(sPropertyDateTime))
1030 rPropertySet->setPropertyValue(sPropertyDateTime, Any(aDateTimeValue));
1036 if (bFormatOK &&
1037 xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1039 rPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormatKey));
1041 if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
1043 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1044 rPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1050 // date field
1053 XMLDateFieldImportContext::XMLDateFieldImportContext(
1054 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1055 XMLTimeFieldImportContext(rImport, rHlp)
1057 bIsDate = true; // always a date!
1060 void XMLDateFieldImportContext::ProcessAttribute(
1061 sal_Int32 nAttrToken,
1062 std::string_view sAttrValue )
1064 switch (nAttrToken)
1066 case XML_ELEMENT(TEXT, XML_DATE_VALUE):
1067 case XML_ELEMENT(OFFICE, XML_DATE_VALUE):
1069 if (::sax::Converter::parseDateTime(aDateTimeValue, sAttrValue))
1071 bTimeOK = true;
1073 break;
1075 case XML_ELEMENT(TEXT, XML_DATE_ADJUST):
1076 // delegate to superclass, pretending it was a time-adjust attr.
1077 XMLTimeFieldImportContext::ProcessAttribute(
1078 XML_ELEMENT(TEXT, XML_TIME_ADJUST),
1079 sAttrValue);
1080 break;
1081 case XML_ELEMENT(TEXT, XML_TIME_VALUE):
1082 case XML_ELEMENT(OFFICE, XML_TIME_VALUE):
1083 case XML_ELEMENT(TEXT, XML_TIME_ADJUST):
1084 ; // ignore time-adjust and time-value attributes
1085 break;
1086 default:
1087 // all others: delegate to super-class
1088 return XMLTimeFieldImportContext::ProcessAttribute(nAttrToken,
1089 sAttrValue);
1090 break;
1095 // database field superclass
1098 constexpr OUStringLiteral gsPropertyDataBaseName(u"DataBaseName");
1099 constexpr OUStringLiteral gsPropertyDataBaseURL(u"DataBaseURL");
1100 constexpr OUStringLiteral gsPropertyTableName(u"DataTableName");
1101 constexpr OUStringLiteral gsPropertyDataCommandType(u"DataCommandType");
1102 constexpr OUStringLiteral gsPropertyIsVisible(u"IsVisible");
1104 XMLDatabaseFieldImportContext::XMLDatabaseFieldImportContext(
1105 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1106 const OUString& pServiceName, bool bUseDisplay)
1107 : XMLTextFieldImportContext(rImport, rHlp, pServiceName)
1108 , m_nCommandType( sdb::CommandType::TABLE )
1109 , m_bCommandTypeOK(false)
1110 , m_bDisplay( true )
1111 , m_bDisplayOK( false )
1112 , m_bUseDisplay( bUseDisplay )
1113 , m_bDatabaseOK(false)
1114 , m_bDatabaseNameOK(false)
1115 , m_bDatabaseURLOK(false)
1116 , m_bTableOK(false)
1120 void XMLDatabaseFieldImportContext::ProcessAttribute(
1121 sal_Int32 nAttrToken, std::string_view sAttrValue )
1123 switch (nAttrToken)
1125 case XML_ELEMENT(TEXT, XML_DATABASE_NAME):
1126 m_sDatabaseName = OUString::fromUtf8(sAttrValue);
1127 m_bDatabaseOK = true;
1128 m_bDatabaseNameOK = true;
1129 break;
1130 case XML_ELEMENT(TEXT, XML_TABLE_NAME):
1131 m_sTableName = OUString::fromUtf8(sAttrValue);
1132 m_bTableOK = true;
1133 break;
1134 case XML_ELEMENT(TEXT, XML_TABLE_TYPE):
1135 if( IsXMLToken( sAttrValue, XML_TABLE ) )
1137 m_nCommandType = sdb::CommandType::TABLE;
1138 m_bCommandTypeOK = true;
1140 else if( IsXMLToken( sAttrValue, XML_QUERY ) )
1142 m_nCommandType = sdb::CommandType::QUERY;
1143 m_bCommandTypeOK = true;
1145 else if( IsXMLToken( sAttrValue, XML_COMMAND ) )
1147 m_nCommandType = sdb::CommandType::COMMAND;
1148 m_bCommandTypeOK = true;
1150 break;
1151 case XML_ELEMENT(TEXT, XML_DISPLAY):
1152 if( IsXMLToken( sAttrValue, XML_NONE ) )
1154 m_bDisplay = false;
1155 m_bDisplayOK = true;
1157 else if( IsXMLToken( sAttrValue, XML_VALUE ) )
1159 m_bDisplay = true;
1160 m_bDisplayOK = true;
1162 break;
1163 default:
1164 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1168 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDatabaseFieldImportContext::createFastChildContext(
1169 sal_Int32 nElement,
1170 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1172 if (nElement == XML_ELEMENT(FORM, XML_CONNECTION_RESOURCE) )
1174 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
1176 switch (aIter.getToken())
1178 case XML_ELEMENT(XLINK, XML_HREF):
1180 m_sDatabaseURL = aIter.toString();
1181 m_bDatabaseOK = true;
1182 m_bDatabaseURLOK = true;
1184 break;
1185 default:;
1189 // we call ProcessAttribute in order to set bValid appropriately
1190 ProcessAttribute( XML_TOKEN_INVALID, "" );
1192 else
1193 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1195 return nullptr;
1199 void XMLDatabaseFieldImportContext::PrepareField(
1200 const Reference<XPropertySet> & xPropertySet)
1202 xPropertySet->setPropertyValue(gsPropertyTableName, Any(m_sTableName));
1204 if( m_bDatabaseNameOK )
1206 xPropertySet->setPropertyValue(gsPropertyDataBaseName, Any(m_sDatabaseName));
1208 else if( m_bDatabaseURLOK )
1210 xPropertySet->setPropertyValue(gsPropertyDataBaseURL, Any(m_sDatabaseURL));
1213 // #99980# load/save command type for all fields; also load
1214 // old documents without command type
1215 if( m_bCommandTypeOK )
1217 xPropertySet->setPropertyValue( gsPropertyDataCommandType, Any(m_nCommandType) );
1220 if( m_bUseDisplay && m_bDisplayOK )
1222 xPropertySet->setPropertyValue( gsPropertyIsVisible, Any(m_bDisplay) );
1227 // database name field
1230 XMLDatabaseNameImportContext::XMLDatabaseNameImportContext(
1231 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1232 XMLDatabaseFieldImportContext(rImport, rHlp, "DatabaseName", true)
1236 void XMLDatabaseNameImportContext::ProcessAttribute(
1237 sal_Int32 nAttrToken, std::string_view sAttrValue )
1239 // delegate to superclass and check for success
1240 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1241 bValid = m_bDatabaseOK && m_bTableOK;
1245 // database next field
1248 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1249 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1250 const OUString& pServiceName) :
1251 XMLDatabaseFieldImportContext(rImport, rHlp, pServiceName, false),
1252 sPropertyCondition(sAPI_condition),
1253 sTrue(sAPI_true),
1254 bConditionOK(false)
1258 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1259 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
1260 : XMLDatabaseFieldImportContext(rImport, rHlp, "DatabaseNextSet", false)
1261 , sPropertyCondition(sAPI_condition)
1262 , sTrue(sAPI_true)
1263 , bConditionOK(false)
1267 void XMLDatabaseNextImportContext::ProcessAttribute(
1268 sal_Int32 nAttrToken, std::string_view sAttrValue )
1270 if (XML_ELEMENT(TEXT, XML_CONDITION) == nAttrToken)
1272 OUString sTmp;
1273 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrValueQName(
1274 OUString::fromUtf8(sAttrValue), &sTmp );
1275 if( XML_NAMESPACE_OOOW == nPrefix )
1277 sCondition = sTmp;
1278 bConditionOK = true;
1280 else
1281 sCondition = OUString::fromUtf8(sAttrValue);
1283 else
1285 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1286 sAttrValue);
1289 bValid = m_bDatabaseOK && m_bTableOK;
1292 void XMLDatabaseNextImportContext::PrepareField(
1293 const Reference<XPropertySet> & xPropertySet)
1295 Any aAny;
1297 aAny <<= bConditionOK ? sCondition : sTrue;
1298 xPropertySet->setPropertyValue(sPropertyCondition, aAny);
1300 XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1304 // database select field
1307 XMLDatabaseSelectImportContext::XMLDatabaseSelectImportContext(
1308 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1309 XMLDatabaseNextImportContext(rImport, rHlp, "DatabaseNumberOfSet"),
1310 sPropertySetNumber(sAPI_set_number),
1311 nNumber(0),
1312 bNumberOK(false)
1316 void XMLDatabaseSelectImportContext::ProcessAttribute(
1317 sal_Int32 nAttrToken,
1318 std::string_view sAttrValue )
1320 if (XML_ELEMENT(TEXT, XML_ROW_NUMBER) == nAttrToken)
1322 sal_Int32 nTmp;
1323 if (::sax::Converter::convertNumber( nTmp, sAttrValue
1324 /* , nMin, nMax ??? */ ))
1326 nNumber = nTmp;
1327 bNumberOK = true;
1330 else
1332 XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1335 bValid = m_bTableOK && m_bDatabaseOK && bNumberOK;
1338 void XMLDatabaseSelectImportContext::PrepareField(
1339 const Reference<XPropertySet> & xPropertySet)
1341 xPropertySet->setPropertyValue(sPropertySetNumber, Any(nNumber));
1343 XMLDatabaseNextImportContext::PrepareField(xPropertySet);
1347 // database display row number field
1350 XMLDatabaseNumberImportContext::XMLDatabaseNumberImportContext(
1351 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1352 XMLDatabaseFieldImportContext(rImport, rHlp, "DatabaseSetNumber", true),
1353 sPropertyNumberingType(
1354 sAPI_numbering_type),
1355 sPropertySetNumber(sAPI_set_number),
1356 sNumberFormat("1"),
1357 sNumberSync(GetXMLToken(XML_FALSE)),
1358 nValue(0),
1359 bValueOK(false)
1363 void XMLDatabaseNumberImportContext::ProcessAttribute(
1364 sal_Int32 nAttrToken,
1365 std::string_view sAttrValue )
1367 switch (nAttrToken)
1369 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
1370 sNumberFormat = OUString::fromUtf8(sAttrValue);
1371 break;
1372 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
1373 sNumberSync = OUString::fromUtf8(sAttrValue);
1374 break;
1375 case XML_ELEMENT(TEXT, XML_VALUE_TYPE):
1376 case XML_ELEMENT(OFFICE, XML_VALUE_TYPE):
1378 sal_Int32 nTmp;
1379 if (::sax::Converter::convertNumber( nTmp, sAttrValue ))
1381 nValue = nTmp;
1382 bValueOK = true;
1384 break;
1386 default:
1387 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1388 sAttrValue);
1389 break;
1392 bValid = m_bTableOK && m_bDatabaseOK;
1395 void XMLDatabaseNumberImportContext::PrepareField(
1396 const Reference<XPropertySet> & xPropertySet)
1398 sal_Int16 nNumType = style::NumberingType::ARABIC;
1399 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
1400 sNumberFormat,
1401 sNumberSync );
1402 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
1404 if (bValueOK)
1406 xPropertySet->setPropertyValue(sPropertySetNumber, Any(nValue));
1409 XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1413 // Simple doc info fields
1416 XMLSimpleDocInfoImportContext::XMLSimpleDocInfoImportContext(
1417 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1418 sal_Int32 nElementToken,
1419 bool bContent, bool bAuthor)
1420 : XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nElementToken) )
1421 , sPropertyFixed(sAPI_is_fixed)
1422 , sPropertyContent(sAPI_content)
1423 , sPropertyAuthor(sAPI_author)
1424 , sPropertyCurrentPresentation(sAPI_current_presentation)
1425 , bFixed(false)
1426 , bHasAuthor(bAuthor)
1427 , bHasContent(bContent)
1429 bValid = true;
1432 void XMLSimpleDocInfoImportContext::ProcessAttribute(
1433 sal_Int32 nAttrToken,
1434 std::string_view sAttrValue )
1436 if (XML_ELEMENT(TEXT, XML_FIXED) == nAttrToken)
1438 bool bTmp(false);
1439 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1441 bFixed = bTmp;
1444 else
1445 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1448 void XMLSimpleDocInfoImportContext::PrepareField(
1449 const Reference<XPropertySet> & rPropertySet)
1451 // title field in Calc has no Fixed property
1452 Reference<XPropertySetInfo> xPropertySetInfo(rPropertySet->getPropertySetInfo());
1453 if (!xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1454 return;
1456 Any aAny;
1457 rPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
1459 // set Content and CurrentPresentation (if fixed)
1460 if (!bFixed)
1461 return;
1463 // in organizer-mode or styles-only-mode, only force update
1464 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1465 GetImport().GetTextImport()->IsStylesOnlyMode() )
1467 ForceUpdate(rPropertySet);
1469 else
1471 // set content (author, if that's the name) and current
1472 // presentation
1473 aAny <<= GetContent();
1475 if (bFixed && bHasAuthor)
1477 rPropertySet->setPropertyValue(sPropertyAuthor, aAny);
1480 if (bFixed && bHasContent)
1482 rPropertySet->setPropertyValue(sPropertyContent, aAny);
1485 rPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
1489 OUString XMLSimpleDocInfoImportContext::MapTokenToServiceName(
1490 sal_Int32 nElementToken)
1492 OUString pServiceName;
1494 switch(nElementToken)
1496 case XML_ELEMENT(TEXT, XML_INITIAL_CREATOR):
1497 pServiceName = "DocInfo.CreateAuthor";
1498 break;
1499 case XML_ELEMENT(TEXT, XML_CREATION_DATE):
1500 pServiceName = sAPI_docinfo_create_date_time;
1501 break;
1502 case XML_ELEMENT(TEXT, XML_CREATION_TIME):
1503 pServiceName = sAPI_docinfo_create_date_time;
1504 break;
1505 case XML_ELEMENT(TEXT, XML_DESCRIPTION):
1506 pServiceName = "DocInfo.Description";
1507 break;
1508 case XML_ELEMENT(TEXT, XML_EDITING_DURATION):
1509 pServiceName = "DocInfo.EditTime";
1510 break;
1511 case XML_ELEMENT(TEXT, XML_USER_DEFINED):
1512 pServiceName = sAPI_docinfo_custom;
1513 break;
1514 case XML_ELEMENT(TEXT, XML_PRINTED_BY):
1515 pServiceName = "DocInfo.PrintAuthor";
1516 break;
1517 case XML_ELEMENT(TEXT, XML_PRINT_DATE):
1518 pServiceName = sAPI_docinfo_print_date_time;
1519 break;
1520 case XML_ELEMENT(TEXT, XML_PRINT_TIME):
1521 pServiceName = sAPI_docinfo_print_date_time;
1522 break;
1523 case XML_ELEMENT(TEXT, XML_KEYWORDS):
1524 pServiceName = "DocInfo.KeyWords";
1525 break;
1526 case XML_ELEMENT(TEXT, XML_SUBJECT):
1527 pServiceName = "DocInfo.Subject";
1528 break;
1529 case XML_ELEMENT(TEXT, XML_EDITING_CYCLES):
1530 pServiceName = "DocInfo.Revision";
1531 break;
1532 case XML_ELEMENT(TEXT, XML_CREATOR):
1533 pServiceName = "DocInfo.ChangeAuthor";
1534 break;
1535 case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE):
1536 pServiceName = sAPI_docinfo_change_date_time;
1537 break;
1538 case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME):
1539 pServiceName = sAPI_docinfo_change_date_time;
1540 break;
1541 case XML_ELEMENT(TEXT, XML_TITLE):
1542 pServiceName = "DocInfo.Title";
1543 break;
1544 default:
1545 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElementToken);
1546 assert(false);
1549 return pServiceName;
1553 // revision field
1555 constexpr OUStringLiteral sPropertyRevision(u"Revision");
1557 XMLRevisionDocInfoImportContext::XMLRevisionDocInfoImportContext(
1558 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_Int32 nElement) :
1559 XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false)
1561 bValid = true;
1564 void XMLRevisionDocInfoImportContext::PrepareField(
1565 const Reference<XPropertySet> & rPropertySet)
1567 XMLSimpleDocInfoImportContext::PrepareField(rPropertySet);
1569 // set revision number
1570 // if fixed, if not in organizer-mode, if not in styles-only-mode
1571 if (!bFixed)
1572 return;
1574 if ( GetImport().GetTextImport()->IsOrganizerMode() ||
1575 GetImport().GetTextImport()->IsStylesOnlyMode() )
1577 ForceUpdate(rPropertySet);
1579 else
1581 sal_Int32 nTmp;
1582 if (::sax::Converter::convertNumber(nTmp, GetContent()))
1584 rPropertySet->setPropertyValue(sPropertyRevision, Any(nTmp));
1590 // DocInfo fields with date/time attributes
1593 XMLDateTimeDocInfoImportContext::XMLDateTimeDocInfoImportContext(
1594 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_Int32 nElement)
1595 : XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false)
1596 , sPropertyNumberFormat(sAPI_number_format)
1597 , sPropertyIsDate(sAPI_is_date)
1598 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1599 , nFormat(0)
1600 , bFormatOK(false)
1601 , bIsDate(false)
1602 , bHasDateTime(false)
1603 , bIsDefaultLanguage(true)
1605 // we allow processing of EDIT_DURATION here, because import of actual
1606 // is not supported anyway. If it was, we'd need an extra import class
1607 // because times and time durations are presented differently!
1609 bValid = true;
1610 switch (nElement)
1612 case XML_ELEMENT(TEXT, XML_CREATION_DATE):
1613 case XML_ELEMENT(TEXT, XML_PRINT_DATE):
1614 case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE):
1615 bIsDate = true;
1616 bHasDateTime = true;
1617 break;
1618 case XML_ELEMENT(TEXT, XML_CREATION_TIME):
1619 case XML_ELEMENT(TEXT, XML_PRINT_TIME):
1620 case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME):
1621 bIsDate = false;
1622 bHasDateTime = true;
1623 break;
1624 case XML_ELEMENT(TEXT, XML_EDITING_DURATION):
1625 bIsDate = false;
1626 bHasDateTime = false;
1627 break;
1628 default:
1629 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1630 OSL_FAIL("XMLDateTimeDocInfoImportContext needs date/time doc. fields");
1631 bValid = false;
1632 break;
1636 void XMLDateTimeDocInfoImportContext::ProcessAttribute(
1637 sal_Int32 nAttrToken,
1638 std::string_view sAttrValue )
1640 switch (nAttrToken)
1642 case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME):
1644 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1645 OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage);
1646 if (-1 != nKey)
1648 nFormat = nKey;
1649 bFormatOK = true;
1651 break;
1653 case XML_ELEMENT(TEXT, XML_FIXED):
1654 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1655 sAttrValue);
1656 break;
1657 default:
1658 // ignore -> we can't set date/time value anyway!
1659 break;
1663 void XMLDateTimeDocInfoImportContext::PrepareField(
1664 const Reference<XPropertySet> & xPropertySet)
1666 // process fixed and presentation
1667 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
1669 if (bHasDateTime)
1671 xPropertySet->setPropertyValue(sPropertyIsDate, Any(bIsDate));
1674 if (bFormatOK)
1676 xPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormat));
1678 if( xPropertySet->getPropertySetInfo()->
1679 hasPropertyByName( sPropertyIsFixedLanguage ) )
1681 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1682 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1686 // can't set date/time/duration value! Sorry.
1690 // user defined docinfo fields
1693 XMLUserDocInfoImportContext::XMLUserDocInfoImportContext(
1694 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1695 sal_Int32 nElement) :
1696 XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false)
1697 , sPropertyName(sAPI_name)
1698 , sPropertyNumberFormat(sAPI_number_format)
1699 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1700 , nFormat(0)
1701 , bFormatOK(false)
1702 , bIsDefaultLanguage( true )
1704 bValid = false;
1707 void XMLUserDocInfoImportContext::ProcessAttribute(
1708 sal_Int32 nAttrToken,
1709 std::string_view sAttrValue )
1711 switch (nAttrToken)
1713 case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME):
1715 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1716 OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage);
1717 if (-1 != nKey)
1719 nFormat = nKey;
1720 bFormatOK = true;
1722 break;
1724 case XML_ELEMENT(TEXT, XML_NAME):
1726 if (!bValid)
1728 SetServiceName(sAPI_docinfo_custom );
1729 aName = OUString::fromUtf8(sAttrValue);
1730 bValid = true;
1732 break;
1735 default:
1736 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1737 sAttrValue);
1738 break;
1742 void XMLUserDocInfoImportContext::PrepareField(
1743 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet)
1745 if ( !aName.isEmpty() )
1747 xPropertySet->setPropertyValue(sPropertyName, Any(aName));
1749 Reference<XPropertySetInfo> xPropertySetInfo(
1750 xPropertySet->getPropertySetInfo());
1751 if (bFormatOK &&
1752 xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1754 xPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormat));
1756 if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
1758 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1759 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1763 // call superclass to handle "fixed"
1764 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
1768 // import hidden paragraph fields
1771 XMLHiddenParagraphImportContext::XMLHiddenParagraphImportContext(
1772 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1773 XMLTextFieldImportContext(rImport, rHlp, "HiddenParagraph"),
1774 sPropertyCondition(sAPI_condition),
1775 sPropertyIsHidden(sAPI_is_hidden),
1776 bIsHidden(false)
1780 void XMLHiddenParagraphImportContext::ProcessAttribute(
1781 sal_Int32 nAttrToken,
1782 std::string_view sAttrValue )
1784 if ( XML_ELEMENT(TEXT, XML_CONDITION) == nAttrToken)
1786 OUString sTmp;
1787 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrValueQName(
1788 OUString::fromUtf8(sAttrValue), &sTmp );
1789 if( XML_NAMESPACE_OOOW == nPrefix )
1791 sCondition = sTmp;
1792 bValid = true;
1794 else
1795 sCondition = OUString::fromUtf8(sAttrValue);
1797 else if ( XML_ELEMENT(TEXT, XML_IS_HIDDEN) == nAttrToken)
1799 bool bTmp(false);
1800 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1802 bIsHidden = bTmp;
1805 else
1806 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1809 void XMLHiddenParagraphImportContext::PrepareField(
1810 const Reference<XPropertySet> & xPropertySet)
1812 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
1813 xPropertySet->setPropertyValue(sPropertyIsHidden, Any(bIsHidden));
1817 // import conditional text (<text:conditional-text>)
1819 constexpr OUStringLiteral gsPropertyTrueContent(u"TrueContent");
1820 constexpr OUStringLiteral gsPropertyFalseContent(u"FalseContent");
1821 constexpr OUStringLiteral gsPropertyIsConditionTrue(u"IsConditionTrue");
1823 XMLConditionalTextImportContext::XMLConditionalTextImportContext(
1824 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1825 XMLTextFieldImportContext(rImport, rHlp, "ConditionalText"),
1826 sPropertyCondition(sAPI_condition),
1827 sPropertyCurrentPresentation(sAPI_current_presentation),
1828 bConditionOK(false),
1829 bTrueOK(false),
1830 bFalseOK(false),
1831 bCurrentValue(false)
1835 void XMLConditionalTextImportContext::ProcessAttribute(
1836 sal_Int32 nAttrToken,
1837 std::string_view sAttrValue )
1839 switch (nAttrToken)
1841 case XML_ELEMENT(TEXT, XML_CONDITION):
1843 OUString sTmp;
1844 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1845 GetKeyByAttrValueQName(OUString::fromUtf8(sAttrValue), &sTmp);
1846 if( XML_NAMESPACE_OOOW == nPrefix )
1848 sCondition = sTmp;
1849 bConditionOK = true;
1851 else
1852 sCondition = OUString::fromUtf8(sAttrValue);
1854 break;
1855 case XML_ELEMENT(TEXT, XML_STRING_VALUE_IF_FALSE):
1856 sFalseContent = OUString::fromUtf8(sAttrValue);
1857 bFalseOK = true;
1858 break;
1859 case XML_ELEMENT(TEXT, XML_STRING_VALUE_IF_TRUE):
1860 sTrueContent = OUString::fromUtf8(sAttrValue);
1861 bTrueOK = true;
1862 break;
1863 case XML_ELEMENT(TEXT, XML_CURRENT_VALUE):
1865 bool bTmp(false);
1866 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1868 bCurrentValue = bTmp;
1870 break;
1872 default:
1873 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1876 bValid = bConditionOK && bFalseOK && bTrueOK;
1879 void XMLConditionalTextImportContext::PrepareField(
1880 const Reference<XPropertySet> & xPropertySet)
1882 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
1883 xPropertySet->setPropertyValue(gsPropertyFalseContent, Any(sFalseContent));
1884 xPropertySet->setPropertyValue(gsPropertyTrueContent, Any(sTrueContent));
1885 xPropertySet->setPropertyValue(gsPropertyIsConditionTrue, Any(bCurrentValue));
1886 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, Any(GetContent()));
1890 // hidden text
1893 XMLHiddenTextImportContext::XMLHiddenTextImportContext(
1894 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1895 XMLTextFieldImportContext(rImport, rHlp, "HiddenText"),
1896 sPropertyCondition(sAPI_condition),
1897 sPropertyContent(sAPI_content),
1898 sPropertyIsHidden(sAPI_is_hidden),
1899 bConditionOK(false),
1900 bStringOK(false),
1901 bIsHidden(false)
1905 void XMLHiddenTextImportContext::ProcessAttribute(
1906 sal_Int32 nAttrToken,
1907 std::string_view sAttrValue )
1909 switch (nAttrToken)
1911 case XML_ELEMENT(TEXT, XML_CONDITION):
1913 OUString sTmp;
1914 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1915 GetKeyByAttrValueQName(OUString::fromUtf8(sAttrValue), &sTmp);
1916 if( XML_NAMESPACE_OOOW == nPrefix )
1918 sCondition = sTmp;
1919 bConditionOK = true;
1921 else
1922 sCondition = OUString::fromUtf8(sAttrValue);
1924 break;
1925 case XML_ELEMENT(TEXT, XML_STRING_VALUE):
1926 case XML_ELEMENT(OFFICE, XML_STRING_VALUE):
1927 sString = OUString::fromUtf8(sAttrValue);
1928 bStringOK = true;
1929 break;
1930 case XML_ELEMENT(TEXT, XML_IS_HIDDEN):
1932 bool bTmp(false);
1933 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1935 bIsHidden = bTmp;
1937 break;
1939 default:
1940 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1943 bValid = bConditionOK && bStringOK;
1946 void XMLHiddenTextImportContext::PrepareField(
1947 const Reference<XPropertySet> & xPropertySet)
1949 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
1950 xPropertySet->setPropertyValue(sPropertyContent, Any(sString));
1951 xPropertySet->setPropertyValue(sPropertyIsHidden, Any(bIsHidden));
1955 // file name fields
1958 const SvXMLEnumMapEntry<sal_uInt16> aFilenameDisplayMap[] =
1960 { XML_PATH, FilenameDisplayFormat::PATH },
1961 { XML_NAME, FilenameDisplayFormat::NAME },
1962 { XML_NAME_AND_EXTENSION, FilenameDisplayFormat::NAME_AND_EXT },
1963 { XML_FULL, FilenameDisplayFormat::FULL },
1964 { XML_TOKEN_INVALID, 0 }
1967 XMLFileNameImportContext::XMLFileNameImportContext(
1968 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1969 XMLTextFieldImportContext(rImport, rHlp, "FileName"),
1970 sPropertyFixed(sAPI_is_fixed),
1971 sPropertyFileFormat(sAPI_file_format),
1972 sPropertyCurrentPresentation(
1973 sAPI_current_presentation),
1974 nFormat(FilenameDisplayFormat::FULL),
1975 bFixed(false)
1977 bValid = true;
1980 void XMLFileNameImportContext::ProcessAttribute(
1981 sal_Int32 nAttrToken,
1982 std::string_view sAttrValue )
1984 switch (nAttrToken)
1986 case XML_ELEMENT(TEXT, XML_FIXED):
1988 bool bTmp(false);
1989 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1991 bFixed = bTmp;
1993 break;
1995 case XML_ELEMENT(TEXT, XML_DISPLAY):
1997 sal_uInt16 nTmp;
1998 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
1999 aFilenameDisplayMap))
2001 nFormat = nTmp;
2003 break;
2005 default:
2006 // unknown attribute: ignore
2007 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2008 break;
2012 void XMLFileNameImportContext::PrepareField(
2013 const Reference<XPropertySet> & xPropertySet)
2015 // properties are optional
2016 Reference<XPropertySetInfo> xPropertySetInfo(
2017 xPropertySet->getPropertySetInfo());
2019 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
2021 xPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
2024 if (xPropertySetInfo->hasPropertyByName(sPropertyFileFormat))
2026 xPropertySet->setPropertyValue(sPropertyFileFormat, Any(nFormat));
2029 if (xPropertySetInfo->hasPropertyByName(sPropertyCurrentPresentation))
2031 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, Any(GetContent()));
2036 // template name field
2039 const SvXMLEnumMapEntry<sal_uInt16> aTemplateDisplayMap[] =
2041 { XML_FULL, TemplateDisplayFormat::FULL },
2042 { XML_PATH, TemplateDisplayFormat::PATH },
2043 { XML_NAME, TemplateDisplayFormat::NAME },
2044 { XML_NAME_AND_EXTENSION, TemplateDisplayFormat::NAME_AND_EXT },
2045 { XML_AREA, TemplateDisplayFormat::AREA },
2046 { XML_TITLE, TemplateDisplayFormat::TITLE },
2047 { XML_TOKEN_INVALID, 0 }
2051 XMLTemplateNameImportContext::XMLTemplateNameImportContext(
2052 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2053 XMLTextFieldImportContext(rImport, rHlp, "TemplateName"),
2054 sPropertyFileFormat(sAPI_file_format),
2055 nFormat(TemplateDisplayFormat::FULL)
2057 bValid = true;
2060 void XMLTemplateNameImportContext::ProcessAttribute(
2061 sal_Int32 nAttrToken,
2062 std::string_view sAttrValue )
2064 switch (nAttrToken)
2066 case XML_ELEMENT(TEXT, XML_DISPLAY):
2068 sal_uInt16 nTmp;
2069 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2070 aTemplateDisplayMap))
2072 nFormat = nTmp;
2074 break;
2076 default:
2077 // unknown attribute: ignore
2078 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2079 break;
2083 void XMLTemplateNameImportContext::PrepareField(
2084 const Reference<XPropertySet> & xPropertySet)
2086 xPropertySet->setPropertyValue(sPropertyFileFormat, Any(nFormat));
2090 // import chapter fields
2093 const SvXMLEnumMapEntry<sal_uInt16> aChapterDisplayMap[] =
2095 { XML_NAME, ChapterFormat::NAME },
2096 { XML_NUMBER, ChapterFormat::NUMBER },
2097 { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
2098 { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
2099 { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
2100 { XML_TOKEN_INVALID, 0 }
2103 constexpr OUStringLiteral gsPropertyChapterFormat(u"ChapterFormat");
2104 constexpr OUStringLiteral gsPropertyLevel(u"Level");
2106 XMLChapterImportContext::XMLChapterImportContext(
2107 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2108 XMLTextFieldImportContext(rImport, rHlp, "Chapter"),
2109 nFormat(ChapterFormat::NAME_NUMBER),
2110 nLevel(0)
2112 bValid = true;
2115 void XMLChapterImportContext::ProcessAttribute(
2116 sal_Int32 nAttrToken,
2117 std::string_view sAttrValue )
2119 switch (nAttrToken)
2121 case XML_ELEMENT(TEXT, XML_DISPLAY):
2123 sal_uInt16 nTmp;
2124 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2125 aChapterDisplayMap))
2127 nFormat = static_cast<sal_Int16>(nTmp);
2129 break;
2131 case XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL):
2133 sal_Int32 nTmp;
2134 if (::sax::Converter::convertNumber(
2135 nTmp, sAttrValue, 1,
2136 GetImport().GetTextImport()->GetChapterNumbering()->getCount()
2139 // API numbers 0..9, we number 1..10
2140 nLevel = static_cast<sal_Int8>(nTmp);
2141 nLevel--;
2143 break;
2145 default:
2146 // unknown attribute: ignore
2147 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2148 break;
2152 void XMLChapterImportContext::PrepareField(
2153 const Reference<XPropertySet> & xPropertySet)
2155 xPropertySet->setPropertyValue(gsPropertyChapterFormat, Any(nFormat));
2156 xPropertySet->setPropertyValue(gsPropertyLevel, Any(nLevel));
2160 // counting fields
2163 XMLCountFieldImportContext::XMLCountFieldImportContext(
2164 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2165 sal_Int32 nElement) :
2166 XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nElement)),
2167 sPropertyNumberingType(
2168 sAPI_numbering_type),
2169 bNumberFormatOK(false)
2171 bValid = true;
2174 void XMLCountFieldImportContext::ProcessAttribute(
2175 sal_Int32 nAttrToken,
2176 std::string_view sAttrValue )
2178 switch (nAttrToken)
2180 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
2181 sNumberFormat = OUString::fromUtf8(sAttrValue);
2182 bNumberFormatOK = true;
2183 break;
2184 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
2185 sLetterSync = OUString::fromUtf8(sAttrValue);
2186 break;
2187 default:
2188 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2192 void XMLCountFieldImportContext::PrepareField(
2193 const Reference<XPropertySet> & xPropertySet)
2195 // properties optional
2196 // (only page count, but do for all to save common implementation)
2198 if (!xPropertySet->getPropertySetInfo()->
2199 hasPropertyByName(sPropertyNumberingType))
2200 return;
2202 sal_Int16 nNumType;
2203 if( bNumberFormatOK )
2205 nNumType= style::NumberingType::ARABIC;
2206 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2207 sNumberFormat,
2208 sLetterSync );
2210 else
2211 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2212 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
2215 OUString XMLCountFieldImportContext::MapTokenToServiceName(
2216 sal_Int32 nElement)
2218 OUString pServiceName;
2220 switch (nElement)
2222 case XML_ELEMENT(TEXT, XML_WORD_COUNT):
2223 pServiceName = "WordCount";
2224 break;
2225 case XML_ELEMENT(TEXT, XML_PARAGRAPH_COUNT):
2226 pServiceName = "ParagraphCount";
2227 break;
2228 case XML_ELEMENT(TEXT, XML_TABLE_COUNT):
2229 pServiceName = "TableCount";
2230 break;
2231 case XML_ELEMENT(TEXT, XML_CHARACTER_COUNT):
2232 pServiceName = "CharacterCount";
2233 break;
2234 case XML_ELEMENT(TEXT, XML_IMAGE_COUNT):
2235 pServiceName = "GraphicObjectCount";
2236 break;
2237 case XML_ELEMENT(TEXT, XML_OBJECT_COUNT):
2238 pServiceName = "EmbeddedObjectCount";
2239 break;
2240 case XML_ELEMENT(TEXT, XML_PAGE_COUNT):
2241 pServiceName = "PageCount";
2242 break;
2243 default:
2244 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
2245 assert(false);
2248 return pServiceName;
2252 // page variable import
2255 XMLPageVarGetFieldImportContext::XMLPageVarGetFieldImportContext(
2256 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2257 XMLTextFieldImportContext(rImport, rHlp, "ReferencePageGet"),
2258 bNumberFormatOK(false)
2260 bValid = true;
2263 void XMLPageVarGetFieldImportContext::ProcessAttribute(
2264 sal_Int32 nAttrToken,
2265 std::string_view sAttrValue )
2267 switch (nAttrToken)
2269 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
2270 sNumberFormat = OUString::fromUtf8(sAttrValue);
2271 bNumberFormatOK = true;
2272 break;
2273 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
2274 sLetterSync = OUString::fromUtf8(sAttrValue);
2275 break;
2276 default:
2277 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2281 void XMLPageVarGetFieldImportContext::PrepareField(
2282 const Reference<XPropertySet> & xPropertySet)
2284 sal_Int16 nNumType;
2285 if( bNumberFormatOK )
2287 nNumType= style::NumberingType::ARABIC;
2288 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2289 sNumberFormat,
2290 sLetterSync );
2292 else
2293 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2294 xPropertySet->setPropertyValue(sAPI_numbering_type, Any(nNumType));
2296 // display old content (#96657#)
2297 xPropertySet->setPropertyValue( sAPI_current_presentation, Any(GetContent()) );
2301 // page variable set fields
2304 XMLPageVarSetFieldImportContext::XMLPageVarSetFieldImportContext(
2305 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2306 XMLTextFieldImportContext(rImport, rHlp, "ReferencePageSet"),
2307 nAdjust(0),
2308 bActive(true)
2310 bValid = true;
2313 void XMLPageVarSetFieldImportContext::ProcessAttribute(
2314 sal_Int32 nAttrToken,
2315 std::string_view sAttrValue )
2317 switch (nAttrToken)
2319 case XML_ELEMENT(TEXT, XML_ACTIVE):
2321 bool bTmp(false);
2322 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2324 bActive = bTmp;
2326 break;
2328 case XML_ELEMENT(TEXT, XML_PAGE_ADJUST):
2330 sal_Int32 nTmp(0);
2331 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
2333 nAdjust = static_cast<sal_Int16>(nTmp);
2335 break;
2337 default:
2338 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2339 break;
2343 void XMLPageVarSetFieldImportContext::PrepareField(
2344 const Reference<XPropertySet> & xPropertySet)
2346 xPropertySet->setPropertyValue("On", Any(bActive));
2347 xPropertySet->setPropertyValue(sAPI_offset, Any(nAdjust));
2351 // macro fields
2354 XMLMacroFieldImportContext::XMLMacroFieldImportContext(
2355 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2356 XMLTextFieldImportContext(rImport, rHlp, "Macro"),
2357 bDescriptionOK(false)
2361 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLMacroFieldImportContext::createFastChildContext(
2362 sal_Int32 nElement,
2363 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
2365 if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
2367 // create events context and remember it!
2368 xEventContext = new XMLEventsImportContext( GetImport() );
2369 bValid = true;
2370 return xEventContext;
2372 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
2374 return nullptr;
2377 void XMLMacroFieldImportContext::ProcessAttribute(
2378 sal_Int32 nAttrToken,
2379 std::string_view sAttrValue )
2381 switch (nAttrToken)
2383 case XML_ELEMENT(TEXT, XML_DESCRIPTION):
2384 sDescription = OUString::fromUtf8(sAttrValue);
2385 bDescriptionOK = true;
2386 break;
2387 case XML_ELEMENT(TEXT, XML_NAME):
2388 sMacro = OUString::fromUtf8(sAttrValue);
2389 bValid = true;
2390 break;
2391 default:
2392 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2396 void XMLMacroFieldImportContext::PrepareField(
2397 const Reference<XPropertySet> & xPropertySet)
2399 Any aAny;
2400 aAny <<= (bDescriptionOK ? sDescription : GetContent());
2401 xPropertySet->setPropertyValue(sAPI_hint, aAny);
2403 // if we have an events child element, we'll look for the OnClick
2404 // event if not, it may be an old (pre-638i) document. Then, we'll
2405 // have to look at the name attribute.
2406 OUString sMacroName;
2407 OUString sLibraryName;
2408 OUString sScriptURL;
2410 if ( xEventContext.is() )
2412 // get event sequence
2413 XMLEventsImportContext* pEvents = xEventContext.get();
2414 Sequence<PropertyValue> aValues;
2415 pEvents->GetEventSequence( "OnClick", aValues );
2417 for( const auto& rValue : std::as_const(aValues) )
2419 if ( rValue.Name == "ScriptType" )
2421 // ignore ScriptType
2423 else if ( rValue.Name == "Library" )
2425 rValue.Value >>= sLibraryName;
2427 else if ( rValue.Name == "MacroName" )
2429 rValue.Value >>= sMacroName;
2431 if ( rValue.Name == "Script" )
2433 rValue.Value >>= sScriptURL;
2437 else
2439 // disassemble old-style macro-name: Everything before the
2440 // third-last dot is the library
2441 sal_Int32 nPos = sMacro.getLength() + 1; // the loop starts with nPos--
2442 const sal_Unicode* pBuf = sMacro.getStr();
2443 for( sal_Int32 i = 0; (i < 3) && (nPos > 0); i++ )
2445 nPos--;
2446 while ( (pBuf[nPos] != '.') && (nPos > 0) )
2447 nPos--;
2450 if (nPos > 0)
2452 sLibraryName = sMacro.copy(0, nPos);
2453 sMacroName = sMacro.copy(nPos+1);
2455 else
2456 sMacroName = sMacro;
2459 xPropertySet->setPropertyValue("ScriptURL", Any(sScriptURL));
2460 xPropertySet->setPropertyValue("MacroName", Any(sMacroName));
2461 xPropertySet->setPropertyValue("MacroLibrary", Any(sLibraryName));
2465 // reference field import
2468 XMLReferenceFieldImportContext::XMLReferenceFieldImportContext(
2469 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2470 sal_Int32 nToken)
2471 : XMLTextFieldImportContext(rImport, rHlp, "GetReference")
2472 , nElementToken(nToken)
2473 , nSource(0)
2474 , nType(ReferenceFieldPart::PAGE_DESC)
2475 , nFlags(0)
2476 , bNameOK(false)
2477 , bTypeOK(false)
2481 SvXMLEnumMapEntry<sal_uInt16> const lcl_aReferenceTypeTokenMap[] =
2483 { XML_PAGE, ReferenceFieldPart::PAGE},
2484 { XML_CHAPTER, ReferenceFieldPart::CHAPTER },
2485 { XML_TEXT, ReferenceFieldPart::TEXT },
2486 { XML_DIRECTION, ReferenceFieldPart::UP_DOWN },
2487 { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
2488 { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
2489 { XML_VALUE, ReferenceFieldPart::ONLY_SEQUENCE_NUMBER },
2490 // Core implementation for direct cross-references (#i81002#)
2491 { XML_NUMBER, ReferenceFieldPart::NUMBER },
2492 { XML_NUMBER_NO_SUPERIOR, ReferenceFieldPart::NUMBER_NO_CONTEXT },
2493 { XML_NUMBER_ALL_SUPERIOR, ReferenceFieldPart::NUMBER_FULL_CONTEXT },
2494 { XML_TOKEN_INVALID, 0 }
2497 void XMLReferenceFieldImportContext::startFastElement(
2498 sal_Int32 nElement,
2499 const Reference<XFastAttributeList> & xAttrList)
2501 bTypeOK = true;
2502 switch (nElementToken)
2504 case XML_ELEMENT(TEXT, XML_REFERENCE_REF):
2505 nSource = ReferenceFieldSource::REFERENCE_MARK;
2506 break;
2507 case XML_ELEMENT(TEXT, XML_BOOKMARK_REF):
2508 nSource = ReferenceFieldSource::BOOKMARK;
2509 break;
2510 case XML_ELEMENT(TEXT, XML_NOTE_REF):
2511 nSource = ReferenceFieldSource::FOOTNOTE;
2512 break;
2513 case XML_ELEMENT(TEXT, XML_SEQUENCE_REF):
2514 nSource = ReferenceFieldSource::SEQUENCE_FIELD;
2515 break;
2516 case XML_ELEMENT(TEXT, XML_STYLE_REF):
2517 case XML_ELEMENT(LO_EXT, XML_STYLE_REF):
2518 nSource = ReferenceFieldSource::STYLE;
2519 break;
2520 default:
2521 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElementToken);
2522 bTypeOK = false;
2523 break;
2526 XMLTextFieldImportContext::startFastElement(nElement, xAttrList);
2530 void XMLReferenceFieldImportContext::ProcessAttribute(
2531 sal_Int32 nAttrToken,
2532 std::string_view sAttrValue )
2534 switch (nAttrToken)
2536 case XML_ELEMENT(TEXT, XML_NOTE_CLASS):
2537 if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
2538 nSource = ReferenceFieldSource::ENDNOTE;
2539 break;
2540 case XML_ELEMENT(TEXT, XML_REF_NAME):
2541 sName = OUString::fromUtf8(sAttrValue);
2542 bNameOK = true;
2543 break;
2544 case XML_ELEMENT(TEXT, XML_REFERENCE_FORMAT):
2546 sal_uInt16 nToken;
2547 if (SvXMLUnitConverter::convertEnum(nToken, sAttrValue,
2548 lcl_aReferenceTypeTokenMap))
2550 nType = nToken;
2553 // check for sequence-only-attributes
2554 if ( (XML_ELEMENT(TEXT, XML_SEQUENCE_REF) != nElementToken) &&
2555 ( (nType == ReferenceFieldPart::CATEGORY_AND_NUMBER) ||
2556 (nType == ReferenceFieldPart::ONLY_CAPTION) ||
2557 (nType == ReferenceFieldPart::ONLY_SEQUENCE_NUMBER) ) )
2559 nType = ReferenceFieldPart::PAGE_DESC;
2562 break;
2564 case XML_ELEMENT(LO_EXT, XML_REFERENCE_LANGUAGE):
2565 case XML_ELEMENT(TEXT, XML_REFERENCE_LANGUAGE):
2566 sLanguage = OUString::fromUtf8(sAttrValue);
2567 break;
2568 case XML_ELEMENT(LO_EXT, XML_REFERENCE_HIDE_NON_NUMERICAL):
2569 case XML_ELEMENT(TEXT, XML_REFERENCE_HIDE_NON_NUMERICAL):
2570 if (OUString::fromUtf8(sAttrValue).toBoolean())
2571 nFlags |= REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL;
2572 break;
2573 case XML_ELEMENT(LO_EXT, XML_REFERENCE_FROM_BOTTOM):
2574 case XML_ELEMENT(TEXT, XML_REFERENCE_FROM_BOTTOM):
2575 if (OUString::fromUtf8(sAttrValue).toBoolean())
2576 nFlags |= REFFLDFLAG_STYLE_FROM_BOTTOM;
2577 break;
2578 default:
2579 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2582 // bValid: we need proper element type and name
2583 bValid = bTypeOK && bNameOK;
2586 void XMLReferenceFieldImportContext::PrepareField(
2587 const Reference<XPropertySet> & xPropertySet)
2589 xPropertySet->setPropertyValue("ReferenceFieldPart", Any(nType));
2591 xPropertySet->setPropertyValue("ReferenceFieldSource", Any(nSource));
2593 xPropertySet->setPropertyValue("ReferenceFieldLanguage", Any(sLanguage));
2594 switch (nElementToken)
2596 case XML_ELEMENT(TEXT, XML_REFERENCE_REF):
2597 case XML_ELEMENT(TEXT, XML_BOOKMARK_REF):
2598 case XML_ELEMENT(TEXT, XML_STYLE_REF):
2599 case XML_ELEMENT(LO_EXT, XML_STYLE_REF):
2600 xPropertySet->setPropertyValue("SourceName", Any(sName));
2601 xPropertySet->setPropertyValue("ReferenceFieldFlags", Any(nFlags));
2602 break;
2604 case XML_ELEMENT(TEXT, XML_NOTE_REF):
2605 GetImportHelper().ProcessFootnoteReference(sName, xPropertySet);
2606 break;
2608 case XML_ELEMENT(TEXT, XML_SEQUENCE_REF):
2609 GetImportHelper().ProcessSequenceReference(sName, xPropertySet);
2610 break;
2613 xPropertySet->setPropertyValue(sAPI_current_presentation, Any(GetContent()));
2617 // field declarations container
2619 XMLDdeFieldDeclsImportContext::XMLDdeFieldDeclsImportContext(SvXMLImport& rImport) :
2620 SvXMLImportContext(rImport)
2624 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDdeFieldDeclsImportContext::createFastChildContext(
2625 sal_Int32 nElement,
2626 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
2628 if ( nElement == XML_ELEMENT(TEXT, XML_DDE_CONNECTION_DECL) )
2630 return new XMLDdeFieldDeclImportContext(GetImport());
2632 else
2633 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
2634 return nullptr;
2638 // import dde field declaration
2641 XMLDdeFieldDeclImportContext::XMLDdeFieldDeclImportContext(SvXMLImport& rImport)
2642 : SvXMLImportContext(rImport)
2646 void XMLDdeFieldDeclImportContext::startFastElement(
2647 sal_Int32 /*nElement*/,
2648 const Reference<XFastAttributeList> & xAttrList)
2650 OUString sName;
2651 OUString sCommandApplication;
2652 OUString sCommandTopic;
2653 OUString sCommandItem;
2655 bool bUpdate = false;
2656 bool bNameOK = false;
2657 bool bCommandApplicationOK = false;
2658 bool bCommandTopicOK = false;
2659 bool bCommandItemOK = false;
2661 // process attributes
2662 for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
2664 switch (aIter.getToken())
2666 case XML_ELEMENT(OFFICE, XML_NAME):
2667 sName = aIter.toString();
2668 bNameOK = true;
2669 break;
2670 case XML_ELEMENT(OFFICE, XML_DDE_APPLICATION):
2671 sCommandApplication = aIter.toString();
2672 bCommandApplicationOK = true;
2673 break;
2674 case XML_ELEMENT(OFFICE, XML_DDE_TOPIC):
2675 sCommandTopic = aIter.toString();
2676 bCommandTopicOK = true;
2677 break;
2678 case XML_ELEMENT(OFFICE, XML_DDE_ITEM):
2679 sCommandItem = aIter.toString();
2680 bCommandItemOK = true;
2681 break;
2682 case XML_ELEMENT(OFFICE, XML_AUTOMATIC_UPDATE):
2684 bool bTmp(false);
2685 if (::sax::Converter::convertBool(bTmp, aIter.toView()) )
2687 bUpdate = bTmp;
2689 break;
2691 default:
2692 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
2696 // valid data?
2697 if (!(bNameOK && bCommandApplicationOK && bCommandTopicOK && bCommandItemOK))
2698 return;
2700 // create DDE TextFieldMaster
2701 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),
2702 UNO_QUERY);
2703 if( !xFactory.is() )
2704 return;
2706 /* #i6432# There might be multiple occurrences of one DDE
2707 declaration if it is used in more than one of
2708 header/footer/body. createInstance will throw an exception if we
2709 try to create the second, third, etc. instance of such a
2710 declaration. Thus we ignore the exception. Otherwise this will
2711 lead to an unloadable document. */
2714 Reference<XInterface> xIfc =
2715 xFactory->createInstance(OUString::Concat(sAPI_fieldmaster_prefix) + sAPI_dde);
2716 if( xIfc.is() )
2718 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
2719 if (xPropSet.is() &&
2720 xPropSet->getPropertySetInfo()->hasPropertyByName(
2721 "DDECommandType"))
2723 xPropSet->setPropertyValue(sAPI_name, Any(sName));
2725 xPropSet->setPropertyValue("DDECommandType", Any(sCommandApplication));
2727 xPropSet->setPropertyValue("DDECommandFile", Any(sCommandTopic));
2729 xPropSet->setPropertyValue("DDECommandElement",
2730 Any(sCommandItem));
2732 xPropSet->setPropertyValue("IsAutomaticUpdate",
2733 Any(bUpdate));
2735 // else: ignore (can't get XPropertySet, or DDE
2736 // properties are not supported)
2738 // else: ignore
2740 catch (const Exception&)
2742 //ignore
2744 // else: ignore
2745 // else: ignore
2749 // DDE field import
2752 XMLDdeFieldImportContext::XMLDdeFieldImportContext(
2753 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2754 XMLTextFieldImportContext(rImport, rHlp, sAPI_dde),
2755 sPropertyContent(sAPI_content)
2759 void XMLDdeFieldImportContext::ProcessAttribute(
2760 sal_Int32 nAttrToken,
2761 std::string_view sAttrValue )
2763 if ( XML_ELEMENT(TEXT, XML_CONNECTION_NAME) == nAttrToken)
2765 sName = OUString::fromUtf8(sAttrValue);
2766 bValid = true;
2768 else
2769 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2773 void XMLDdeFieldImportContext::endFastElement(sal_Int32 )
2775 if (!bValid)
2776 return;
2778 // find master
2779 OUString sMasterName = OUString::Concat(sAPI_fieldmaster_prefix) + sAPI_dde + "." + sName;
2781 Reference<XTextFieldsSupplier> xTextFieldsSupp(GetImport().GetModel(),
2782 UNO_QUERY);
2783 Reference<container::XNameAccess> xFieldMasterNameAccess =
2784 xTextFieldsSupp->getTextFieldMasters();
2786 if (!xFieldMasterNameAccess->hasByName(sMasterName))
2787 return;
2789 Reference<XPropertySet> xMaster;
2790 Any aAny = xFieldMasterNameAccess->getByName(sMasterName);
2791 aAny >>= xMaster;
2792 //apply the content to the master
2793 xMaster->setPropertyValue( sPropertyContent, uno::Any( GetContent()));
2794 // master exists: create text field and attach
2795 Reference<XPropertySet> xField;
2796 OUString sFieldName = OUString::Concat(sAPI_textfield_prefix) + sAPI_dde;
2797 if (!CreateField(xField, sFieldName))
2798 return;
2800 Reference<XDependentTextField> xDepTextField(xField,UNO_QUERY);
2801 xDepTextField->attachTextFieldMaster(xMaster);
2803 // attach field to document
2804 Reference<XTextContent> xTextContent(xField, UNO_QUERY);
2805 if (xTextContent.is())
2807 GetImportHelper().InsertTextContent(xTextContent);
2809 // we're lucky. nothing else to prepare.
2811 // else: fail, because text content could not be created
2812 // else: fail, because field could not be created
2813 // else: fail, because no master was found (faulty document?!)
2814 // not valid: ignore
2817 void XMLDdeFieldImportContext::PrepareField(
2818 const Reference<XPropertySet> &)
2820 // empty, since not needed.
2824 // sheet name fields
2827 XMLSheetNameImportContext::XMLSheetNameImportContext(
2828 SvXMLImport& rImport,
2829 XMLTextImportHelper& rHlp) :
2830 XMLTextFieldImportContext(rImport, rHlp, "SheetName")
2832 bValid = true; // always valid!
2835 void XMLSheetNameImportContext::ProcessAttribute(
2836 sal_Int32 nAttrToken,
2837 std::string_view sAttrValue)
2839 // no attributes -> nothing to be done
2840 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2843 void XMLSheetNameImportContext::PrepareField(
2844 const Reference<XPropertySet> &)
2846 // no attributes -> nothing to be done
2849 /** import page|slide name fields (<text:page-name>) */
2851 XMLPageNameFieldImportContext::XMLPageNameFieldImportContext(
2852 SvXMLImport& rImport, /// XML Import
2853 XMLTextImportHelper& rHlp) /// Text import helper
2854 : XMLTextFieldImportContext(rImport, rHlp, "PageName" )
2856 bValid = true;
2859 /// process attribute values
2860 void XMLPageNameFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken,
2861 std::string_view sAttrValue )
2863 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2866 /// prepare XTextField for insertion into document
2867 void XMLPageNameFieldImportContext::PrepareField(
2868 const css::uno::Reference<css::beans::XPropertySet> &)
2873 // URL fields (Calc, Impress, Draw)
2876 XMLUrlFieldImportContext::XMLUrlFieldImportContext(
2877 SvXMLImport& rImport,
2878 XMLTextImportHelper& rHlp) :
2879 XMLTextFieldImportContext(rImport, rHlp, sAPI_url),
2880 bFrameOK(false)
2884 void XMLUrlFieldImportContext::ProcessAttribute(
2885 sal_Int32 nAttrToken,
2886 std::string_view sAttrValue )
2888 switch (nAttrToken)
2890 case XML_ELEMENT(XLINK, XML_HREF):
2891 sURL = GetImport().GetAbsoluteReference( OUString::fromUtf8(sAttrValue) );
2892 bValid = true;
2893 break;
2894 case XML_ELEMENT(OFFICE, XML_TARGET_FRAME_NAME):
2895 sFrame = OUString::fromUtf8(sAttrValue);
2896 bFrameOK = true;
2897 break;
2898 default:
2899 // ignore
2900 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2901 break;
2905 void XMLUrlFieldImportContext::PrepareField(
2906 const Reference<XPropertySet> & xPropertySet)
2908 xPropertySet->setPropertyValue(sAPI_url, Any(sURL));
2910 if (bFrameOK)
2912 xPropertySet->setPropertyValue("TargetFrame", Any(sFrame));
2915 xPropertySet->setPropertyValue("Representation", Any(GetContent()));
2919 XMLBibliographyFieldImportContext::XMLBibliographyFieldImportContext(
2920 SvXMLImport& rImport,
2921 XMLTextImportHelper& rHlp) :
2922 XMLTextFieldImportContext(rImport, rHlp, "Bibliography")
2924 bValid = true;
2927 // TODO: this is the same map as is used in the text field export
2928 SvXMLEnumMapEntry<sal_uInt16> const aBibliographyDataTypeMap[] =
2930 { XML_ARTICLE, BibliographyDataType::ARTICLE },
2931 { XML_BOOK, BibliographyDataType::BOOK },
2932 { XML_BOOKLET, BibliographyDataType::BOOKLET },
2933 { XML_CONFERENCE, BibliographyDataType::CONFERENCE },
2934 { XML_CUSTOM1, BibliographyDataType::CUSTOM1 },
2935 { XML_CUSTOM2, BibliographyDataType::CUSTOM2 },
2936 { XML_CUSTOM3, BibliographyDataType::CUSTOM3 },
2937 { XML_CUSTOM4, BibliographyDataType::CUSTOM4 },
2938 { XML_CUSTOM5, BibliographyDataType::CUSTOM5 },
2939 { XML_EMAIL, BibliographyDataType::EMAIL },
2940 { XML_INBOOK, BibliographyDataType::INBOOK },
2941 { XML_INCOLLECTION, BibliographyDataType::INCOLLECTION },
2942 { XML_INPROCEEDINGS, BibliographyDataType::INPROCEEDINGS },
2943 { XML_JOURNAL, BibliographyDataType::JOURNAL },
2944 { XML_MANUAL, BibliographyDataType::MANUAL },
2945 { XML_MASTERSTHESIS, BibliographyDataType::MASTERSTHESIS },
2946 { XML_MISC, BibliographyDataType::MISC },
2947 { XML_PHDTHESIS, BibliographyDataType::PHDTHESIS },
2948 { XML_PROCEEDINGS, BibliographyDataType::PROCEEDINGS },
2949 { XML_TECHREPORT, BibliographyDataType::TECHREPORT },
2950 { XML_UNPUBLISHED, BibliographyDataType::UNPUBLISHED },
2951 { XML_WWW, BibliographyDataType::WWW },
2952 { XML_TOKEN_INVALID, 0 }
2956 // we'll process attributes on our own and for fit the standard
2957 // textfield mechanism, because our attributes have zero overlap with
2958 // all the other textfields.
2959 void XMLBibliographyFieldImportContext::startFastElement(
2960 sal_Int32 /*nElement*/,
2961 const Reference<XFastAttributeList> & xAttrList)
2963 // iterate over attributes
2964 for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
2966 if (IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_TEXT)
2967 || IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_LO_EXT))
2969 auto nToken = aIter.getToken() & TOKEN_MASK;
2970 PropertyValue aValue;
2971 aValue.Name = OUString::createFromAscii(
2972 MapBibliographyFieldName(nToken));
2973 Any aAny;
2975 // special treatment for bibliography type
2976 // biblio vs bibilio: #96658#; also read old documents
2977 if (nToken == XML_BIBILIOGRAPHIC_TYPE ||
2978 nToken == XML_BIBLIOGRAPHY_TYPE )
2980 sal_uInt16 nTmp;
2981 if (SvXMLUnitConverter::convertEnum(
2982 nTmp, aIter.toView(),
2983 aBibliographyDataTypeMap))
2985 aAny <<= static_cast<sal_Int16>(nTmp);
2986 aValue.Value = aAny;
2988 aValues.push_back(aValue);
2991 else
2993 OUString aStringValue = aIter.toString();
2994 if (nToken == XML_URL || nToken == XML_LOCAL_URL || nToken == XML_TARGET_URL)
2996 aStringValue = GetImport().GetAbsoluteReference(aStringValue);
2998 aAny <<= aStringValue;
2999 aValue.Value = aAny;
3001 aValues.push_back(aValue);
3004 // else: unknown namespace -> ignore
3008 void XMLBibliographyFieldImportContext::ProcessAttribute(
3009 sal_Int32 ,
3010 std::string_view )
3012 // attributes are handled in StartElement
3013 assert(false && "This should not have happened.");
3017 void XMLBibliographyFieldImportContext::PrepareField(
3018 const Reference<XPropertySet> & xPropertySet)
3020 // convert vector into sequence
3021 sal_Int32 nCount = aValues.size();
3022 Sequence<PropertyValue> aValueSequence(nCount);
3023 auto aValueSequenceRange = asNonConstRange(aValueSequence);
3024 for(sal_Int32 i = 0; i < nCount; i++)
3026 aValueSequenceRange[i] = aValues[i];
3029 // set sequence
3030 xPropertySet->setPropertyValue("Fields", Any(aValueSequence));
3033 const char* XMLBibliographyFieldImportContext::MapBibliographyFieldName(
3034 sal_Int32 nElement)
3036 const char* pName = nullptr;
3038 switch (nElement & TOKEN_MASK)
3040 case XML_IDENTIFIER:
3041 pName = "Identifier";
3042 break;
3043 case XML_BIBILIOGRAPHIC_TYPE:
3044 case XML_BIBLIOGRAPHY_TYPE:
3045 // biblio... vs bibilio...: #96658#: also read old documents
3046 pName = "BibiliographicType";
3047 break;
3048 case XML_ADDRESS:
3049 pName = "Address";
3050 break;
3051 case XML_ANNOTE:
3052 pName = "Annote";
3053 break;
3054 case XML_AUTHOR:
3055 pName = "Author";
3056 break;
3057 case XML_BOOKTITLE:
3058 pName = "Booktitle";
3059 break;
3060 case XML_CHAPTER:
3061 pName = "Chapter";
3062 break;
3063 case XML_EDITION:
3064 pName = "Edition";
3065 break;
3066 case XML_EDITOR:
3067 pName = "Editor";
3068 break;
3069 case XML_HOWPUBLISHED:
3070 pName = "Howpublished";
3071 break;
3072 case XML_INSTITUTION:
3073 pName = "Institution";
3074 break;
3075 case XML_JOURNAL:
3076 pName = "Journal";
3077 break;
3078 case XML_MONTH:
3079 pName = "Month";
3080 break;
3081 case XML_NOTE:
3082 pName = "Note";
3083 break;
3084 case XML_NUMBER:
3085 pName = "Number";
3086 break;
3087 case XML_ORGANIZATIONS:
3088 pName = "Organizations";
3089 break;
3090 case XML_PAGES:
3091 pName = "Pages";
3092 break;
3093 case XML_PUBLISHER:
3094 pName = "Publisher";
3095 break;
3096 case XML_SCHOOL:
3097 pName = "School";
3098 break;
3099 case XML_SERIES:
3100 pName = "Series";
3101 break;
3102 case XML_TITLE:
3103 pName = "Title";
3104 break;
3105 case XML_REPORT_TYPE:
3106 pName = "Report_Type";
3107 break;
3108 case XML_VOLUME:
3109 pName = "Volume";
3110 break;
3111 case XML_YEAR:
3112 pName = "Year";
3113 break;
3114 case XML_URL:
3115 pName = "URL";
3116 break;
3117 case XML_CUSTOM1:
3118 pName = "Custom1";
3119 break;
3120 case XML_CUSTOM2:
3121 pName = "Custom2";
3122 break;
3123 case XML_CUSTOM3:
3124 pName = "Custom3";
3125 break;
3126 case XML_CUSTOM4:
3127 pName = "Custom4";
3128 break;
3129 case XML_CUSTOM5:
3130 pName = "Custom5";
3131 break;
3132 case XML_ISBN:
3133 pName = "ISBN";
3134 break;
3135 case XML_LOCAL_URL:
3136 pName = "LocalURL";
3137 break;
3138 case XML_TARGET_TYPE:
3139 pName = "TargetType";
3140 break;
3141 case XML_TARGET_URL:
3142 pName = "TargetURL";
3143 break;
3144 default:
3145 assert(false && "Unknown bibliography info data");
3146 pName = nullptr;
3148 return pName;
3151 // Annotation Field
3154 XMLAnnotationImportContext::XMLAnnotationImportContext(
3155 SvXMLImport& rImport,
3156 XMLTextImportHelper& rHlp,
3157 sal_Int32 nElement) :
3158 XMLTextFieldImportContext(rImport, rHlp, "Annotation"),
3159 mnElement(nElement)
3161 bValid = true;
3163 // remember old list item and block (#91964#) and reset them
3164 // for the text frame
3165 // do this in the constructor, not in CreateChildContext (#i93392#)
3166 GetImport().GetTextImport()->PushListContext();
3169 void XMLAnnotationImportContext::ProcessAttribute(
3170 sal_Int32 nAttrToken,
3171 std::string_view sAttrValue )
3173 if (nAttrToken == XML_ELEMENT(OFFICE, XML_NAME))
3174 aName = OUString::fromUtf8(sAttrValue);
3175 else if (nAttrToken == XML_ELEMENT(LO_EXT, XML_RESOLVED))
3176 aResolved = OUString::fromUtf8(sAttrValue);
3177 else if (nAttrToken == XML_ELEMENT(LO_EXT, XML_PARENT_NAME))
3178 aParentName = OUString::fromUtf8(sAttrValue);
3179 else
3180 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3183 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLAnnotationImportContext::createFastChildContext(
3184 sal_Int32 nElement,
3185 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList )
3187 if( nElement == XML_ELEMENT(DC, XML_CREATOR) )
3188 return new XMLStringBufferImportContext(GetImport(), aAuthorBuffer);
3189 else if( nElement == XML_ELEMENT(DC, XML_DATE) )
3190 return new XMLStringBufferImportContext(GetImport(), aDateBuffer);
3191 else if (nElement == XML_ELEMENT(TEXT,XML_SENDER_INITIALS) ||
3192 nElement == XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS) ||
3193 nElement == XML_ELEMENT(META, XML_CREATOR_INITIALS))
3194 return new XMLStringBufferImportContext(GetImport(), aInitialsBuffer);
3198 bool bOK = true;
3199 if ( !mxField.is() )
3200 bOK = CreateField( mxField, sServicePrefix + GetServiceName() );
3201 if (bOK)
3203 Any aAny = mxField->getPropertyValue( "TextRange" );
3204 Reference< XText > xText;
3205 aAny >>= xText;
3206 if( xText.is() )
3208 rtl::Reference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport();
3209 if( !mxCursor.is() )
3211 mxOldCursor = xTxtImport->GetCursor();
3212 mxCursor = xText->createTextCursor();
3215 if( mxCursor.is() )
3217 xTxtImport->SetCursor( mxCursor );
3218 return xTxtImport->CreateTextChildContext( GetImport(), nElement, xAttrList );
3223 catch (const Exception&)
3227 return new XMLStringBufferImportContext(GetImport(), aTextBuffer);
3230 void XMLAnnotationImportContext::endFastElement(sal_Int32 /*nElement*/)
3232 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
3233 if( mxCursor.is() )
3235 // delete addition newline
3236 mxCursor->gotoEnd( false );
3237 mxCursor->goLeft( 1, true );
3238 mxCursor->setString( "" );
3240 // reset cursor
3241 GetImport().GetTextImport()->ResetCursor();
3244 if( mxOldCursor.is() )
3245 GetImport().GetTextImport()->SetCursor( mxOldCursor );
3247 // reinstall old list item #91964#
3248 GetImport().GetTextImport()->PopListContext();
3250 if ( bValid )
3252 if ( mnElement == XML_ELEMENT(OFFICE, XML_ANNOTATION_END) )
3254 // Search for a previous annotation with the same name.
3255 uno::Reference< text::XTextContent > xPrevField;
3257 Reference<XTextFieldsSupplier> xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY);
3258 uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
3259 uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
3260 while (xFields->hasMoreElements())
3262 uno::Reference<beans::XPropertySet> xCurrField(xFields->nextElement(), uno::UNO_QUERY);
3263 uno::Reference<beans::XPropertySetInfo> const xInfo(
3264 xCurrField->getPropertySetInfo());
3265 if (xInfo->hasPropertyByName(sAPI_name))
3267 OUString aFieldName;
3268 xCurrField->getPropertyValue(sAPI_name) >>= aFieldName;
3269 if (aFieldName == aName)
3271 xPrevField.set( xCurrField, uno::UNO_QUERY );
3272 break;
3277 if ( xPrevField.is() )
3279 // So we are ending a previous annotation,
3280 // let's create a text range covering the old and the current position.
3281 uno::Reference<text::XText> xText = GetImportHelper().GetText();
3282 uno::Reference<text::XTextCursor> xCursor =
3283 xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange());
3286 xCursor->gotoRange(xPrevField->getAnchor(), true);
3288 catch (const uno::RuntimeException&)
3290 // Losing the start of the anchor is better than not opening the document at
3291 // all.
3292 TOOLS_WARN_EXCEPTION(
3293 "xmloff.text",
3294 "XMLAnnotationImportContext::endFastElement: gotoRange() failed: ");
3297 xText->insertTextContent(xCursor, xPrevField, !xCursor->isCollapsed());
3300 else
3302 if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) )
3304 // set field properties
3305 PrepareField( mxField );
3307 // attach field to document
3308 Reference < XTextContent > xTextContent( mxField, UNO_QUERY );
3310 // workaround for #80606#
3313 GetImportHelper().InsertTextContent( xTextContent );
3315 catch (const lang::IllegalArgumentException&)
3317 // ignore
3322 else
3323 GetImportHelper().InsertString(GetContent());
3326 void XMLAnnotationImportContext::PrepareField(
3327 const Reference<XPropertySet> & xPropertySet )
3329 // import (possibly empty) author
3330 OUString sAuthor( aAuthorBuffer.makeStringAndClear() );
3331 xPropertySet->setPropertyValue(sAPI_author, Any(sAuthor));
3333 // import (possibly empty) initials
3334 OUString sInitials( aInitialsBuffer.makeStringAndClear() );
3335 xPropertySet->setPropertyValue("Initials", Any(sInitials));
3337 //import resolved flag
3338 bool bTmp(false);
3339 (void)::sax::Converter::convertBool(bTmp, aResolved);
3340 xPropertySet->setPropertyValue("Resolved", Any(bTmp));
3342 util::DateTime aDateTime;
3343 if (::sax::Converter::parseDateTime(aDateTime, aDateBuffer))
3346 Date aDate;
3347 aDate.Year = aDateTime.Year;
3348 aDate.Month = aDateTime.Month;
3349 aDate.Day = aDateTime.Day;
3350 xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDate));
3352 // why is there no UNO_NAME_DATE_TIME, but only UNO_NAME_DATE_TIME_VALUE?
3353 xPropertySet->setPropertyValue(sAPI_date_time_value, Any(aDateTime));
3355 aDateBuffer.setLength(0);
3357 if ( aTextBuffer.getLength() )
3359 // delete last paragraph mark (if necessary)
3360 if (char(0x0a) == aTextBuffer[aTextBuffer.getLength()-1])
3361 aTextBuffer.setLength(aTextBuffer.getLength()-1);
3362 xPropertySet->setPropertyValue(sAPI_content, Any(aTextBuffer.makeStringAndClear()));
3365 if (!aName.isEmpty())
3366 xPropertySet->setPropertyValue(sAPI_name, Any(aName));
3368 if (!aParentName.isEmpty())
3369 xPropertySet->setPropertyValue(sAPI_parent_name, Any(aParentName));
3373 // script field
3376 XMLScriptImportContext::XMLScriptImportContext(
3377 SvXMLImport& rImport,
3378 XMLTextImportHelper& rHlp)
3379 : XMLTextFieldImportContext(rImport, rHlp, "Script")
3380 , bContentOK(false)
3384 void XMLScriptImportContext::ProcessAttribute(
3385 sal_Int32 nAttrToken,
3386 std::string_view sAttrValue )
3388 switch (nAttrToken)
3390 case XML_ELEMENT(XLINK, XML_HREF):
3391 sContent = GetImport().GetAbsoluteReference( OUString::fromUtf8(sAttrValue) );
3392 bContentOK = true;
3393 break;
3395 case XML_ELEMENT(SCRIPT, XML_LANGUAGE):
3396 sScriptType = OUString::fromUtf8(sAttrValue);
3397 break;
3399 default:
3400 // ignore
3401 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3402 break;
3405 // always valid (even without ScriptType; cf- #96531#)
3406 bValid = true;
3409 void XMLScriptImportContext::PrepareField(
3410 const Reference<XPropertySet> & xPropertySet)
3412 // if href attribute was present, we use it. Else we use element content
3413 if (! bContentOK)
3415 sContent = GetContent();
3417 xPropertySet->setPropertyValue(sAPI_content, Any(sContent));
3419 // URL or script text? We use URL if we have an href-attribute
3420 xPropertySet->setPropertyValue("URLContent", Any(bContentOK));
3422 xPropertySet->setPropertyValue("ScriptType", Any(sScriptType));
3426 // measure field
3429 XMLMeasureFieldImportContext::XMLMeasureFieldImportContext(
3430 SvXMLImport& rImport,
3431 XMLTextImportHelper& rHlp) :
3432 XMLTextFieldImportContext(rImport, rHlp, "Measure"),
3433 mnKind( 0 )
3437 void XMLMeasureFieldImportContext::ProcessAttribute(
3438 sal_Int32 nAttrToken,
3439 std::string_view sAttrValue )
3441 switch (nAttrToken)
3443 case XML_ELEMENT(TEXT, XML_KIND):
3444 if( IsXMLToken( sAttrValue, XML_VALUE ) )
3446 mnKind = 0; bValid = true;
3448 else if( IsXMLToken( sAttrValue, XML_UNIT ) )
3450 mnKind = 1; bValid = true;
3452 else if( IsXMLToken( sAttrValue, XML_GAP ) )
3454 mnKind = 2; bValid = true;
3456 break;
3457 default:
3458 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3462 void XMLMeasureFieldImportContext::PrepareField(
3463 const Reference<XPropertySet> & xPropertySet)
3465 xPropertySet->setPropertyValue("Kind", Any(mnKind));
3469 // dropdown field
3472 XMLDropDownFieldImportContext::XMLDropDownFieldImportContext(
3473 SvXMLImport& rImport,
3474 XMLTextImportHelper& rHlp) :
3475 XMLTextFieldImportContext( rImport, rHlp, "DropDown" ),
3476 nSelected( -1 ),
3477 bNameOK( false ),
3478 bHelpOK(false),
3479 bHintOK(false)
3481 bValid = true;
3484 static bool lcl_ProcessLabel(
3485 const Reference<XFastAttributeList>& xAttrList,
3486 OUString& rLabel,
3487 bool& rIsSelected )
3489 bool bValid = false;
3490 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
3492 switch (aIter.getToken())
3494 case XML_ELEMENT(TEXT, XML_VALUE):
3496 rLabel = aIter.toString();
3497 bValid = true;
3498 break;
3500 case XML_ELEMENT(TEXT, XML_CURRENT_SELECTED):
3502 bool bTmp(false);
3503 if (::sax::Converter::convertBool( bTmp, aIter.toView() ))
3504 rIsSelected = bTmp;
3505 break;
3507 default:
3508 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
3511 return bValid;
3514 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDropDownFieldImportContext::createFastChildContext(
3515 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
3517 if( nElement == XML_ELEMENT(TEXT, XML_LABEL) )
3519 OUString sLabel;
3520 bool bIsSelected = false;
3521 if( lcl_ProcessLabel( xAttrList, sLabel, bIsSelected ) )
3523 if( bIsSelected )
3524 nSelected = static_cast<sal_Int32>( aLabels.size() );
3525 aLabels.push_back( sLabel );
3528 return new SvXMLImportContext( GetImport() );
3531 void XMLDropDownFieldImportContext::ProcessAttribute(
3532 sal_Int32 nAttrToken,
3533 std::string_view sAttrValue )
3535 if( nAttrToken == XML_ELEMENT(TEXT, XML_NAME))
3537 sName = OUString::fromUtf8(sAttrValue);
3538 bNameOK = true;
3540 else if (nAttrToken == XML_ELEMENT(TEXT, XML_HELP))
3542 sHelp = OUString::fromUtf8(sAttrValue);
3543 bHelpOK = true;
3545 else if (nAttrToken == XML_ELEMENT(TEXT, XML_HINT))
3547 sHint = OUString::fromUtf8(sAttrValue);
3548 bHintOK = true;
3550 else
3551 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3554 void XMLDropDownFieldImportContext::PrepareField(
3555 const Reference<XPropertySet>& xPropertySet)
3557 // create sequence
3558 sal_Int32 nLength = static_cast<sal_Int32>( aLabels.size() );
3559 Sequence<OUString> aSequence( nLength );
3560 OUString* pSequence = aSequence.getArray();
3561 for( sal_Int32 n = 0; n < nLength; n++ )
3562 pSequence[n] = aLabels[n];
3564 // now set values:
3566 xPropertySet->setPropertyValue( "Items", Any(aSequence) );
3568 if( nSelected >= 0 && nSelected < nLength )
3570 xPropertySet->setPropertyValue( "SelectedItem", Any(pSequence[nSelected]) );
3573 // set name
3574 if( bNameOK )
3576 xPropertySet->setPropertyValue( "Name", Any(sName) );
3578 // set help
3579 if( bHelpOK )
3581 xPropertySet->setPropertyValue( "Help", Any(sHelp) );
3583 // set hint
3584 if( bHintOK )
3586 xPropertySet->setPropertyValue( "Tooltip", Any(sHint) );
3591 /** import header fields (<draw:header>) */
3593 XMLHeaderFieldImportContext::XMLHeaderFieldImportContext(
3594 SvXMLImport& rImport, /// XML Import
3595 XMLTextImportHelper& rHlp) /// Text import helper
3596 : XMLTextFieldImportContext(rImport, rHlp, "Header" )
3598 sServicePrefix = sAPI_presentation_prefix;
3599 bValid = true;
3602 /// process attribute values
3603 void XMLHeaderFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken, std::string_view sAttrValue )
3605 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3608 /// prepare XTextField for insertion into document
3609 void XMLHeaderFieldImportContext::PrepareField(const Reference<XPropertySet> &)
3613 /** import footer fields (<draw:footer>) */
3615 XMLFooterFieldImportContext::XMLFooterFieldImportContext(
3616 SvXMLImport& rImport, /// XML Import
3617 XMLTextImportHelper& rHlp) /// Text import helper
3618 : XMLTextFieldImportContext(rImport, rHlp, "Footer" )
3620 sServicePrefix = sAPI_presentation_prefix;
3621 bValid = true;
3624 /// process attribute values
3625 void XMLFooterFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken, std::string_view sAttrValue)
3627 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3630 /// prepare XTextField for insertion into document
3631 void XMLFooterFieldImportContext::PrepareField(const Reference<XPropertySet> &)
3636 /** import footer fields (<draw:date-and-time>) */
3638 XMLDateTimeFieldImportContext::XMLDateTimeFieldImportContext(
3639 SvXMLImport& rImport, /// XML Import
3640 XMLTextImportHelper& rHlp) /// Text import helper
3641 : XMLTextFieldImportContext(rImport, rHlp, "DateTime" )
3643 sServicePrefix = sAPI_presentation_prefix;
3644 bValid = true;
3647 /// process attribute values
3648 void XMLDateTimeFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken,
3649 std::string_view sAttrValue )
3651 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3654 /// prepare XTextField for insertion into document
3655 void XMLDateTimeFieldImportContext::PrepareField(
3656 const css::uno::Reference<
3657 css::beans::XPropertySet> &)
3661 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */