tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / text / txtfldi.cxx
blobfcaf900b8f41dbfac23aec21d7b0175df2a2da11
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 <sal/config.h>
29 #include <cassert>
31 #include <txtfld.hxx>
32 #include <txtfldi.hxx>
33 #include <txtvfldi.hxx>
34 #include <utility>
35 #include <xmloff/xmlimp.hxx>
36 #include <xmloff/txtimp.hxx>
37 #include <xmloff/xmlnamespace.hxx>
38 #include <xmloff/namespacemap.hxx>
39 #include <xmloff/xmltoken.hxx>
40 #include <xmloff/xmluconv.hxx>
41 #include <xmloff/xmlement.hxx>
42 #include <XMLStringBufferImportContext.hxx>
43 #include <xmloff/XMLEventsImportContext.hxx>
44 #include <com/sun/star/frame/XModel.hpp>
45 #include <com/sun/star/text/UserDataPart.hpp>
46 #include <com/sun/star/style/NumberingType.hpp>
47 #include <com/sun/star/text/PlaceholderType.hpp>
48 #include <com/sun/star/text/ReferenceFieldPart.hpp>
49 #include <com/sun/star/text/ReferenceFieldSource.hpp>
50 #include <com/sun/star/text/XTextContent.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #include <com/sun/star/beans/XPropertySetInfo.hpp>
53 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
54 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
55 #include <com/sun/star/text/XDependentTextField.hpp>
56 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
57 #include <com/sun/star/text/ChapterFormat.hpp>
58 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
59 #include <com/sun/star/beans/PropertyValue.hpp>
60 #include <com/sun/star/text/BibliographyDataType.hpp>
61 #include <com/sun/star/util/XUpdatable.hpp>
62 #include <com/sun/star/sdb/CommandType.hpp>
63 #include <com/sun/star/container/XIndexReplace.hpp>
64 #include <com/sun/star/container/XUniqueIDAccess.hpp>
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 xField.set(xIfc, UNO_QUERY);
208 } else {
209 return false; // can't create instance
211 } else {
212 return false; // can't get MultiServiceFactory
215 return true;
218 /// create the appropriate field context from
219 XMLTextFieldImportContext*
220 XMLTextFieldImportContext::CreateTextFieldImportContext(
221 SvXMLImport& rImport,
222 XMLTextImportHelper& rHlp,
223 sal_Int32 nToken)
225 XMLTextFieldImportContext* pContext = nullptr;
227 switch (nToken)
229 case XML_ELEMENT(TEXT, XML_SENDER_FIRSTNAME):
230 case XML_ELEMENT(TEXT, XML_SENDER_LASTNAME):
231 case XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS):
232 case XML_ELEMENT(TEXT, XML_SENDER_INITIALS):
233 case XML_ELEMENT(TEXT, XML_SENDER_TITLE):
234 case XML_ELEMENT(TEXT, XML_SENDER_POSITION):
235 case XML_ELEMENT(TEXT, XML_SENDER_EMAIL):
236 case XML_ELEMENT(TEXT, XML_SENDER_PHONE_PRIVATE):
238 case XML_ELEMENT(TEXT, XML_SENDER_FAX):
239 case XML_ELEMENT(TEXT, XML_SENDER_COMPANY):
240 case XML_ELEMENT(TEXT, XML_SENDER_PHONE_WORK):
241 case XML_ELEMENT(TEXT, XML_SENDER_STREET):
242 case XML_ELEMENT(TEXT, XML_SENDER_CITY):
243 case XML_ELEMENT(TEXT, XML_SENDER_POSTAL_CODE):
244 case XML_ELEMENT(TEXT, XML_SENDER_COUNTRY):
245 case XML_ELEMENT(TEXT, XML_SENDER_STATE_OR_PROVINCE):
246 pContext =
247 new XMLSenderFieldImportContext( rImport, rHlp );
248 break;
250 case XML_ELEMENT(TEXT, XML_AUTHOR_NAME):
251 case XML_ELEMENT(TEXT, XML_AUTHOR_INITIALS):
252 pContext =
253 new XMLAuthorFieldImportContext( rImport, rHlp );
254 break;
256 case XML_ELEMENT(TEXT, XML_PLACEHOLDER):
257 pContext =
258 new XMLPlaceholderFieldImportContext( rImport, rHlp);
259 break;
260 case XML_ELEMENT(TEXT, XML_SEQUENCE):
261 pContext =
262 new XMLSequenceFieldImportContext( rImport, rHlp );
263 break;
264 case XML_ELEMENT(TEXT, XML_TEXT_INPUT):
265 pContext =
266 new XMLTextInputFieldImportContext( rImport, rHlp );
267 break;
268 case XML_ELEMENT(TEXT, XML_EXPRESSION):
269 pContext =
270 new XMLExpressionFieldImportContext( rImport, rHlp );
271 break;
272 case XML_ELEMENT(TEXT, XML_VARIABLE_SET):
273 pContext =
274 new XMLVariableSetFieldImportContext( rImport, rHlp );
275 break;
276 case XML_ELEMENT(TEXT, XML_VARIABLE_INPUT):
277 pContext =
278 new XMLVariableInputFieldImportContext( rImport, rHlp );
279 break;
280 case XML_ELEMENT(TEXT, XML_VARIABLE_GET):
281 pContext =
282 new XMLVariableGetFieldImportContext( rImport, rHlp );
283 break;
284 case XML_ELEMENT(TEXT, XML_USER_FIELD_GET):
285 pContext = new XMLUserFieldImportContext( rImport, rHlp );
286 break;
287 case XML_ELEMENT(TEXT, XML_USER_FIELD_INPUT):
288 pContext = new XMLUserFieldInputImportContext( rImport, rHlp );
289 break;
290 case XML_ELEMENT(TEXT, XML_TIME):
291 pContext = new XMLTimeFieldImportContext( rImport, rHlp );
292 break;
293 case XML_ELEMENT(TEXT, XML_PAGE_CONTINUATION_STRING):
294 case XML_ELEMENT(TEXT, XML_PAGE_CONTINUATION):
295 pContext = new XMLPageContinuationImportContext( rImport, rHlp );
296 break;
298 case XML_ELEMENT(TEXT, XML_PAGE_NUMBER):
299 pContext = new XMLPageNumberImportContext( rImport, rHlp );
300 break;
302 case XML_ELEMENT(TEXT, XML_DATE):
303 pContext = new XMLDateFieldImportContext( rImport, rHlp );
304 break;
306 case XML_ELEMENT(TEXT, XML_DATABASE_NAME):
307 pContext = new XMLDatabaseNameImportContext( rImport, rHlp );
308 break;
309 case XML_ELEMENT(TEXT, XML_DATABASE_NEXT):
310 pContext = new XMLDatabaseNextImportContext( rImport, rHlp );
311 break;
312 case XML_ELEMENT(TEXT, XML_DATABASE_ROW_SELECT):
313 pContext = new XMLDatabaseSelectImportContext( rImport, rHlp );
314 break;
315 case XML_ELEMENT(TEXT, XML_DATABASE_ROW_NUMBER):
316 pContext = new XMLDatabaseNumberImportContext( rImport, rHlp );
317 break;
318 case XML_ELEMENT(TEXT, XML_DATABASE_DISPLAY):
319 pContext = new XMLDatabaseDisplayImportContext( rImport, rHlp );
320 break;
321 case XML_ELEMENT(TEXT, XML_CONDITIONAL_TEXT):
322 pContext = new XMLConditionalTextImportContext( rImport, rHlp );
323 break;
324 case XML_ELEMENT(TEXT, XML_HIDDEN_TEXT):
325 pContext = new XMLHiddenTextImportContext( rImport, rHlp );
326 break;
327 case XML_ELEMENT(TEXT, XML_HIDDEN_PARAGRAPH):
328 pContext = new XMLHiddenParagraphImportContext( rImport, rHlp );
329 break;
330 case XML_ELEMENT(TEXT, XML_DESCRIPTION):
331 case XML_ELEMENT(TEXT, XML_TITLE):
332 case XML_ELEMENT(TEXT, XML_SUBJECT):
333 case XML_ELEMENT(TEXT, XML_KEYWORDS):
334 pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
335 nToken, true,
336 false );
337 break;
338 case XML_ELEMENT(TEXT, XML_INITIAL_CREATOR):
339 case XML_ELEMENT(TEXT, XML_PRINTED_BY):
340 case XML_ELEMENT(TEXT, XML_CREATOR):
341 pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
342 nToken, false,
343 true );
344 break;
346 case XML_ELEMENT(TEXT, XML_CREATION_DATE):
347 case XML_ELEMENT(TEXT, XML_CREATION_TIME):
348 case XML_ELEMENT(TEXT, XML_PRINT_DATE):
349 case XML_ELEMENT(TEXT, XML_PRINT_TIME):
350 case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE):
351 case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME):
352 case XML_ELEMENT(TEXT, XML_EDITING_DURATION):
353 pContext = new XMLDateTimeDocInfoImportContext( rImport, rHlp,
354 nToken );
355 break;
357 case XML_ELEMENT(TEXT, XML_EDITING_CYCLES):
358 pContext = new XMLRevisionDocInfoImportContext( rImport, rHlp,
359 nToken );
360 break;
362 case XML_ELEMENT(TEXT, XML_USER_DEFINED):
363 pContext = new XMLUserDocInfoImportContext( rImport, rHlp,
364 nToken );
365 break;
367 case XML_ELEMENT(TEXT, XML_FILE_NAME):
368 pContext = new XMLFileNameImportContext( rImport, rHlp );
369 break;
371 case XML_ELEMENT(TEXT, XML_CHAPTER):
372 pContext = new XMLChapterImportContext( rImport, rHlp );
373 break;
375 case XML_ELEMENT(TEXT, XML_TEMPLATE_NAME):
376 pContext = new XMLTemplateNameImportContext( rImport, rHlp );
377 break;
379 case XML_ELEMENT(TEXT, XML_WORD_COUNT):
380 case XML_ELEMENT(TEXT, XML_PARAGRAPH_COUNT):
381 case XML_ELEMENT(TEXT, XML_TABLE_COUNT):
382 case XML_ELEMENT(TEXT, XML_CHARACTER_COUNT):
383 case XML_ELEMENT(TEXT, XML_IMAGE_COUNT):
384 case XML_ELEMENT(TEXT, XML_OBJECT_COUNT):
385 case XML_ELEMENT(TEXT, XML_PAGE_COUNT):
386 pContext = new XMLCountFieldImportContext( rImport, rHlp, nToken);
387 break;
389 case XML_ELEMENT(TEXT, XML_PAGE_VARIABLE_GET):
390 pContext = new XMLPageVarGetFieldImportContext( rImport, rHlp );
391 break;
393 case XML_ELEMENT(TEXT, XML_PAGE_VARIABLE_SET):
394 pContext = new XMLPageVarSetFieldImportContext( rImport, rHlp );
395 break;
397 case XML_ELEMENT(TEXT, XML_EXECUTE_MACRO):
398 pContext = new XMLMacroFieldImportContext( rImport, rHlp );
399 break;
401 case XML_ELEMENT(TEXT, XML_DDE_CONNECTION):
402 pContext = new XMLDdeFieldImportContext( rImport, rHlp );
403 break;
405 case XML_ELEMENT(TEXT, XML_REFERENCE_REF):
406 case XML_ELEMENT(TEXT, XML_BOOKMARK_REF):
407 case XML_ELEMENT(TEXT, XML_NOTE_REF):
408 case XML_ELEMENT(TEXT, XML_SEQUENCE_REF):
409 case XML_ELEMENT(TEXT, XML_STYLE_REF):
410 case XML_ELEMENT(LO_EXT, XML_STYLE_REF):
411 pContext = new XMLReferenceFieldImportContext( rImport, rHlp, nToken );
412 break;
414 case XML_ELEMENT(TEXT, XML_SHEET_NAME):
415 pContext = new XMLSheetNameImportContext( rImport, rHlp );
416 break;
418 case XML_ELEMENT(TEXT, XML_PAGE_NAME):
419 case XML_ELEMENT(LO_EXT, XML_PAGE_NAME):
420 pContext = new XMLPageNameFieldImportContext( rImport, rHlp );
421 break;
423 case XML_ELEMENT(TEXT, XML_BIBLIOGRAPHY_MARK):
424 pContext = new XMLBibliographyFieldImportContext( rImport, rHlp );
425 break;
427 case XML_ELEMENT(OFFICE, XML_ANNOTATION):
428 case XML_ELEMENT(OFFICE, XML_ANNOTATION_END):
429 pContext = new XMLAnnotationImportContext( rImport, rHlp, nToken);
430 break;
432 case XML_ELEMENT(TEXT, XML_SCRIPT):
433 pContext = new XMLScriptImportContext( rImport, rHlp);
434 break;
436 case XML_ELEMENT(TEXT, XML_MEASURE):
437 pContext = new XMLMeasureFieldImportContext( rImport, rHlp );
438 break;
440 case XML_ELEMENT(TEXT, XML_TABLE_FORMULA):
441 pContext = new XMLTableFormulaImportContext( rImport, rHlp );
442 break;
443 case XML_ELEMENT(TEXT, XML_DROP_DOWN):
444 pContext = new XMLDropDownFieldImportContext( rImport, rHlp );
445 break;
446 case XML_ELEMENT(PRESENTATION, XML_HEADER):
447 pContext = new XMLHeaderFieldImportContext( rImport, rHlp );
448 break;
449 case XML_ELEMENT(PRESENTATION, XML_FOOTER):
450 pContext = new XMLFooterFieldImportContext( rImport, rHlp );
451 break;
452 case XML_ELEMENT(PRESENTATION, XML_DATE_TIME):
453 pContext = new XMLDateTimeFieldImportContext( rImport, rHlp );
454 break;
456 default:
457 // ignore! May not even be a textfield.
458 // (Reminder: This method is called inside default:-branch)
459 pContext = nullptr;
460 break;
463 return pContext;
467 void XMLTextFieldImportContext::ForceUpdate(
468 const Reference<XPropertySet> & rPropertySet)
470 // force update
471 Reference<XUpdatable> xUpdate(rPropertySet, UNO_QUERY);
472 if (xUpdate.is())
474 xUpdate->update();
476 else
478 OSL_FAIL("Expected XUpdatable support!");
483 // XMLSenderFieldImportContext
486 constexpr OUStringLiteral gsPropertyFieldSubType(u"UserDataType");
488 XMLSenderFieldImportContext::XMLSenderFieldImportContext(
489 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
490 : XMLTextFieldImportContext(rImport, rHlp, u"ExtendedUser"_ustr)
491 , nSubType(0)
492 , sPropertyFixed(sAPI_is_fixed)
493 , sPropertyContent(sAPI_content)
494 , bFixed(true)
498 void XMLSenderFieldImportContext::startFastElement(
499 sal_Int32 nElement,
500 const Reference<XFastAttributeList> & xAttrList)
502 bValid = true;
503 switch (nElement) {
504 case XML_ELEMENT(TEXT, XML_SENDER_FIRSTNAME):
505 nSubType = UserDataPart::FIRSTNAME;
506 break;
507 case XML_ELEMENT(TEXT, XML_SENDER_LASTNAME):
508 nSubType = UserDataPart::NAME;
509 break;
510 case XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS):
511 case XML_ELEMENT(TEXT, XML_SENDER_INITIALS):
512 nSubType = UserDataPart::SHORTCUT;
513 break;
514 case XML_ELEMENT(TEXT, XML_SENDER_TITLE):
515 nSubType = UserDataPart::TITLE;
516 break;
517 case XML_ELEMENT(TEXT, XML_SENDER_POSITION):
518 nSubType = UserDataPart::POSITION;
519 break;
520 case XML_ELEMENT(TEXT, XML_SENDER_EMAIL):
521 nSubType = UserDataPart::EMAIL;
522 break;
523 case XML_ELEMENT(TEXT, XML_SENDER_PHONE_PRIVATE):
524 nSubType = UserDataPart::PHONE_PRIVATE;
525 break;
526 case XML_ELEMENT(TEXT, XML_SENDER_FAX):
527 nSubType = UserDataPart::FAX;
528 break;
529 case XML_ELEMENT(TEXT, XML_SENDER_COMPANY):
530 nSubType = UserDataPart::COMPANY;
531 break;
532 case XML_ELEMENT(TEXT, XML_SENDER_PHONE_WORK):
533 nSubType = UserDataPart::PHONE_COMPANY;
534 break;
535 case XML_ELEMENT(TEXT, XML_SENDER_STREET):
536 nSubType = UserDataPart::STREET;
537 break;
538 case XML_ELEMENT(TEXT, XML_SENDER_CITY):
539 nSubType = UserDataPart::CITY;
540 break;
541 case XML_ELEMENT(TEXT, XML_SENDER_POSTAL_CODE):
542 nSubType = UserDataPart::ZIP;
543 break;
544 case XML_ELEMENT(TEXT, XML_SENDER_COUNTRY):
545 nSubType = UserDataPart::COUNTRY;
546 break;
547 case XML_ELEMENT(TEXT, XML_SENDER_STATE_OR_PROVINCE):
548 nSubType = UserDataPart::STATE;
549 break;
550 default:
551 bValid = false;
552 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
553 break;
556 // process Attributes
557 XMLTextFieldImportContext::startFastElement(nElement, xAttrList);
560 void XMLSenderFieldImportContext::ProcessAttribute(
561 sal_Int32 nAttrToken,
562 std::string_view sAttrValue)
564 if (XML_ELEMENT(TEXT, XML_FIXED) == nAttrToken) {
566 // set bVal
567 bool bVal(false);
568 bool const bRet = ::sax::Converter::convertBool(bVal, sAttrValue);
570 // set bFixed if successful
571 if (bRet) {
572 bFixed = bVal;
575 else
576 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
579 void XMLSenderFieldImportContext::PrepareField(
580 const Reference<XPropertySet> & rPropSet)
582 // set members
583 rPropSet->setPropertyValue(gsPropertyFieldSubType, Any(nSubType));
585 // set fixed
586 rPropSet->setPropertyValue(sPropertyFixed, Any(bFixed));
588 // set content if fixed
589 if (!bFixed)
590 return;
592 // in organizer or styles-only mode: force update
593 if (GetImport().GetTextImport()->IsOrganizerMode() ||
594 GetImport().GetTextImport()->IsStylesOnlyMode() )
596 ForceUpdate(rPropSet);
598 else
600 rPropSet->setPropertyValue(sPropertyContent, Any(GetContent()));
605 // XMLAuthorFieldImportContext
607 constexpr OUStringLiteral gsPropertyAuthorFullName(u"FullName");
609 XMLAuthorFieldImportContext::XMLAuthorFieldImportContext(
610 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
611 : XMLSenderFieldImportContext(rImport, rHlp)
612 , bAuthorFullName(true)
613 , sPropertyFixed(sAPI_is_fixed)
614 , sPropertyContent(sAPI_content)
616 // overwrite service name from XMLSenderFieldImportContext
617 SetServiceName(sAPI_author);
620 void XMLAuthorFieldImportContext::startFastElement(
621 sal_Int32 nElement,
622 const Reference<XFastAttributeList> & xAttrList)
624 bAuthorFullName = ( XML_ELEMENT(TEXT, XML_AUTHOR_INITIALS) != nElement);
625 bValid = true;
627 // process Attributes
628 XMLTextFieldImportContext::startFastElement(nElement, xAttrList);
631 void XMLAuthorFieldImportContext::ProcessAttribute(sal_Int32 nAttrToken, std::string_view sAttrValue)
633 if(nAttrToken == XML_ELEMENT(TEXT, XML_FIXED))
635 bool bTmp(false);
636 if (::sax::Converter::convertBool(bTmp, sAttrValue))
637 bFixed = bTmp;
639 else
640 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
643 void XMLAuthorFieldImportContext::PrepareField(
644 const Reference<XPropertySet> & rPropSet)
646 // set members
647 Any aAny;
648 rPropSet->setPropertyValue(gsPropertyAuthorFullName, Any(bAuthorFullName));
650 rPropSet->setPropertyValue(sPropertyFixed, Any(bFixed));
652 // set content if fixed
653 if (!bFixed)
654 return;
656 // organizer or styles-only mode: force update
657 if (GetImport().GetTextImport()->IsOrganizerMode() ||
658 GetImport().GetTextImport()->IsStylesOnlyMode() )
660 ForceUpdate(rPropSet);
662 else
664 aAny <<= GetContent();
665 rPropSet->setPropertyValue(sPropertyContent, aAny);
670 // page continuation string
673 SvXMLEnumMapEntry<PageNumberType> const lcl_aSelectPageAttrMap[] =
675 { XML_PREVIOUS, PageNumberType_PREV },
676 { XML_CURRENT, PageNumberType_CURRENT },
677 { XML_NEXT, PageNumberType_NEXT },
678 { XML_TOKEN_INVALID, PageNumberType(0) },
681 constexpr OUStringLiteral gsPropertyUserText(u"UserText");
683 XMLPageContinuationImportContext::XMLPageContinuationImportContext(
684 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
685 : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number)
686 , sPropertySubType(sAPI_sub_type)
687 , sPropertyNumberingType(sAPI_numbering_type)
688 , eSelectPage(PageNumberType_CURRENT)
689 , sStringOK(false)
691 bValid = true;
694 void XMLPageContinuationImportContext::ProcessAttribute(
695 sal_Int32 nAttrToken, std::string_view sAttrValue )
697 switch(nAttrToken)
699 case XML_ELEMENT(TEXT, XML_SELECT_PAGE):
701 PageNumberType nTmp;
702 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
703 lcl_aSelectPageAttrMap)
704 && (PageNumberType_CURRENT != nTmp) )
706 eSelectPage = nTmp;
708 break;
710 case XML_ELEMENT(TEXT, XML_STRING_VALUE):
711 case XML_ELEMENT(OFFICE, XML_STRING_VALUE):
712 sString = OUString::fromUtf8(sAttrValue);
713 sStringOK = true;
714 break;
715 default:
716 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
720 void XMLPageContinuationImportContext::PrepareField(
721 const Reference<XPropertySet> & xPropertySet)
723 Any aAny;
725 xPropertySet->setPropertyValue(sPropertySubType, Any(eSelectPage));
727 aAny <<= (sStringOK ? sString : GetContent());
728 xPropertySet->setPropertyValue(gsPropertyUserText, aAny);
730 aAny <<= style::NumberingType::CHAR_SPECIAL;
731 xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
735 // page number field
738 XMLPageNumberImportContext::XMLPageNumberImportContext(
739 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
740 : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number)
741 , sPropertySubType(sAPI_sub_type)
742 , sPropertyNumberingType(sAPI_numbering_type)
743 , sPropertyOffset(sAPI_offset)
744 , sNumberSync(GetXMLToken(XML_FALSE))
745 , nPageAdjust(0)
746 , eSelectPage(PageNumberType_CURRENT)
747 , sNumberFormatOK(false)
749 bValid = true;
752 void XMLPageNumberImportContext::ProcessAttribute(
753 sal_Int32 nAttrToken,
754 std::string_view sAttrValue )
756 switch (nAttrToken)
758 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
759 sNumberFormat = OUString::fromUtf8(sAttrValue);
760 sNumberFormatOK = true;
761 break;
762 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
763 sNumberSync = OUString::fromUtf8(sAttrValue);
764 break;
765 case XML_ELEMENT(TEXT, XML_SELECT_PAGE):
766 SvXMLUnitConverter::convertEnum(eSelectPage, sAttrValue,
767 lcl_aSelectPageAttrMap);
768 break;
769 case XML_ELEMENT(TEXT, XML_PAGE_ADJUST):
771 sal_Int32 nTmp;
772 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
774 nPageAdjust = static_cast<sal_Int16>(nTmp);
776 break;
778 default:
779 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
783 void XMLPageNumberImportContext::PrepareField(
784 const Reference<XPropertySet> & xPropertySet)
786 // all properties are optional
787 Reference<XPropertySetInfo> xPropertySetInfo(
788 xPropertySet->getPropertySetInfo());
790 if (xPropertySetInfo->hasPropertyByName(sPropertyNumberingType))
792 sal_Int16 nNumType;
793 if( sNumberFormatOK )
795 nNumType= style::NumberingType::ARABIC;
796 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
797 sNumberFormat,
798 sNumberSync );
800 else
801 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
803 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
806 if (xPropertySetInfo->hasPropertyByName(sPropertyOffset))
808 // adjust offset
809 switch (eSelectPage)
811 case PageNumberType_PREV:
812 nPageAdjust--;
813 break;
814 case PageNumberType_CURRENT:
815 break;
816 case PageNumberType_NEXT:
817 nPageAdjust++;
818 break;
819 default:
820 SAL_WARN("xmloff.text", "unknown page number type");
822 xPropertySet->setPropertyValue(sPropertyOffset, Any(nPageAdjust));
825 if (xPropertySetInfo->hasPropertyByName(sPropertySubType))
827 xPropertySet->setPropertyValue(sPropertySubType, Any(eSelectPage));
832 // Placeholder
835 constexpr OUStringLiteral gsPropertyPlaceholderType(u"PlaceHolderType");
836 constexpr OUStringLiteral gsPropertyPlaceholder(u"PlaceHolder");
838 XMLPlaceholderFieldImportContext::XMLPlaceholderFieldImportContext(
839 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
840 : XMLTextFieldImportContext(rImport, rHlp, u"JumpEdit"_ustr)
841 , sPropertyHint(sAPI_hint)
842 , nPlaceholderType(PlaceholderType::TEXT)
846 /// process attribute values
847 void XMLPlaceholderFieldImportContext::ProcessAttribute(
848 sal_Int32 nAttrToken, std::string_view sAttrValue )
850 switch (nAttrToken) {
851 case XML_ELEMENT(TEXT, XML_DESCRIPTION):
852 sDescription = OUString::fromUtf8(sAttrValue);
853 break;
855 case XML_ELEMENT(TEXT, XML_PLACEHOLDER_TYPE):
856 bValid = true;
857 if (IsXMLToken(sAttrValue, XML_TABLE))
859 nPlaceholderType = PlaceholderType::TABLE;
861 else if (IsXMLToken(sAttrValue, XML_TEXT))
863 nPlaceholderType = PlaceholderType::TEXT;
865 else if (IsXMLToken(sAttrValue, XML_TEXT_BOX))
867 nPlaceholderType = PlaceholderType::TEXTFRAME;
869 else if (IsXMLToken(sAttrValue, XML_IMAGE))
871 nPlaceholderType = PlaceholderType::GRAPHIC;
873 else if (IsXMLToken(sAttrValue, XML_OBJECT))
875 nPlaceholderType = PlaceholderType::OBJECT;
877 else
879 bValid = false;
881 break;
883 default:
884 // ignore
885 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
889 void XMLPlaceholderFieldImportContext::PrepareField(
890 const Reference<XPropertySet> & xPropertySet) {
892 Any aAny;
893 xPropertySet->setPropertyValue(sPropertyHint, Any(sDescription));
895 // remove <...> around content (if present)
896 OUString aContent = GetContent();
897 sal_Int32 nStart = 0;
898 sal_Int32 nLength = aContent.getLength();
899 if (aContent.startsWith("<"))
901 --nLength;
902 ++nStart;
904 if (aContent.endsWith(">"))
906 --nLength;
908 aAny <<= aContent.copy(nStart, nLength);
909 xPropertySet->setPropertyValue(gsPropertyPlaceholder, aAny);
911 xPropertySet->setPropertyValue(gsPropertyPlaceholderType, Any(nPlaceholderType));
915 // time field
917 constexpr OUString gsPropertyAdjust(u"Adjust"_ustr);
919 XMLTimeFieldImportContext::XMLTimeFieldImportContext(
920 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
921 : XMLTextFieldImportContext(rImport, rHlp, sAPI_date_time)
922 , sPropertyNumberFormat(sAPI_number_format)
923 , sPropertyFixed(sAPI_is_fixed)
924 , sPropertyDateTimeValue(sAPI_date_time_value)
925 , sPropertyDateTime(sAPI_date_time)
926 , sPropertyIsDate(sAPI_is_date)
927 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
928 , nAdjust(0)
929 , nFormatKey(0)
930 , bTimeOK(false)
931 , bFormatOK(false)
932 , bFixed(false)
933 , bIsDate(false)
934 , bIsDefaultLanguage( true )
936 bValid = true; // always valid!
939 void XMLTimeFieldImportContext::ProcessAttribute(
940 sal_Int32 nAttrToken, std::string_view sAttrValue )
942 switch (nAttrToken)
944 case XML_ELEMENT(TEXT, XML_TIME_VALUE):
945 case XML_ELEMENT(OFFICE, XML_TIME_VALUE):
947 if (::sax::Converter::parseTimeOrDateTime(aDateTimeValue, sAttrValue))
949 bTimeOK = true;
951 break;
953 case XML_ELEMENT(TEXT, XML_FIXED):
955 bool bTmp(false);
956 if (::sax::Converter::convertBool(bTmp, sAttrValue))
958 bFixed = bTmp;
960 break;
962 case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME):
964 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
965 OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage);
966 if (-1 != nKey)
968 nFormatKey = nKey;
969 bFormatOK = true;
971 break;
973 case XML_ELEMENT(TEXT, XML_TIME_ADJUST):
975 double fTmp;
977 if (::sax::Converter::convertDuration(fTmp, sAttrValue))
979 // convert to minutes
980 nAdjust = static_cast<sal_Int32>(::rtl::math::approxFloor(fTmp * 60 * 24));
982 break;
984 default:
985 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
989 void XMLTimeFieldImportContext::PrepareField(
990 const Reference<XPropertySet> & rPropertySet)
992 // all properties are optional (except IsDate)
993 Reference<XPropertySetInfo> xPropertySetInfo(
994 rPropertySet->getPropertySetInfo());
996 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
998 rPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
1001 rPropertySet->setPropertyValue(sPropertyIsDate, Any(bIsDate));
1003 if (xPropertySetInfo->hasPropertyByName(gsPropertyAdjust))
1005 rPropertySet->setPropertyValue(gsPropertyAdjust, Any(nAdjust));
1008 // set value
1009 if (bFixed)
1011 // organizer or styles-only mode: force update
1012 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1013 GetImport().GetTextImport()->IsStylesOnlyMode() )
1015 ForceUpdate(rPropertySet);
1017 else
1019 // normal mode: set value (if present)
1020 if (bTimeOK)
1022 if (xPropertySetInfo->hasPropertyByName(sPropertyDateTimeValue))
1024 rPropertySet->setPropertyValue(sPropertyDateTimeValue, Any(aDateTimeValue));
1026 else if (xPropertySetInfo->hasPropertyByName(sPropertyDateTime))
1028 rPropertySet->setPropertyValue(sPropertyDateTime, Any(aDateTimeValue));
1034 if (bFormatOK &&
1035 xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1037 rPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormatKey));
1039 if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
1041 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1042 rPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1048 // date field
1051 XMLDateFieldImportContext::XMLDateFieldImportContext(
1052 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1053 XMLTimeFieldImportContext(rImport, rHlp)
1055 bIsDate = true; // always a date!
1058 void XMLDateFieldImportContext::ProcessAttribute(
1059 sal_Int32 nAttrToken,
1060 std::string_view sAttrValue )
1062 switch (nAttrToken)
1064 case XML_ELEMENT(TEXT, XML_DATE_VALUE):
1065 case XML_ELEMENT(OFFICE, XML_DATE_VALUE):
1067 if (::sax::Converter::parseDateTime(aDateTimeValue, sAttrValue))
1069 bTimeOK = true;
1071 break;
1073 case XML_ELEMENT(TEXT, XML_DATE_ADJUST):
1074 // delegate to superclass, pretending it was a time-adjust attr.
1075 XMLTimeFieldImportContext::ProcessAttribute(
1076 XML_ELEMENT(TEXT, XML_TIME_ADJUST),
1077 sAttrValue);
1078 break;
1079 case XML_ELEMENT(TEXT, XML_TIME_VALUE):
1080 case XML_ELEMENT(OFFICE, XML_TIME_VALUE):
1081 case XML_ELEMENT(TEXT, XML_TIME_ADJUST):
1082 ; // ignore time-adjust and time-value attributes
1083 break;
1084 default:
1085 // all others: delegate to super-class
1086 return XMLTimeFieldImportContext::ProcessAttribute(nAttrToken,
1087 sAttrValue);
1088 break;
1093 // database field superclass
1096 constexpr OUStringLiteral gsPropertyDataBaseName(u"DataBaseName");
1097 constexpr OUStringLiteral gsPropertyDataBaseURL(u"DataBaseURL");
1098 constexpr OUStringLiteral gsPropertyTableName(u"DataTableName");
1099 constexpr OUStringLiteral gsPropertyDataCommandType(u"DataCommandType");
1100 constexpr OUStringLiteral gsPropertyIsVisible(u"IsVisible");
1102 XMLDatabaseFieldImportContext::XMLDatabaseFieldImportContext(
1103 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1104 const OUString& pServiceName, bool bUseDisplay)
1105 : XMLTextFieldImportContext(rImport, rHlp, pServiceName)
1106 , m_nCommandType( sdb::CommandType::TABLE )
1107 , m_bCommandTypeOK(false)
1108 , m_bDisplay( true )
1109 , m_bDisplayOK( false )
1110 , m_bUseDisplay( bUseDisplay )
1111 , m_bDatabaseOK(false)
1112 , m_bDatabaseNameOK(false)
1113 , m_bDatabaseURLOK(false)
1114 , m_bTableOK(false)
1118 void XMLDatabaseFieldImportContext::ProcessAttribute(
1119 sal_Int32 nAttrToken, std::string_view sAttrValue )
1121 switch (nAttrToken)
1123 case XML_ELEMENT(TEXT, XML_DATABASE_NAME):
1124 m_sDatabaseName = OUString::fromUtf8(sAttrValue);
1125 m_bDatabaseOK = true;
1126 m_bDatabaseNameOK = true;
1127 break;
1128 case XML_ELEMENT(TEXT, XML_TABLE_NAME):
1129 m_sTableName = OUString::fromUtf8(sAttrValue);
1130 m_bTableOK = true;
1131 break;
1132 case XML_ELEMENT(TEXT, XML_TABLE_TYPE):
1133 if( IsXMLToken( sAttrValue, XML_TABLE ) )
1135 m_nCommandType = sdb::CommandType::TABLE;
1136 m_bCommandTypeOK = true;
1138 else if( IsXMLToken( sAttrValue, XML_QUERY ) )
1140 m_nCommandType = sdb::CommandType::QUERY;
1141 m_bCommandTypeOK = true;
1143 else if( IsXMLToken( sAttrValue, XML_COMMAND ) )
1145 m_nCommandType = sdb::CommandType::COMMAND;
1146 m_bCommandTypeOK = true;
1148 break;
1149 case XML_ELEMENT(TEXT, XML_DISPLAY):
1150 if( IsXMLToken( sAttrValue, XML_NONE ) )
1152 m_bDisplay = false;
1153 m_bDisplayOK = true;
1155 else if( IsXMLToken( sAttrValue, XML_VALUE ) )
1157 m_bDisplay = true;
1158 m_bDisplayOK = true;
1160 break;
1161 default:
1162 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1166 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDatabaseFieldImportContext::createFastChildContext(
1167 sal_Int32 nElement,
1168 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1170 if (nElement == XML_ELEMENT(FORM, XML_CONNECTION_RESOURCE) )
1172 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
1174 switch (aIter.getToken())
1176 case XML_ELEMENT(XLINK, XML_HREF):
1178 m_sDatabaseURL = aIter.toString();
1179 m_bDatabaseOK = true;
1180 m_bDatabaseURLOK = true;
1182 break;
1183 default:;
1187 // we call ProcessAttribute in order to set bValid appropriately
1188 ProcessAttribute( XML_TOKEN_INVALID, "" );
1190 else
1191 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1193 return nullptr;
1197 void XMLDatabaseFieldImportContext::PrepareField(
1198 const Reference<XPropertySet> & xPropertySet)
1200 xPropertySet->setPropertyValue(gsPropertyTableName, Any(m_sTableName));
1202 if( m_bDatabaseNameOK )
1204 xPropertySet->setPropertyValue(gsPropertyDataBaseName, Any(m_sDatabaseName));
1206 else if( m_bDatabaseURLOK )
1208 xPropertySet->setPropertyValue(gsPropertyDataBaseURL, Any(m_sDatabaseURL));
1211 // #99980# load/save command type for all fields; also load
1212 // old documents without command type
1213 if( m_bCommandTypeOK )
1215 xPropertySet->setPropertyValue( gsPropertyDataCommandType, Any(m_nCommandType) );
1218 if( m_bUseDisplay && m_bDisplayOK )
1220 xPropertySet->setPropertyValue( gsPropertyIsVisible, Any(m_bDisplay) );
1225 // database name field
1228 XMLDatabaseNameImportContext::XMLDatabaseNameImportContext(
1229 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1230 XMLDatabaseFieldImportContext(rImport, rHlp, u"DatabaseName"_ustr, true)
1234 void XMLDatabaseNameImportContext::ProcessAttribute(
1235 sal_Int32 nAttrToken, std::string_view sAttrValue )
1237 // delegate to superclass and check for success
1238 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1239 bValid = m_bDatabaseOK && m_bTableOK;
1243 // database next field
1246 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1247 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1248 const OUString& pServiceName) :
1249 XMLDatabaseFieldImportContext(rImport, rHlp, pServiceName, false),
1250 sPropertyCondition(sAPI_condition),
1251 sTrue(sAPI_true),
1252 bConditionOK(false)
1256 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1257 SvXMLImport& rImport, XMLTextImportHelper& rHlp)
1258 : XMLDatabaseFieldImportContext(rImport, rHlp, u"DatabaseNextSet"_ustr, false)
1259 , sPropertyCondition(sAPI_condition)
1260 , sTrue(sAPI_true)
1261 , bConditionOK(false)
1265 void XMLDatabaseNextImportContext::ProcessAttribute(
1266 sal_Int32 nAttrToken, std::string_view sAttrValue )
1268 if (XML_ELEMENT(TEXT, XML_CONDITION) == nAttrToken)
1270 OUString sTmp;
1271 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrValueQName(
1272 OUString::fromUtf8(sAttrValue), &sTmp );
1273 if( XML_NAMESPACE_OOOW == nPrefix )
1275 sCondition = sTmp;
1276 bConditionOK = true;
1278 else
1279 sCondition = OUString::fromUtf8(sAttrValue);
1281 else
1283 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1284 sAttrValue);
1287 bValid = m_bDatabaseOK && m_bTableOK;
1290 void XMLDatabaseNextImportContext::PrepareField(
1291 const Reference<XPropertySet> & xPropertySet)
1293 Any aAny;
1295 aAny <<= bConditionOK ? sCondition : sTrue;
1296 xPropertySet->setPropertyValue(sPropertyCondition, aAny);
1298 XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1302 // database select field
1305 XMLDatabaseSelectImportContext::XMLDatabaseSelectImportContext(
1306 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1307 XMLDatabaseNextImportContext(rImport, rHlp, u"DatabaseNumberOfSet"_ustr),
1308 sPropertySetNumber(sAPI_set_number),
1309 nNumber(0),
1310 bNumberOK(false)
1314 void XMLDatabaseSelectImportContext::ProcessAttribute(
1315 sal_Int32 nAttrToken,
1316 std::string_view sAttrValue )
1318 if (XML_ELEMENT(TEXT, XML_ROW_NUMBER) == nAttrToken)
1320 sal_Int32 nTmp;
1321 if (::sax::Converter::convertNumber( nTmp, sAttrValue
1322 /* , nMin, nMax ??? */ ))
1324 nNumber = nTmp;
1325 bNumberOK = true;
1328 else
1330 XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1333 bValid = m_bTableOK && m_bDatabaseOK && bNumberOK;
1336 void XMLDatabaseSelectImportContext::PrepareField(
1337 const Reference<XPropertySet> & xPropertySet)
1339 xPropertySet->setPropertyValue(sPropertySetNumber, Any(nNumber));
1341 XMLDatabaseNextImportContext::PrepareField(xPropertySet);
1345 // database display row number field
1348 XMLDatabaseNumberImportContext::XMLDatabaseNumberImportContext(
1349 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1350 XMLDatabaseFieldImportContext(rImport, rHlp, u"DatabaseSetNumber"_ustr, true),
1351 sPropertyNumberingType(
1352 sAPI_numbering_type),
1353 sPropertySetNumber(sAPI_set_number),
1354 sNumberFormat(u"1"_ustr),
1355 sNumberSync(GetXMLToken(XML_FALSE)),
1356 nValue(0),
1357 bValueOK(false)
1361 void XMLDatabaseNumberImportContext::ProcessAttribute(
1362 sal_Int32 nAttrToken,
1363 std::string_view sAttrValue )
1365 switch (nAttrToken)
1367 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
1368 sNumberFormat = OUString::fromUtf8(sAttrValue);
1369 break;
1370 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
1371 sNumberSync = OUString::fromUtf8(sAttrValue);
1372 break;
1373 case XML_ELEMENT(TEXT, XML_VALUE_TYPE):
1374 case XML_ELEMENT(OFFICE, XML_VALUE_TYPE):
1376 sal_Int32 nTmp;
1377 if (::sax::Converter::convertNumber( nTmp, sAttrValue ))
1379 nValue = nTmp;
1380 bValueOK = true;
1382 break;
1384 default:
1385 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1386 sAttrValue);
1387 break;
1390 bValid = m_bTableOK && m_bDatabaseOK;
1393 void XMLDatabaseNumberImportContext::PrepareField(
1394 const Reference<XPropertySet> & xPropertySet)
1396 sal_Int16 nNumType = style::NumberingType::ARABIC;
1397 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
1398 sNumberFormat,
1399 sNumberSync );
1400 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
1402 if (bValueOK)
1404 xPropertySet->setPropertyValue(sPropertySetNumber, Any(nValue));
1407 XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1411 // Simple doc info fields
1414 XMLSimpleDocInfoImportContext::XMLSimpleDocInfoImportContext(
1415 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1416 sal_Int32 nElementToken,
1417 bool bContent, bool bAuthor)
1418 : XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nElementToken) )
1419 , sPropertyFixed(sAPI_is_fixed)
1420 , sPropertyContent(sAPI_content)
1421 , sPropertyAuthor(sAPI_author)
1422 , sPropertyCurrentPresentation(sAPI_current_presentation)
1423 , bFixed(false)
1424 , bHasAuthor(bAuthor)
1425 , bHasContent(bContent)
1427 bValid = true;
1430 void XMLSimpleDocInfoImportContext::ProcessAttribute(
1431 sal_Int32 nAttrToken,
1432 std::string_view sAttrValue )
1434 if (XML_ELEMENT(TEXT, XML_FIXED) == nAttrToken)
1436 bool bTmp(false);
1437 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1439 bFixed = bTmp;
1442 else
1443 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1446 void XMLSimpleDocInfoImportContext::PrepareField(
1447 const Reference<XPropertySet> & rPropertySet)
1449 // title field in Calc has no Fixed property
1450 Reference<XPropertySetInfo> xPropertySetInfo(rPropertySet->getPropertySetInfo());
1451 if (!xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1452 return;
1454 Any aAny;
1455 rPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
1457 // set Content and CurrentPresentation (if fixed)
1458 if (!bFixed)
1459 return;
1461 // in organizer-mode or styles-only-mode, only force update
1462 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1463 GetImport().GetTextImport()->IsStylesOnlyMode() )
1465 ForceUpdate(rPropertySet);
1467 else
1469 // set content (author, if that's the name) and current
1470 // presentation
1471 aAny <<= GetContent();
1473 if (bFixed && bHasAuthor)
1475 rPropertySet->setPropertyValue(sPropertyAuthor, aAny);
1478 if (bFixed && bHasContent)
1480 rPropertySet->setPropertyValue(sPropertyContent, aAny);
1483 rPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
1487 OUString XMLSimpleDocInfoImportContext::MapTokenToServiceName(
1488 sal_Int32 nElementToken)
1490 OUString pServiceName;
1492 switch(nElementToken)
1494 case XML_ELEMENT(TEXT, XML_INITIAL_CREATOR):
1495 pServiceName = "DocInfo.CreateAuthor";
1496 break;
1497 case XML_ELEMENT(TEXT, XML_CREATION_DATE):
1498 pServiceName = sAPI_docinfo_create_date_time;
1499 break;
1500 case XML_ELEMENT(TEXT, XML_CREATION_TIME):
1501 pServiceName = sAPI_docinfo_create_date_time;
1502 break;
1503 case XML_ELEMENT(TEXT, XML_DESCRIPTION):
1504 pServiceName = "DocInfo.Description";
1505 break;
1506 case XML_ELEMENT(TEXT, XML_EDITING_DURATION):
1507 pServiceName = "DocInfo.EditTime";
1508 break;
1509 case XML_ELEMENT(TEXT, XML_USER_DEFINED):
1510 pServiceName = sAPI_docinfo_custom;
1511 break;
1512 case XML_ELEMENT(TEXT, XML_PRINTED_BY):
1513 pServiceName = "DocInfo.PrintAuthor";
1514 break;
1515 case XML_ELEMENT(TEXT, XML_PRINT_DATE):
1516 pServiceName = sAPI_docinfo_print_date_time;
1517 break;
1518 case XML_ELEMENT(TEXT, XML_PRINT_TIME):
1519 pServiceName = sAPI_docinfo_print_date_time;
1520 break;
1521 case XML_ELEMENT(TEXT, XML_KEYWORDS):
1522 pServiceName = "DocInfo.KeyWords";
1523 break;
1524 case XML_ELEMENT(TEXT, XML_SUBJECT):
1525 pServiceName = "DocInfo.Subject";
1526 break;
1527 case XML_ELEMENT(TEXT, XML_EDITING_CYCLES):
1528 pServiceName = "DocInfo.Revision";
1529 break;
1530 case XML_ELEMENT(TEXT, XML_CREATOR):
1531 pServiceName = "DocInfo.ChangeAuthor";
1532 break;
1533 case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE):
1534 pServiceName = sAPI_docinfo_change_date_time;
1535 break;
1536 case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME):
1537 pServiceName = sAPI_docinfo_change_date_time;
1538 break;
1539 case XML_ELEMENT(TEXT, XML_TITLE):
1540 pServiceName = "DocInfo.Title";
1541 break;
1542 default:
1543 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElementToken);
1544 assert(false);
1547 return pServiceName;
1551 // revision field
1553 constexpr OUStringLiteral sPropertyRevision(u"Revision");
1555 XMLRevisionDocInfoImportContext::XMLRevisionDocInfoImportContext(
1556 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_Int32 nElement) :
1557 XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false)
1559 bValid = true;
1562 void XMLRevisionDocInfoImportContext::PrepareField(
1563 const Reference<XPropertySet> & rPropertySet)
1565 XMLSimpleDocInfoImportContext::PrepareField(rPropertySet);
1567 // set revision number
1568 // if fixed, if not in organizer-mode, if not in styles-only-mode
1569 if (!bFixed)
1570 return;
1572 if ( GetImport().GetTextImport()->IsOrganizerMode() ||
1573 GetImport().GetTextImport()->IsStylesOnlyMode() )
1575 ForceUpdate(rPropertySet);
1577 else
1579 sal_Int32 nTmp;
1580 if (::sax::Converter::convertNumber(nTmp, GetContent()))
1582 rPropertySet->setPropertyValue(sPropertyRevision, Any(nTmp));
1588 // DocInfo fields with date/time attributes
1591 XMLDateTimeDocInfoImportContext::XMLDateTimeDocInfoImportContext(
1592 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_Int32 nElement)
1593 : XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false)
1594 , sPropertyNumberFormat(sAPI_number_format)
1595 , sPropertyIsDate(sAPI_is_date)
1596 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1597 , nFormat(0)
1598 , bFormatOK(false)
1599 , bIsDate(false)
1600 , bHasDateTime(false)
1601 , bIsDefaultLanguage(true)
1603 // we allow processing of EDIT_DURATION here, because import of actual
1604 // is not supported anyway. If it was, we'd need an extra import class
1605 // because times and time durations are presented differently!
1607 bValid = true;
1608 switch (nElement)
1610 case XML_ELEMENT(TEXT, XML_CREATION_DATE):
1611 case XML_ELEMENT(TEXT, XML_PRINT_DATE):
1612 case XML_ELEMENT(TEXT, XML_MODIFICATION_DATE):
1613 bIsDate = true;
1614 bHasDateTime = true;
1615 break;
1616 case XML_ELEMENT(TEXT, XML_CREATION_TIME):
1617 case XML_ELEMENT(TEXT, XML_PRINT_TIME):
1618 case XML_ELEMENT(TEXT, XML_MODIFICATION_TIME):
1619 bIsDate = false;
1620 bHasDateTime = true;
1621 break;
1622 case XML_ELEMENT(TEXT, XML_EDITING_DURATION):
1623 bIsDate = false;
1624 bHasDateTime = false;
1625 break;
1626 default:
1627 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1628 OSL_FAIL("XMLDateTimeDocInfoImportContext needs date/time doc. fields");
1629 bValid = false;
1630 break;
1634 void XMLDateTimeDocInfoImportContext::ProcessAttribute(
1635 sal_Int32 nAttrToken,
1636 std::string_view sAttrValue )
1638 switch (nAttrToken)
1640 case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME):
1642 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1643 OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage);
1644 if (-1 != nKey)
1646 nFormat = nKey;
1647 bFormatOK = true;
1649 break;
1651 case XML_ELEMENT(TEXT, XML_FIXED):
1652 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1653 sAttrValue);
1654 break;
1655 default:
1656 // ignore -> we can't set date/time value anyway!
1657 break;
1661 void XMLDateTimeDocInfoImportContext::PrepareField(
1662 const Reference<XPropertySet> & xPropertySet)
1664 // process fixed and presentation
1665 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
1667 if (bHasDateTime)
1669 xPropertySet->setPropertyValue(sPropertyIsDate, Any(bIsDate));
1672 if (bFormatOK)
1674 xPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormat));
1676 if( xPropertySet->getPropertySetInfo()->
1677 hasPropertyByName( sPropertyIsFixedLanguage ) )
1679 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1680 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1684 // can't set date/time/duration value! Sorry.
1688 // user defined docinfo fields
1691 XMLUserDocInfoImportContext::XMLUserDocInfoImportContext(
1692 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1693 sal_Int32 nElement) :
1694 XMLSimpleDocInfoImportContext(rImport, rHlp, nElement, false, false)
1695 , sPropertyName(sAPI_name)
1696 , sPropertyNumberFormat(sAPI_number_format)
1697 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1698 , nFormat(0)
1699 , bFormatOK(false)
1700 , bIsDefaultLanguage( true )
1702 bValid = false;
1705 void XMLUserDocInfoImportContext::ProcessAttribute(
1706 sal_Int32 nAttrToken,
1707 std::string_view sAttrValue )
1709 switch (nAttrToken)
1711 case XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME):
1713 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1714 OUString::fromUtf8(sAttrValue), &bIsDefaultLanguage);
1715 if (-1 != nKey)
1717 nFormat = nKey;
1718 bFormatOK = true;
1720 break;
1722 case XML_ELEMENT(TEXT, XML_NAME):
1724 if (!bValid)
1726 SetServiceName(sAPI_docinfo_custom );
1727 aName = OUString::fromUtf8(sAttrValue);
1728 bValid = true;
1730 break;
1733 default:
1734 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1735 sAttrValue);
1736 break;
1740 void XMLUserDocInfoImportContext::PrepareField(
1741 const css::uno::Reference<css::beans::XPropertySet> & xPropertySet)
1743 if ( !aName.isEmpty() )
1745 xPropertySet->setPropertyValue(sPropertyName, Any(aName));
1747 Reference<XPropertySetInfo> xPropertySetInfo(
1748 xPropertySet->getPropertySetInfo());
1749 if (bFormatOK &&
1750 xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1752 xPropertySet->setPropertyValue(sPropertyNumberFormat, Any(nFormat));
1754 if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
1756 bool bIsFixedLanguage = ! bIsDefaultLanguage;
1757 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, Any(bIsFixedLanguage) );
1761 // call superclass to handle "fixed"
1762 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
1766 // import hidden paragraph fields
1769 XMLHiddenParagraphImportContext::XMLHiddenParagraphImportContext(
1770 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1771 XMLTextFieldImportContext(rImport, rHlp, u"HiddenParagraph"_ustr),
1772 sPropertyCondition(sAPI_condition),
1773 sPropertyIsHidden(sAPI_is_hidden),
1774 bIsHidden(false)
1778 void XMLHiddenParagraphImportContext::ProcessAttribute(
1779 sal_Int32 nAttrToken,
1780 std::string_view sAttrValue )
1782 if ( XML_ELEMENT(TEXT, XML_CONDITION) == nAttrToken)
1784 OUString sTmp;
1785 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrValueQName(
1786 OUString::fromUtf8(sAttrValue), &sTmp );
1787 if( XML_NAMESPACE_OOOW == nPrefix )
1789 sCondition = sTmp;
1790 bValid = true;
1792 else
1793 sCondition = OUString::fromUtf8(sAttrValue);
1795 else if ( XML_ELEMENT(TEXT, XML_IS_HIDDEN) == nAttrToken)
1797 bool bTmp(false);
1798 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1800 bIsHidden = bTmp;
1803 else
1804 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1807 void XMLHiddenParagraphImportContext::PrepareField(
1808 const Reference<XPropertySet> & xPropertySet)
1810 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
1811 xPropertySet->setPropertyValue(sPropertyIsHidden, Any(bIsHidden));
1815 // import conditional text (<text:conditional-text>)
1817 constexpr OUStringLiteral gsPropertyTrueContent(u"TrueContent");
1818 constexpr OUStringLiteral gsPropertyFalseContent(u"FalseContent");
1819 constexpr OUStringLiteral gsPropertyIsConditionTrue(u"IsConditionTrue");
1821 XMLConditionalTextImportContext::XMLConditionalTextImportContext(
1822 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1823 XMLTextFieldImportContext(rImport, rHlp, u"ConditionalText"_ustr),
1824 sPropertyCondition(sAPI_condition),
1825 sPropertyCurrentPresentation(sAPI_current_presentation),
1826 bConditionOK(false),
1827 bTrueOK(false),
1828 bFalseOK(false),
1829 bCurrentValue(false)
1833 void XMLConditionalTextImportContext::ProcessAttribute(
1834 sal_Int32 nAttrToken,
1835 std::string_view sAttrValue )
1837 switch (nAttrToken)
1839 case XML_ELEMENT(TEXT, XML_CONDITION):
1841 OUString sTmp;
1842 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1843 GetKeyByAttrValueQName(OUString::fromUtf8(sAttrValue), &sTmp);
1844 if( XML_NAMESPACE_OOOW == nPrefix )
1846 sCondition = sTmp;
1847 bConditionOK = true;
1849 else
1850 sCondition = OUString::fromUtf8(sAttrValue);
1852 break;
1853 case XML_ELEMENT(TEXT, XML_STRING_VALUE_IF_FALSE):
1854 sFalseContent = OUString::fromUtf8(sAttrValue);
1855 bFalseOK = true;
1856 break;
1857 case XML_ELEMENT(TEXT, XML_STRING_VALUE_IF_TRUE):
1858 sTrueContent = OUString::fromUtf8(sAttrValue);
1859 bTrueOK = true;
1860 break;
1861 case XML_ELEMENT(TEXT, XML_CURRENT_VALUE):
1863 bool bTmp(false);
1864 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1866 bCurrentValue = bTmp;
1868 break;
1870 default:
1871 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1874 bValid = bConditionOK && bFalseOK && bTrueOK;
1877 void XMLConditionalTextImportContext::PrepareField(
1878 const Reference<XPropertySet> & xPropertySet)
1880 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
1881 xPropertySet->setPropertyValue(gsPropertyFalseContent, Any(sFalseContent));
1882 xPropertySet->setPropertyValue(gsPropertyTrueContent, Any(sTrueContent));
1883 xPropertySet->setPropertyValue(gsPropertyIsConditionTrue, Any(bCurrentValue));
1884 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, Any(GetContent()));
1888 // hidden text
1891 XMLHiddenTextImportContext::XMLHiddenTextImportContext(
1892 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1893 XMLTextFieldImportContext(rImport, rHlp, u"HiddenText"_ustr),
1894 sPropertyCondition(sAPI_condition),
1895 sPropertyContent(sAPI_content),
1896 sPropertyIsHidden(sAPI_is_hidden),
1897 bConditionOK(false),
1898 bStringOK(false),
1899 bIsHidden(false)
1903 void XMLHiddenTextImportContext::ProcessAttribute(
1904 sal_Int32 nAttrToken,
1905 std::string_view sAttrValue )
1907 switch (nAttrToken)
1909 case XML_ELEMENT(TEXT, XML_CONDITION):
1911 OUString sTmp;
1912 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1913 GetKeyByAttrValueQName(OUString::fromUtf8(sAttrValue), &sTmp);
1914 if( XML_NAMESPACE_OOOW == nPrefix )
1916 sCondition = sTmp;
1917 bConditionOK = true;
1919 else
1920 sCondition = OUString::fromUtf8(sAttrValue);
1922 break;
1923 case XML_ELEMENT(TEXT, XML_STRING_VALUE):
1924 case XML_ELEMENT(OFFICE, XML_STRING_VALUE):
1925 sString = OUString::fromUtf8(sAttrValue);
1926 bStringOK = true;
1927 break;
1928 case XML_ELEMENT(TEXT, XML_IS_HIDDEN):
1930 bool bTmp(false);
1931 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1933 bIsHidden = bTmp;
1935 break;
1937 default:
1938 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
1941 bValid = bConditionOK && bStringOK;
1944 void XMLHiddenTextImportContext::PrepareField(
1945 const Reference<XPropertySet> & xPropertySet)
1947 xPropertySet->setPropertyValue(sPropertyCondition, Any(sCondition));
1948 xPropertySet->setPropertyValue(sPropertyContent, Any(sString));
1949 xPropertySet->setPropertyValue(sPropertyIsHidden, Any(bIsHidden));
1953 // file name fields
1956 const SvXMLEnumMapEntry<sal_uInt16> aFilenameDisplayMap[] =
1958 { XML_PATH, FilenameDisplayFormat::PATH },
1959 { XML_NAME, FilenameDisplayFormat::NAME },
1960 { XML_NAME_AND_EXTENSION, FilenameDisplayFormat::NAME_AND_EXT },
1961 { XML_FULL, FilenameDisplayFormat::FULL },
1962 { XML_TOKEN_INVALID, 0 }
1965 XMLFileNameImportContext::XMLFileNameImportContext(
1966 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
1967 XMLTextFieldImportContext(rImport, rHlp, u"FileName"_ustr),
1968 sPropertyFixed(sAPI_is_fixed),
1969 sPropertyFileFormat(sAPI_file_format),
1970 sPropertyCurrentPresentation(
1971 sAPI_current_presentation),
1972 nFormat(FilenameDisplayFormat::FULL),
1973 bFixed(false)
1975 bValid = true;
1978 void XMLFileNameImportContext::ProcessAttribute(
1979 sal_Int32 nAttrToken,
1980 std::string_view sAttrValue )
1982 switch (nAttrToken)
1984 case XML_ELEMENT(TEXT, XML_FIXED):
1986 bool bTmp(false);
1987 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1989 bFixed = bTmp;
1991 break;
1993 case XML_ELEMENT(TEXT, XML_DISPLAY):
1995 sal_uInt16 nTmp;
1996 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
1997 aFilenameDisplayMap))
1999 nFormat = nTmp;
2001 break;
2003 default:
2004 // unknown attribute: ignore
2005 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2006 break;
2010 void XMLFileNameImportContext::PrepareField(
2011 const Reference<XPropertySet> & xPropertySet)
2013 // properties are optional
2014 Reference<XPropertySetInfo> xPropertySetInfo(
2015 xPropertySet->getPropertySetInfo());
2017 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
2019 xPropertySet->setPropertyValue(sPropertyFixed, Any(bFixed));
2022 if (xPropertySetInfo->hasPropertyByName(sPropertyFileFormat))
2024 xPropertySet->setPropertyValue(sPropertyFileFormat, Any(nFormat));
2027 if (xPropertySetInfo->hasPropertyByName(sPropertyCurrentPresentation))
2029 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, Any(GetContent()));
2034 // template name field
2037 const SvXMLEnumMapEntry<sal_uInt16> aTemplateDisplayMap[] =
2039 { XML_FULL, TemplateDisplayFormat::FULL },
2040 { XML_PATH, TemplateDisplayFormat::PATH },
2041 { XML_NAME, TemplateDisplayFormat::NAME },
2042 { XML_NAME_AND_EXTENSION, TemplateDisplayFormat::NAME_AND_EXT },
2043 { XML_AREA, TemplateDisplayFormat::AREA },
2044 { XML_TITLE, TemplateDisplayFormat::TITLE },
2045 { XML_TOKEN_INVALID, 0 }
2049 XMLTemplateNameImportContext::XMLTemplateNameImportContext(
2050 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2051 XMLTextFieldImportContext(rImport, rHlp, u"TemplateName"_ustr),
2052 sPropertyFileFormat(sAPI_file_format),
2053 nFormat(TemplateDisplayFormat::FULL)
2055 bValid = true;
2058 void XMLTemplateNameImportContext::ProcessAttribute(
2059 sal_Int32 nAttrToken,
2060 std::string_view sAttrValue )
2062 switch (nAttrToken)
2064 case XML_ELEMENT(TEXT, XML_DISPLAY):
2066 sal_uInt16 nTmp;
2067 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2068 aTemplateDisplayMap))
2070 nFormat = nTmp;
2072 break;
2074 default:
2075 // unknown attribute: ignore
2076 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2077 break;
2081 void XMLTemplateNameImportContext::PrepareField(
2082 const Reference<XPropertySet> & xPropertySet)
2084 xPropertySet->setPropertyValue(sPropertyFileFormat, Any(nFormat));
2088 // import chapter fields
2091 const SvXMLEnumMapEntry<sal_uInt16> aChapterDisplayMap[] =
2093 { XML_NAME, ChapterFormat::NAME },
2094 { XML_NUMBER, ChapterFormat::NUMBER },
2095 { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
2096 { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
2097 { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
2098 { XML_TOKEN_INVALID, 0 }
2101 constexpr OUStringLiteral gsPropertyChapterFormat(u"ChapterFormat");
2102 constexpr OUStringLiteral gsPropertyLevel(u"Level");
2104 XMLChapterImportContext::XMLChapterImportContext(
2105 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2106 XMLTextFieldImportContext(rImport, rHlp, u"Chapter"_ustr),
2107 nFormat(ChapterFormat::NAME_NUMBER),
2108 nLevel(0)
2110 bValid = true;
2113 void XMLChapterImportContext::ProcessAttribute(
2114 sal_Int32 nAttrToken,
2115 std::string_view sAttrValue )
2117 switch (nAttrToken)
2119 case XML_ELEMENT(TEXT, XML_DISPLAY):
2121 sal_uInt16 nTmp;
2122 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2123 aChapterDisplayMap))
2125 nFormat = static_cast<sal_Int16>(nTmp);
2127 break;
2129 case XML_ELEMENT(TEXT, XML_OUTLINE_LEVEL):
2131 sal_Int32 nTmp;
2132 if (::sax::Converter::convertNumber(
2133 nTmp, sAttrValue, 1,
2134 GetImport().GetTextImport()->GetChapterNumbering()->getCount()
2137 // API numbers 0..9, we number 1..10
2138 nLevel = static_cast<sal_Int8>(nTmp);
2139 nLevel--;
2141 break;
2143 default:
2144 // unknown attribute: ignore
2145 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2146 break;
2150 void XMLChapterImportContext::PrepareField(
2151 const Reference<XPropertySet> & xPropertySet)
2153 xPropertySet->setPropertyValue(gsPropertyChapterFormat, Any(nFormat));
2154 xPropertySet->setPropertyValue(gsPropertyLevel, Any(nLevel));
2158 // counting fields
2161 XMLCountFieldImportContext::XMLCountFieldImportContext(
2162 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2163 sal_Int32 nElement) :
2164 XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nElement)),
2165 sPropertyNumberingType(
2166 sAPI_numbering_type),
2167 bNumberFormatOK(false)
2169 bValid = true;
2172 void XMLCountFieldImportContext::ProcessAttribute(
2173 sal_Int32 nAttrToken,
2174 std::string_view sAttrValue )
2176 switch (nAttrToken)
2178 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
2179 sNumberFormat = OUString::fromUtf8(sAttrValue);
2180 bNumberFormatOK = true;
2181 break;
2182 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
2183 sLetterSync = OUString::fromUtf8(sAttrValue);
2184 break;
2185 default:
2186 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2190 void XMLCountFieldImportContext::PrepareField(
2191 const Reference<XPropertySet> & xPropertySet)
2193 // properties optional
2194 // (only page count, but do for all to save common implementation)
2196 if (!xPropertySet->getPropertySetInfo()->
2197 hasPropertyByName(sPropertyNumberingType))
2198 return;
2200 sal_Int16 nNumType;
2201 if( bNumberFormatOK )
2203 nNumType= style::NumberingType::ARABIC;
2204 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2205 sNumberFormat,
2206 sLetterSync );
2208 else
2209 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2210 xPropertySet->setPropertyValue(sPropertyNumberingType, Any(nNumType));
2213 OUString XMLCountFieldImportContext::MapTokenToServiceName(
2214 sal_Int32 nElement)
2216 OUString pServiceName;
2218 switch (nElement)
2220 case XML_ELEMENT(TEXT, XML_WORD_COUNT):
2221 pServiceName = "WordCount";
2222 break;
2223 case XML_ELEMENT(TEXT, XML_PARAGRAPH_COUNT):
2224 pServiceName = "ParagraphCount";
2225 break;
2226 case XML_ELEMENT(TEXT, XML_TABLE_COUNT):
2227 pServiceName = "TableCount";
2228 break;
2229 case XML_ELEMENT(TEXT, XML_CHARACTER_COUNT):
2230 pServiceName = "CharacterCount";
2231 break;
2232 case XML_ELEMENT(TEXT, XML_IMAGE_COUNT):
2233 pServiceName = "GraphicObjectCount";
2234 break;
2235 case XML_ELEMENT(TEXT, XML_OBJECT_COUNT):
2236 pServiceName = "EmbeddedObjectCount";
2237 break;
2238 case XML_ELEMENT(TEXT, XML_PAGE_COUNT):
2239 pServiceName = "PageCount";
2240 break;
2241 default:
2242 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
2243 assert(false);
2246 return pServiceName;
2250 // page variable import
2253 XMLPageVarGetFieldImportContext::XMLPageVarGetFieldImportContext(
2254 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2255 XMLTextFieldImportContext(rImport, rHlp, u"ReferencePageGet"_ustr),
2256 bNumberFormatOK(false)
2258 bValid = true;
2261 void XMLPageVarGetFieldImportContext::ProcessAttribute(
2262 sal_Int32 nAttrToken,
2263 std::string_view sAttrValue )
2265 switch (nAttrToken)
2267 case XML_ELEMENT(STYLE, XML_NUM_FORMAT):
2268 sNumberFormat = OUString::fromUtf8(sAttrValue);
2269 bNumberFormatOK = true;
2270 break;
2271 case XML_ELEMENT(STYLE, XML_NUM_LETTER_SYNC):
2272 sLetterSync = OUString::fromUtf8(sAttrValue);
2273 break;
2274 default:
2275 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2279 void XMLPageVarGetFieldImportContext::PrepareField(
2280 const Reference<XPropertySet> & xPropertySet)
2282 sal_Int16 nNumType;
2283 if( bNumberFormatOK )
2285 nNumType= style::NumberingType::ARABIC;
2286 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2287 sNumberFormat,
2288 sLetterSync );
2290 else
2291 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2292 xPropertySet->setPropertyValue(sAPI_numbering_type, Any(nNumType));
2294 // display old content (#96657#)
2295 xPropertySet->setPropertyValue( sAPI_current_presentation, Any(GetContent()) );
2299 // page variable set fields
2302 XMLPageVarSetFieldImportContext::XMLPageVarSetFieldImportContext(
2303 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2304 XMLTextFieldImportContext(rImport, rHlp, u"ReferencePageSet"_ustr),
2305 nAdjust(0),
2306 bActive(true)
2308 bValid = true;
2311 void XMLPageVarSetFieldImportContext::ProcessAttribute(
2312 sal_Int32 nAttrToken,
2313 std::string_view sAttrValue )
2315 switch (nAttrToken)
2317 case XML_ELEMENT(TEXT, XML_ACTIVE):
2319 bool bTmp(false);
2320 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2322 bActive = bTmp;
2324 break;
2326 case XML_ELEMENT(TEXT, XML_PAGE_ADJUST):
2328 sal_Int32 nTmp(0);
2329 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
2331 nAdjust = static_cast<sal_Int16>(nTmp);
2333 break;
2335 default:
2336 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2337 break;
2341 void XMLPageVarSetFieldImportContext::PrepareField(
2342 const Reference<XPropertySet> & xPropertySet)
2344 xPropertySet->setPropertyValue(u"On"_ustr, Any(bActive));
2345 xPropertySet->setPropertyValue(sAPI_offset, Any(nAdjust));
2349 // macro fields
2352 XMLMacroFieldImportContext::XMLMacroFieldImportContext(
2353 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2354 XMLTextFieldImportContext(rImport, rHlp, u"Macro"_ustr),
2355 bDescriptionOK(false)
2359 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLMacroFieldImportContext::createFastChildContext(
2360 sal_Int32 nElement,
2361 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
2363 if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) )
2365 // create events context and remember it!
2366 xEventContext = new XMLEventsImportContext( GetImport() );
2367 bValid = true;
2368 return xEventContext;
2370 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
2372 return nullptr;
2375 void XMLMacroFieldImportContext::ProcessAttribute(
2376 sal_Int32 nAttrToken,
2377 std::string_view sAttrValue )
2379 switch (nAttrToken)
2381 case XML_ELEMENT(TEXT, XML_DESCRIPTION):
2382 sDescription = OUString::fromUtf8(sAttrValue);
2383 bDescriptionOK = true;
2384 break;
2385 case XML_ELEMENT(TEXT, XML_NAME):
2386 sMacro = OUString::fromUtf8(sAttrValue);
2387 bValid = true;
2388 break;
2389 default:
2390 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2394 void XMLMacroFieldImportContext::PrepareField(
2395 const Reference<XPropertySet> & xPropertySet)
2397 Any aAny;
2398 aAny <<= (bDescriptionOK ? sDescription : GetContent());
2399 xPropertySet->setPropertyValue(sAPI_hint, aAny);
2401 // if we have an events child element, we'll look for the OnClick
2402 // event if not, it may be an old (pre-638i) document. Then, we'll
2403 // have to look at the name attribute.
2404 OUString sMacroName;
2405 OUString sLibraryName;
2406 OUString sScriptURL;
2408 if ( xEventContext.is() )
2410 // get event sequence
2411 XMLEventsImportContext* pEvents = xEventContext.get();
2412 Sequence<PropertyValue> aValues;
2413 pEvents->GetEventSequence( u"OnClick"_ustr, aValues );
2415 for (const auto& rValue : aValues)
2417 if ( rValue.Name == "ScriptType" )
2419 // ignore ScriptType
2421 else if ( rValue.Name == "Library" )
2423 rValue.Value >>= sLibraryName;
2425 else if ( rValue.Name == "MacroName" )
2427 rValue.Value >>= sMacroName;
2429 if ( rValue.Name == "Script" )
2431 rValue.Value >>= sScriptURL;
2435 else
2437 // disassemble old-style macro-name: Everything before the
2438 // third-last dot is the library
2439 sal_Int32 nPos = sMacro.getLength() + 1; // the loop starts with nPos--
2440 const sal_Unicode* pBuf = sMacro.getStr();
2441 for( sal_Int32 i = 0; (i < 3) && (nPos > 0); i++ )
2443 nPos--;
2444 while ( (pBuf[nPos] != '.') && (nPos > 0) )
2445 nPos--;
2448 if (nPos > 0)
2450 sLibraryName = sMacro.copy(0, nPos);
2451 sMacroName = sMacro.copy(nPos+1);
2453 else
2454 sMacroName = sMacro;
2457 xPropertySet->setPropertyValue(u"ScriptURL"_ustr, Any(sScriptURL));
2458 xPropertySet->setPropertyValue(u"MacroName"_ustr, Any(sMacroName));
2459 xPropertySet->setPropertyValue(u"MacroLibrary"_ustr, Any(sLibraryName));
2463 // reference field import
2466 XMLReferenceFieldImportContext::XMLReferenceFieldImportContext(
2467 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2468 sal_Int32 nToken)
2469 : XMLTextFieldImportContext(rImport, rHlp, u"GetReference"_ustr)
2470 , nElementToken(nToken)
2471 , nSource(0)
2472 , nType(ReferenceFieldPart::PAGE_DESC)
2473 , nFlags(0)
2474 , bNameOK(false)
2475 , bTypeOK(false)
2479 SvXMLEnumMapEntry<sal_uInt16> const lcl_aReferenceTypeTokenMap[] =
2481 { XML_PAGE, ReferenceFieldPart::PAGE},
2482 { XML_CHAPTER, ReferenceFieldPart::CHAPTER },
2483 { XML_TEXT, ReferenceFieldPart::TEXT },
2484 { XML_DIRECTION, ReferenceFieldPart::UP_DOWN },
2485 { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
2486 { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
2487 { XML_VALUE, ReferenceFieldPart::ONLY_SEQUENCE_NUMBER },
2488 // Core implementation for direct cross-references (#i81002#)
2489 { XML_NUMBER, ReferenceFieldPart::NUMBER },
2490 { XML_NUMBER_NO_SUPERIOR, ReferenceFieldPart::NUMBER_NO_CONTEXT },
2491 { XML_NUMBER_ALL_SUPERIOR, ReferenceFieldPart::NUMBER_FULL_CONTEXT },
2492 { XML_TOKEN_INVALID, 0 }
2495 void XMLReferenceFieldImportContext::startFastElement(
2496 sal_Int32 nElement,
2497 const Reference<XFastAttributeList> & xAttrList)
2499 bTypeOK = true;
2500 switch (nElementToken)
2502 case XML_ELEMENT(TEXT, XML_REFERENCE_REF):
2503 nSource = ReferenceFieldSource::REFERENCE_MARK;
2504 break;
2505 case XML_ELEMENT(TEXT, XML_BOOKMARK_REF):
2506 nSource = ReferenceFieldSource::BOOKMARK;
2507 break;
2508 case XML_ELEMENT(TEXT, XML_NOTE_REF):
2509 nSource = ReferenceFieldSource::FOOTNOTE;
2510 break;
2511 case XML_ELEMENT(TEXT, XML_SEQUENCE_REF):
2512 nSource = ReferenceFieldSource::SEQUENCE_FIELD;
2513 break;
2514 case XML_ELEMENT(TEXT, XML_STYLE_REF):
2515 case XML_ELEMENT(LO_EXT, XML_STYLE_REF):
2516 nSource = ReferenceFieldSource::STYLE;
2517 break;
2518 default:
2519 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElementToken);
2520 bTypeOK = false;
2521 break;
2524 XMLTextFieldImportContext::startFastElement(nElement, xAttrList);
2528 void XMLReferenceFieldImportContext::ProcessAttribute(
2529 sal_Int32 nAttrToken,
2530 std::string_view sAttrValue )
2532 switch (nAttrToken)
2534 case XML_ELEMENT(TEXT, XML_NOTE_CLASS):
2535 if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
2536 nSource = ReferenceFieldSource::ENDNOTE;
2537 break;
2538 case XML_ELEMENT(TEXT, XML_REF_NAME):
2539 sName = OUString::fromUtf8(sAttrValue);
2540 bNameOK = true;
2541 break;
2542 case XML_ELEMENT(TEXT, XML_REFERENCE_FORMAT):
2544 sal_uInt16 nToken;
2545 if (SvXMLUnitConverter::convertEnum(nToken, sAttrValue,
2546 lcl_aReferenceTypeTokenMap))
2548 nType = nToken;
2551 // check for sequence-only-attributes
2552 if ( (XML_ELEMENT(TEXT, XML_SEQUENCE_REF) != nElementToken) &&
2553 ( (nType == ReferenceFieldPart::CATEGORY_AND_NUMBER) ||
2554 (nType == ReferenceFieldPart::ONLY_CAPTION) ||
2555 (nType == ReferenceFieldPart::ONLY_SEQUENCE_NUMBER) ) )
2557 nType = ReferenceFieldPart::PAGE_DESC;
2560 break;
2562 case XML_ELEMENT(LO_EXT, XML_REFERENCE_LANGUAGE):
2563 case XML_ELEMENT(TEXT, XML_REFERENCE_LANGUAGE):
2564 sLanguage = OUString::fromUtf8(sAttrValue);
2565 break;
2566 case XML_ELEMENT(LO_EXT, XML_REFERENCE_HIDE_NON_NUMERICAL):
2567 case XML_ELEMENT(TEXT, XML_REFERENCE_HIDE_NON_NUMERICAL):
2568 if (OUString::fromUtf8(sAttrValue).toBoolean())
2569 nFlags |= REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL;
2570 break;
2571 case XML_ELEMENT(LO_EXT, XML_REFERENCE_FROM_BOTTOM):
2572 case XML_ELEMENT(TEXT, XML_REFERENCE_FROM_BOTTOM):
2573 if (OUString::fromUtf8(sAttrValue).toBoolean())
2574 nFlags |= REFFLDFLAG_STYLE_FROM_BOTTOM;
2575 break;
2576 default:
2577 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2580 // bValid: we need proper element type and name
2581 bValid = bTypeOK && bNameOK;
2584 void XMLReferenceFieldImportContext::PrepareField(
2585 const Reference<XPropertySet> & xPropertySet)
2587 xPropertySet->setPropertyValue(u"ReferenceFieldPart"_ustr, Any(nType));
2589 xPropertySet->setPropertyValue(u"ReferenceFieldSource"_ustr, Any(nSource));
2591 xPropertySet->setPropertyValue(u"ReferenceFieldLanguage"_ustr, Any(sLanguage));
2592 switch (nElementToken)
2594 case XML_ELEMENT(TEXT, XML_REFERENCE_REF):
2595 case XML_ELEMENT(TEXT, XML_BOOKMARK_REF):
2596 case XML_ELEMENT(TEXT, XML_STYLE_REF):
2597 case XML_ELEMENT(LO_EXT, XML_STYLE_REF):
2598 xPropertySet->setPropertyValue(u"SourceName"_ustr, Any(sName));
2599 xPropertySet->setPropertyValue(u"ReferenceFieldFlags"_ustr, Any(nFlags));
2600 break;
2602 case XML_ELEMENT(TEXT, XML_NOTE_REF):
2603 GetImportHelper().ProcessFootnoteReference(sName, xPropertySet);
2604 break;
2606 case XML_ELEMENT(TEXT, XML_SEQUENCE_REF):
2607 GetImportHelper().ProcessSequenceReference(sName, xPropertySet);
2608 break;
2611 xPropertySet->setPropertyValue(sAPI_current_presentation, Any(GetContent()));
2615 // field declarations container
2617 XMLDdeFieldDeclsImportContext::XMLDdeFieldDeclsImportContext(SvXMLImport& rImport) :
2618 SvXMLImportContext(rImport)
2622 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDdeFieldDeclsImportContext::createFastChildContext(
2623 sal_Int32 nElement,
2624 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
2626 if ( nElement == XML_ELEMENT(TEXT, XML_DDE_CONNECTION_DECL) )
2628 return new XMLDdeFieldDeclImportContext(GetImport());
2630 else
2631 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
2632 return nullptr;
2636 // import dde field declaration
2639 XMLDdeFieldDeclImportContext::XMLDdeFieldDeclImportContext(SvXMLImport& rImport)
2640 : SvXMLImportContext(rImport)
2644 void XMLDdeFieldDeclImportContext::startFastElement(
2645 sal_Int32 /*nElement*/,
2646 const Reference<XFastAttributeList> & xAttrList)
2648 OUString sName;
2649 OUString sCommandApplication;
2650 OUString sCommandTopic;
2651 OUString sCommandItem;
2653 bool bUpdate = false;
2654 bool bNameOK = false;
2655 bool bCommandApplicationOK = false;
2656 bool bCommandTopicOK = false;
2657 bool bCommandItemOK = false;
2659 // process attributes
2660 for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
2662 switch (aIter.getToken())
2664 case XML_ELEMENT(OFFICE, XML_NAME):
2665 sName = aIter.toString();
2666 bNameOK = true;
2667 break;
2668 case XML_ELEMENT(OFFICE, XML_DDE_APPLICATION):
2669 sCommandApplication = aIter.toString();
2670 bCommandApplicationOK = true;
2671 break;
2672 case XML_ELEMENT(OFFICE, XML_DDE_TOPIC):
2673 sCommandTopic = aIter.toString();
2674 bCommandTopicOK = true;
2675 break;
2676 case XML_ELEMENT(OFFICE, XML_DDE_ITEM):
2677 sCommandItem = aIter.toString();
2678 bCommandItemOK = true;
2679 break;
2680 case XML_ELEMENT(OFFICE, XML_AUTOMATIC_UPDATE):
2682 bool bTmp(false);
2683 if (::sax::Converter::convertBool(bTmp, aIter.toView()) )
2685 bUpdate = bTmp;
2687 break;
2689 default:
2690 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
2694 // valid data?
2695 if (!(bNameOK && bCommandApplicationOK && bCommandTopicOK && bCommandItemOK))
2696 return;
2698 // create DDE TextFieldMaster
2699 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),
2700 UNO_QUERY);
2701 if( !xFactory.is() )
2702 return;
2704 /* #i6432# There might be multiple occurrences of one DDE
2705 declaration if it is used in more than one of
2706 header/footer/body. createInstance will throw an exception if we
2707 try to create the second, third, etc. instance of such a
2708 declaration. Thus we ignore the exception. Otherwise this will
2709 lead to an unloadable document. */
2712 Reference<XInterface> xIfc =
2713 xFactory->createInstance(OUString::Concat(sAPI_fieldmaster_prefix) + sAPI_dde);
2714 if( xIfc.is() )
2716 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
2717 if (xPropSet.is() &&
2718 xPropSet->getPropertySetInfo()->hasPropertyByName(
2719 u"DDECommandType"_ustr))
2721 xPropSet->setPropertyValue(sAPI_name, Any(sName));
2723 xPropSet->setPropertyValue(u"DDECommandType"_ustr, Any(sCommandApplication));
2725 xPropSet->setPropertyValue(u"DDECommandFile"_ustr, Any(sCommandTopic));
2727 xPropSet->setPropertyValue(u"DDECommandElement"_ustr,
2728 Any(sCommandItem));
2730 xPropSet->setPropertyValue(u"IsAutomaticUpdate"_ustr,
2731 Any(bUpdate));
2733 // else: ignore (can't get XPropertySet, or DDE
2734 // properties are not supported)
2736 // else: ignore
2738 catch (const Exception&)
2740 //ignore
2742 // else: ignore
2743 // else: ignore
2747 // DDE field import
2750 XMLDdeFieldImportContext::XMLDdeFieldImportContext(
2751 SvXMLImport& rImport, XMLTextImportHelper& rHlp) :
2752 XMLTextFieldImportContext(rImport, rHlp, sAPI_dde),
2753 sPropertyContent(sAPI_content)
2757 void XMLDdeFieldImportContext::ProcessAttribute(
2758 sal_Int32 nAttrToken,
2759 std::string_view sAttrValue )
2761 if ( XML_ELEMENT(TEXT, XML_CONNECTION_NAME) == nAttrToken)
2763 sName = OUString::fromUtf8(sAttrValue);
2764 bValid = true;
2766 else
2767 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2771 void XMLDdeFieldImportContext::endFastElement(sal_Int32 )
2773 if (!bValid)
2774 return;
2776 // find master
2777 OUString sMasterName = OUString::Concat(sAPI_fieldmaster_prefix) + sAPI_dde + "." + sName;
2779 Reference<XTextFieldsSupplier> xTextFieldsSupp(GetImport().GetModel(),
2780 UNO_QUERY);
2781 Reference<container::XNameAccess> xFieldMasterNameAccess =
2782 xTextFieldsSupp->getTextFieldMasters();
2784 if (!xFieldMasterNameAccess->hasByName(sMasterName))
2785 return;
2787 Reference<XPropertySet> xMaster;
2788 Any aAny = xFieldMasterNameAccess->getByName(sMasterName);
2789 aAny >>= xMaster;
2790 //apply the content to the master
2791 xMaster->setPropertyValue( sPropertyContent, uno::Any( GetContent()));
2792 // master exists: create text field and attach
2793 Reference<XPropertySet> xField;
2794 OUString sFieldName = OUString::Concat(sAPI_textfield_prefix) + sAPI_dde;
2795 if (!CreateField(xField, sFieldName))
2796 return;
2798 Reference<XDependentTextField> xDepTextField(xField,UNO_QUERY);
2799 xDepTextField->attachTextFieldMaster(xMaster);
2801 // attach field to document
2802 Reference<XTextContent> xTextContent(xField, UNO_QUERY);
2803 if (xTextContent.is())
2805 GetImportHelper().InsertTextContent(xTextContent);
2807 // we're lucky. nothing else to prepare.
2809 // else: fail, because text content could not be created
2810 // else: fail, because field could not be created
2811 // else: fail, because no master was found (faulty document?!)
2812 // not valid: ignore
2815 void XMLDdeFieldImportContext::PrepareField(
2816 const Reference<XPropertySet> &)
2818 // empty, since not needed.
2822 // sheet name fields
2825 XMLSheetNameImportContext::XMLSheetNameImportContext(
2826 SvXMLImport& rImport,
2827 XMLTextImportHelper& rHlp) :
2828 XMLTextFieldImportContext(rImport, rHlp, u"SheetName"_ustr)
2830 bValid = true; // always valid!
2833 void XMLSheetNameImportContext::ProcessAttribute(
2834 sal_Int32 nAttrToken,
2835 std::string_view sAttrValue)
2837 // no attributes -> nothing to be done
2838 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2841 void XMLSheetNameImportContext::PrepareField(
2842 const Reference<XPropertySet> &)
2844 // no attributes -> nothing to be done
2847 /** import page|slide name fields (<text:page-name>) */
2849 XMLPageNameFieldImportContext::XMLPageNameFieldImportContext(
2850 SvXMLImport& rImport, /// XML Import
2851 XMLTextImportHelper& rHlp) /// Text import helper
2852 : XMLTextFieldImportContext(rImport, rHlp, u"PageName"_ustr )
2854 bValid = true;
2857 /// process attribute values
2858 void XMLPageNameFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken,
2859 std::string_view sAttrValue )
2861 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2864 /// prepare XTextField for insertion into document
2865 void XMLPageNameFieldImportContext::PrepareField(
2866 const css::uno::Reference<css::beans::XPropertySet> &)
2871 // URL fields (Calc, Impress, Draw)
2874 XMLUrlFieldImportContext::XMLUrlFieldImportContext(
2875 SvXMLImport& rImport,
2876 XMLTextImportHelper& rHlp) :
2877 XMLTextFieldImportContext(rImport, rHlp, sAPI_url),
2878 bFrameOK(false)
2882 void XMLUrlFieldImportContext::ProcessAttribute(
2883 sal_Int32 nAttrToken,
2884 std::string_view sAttrValue )
2886 switch (nAttrToken)
2888 case XML_ELEMENT(XLINK, XML_HREF):
2889 sURL = GetImport().GetAbsoluteReference( OUString::fromUtf8(sAttrValue) );
2890 bValid = true;
2891 break;
2892 case XML_ELEMENT(OFFICE, XML_TARGET_FRAME_NAME):
2893 sFrame = OUString::fromUtf8(sAttrValue);
2894 bFrameOK = true;
2895 break;
2896 default:
2897 // ignore
2898 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
2899 break;
2903 void XMLUrlFieldImportContext::PrepareField(
2904 const Reference<XPropertySet> & xPropertySet)
2906 xPropertySet->setPropertyValue(sAPI_url, Any(sURL));
2908 if (bFrameOK)
2910 xPropertySet->setPropertyValue(u"TargetFrame"_ustr, Any(sFrame));
2913 xPropertySet->setPropertyValue(u"Representation"_ustr, Any(GetContent()));
2917 XMLBibliographyFieldImportContext::XMLBibliographyFieldImportContext(
2918 SvXMLImport& rImport,
2919 XMLTextImportHelper& rHlp) :
2920 XMLTextFieldImportContext(rImport, rHlp, u"Bibliography"_ustr)
2922 bValid = true;
2925 // TODO: this is the same map as is used in the text field export
2926 SvXMLEnumMapEntry<sal_uInt16> const aBibliographyDataTypeMap[] =
2928 { XML_ARTICLE, BibliographyDataType::ARTICLE },
2929 { XML_BOOK, BibliographyDataType::BOOK },
2930 { XML_BOOKLET, BibliographyDataType::BOOKLET },
2931 { XML_CONFERENCE, BibliographyDataType::CONFERENCE },
2932 { XML_CUSTOM1, BibliographyDataType::CUSTOM1 },
2933 { XML_CUSTOM2, BibliographyDataType::CUSTOM2 },
2934 { XML_CUSTOM3, BibliographyDataType::CUSTOM3 },
2935 { XML_CUSTOM4, BibliographyDataType::CUSTOM4 },
2936 { XML_CUSTOM5, BibliographyDataType::CUSTOM5 },
2937 { XML_EMAIL, BibliographyDataType::EMAIL },
2938 { XML_INBOOK, BibliographyDataType::INBOOK },
2939 { XML_INCOLLECTION, BibliographyDataType::INCOLLECTION },
2940 { XML_INPROCEEDINGS, BibliographyDataType::INPROCEEDINGS },
2941 { XML_JOURNAL, BibliographyDataType::JOURNAL },
2942 { XML_MANUAL, BibliographyDataType::MANUAL },
2943 { XML_MASTERSTHESIS, BibliographyDataType::MASTERSTHESIS },
2944 { XML_MISC, BibliographyDataType::MISC },
2945 { XML_PHDTHESIS, BibliographyDataType::PHDTHESIS },
2946 { XML_PROCEEDINGS, BibliographyDataType::PROCEEDINGS },
2947 { XML_TECHREPORT, BibliographyDataType::TECHREPORT },
2948 { XML_UNPUBLISHED, BibliographyDataType::UNPUBLISHED },
2949 { XML_WWW, BibliographyDataType::WWW },
2950 { XML_TOKEN_INVALID, 0 }
2954 // we'll process attributes on our own and for fit the standard
2955 // textfield mechanism, because our attributes have zero overlap with
2956 // all the other textfields.
2957 void XMLBibliographyFieldImportContext::startFastElement(
2958 sal_Int32 /*nElement*/,
2959 const Reference<XFastAttributeList> & xAttrList)
2961 // iterate over attributes
2962 for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) )
2964 if (IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_TEXT)
2965 || IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_LO_EXT))
2967 auto nToken = aIter.getToken() & TOKEN_MASK;
2968 PropertyValue aValue;
2969 aValue.Name = MapBibliographyFieldName(nToken);
2971 // special treatment for bibliography type
2972 // biblio vs bibilio: #96658#; also read old documents
2973 if (nToken == XML_BIBILIOGRAPHIC_TYPE ||
2974 nToken == XML_BIBLIOGRAPHY_TYPE )
2976 sal_uInt16 nTmp;
2977 if (SvXMLUnitConverter::convertEnum(
2978 nTmp, aIter.toView(),
2979 aBibliographyDataTypeMap))
2981 aValue.Value <<= static_cast<sal_Int16>(nTmp);
2983 aValues.push_back(aValue);
2986 else
2988 OUString aStringValue = aIter.toString();
2989 if (nToken == XML_URL || nToken == XML_LOCAL_URL || nToken == XML_TARGET_URL)
2991 aStringValue = GetImport().GetAbsoluteReference(aStringValue);
2993 aValue.Value <<= aStringValue;
2995 aValues.push_back(aValue);
2998 // else: unknown namespace -> ignore
3002 void XMLBibliographyFieldImportContext::ProcessAttribute(
3003 sal_Int32 ,
3004 std::string_view )
3006 // attributes are handled in StartElement
3007 assert(false && "This should not have happened.");
3011 void XMLBibliographyFieldImportContext::PrepareField(
3012 const Reference<XPropertySet> & xPropertySet)
3014 // convert vector into sequence
3015 sal_Int32 nCount = aValues.size();
3016 Sequence<PropertyValue> aValueSequence(nCount);
3017 auto aValueSequenceRange = asNonConstRange(aValueSequence);
3018 for(sal_Int32 i = 0; i < nCount; i++)
3020 aValueSequenceRange[i] = aValues[i];
3023 // set sequence
3024 xPropertySet->setPropertyValue(u"Fields"_ustr, Any(aValueSequence));
3027 OUString XMLBibliographyFieldImportContext::MapBibliographyFieldName(
3028 sal_Int32 nElement)
3030 OUString pName;
3032 switch (nElement & TOKEN_MASK)
3034 case XML_IDENTIFIER:
3035 pName = u"Identifier"_ustr;
3036 break;
3037 case XML_BIBILIOGRAPHIC_TYPE:
3038 case XML_BIBLIOGRAPHY_TYPE:
3039 // biblio... vs bibilio...: #96658#: also read old documents
3040 pName = u"BibiliographicType"_ustr;
3041 break;
3042 case XML_ADDRESS:
3043 pName = u"Address"_ustr;
3044 break;
3045 case XML_ANNOTE:
3046 pName = u"Annote"_ustr;
3047 break;
3048 case XML_AUTHOR:
3049 pName = u"Author"_ustr;
3050 break;
3051 case XML_BOOKTITLE:
3052 pName = u"Booktitle"_ustr;
3053 break;
3054 case XML_CHAPTER:
3055 pName = u"Chapter"_ustr;
3056 break;
3057 case XML_EDITION:
3058 pName = u"Edition"_ustr;
3059 break;
3060 case XML_EDITOR:
3061 pName = u"Editor"_ustr;
3062 break;
3063 case XML_HOWPUBLISHED:
3064 pName = u"Howpublished"_ustr;
3065 break;
3066 case XML_INSTITUTION:
3067 pName = u"Institution"_ustr;
3068 break;
3069 case XML_JOURNAL:
3070 pName = u"Journal"_ustr;
3071 break;
3072 case XML_MONTH:
3073 pName = u"Month"_ustr;
3074 break;
3075 case XML_NOTE:
3076 pName = u"Note"_ustr;
3077 break;
3078 case XML_NUMBER:
3079 pName = u"Number"_ustr;
3080 break;
3081 case XML_ORGANIZATIONS:
3082 pName = u"Organizations"_ustr;
3083 break;
3084 case XML_PAGES:
3085 pName = u"Pages"_ustr;
3086 break;
3087 case XML_PUBLISHER:
3088 pName = u"Publisher"_ustr;
3089 break;
3090 case XML_SCHOOL:
3091 pName = u"School"_ustr;
3092 break;
3093 case XML_SERIES:
3094 pName = u"Series"_ustr;
3095 break;
3096 case XML_TITLE:
3097 pName = u"Title"_ustr;
3098 break;
3099 case XML_REPORT_TYPE:
3100 pName = u"Report_Type"_ustr;
3101 break;
3102 case XML_VOLUME:
3103 pName = u"Volume"_ustr;
3104 break;
3105 case XML_YEAR:
3106 pName = u"Year"_ustr;
3107 break;
3108 case XML_URL:
3109 pName = u"URL"_ustr;
3110 break;
3111 case XML_CUSTOM1:
3112 pName = u"Custom1"_ustr;
3113 break;
3114 case XML_CUSTOM2:
3115 pName = u"Custom2"_ustr;
3116 break;
3117 case XML_CUSTOM3:
3118 pName = u"Custom3"_ustr;
3119 break;
3120 case XML_CUSTOM4:
3121 pName = u"Custom4"_ustr;
3122 break;
3123 case XML_CUSTOM5:
3124 pName = u"Custom5"_ustr;
3125 break;
3126 case XML_ISBN:
3127 pName = u"ISBN"_ustr;
3128 break;
3129 case XML_LOCAL_URL:
3130 pName = u"LocalURL"_ustr;
3131 break;
3132 case XML_TARGET_TYPE:
3133 pName = u"TargetType"_ustr;
3134 break;
3135 case XML_TARGET_URL:
3136 pName = u"TargetURL"_ustr;
3137 break;
3138 default:
3139 assert(false && "Unknown bibliography info data");
3141 return pName;
3144 // Annotation Field
3147 XMLAnnotationImportContext::XMLAnnotationImportContext(
3148 SvXMLImport& rImport,
3149 XMLTextImportHelper& rHlp,
3150 sal_Int32 nElement) :
3151 XMLTextFieldImportContext(rImport, rHlp, u"Annotation"_ustr),
3152 mnElement(nElement)
3154 bValid = true;
3156 // remember old list item and block (#91964#) and reset them
3157 // for the text frame
3158 // do this in the constructor, not in CreateChildContext (#i93392#)
3159 GetImport().GetTextImport()->PushListContext();
3162 void XMLAnnotationImportContext::ProcessAttribute(
3163 sal_Int32 nAttrToken,
3164 std::string_view sAttrValue )
3166 if (nAttrToken == XML_ELEMENT(OFFICE, XML_NAME))
3167 aName = OUString::fromUtf8(sAttrValue);
3168 else if (nAttrToken == XML_ELEMENT(LO_EXT, XML_RESOLVED))
3169 aResolved = OUString::fromUtf8(sAttrValue);
3170 else if (nAttrToken == XML_ELEMENT(LO_EXT, XML_PARENT_NAME))
3171 aParentName = OUString::fromUtf8(sAttrValue);
3172 else
3173 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3176 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLAnnotationImportContext::createFastChildContext(
3177 sal_Int32 nElement,
3178 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList )
3180 if( nElement == XML_ELEMENT(DC, XML_CREATOR) )
3181 return new XMLStringBufferImportContext(GetImport(), aAuthorBuffer);
3182 else if( nElement == XML_ELEMENT(DC, XML_DATE) )
3183 return new XMLStringBufferImportContext(GetImport(), aDateBuffer);
3184 else if (nElement == XML_ELEMENT(TEXT,XML_SENDER_INITIALS) ||
3185 nElement == XML_ELEMENT(LO_EXT, XML_SENDER_INITIALS) ||
3186 nElement == XML_ELEMENT(META, XML_CREATOR_INITIALS))
3187 return new XMLStringBufferImportContext(GetImport(), aInitialsBuffer);
3191 bool bOK = true;
3192 if ( !mxField.is() )
3193 bOK = CreateField( mxField, sServicePrefix + GetServiceName() );
3194 if (bOK)
3196 Any aAny = mxField->getPropertyValue( u"TextRange"_ustr );
3197 Reference< XText > xText;
3198 aAny >>= xText;
3199 if( xText.is() )
3201 rtl::Reference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport();
3202 if( !mxCursor.is() )
3204 mxOldCursor = xTxtImport->GetCursor();
3205 mxCursor = xText->createTextCursor();
3208 if( mxCursor.is() )
3210 xTxtImport->SetCursor( mxCursor );
3211 return xTxtImport->CreateTextChildContext( GetImport(), nElement, xAttrList );
3216 catch (const Exception&)
3220 return new XMLStringBufferImportContext(GetImport(), aTextBuffer);
3223 void XMLAnnotationImportContext::endFastElement(sal_Int32 /*nElement*/)
3225 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
3226 if( mxCursor.is() )
3228 // delete addition newline
3229 mxCursor->gotoEnd( false );
3230 mxCursor->goLeft( 1, true );
3231 mxCursor->setString( u""_ustr );
3233 // reset cursor
3234 GetImport().GetTextImport()->ResetCursor();
3237 if( mxOldCursor.is() )
3238 GetImport().GetTextImport()->SetCursor( mxOldCursor );
3240 // reinstall old list item #91964#
3241 GetImport().GetTextImport()->PopListContext();
3243 if (!bValid)
3245 GetImportHelper().InsertString(GetContent());
3246 return;
3249 if ( mnElement == XML_ELEMENT(OFFICE, XML_ANNOTATION_END) )
3251 // Search for a previous annotation with the same name.
3252 uno::Reference< text::XTextContent > xPrevField;
3254 Reference<XTextFieldsSupplier> xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY);
3255 if (!xTextFieldsSupplier)
3256 return;
3257 uno::Reference<container::XUniqueIDAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields(), UNO_QUERY_THROW);
3258 uno::Any aAny = xFieldsAccess->getByUniqueID(aName);
3259 aAny >>= xPrevField;
3261 if ( xPrevField.is() )
3263 // So we are ending a previous annotation,
3264 // let's create a text range covering the old and the current position.
3265 uno::Reference<text::XText> xText = GetImportHelper().GetText();
3266 uno::Reference<text::XTextCursor> xCursor =
3267 xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange());
3270 xCursor->gotoRange(xPrevField->getAnchor(), true);
3272 catch (const uno::RuntimeException&)
3274 // Losing the start of the anchor is better than not opening the document at
3275 // all.
3276 TOOLS_WARN_EXCEPTION(
3277 "xmloff.text",
3278 "XMLAnnotationImportContext::endFastElement: gotoRange() failed: ");
3281 xText->insertTextContent(xCursor, xPrevField, !xCursor->isCollapsed());
3283 return;
3286 if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) )
3288 // set field properties
3289 PrepareField( mxField );
3291 // attach field to document
3292 Reference < XTextContent > xTextContent( mxField, UNO_QUERY );
3294 // workaround for #80606#
3297 GetImportHelper().InsertTextContent( xTextContent );
3299 catch (const lang::IllegalArgumentException&)
3301 // ignore
3306 void XMLAnnotationImportContext::PrepareField(
3307 const Reference<XPropertySet> & xPropertySet )
3309 // import (possibly empty) author
3310 OUString sAuthor( aAuthorBuffer.makeStringAndClear() );
3311 xPropertySet->setPropertyValue(sAPI_author, Any(sAuthor));
3313 // import (possibly empty) initials
3314 OUString sInitials( aInitialsBuffer.makeStringAndClear() );
3315 xPropertySet->setPropertyValue(u"Initials"_ustr, Any(sInitials));
3317 //import resolved flag
3318 bool bTmp(false);
3319 (void)::sax::Converter::convertBool(bTmp, aResolved);
3320 xPropertySet->setPropertyValue(u"Resolved"_ustr, Any(bTmp));
3322 util::DateTime aDateTime;
3323 if (::sax::Converter::parseDateTime(aDateTime, aDateBuffer))
3326 Date aDate;
3327 aDate.Year = aDateTime.Year;
3328 aDate.Month = aDateTime.Month;
3329 aDate.Day = aDateTime.Day;
3330 xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDate));
3332 // why is there no UNO_NAME_DATE_TIME, but only UNO_NAME_DATE_TIME_VALUE?
3333 xPropertySet->setPropertyValue(sAPI_date_time_value, Any(aDateTime));
3335 aDateBuffer.setLength(0);
3337 if ( aTextBuffer.getLength() )
3339 // delete last paragraph mark (if necessary)
3340 if (char(0x0a) == aTextBuffer[aTextBuffer.getLength()-1])
3341 aTextBuffer.setLength(aTextBuffer.getLength()-1);
3342 xPropertySet->setPropertyValue(sAPI_content, Any(aTextBuffer.makeStringAndClear()));
3345 if (!aName.isEmpty())
3346 xPropertySet->setPropertyValue(sAPI_name, Any(aName));
3348 if (!aParentName.isEmpty())
3349 xPropertySet->setPropertyValue(sAPI_parent_name, Any(aParentName));
3353 // script field
3356 XMLScriptImportContext::XMLScriptImportContext(
3357 SvXMLImport& rImport,
3358 XMLTextImportHelper& rHlp)
3359 : XMLTextFieldImportContext(rImport, rHlp, u"Script"_ustr)
3360 , bContentOK(false)
3364 void XMLScriptImportContext::ProcessAttribute(
3365 sal_Int32 nAttrToken,
3366 std::string_view sAttrValue )
3368 switch (nAttrToken)
3370 case XML_ELEMENT(XLINK, XML_HREF):
3371 sContent = GetImport().GetAbsoluteReference( OUString::fromUtf8(sAttrValue) );
3372 bContentOK = true;
3373 break;
3375 case XML_ELEMENT(SCRIPT, XML_LANGUAGE):
3376 sScriptType = OUString::fromUtf8(sAttrValue);
3377 break;
3379 default:
3380 // ignore
3381 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3382 break;
3385 // always valid (even without ScriptType; cf- #96531#)
3386 bValid = true;
3389 void XMLScriptImportContext::PrepareField(
3390 const Reference<XPropertySet> & xPropertySet)
3392 // if href attribute was present, we use it. Else we use element content
3393 if (! bContentOK)
3395 sContent = GetContent();
3397 xPropertySet->setPropertyValue(sAPI_content, Any(sContent));
3399 // URL or script text? We use URL if we have an href-attribute
3400 xPropertySet->setPropertyValue(u"URLContent"_ustr, Any(bContentOK));
3402 xPropertySet->setPropertyValue(u"ScriptType"_ustr, Any(sScriptType));
3406 // measure field
3409 XMLMeasureFieldImportContext::XMLMeasureFieldImportContext(
3410 SvXMLImport& rImport,
3411 XMLTextImportHelper& rHlp) :
3412 XMLTextFieldImportContext(rImport, rHlp, u"Measure"_ustr),
3413 mnKind( 0 )
3417 void XMLMeasureFieldImportContext::ProcessAttribute(
3418 sal_Int32 nAttrToken,
3419 std::string_view sAttrValue )
3421 switch (nAttrToken)
3423 case XML_ELEMENT(TEXT, XML_KIND):
3424 if( IsXMLToken( sAttrValue, XML_VALUE ) )
3426 mnKind = 0; bValid = true;
3428 else if( IsXMLToken( sAttrValue, XML_UNIT ) )
3430 mnKind = 1; bValid = true;
3432 else if( IsXMLToken( sAttrValue, XML_GAP ) )
3434 mnKind = 2; bValid = true;
3436 break;
3437 default:
3438 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3442 void XMLMeasureFieldImportContext::PrepareField(
3443 const Reference<XPropertySet> & xPropertySet)
3445 xPropertySet->setPropertyValue(u"Kind"_ustr, Any(mnKind));
3449 // dropdown field
3452 XMLDropDownFieldImportContext::XMLDropDownFieldImportContext(
3453 SvXMLImport& rImport,
3454 XMLTextImportHelper& rHlp) :
3455 XMLTextFieldImportContext( rImport, rHlp, u"DropDown"_ustr ),
3456 nSelected( -1 ),
3457 bNameOK( false ),
3458 bHelpOK(false),
3459 bHintOK(false)
3461 bValid = true;
3464 static bool lcl_ProcessLabel(
3465 const Reference<XFastAttributeList>& xAttrList,
3466 OUString& rLabel,
3467 bool& rIsSelected )
3469 bool bValid = false;
3470 for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) )
3472 switch (aIter.getToken())
3474 case XML_ELEMENT(TEXT, XML_VALUE):
3476 rLabel = aIter.toString();
3477 bValid = true;
3478 break;
3480 case XML_ELEMENT(TEXT, XML_CURRENT_SELECTED):
3482 bool bTmp(false);
3483 if (::sax::Converter::convertBool( bTmp, aIter.toView() ))
3484 rIsSelected = bTmp;
3485 break;
3487 default:
3488 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
3491 return bValid;
3494 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLDropDownFieldImportContext::createFastChildContext(
3495 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
3497 if( nElement == XML_ELEMENT(TEXT, XML_LABEL) )
3499 OUString sLabel;
3500 bool bIsSelected = false;
3501 if( lcl_ProcessLabel( xAttrList, sLabel, bIsSelected ) )
3503 if( bIsSelected )
3504 nSelected = static_cast<sal_Int32>( aLabels.size() );
3505 aLabels.push_back( sLabel );
3508 return new SvXMLImportContext( GetImport() );
3511 void XMLDropDownFieldImportContext::ProcessAttribute(
3512 sal_Int32 nAttrToken,
3513 std::string_view sAttrValue )
3515 if( nAttrToken == XML_ELEMENT(TEXT, XML_NAME))
3517 sName = OUString::fromUtf8(sAttrValue);
3518 bNameOK = true;
3520 else if (nAttrToken == XML_ELEMENT(TEXT, XML_HELP))
3522 sHelp = OUString::fromUtf8(sAttrValue);
3523 bHelpOK = true;
3525 else if (nAttrToken == XML_ELEMENT(TEXT, XML_HINT))
3527 sHint = OUString::fromUtf8(sAttrValue);
3528 bHintOK = true;
3530 else
3531 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3534 void XMLDropDownFieldImportContext::PrepareField(
3535 const Reference<XPropertySet>& xPropertySet)
3537 // create sequence
3538 sal_Int32 nLength = static_cast<sal_Int32>( aLabels.size() );
3539 Sequence<OUString> aSequence( nLength );
3540 OUString* pSequence = aSequence.getArray();
3541 for( sal_Int32 n = 0; n < nLength; n++ )
3542 pSequence[n] = aLabels[n];
3544 // now set values:
3546 xPropertySet->setPropertyValue( u"Items"_ustr, Any(aSequence) );
3548 if( nSelected >= 0 && nSelected < nLength )
3550 xPropertySet->setPropertyValue( u"SelectedItem"_ustr, Any(pSequence[nSelected]) );
3553 // set name
3554 if( bNameOK )
3556 xPropertySet->setPropertyValue( u"Name"_ustr, Any(sName) );
3558 // set help
3559 if( bHelpOK )
3561 xPropertySet->setPropertyValue( u"Help"_ustr, Any(sHelp) );
3563 // set hint
3564 if( bHintOK )
3566 xPropertySet->setPropertyValue( u"Tooltip"_ustr, Any(sHint) );
3571 /** import header fields (<draw:header>) */
3573 XMLHeaderFieldImportContext::XMLHeaderFieldImportContext(
3574 SvXMLImport& rImport, /// XML Import
3575 XMLTextImportHelper& rHlp) /// Text import helper
3576 : XMLTextFieldImportContext(rImport, rHlp, u"Header"_ustr )
3578 sServicePrefix = sAPI_presentation_prefix;
3579 bValid = true;
3582 /// process attribute values
3583 void XMLHeaderFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken, std::string_view sAttrValue )
3585 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3588 /// prepare XTextField for insertion into document
3589 void XMLHeaderFieldImportContext::PrepareField(const Reference<XPropertySet> &)
3593 /** import footer fields (<draw:footer>) */
3595 XMLFooterFieldImportContext::XMLFooterFieldImportContext(
3596 SvXMLImport& rImport, /// XML Import
3597 XMLTextImportHelper& rHlp) /// Text import helper
3598 : XMLTextFieldImportContext(rImport, rHlp, u"Footer"_ustr )
3600 sServicePrefix = sAPI_presentation_prefix;
3601 bValid = true;
3604 /// process attribute values
3605 void XMLFooterFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken, std::string_view sAttrValue)
3607 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3610 /// prepare XTextField for insertion into document
3611 void XMLFooterFieldImportContext::PrepareField(const Reference<XPropertySet> &)
3616 /** import footer fields (<draw:date-and-time>) */
3618 XMLDateTimeFieldImportContext::XMLDateTimeFieldImportContext(
3619 SvXMLImport& rImport, /// XML Import
3620 XMLTextImportHelper& rHlp) /// Text import helper
3621 : XMLTextFieldImportContext(rImport, rHlp, u"DateTime"_ustr )
3623 sServicePrefix = sAPI_presentation_prefix;
3624 bValid = true;
3627 /// process attribute values
3628 void XMLDateTimeFieldImportContext::ProcessAttribute( sal_Int32 nAttrToken,
3629 std::string_view sAttrValue )
3631 XMLOFF_WARN_UNKNOWN_ATTR("xmloff", nAttrToken, sAttrValue);
3634 /// prepare XTextField for insertion into document
3635 void XMLDateTimeFieldImportContext::PrepareField(
3636 const css::uno::Reference<
3637 css::beans::XPropertySet> &)
3641 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */