Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / text / txtflde.cxx
blob2c054d57e3f66142f75b585760415f71b3b7f7f0
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 * export of all text fields
25 #include <comphelper/propertyvalue.hxx>
26 #include <txtflde.hxx>
27 #include <xmloff/XMLEventExport.hxx>
28 #include <xmloff/families.hxx>
29 #include <xmloff/namespacemap.hxx>
30 #include <xmloff/numehelp.hxx>
31 #include <xmloff/xmlement.hxx>
32 #include <xmloff/xmlexp.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include <xmloff/maptype.hxx>
37 #include "XMLTextCharStyleNamesElementExport.hxx"
38 #include <sax/tools/converter.hxx>
39 #include <com/sun/star/frame/XModel.hpp>
40 #include <com/sun/star/util/DateTime.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/text/UserDataPart.hpp>
43 #include <com/sun/star/text/PageNumberType.hpp>
44 #include <com/sun/star/style/NumberingType.hpp>
45 #include <com/sun/star/text/ReferenceFieldPart.hpp>
46 #include <com/sun/star/text/ReferenceFieldSource.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/beans/XPropertyState.hpp>
49 #include <com/sun/star/text/XTextField.hpp>
50 #include <com/sun/star/text/XDependentTextField.hpp>
51 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
53 #include <com/sun/star/text/SetVariableType.hpp>
54 #include <com/sun/star/text/PlaceholderType.hpp>
55 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
56 #include <com/sun/star/text/ChapterFormat.hpp>
57 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
58 #include <com/sun/star/container/XNameReplace.hpp>
59 #include <com/sun/star/uno/Sequence.h>
60 #include <com/sun/star/text/BibliographyDataType.hpp>
61 #include <com/sun/star/sdb/CommandType.hpp>
62 #include <com/sun/star/rdf/XMetadatable.hpp>
63 #include <comphelper/sequence.hxx>
64 #include <o3tl/any.hxx>
65 #include <o3tl/safeint.hxx>
66 #include <rtl/ustrbuf.hxx>
67 #include <tools/debug.hxx>
68 #include <rtl/math.hxx>
69 #include <sal/log.hxx>
71 #include <vector>
74 using namespace ::com::sun::star;
75 using namespace ::com::sun::star::uno;
76 using namespace ::com::sun::star::text;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::beans;
79 using namespace ::com::sun::star::util;
80 using namespace ::com::sun::star::style;
81 using namespace ::com::sun::star::document;
82 using namespace ::com::sun::star::container;
83 using namespace ::xmloff::token;
86 char const FIELD_SERVICE_SENDER[] = "ExtendedUser";
87 char const FIELD_SERVICE_AUTHOR[] = "Author";
88 char const FIELD_SERVICE_JUMPEDIT[] = "JumpEdit";
89 char const FIELD_SERVICE_GETEXP[] = "GetExpression";
90 char const FIELD_SERVICE_SETEXP[] = "SetExpression";
91 char const FIELD_SERVICE_USER[] = "User";
92 char const FIELD_SERVICE_INPUT[] = "Input";
93 char const FIELD_SERVICE_USERINPUT[] = "InputUser";
94 char const FIELD_SERVICE_DATETIME[] = "DateTime";
95 char const FIELD_SERVICE_PAGENUMBER[] = "PageNumber";
96 char const FIELD_SERVICE_DB_NEXT[] = "DatabaseNextSet";
97 char const FIELD_SERVICE_DB_SELECT[] = "DatabaseNumberOfSet";
98 char const FIELD_SERVICE_DB_NUMBER[] = "DatabaseSetNumber";
99 char const FIELD_SERVICE_DB_DISPLAY[] = "Database";
100 char const FIELD_SERVICE_DB_NAME[] = "DatabaseName";
101 char const FIELD_SERVICE_CONDITIONAL_TEXT[] = "ConditionalText";
102 char const FIELD_SERVICE_HIDDEN_TEXT[] = "HiddenText";
103 char const FIELD_SERVICE_HIDDEN_PARAGRAPH[] = "HiddenParagraph";
104 char const FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR[] = "DocInfo.ChangeAuthor";
105 char const FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR2[] = "docinfo.ChangeAuthor";
106 char const FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME[] = "DocInfo.ChangeDateTime";
107 char const FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME2[] = "docinfo.ChangeDateTime";
108 char const FIELD_SERVICE_DOC_INFO_EDIT_TIME[] = "DocInfo.EditTime";
109 char const FIELD_SERVICE_DOC_INFO_EDIT_TIME2[] = "docinfo.EditTime";
110 char const FIELD_SERVICE_DOC_INFO_DESCRIPTION[] = "DocInfo.Description";
111 char const FIELD_SERVICE_DOC_INFO_DESCRIPTION2[] = "docinfo.Description";
112 char const FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR[] = "DocInfo.CreateAuthor";
113 char const FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR2[] = "docinfo.CreateAuthor";
114 char const FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME[] = "DocInfo.CreateDateTime";
115 char const FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME2[] = "docinfo.CreateDateTime";
116 char const FIELD_SERVICE_DOC_INFO_CUSTOM[] = "DocInfo.Custom";
117 char const FIELD_SERVICE_DOC_INFO_CUSTOM2[] = "docinfo.Custom";
118 char const FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR[] = "DocInfo.PrintAuthor";
119 char const FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR2[] = "docinfo.PrintAuthor";
120 char const FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME[] = "DocInfo.PrintDateTime";
121 char const FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME2[] = "docinfo.PrintDateTime";
122 char const FIELD_SERVICE_DOC_INFO_KEY_WORDS[] = "DocInfo.KeyWords";
123 char const FIELD_SERVICE_DOC_INFO_KEY_WORDS2[] = "docinfo.KeyWords";
124 char const FIELD_SERVICE_DOC_INFO_SUBJECT[] = "DocInfo.Subject";
125 char const FIELD_SERVICE_DOC_INFO_SUBJECT2[] = "docinfo.Subject";
126 char const FIELD_SERVICE_DOC_INFO_TITLE[] = "DocInfo.Title";
127 char const FIELD_SERVICE_DOC_INFO_TITLE2[] = "docinfo.Title";
128 char const FIELD_SERVICE_DOC_INFO_REVISION[] = "DocInfo.Revision";
129 char const FIELD_SERVICE_DOC_INFO_REVISION2[] = "docinfo.Revision";
130 char const FIELD_SERVICE_FILE_NAME[] = "FileName";
131 char const FIELD_SERVICE_CHAPTER[] = "Chapter";
132 char const FIELD_SERVICE_TEMPLATE_NAME[] = "TemplateName";
133 char const FIELD_SERVICE_PAGE_COUNT[] = "PageCount";
134 char const FIELD_SERVICE_PARAGRAPH_COUNT[] = "ParagraphCount";
135 char const FIELD_SERVICE_WORD_COUNT[] = "WordCount";
136 char const FIELD_SERVICE_CHARACTER_COUNT[] = "CharacterCount";
137 char const FIELD_SERVICE_TABLE_COUNT[] = "TableCount";
138 char const FIELD_SERVICE_GRAPHIC_COUNT[] = "GraphicObjectCount";
139 char const FIELD_SERVICE_OBJECT_COUNT[] = "EmbeddedObjectCount";
140 char const FIELD_SERVICE_REFERENCE_PAGE_SET[] = "ReferencePageSet";
141 char const FIELD_SERVICE_REFERENCE_PAGE_GET[] = "ReferencePageGet";
142 char const FIELD_SERVICE_SHEET_NAME[] = "SheetName";
143 char const FIELD_SERVICE_PAGE_NAME[] = "PageName";
144 char const FIELD_SERVICE_MACRO[] = "Macro";
145 char const FIELD_SERVICE_GET_REFERENCE[] = "GetReference";
146 char const FIELD_SERVICE_DDE[] = "DDE";
147 char const FIELD_SERVICE_URL[] = "URL";
148 char const FIELD_SERVICE_BIBLIOGRAPHY[] = "Bibliography";
149 char const FIELD_SERVICE_SCRIPT[] = "Script";
150 char const FIELD_SERVICE_ANNOTATION[] = "Annotation";
151 char const FIELD_SERVICE_COMBINED_CHARACTERS[] = "CombinedCharacters";
152 char const FIELD_SERVICE_META[] = "MetadataField";
153 char const FIELD_SERVICE_MEASURE[] = "Measure";
154 char const FIELD_SERVICE_TABLE_FORMULA[] = "TableFormula";
155 char const FIELD_SERVICE_DROP_DOWN[] = "DropDown";
157 namespace
159 /// Walks up the parent chain of xText and returns the topmost text.
160 uno::Reference<text::XText> GetToplevelText(const uno::Reference<text::XText>& xText)
162 uno::Reference<text::XText> xRet = xText;
163 while (true)
165 uno::Reference<beans::XPropertySet> xPropertySet(xRet, uno::UNO_QUERY);
166 if (!xPropertySet.is())
167 return xRet;
169 if (!xPropertySet->getPropertySetInfo()->hasPropertyByName("ParentText"))
170 return xRet;
172 uno::Reference<text::XText> xParent;
173 if (xPropertySet->getPropertyValue("ParentText") >>= xParent)
174 xRet = xParent;
175 else
176 return xRet;
178 return xRet;
182 SvXMLEnumStringMapEntry<FieldIdEnum> const aFieldServiceNameMapping[] =
184 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SENDER, FIELD_ID_SENDER ),
185 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_AUTHOR, FIELD_ID_AUTHOR ),
186 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_JUMPEDIT, FIELD_ID_PLACEHOLDER ),
187 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GETEXP, FIELD_ID_VARIABLE_GET ),
188 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SETEXP, FIELD_ID_VARIABLE_SET ),
189 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_USER, FIELD_ID_USER_GET ),
190 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_INPUT, FIELD_ID_TEXT_INPUT ),
191 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_USERINPUT, FIELD_ID_USER_INPUT ),
192 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DATETIME, FIELD_ID_TIME ),
193 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PAGENUMBER, FIELD_ID_PAGENUMBER ),
194 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_REFERENCE_PAGE_SET, FIELD_ID_REFPAGE_SET ),
195 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_REFERENCE_PAGE_GET, FIELD_ID_REFPAGE_GET ),
197 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NEXT, FIELD_ID_DATABASE_NEXT ),
198 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_SELECT, FIELD_ID_DATABASE_SELECT ),
199 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NUMBER, FIELD_ID_DATABASE_NUMBER ),
200 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_DISPLAY, FIELD_ID_DATABASE_DISPLAY ),
201 // workaround for #no-bug#: Database/DataBase
202 ENUM_STRING_MAP_ENTRY( "DataBase", FIELD_ID_DATABASE_DISPLAY ),
203 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NAME, FIELD_ID_DATABASE_NAME ),
205 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR, FIELD_ID_DOCINFO_CREATION_AUTHOR ),
206 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR2, FIELD_ID_DOCINFO_CREATION_AUTHOR ),
207 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME, FIELD_ID_DOCINFO_CREATION_TIME),
208 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME2, FIELD_ID_DOCINFO_CREATION_TIME),
209 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR, FIELD_ID_DOCINFO_SAVE_AUTHOR ),
210 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR2, FIELD_ID_DOCINFO_SAVE_AUTHOR ),
211 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME, FIELD_ID_DOCINFO_SAVE_TIME ),
212 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME2, FIELD_ID_DOCINFO_SAVE_TIME ),
213 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_EDIT_TIME, FIELD_ID_DOCINFO_EDIT_DURATION ),
214 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_EDIT_TIME2, FIELD_ID_DOCINFO_EDIT_DURATION ),
215 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_DESCRIPTION, FIELD_ID_DOCINFO_DESCRIPTION ),
216 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_DESCRIPTION2, FIELD_ID_DOCINFO_DESCRIPTION ),
217 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CUSTOM, FIELD_ID_DOCINFO_CUSTOM ),
218 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CUSTOM2, FIELD_ID_DOCINFO_CUSTOM ),
219 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR, FIELD_ID_DOCINFO_PRINT_AUTHOR ),
220 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR2, FIELD_ID_DOCINFO_PRINT_AUTHOR ),
221 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME, FIELD_ID_DOCINFO_PRINT_TIME ),
222 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME2, FIELD_ID_DOCINFO_PRINT_TIME ),
223 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_KEY_WORDS, FIELD_ID_DOCINFO_KEYWORDS ),
224 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_KEY_WORDS2, FIELD_ID_DOCINFO_KEYWORDS ),
225 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_SUBJECT, FIELD_ID_DOCINFO_SUBJECT ),
226 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_SUBJECT2, FIELD_ID_DOCINFO_SUBJECT ),
227 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_TITLE, FIELD_ID_DOCINFO_TITLE ),
228 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_TITLE2, FIELD_ID_DOCINFO_TITLE ),
229 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_REVISION, FIELD_ID_DOCINFO_REVISION ),
230 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_REVISION2, FIELD_ID_DOCINFO_REVISION ),
232 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CONDITIONAL_TEXT, FIELD_ID_CONDITIONAL_TEXT ),
233 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_HIDDEN_TEXT, FIELD_ID_HIDDEN_TEXT ),
234 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_HIDDEN_PARAGRAPH, FIELD_ID_HIDDEN_PARAGRAPH ),
236 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_FILE_NAME, FIELD_ID_FILE_NAME ),
237 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CHAPTER, FIELD_ID_CHAPTER ),
238 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TEMPLATE_NAME, FIELD_ID_TEMPLATE_NAME ),
240 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PAGE_COUNT, FIELD_ID_COUNT_PAGES ),
241 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PARAGRAPH_COUNT, FIELD_ID_COUNT_PARAGRAPHS ),
242 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_WORD_COUNT, FIELD_ID_COUNT_WORDS ),
243 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CHARACTER_COUNT, FIELD_ID_COUNT_CHARACTERS ),
244 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TABLE_COUNT, FIELD_ID_COUNT_TABLES ),
245 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GRAPHIC_COUNT, FIELD_ID_COUNT_GRAPHICS ),
246 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_OBJECT_COUNT, FIELD_ID_COUNT_OBJECTS ),
248 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_MACRO, FIELD_ID_MACRO ),
249 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GET_REFERENCE, FIELD_ID_REF_REFERENCE ),
250 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DDE, FIELD_ID_DDE ),
252 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_BIBLIOGRAPHY, FIELD_ID_BIBLIOGRAPHY ),
254 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SCRIPT, FIELD_ID_SCRIPT ),
255 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_ANNOTATION, FIELD_ID_ANNOTATION ),
257 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_COMBINED_CHARACTERS, FIELD_ID_COMBINED_CHARACTERS ),
258 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_META, FIELD_ID_META ),
260 // non-writer fields
261 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SHEET_NAME, FIELD_ID_SHEET_NAME ),
262 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PAGE_NAME, FIELD_ID_PAGENAME ),
263 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_URL, FIELD_ID_URL ),
264 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_MEASURE, FIELD_ID_MEASURE ),
266 // deprecated fields
267 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TABLE_FORMULA, FIELD_ID_TABLE_FORMULA ),
268 ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DROP_DOWN, FIELD_ID_DROP_DOWN ),
270 { nullptr, 0, FieldIdEnum(0) }
274 // property accessor helper functions
275 static bool GetBoolProperty(const OUString&,
276 const Reference<XPropertySet> &);
277 static bool GetOptionalBoolProperty(const OUString&,
278 const Reference<XPropertySet> &,
279 const Reference<XPropertySetInfo> &,
280 bool bDefault);
281 static double GetDoubleProperty(const OUString&,
282 const Reference<XPropertySet> &);
283 static OUString GetStringProperty(const OUString&,
284 const Reference<XPropertySet> &);
285 static sal_Int32 GetIntProperty(const OUString&,
286 const Reference<XPropertySet> &);
287 static sal_Int16 GetInt16Property(const OUString&,
288 const Reference<XPropertySet> &);
289 static sal_Int8 GetInt8Property(const OUString&,
290 const Reference<XPropertySet> &);
291 static util::DateTime GetDateTimeProperty( const OUString& sPropName,
292 const Reference<XPropertySet> & xPropSet);
293 static Sequence<OUString> GetStringSequenceProperty(
294 const OUString& sPropName,
295 const Reference<XPropertySet> & xPropSet);
298 // service names
299 constexpr OUString gsServicePrefix(u"com.sun.star.text.textfield."_ustr);
300 constexpr OUStringLiteral gsFieldMasterPrefix(u"com.sun.star.text.FieldMaster.");
301 constexpr OUString gsPresentationServicePrefix(u"com.sun.star.presentation.TextField."_ustr);
303 // property names
304 constexpr OUString gsPropertyAdjust(u"Adjust"_ustr);
305 constexpr OUStringLiteral gsPropertyAuthor(u"Author");
306 constexpr OUStringLiteral gsPropertyChapterFormat(u"ChapterFormat");
307 constexpr OUStringLiteral gsPropertyChapterNumberingLevel(u"ChapterNumberingLevel");
308 constexpr OUStringLiteral gsPropertyCharStyleNames(u"CharStyleNames");
309 constexpr OUString gsPropertyCondition(u"Condition"_ustr);
310 constexpr OUString gsPropertyContent(u"Content"_ustr);
311 constexpr OUStringLiteral gsPropertyDataBaseName(u"DataBaseName");
312 constexpr OUString gsPropertyDataBaseURL(u"DataBaseURL"_ustr);
313 constexpr OUStringLiteral gsPropertyDataColumnName(u"DataColumnName");
314 constexpr OUString gsPropertyDataCommandType(u"DataCommandType"_ustr);
315 constexpr OUString gsPropertyDataTableName(u"DataTableName"_ustr);
316 constexpr OUString gsPropertyDateTime(u"DateTime"_ustr);
317 constexpr OUString gsPropertyDateTimeValue(u"DateTimeValue"_ustr);
318 constexpr OUStringLiteral gsPropertyDDECommandElement(u"DDECommandElement");
319 constexpr OUStringLiteral gsPropertyDDECommandFile(u"DDECommandFile");
320 constexpr OUStringLiteral gsPropertyDDECommandType(u"DDECommandType");
321 constexpr OUStringLiteral gsPropertyDependentTextFields(u"DependentTextFields");
322 constexpr OUStringLiteral gsPropertyFalseContent(u"FalseContent");
323 constexpr OUStringLiteral gsPropertyFields(u"Fields");
324 constexpr OUStringLiteral gsPropertyFieldSubType(u"UserDataType");
325 constexpr OUString gsPropertyFileFormat(u"FileFormat"_ustr);
326 constexpr OUStringLiteral gsPropertyFullName(u"FullName");
327 constexpr OUString gsPropertyHint(u"Hint"_ustr);
328 constexpr OUStringLiteral gsPropertyInitials(u"Initials");
329 constexpr OUStringLiteral gsPropertyInstanceName(u"InstanceName");
330 constexpr OUStringLiteral gsPropertyIsAutomaticUpdate(u"IsAutomaticUpdate");
331 constexpr OUStringLiteral gsPropertyIsConditionTrue(u"IsConditionTrue");
332 constexpr OUString gsPropertyIsDataBaseFormat(u"DataBaseFormat"_ustr);
333 constexpr OUString gsPropertyIsDate(u"IsDate"_ustr);
334 constexpr OUString gsPropertyIsExpression(u"IsExpression"_ustr);
335 constexpr OUString gsPropertyIsFixed(u"IsFixed"_ustr);
336 constexpr OUString gsPropertyIsFixedLanguage(u"IsFixedLanguage"_ustr);
337 constexpr OUString gsPropertyIsHidden(u"IsHidden"_ustr);
338 constexpr OUStringLiteral gsPropertyIsInput(u"Input");
339 constexpr OUString gsPropertyIsShowFormula(u"IsShowFormula"_ustr);
340 constexpr OUString gsPropertyIsVisible(u"IsVisible"_ustr);
341 constexpr OUStringLiteral gsPropertyItems(u"Items");
342 constexpr OUStringLiteral gsPropertyLevel(u"Level");
343 constexpr OUStringLiteral gsPropertyMeasureKind(u"Kind");
344 constexpr OUString gsPropertyName(u"Name"_ustr);
345 constexpr OUStringLiteral gsPropertyParentName(u"ParentName");
346 constexpr OUString gsPropertyNumberFormat(u"NumberFormat"_ustr);
347 constexpr OUStringLiteral gsPropertyNumberingSeparator(u"NumberingSeparator");
348 constexpr OUString gsPropertyNumberingType(u"NumberingType"_ustr);
349 constexpr OUString gsPropertyOffset(u"Offset"_ustr);
350 constexpr OUStringLiteral gsPropertyOn(u"On");
351 constexpr OUStringLiteral gsPropertyPlaceholderType(u"PlaceHolderType");
352 constexpr OUString gsPropertyReferenceFieldFlags(u"ReferenceFieldFlags"_ustr);
353 constexpr OUString gsPropertyReferenceFieldPart(u"ReferenceFieldPart"_ustr);
354 constexpr OUString gsPropertyReferenceFieldSource(u"ReferenceFieldSource"_ustr);
355 constexpr OUString gsPropertyReferenceFieldLanguage(u"ReferenceFieldLanguage"_ustr);
356 constexpr OUStringLiteral gsPropertyScriptType(u"ScriptType");
357 constexpr OUStringLiteral gsPropertySelectedItem(u"SelectedItem");
358 constexpr OUString gsPropertySequenceNumber(u"SequenceNumber"_ustr);
359 constexpr OUStringLiteral gsPropertySequenceValue(u"SequenceValue");
360 constexpr OUString gsPropertySetNumber(u"SetNumber"_ustr);
361 constexpr OUString gsPropertySourceName(u"SourceName"_ustr);
362 constexpr OUString gsPropertySubType(u"SubType"_ustr);
363 constexpr OUStringLiteral gsPropertyTargetFrame(u"TargetFrame");
364 constexpr OUStringLiteral gsPropertyTrueContent(u"TrueContent");
365 constexpr OUStringLiteral gsPropertyURL(u"URL");
366 constexpr OUStringLiteral gsPropertyURLContent(u"URLContent");
367 constexpr OUStringLiteral gsPropertyUserText(u"UserText");
368 constexpr OUString gsPropertyValue(u"Value"_ustr);
369 constexpr OUString gsPropertyVariableName(u"VariableName"_ustr);
370 constexpr OUString gsPropertyHelp(u"Help"_ustr);
371 constexpr OUString gsPropertyTooltip(u"Tooltip"_ustr);
372 constexpr OUStringLiteral gsPropertyTextRange(u"TextRange");
374 XMLTextFieldExport::XMLTextFieldExport( SvXMLExport& rExp,
375 std::unique_ptr<XMLPropertyState> pCombinedCharState)
376 : rExport(rExp),
377 pCombinedCharactersPropertyState(std::move(pCombinedCharState))
379 SetExportOnlyUsedFieldDeclarations();
382 XMLTextFieldExport::~XMLTextFieldExport()
386 /// get the field ID (as in FieldIDEnum) from XTextField
387 enum FieldIdEnum XMLTextFieldExport::GetFieldID(
388 const Reference<XTextField> & rTextField,
389 const Reference<XPropertySet> & xPropSet)
391 // get service names for rTextField (via XServiceInfo service)
392 Reference<XServiceInfo> xService(rTextField, UNO_QUERY);
393 const Sequence<OUString> aServices = xService->getSupportedServiceNames();
395 OUString sFieldName; // service name postfix of current field
397 // search for TextField service name
398 const OUString* pNames = std::find_if(aServices.begin(), aServices.end(),
399 [](const OUString& rName) { return rName.matchIgnoreAsciiCase(gsServicePrefix); });
400 if (pNames != aServices.end())
402 // TextField found => postfix is field type!
403 sFieldName = pNames->copy(gsServicePrefix.getLength());
406 // if this is not a normal text field, check if it's a presentation text field
407 if( sFieldName.isEmpty() )
409 // search for TextField service name
410 pNames = std::find_if(aServices.begin(), aServices.end(),
411 [](const OUString& rName) { return rName.startsWith(gsPresentationServicePrefix); });
412 if (pNames != aServices.end())
414 // TextField found => postfix is field type!
415 sFieldName = pNames->copy(gsPresentationServicePrefix.getLength());
418 if( !sFieldName.isEmpty() )
420 if( sFieldName == "Header" )
422 return FIELD_ID_DRAW_HEADER;
424 else if( sFieldName == "Footer" )
426 return FIELD_ID_DRAW_FOOTER;
428 else if( sFieldName == "DateTime" )
430 return FIELD_ID_DRAW_DATE_TIME;
435 // map postfix of service name to field ID
436 DBG_ASSERT(!sFieldName.isEmpty(), "no TextField service found!");
437 return MapFieldName(sFieldName, xPropSet);
440 enum FieldIdEnum XMLTextFieldExport::MapFieldName(
441 std::u16string_view sFieldName, // field (master) name
442 const Reference<XPropertySet> & xPropSet) // for subtype
444 // we'll proceed in 2 steps:
445 // a) map service name to preliminary FIELD_ID
446 // b) map those prelim. FIELD_IDs that correspond to several field types
447 // (in our (XML) world) to final FIELD IDs
450 // a) find prelim. FIELD_ID via aFieldServiceMapping
452 // check for non-empty service name
453 DBG_ASSERT(!sFieldName.empty(), "no valid service name!");
454 enum FieldIdEnum nToken = FIELD_ID_UNKNOWN;
455 if (!sFieldName.empty())
457 // map name to prelim. ID
458 bool bRet = SvXMLUnitConverter::convertEnum(
459 nToken, sFieldName, aFieldServiceNameMapping);
461 // check return
462 DBG_ASSERT(bRet, "Unknown field service name encountered!");
465 // b) map prelim. to final FIELD_IDs
466 switch (nToken) {
467 case FIELD_ID_VARIABLE_SET:
468 if (GetBoolProperty(gsPropertyIsInput, xPropSet))
470 nToken = FIELD_ID_VARIABLE_INPUT;
472 else
474 switch (GetIntProperty(gsPropertySubType, xPropSet))
476 case SetVariableType::STRING: // text field
477 case SetVariableType::VAR: // num field
478 nToken = FIELD_ID_VARIABLE_SET;
479 break;
480 case SetVariableType::SEQUENCE:
481 nToken = FIELD_ID_SEQUENCE;
482 break;
483 case SetVariableType::FORMULA:
484 default:
485 nToken = FIELD_ID_UNKNOWN;
486 break;
489 break;
491 case FIELD_ID_VARIABLE_GET:
492 switch (GetIntProperty(gsPropertySubType, xPropSet))
494 case SetVariableType::STRING: // text field
495 case SetVariableType::VAR: // num field
496 nToken = FIELD_ID_VARIABLE_GET;
497 break;
498 case SetVariableType::FORMULA:
499 nToken = FIELD_ID_EXPRESSION;
500 break;
501 case SetVariableType::SEQUENCE:
502 default:
503 nToken = FIELD_ID_UNKNOWN;
504 break;
506 break;
508 case FIELD_ID_TIME:
509 if (GetBoolProperty(gsPropertyIsDate, xPropSet))
511 nToken = FIELD_ID_DATE;
513 break;
515 case FIELD_ID_PAGENUMBER:
516 // NumberingType not available in non-Writer apps
517 if (xPropSet->getPropertySetInfo()->
518 hasPropertyByName(gsPropertyNumberingType))
520 if (NumberingType::CHAR_SPECIAL == GetIntProperty(
521 gsPropertyNumberingType, xPropSet))
523 nToken = FIELD_ID_PAGESTRING;
526 break;
528 case FIELD_ID_DOCINFO_CREATION_TIME:
529 if (GetBoolProperty(gsPropertyIsDate, xPropSet))
531 nToken = FIELD_ID_DOCINFO_CREATION_DATE;
533 break;
535 case FIELD_ID_DOCINFO_PRINT_TIME:
536 if (GetBoolProperty(gsPropertyIsDate, xPropSet))
538 nToken = FIELD_ID_DOCINFO_PRINT_DATE;
540 break;
542 case FIELD_ID_DOCINFO_SAVE_TIME:
543 if (GetBoolProperty(gsPropertyIsDate, xPropSet))
545 nToken = FIELD_ID_DOCINFO_SAVE_DATE;
547 break;
549 case FIELD_ID_REF_REFERENCE:
550 switch (GetInt16Property(gsPropertyReferenceFieldSource, xPropSet))
552 case ReferenceFieldSource::REFERENCE_MARK:
553 nToken = FIELD_ID_REF_REFERENCE;
554 break;
555 case ReferenceFieldSource::SEQUENCE_FIELD:
556 nToken = FIELD_ID_REF_SEQUENCE;
557 break;
558 case ReferenceFieldSource::BOOKMARK:
559 nToken = FIELD_ID_REF_BOOKMARK;
560 break;
561 case ReferenceFieldSource::FOOTNOTE:
562 nToken = FIELD_ID_REF_FOOTNOTE;
563 break;
564 case ReferenceFieldSource::ENDNOTE:
565 nToken = FIELD_ID_REF_ENDNOTE;
566 break;
567 case ReferenceFieldSource::STYLE:
568 nToken = FIELD_ID_REF_STYLE;
569 break;
570 default:
571 nToken = FIELD_ID_UNKNOWN;
572 break;
574 break;
576 case FIELD_ID_COMBINED_CHARACTERS:
577 case FIELD_ID_SCRIPT:
578 case FIELD_ID_ANNOTATION:
579 case FIELD_ID_BIBLIOGRAPHY:
580 case FIELD_ID_DDE:
581 case FIELD_ID_MACRO:
582 case FIELD_ID_REFPAGE_SET:
583 case FIELD_ID_REFPAGE_GET:
584 case FIELD_ID_COUNT_PAGES:
585 case FIELD_ID_COUNT_PARAGRAPHS:
586 case FIELD_ID_COUNT_WORDS:
587 case FIELD_ID_COUNT_CHARACTERS:
588 case FIELD_ID_COUNT_TABLES:
589 case FIELD_ID_COUNT_GRAPHICS:
590 case FIELD_ID_COUNT_OBJECTS:
591 case FIELD_ID_CONDITIONAL_TEXT:
592 case FIELD_ID_HIDDEN_TEXT:
593 case FIELD_ID_HIDDEN_PARAGRAPH:
594 case FIELD_ID_DOCINFO_CREATION_AUTHOR:
595 case FIELD_ID_DOCINFO_DESCRIPTION:
596 case FIELD_ID_DOCINFO_CUSTOM:
597 case FIELD_ID_DOCINFO_PRINT_AUTHOR:
598 case FIELD_ID_DOCINFO_TITLE:
599 case FIELD_ID_DOCINFO_SUBJECT:
600 case FIELD_ID_DOCINFO_KEYWORDS:
601 case FIELD_ID_DOCINFO_REVISION:
602 case FIELD_ID_DOCINFO_EDIT_DURATION:
603 case FIELD_ID_DOCINFO_SAVE_AUTHOR:
604 case FIELD_ID_TEXT_INPUT:
605 case FIELD_ID_USER_INPUT:
606 case FIELD_ID_AUTHOR:
607 case FIELD_ID_SENDER:
608 case FIELD_ID_PLACEHOLDER:
609 case FIELD_ID_USER_GET:
610 case FIELD_ID_DATABASE_NEXT:
611 case FIELD_ID_DATABASE_SELECT:
612 case FIELD_ID_DATABASE_DISPLAY:
613 case FIELD_ID_DATABASE_NAME:
614 case FIELD_ID_DATABASE_NUMBER:
615 case FIELD_ID_TEMPLATE_NAME:
616 case FIELD_ID_CHAPTER:
617 case FIELD_ID_FILE_NAME:
618 case FIELD_ID_META:
619 case FIELD_ID_SHEET_NAME:
620 case FIELD_ID_PAGENAME:
621 case FIELD_ID_MEASURE:
622 case FIELD_ID_URL:
623 case FIELD_ID_TABLE_FORMULA:
624 case FIELD_ID_DROP_DOWN:
625 ; // these field IDs are final
626 break;
628 default:
629 nToken = FIELD_ID_UNKNOWN;
632 // ... and return final FIELD_ID
633 return nToken;
636 // is string or numeric field?
637 bool XMLTextFieldExport::IsStringField(
638 FieldIdEnum nFieldType,
639 const Reference<XPropertySet> & xPropSet)
641 switch (nFieldType) {
643 case FIELD_ID_VARIABLE_GET:
644 case FIELD_ID_VARIABLE_SET:
645 case FIELD_ID_VARIABLE_INPUT:
647 // depends on field sub type
648 return ( GetIntProperty(gsPropertySubType, xPropSet) ==
649 SetVariableType::STRING );
652 case FIELD_ID_USER_GET:
653 case FIELD_ID_USER_INPUT:
655 Reference<XTextField> xTextField(xPropSet, UNO_QUERY);
656 DBG_ASSERT(xTextField.is(), "field is no XTextField!");
657 bool bRet = GetBoolProperty(gsPropertyIsExpression,
658 GetMasterPropertySet(xTextField));
659 return !bRet;
662 case FIELD_ID_META:
663 return 0 > GetIntProperty(gsPropertyNumberFormat, xPropSet);
665 case FIELD_ID_DATABASE_DISPLAY:
666 // TODO: depends on... ???
667 // workaround #no-bug#: no data type
668 return 5100 == GetIntProperty(gsPropertyNumberFormat, xPropSet);
670 case FIELD_ID_TABLE_FORMULA:
671 // legacy field: always a number field (because it always has
672 // a number format)
673 return false;
675 case FIELD_ID_COUNT_PAGES:
676 case FIELD_ID_COUNT_PARAGRAPHS:
677 case FIELD_ID_COUNT_WORDS:
678 case FIELD_ID_COUNT_CHARACTERS:
679 case FIELD_ID_COUNT_TABLES:
680 case FIELD_ID_COUNT_GRAPHICS:
681 case FIELD_ID_COUNT_OBJECTS:
682 case FIELD_ID_DOCINFO_SAVE_TIME:
683 case FIELD_ID_DOCINFO_SAVE_DATE:
684 case FIELD_ID_DOCINFO_CREATION_DATE:
685 case FIELD_ID_DOCINFO_CREATION_TIME:
686 case FIELD_ID_DOCINFO_PRINT_TIME:
687 case FIELD_ID_DOCINFO_PRINT_DATE:
688 case FIELD_ID_DOCINFO_EDIT_DURATION:
689 case FIELD_ID_DOCINFO_REVISION:
690 case FIELD_ID_DATABASE_NUMBER:
691 case FIELD_ID_EXPRESSION:
692 case FIELD_ID_SEQUENCE:
693 case FIELD_ID_DATE:
694 case FIELD_ID_TIME:
695 case FIELD_ID_PAGENUMBER:
696 case FIELD_ID_REFPAGE_SET:
697 case FIELD_ID_REFPAGE_GET:
698 case FIELD_ID_DOCINFO_CUSTOM:
699 // always number
700 return false;
702 case FIELD_ID_COMBINED_CHARACTERS:
703 case FIELD_ID_BIBLIOGRAPHY:
704 case FIELD_ID_DDE:
705 case FIELD_ID_REF_REFERENCE:
706 case FIELD_ID_REF_SEQUENCE:
707 case FIELD_ID_REF_BOOKMARK:
708 case FIELD_ID_REF_FOOTNOTE:
709 case FIELD_ID_REF_ENDNOTE:
710 case FIELD_ID_REF_STYLE:
711 case FIELD_ID_MACRO:
712 case FIELD_ID_TEMPLATE_NAME:
713 case FIELD_ID_CHAPTER:
714 case FIELD_ID_FILE_NAME:
715 case FIELD_ID_CONDITIONAL_TEXT:
716 case FIELD_ID_HIDDEN_TEXT:
717 case FIELD_ID_HIDDEN_PARAGRAPH:
718 case FIELD_ID_DOCINFO_CREATION_AUTHOR:
719 case FIELD_ID_DOCINFO_DESCRIPTION:
720 case FIELD_ID_DOCINFO_PRINT_AUTHOR:
721 case FIELD_ID_DOCINFO_TITLE:
722 case FIELD_ID_DOCINFO_SUBJECT:
723 case FIELD_ID_DOCINFO_KEYWORDS:
724 case FIELD_ID_DOCINFO_SAVE_AUTHOR:
725 case FIELD_ID_DATABASE_NAME:
726 case FIELD_ID_TEXT_INPUT:
727 case FIELD_ID_SENDER:
728 case FIELD_ID_AUTHOR:
729 case FIELD_ID_PAGENAME:
730 case FIELD_ID_PAGESTRING:
731 case FIELD_ID_SHEET_NAME:
732 case FIELD_ID_MEASURE:
733 case FIELD_ID_URL:
734 case FIELD_ID_DROP_DOWN:
735 // always string:
736 return true;
738 case FIELD_ID_SCRIPT:
739 case FIELD_ID_ANNOTATION:
740 case FIELD_ID_DATABASE_NEXT:
741 case FIELD_ID_DATABASE_SELECT:
742 case FIELD_ID_PLACEHOLDER:
743 case FIELD_ID_UNKNOWN:
744 case FIELD_ID_DRAW_HEADER:
745 case FIELD_ID_DRAW_FOOTER:
746 case FIELD_ID_DRAW_DATE_TIME:
747 default:
748 OSL_FAIL("unknown field type/field has no content");
749 return true; // invalid info; string in case of doubt
753 /// export the styles needed by the given field. Called on first pass
754 /// through document
755 void XMLTextFieldExport::ExportFieldAutoStyle(
756 const Reference<XTextField> & rTextField, const bool bProgress,
757 const bool bRecursive )
759 // get property set
760 Reference<XPropertySet> xPropSet(rTextField, UNO_QUERY);
762 // add field master to list of used field masters (if desired)
763 if (nullptr != pUsedMasters)
765 Reference<XDependentTextField> xDepField(rTextField, UNO_QUERY);
766 if (xDepField.is())
768 // The direct parent may be just the table cell, while we want the topmost parent, e.g.
769 // a header text.
770 Reference<XText> xOurText = GetToplevelText(rTextField->getAnchor()->getText());
772 std::map<Reference<XText>, std::set<OUString> >::iterator aMapIter =
773 pUsedMasters->find(xOurText);
775 // insert a list for our XText (if necessary)
776 if (aMapIter == pUsedMasters->end())
778 std::set<OUString> aSet;
779 (*pUsedMasters)[xOurText] = aSet;
780 aMapIter = pUsedMasters->find(xOurText);
783 // insert this text field master
784 OUString sFieldMasterName = GetStringProperty(
785 gsPropertyInstanceName, xDepField->getTextFieldMaster());
786 if (!sFieldMasterName.isEmpty())
787 aMapIter->second.insert( sFieldMasterName );
789 // else: no dependent field -> no master -> ignore
792 // get Field ID
793 FieldIdEnum nToken = GetFieldID(rTextField, xPropSet);
795 // export the character style for all fields
796 // with one exception: combined character fields export their own
797 // text style below
798 Reference <XPropertySet> xRangePropSet(rTextField->getAnchor(), UNO_QUERY);
799 if (FIELD_ID_COMBINED_CHARACTERS != nToken)
801 GetExport().GetTextParagraphExport()->Add(
802 XmlStyleFamily::TEXT_TEXT, xRangePropSet);
805 // process special styles for each field (e.g. data styles)
806 switch (nToken) {
808 case FIELD_ID_DATABASE_DISPLAY:
810 sal_Int32 nFormat = GetIntProperty(gsPropertyNumberFormat, xPropSet);
811 // workaround: #no-bug#; see IsStringField(...)
812 if ( (5100 != nFormat) &&
813 !GetBoolProperty(gsPropertyIsDataBaseFormat, xPropSet) )
815 GetExport().addDataStyle(nFormat);
817 break;
820 case FIELD_ID_DATE:
821 case FIELD_ID_TIME:
823 // date and time fields are always number fields, but the
824 // NumberFormat property is optional (e.g. Calc doesn't
825 // support it)
826 Reference<XPropertySetInfo> xPropSetInfo(
827 xPropSet->getPropertySetInfo() );
828 if ( xPropSetInfo->hasPropertyByName( gsPropertyNumberFormat ) )
830 sal_Int32 nFormat =
831 GetIntProperty(gsPropertyNumberFormat, xPropSet);
833 // nFormat may be -1 for numeric fields that display their
834 // variable name. (Maybe this should be a field type, then?)
835 if (nFormat != -1)
837 if( ! GetOptionalBoolProperty(
838 gsPropertyIsFixedLanguage,
839 xPropSet, xPropSetInfo, false ) )
841 nFormat =
842 GetExport().dataStyleForceSystemLanguage(nFormat);
845 GetExport().addDataStyle( nFormat,
846 nToken == FIELD_ID_TIME );
850 break;
852 case FIELD_ID_META:
853 // recurse into content (does not export element, so can be done first)
854 if (bRecursive)
856 bool dummy_for_autostyles(true);
857 ExportMetaField(xPropSet, true, bProgress, dummy_for_autostyles);
859 [[fallthrough]];
860 case FIELD_ID_DOCINFO_PRINT_TIME:
861 case FIELD_ID_DOCINFO_PRINT_DATE:
862 case FIELD_ID_DOCINFO_CREATION_DATE:
863 case FIELD_ID_DOCINFO_CREATION_TIME:
864 case FIELD_ID_DOCINFO_SAVE_TIME:
865 case FIELD_ID_DOCINFO_SAVE_DATE:
866 case FIELD_ID_DOCINFO_EDIT_DURATION:
867 case FIELD_ID_VARIABLE_SET:
868 case FIELD_ID_VARIABLE_GET:
869 case FIELD_ID_VARIABLE_INPUT:
870 case FIELD_ID_USER_GET:
871 case FIELD_ID_EXPRESSION:
872 case FIELD_ID_TABLE_FORMULA:
873 case FIELD_ID_DOCINFO_CUSTOM:
874 // register number format, if this is a numeric field
875 if (! IsStringField(nToken, xPropSet)) {
877 sal_Int32 nFormat =
878 GetIntProperty(gsPropertyNumberFormat, xPropSet);
880 // nFormat may be -1 for numeric fields that display their
881 // variable name. (Maybe this should be a field type, then?)
882 if (nFormat != -1)
884 // handle formats for fixed language fields
885 // for all these fields (except table formula)
886 if( ( nToken != FIELD_ID_TABLE_FORMULA ) &&
887 ! GetOptionalBoolProperty(
888 gsPropertyIsFixedLanguage,
889 xPropSet, xPropSet->getPropertySetInfo(),
890 false ) )
892 nFormat =
893 GetExport().dataStyleForceSystemLanguage(nFormat);
896 GetExport().addDataStyle(nFormat);
899 break;
901 case FIELD_ID_COMBINED_CHARACTERS:
903 // export text style with the addition of the combined characters
904 DBG_ASSERT(nullptr != pCombinedCharactersPropertyState,
905 "need proper PropertyState for combined characters");
906 std::span<XMLPropertyState> aStates( pCombinedCharactersPropertyState.get(), 1 );
907 GetExport().GetTextParagraphExport()->Add(
908 XmlStyleFamily::TEXT_TEXT, xRangePropSet,
909 aStates);
910 break;
913 case FIELD_ID_SCRIPT:
914 case FIELD_ID_ANNOTATION:
915 case FIELD_ID_BIBLIOGRAPHY:
916 case FIELD_ID_DDE:
917 case FIELD_ID_REF_REFERENCE:
918 case FIELD_ID_REF_SEQUENCE:
919 case FIELD_ID_REF_BOOKMARK:
920 case FIELD_ID_REF_FOOTNOTE:
921 case FIELD_ID_REF_ENDNOTE:
922 case FIELD_ID_REF_STYLE:
923 case FIELD_ID_MACRO:
924 case FIELD_ID_REFPAGE_SET:
925 case FIELD_ID_REFPAGE_GET:
926 case FIELD_ID_COUNT_PAGES:
927 case FIELD_ID_COUNT_PARAGRAPHS:
928 case FIELD_ID_COUNT_WORDS:
929 case FIELD_ID_COUNT_CHARACTERS:
930 case FIELD_ID_COUNT_TABLES:
931 case FIELD_ID_COUNT_GRAPHICS:
932 case FIELD_ID_COUNT_OBJECTS:
933 case FIELD_ID_CONDITIONAL_TEXT:
934 case FIELD_ID_HIDDEN_TEXT:
935 case FIELD_ID_HIDDEN_PARAGRAPH:
936 case FIELD_ID_DOCINFO_CREATION_AUTHOR:
937 case FIELD_ID_DOCINFO_DESCRIPTION:
938 case FIELD_ID_DOCINFO_PRINT_AUTHOR:
939 case FIELD_ID_DOCINFO_TITLE:
940 case FIELD_ID_DOCINFO_SUBJECT:
941 case FIELD_ID_DOCINFO_KEYWORDS:
942 case FIELD_ID_DOCINFO_REVISION:
943 case FIELD_ID_DOCINFO_SAVE_AUTHOR:
944 case FIELD_ID_SEQUENCE:
945 case FIELD_ID_PAGENAME:
946 case FIELD_ID_PAGENUMBER:
947 case FIELD_ID_PAGESTRING:
948 case FIELD_ID_AUTHOR:
949 case FIELD_ID_SENDER:
950 case FIELD_ID_PLACEHOLDER:
951 case FIELD_ID_USER_INPUT:
952 case FIELD_ID_TEXT_INPUT:
953 case FIELD_ID_DATABASE_NEXT:
954 case FIELD_ID_DATABASE_SELECT:
955 case FIELD_ID_DATABASE_NAME:
956 case FIELD_ID_DATABASE_NUMBER:
957 case FIELD_ID_TEMPLATE_NAME:
958 case FIELD_ID_CHAPTER:
959 case FIELD_ID_FILE_NAME:
960 case FIELD_ID_SHEET_NAME:
961 case FIELD_ID_MEASURE:
962 case FIELD_ID_URL:
963 case FIELD_ID_DROP_DOWN:
964 case FIELD_ID_DRAW_DATE_TIME:
965 case FIELD_ID_DRAW_FOOTER:
966 case FIELD_ID_DRAW_HEADER:
967 ; // no formats for these fields!
968 break;
970 case FIELD_ID_UNKNOWN:
971 default:
972 OSL_FAIL("unknown field type!");
973 // ignore -> no format for unknown
974 break;
978 /// export the given field to XML. Called on second pass through document
979 void XMLTextFieldExport::ExportField(
980 const Reference<XTextField> & rTextField, bool bProgress,
981 bool & rPrevCharIsSpace)
983 // get property set
984 Reference<XPropertySet> xPropSet(rTextField, UNO_QUERY);
986 // get property set of range (for the attributes)
987 Reference <XPropertySet> xRangePropSet(rTextField->getAnchor(), UNO_QUERY);
989 // get Field ID
990 enum FieldIdEnum nToken = GetFieldID(rTextField, xPropSet);
992 // special treatment for combined characters field, because it is
993 // exported as a style
994 const XMLPropertyState* aStates[] = { pCombinedCharactersPropertyState.get(), nullptr };
995 const XMLPropertyState **pStates =
996 FIELD_ID_COMBINED_CHARACTERS == nToken
997 ? aStates
998 : nullptr;
1000 // find out whether we need to set the style
1001 bool bIsUICharStyle;
1002 bool bHasAutoStyle;
1003 OUString sStyle = GetExport().GetTextParagraphExport()->
1004 FindTextStyle( xRangePropSet, bIsUICharStyle, bHasAutoStyle, pStates );
1005 bool bHasStyle = !sStyle.isEmpty();
1008 Reference<XPropertySetInfo> xRangePropSetInfo;
1009 XMLTextCharStyleNamesElementExport aCharStylesExport(
1010 GetExport(), bIsUICharStyle &&
1011 GetExport().GetTextParagraphExport()
1012 ->GetCharStyleNamesPropInfoCache().hasProperty(
1013 xRangePropSet, xRangePropSetInfo ), bHasAutoStyle,
1014 xRangePropSet, gsPropertyCharStyleNames );
1016 // export span with style (if necessary)
1017 // (except for combined characters field)
1018 if( bHasStyle )
1020 // export <text:span> element
1021 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
1022 GetExport().EncodeStyleName( sStyle ) );
1024 SvXMLElementExport aSpan( GetExport(), bHasStyle,
1025 XML_NAMESPACE_TEXT, XML_SPAN,
1026 false, false);
1028 // finally, export the field itself
1029 ExportFieldHelper( rTextField, xPropSet, xRangePropSet, nToken,
1030 bProgress, rPrevCharIsSpace);
1034 /// export the given field to XML. Called on second pass through document
1035 void XMLTextFieldExport::ExportFieldHelper(
1036 const Reference<XTextField> & rTextField,
1037 const Reference<XPropertySet> & rPropSet,
1038 const Reference<XPropertySet> &,
1039 enum FieldIdEnum nToken,
1040 bool bProgress,
1041 bool & rPrevCharIsSpace)
1043 // get property set info (because some attributes are not support
1044 // in all implementations)
1045 Reference<XPropertySetInfo> xPropSetInfo(rPropSet->getPropertySetInfo());
1047 OUString sPresentation = rTextField->getPresentation(false);
1049 // process each field type
1050 switch (nToken) {
1051 case FIELD_ID_AUTHOR:
1052 // author field: fixed, field (sub-)type
1053 if (xPropSetInfo->hasPropertyByName(gsPropertyIsFixed))
1055 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_FIXED,
1056 (GetBoolProperty(gsPropertyIsFixed, rPropSet) ? XML_TRUE : XML_FALSE) );
1058 ExportElement(MapAuthorFieldName(rPropSet), sPresentation);
1059 break;
1061 case FIELD_ID_SENDER:
1062 // sender field: fixed, field (sub-)type
1063 ProcessBoolean(XML_FIXED,
1064 GetBoolProperty(gsPropertyIsFixed, rPropSet), true);
1065 ExportElement(MapSenderFieldName(rPropSet), sPresentation);
1066 break;
1068 case FIELD_ID_PLACEHOLDER:
1069 // placeholder field: type, name, description
1070 ProcessString(XML_PLACEHOLDER_TYPE,
1071 MapPlaceholderType(
1072 GetInt16Property(gsPropertyPlaceholderType, rPropSet)));
1073 ProcessString(XML_DESCRIPTION,
1074 GetStringProperty(gsPropertyHint,rPropSet), true);
1075 ExportElement(XML_PLACEHOLDER, sPresentation);
1076 break;
1078 case FIELD_ID_VARIABLE_SET:
1080 // variable set field: name, visible, format&value
1081 ProcessString(XML_NAME,
1082 GetStringProperty(gsPropertyVariableName, rPropSet));
1083 ProcessDisplay(GetBoolProperty(gsPropertyIsVisible, rPropSet),
1084 false);
1085 ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW,
1086 GetStringProperty(gsPropertyContent, rPropSet),
1087 sPresentation);
1088 ProcessValueAndType(IsStringField(nToken, rPropSet),
1089 GetIntProperty(gsPropertyNumberFormat, rPropSet),
1090 GetStringProperty(gsPropertyContent, rPropSet),
1091 sPresentation,
1092 GetDoubleProperty(gsPropertyValue, rPropSet),
1093 true, true, true,
1094 ! GetOptionalBoolProperty(
1095 gsPropertyIsFixedLanguage,
1096 rPropSet, xPropSetInfo, false ) );
1097 ExportElement(XML_VARIABLE_SET, sPresentation);
1098 break;
1100 case FIELD_ID_VARIABLE_GET:
1102 // variable get field: name, format&value
1103 ProcessString(XML_NAME,
1104 GetStringProperty(gsPropertyContent, rPropSet));
1105 bool bCmd = GetBoolProperty(gsPropertyIsShowFormula, rPropSet);
1106 ProcessDisplay(true, bCmd);
1107 // show style, unless name will be shown
1108 ProcessValueAndType(IsStringField(nToken, rPropSet),
1109 GetIntProperty(gsPropertyNumberFormat, rPropSet),
1110 "", u"", 0.0, // values not used
1111 false,
1112 false,
1113 !bCmd,
1114 ! GetOptionalBoolProperty(
1115 gsPropertyIsFixedLanguage,
1116 rPropSet, xPropSetInfo, false ) );
1117 ExportElement(XML_VARIABLE_GET, sPresentation);
1118 break;
1120 case FIELD_ID_VARIABLE_INPUT:
1121 // variable input field: name, description, format&value
1122 ProcessString(XML_NAME,
1123 GetStringProperty(gsPropertyVariableName, rPropSet));
1124 ProcessString(XML_DESCRIPTION,
1125 GetStringProperty(gsPropertyHint , rPropSet));
1126 ProcessDisplay(GetBoolProperty(gsPropertyIsVisible, rPropSet),
1127 false);
1128 ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW,
1129 GetStringProperty(gsPropertyContent, rPropSet),
1130 sPresentation);
1131 ProcessValueAndType(IsStringField(nToken, rPropSet),
1132 GetIntProperty(gsPropertyNumberFormat, rPropSet),
1133 GetStringProperty(gsPropertyContent, rPropSet),
1134 sPresentation,
1135 GetDoubleProperty(gsPropertyValue, rPropSet),
1136 true, true, true,
1137 ! GetOptionalBoolProperty(
1138 gsPropertyIsFixedLanguage,
1139 rPropSet, xPropSetInfo, false ) );
1140 ExportElement(XML_VARIABLE_INPUT, sPresentation);
1141 break;
1143 case FIELD_ID_USER_GET:
1144 // user field: name, hidden, style
1146 bool bCmd = GetBoolProperty(gsPropertyIsShowFormula, rPropSet);
1147 ProcessDisplay(GetBoolProperty(gsPropertyIsVisible, rPropSet),
1148 bCmd);
1149 ProcessValueAndType(IsStringField(nToken, rPropSet),
1150 GetIntProperty(gsPropertyNumberFormat, rPropSet),
1151 "", u"", 0.0, // values not used
1152 false, false, !bCmd,
1153 ! GetOptionalBoolProperty(
1154 gsPropertyIsFixedLanguage,
1155 rPropSet, xPropSetInfo, false ) );
1157 // name from FieldMaster
1158 ProcessString(XML_NAME,
1159 GetStringProperty(gsPropertyName,
1160 GetMasterPropertySet(rTextField)));
1161 ExportElement(XML_USER_FIELD_GET, sPresentation);
1162 break;
1165 case FIELD_ID_USER_INPUT:
1166 // user input field: name (from FieldMaster), description
1167 // ProcessString(XML_NAME,
1168 // GetStringProperty(sPropertyName,
1169 // GetMasterPropertySet(rTextField)));
1170 ProcessString(XML_NAME,
1171 GetStringProperty(gsPropertyContent, rPropSet));
1172 ProcessString(XML_DESCRIPTION,
1173 GetStringProperty(gsPropertyHint, rPropSet));
1174 ExportElement(XML_USER_FIELD_INPUT, sPresentation);
1175 break;
1177 case FIELD_ID_SEQUENCE:
1179 // sequence field: name, formula, seq-format
1180 OUString sName = GetStringProperty(gsPropertyVariableName, rPropSet);
1181 // TODO: use reference name only if actually being referenced.
1182 ProcessString(XML_REF_NAME,
1183 MakeSequenceRefName(
1184 GetInt16Property(gsPropertySequenceValue, rPropSet),
1185 sName));
1186 ProcessString(XML_NAME, sName);
1187 ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW,
1188 GetStringProperty(gsPropertyContent, rPropSet),
1189 sPresentation);
1190 ProcessNumberingType(GetInt16Property(gsPropertyNumberingType,
1191 rPropSet));
1192 ExportElement(XML_SEQUENCE, sPresentation);
1193 break;
1196 case FIELD_ID_EXPRESSION:
1198 // formula field: formula, format&value
1199 bool bCmd = GetBoolProperty(gsPropertyIsShowFormula, rPropSet);
1200 ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW,
1201 GetStringProperty(gsPropertyContent, rPropSet),
1202 sPresentation);
1203 ProcessDisplay(true, bCmd);
1204 ProcessValueAndType(IsStringField(nToken, rPropSet),
1205 GetIntProperty(gsPropertyNumberFormat, rPropSet),
1206 GetStringProperty(gsPropertyContent, rPropSet),
1207 sPresentation,
1208 GetDoubleProperty(gsPropertyValue, rPropSet),
1209 !bCmd, !bCmd, !bCmd,
1210 ! GetOptionalBoolProperty(
1211 gsPropertyIsFixedLanguage,
1212 rPropSet, xPropSetInfo, false ) );
1213 ExportElement(XML_EXPRESSION, sPresentation);
1214 break;
1217 case FIELD_ID_TEXT_INPUT:
1218 // text input field: description and string-value
1219 ProcessString(XML_DESCRIPTION,
1220 GetStringProperty(gsPropertyHint, rPropSet));
1221 ProcessString(XML_HELP,
1222 GetStringProperty(gsPropertyHelp, rPropSet), true);
1223 ProcessString(XML_HINT,
1224 GetStringProperty(gsPropertyTooltip, rPropSet), true);
1225 ExportElement(XML_TEXT_INPUT, sPresentation);
1226 break;
1228 case FIELD_ID_TIME:
1229 // all properties (except IsDate) are optional!
1230 if (xPropSetInfo->hasPropertyByName(gsPropertyNumberFormat))
1232 ProcessValueAndType(false,
1233 GetIntProperty(gsPropertyNumberFormat,rPropSet),
1234 "", u"", 0.0, // not used
1235 false, false, true,
1236 ! GetOptionalBoolProperty(
1237 gsPropertyIsFixedLanguage,
1238 rPropSet, xPropSetInfo, false ),
1239 true);
1241 if (xPropSetInfo->hasPropertyByName(gsPropertyDateTimeValue))
1243 // no value -> current time
1244 ProcessTimeOrDateTime(XML_TIME_VALUE,
1245 GetDateTimeProperty(gsPropertyDateTimeValue,
1246 rPropSet));
1248 if (xPropSetInfo->hasPropertyByName(gsPropertyDateTime))
1250 // no value -> current time
1251 ProcessTimeOrDateTime(XML_TIME_VALUE,
1252 GetDateTimeProperty(gsPropertyDateTime,rPropSet));
1254 if (xPropSetInfo->hasPropertyByName(gsPropertyIsFixed))
1256 ProcessBoolean(XML_FIXED,
1257 GetBoolProperty(gsPropertyIsFixed, rPropSet),
1258 false);
1260 if (xPropSetInfo->hasPropertyByName(gsPropertyAdjust))
1262 // adjust value given as integer in minutes
1263 ProcessDateTime(XML_TIME_ADJUST,
1264 GetIntProperty(gsPropertyAdjust, rPropSet),
1265 false, true);
1267 ExportElement(XML_TIME, sPresentation);
1268 break;
1270 case FIELD_ID_DATE:
1271 // all properties (except IsDate) are optional!
1272 if (xPropSetInfo->hasPropertyByName(gsPropertyNumberFormat))
1274 ProcessValueAndType(false,
1275 GetIntProperty(gsPropertyNumberFormat,rPropSet),
1276 "", u"", 0.0, // not used
1277 false, false, true,
1278 ! GetOptionalBoolProperty(
1279 gsPropertyIsFixedLanguage,
1280 rPropSet, xPropSetInfo, false ) );
1282 if (xPropSetInfo->hasPropertyByName(gsPropertyDateTimeValue))
1284 // no value -> current date
1285 ProcessDateTime(XML_DATE_VALUE,
1286 GetDateTimeProperty(gsPropertyDateTimeValue,
1287 rPropSet));
1289 // TODO: remove double-handling after SRC614
1290 else if (xPropSetInfo->hasPropertyByName(gsPropertyDateTime))
1292 ProcessDateTime(XML_DATE_VALUE,
1293 GetDateTimeProperty(gsPropertyDateTime,rPropSet));
1295 if (xPropSetInfo->hasPropertyByName(gsPropertyIsFixed))
1297 ProcessBoolean(XML_FIXED,
1298 GetBoolProperty(gsPropertyIsFixed, rPropSet),
1299 false);
1301 if (xPropSetInfo->hasPropertyByName(gsPropertyAdjust))
1303 // adjust value given as number of days
1304 ProcessDateTime(XML_DATE_ADJUST,
1305 GetIntProperty(gsPropertyAdjust, rPropSet),
1306 true, true);
1308 ExportElement(XML_DATE, sPresentation);
1309 break;
1311 case FIELD_ID_PAGENUMBER:
1312 // all properties are optional
1313 if (xPropSetInfo->hasPropertyByName(gsPropertyNumberingType))
1315 ProcessNumberingType(GetInt16Property(gsPropertyNumberingType,
1316 rPropSet));
1318 if (xPropSetInfo->hasPropertyByName(gsPropertyOffset))
1320 sal_Int32 nAdjust = GetIntProperty(gsPropertyOffset, rPropSet);
1322 if (xPropSetInfo->hasPropertyByName(gsPropertySubType))
1324 // property SubType used in MapPageNumberName
1325 ProcessString(XML_SELECT_PAGE,
1326 MapPageNumberName(rPropSet, nAdjust));
1328 ProcessIntegerDef(XML_PAGE_ADJUST, nAdjust, 0);
1330 ExportElement(XML_PAGE_NUMBER, sPresentation);
1331 break;
1333 case FIELD_ID_PAGESTRING:
1335 ProcessString(XML_STRING_VALUE,
1336 GetStringProperty(gsPropertyUserText, rPropSet),
1337 sPresentation);
1338 sal_Int32 nDummy = 0; // MapPageNumberName need int
1339 ProcessString(XML_SELECT_PAGE, MapPageNumberName(rPropSet, nDummy));
1340 ExportElement(XML_PAGE_CONTINUATION, sPresentation);
1341 break;
1344 case FIELD_ID_DATABASE_NAME:
1345 ProcessString(XML_TABLE_NAME,
1346 GetStringProperty(gsPropertyDataTableName, rPropSet));
1347 ProcessCommandType(GetIntProperty(gsPropertyDataCommandType, rPropSet));
1348 ProcessDisplay(GetBoolProperty(gsPropertyIsVisible, rPropSet),
1349 false);
1350 ExportDataBaseElement(XML_DATABASE_NAME, sPresentation,
1351 rPropSet, xPropSetInfo);
1352 break;
1354 case FIELD_ID_DATABASE_NUMBER:
1355 ProcessString(XML_TABLE_NAME,
1356 GetStringProperty(gsPropertyDataTableName, rPropSet));
1357 ProcessCommandType(GetIntProperty(gsPropertyDataCommandType, rPropSet));
1358 ProcessNumberingType(
1359 GetInt16Property(gsPropertyNumberingType,rPropSet));
1360 ProcessInteger(XML_VALUE,
1361 GetIntProperty(gsPropertySetNumber, rPropSet));
1362 ProcessDisplay(GetBoolProperty(gsPropertyIsVisible, rPropSet),
1363 false);
1364 ExportDataBaseElement(XML_DATABASE_ROW_NUMBER, sPresentation,
1365 rPropSet, xPropSetInfo);
1366 break;
1368 case FIELD_ID_DATABASE_NEXT:
1369 ProcessString(XML_TABLE_NAME,
1370 GetStringProperty(gsPropertyDataTableName, rPropSet));
1371 ProcessCommandType(GetIntProperty(gsPropertyDataCommandType, rPropSet));
1372 ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1373 GetStringProperty(gsPropertyCondition, rPropSet));
1374 DBG_ASSERT(sPresentation.isEmpty(),
1375 "Unexpected presentation for database next field");
1376 ExportDataBaseElement(XML_DATABASE_NEXT, OUString(),
1377 rPropSet, xPropSetInfo);
1378 break;
1380 case FIELD_ID_DATABASE_SELECT:
1381 ProcessString(XML_TABLE_NAME,
1382 GetStringProperty(gsPropertyDataTableName, rPropSet));
1383 ProcessCommandType(GetIntProperty(gsPropertyDataCommandType, rPropSet));
1384 ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1385 GetStringProperty(gsPropertyCondition, rPropSet));
1386 ProcessInteger(XML_ROW_NUMBER,
1387 GetIntProperty(gsPropertySetNumber, rPropSet));
1388 DBG_ASSERT(sPresentation.isEmpty(),
1389 "Unexpected presentation for database select field");
1390 ExportDataBaseElement(XML_DATABASE_ROW_SELECT, OUString(),
1391 rPropSet, xPropSetInfo);
1392 break;
1394 case FIELD_ID_DATABASE_DISPLAY:
1396 // get database, table and column name from field master
1397 const Reference<XPropertySet> & xMaster = GetMasterPropertySet(rTextField);
1398 ProcessString(XML_TABLE_NAME,
1399 GetStringProperty(gsPropertyDataTableName, xMaster));
1400 ProcessCommandType(GetIntProperty(gsPropertyDataCommandType, xMaster));
1401 ProcessString(XML_COLUMN_NAME,
1402 GetStringProperty(gsPropertyDataColumnName, xMaster));
1403 // export number format if available (happens only for numbers!)
1404 if (!GetBoolProperty(gsPropertyIsDataBaseFormat, rPropSet))
1406 ProcessValueAndType(false, // doesn't happen for text
1407 GetIntProperty(gsPropertyNumberFormat,rPropSet),
1408 "", u"", 0.0, // not used
1409 false, false, true, false);
1411 ProcessDisplay(GetBoolProperty(gsPropertyIsVisible, rPropSet),
1412 false);
1413 ExportDataBaseElement(XML_DATABASE_DISPLAY, sPresentation,
1414 xMaster, xMaster->getPropertySetInfo());
1415 break;
1418 case FIELD_ID_DOCINFO_REVISION:
1419 ProcessBoolean(XML_FIXED,
1420 GetBoolProperty(gsPropertyIsFixed, rPropSet), false);
1421 ExportElement(MapDocInfoFieldName(nToken), sPresentation);
1422 break;
1424 case FIELD_ID_DOCINFO_EDIT_DURATION:
1425 case FIELD_ID_DOCINFO_SAVE_TIME:
1426 case FIELD_ID_DOCINFO_CREATION_TIME:
1427 case FIELD_ID_DOCINFO_PRINT_TIME:
1428 case FIELD_ID_DOCINFO_SAVE_DATE:
1429 case FIELD_ID_DOCINFO_CREATION_DATE:
1430 case FIELD_ID_DOCINFO_PRINT_DATE:
1431 ProcessValueAndType(false,
1432 GetIntProperty(gsPropertyNumberFormat, rPropSet),
1433 "", u"", 0.0,
1434 false, false, true,
1435 ! GetOptionalBoolProperty(
1436 gsPropertyIsFixedLanguage,
1437 rPropSet, xPropSetInfo, false ) );
1439 // todo: export date/time value, but values not available -> core bug
1440 ProcessBoolean(XML_FIXED,
1441 GetBoolProperty(gsPropertyIsFixed, rPropSet), false);
1442 ExportElement(MapDocInfoFieldName(nToken), sPresentation);
1443 break;
1445 case FIELD_ID_DOCINFO_CREATION_AUTHOR:
1446 case FIELD_ID_DOCINFO_DESCRIPTION:
1447 case FIELD_ID_DOCINFO_PRINT_AUTHOR:
1448 case FIELD_ID_DOCINFO_TITLE:
1449 case FIELD_ID_DOCINFO_SUBJECT:
1450 case FIELD_ID_DOCINFO_KEYWORDS:
1451 case FIELD_ID_DOCINFO_SAVE_AUTHOR:
1452 if (xPropSetInfo->hasPropertyByName(gsPropertyIsFixed))
1454 ProcessBoolean(XML_FIXED,
1455 GetBoolProperty(gsPropertyIsFixed, rPropSet), false);
1457 ExportElement(MapDocInfoFieldName(nToken), sPresentation);
1458 break;
1460 case FIELD_ID_DOCINFO_CUSTOM:
1462 ProcessValueAndType(false, // doesn't happen for text
1463 GetIntProperty(gsPropertyNumberFormat,rPropSet),
1464 "", u"", 0.0, // not used
1465 false, false, true,
1466 ! GetOptionalBoolProperty(
1467 gsPropertyIsFixedLanguage,
1468 rPropSet, xPropSetInfo, false ));
1469 uno::Any aAny = rPropSet->getPropertyValue( gsPropertyName );
1470 OUString sName;
1471 aAny >>= sName;
1472 ProcessString(XML_NAME, sName);
1473 ProcessBoolean(XML_FIXED, GetBoolProperty(gsPropertyIsFixed, rPropSet), false);
1474 ExportElement(XML_USER_DEFINED, sPresentation);
1475 break;
1478 case FIELD_ID_COUNT_PAGES:
1479 case FIELD_ID_COUNT_PARAGRAPHS:
1480 case FIELD_ID_COUNT_WORDS:
1481 case FIELD_ID_COUNT_CHARACTERS:
1482 case FIELD_ID_COUNT_TABLES:
1483 case FIELD_ID_COUNT_GRAPHICS:
1484 case FIELD_ID_COUNT_OBJECTS:
1485 // all properties optional (applies to pages only, but I'll do
1486 // it for all for sake of common implementation)
1487 if (xPropSetInfo->hasPropertyByName(gsPropertyNumberingType))
1489 ProcessNumberingType(GetInt16Property(gsPropertyNumberingType,
1490 rPropSet));
1492 ExportElement(MapCountFieldName(nToken), sPresentation);
1493 break;
1495 case FIELD_ID_CONDITIONAL_TEXT:
1496 ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1497 GetStringProperty(gsPropertyCondition, rPropSet));
1498 ProcessString(XML_STRING_VALUE_IF_TRUE,
1499 GetStringProperty(gsPropertyTrueContent, rPropSet));
1500 ProcessString(XML_STRING_VALUE_IF_FALSE,
1501 GetStringProperty(gsPropertyFalseContent, rPropSet));
1502 ProcessBoolean(XML_CURRENT_VALUE,
1503 GetBoolProperty(gsPropertyIsConditionTrue, rPropSet),
1504 false);
1505 ExportElement(XML_CONDITIONAL_TEXT, sPresentation);
1506 break;
1508 case FIELD_ID_HIDDEN_TEXT:
1509 ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1510 GetStringProperty(gsPropertyCondition, rPropSet));
1511 ProcessString(XML_STRING_VALUE,
1512 GetStringProperty(gsPropertyContent, rPropSet));
1513 ProcessBoolean(XML_IS_HIDDEN,
1514 GetBoolProperty(gsPropertyIsHidden, rPropSet),
1515 false);
1516 ExportElement(XML_HIDDEN_TEXT, sPresentation);
1517 break;
1519 case FIELD_ID_HIDDEN_PARAGRAPH:
1520 ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1521 GetStringProperty(gsPropertyCondition, rPropSet));
1522 ProcessBoolean(XML_IS_HIDDEN,
1523 GetBoolProperty(gsPropertyIsHidden, rPropSet),
1524 false);
1525 DBG_ASSERT(sPresentation.isEmpty(),
1526 "Unexpected presentation for hidden paragraph field");
1527 ExportElement(XML_HIDDEN_PARAGRAPH);
1528 break;
1530 case FIELD_ID_TEMPLATE_NAME:
1531 ProcessString(XML_DISPLAY,
1532 MapTemplateDisplayFormat(
1533 GetInt16Property(gsPropertyFileFormat, rPropSet)));
1534 ExportElement(XML_TEMPLATE_NAME, sPresentation);
1535 break;
1537 case FIELD_ID_CHAPTER:
1538 ProcessString(XML_DISPLAY,
1539 MapChapterDisplayFormat(
1540 GetInt16Property(gsPropertyChapterFormat, rPropSet)));
1541 // API numbers 0..9, we number 1..10
1542 ProcessInteger(XML_OUTLINE_LEVEL,
1543 GetInt8Property(gsPropertyLevel, rPropSet) + 1);
1544 ExportElement(XML_CHAPTER, sPresentation);
1545 break;
1547 case FIELD_ID_FILE_NAME:
1548 // all properties are optional
1549 if (xPropSetInfo->hasPropertyByName(gsPropertyFileFormat))
1551 ProcessString(XML_DISPLAY,
1552 MapFilenameDisplayFormat(
1553 GetInt16Property(gsPropertyFileFormat, rPropSet)));
1555 if (xPropSetInfo->hasPropertyByName(gsPropertyIsFixed))
1557 ProcessBoolean(XML_FIXED,
1558 GetBoolProperty(gsPropertyIsFixed, rPropSet),
1559 false);
1561 ExportElement(XML_FILE_NAME, sPresentation);
1562 break;
1564 case FIELD_ID_REFPAGE_SET:
1565 ProcessBoolean(XML_ACTIVE,
1566 GetBoolProperty(gsPropertyOn, rPropSet), true);
1567 ProcessIntegerDef(XML_PAGE_ADJUST,
1568 GetInt16Property(gsPropertyOffset, rPropSet), 0);
1569 DBG_ASSERT(sPresentation.isEmpty(),
1570 "Unexpected presentation page variable field");
1571 ExportElement(XML_PAGE_VARIABLE_SET);
1572 break;
1574 case FIELD_ID_REFPAGE_GET:
1575 ProcessNumberingType(
1576 GetInt16Property(gsPropertyNumberingType, rPropSet));
1577 ExportElement(XML_PAGE_VARIABLE_GET, sPresentation);
1578 break;
1580 case FIELD_ID_MACRO:
1581 ExportMacro( rPropSet, sPresentation );
1582 break;
1584 case FIELD_ID_REF_SEQUENCE:
1585 // reference to sequence: format, name, find value (and element)
1586 // was: if (nSeqNumber != -1) ...
1587 ProcessString(XML_REFERENCE_FORMAT,
1588 MapReferenceType(GetInt16Property(
1589 gsPropertyReferenceFieldPart, rPropSet)),
1590 XML_TEMPLATE);
1591 ProcessString(XML_REF_NAME,
1592 MakeSequenceRefName(
1593 GetInt16Property(gsPropertySequenceNumber, rPropSet),
1594 GetStringProperty(gsPropertySourceName, rPropSet) ) );
1595 if (xPropSetInfo->hasPropertyByName(gsPropertyReferenceFieldLanguage) &&
1596 GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
1598 // export text:reference-language attribute, if not empty
1599 ProcessString(XML_REFERENCE_LANGUAGE,
1600 GetStringProperty(gsPropertyReferenceFieldLanguage, rPropSet), true, XML_NAMESPACE_LO_EXT);
1602 ExportElement(
1603 MapReferenceSource(
1604 GetInt16Property(gsPropertyReferenceFieldSource, rPropSet)),
1605 sPresentation);
1606 break;
1608 case FIELD_ID_REF_REFERENCE:
1609 case FIELD_ID_REF_BOOKMARK:
1610 // reference to bookmarks, references: format, name (and element)
1611 ProcessString(XML_REFERENCE_FORMAT,
1612 MapReferenceType(GetInt16Property(
1613 gsPropertyReferenceFieldPart, rPropSet)),
1614 XML_TEMPLATE);
1615 ProcessString(XML_REF_NAME,
1616 GetStringProperty(gsPropertySourceName, rPropSet));
1617 if (xPropSetInfo->hasPropertyByName(gsPropertyReferenceFieldLanguage) &&
1618 GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
1620 // export text:reference-language attribute, if not empty
1621 ProcessString(XML_REFERENCE_LANGUAGE,
1622 GetStringProperty(gsPropertyReferenceFieldLanguage, rPropSet), true, XML_NAMESPACE_LO_EXT);
1624 ExportElement(
1625 MapReferenceSource(GetInt16Property(
1626 gsPropertyReferenceFieldSource, rPropSet)),
1627 sPresentation);
1628 break;
1630 case FIELD_ID_REF_FOOTNOTE:
1631 case FIELD_ID_REF_ENDNOTE:
1632 // reference to end-/footnote: format, generate name, (and element)
1633 GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
1634 FIELD_ID_REF_ENDNOTE==nToken ? XML_ENDNOTE : XML_FOOTNOTE );
1635 ProcessString(XML_REFERENCE_FORMAT,
1636 MapReferenceType(GetInt16Property(
1637 gsPropertyReferenceFieldPart, rPropSet)),
1638 XML_TEMPLATE);
1639 ProcessString(XML_REF_NAME,
1640 MakeFootnoteRefName(GetInt16Property(
1641 gsPropertySequenceNumber, rPropSet)));
1642 if (xPropSetInfo->hasPropertyByName(gsPropertyReferenceFieldLanguage) &&
1643 GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
1645 // export text:reference-language attribute, if not empty
1646 ProcessString(XML_REFERENCE_LANGUAGE,
1647 GetStringProperty(gsPropertyReferenceFieldLanguage, rPropSet), true, XML_NAMESPACE_LO_EXT);
1649 ExportElement(
1650 MapReferenceSource(GetInt16Property(
1651 gsPropertyReferenceFieldSource, rPropSet)),
1652 sPresentation);
1653 break;
1655 case FIELD_ID_REF_STYLE:
1657 ProcessString(XML_REFERENCE_FORMAT,
1658 MapReferenceType(GetInt16Property(gsPropertyReferenceFieldPart, rPropSet)),
1659 XML_TEMPLATE);
1660 ProcessString(XML_REF_NAME, GetStringProperty(gsPropertySourceName, rPropSet));
1662 sal_uInt16 referenceFieldFlags = GetIntProperty(gsPropertyReferenceFieldFlags, rPropSet);
1663 // In reality gsPropertyReferenceFieldFlags is a uInt16... but there is no GetUInt16Property
1665 bool fromBottom = (referenceFieldFlags & REFFLDFLAG_STYLE_FROM_BOTTOM) == REFFLDFLAG_STYLE_FROM_BOTTOM;
1666 bool hideNonNumerical = (referenceFieldFlags & REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL) == REFFLDFLAG_STYLE_HIDE_NON_NUMERICAL;
1668 ProcessBoolean(XML_REFERENCE_FROM_BOTTOM, fromBottom, false, XML_NAMESPACE_LO_EXT);
1669 ProcessBoolean(XML_REFERENCE_HIDE_NON_NUMERICAL, hideNonNumerical, false, XML_NAMESPACE_LO_EXT);
1671 if (xPropSetInfo->hasPropertyByName(gsPropertyReferenceFieldLanguage)
1672 && GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
1674 // export text:reference-language attribute, if not empty
1675 ProcessString(XML_REFERENCE_LANGUAGE,
1676 GetStringProperty(gsPropertyReferenceFieldLanguage, rPropSet), true,
1677 XML_NAMESPACE_LO_EXT);
1679 SvXMLElementExport aElem(
1680 GetExport(),
1681 XML_NAMESPACE_LO_EXT,
1682 MapReferenceSource(GetInt16Property(gsPropertyReferenceFieldSource, rPropSet)),
1683 false,
1684 false);
1685 GetExport().Characters(sPresentation);
1686 break;
1689 case FIELD_ID_DDE:
1690 // name from field master
1691 ProcessString(XML_CONNECTION_NAME,
1693 GetStringProperty(gsPropertyName,
1694 GetMasterPropertySet(rTextField)));
1695 ExportElement(XML_DDE_CONNECTION, sPresentation);
1696 break;
1698 case FIELD_ID_SHEET_NAME:
1699 // name of spreadsheet (Calc only)
1700 ExportElement(XML_SHEET_NAME, sPresentation);
1701 break;
1703 case FIELD_ID_PAGENAME:
1705 if (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)
1707 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_LO_EXT, XML_PAGE_NAME, false, false );
1708 GetExport().Characters( sPresentation );
1710 break;
1713 case FIELD_ID_URL:
1715 // this field is a special case because it gets mapped onto a
1716 // hyperlink, rather than one of the regular text field.
1717 ProcessString(XML_HREF, GetExport().GetRelativeReference(GetStringProperty(gsPropertyURL, rPropSet)),
1718 false, XML_NAMESPACE_XLINK);
1719 ProcessString(XML_TARGET_FRAME_NAME,
1720 GetStringProperty(gsPropertyTargetFrame,rPropSet),
1721 true, XML_NAMESPACE_OFFICE);
1722 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
1723 SvXMLElementExport aUrlField(rExport, XML_NAMESPACE_TEXT, XML_A,
1724 false, false);
1725 GetExport().Characters(sPresentation);
1726 break;
1729 case FIELD_ID_BIBLIOGRAPHY:
1731 ProcessBibliographyData(rPropSet);
1732 ExportElement(XML_BIBLIOGRAPHY_MARK, sPresentation);
1733 break;
1736 case FIELD_ID_SCRIPT:
1737 ProcessString(XML_LANGUAGE,
1738 GetStringProperty(gsPropertyScriptType, rPropSet),
1739 true, XML_NAMESPACE_SCRIPT);
1740 DBG_ASSERT(sPresentation.isEmpty(),
1741 "Unexpected presentation for script field");
1742 if (GetBoolProperty(gsPropertyURLContent, rPropSet))
1744 ProcessString(XML_HREF,
1745 GetExport().GetRelativeReference(GetStringProperty(gsPropertyContent, rPropSet)),
1746 false, XML_NAMESPACE_XLINK);
1747 ExportElement(XML_SCRIPT);
1749 else
1751 ExportElement(XML_SCRIPT,
1752 GetStringProperty(gsPropertyContent, rPropSet));
1754 break;
1756 case FIELD_ID_ANNOTATION:
1758 // check for empty presentation (just in case)
1759 DBG_ASSERT(sPresentation.isEmpty(),
1760 "Unexpected presentation for annotation field");
1762 bool bRemovePersonalInfo = SvtSecurityOptions::IsOptionSet(
1763 SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo ) && !SvtSecurityOptions::IsOptionSet(
1764 SvtSecurityOptions::EOption::DocWarnKeepNoteAuthorDateInfo);
1766 // annotation element + content
1767 OUString aName;
1768 rPropSet->getPropertyValue(gsPropertyName) >>= aName;
1769 if (!aName.isEmpty())
1771 GetExport().AddAttribute(XML_NAMESPACE_OFFICE, XML_NAME, aName);
1774 OUString aParentName;
1775 rPropSet->getPropertyValue(gsPropertyParentName) >>= aParentName;
1776 if (!aParentName.isEmpty())
1778 GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_PARENT_NAME, aParentName);
1781 SvtSaveOptions::ODFSaneDefaultVersion eVersion = rExport.getSaneDefaultVersion();
1782 if (eVersion & SvtSaveOptions::ODFSVER_EXTENDED)
1784 bool b = GetBoolProperty("Resolved", rPropSet);
1785 OUString aResolvedText;
1786 OUStringBuffer aResolvedTextBuffer;
1787 ::sax::Converter::convertBool(aResolvedTextBuffer, b);
1788 aResolvedText = aResolvedTextBuffer.makeStringAndClear();
1790 GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_RESOLVED, aResolvedText);
1792 SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_OFFICE,
1793 XML_ANNOTATION, false, true);
1795 // author
1796 OUString aAuthor( GetStringProperty(gsPropertyAuthor, rPropSet) );
1797 if( !aAuthor.isEmpty() )
1799 SvXMLElementExport aCreatorElem( GetExport(), XML_NAMESPACE_DC,
1800 XML_CREATOR, true,
1801 false );
1802 GetExport().Characters( bRemovePersonalInfo
1803 ? "Author" + OUString::number( rExport.GetInfoID(aAuthor) )
1804 : aAuthor );
1807 // date time
1808 util::DateTime aDate( GetDateTimeProperty(gsPropertyDateTimeValue, rPropSet) );
1809 if ( !bRemovePersonalInfo )
1811 OUStringBuffer aBuffer;
1812 ::sax::Converter::convertDateTime(aBuffer, aDate, nullptr, true);
1813 SvXMLElementExport aDateElem( GetExport(), XML_NAMESPACE_DC,
1814 XML_DATE, true,
1815 false );
1816 GetExport().Characters(aBuffer.makeStringAndClear());
1819 if (GetExport().getSaneDefaultVersion() > SvtSaveOptions::ODFSVER_012)
1821 // initials
1822 OUString aInitials( GetStringProperty(gsPropertyInitials, rPropSet) );
1823 if( !aInitials.isEmpty() )
1825 // ODF 1.3 OFFICE-3776 export meta:creator-initials for ODF 1.3
1826 SvXMLElementExport aCreatorElem( GetExport(),
1827 (SvtSaveOptions::ODFSVER_013 <= GetExport().getSaneDefaultVersion())
1828 ? XML_NAMESPACE_META
1829 : XML_NAMESPACE_LO_EXT,
1831 (SvtSaveOptions::ODFSVER_013 <= GetExport().getSaneDefaultVersion())
1832 ? XML_CREATOR_INITIALS
1833 : XML_SENDER_INITIALS,
1834 true, false );
1835 GetExport().Characters( bRemovePersonalInfo
1836 ? OUString::number( rExport.GetInfoID(aInitials) )
1837 : aInitials);
1841 css::uno::Reference < css::text::XText > xText;
1844 css::uno::Any aRet = rPropSet->getPropertyValue(gsPropertyTextRange);
1845 aRet >>= xText;
1847 catch ( css::uno::Exception& )
1850 if ( xText.is() )
1851 GetExport().GetTextParagraphExport()->exportText( xText );
1852 else
1853 ProcessParagraphSequence(GetStringProperty(gsPropertyContent,rPropSet));
1854 break;
1857 case FIELD_ID_COMBINED_CHARACTERS:
1859 // The style with the combined characters attribute has
1860 // already been handled in the ExportField method. So all that
1861 // is left to do now is to export the characters.
1862 GetExport().Characters(sPresentation);
1863 break;
1866 case FIELD_ID_META:
1868 ExportMetaField(rPropSet, false, bProgress, rPrevCharIsSpace);
1869 break;
1872 case FIELD_ID_MEASURE:
1874 ProcessString(XML_KIND, MapMeasureKind(GetInt16Property(gsPropertyMeasureKind, rPropSet)));
1875 ExportElement( XML_MEASURE, sPresentation );
1876 break;
1879 case FIELD_ID_TABLE_FORMULA:
1880 ProcessString( XML_FORMULA, XML_NAMESPACE_OOOW,
1881 GetStringProperty(gsPropertyContent, rPropSet) );
1882 ProcessDisplay( true,
1883 GetBoolProperty(gsPropertyIsShowFormula, rPropSet) );
1884 ProcessValueAndType( false,
1885 GetIntProperty(gsPropertyNumberFormat, rPropSet),
1886 "", u"", 0.0f,
1887 false, false, true,
1888 false );
1889 ExportElement( XML_TABLE_FORMULA, sPresentation );
1890 break;
1892 case FIELD_ID_DROP_DOWN:
1894 // tdf#133555 don't export in strict ODF versions that don't have it
1895 if (GetExport().getSaneDefaultVersion() <= SvtSaveOptions::ODFSVER_012)
1897 break;
1899 ProcessString(XML_NAME, GetStringProperty(gsPropertyName, rPropSet));
1900 ProcessString(XML_HELP,
1901 GetStringProperty(gsPropertyHelp, rPropSet), true);
1902 ProcessString(XML_HINT,
1903 GetStringProperty(gsPropertyTooltip, rPropSet), true);
1904 SvXMLElementExport aElem( GetExport(),
1905 XML_NAMESPACE_TEXT, XML_DROP_DOWN,
1906 false, false );
1907 ProcessStringSequence
1908 (GetStringSequenceProperty( gsPropertyItems, rPropSet ),
1909 GetStringProperty( gsPropertySelectedItem, rPropSet ) );
1911 GetExport().Characters( sPresentation );
1913 break;
1915 case FIELD_ID_DRAW_HEADER:
1917 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_HEADER, false, false );
1919 break;
1921 case FIELD_ID_DRAW_FOOTER:
1923 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_FOOTER, false, false );
1925 break;
1927 case FIELD_ID_DRAW_DATE_TIME:
1929 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_DATE_TIME, false, false );
1931 break;
1934 case FIELD_ID_UNKNOWN:
1935 default:
1936 OSL_FAIL("unknown field type encountered!");
1937 // always export content
1938 GetExport().Characters(sPresentation);
1943 /// export field declarations / field masters
1944 void XMLTextFieldExport::ExportFieldDeclarations()
1946 Reference<XText> xEmptyText;
1947 ExportFieldDeclarations(xEmptyText);
1950 /// export field declarations / field masters
1951 void XMLTextFieldExport::ExportFieldDeclarations(
1952 const Reference<XText> & rText )
1954 // store lists for decl elements
1955 std::vector<OUString> aVarName;
1956 std::vector<OUString> aUserName;
1957 std::vector<OUString> aSeqName;
1958 std::vector<OUString> aDdeName;
1960 // get text fields supplier and field master name access
1961 Reference<XTextFieldsSupplier> xTextFieldsSupp(GetExport().GetModel(),
1962 UNO_QUERY);
1963 if( !xTextFieldsSupp.is() )
1964 return;
1966 Reference<container::XNameAccess> xFieldMasterNameAccess =
1967 xTextFieldsSupp->getTextFieldMasters();
1969 // where to get the text field masters from?
1970 // a) we get a specific XText: then use pUsedMasters
1971 // b) the XText is empty: then export all text fields
1972 Sequence<OUString> aFieldMasters;
1973 if (rText.is())
1975 // export only used masters
1976 DBG_ASSERT(nullptr != pUsedMasters,
1977 "field masters must be recorded in order to be "
1978 "written out separately" );
1979 if (nullptr != pUsedMasters)
1981 std::map<Reference<XText>, std::set<OUString> > ::iterator aMapIter =
1982 pUsedMasters->find(rText);
1983 if (aMapIter != pUsedMasters->end())
1985 // found the set of used field masters
1986 aFieldMasters = comphelper::containerToSequence(aMapIter->second);
1987 pUsedMasters->erase(rText);
1989 // else: XText not found -> ignore
1991 // else: no field masters have been recorded -> ignore
1993 else
1995 // no XText: export all!
1996 aFieldMasters = xFieldMasterNameAccess->getElementNames();
1999 for(const OUString& sFieldMaster : std::as_const(aFieldMasters)) {
2001 // workaround for #no-bug#
2002 if ( sFieldMaster.startsWithIgnoreAsciiCase(
2003 "com.sun.star.text.FieldMaster.DataBase.") )
2005 continue;
2009 OUString sFieldMasterType;
2010 OUString sVarName;
2011 ExplodeFieldMasterName(sFieldMaster, sFieldMasterType, sVarName);
2013 // get XPropertySet of this field master
2014 Reference<XPropertySet> xPropSet;
2015 Any aAny = xFieldMasterNameAccess->getByName(sFieldMaster);
2016 aAny >>= xPropSet;
2018 // save interesting field masters
2019 if (sFieldMasterType == FIELD_SERVICE_SETEXP)
2021 sal_Int32 nType = GetIntProperty(gsPropertySubType, xPropSet);
2023 // sequence or variable?
2024 if ( SetVariableType::SEQUENCE == nType )
2026 aSeqName.push_back( sFieldMaster );
2028 else
2030 aVarName.push_back( sFieldMaster );
2033 else if (sFieldMasterType == FIELD_SERVICE_USER)
2035 aUserName.push_back( sFieldMaster );
2037 else if (sFieldMasterType == FIELD_SERVICE_DDE)
2039 aDdeName.push_back( sFieldMaster );
2041 else
2043 ; // ignore
2047 // now process fields:
2049 // variable field masters:
2050 if ( !aVarName.empty() )
2052 SvXMLElementExport aElem( GetExport(),
2053 XML_NAMESPACE_TEXT,
2054 XML_VARIABLE_DECLS,
2055 true, true );
2057 for (const auto& sName : aVarName)
2059 // get field master property set
2060 Reference<XPropertySet> xPropSet;
2061 Any aAny = xFieldMasterNameAccess->getByName(sName);
2062 aAny >>= xPropSet;
2064 // field name and type
2065 OUString sFieldMasterType;
2066 OUString sVarName;
2067 ExplodeFieldMasterName(sName, sFieldMasterType, sVarName);
2069 // determine string/numeric field
2070 bool bIsString = ( GetIntProperty(gsPropertySubType, xPropSet)
2071 == SetVariableType::STRING );
2073 // get dependent field property set
2074 Reference<XPropertySet> xFieldPropSet;
2075 if (GetDependentFieldPropertySet(xPropSet, xFieldPropSet))
2077 // process value and type.
2078 ProcessValueAndType(
2079 bIsString,
2080 GetIntProperty(gsPropertyNumberFormat, xFieldPropSet),
2081 "", u"", 0.0,
2082 false, true, false, false);
2084 else
2086 // If no dependent field is found, only string and
2087 // float types can be supported
2089 // number format: 0 is default number format for 1st
2090 // language. should be: getDefaultNumberFormat(Locale)
2091 // from NumberFormats
2092 ProcessValueAndType(
2093 bIsString,
2094 0, "", u"", 0.0,
2095 false, true, false, false);
2098 ProcessString(XML_NAME, sVarName);
2099 ExportElement(XML_VARIABLE_DECL, true);
2102 // else: no declarations element
2104 // sequence field masters:
2105 if ( !aSeqName.empty() )
2107 SvXMLElementExport aElem( GetExport(),
2108 XML_NAMESPACE_TEXT,
2109 XML_SEQUENCE_DECLS,
2110 true, true );
2112 for (const auto& sName : aSeqName)
2114 // get field master property set
2115 Reference<XPropertySet> xPropSet;
2116 Any aAny = xFieldMasterNameAccess->getByName(sName);
2117 aAny >>= xPropSet;
2119 // field name and type
2120 OUString sFieldMasterType;
2121 OUString sVarName;
2122 ExplodeFieldMasterName(sName, sFieldMasterType, sVarName);
2124 // outline level
2125 sal_Int32 nLevel = 1 + GetIntProperty(
2126 gsPropertyChapterNumberingLevel, xPropSet);
2127 DBG_ASSERT(nLevel >= 0, "illegal outline level");
2128 DBG_ASSERT(nLevel < 127, "possible illegal outline level");
2129 ProcessInteger(XML_DISPLAY_OUTLINE_LEVEL, nLevel);
2131 // separation character
2132 if (nLevel > 0) {
2133 ProcessString(XML_SEPARATION_CHARACTER, GetStringProperty(
2134 gsPropertyNumberingSeparator, xPropSet));
2136 ProcessString(XML_NAME, sVarName);
2137 ExportElement(XML_SEQUENCE_DECL, true);
2140 // else: no declarations element
2142 // user field masters:
2143 if ( !aUserName.empty() )
2145 SvXMLElementExport aElem( GetExport(),
2146 XML_NAMESPACE_TEXT,
2147 XML_USER_FIELD_DECLS,
2148 true, true );
2150 for (const auto& sName : aUserName)
2152 // get field master property set
2153 Reference<XPropertySet> xPropSet;
2154 Any aAny = xFieldMasterNameAccess->getByName(sName);
2155 aAny >>= xPropSet;
2157 // field name and type
2158 OUString sFieldMasterType;
2159 OUString sVarName;
2160 ExplodeFieldMasterName(sName, sFieldMasterType, sVarName);
2162 if (GetBoolProperty(gsPropertyIsExpression, xPropSet))
2164 // expression:
2165 ProcessValueAndType(
2166 false,
2167 0, "", u"",
2168 GetDoubleProperty(gsPropertyValue, xPropSet),
2169 true,
2170 true,
2171 false,
2172 false);
2174 else
2176 // string: write regardless of default
2177 ProcessString(XML_VALUE_TYPE, XML_STRING,
2178 XML_NAMESPACE_OFFICE);
2179 ProcessString(XML_STRING_VALUE,
2180 GetStringProperty(gsPropertyContent, xPropSet),
2181 false, XML_NAMESPACE_OFFICE );
2183 ProcessString(XML_NAME, sVarName);
2184 ExportElement(XML_USER_FIELD_DECL, true);
2187 // else: no declarations element
2189 // DDE field masters:
2190 if ( aDdeName.empty() )
2191 return;
2193 SvXMLElementExport aElem( GetExport(),
2194 XML_NAMESPACE_TEXT,
2195 XML_DDE_CONNECTION_DECLS,
2196 true, true );
2198 for (const auto& sName : aDdeName)
2200 // get field master property set
2201 Reference<XPropertySet> xPropSet;
2202 Any aAny = xFieldMasterNameAccess->getByName(sName);
2203 aAny >>= xPropSet;
2205 // check if this connection is being used by a field
2206 Reference<XPropertySet> xDummy;
2207 if (GetDependentFieldPropertySet(xPropSet, xDummy))
2210 ProcessString(XML_NAME,
2211 GetStringProperty(gsPropertyName, xPropSet),
2212 false, XML_NAMESPACE_OFFICE);
2214 // export elements; can't use ProcessString because
2215 // elements are in office namespace
2216 ProcessString(XML_DDE_APPLICATION,
2217 GetStringProperty(gsPropertyDDECommandType,
2218 xPropSet),
2219 false, XML_NAMESPACE_OFFICE);
2220 ProcessString(XML_DDE_TOPIC,
2221 GetStringProperty(gsPropertyDDECommandFile,
2222 xPropSet),
2223 false, XML_NAMESPACE_OFFICE);
2224 ProcessString(XML_DDE_ITEM,
2225 GetStringProperty(gsPropertyDDECommandElement,
2226 xPropSet),
2227 false, XML_NAMESPACE_OFFICE);
2228 bool bIsAutomaticUpdate = GetBoolProperty(
2229 gsPropertyIsAutomaticUpdate, xPropSet);
2230 if (bIsAutomaticUpdate)
2232 GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
2233 XML_AUTOMATIC_UPDATE,
2234 XML_TRUE);
2237 ExportElement(XML_DDE_CONNECTION_DECL, true);
2239 // else: no dependent field -> no export of field declaration
2241 // else: no declarations element
2244 void XMLTextFieldExport::SetExportOnlyUsedFieldDeclarations(
2245 bool bExportOnlyUsed)
2247 pUsedMasters.reset();
2249 // create used masters set (if none is used)
2250 if (bExportOnlyUsed)
2251 pUsedMasters.reset( new std::map<Reference<XText>, std::set<OUString> > );
2254 void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
2255 bool bAddSpace)
2257 // can't call ExportElement(eElementName, const OUString&) with empty
2258 // string because xmlprinter only uses empty tags if no content
2259 // (not even empty content) was written.
2261 DBG_ASSERT(XML_TOKEN_INVALID != eElementName, "invalid element name!");
2262 if (XML_TOKEN_INVALID != eElementName)
2264 // Element
2265 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
2266 eElementName, bAddSpace, bAddSpace );
2267 } // else: ignore
2270 void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
2271 const OUString& sContent)
2273 DBG_ASSERT(eElementName != XML_TOKEN_INVALID, "invalid element name!");
2274 if (eElementName != XML_TOKEN_INVALID)
2276 // Element
2277 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
2278 eElementName, false, false );
2279 // export content
2280 GetExport().Characters(sContent);
2281 } else {
2282 // always export content
2283 GetExport().Characters(sContent);
2287 void XMLTextFieldExport::ExportMacro(
2288 const Reference<XPropertySet> & rPropSet,
2289 const OUString& rContent )
2291 // some strings we'll need
2292 OUString sEventType( "EventType" );
2295 // the description attribute
2296 ProcessString(XML_DESCRIPTION,
2297 GetStringProperty(gsPropertyHint, rPropSet),
2298 rContent);
2300 // the element
2301 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
2302 XML_EXECUTE_MACRO, false, false );
2304 // the <office:events>-macro:
2306 // 1) build sequence of PropertyValues
2307 Sequence<PropertyValue> aSeq;
2308 OUString sName;
2309 rPropSet->getPropertyValue("ScriptURL") >>= sName;
2311 // if the ScriptURL property is not empty then this is a Scripting
2312 // Framework URL, otherwise treat it as a Basic Macro
2313 if (!sName.isEmpty())
2315 OUString sScript( "Script" );
2316 aSeq = Sequence<PropertyValue>
2318 comphelper::makePropertyValue(sEventType, sScript),
2319 comphelper::makePropertyValue(sScript, sName)
2322 else
2324 aSeq = Sequence<PropertyValue>
2326 comphelper::makePropertyValue(sEventType, OUString("StarBasic")),
2327 comphelper::makePropertyValue("Library", rPropSet->getPropertyValue( "MacroLibrary" )),
2328 comphelper::makePropertyValue("MacroName", rPropSet->getPropertyValue( "MacroName" ))
2332 // 2) export the sequence
2333 GetExport().GetEventExport().ExportSingleEvent( aSeq, "OnClick", false );
2335 // and finally, the field presentation
2336 GetExport().Characters(rContent);
2339 void XMLTextFieldExport::ExportMetaField(
2340 const Reference<XPropertySet> & i_xMeta,
2341 bool i_bAutoStyles, bool i_bProgress,
2342 bool & rPrevCharIsSpace)
2344 bool doExport(!i_bAutoStyles); // do not export element if autostyles
2345 // check version >= 1.2
2346 switch (GetExport().getSaneDefaultVersion()) {
2347 case SvtSaveOptions::ODFSVER_011: // fall through
2348 case SvtSaveOptions::ODFSVER_010: doExport = false; break;
2349 default: break;
2352 const Reference < XEnumerationAccess > xEA( i_xMeta, UNO_QUERY_THROW );
2353 const Reference < XEnumeration > xTextEnum( xEA->createEnumeration() );
2355 if (doExport)
2357 const Reference<rdf::XMetadatable> xMeta( i_xMeta, UNO_QUERY_THROW );
2359 // style:data-style-name
2360 ProcessValueAndType(false,
2361 GetIntProperty(gsPropertyNumberFormat, i_xMeta),
2362 "", u"", 0.0, false, false, true,
2363 false );
2365 // text:meta-field without xml:id is invalid
2366 xMeta->ensureMetadataReference();
2368 // xml:id for RDF metadata
2369 GetExport().AddAttributeXmlId(xMeta);
2372 SvXMLElementExport aElem( GetExport(), doExport,
2373 XML_NAMESPACE_TEXT, XML_META_FIELD, false, false );
2375 // recurse to export content
2376 GetExport().GetTextParagraphExport()->
2377 exportTextRangeEnumeration(xTextEnum, i_bAutoStyles, i_bProgress, rPrevCharIsSpace);
2380 /// export all data-style related attributes
2381 void XMLTextFieldExport::ProcessValueAndType(
2382 bool bIsString, /// do we process a string or a number?
2383 sal_Int32 nFormatKey, /// format key for NumberFormatter; inv. if string
2384 const OUString& sContent, /// string content; possibly invalid
2385 std::u16string_view sDefault, /// default string
2386 double fValue, /// float content; possibly invalid
2387 bool bExportValue, /// export value attribute?
2388 bool bExportValueType, /// export value-type attribute?
2389 bool bExportStyle, /// export style-attribute?
2390 bool bForceSystemLanguage, /// export language attributes?
2391 bool bTimeStyle) // exporting a time style?
2393 // String or number?
2394 if (bIsString)
2397 // string: attributes value-type=string, string-value=...
2399 if (bExportValue || bExportValueType)
2401 XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
2402 GetExport(), sContent, sDefault, bExportValue);
2406 else
2409 // number: value-type=..., value...=..., data-style-name=...
2411 DBG_ASSERT(bExportValueType || !bExportValue, "value w/o value type not supported!");
2413 // take care of illegal formats
2414 // (shouldn't happen, but does if document is corrupted)
2415 if (-1 != nFormatKey)
2417 if (bExportValue || bExportValueType)
2419 XMLNumberFormatAttributesExportHelper::
2420 SetNumberFormatAttributes(
2421 GetExport(), nFormatKey, fValue, bExportValue);
2424 if (bExportStyle)
2426 // don't export language (if desired)
2427 if( bForceSystemLanguage )
2428 nFormatKey =
2429 GetExport().dataStyleForceSystemLanguage( nFormatKey );
2431 OUString sDataStyleName =
2432 GetExport().getDataStyleName(nFormatKey, bTimeStyle);
2433 if( !sDataStyleName.isEmpty() )
2435 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
2436 XML_DATA_STYLE_NAME,
2437 sDataStyleName );
2438 } // else: ignore (no valid number format)
2439 } // else: ignore (no number format)
2445 /// process display related properties
2446 void XMLTextFieldExport::ProcessDisplay(bool bIsVisible,
2447 bool bIsCommand)
2449 enum XMLTokenEnum eValue;
2451 if (bIsVisible)
2453 eValue = bIsCommand ? XML_FORMULA : XML_VALUE;
2455 else
2457 eValue = XML_NONE;
2460 // omit attribute if default
2461 if (eValue != XML_VALUE)
2463 GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eValue);
2468 void XMLTextFieldExport::ProcessBoolean(enum XMLTokenEnum eName,
2469 bool bBool, bool bDefault)
2471 ProcessBoolean(eName, bBool, bDefault, XML_NAMESPACE_TEXT);
2474 /// export boolean property
2475 void XMLTextFieldExport::ProcessBoolean(enum XMLTokenEnum eName,
2476 bool bBool, bool bDefault, sal_uInt16 nPrefix)
2478 SAL_WARN_IF( eName == XML_TOKEN_INVALID, "xmloff.text", "invalid element token");
2479 if ( XML_TOKEN_INVALID == eName )
2480 return;
2482 // write attribute (if different than default)
2483 // negate to force 0/1 values (and make sal_Bool comparable)
2484 if ((!bBool) != (!bDefault)) {
2485 GetExport().AddAttribute(nPrefix, eName,
2486 (bBool ? XML_TRUE : XML_FALSE) );
2490 /// export string attribute
2491 void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
2492 const OUString& sValue,
2493 bool bOmitEmpty,
2494 sal_uInt16 nPrefix)
2496 SAL_WARN_IF( eName == XML_TOKEN_INVALID, "xmloff.text", "invalid element token");
2497 if ( XML_TOKEN_INVALID == eName )
2498 return;
2500 // check for empty string, if applicable
2501 if ( bOmitEmpty && sValue.isEmpty() )
2502 return;
2504 // write attribute
2505 GetExport().AddAttribute(nPrefix, eName, sValue);
2508 void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
2509 sal_uInt16 nValuePrefix,
2510 const OUString& sValue)
2512 OUString sQValue =
2513 GetExport().GetNamespaceMap().GetQNameByKey( nValuePrefix, sValue, false );
2514 ProcessString( eName, sQValue );
2517 /// export a string attribute
2518 void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
2519 const OUString& sValue,
2520 std::u16string_view sDefault)
2522 if (sValue != sDefault)
2524 ProcessString(eName, sValue);
2528 /// export a string attribute
2529 void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
2530 sal_uInt16 nValuePrefix,
2531 const OUString& sValue,
2532 std::u16string_view sDefault)
2534 if (sValue != sDefault)
2536 ProcessString(eName, nValuePrefix, sValue);
2541 /// export string attribute
2542 void XMLTextFieldExport::ProcessString(
2543 enum XMLTokenEnum eName,
2544 enum XMLTokenEnum eValue,
2545 sal_uInt16 nPrefix)
2547 SAL_WARN_IF( eName == XML_TOKEN_INVALID, "xmloff.text", "invalid element token" );
2548 SAL_WARN_IF( eValue == XML_TOKEN_INVALID, "xmloff.text", "invalid value token" );
2549 if ( XML_TOKEN_INVALID == eName )
2550 return;
2552 GetExport().AddAttribute(nPrefix, eName, eValue);
2555 /// export a string attribute
2556 void XMLTextFieldExport::ProcessString(
2557 enum XMLTokenEnum eName,
2558 enum XMLTokenEnum eValue,
2559 enum XMLTokenEnum eDefault)
2561 if ( eValue != eDefault )
2562 ProcessString( eName, eValue);
2566 /// export a string as a sequence of paragraphs
2567 void XMLTextFieldExport::ProcessParagraphSequence(
2568 std::u16string_view sParagraphSequence)
2570 // iterate over all string-pieces separated by return (0x0a) and
2571 // put each inside a paragraph element.
2572 SvXMLTokenEnumerator aEnumerator(sParagraphSequence, char(0x0a));
2573 std::u16string_view aSubString;
2574 while (aEnumerator.getNextToken(aSubString))
2576 SvXMLElementExport aParagraph(
2577 GetExport(), XML_NAMESPACE_TEXT, XML_P, true, false);
2578 GetExport().Characters(OUString(aSubString));
2582 // export an integer attribute
2583 void XMLTextFieldExport::ProcessInteger(enum XMLTokenEnum eName,
2584 sal_Int32 nNum)
2586 SAL_WARN_IF( eName == XML_TOKEN_INVALID, "xmloff.text", "invalid element token");
2587 if ( XML_TOKEN_INVALID == eName )
2588 return;
2590 GetExport().AddAttribute(XML_NAMESPACE_TEXT, eName,
2591 OUString::number(nNum));
2594 /// export an integer attribute, omit if default
2595 void XMLTextFieldExport::ProcessIntegerDef(enum XMLTokenEnum eName,
2596 sal_Int32 nNum, sal_Int32 nDefault)
2598 if (nNum != nDefault)
2599 ProcessInteger(eName, nNum);
2603 /// export a numbering type
2604 void XMLTextFieldExport::ProcessNumberingType(sal_Int16 nNumberingType)
2606 // process only if real format (not: like page descriptor)
2607 if (NumberingType::PAGE_DESCRIPTOR == nNumberingType)
2608 return;
2610 OUStringBuffer sTmp( 10 );
2611 // number type: num format
2612 GetExport().GetMM100UnitConverter().convertNumFormat( sTmp,
2613 nNumberingType );
2614 GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
2615 sTmp.makeStringAndClear() );
2616 // and letter sync, if applicable
2617 SvXMLUnitConverter::convertNumLetterSync( sTmp, nNumberingType );
2619 if (!sTmp.isEmpty())
2621 GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
2622 sTmp.makeStringAndClear() );
2624 // else: like page descriptor => ignore
2628 /// export a date, time, or duration
2629 void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
2630 double dValue,
2631 bool bIsDate,
2632 bool bIsDuration,
2633 bool bOmitDurationIfZero,
2634 sal_uInt16 nPrefix)
2636 // truncate for date granularity
2637 if (bIsDate)
2639 dValue = ::rtl::math::approxFloor(dValue);
2642 OUStringBuffer aBuffer;
2643 if (bIsDuration)
2645 // date/time duration handle bOmitDurationIfZero
2646 if (!bOmitDurationIfZero || dValue != 0.0)
2648 ::sax::Converter::convertDuration(aBuffer, dValue);
2651 else
2653 // date/time value
2654 rExport.GetMM100UnitConverter().convertDateTime(aBuffer, dValue);
2657 // output attribute
2658 ProcessString(eName, aBuffer.makeStringAndClear(), true, nPrefix);
2661 /// export a date or time
2662 void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
2663 const util::DateTime& rTime)
2665 OUStringBuffer aBuffer;
2667 util::DateTime aDateTime(rTime);
2669 // date/time value
2670 ::sax::Converter::convertDateTime(aBuffer, aDateTime, nullptr);
2672 // output attribute
2673 ProcessString(eName, aBuffer.makeStringAndClear(), true);
2676 /// export a date, time, or duration
2677 void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
2678 sal_Int32 nMinutes,
2679 bool bIsDate,
2680 bool bIsDuration)
2682 // handle bOmitDurationIfZero here, because we can precisely compare ints
2683 if (!(bIsDuration && (nMinutes==0)))
2685 ProcessDateTime(eName, static_cast<double>(nMinutes) / double(24*60),
2686 bIsDate, bIsDuration);
2690 /// export a time or dateTime
2691 void XMLTextFieldExport::ProcessTimeOrDateTime(enum XMLTokenEnum eName,
2692 const util::DateTime& rTime)
2694 OUStringBuffer aBuffer;
2696 // date/time value
2697 ::sax::Converter::convertTimeOrDateTime(aBuffer, rTime);
2699 // output attribute
2700 ProcessString(eName, aBuffer.makeStringAndClear(), true);
2704 SvXMLEnumMapEntry<sal_Int16> const aBibliographyDataTypeMap[] =
2706 { XML_ARTICLE, BibliographyDataType::ARTICLE },
2707 { XML_BOOK, BibliographyDataType::BOOK },
2708 { XML_BOOKLET, BibliographyDataType::BOOKLET },
2709 { XML_CONFERENCE, BibliographyDataType::CONFERENCE },
2710 { XML_CUSTOM1, BibliographyDataType::CUSTOM1 },
2711 { XML_CUSTOM2, BibliographyDataType::CUSTOM2 },
2712 { XML_CUSTOM3, BibliographyDataType::CUSTOM3 },
2713 { XML_CUSTOM4, BibliographyDataType::CUSTOM4 },
2714 { XML_CUSTOM5, BibliographyDataType::CUSTOM5 },
2715 { XML_EMAIL, BibliographyDataType::EMAIL },
2716 { XML_INBOOK, BibliographyDataType::INBOOK },
2717 { XML_INCOLLECTION, BibliographyDataType::INCOLLECTION },
2718 { XML_INPROCEEDINGS, BibliographyDataType::INPROCEEDINGS },
2719 { XML_JOURNAL, BibliographyDataType::JOURNAL },
2720 { XML_MANUAL, BibliographyDataType::MANUAL },
2721 { XML_MASTERSTHESIS, BibliographyDataType::MASTERSTHESIS },
2722 { XML_MISC, BibliographyDataType::MISC },
2723 { XML_PHDTHESIS, BibliographyDataType::PHDTHESIS },
2724 { XML_PROCEEDINGS, BibliographyDataType::PROCEEDINGS },
2725 { XML_TECHREPORT, BibliographyDataType::TECHREPORT },
2726 { XML_UNPUBLISHED, BibliographyDataType::UNPUBLISHED },
2727 { XML_WWW, BibliographyDataType::WWW },
2728 { XML_TOKEN_INVALID, 0 }
2732 void XMLTextFieldExport::ProcessBibliographyData(
2733 const Reference<XPropertySet>& rPropSet)
2735 // get the values
2736 Any aAny = rPropSet->getPropertyValue(gsPropertyFields);
2737 Sequence<PropertyValue> aValues;
2738 aAny >>= aValues;
2740 // one attribute per value (unless empty)
2741 for (const auto& rProp : std::as_const(aValues))
2743 if( rProp.Name == "BibiliographicType" )
2745 sal_Int16 nTypeId = 0;
2746 rProp.Value >>= nTypeId;
2747 OUStringBuffer sBuf;
2749 if (SvXMLUnitConverter::convertEnum(sBuf, nTypeId,
2750 aBibliographyDataTypeMap))
2752 rExport.AddAttribute(XML_NAMESPACE_TEXT,
2753 XML_BIBLIOGRAPHY_TYPE,
2754 sBuf.makeStringAndClear());
2756 // else: ignore this argument
2758 else
2760 OUString sStr;
2761 rProp.Value >>= sStr;
2763 if (!sStr.isEmpty())
2765 XMLTokenEnum eElement = MapBibliographyFieldName(rProp.Name);
2766 if (eElement == XML_URL || eElement == XML_LOCAL_URL || eElement == XML_TARGET_URL)
2768 sStr = GetExport().GetRelativeReference(sStr);
2770 sal_uInt16 nPrefix = XML_NAMESPACE_TEXT;
2771 if (eElement == XML_LOCAL_URL || eElement == XML_TARGET_TYPE
2772 || eElement == XML_TARGET_URL)
2774 nPrefix = XML_NAMESPACE_LO_EXT;
2776 rExport.AddAttribute(nPrefix, eElement, sStr);
2782 /// export CommandTypeAttribute
2783 void XMLTextFieldExport::ProcessCommandType(
2784 sal_Int32 nCommandType)
2786 enum XMLTokenEnum eToken = XML_TOKEN_INVALID;
2787 switch( nCommandType )
2789 case sdb::CommandType::TABLE: eToken = XML_TABLE; break;
2790 case sdb::CommandType::QUERY: eToken = XML_QUERY; break;
2791 case sdb::CommandType::COMMAND: eToken = XML_COMMAND; break;
2794 if( eToken != XML_TOKEN_INVALID )
2795 rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_TABLE_TYPE, eToken );
2799 void XMLTextFieldExport::ProcessStringSequence(
2800 const Sequence<OUString>& rSequence,
2801 const OUString& sSelected )
2803 // find selected element
2804 sal_Int32 nSelected = comphelper::findValue(rSequence, sSelected);
2806 // delegate to ProcessStringSequence(OUString,sal_Int32)
2807 ProcessStringSequence( rSequence, nSelected );
2810 void XMLTextFieldExport::ProcessStringSequence(
2811 const Sequence<OUString>& rSequence,
2812 sal_Int32 nSelected )
2814 sal_Int32 nLength = rSequence.getLength();
2815 const OUString* pSequence = rSequence.getConstArray();
2816 for( sal_Int32 i = 0; i < nLength; i++ )
2818 if( i == nSelected )
2819 rExport.AddAttribute( XML_NAMESPACE_TEXT,
2820 XML_CURRENT_SELECTED, XML_TRUE );
2821 rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_VALUE, pSequence[i] );
2822 SvXMLElementExport aElement( rExport, XML_NAMESPACE_TEXT, XML_LABEL,
2823 false, false );
2827 void XMLTextFieldExport::ExportDataBaseElement(
2828 enum XMLTokenEnum eElementName,
2829 const OUString& sPresentation,
2830 const Reference<XPropertySet>& rPropertySet,
2831 const Reference<XPropertySetInfo>& rPropertySetInfo )
2833 SAL_WARN_IF( eElementName == XML_TOKEN_INVALID, "xmloff.text", "need token" );
2834 SAL_WARN_IF( !rPropertySet.is(), "xmloff.text", "need property set" );
2835 SAL_WARN_IF( !rPropertySetInfo.is(), "xmloff.text", "need property set info" );
2837 // get database properties
2838 OUString sDataBaseName;
2839 OUString sDataBaseURL;
2840 OUString sStr;
2841 if( ( rPropertySet->getPropertyValue( gsPropertyDataBaseName ) >>= sStr )
2842 && !sStr.isEmpty() )
2844 sDataBaseName = sStr;
2846 else if( rPropertySetInfo->hasPropertyByName( gsPropertyDataBaseURL ) &&
2847 (rPropertySet->getPropertyValue( gsPropertyDataBaseURL ) >>= sStr) &&
2848 !sStr.isEmpty() )
2850 sDataBaseURL = sStr;
2853 // add database name property (if present)
2854 if( !sDataBaseName.isEmpty() )
2855 rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_DATABASE_NAME,
2856 sDataBaseName );
2857 SvXMLElementExport aDataBaseElement( GetExport(),
2858 XML_NAMESPACE_TEXT, eElementName,
2859 false, false );
2861 // write URL as children
2862 if( !sDataBaseURL.isEmpty() )
2864 rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sDataBaseURL );
2865 SvXMLElementExport aDataSourceElement(
2866 GetExport(), XML_NAMESPACE_FORM, XML_CONNECTION_RESOURCE,
2867 false, false );
2870 // write presentation
2871 rExport.Characters( sPresentation );
2875 // explode a field master name into field type and field name
2876 void XMLTextFieldExport::ExplodeFieldMasterName(
2877 std::u16string_view sMasterName, OUString& sFieldType, OUString& sVarName)
2879 sal_Int32 nLength = gsFieldMasterPrefix.getLength();
2880 size_t nSeparator = sMasterName.find('.', nLength);
2882 // '.' found?
2883 if (nSeparator == o3tl::make_unsigned(nLength) || nSeparator == std::u16string_view::npos) {
2884 SAL_WARN("xmloff.text", "no field var name!");
2886 else
2888 sFieldType = sMasterName.substr(nLength, nSeparator-nLength);
2889 sVarName = sMasterName.substr(nSeparator+1);
2894 // for XDependentTextFields, get PropertySet of FieldMaster
2895 Reference<XPropertySet> XMLTextFieldExport::GetMasterPropertySet(
2896 const Reference<XTextField> & rTextField)
2898 // name, value => get Property set of TextFieldMaster
2899 Reference<XDependentTextField> xDep(rTextField, UNO_QUERY);
2900 return xDep->getTextFieldMaster();
2903 // get PropertySet of (any; the first) dependent field
2904 bool XMLTextFieldExport::GetDependentFieldPropertySet(
2905 const Reference<XPropertySet> & xMaster,
2906 Reference<XPropertySet> & xField)
2908 Any aAny;
2909 Sequence<Reference<XDependentTextField> > aFields;
2910 aAny = xMaster->getPropertyValue(gsPropertyDependentTextFields);
2911 aAny >>= aFields;
2913 // any fields?
2914 if (aFields.hasElements())
2916 // get first one and return
2917 Reference<XDependentTextField> xTField = aFields[0];
2918 xField.set(xTField, UNO_QUERY);
2919 DBG_ASSERT(xField.is(),
2920 "Surprisingly, this TextField refuses to be a PropertySet!");
2921 return true;
2923 else
2925 return false;
2930 /// map placeholder type
2931 enum XMLTokenEnum XMLTextFieldExport::MapPlaceholderType(sal_uInt16 nType)
2933 enum XMLTokenEnum eType = XML_TEXT;
2935 switch (nType)
2937 case PlaceholderType::TEXT:
2938 eType = XML_TEXT;
2939 break;
2941 case PlaceholderType::TABLE:
2942 eType = XML_TABLE;
2943 break;
2945 case PlaceholderType::TEXTFRAME:
2946 eType = XML_TEXT_BOX;
2947 break;
2949 case PlaceholderType::GRAPHIC:
2950 eType = XML_IMAGE;
2951 break;
2953 case PlaceholderType::OBJECT:
2954 eType = XML_OBJECT;
2955 break;
2957 default:
2958 // unknown placeholder: XML_TEXT
2959 OSL_FAIL("unknown placeholder type");
2962 return eType;
2966 /// element name for author fields
2967 enum XMLTokenEnum XMLTextFieldExport::MapAuthorFieldName(
2968 const Reference<XPropertySet> & xPropSet)
2970 // Initials or full name?
2971 return GetBoolProperty(gsPropertyFullName, xPropSet)
2972 ? XML_AUTHOR_NAME : XML_AUTHOR_INITIALS;
2975 enum XMLTokenEnum XMLTextFieldExport::MapPageNumberName(
2976 const Reference<XPropertySet> & xPropSet,
2977 sal_Int32& nOffset)
2979 enum XMLTokenEnum eName = XML_TOKEN_INVALID;
2980 PageNumberType ePage;
2981 Any aAny = xPropSet->getPropertyValue(gsPropertySubType);
2982 ePage = *o3tl::doAccess<PageNumberType>(aAny);
2984 switch (ePage)
2986 case PageNumberType_PREV:
2987 eName = XML_PREVIOUS;
2988 nOffset += 1;
2989 break;
2990 case PageNumberType_CURRENT:
2991 eName = XML_CURRENT;
2992 break;
2993 case PageNumberType_NEXT:
2994 eName = XML_NEXT;
2995 nOffset -= 1;
2996 break;
2997 default:
2998 OSL_FAIL("unknown page number type");
2999 eName = XML_TOKEN_INVALID;
3000 break;
3003 return eName;
3006 /// map TemplateDisplayFormat to XML
3007 enum XMLTokenEnum XMLTextFieldExport::MapTemplateDisplayFormat(sal_Int16 nFormat)
3009 enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3011 switch (nFormat)
3013 case TemplateDisplayFormat::FULL:
3014 eName = XML_FULL;
3015 break;
3016 case TemplateDisplayFormat::PATH:
3017 eName = XML_PATH;
3018 break;
3019 case TemplateDisplayFormat::NAME:
3020 eName = XML_NAME;
3021 break;
3022 case TemplateDisplayFormat::NAME_AND_EXT:
3023 eName = XML_NAME_AND_EXTENSION;
3024 break;
3025 case TemplateDisplayFormat::AREA:
3026 eName = XML_AREA;
3027 break;
3028 case TemplateDisplayFormat::TITLE:
3029 eName = XML_TITLE;
3030 break;
3031 default:
3032 OSL_FAIL("unknown template display format");
3033 eName = XML_TOKEN_INVALID;
3034 break;
3037 return eName;
3040 /// map count/statistics field token to XML name
3041 enum XMLTokenEnum XMLTextFieldExport::MapCountFieldName(FieldIdEnum nToken)
3043 enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
3045 switch (nToken)
3047 case FIELD_ID_COUNT_PAGES:
3048 eElement = XML_PAGE_COUNT;
3049 break;
3050 case FIELD_ID_COUNT_PARAGRAPHS:
3051 eElement = XML_PARAGRAPH_COUNT;
3052 break;
3053 case FIELD_ID_COUNT_WORDS:
3054 eElement = XML_WORD_COUNT;
3055 break;
3056 case FIELD_ID_COUNT_CHARACTERS:
3057 eElement = XML_CHARACTER_COUNT;
3058 break;
3059 case FIELD_ID_COUNT_TABLES:
3060 eElement = XML_TABLE_COUNT;
3061 break;
3062 case FIELD_ID_COUNT_GRAPHICS:
3063 eElement = XML_IMAGE_COUNT;
3064 break;
3065 case FIELD_ID_COUNT_OBJECTS:
3066 eElement = XML_OBJECT_COUNT;
3067 break;
3068 default:
3069 OSL_FAIL("no count field token");
3070 eElement = XML_TOKEN_INVALID;
3071 break;
3074 return eElement;
3077 /// map ChapterDisplayFormat to XML string
3078 enum XMLTokenEnum XMLTextFieldExport::MapChapterDisplayFormat(sal_Int16 nFormat)
3080 enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3082 switch (nFormat)
3084 case ChapterFormat::NAME:
3085 eName = XML_NAME;
3086 break;
3087 case ChapterFormat::NUMBER:
3088 eName = XML_NUMBER;
3089 break;
3090 case ChapterFormat::NAME_NUMBER:
3091 eName = XML_NUMBER_AND_NAME;
3092 break;
3093 case ChapterFormat::NO_PREFIX_SUFFIX:
3094 eName = XML_PLAIN_NUMBER_AND_NAME;
3095 break;
3096 case ChapterFormat::DIGIT:
3097 eName = XML_PLAIN_NUMBER;
3098 break;
3099 default:
3100 OSL_FAIL("unknown chapter display format");
3101 eName = XML_TOKEN_INVALID;
3102 break;
3105 return eName;
3109 /// map FilenameDisplayFormat to XML attribute names
3110 enum XMLTokenEnum XMLTextFieldExport::MapFilenameDisplayFormat(sal_Int16 nFormat)
3112 enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3114 switch (nFormat)
3116 case FilenameDisplayFormat::FULL:
3117 eName = XML_FULL;
3118 break;
3119 case FilenameDisplayFormat::PATH:
3120 eName = XML_PATH;
3121 break;
3122 case FilenameDisplayFormat::NAME:
3123 eName = XML_NAME;
3124 break;
3125 case FilenameDisplayFormat::NAME_AND_EXT:
3126 eName = XML_NAME_AND_EXTENSION;
3127 break;
3128 default:
3129 OSL_FAIL("unknown filename display format");
3132 return eName;
3136 /// map ReferenceFieldPart to XML string
3137 enum XMLTokenEnum XMLTextFieldExport::MapReferenceType(sal_Int16 nType)
3139 enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
3141 switch (nType)
3143 case ReferenceFieldPart::PAGE:
3144 eElement = XML_PAGE;
3145 break;
3146 case ReferenceFieldPart::CHAPTER:
3147 eElement = XML_CHAPTER;
3148 break;
3149 case ReferenceFieldPart::TEXT:
3150 eElement = XML_TEXT;
3151 break;
3152 case ReferenceFieldPart::UP_DOWN:
3153 eElement = XML_DIRECTION;
3154 break;
3155 case ReferenceFieldPart::CATEGORY_AND_NUMBER:
3156 eElement = XML_CATEGORY_AND_VALUE;
3157 break;
3158 case ReferenceFieldPart::ONLY_CAPTION:
3159 eElement = XML_CAPTION;
3160 break;
3161 case ReferenceFieldPart::ONLY_SEQUENCE_NUMBER:
3162 eElement = XML_VALUE;
3163 break;
3164 case ReferenceFieldPart::PAGE_DESC:
3165 // small hack: this value never gets written, because
3166 // XML_TEMPLATE is default
3167 eElement = XML_TEMPLATE;
3168 break;
3169 // Core implementation for direct cross-references (#i81002#)
3170 case ReferenceFieldPart::NUMBER:
3171 eElement = XML_NUMBER;
3172 break;
3173 case ReferenceFieldPart::NUMBER_NO_CONTEXT:
3174 eElement = XML_NUMBER_NO_SUPERIOR;
3175 break;
3176 case ReferenceFieldPart::NUMBER_FULL_CONTEXT:
3177 eElement = XML_NUMBER_ALL_SUPERIOR;
3178 break;
3179 default:
3180 OSL_FAIL("unknown reference type");
3181 eElement = XML_TEMPLATE;
3182 break;
3185 return eElement;
3188 /// map ReferenceFieldPart to XML string
3189 enum XMLTokenEnum XMLTextFieldExport::MapReferenceSource(sal_Int16 nType)
3191 enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
3193 switch (nType)
3195 case ReferenceFieldSource::REFERENCE_MARK:
3196 eElement = XML_REFERENCE_REF;
3197 break;
3198 case ReferenceFieldSource::SEQUENCE_FIELD:
3199 eElement = XML_SEQUENCE_REF;
3200 break;
3201 case ReferenceFieldSource::BOOKMARK:
3202 eElement = XML_BOOKMARK_REF;
3203 break;
3204 case ReferenceFieldSource::FOOTNOTE:
3205 case ReferenceFieldSource::ENDNOTE:
3206 eElement = XML_NOTE_REF;
3207 break;
3208 case ReferenceFieldSource::STYLE:
3209 eElement = XML_STYLE_REF;
3210 break;
3211 default:
3212 OSL_FAIL("unknown reference source");
3213 break;
3216 return eElement;
3220 /// element name for sender fields
3221 enum XMLTokenEnum XMLTextFieldExport::MapSenderFieldName(
3222 const Reference<XPropertySet> & xPropSet)
3224 enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3226 // sub-field type
3227 switch (GetInt16Property(gsPropertyFieldSubType, xPropSet))
3229 case UserDataPart::COMPANY :
3230 eName = XML_SENDER_COMPANY;
3231 break;
3232 case UserDataPart::FIRSTNAME :
3233 eName = XML_SENDER_FIRSTNAME;
3234 break;
3235 case UserDataPart::NAME :
3236 eName = XML_SENDER_LASTNAME;
3237 break;
3238 case UserDataPart::SHORTCUT :
3239 eName = XML_SENDER_INITIALS;
3240 break;
3241 case UserDataPart::STREET :
3242 eName = XML_SENDER_STREET;
3243 break;
3244 case UserDataPart::COUNTRY :
3245 eName = XML_SENDER_COUNTRY;
3246 break;
3247 case UserDataPart::ZIP :
3248 eName = XML_SENDER_POSTAL_CODE;
3249 break;
3250 case UserDataPart::CITY :
3251 eName = XML_SENDER_CITY;
3252 break;
3253 case UserDataPart::TITLE :
3254 eName = XML_SENDER_TITLE;
3255 break;
3256 case UserDataPart::POSITION :
3257 eName = XML_SENDER_POSITION;
3258 break;
3259 case UserDataPart::PHONE_PRIVATE :
3260 eName = XML_SENDER_PHONE_PRIVATE;
3261 break;
3262 case UserDataPart::PHONE_COMPANY :
3263 eName = XML_SENDER_PHONE_WORK;
3264 break;
3265 case UserDataPart::FAX :
3266 eName = XML_SENDER_FAX;
3267 break;
3268 case UserDataPart::EMAIL :
3269 eName = XML_SENDER_EMAIL;
3270 break;
3271 case UserDataPart::STATE :
3272 eName = XML_SENDER_STATE_OR_PROVINCE;
3273 break;
3274 default:
3275 SAL_WARN("xmloff.text", "unknown sender type");
3276 eName = XML_TOKEN_INVALID;
3277 break;
3280 return eName;
3283 enum XMLTokenEnum XMLTextFieldExport::MapDocInfoFieldName(
3284 enum FieldIdEnum nToken)
3286 enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
3288 switch (nToken)
3290 case FIELD_ID_DOCINFO_CREATION_AUTHOR:
3291 eElement = XML_INITIAL_CREATOR;
3292 break;
3293 case FIELD_ID_DOCINFO_CREATION_DATE:
3294 eElement = XML_CREATION_DATE;
3295 break;
3296 case FIELD_ID_DOCINFO_CREATION_TIME:
3297 eElement = XML_CREATION_TIME;
3298 break;
3299 case FIELD_ID_DOCINFO_DESCRIPTION:
3300 eElement = XML_DESCRIPTION;
3301 break;
3302 case FIELD_ID_DOCINFO_PRINT_TIME:
3303 eElement = XML_PRINT_TIME;
3304 break;
3305 case FIELD_ID_DOCINFO_PRINT_DATE:
3306 eElement = XML_PRINT_DATE;
3307 break;
3308 case FIELD_ID_DOCINFO_PRINT_AUTHOR:
3309 eElement = XML_PRINTED_BY;
3310 break;
3311 case FIELD_ID_DOCINFO_TITLE:
3312 eElement = XML_TITLE;
3313 break;
3314 case FIELD_ID_DOCINFO_SUBJECT:
3315 eElement = XML_SUBJECT;
3316 break;
3317 case FIELD_ID_DOCINFO_KEYWORDS:
3318 eElement = XML_KEYWORDS;
3319 break;
3320 case FIELD_ID_DOCINFO_REVISION:
3321 eElement = XML_EDITING_CYCLES;
3322 break;
3323 case FIELD_ID_DOCINFO_EDIT_DURATION:
3324 eElement = XML_EDITING_DURATION;
3325 break;
3326 case FIELD_ID_DOCINFO_SAVE_TIME:
3327 eElement = XML_MODIFICATION_TIME;
3328 break;
3329 case FIELD_ID_DOCINFO_SAVE_DATE:
3330 eElement = XML_MODIFICATION_DATE;
3331 break;
3332 case FIELD_ID_DOCINFO_SAVE_AUTHOR:
3333 eElement = XML_CREATOR;
3334 break;
3335 default:
3336 SAL_WARN("xmloff.text", "unknown docinfo field type!");
3337 eElement = XML_TOKEN_INVALID;
3338 break;
3341 return eElement;
3344 enum XMLTokenEnum XMLTextFieldExport::MapBibliographyFieldName(std::u16string_view sName)
3346 enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3348 if( sName == u"Identifier" )
3350 eName = XML_IDENTIFIER;
3352 else if( sName == u"BibiliographicType" )
3354 eName = XML_BIBLIOGRAPHY_TYPE;
3356 else if( sName == u"Address" )
3358 eName = XML_ADDRESS;
3360 else if( sName == u"Annote" )
3362 eName = XML_ANNOTE;
3364 else if( sName == u"Author" )
3366 eName = XML_AUTHOR;
3368 else if( sName == u"Booktitle" )
3370 eName = XML_BOOKTITLE;
3372 else if( sName == u"Chapter" )
3374 eName = XML_CHAPTER;
3376 else if( sName == u"Edition" )
3378 eName = XML_EDITION;
3380 else if( sName == u"Editor" )
3382 eName = XML_EDITOR;
3384 else if( sName == u"Howpublished" )
3386 eName = XML_HOWPUBLISHED;
3388 else if( sName == u"Institution" )
3390 eName = XML_INSTITUTION;
3392 else if( sName == u"Journal" )
3394 eName = XML_JOURNAL;
3396 else if( sName == u"Month" )
3398 eName = XML_MONTH;
3400 else if( sName == u"Note" )
3402 eName = XML_NOTE;
3404 else if( sName == u"Number" )
3406 eName = XML_NUMBER;
3408 else if( sName == u"Organizations" )
3410 eName = XML_ORGANIZATIONS;
3412 else if( sName == u"Pages" )
3414 eName = XML_PAGES;
3416 else if( sName == u"Publisher" )
3418 eName = XML_PUBLISHER;
3420 else if( sName == u"School" )
3422 eName = XML_SCHOOL;
3424 else if( sName == u"Series" )
3426 eName = XML_SERIES;
3428 else if( sName == u"Title" )
3430 eName = XML_TITLE;
3432 else if( sName == u"Report_Type" )
3434 eName = XML_REPORT_TYPE;
3436 else if( sName == u"Volume" )
3438 eName = XML_VOLUME;
3440 else if( sName == u"Year" )
3442 eName = XML_YEAR;
3444 else if( sName == u"URL" )
3446 eName = XML_URL;
3448 else if( sName == u"Custom1" )
3450 eName = XML_CUSTOM1;
3452 else if( sName == u"Custom2" )
3454 eName = XML_CUSTOM2;
3456 else if( sName == u"Custom3" )
3458 eName = XML_CUSTOM3;
3460 else if( sName == u"Custom4" )
3462 eName = XML_CUSTOM4;
3464 else if( sName == u"Custom5" )
3466 eName = XML_CUSTOM5;
3468 else if( sName == u"ISBN" )
3470 eName = XML_ISBN;
3472 else if (sName == u"LocalURL")
3474 eName = XML_LOCAL_URL;
3476 else if (sName == u"TargetType")
3478 eName = XML_TARGET_TYPE;
3480 else if (sName == u"TargetURL")
3482 eName = XML_TARGET_URL;
3484 else
3486 SAL_WARN("xmloff.text", "Unknown bibliography info data");
3487 eName = XML_TOKEN_INVALID;
3490 return eName;
3493 enum XMLTokenEnum XMLTextFieldExport::MapMeasureKind(sal_Int16 nKind)
3495 switch( nKind )
3497 case 0:
3498 return XML_VALUE;
3499 case 1:
3500 return XML_UNIT;
3502 return XML_GAP;
3505 OUString XMLTextFieldExport::MakeFootnoteRefName(
3506 sal_Int16 nSeqNo)
3508 // generate foot-/endnote ID
3509 return "ftn" + OUString::number(static_cast<sal_Int32>(nSeqNo));
3512 OUString XMLTextFieldExport::MakeSequenceRefName(
3513 sal_Int16 nSeqNo,
3514 std::u16string_view rSeqName)
3516 // generate foot-/endnote ID
3517 return OUString::Concat("ref") +rSeqName + OUString::number(static_cast<sal_Int32>(nSeqNo));
3521 // Property accessor helper functions
3524 // to be relegated (does that word exist?) to a more appropriate place
3527 bool GetBoolProperty(
3528 const OUString& sPropName,
3529 const Reference<XPropertySet> & xPropSet)
3531 Any aAny = xPropSet->getPropertyValue(sPropName);
3532 bool bBool = *o3tl::doAccess<bool>(aAny);
3533 return bBool;
3536 bool GetOptionalBoolProperty(
3537 const OUString& sPropName,
3538 const Reference<XPropertySet> & xPropSet,
3539 const Reference<XPropertySetInfo> & xPropSetInfo,
3540 bool bDefault)
3542 return xPropSetInfo->hasPropertyByName( sPropName )
3543 ? GetBoolProperty( sPropName, xPropSet ) : bDefault;
3546 double GetDoubleProperty(
3547 const OUString& sPropName,
3548 const Reference<XPropertySet> & xPropSet)
3550 Any aAny = xPropSet->getPropertyValue(sPropName);
3551 double fDouble = 0.0;
3552 aAny >>= fDouble;
3553 return fDouble;
3556 OUString GetStringProperty(
3557 const OUString& sPropName,
3558 const Reference<XPropertySet> & xPropSet)
3560 Any aAny = xPropSet->getPropertyValue(sPropName);
3561 OUString sString;
3562 aAny >>= sString;
3563 return sString;
3566 sal_Int32 GetIntProperty(
3567 const OUString& sPropName,
3568 const Reference<XPropertySet> & xPropSet)
3570 Any aAny = xPropSet->getPropertyValue(sPropName);
3571 sal_Int32 nInt = 0;
3572 aAny >>= nInt;
3573 return nInt;
3576 sal_Int16 GetInt16Property(
3577 const OUString& sPropName,
3578 const Reference<XPropertySet> & xPropSet)
3580 Any aAny = xPropSet->getPropertyValue(sPropName);
3581 sal_Int16 nInt = 0;
3582 aAny >>= nInt;
3583 return nInt;
3586 sal_Int8 GetInt8Property(
3587 const OUString& sPropName,
3588 const Reference<XPropertySet> & xPropSet)
3590 Any aAny = xPropSet->getPropertyValue(sPropName);
3591 sal_Int8 nInt = 0;
3592 aAny >>= nInt;
3593 return nInt;
3596 util::DateTime GetDateTimeProperty(
3597 const OUString& sPropName,
3598 const Reference<XPropertySet> & xPropSet)
3600 Any aAny = xPropSet->getPropertyValue(sPropName);
3601 util::DateTime aTime;
3602 aAny >>= aTime;
3603 return aTime;
3606 Sequence<OUString> GetStringSequenceProperty(
3607 const OUString& sPropName,
3608 const Reference<XPropertySet> & xPropSet)
3610 Any aAny = xPropSet->getPropertyValue(sPropName);
3611 Sequence<OUString> aSequence;
3612 aAny >>= aSequence;
3613 return aSequence;
3616 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */