1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * XML export of all text fields
26 #include <com/sun/star/uno/Reference.h>
27 #include <xmloff/xmlnamespace.hxx>
29 #include <rtl/ustring.hxx>
30 #include <xmloff/xmltoken.hxx>
35 #include <string_view>
38 struct XMLPropertyState
;
40 namespace com::sun::star
{
41 namespace util
{ struct DateTime
; }
42 namespace util
{ struct Date
; }
43 namespace text
{ class XTextField
; }
44 namespace text
{ class XText
; }
45 namespace beans
{ class XPropertySet
; }
46 namespace beans
{ class XPropertySetInfo
; }
47 namespace frame
{ class XModel
; }
48 namespace uno
{ template<typename A
> class Sequence
; }
53 // including translation between UNO speak and XML speak if appropriate
56 FIELD_ID_SENDER
, // sender == extended user
58 FIELD_ID_DATE
, // current date
59 FIELD_ID_TIME
, // current time (+date)
60 FIELD_ID_PAGENAME
, // page/slide name
61 FIELD_ID_PAGENUMBER
, // page number
62 FIELD_ID_PAGESTRING
, // page continuation string (page number string)
63 FIELD_ID_REFPAGE_SET
, // set reference page
64 FIELD_ID_REFPAGE_GET
, // get reference page number
66 FIELD_ID_PLACEHOLDER
, // placeholder field == jump edit field
68 FIELD_ID_VARIABLE_GET
, // get variable == get expression
69 FIELD_ID_VARIABLE_SET
, // set variable == set expression
70 FIELD_ID_VARIABLE_INPUT
, // input field (variable)
71 FIELD_ID_USER_GET
, // user field
72 FIELD_ID_USER_INPUT
, // input field (user field)
73 FIELD_ID_TEXT_INPUT
, // input field (text)
74 FIELD_ID_EXPRESSION
, // expression field = formula field
75 FIELD_ID_SEQUENCE
, // sequence field
77 FIELD_ID_DATABASE_NEXT
, // select next row
78 FIELD_ID_DATABASE_SELECT
, // select row # (NumSet)
79 FIELD_ID_DATABASE_DISPLAY
, // display data (form letter field)
80 FIELD_ID_DATABASE_NAME
, // display current db name (database name)
81 FIELD_ID_DATABASE_NUMBER
, // display row # (SetNumber)
83 FIELD_ID_DOCINFO_CREATION_AUTHOR
, // docinfo fields
84 FIELD_ID_DOCINFO_CREATION_TIME
,
85 FIELD_ID_DOCINFO_CREATION_DATE
,
86 FIELD_ID_DOCINFO_DESCRIPTION
,
87 FIELD_ID_DOCINFO_CUSTOM
,
88 FIELD_ID_DOCINFO_PRINT_TIME
,
89 FIELD_ID_DOCINFO_PRINT_DATE
,
90 FIELD_ID_DOCINFO_PRINT_AUTHOR
,
91 FIELD_ID_DOCINFO_TITLE
,
92 FIELD_ID_DOCINFO_SUBJECT
,
93 FIELD_ID_DOCINFO_KEYWORDS
,
94 FIELD_ID_DOCINFO_REVISION
,
95 FIELD_ID_DOCINFO_EDIT_DURATION
,
96 FIELD_ID_DOCINFO_SAVE_TIME
,
97 FIELD_ID_DOCINFO_SAVE_DATE
,
98 FIELD_ID_DOCINFO_SAVE_AUTHOR
,
100 FIELD_ID_CONDITIONAL_TEXT
, // conditionally choose between 2 texts
101 FIELD_ID_HIDDEN_TEXT
, // conditionally hide a text
102 FIELD_ID_HIDDEN_PARAGRAPH
, // conditionally hide a paragraph
104 FIELD_ID_TEMPLATE_NAME
, // display name of template
105 FIELD_ID_CHAPTER
, // display name/number of current chapter
106 FIELD_ID_FILE_NAME
, // display name of current file
108 FIELD_ID_COUNT_PARAGRAPHS
, // statistics fields: - paragraphs
109 FIELD_ID_COUNT_WORDS
, // - words
110 FIELD_ID_COUNT_CHARACTERS
, // - chars
111 FIELD_ID_COUNT_PAGES
, // - pages
112 FIELD_ID_COUNT_TABLES
, // - tables
113 FIELD_ID_COUNT_GRAPHICS
, // - graphics
114 FIELD_ID_COUNT_OBJECTS
, // - objects
116 FIELD_ID_MACRO
, // macro fields
117 FIELD_ID_REF_REFERENCE
, // get reference field (reference)
118 FIELD_ID_REF_SEQUENCE
, // get reference field (sequence)
119 FIELD_ID_REF_BOOKMARK
, // get reference field (bookmark)
120 FIELD_ID_REF_FOOTNOTE
, // get reference field (footnote)
121 FIELD_ID_REF_ENDNOTE
, // get reference field (endnote)
122 FIELD_ID_DDE
, // DDE field
124 FIELD_ID_BIBLIOGRAPHY
, // bibliography index entry
126 FIELD_ID_SHEET_NAME
, // name of current (spread-)sheet
127 FIELD_ID_URL
, // URL field (only Calc, Draw, Impress)
129 FIELD_ID_SCRIPT
, // script fields (for HTML pages, mostly)
130 FIELD_ID_ANNOTATION
, // annotation (notice) field
132 FIELD_ID_COMBINED_CHARACTERS
, // combined characters (asian typography)
134 FIELD_ID_META
, // text:meta-field (RDF metadata)
136 FIELD_ID_MEASURE
, // for measure shapes
138 FIELD_ID_TABLE_FORMULA
, // DEPRECATED: table formulas (Writer 2.0)
139 FIELD_ID_DROP_DOWN
, // DEPRECATED: dropdown fields (WW8)
141 FIELD_ID_DRAW_HEADER
,
142 FIELD_ID_DRAW_FOOTER
,
143 FIELD_ID_DRAW_DATE_TIME
,
145 FIELD_ID_UNKNOWN
// invalid or unknown field type!
149 class XMLTextFieldExport final
151 SvXMLExport
& rExport
;
153 /// store used text field master names (NULL means: don't collect)
154 std::unique_ptr
< ::std::map
<
155 css::uno::Reference
< css::text::XText
>,
156 ::std::set
< OUString
> > >
161 XMLTextFieldExport( SvXMLExport
& rExp
,
162 /// XMLPropertyState for the combined characters field
163 std::unique_ptr
<XMLPropertyState
> pCombinedCharState
);
164 ~XMLTextFieldExport();
166 /// Export this field and the surrounding span element with the formatting.
167 /// To be called for every field in the document body.
168 void ExportField(const css::uno::Reference
< css::text::XTextField
> & rTextField
,
169 bool bProgress
, bool & rPrevCharIsSpace
);
171 /// collect styles (character styles, data styles, ...) for this field
172 /// (if appropriate).
173 /// Also collect used field masters (if pUsedMasters is set)
174 /// to be called for every field during style export.
175 void ExportFieldAutoStyle(const css::uno::Reference
< css::text::XTextField
> & rTextField
,
176 const bool bProgress
, const bool bRecursive
);
178 /// export field declarations.
179 /// to be called once at beginning of document body.
180 void ExportFieldDeclarations();
182 /// export field declarations for fields used in the particular XText.
183 /// (Requires that a list of used field declarations has previously been
184 /// built-up in ExportFieldAutoStyle() )
185 void ExportFieldDeclarations(
186 const css::uno::Reference
< css::text::XText
> & rText
);
188 /// export all field declarations, or only those that have been used?
189 /// Calling this method will reset the list of used field declarations.
190 void SetExportOnlyUsedFieldDeclarations(
191 bool bExportOnlyUsed
= true);
193 // determine element or attribute names
194 // (public, because they may be useful in related XML export classes)
195 static enum ::xmloff::token::XMLTokenEnum
MapPlaceholderType(sal_uInt16 nType
);
196 static enum ::xmloff::token::XMLTokenEnum
MapTemplateDisplayFormat(sal_Int16 nType
);
197 static enum ::xmloff::token::XMLTokenEnum
MapChapterDisplayFormat(sal_Int16 nType
);
198 static enum ::xmloff::token::XMLTokenEnum
MapFilenameDisplayFormat(sal_Int16 nType
);
199 static enum ::xmloff::token::XMLTokenEnum
MapDocInfoFieldName(enum FieldIdEnum nToken
);
200 static enum ::xmloff::token::XMLTokenEnum
MapReferenceSource(sal_Int16 nType
);
201 static enum ::xmloff::token::XMLTokenEnum
MapReferenceType(sal_Int16 nType
);
202 static enum ::xmloff::token::XMLTokenEnum
MapCountFieldName(FieldIdEnum nToken
);
203 static enum ::xmloff::token::XMLTokenEnum
MapBibliographyFieldName(std::u16string_view sName
);
204 static enum ::xmloff::token::XMLTokenEnum
MapMeasureKind(sal_Int16 nKind
);
205 static enum ::xmloff::token::XMLTokenEnum
MapPageNumberName(const css::uno::Reference
< css::beans::XPropertySet
> & xPropSet
,
206 sal_Int32
& nOffset
); /// also adjust page offset
207 static enum ::xmloff::token::XMLTokenEnum
MapAuthorFieldName(const css::uno::Reference
< css::beans::XPropertySet
> & xPropSet
);
208 static enum ::xmloff::token::XMLTokenEnum
MapSenderFieldName(const css::uno::Reference
< css::beans::XPropertySet
> & xPropSet
);
212 SvXMLExport
& GetExport() { return rExport
; }
214 /// export a field after <text:span> is already written
215 void ExportFieldHelper(
216 const css::uno::Reference
< css::text::XTextField
> & rTextField
,
217 const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
218 const css::uno::Reference
< css::beans::XPropertySet
> & rRangePropSet
,
219 enum FieldIdEnum nToken
,
221 bool & rPrevCharIsSpace
);
223 /// export an empty element
224 void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement
, /// element token
225 bool bAddSpace
= false); /// add blanks around
228 /// export an element with string content
229 void ExportElement(enum ::xmloff::token::XMLTokenEnum eElement
, /// element token
230 const OUString
& sContent
); /// element content
232 /// export a macro (as used in the macro field)
233 void ExportMacro( const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
234 const OUString
& rContent
);
236 /// export text:meta-field (RDF metadata)
237 void ExportMetaField( const css::uno::Reference
< css::beans::XPropertySet
> & i_xMeta
,
238 bool i_bAutoStyles
, bool i_bProgress
,
239 bool & rPrevCharIsSpace
);
241 /// export a boolean attribute
243 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
244 bool bBool
, /// attribute value
245 bool bDefault
); /// attribute default; omit, if attribute differs
247 /// export an integer attribute
249 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
250 sal_Int32 nNum
); /// attribute value
252 /// export an integer attribute, omit if default
253 void ProcessIntegerDef(
254 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
255 sal_Int32 nNum
, /// attribute value
256 sal_Int32 nDefault
); /// default value
258 /// export a string attribute
260 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
261 const OUString
& sValue
, /// attribute value
262 bool bOmitEmpty
= false, /// omit attribute, if value is empty
263 sal_uInt16 nPrefix
= XML_NAMESPACE_TEXT
); /// attribute name prefix
265 /// export a string attribute that gets a QName value
267 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
268 sal_uInt16 nValuePrefix
,
269 const OUString
& sValue
); /// attribute value
272 /// export a string attribute, omit if default
274 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
275 const OUString
& sValue
, /// attribute value
276 std::u16string_view sDefault
); /// default value; omit if equal
278 /// export a string attribute, omit if default
280 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
281 sal_uInt16 nValuePrefix
,
282 const OUString
& sValue
, /// attribute value
283 std::u16string_view sDefault
); /// default value; omit if equal
285 /// export a string attribute
287 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
288 enum ::xmloff::token::XMLTokenEnum eValue
, /// attribute token
289 sal_uInt16 nPrefix
= XML_NAMESPACE_TEXT
); /// attribute name prefix
291 /// export a string attribute, omit if default
293 enum ::xmloff::token::XMLTokenEnum eXmlName
, /// attribute token (namespace text)
294 enum ::xmloff::token::XMLTokenEnum eValue
, /// attribute value token
295 enum ::xmloff::token::XMLTokenEnum eDefault
); /// default value token
297 /// export a string as a sequence of paragraphs
298 void ProcessParagraphSequence(
299 /// string containing the paragraphs
300 std::u16string_view sParagraphSequence
);
302 /// export a numbering format (numeric, roman, alphabetic, etc.)
303 void ProcessNumberingType(
304 sal_Int16 nNumberingType
); /// numbering type key
306 /// export display attribute (value, formula, none)
307 void ProcessDisplay(bool bIsVisible
, /// is visible?
308 bool bIsCommand
); /// is show command/show name?
310 /// export all data-style related attributes
311 void ProcessValueAndType(
312 bool bIsString
, /// do we process a string or a number?
313 sal_Int32 nFormatKey
, /// format key for NumberFormatter; possibly -1
314 const OUString
& sContent
, /// string content; possibly invalid
315 std::u16string_view sDefault
, /// default string
316 double fValue
, /// float content; possibly invalid
317 bool bExportValue
, /// export value attribute?
318 bool bExportValueType
, /// export value-type attribute?
319 bool bExportStyle
, /// export style-attribute?
320 bool bForceSystemLanguage
, /// no style language export
321 bool bTimeStyle
= false); /// exporting a time style?
323 /// export times, dates and durations according to ISO 8601
324 void ProcessDateTime(
325 enum ::xmloff::token::XMLTokenEnum eXMLName
, /// attribute token
326 double dValue
, /// date/time value
327 bool bIsDate
, /// export as date (rather than date/time)?
328 bool bIsDuration
, /// export as duration
329 bool bOmitDurationIfZero
= true, /// omit zero-length durat.
330 sal_uInt16 nPrefix
= XML_NAMESPACE_TEXT
); /// attribute name prefix
332 /// export a date, time, or duration
333 void ProcessDateTime(
334 enum ::xmloff::token::XMLTokenEnum eXMLName
, /// attribute token
335 sal_Int32 nMinutes
, /// date/time value in minutes
336 bool bIsDate
, /// export as date?
337 bool bIsDuration
); /// export as duration?
339 /// export times, dates and durations according to ISO 8601
340 void ProcessDateTime(
341 enum ::xmloff::token::XMLTokenEnum eXMLName
, /// attribute token
342 const css::util::DateTime
& rTime
); /// date/time value
344 /// export time or dateTime
345 void ProcessTimeOrDateTime(
346 enum ::xmloff::token::XMLTokenEnum eXMLName
, /// attribute token
347 const css::util::DateTime
& rTime
); /// date/time value
349 /// export all attributes for bibliography data fields
350 void ProcessBibliographyData(
351 const css::uno::Reference
<
352 css::beans::XPropertySet
> & rPropertySet
);
354 /// export CommandTypeAttribute
355 void ProcessCommandType(
356 sal_Int32 nCommandType
); /// css::sdb::CommandType
358 void ProcessStringSequence(
359 const css::uno::Sequence
<OUString
>& rSequence
,
360 const OUString
& sSelected
);
362 void ProcessStringSequence(
363 const css::uno::Sequence
<OUString
>& rSequence
,
364 sal_Int32 nSelected
);
366 /// export attributes that describe a data source
367 void ExportDataBaseElement(
368 enum ::xmloff::token::XMLTokenEnum eElement
,
369 const OUString
& sContent
,
370 const css::uno::Reference
< css::beans::XPropertySet
> & rPropertySet
,
371 const css::uno::Reference
< css::beans::XPropertySetInfo
> & rPropertySetInfo
);
373 /// for XDependentTextFields, get PropertySet of FieldMaster
374 static css::uno::Reference
< css::beans::XPropertySet
>
375 GetMasterPropertySet(const css::uno::Reference
< css::text::XTextField
> & rTextField
);
377 /// get PropertySet of (any) DependentTextField for this FieldMaster
378 static bool GetDependentFieldPropertySet(
379 const css::uno::Reference
< css::beans::XPropertySet
> & xmaster
,
380 css::uno::Reference
< css::beans::XPropertySet
> & xField
);
383 /// get field ID from XTextField (and it's Property-Set)
384 static enum FieldIdEnum
GetFieldID(const css::uno::Reference
< css::text::XTextField
> & rTextField
,
385 const css::uno::Reference
< css::beans::XPropertySet
> & xPropSet
);
387 /// get field ID from XTextField service name (and it's PropertySet)
388 static enum FieldIdEnum
MapFieldName(std::u16string_view sFieldName
,
389 const css::uno::Reference
< css::beans::XPropertySet
> & xPropSet
);
391 /// determine, whether field has string or numeric content
392 static bool IsStringField(FieldIdEnum nFieldType
, /// field ID
393 const css::uno::Reference
< css::beans::XPropertySet
> & xPropSet
);
396 /// explode a field master name into field type and field name
397 static void ExplodeFieldMasterName(
398 const OUString
& sMasterName
, /// name as returned by SO API
399 OUString
& sFieldType
, /// out: field type
400 OUString
& sVarName
); /// out: variable name
402 /// make reference name for a foot- or endnote
403 static OUString
MakeFootnoteRefName(sal_Int16 nSeqNo
);
405 /// make reference name for a sequence field
406 static OUString
MakeSequenceRefName(sal_Int16 nSeqNo
,
407 std::u16string_view rSeqName
);
409 std::unique_ptr
<XMLPropertyState
> pCombinedCharactersPropertyState
;
414 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */