xref: /AOO41X/main/xmloff/source/text/txtflde.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmloff.hxx"
26 
27 /** @#file
28  *
29  *  export of all text fields
30  */
31 #include "txtflde.hxx"
32 #include <xmloff/xmlexp.hxx>
33 #include <xmloff/xmlnumfe.hxx>
34 #include <xmloff/xmltoken.hxx>
35 #include <xmloff/xmlement.hxx>
36 #include <xmloff/xmluconv.hxx>
37 #include <xmloff/xmlnume.hxx>
38 #include "xmloff/numehelp.hxx"
39 
40 #include <xmloff/families.hxx>
41 #include <xmloff/XMLEventExport.hxx>
42 #include "XMLTextCharStyleNamesElementExport.hxx"
43 #include <xmloff/nmspmap.hxx>
44 #include <com/sun/star/util/DateTime.hpp>
45 #include <com/sun/star/util/Date.hpp>
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <com/sun/star/text/UserDataPart.hpp>
48 #include <com/sun/star/text/PageNumberType.hpp>
49 #include <com/sun/star/style/NumberingType.hpp>
50 #include <com/sun/star/text/ReferenceFieldPart.hpp>
51 #include <com/sun/star/text/ReferenceFieldSource.hpp>
52 #include <com/sun/star/beans/XPropertySet.hpp>
53 #include <com/sun/star/beans/XPropertyState.hpp>
54 #include <com/sun/star/text/XTextField.hpp>
55 #include <com/sun/star/text/XDependentTextField.hpp>
56 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
57 
58 #include <com/sun/star/text/SetVariableType.hpp>
59 #include <com/sun/star/text/PlaceholderType.hpp>
60 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
61 #include <com/sun/star/text/ChapterFormat.hpp>
62 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
63 #include <com/sun/star/frame/XModel.hpp>
64 #include <com/sun/star/container/XNameReplace.hpp>
65 #include <com/sun/star/uno/Sequence.h>
66 #include <com/sun/star/util/NumberFormat.hpp>
67 #include <com/sun/star/text/BibliographyDataType.hpp>
68 #include <com/sun/star/sdb/CommandType.hpp>
69 #include <com/sun/star/rdf/XMetadatable.hpp>
70 #include <rtl/ustrbuf.hxx>
71 #include <tools/debug.hxx>
72 #include <rtl/math.hxx>
73 
74 #include <vector>
75 
76 using ::rtl::OUString;
77 using ::rtl::OUStringBuffer;
78 
79 using namespace ::std;
80 using namespace ::com::sun::star;
81 using namespace ::com::sun::star::uno;
82 using namespace ::com::sun::star::text;
83 using namespace ::com::sun::star::lang;
84 using namespace ::com::sun::star::beans;
85 using namespace ::com::sun::star::util;
86 using namespace ::com::sun::star::style;
87 using namespace ::com::sun::star::document;
88 using namespace ::com::sun::star::container;
89 using namespace ::xmloff::token;
90 
91 
92 static sal_Char __READONLY_DATA FIELD_SERVICE_SENDER[] = "ExtendedUser";
93 static sal_Char __READONLY_DATA FIELD_SERVICE_AUTHOR[] = "Author";
94 static sal_Char __READONLY_DATA FIELD_SERVICE_JUMPEDIT[] = "JumpEdit";
95 static sal_Char __READONLY_DATA FIELD_SERVICE_GETEXP[] = "GetExpression";
96 static sal_Char __READONLY_DATA FIELD_SERVICE_SETEXP[] = "SetExpression";
97 static sal_Char __READONLY_DATA FIELD_SERVICE_USER[] = "User";
98 static sal_Char __READONLY_DATA FIELD_SERVICE_INPUT[] = "Input";
99 static sal_Char __READONLY_DATA FIELD_SERVICE_USERINPUT[] = "InputUser";
100 static sal_Char __READONLY_DATA FIELD_SERVICE_DATETIME[] = "DateTime";
101 static sal_Char __READONLY_DATA FIELD_SERVICE_PAGENUMBER[] = "PageNumber";
102 static sal_Char __READONLY_DATA FIELD_SERVICE_DB_NEXT[] = "DatabaseNextSet";
103 static sal_Char __READONLY_DATA FIELD_SERVICE_DB_SELECT[] = "DatabaseNumberOfSet";
104 static sal_Char __READONLY_DATA FIELD_SERVICE_DB_NUMBER[] = "DatabaseSetNumber";
105 static sal_Char __READONLY_DATA FIELD_SERVICE_DB_DISPLAY[] = "Database";
106 static sal_Char __READONLY_DATA FIELD_SERVICE_DB_NAME[] = "DatabaseName";
107 static sal_Char __READONLY_DATA FIELD_SERVICE_CONDITIONAL_TEXT[] = "ConditionalText";
108 static sal_Char __READONLY_DATA FIELD_SERVICE_HIDDEN_TEXT[] = "HiddenText";
109 static sal_Char __READONLY_DATA FIELD_SERVICE_HIDDEN_PARAGRAPH[] = "HiddenParagraph";
110 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR[] = "DocInfo.ChangeAuthor";
111 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR2[] = "docinfo.ChangeAuthor";
112 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME[] = "DocInfo.ChangeDateTime";
113 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME2[] = "docinfo.ChangeDateTime";
114 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_EDIT_TIME[] = "DocInfo.EditTime";
115 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_EDIT_TIME2[] = "docinfo.EditTime";
116 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_DESCRIPTION[] = "DocInfo.Description";
117 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_DESCRIPTION2[] = "docinfo.Description";
118 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR[] = "DocInfo.CreateAuthor";
119 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR2[] = "docinfo.CreateAuthor";
120 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME[] = "DocInfo.CreateDateTime";
121 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME2[] = "docinfo.CreateDateTime";
122 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CUSTOM[] = "DocInfo.Custom";
123 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_CUSTOM2[] = "docinfo.Custom";
124 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR[] = "DocInfo.PrintAuthor";
125 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR2[] = "docinfo.PrintAuthor";
126 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME[] = "DocInfo.PrintDateTime";
127 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME2[] = "docinfo.PrintDateTime";
128 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_KEY_WORDS[] = "DocInfo.KeyWords";
129 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_KEY_WORDS2[] = "docinfo.KeyWords";
130 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_SUBJECT[] = "DocInfo.Subject";
131 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_SUBJECT2[] = "docinfo.Subject";
132 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_TITLE[] = "DocInfo.Title";
133 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_TITLE2[] = "docinfo.Title";
134 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_REVISION[] = "DocInfo.Revision";
135 static sal_Char __READONLY_DATA FIELD_SERVICE_DOC_INFO_REVISION2[] = "docinfo.Revision";
136 static sal_Char __READONLY_DATA FIELD_SERVICE_FILE_NAME[] = "FileName";
137 static sal_Char __READONLY_DATA FIELD_SERVICE_CHAPTER[] = "Chapter";
138 static sal_Char __READONLY_DATA FIELD_SERVICE_TEMPLATE_NAME[] = "TemplateName";
139 static sal_Char __READONLY_DATA FIELD_SERVICE_PAGE_COUNT[] = "PageCount";
140 static sal_Char __READONLY_DATA FIELD_SERVICE_PARAGRAPH_COUNT[] = "ParagraphCount";
141 static sal_Char __READONLY_DATA FIELD_SERVICE_WORD_COUNT[] = "WordCount";
142 static sal_Char __READONLY_DATA FIELD_SERVICE_CHARACTER_COUNT[] = "CharacterCount";
143 static sal_Char __READONLY_DATA FIELD_SERVICE_TABLE_COUNT[] = "TableCount";
144 static sal_Char __READONLY_DATA FIELD_SERVICE_GRAPHIC_COUNT[] = "GraphicObjectCount";
145 static sal_Char __READONLY_DATA FIELD_SERVICE_OBJECT_COUNT[] = "EmbeddedObjectCount";
146 static sal_Char __READONLY_DATA FIELD_SERVICE_REFERENCE_PAGE_SET[] = "ReferencePageSet";
147 static sal_Char __READONLY_DATA FIELD_SERVICE_REFERENCE_PAGE_GET[] = "ReferencePageGet";
148 static sal_Char __READONLY_DATA FIELD_SERVICE_SHEET_NAME[] = "SheetName";
149 static sal_Char __READONLY_DATA FIELD_SERVICE_MACRO[] = "Macro";
150 static sal_Char __READONLY_DATA FIELD_SERVICE_GET_REFERENCE[] = "GetReference";
151 static sal_Char __READONLY_DATA FIELD_SERVICE_DDE[] = "DDE";
152 static sal_Char __READONLY_DATA FIELD_SERVICE_URL[] = "URL";
153 static sal_Char __READONLY_DATA FIELD_SERVICE_BIBLIOGRAPHY[] = "Bibliography";
154 static sal_Char __READONLY_DATA FIELD_SERVICE_SCRIPT[] = "Script";
155 static sal_Char __READONLY_DATA FIELD_SERVICE_ANNOTATION[] = "Annotation";
156 static sal_Char __READONLY_DATA FIELD_SERVICE_COMBINED_CHARACTERS[] = "CombinedCharacters";
157 static sal_Char __READONLY_DATA FIELD_SERVICE_META[] = "MetadataField";
158 static sal_Char __READONLY_DATA FIELD_SERVICE_MEASURE[] = "Measure";
159 static sal_Char __READONLY_DATA FIELD_SERVICE_TABLE_FORMULA[] = "TableFormula";
160 static sal_Char __READONLY_DATA FIELD_SERVICE_DROP_DOWN[] = "DropDown";
161 
162 SvXMLEnumStringMapEntry __READONLY_DATA aFieldServiceNameMapping[] =
163 {
164     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SENDER, FIELD_ID_SENDER ),
165     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_AUTHOR, FIELD_ID_AUTHOR ),
166     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_JUMPEDIT, FIELD_ID_PLACEHOLDER ),
167     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GETEXP, FIELD_ID_VARIABLE_GET ),
168     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SETEXP, FIELD_ID_VARIABLE_SET ),
169     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_USER, FIELD_ID_USER_GET ),
170     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_INPUT, FIELD_ID_TEXT_INPUT ),
171     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_USERINPUT, FIELD_ID_USER_INPUT ),
172     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DATETIME, FIELD_ID_TIME ),
173     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PAGENUMBER, FIELD_ID_PAGENUMBER ),
174     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_REFERENCE_PAGE_SET, FIELD_ID_REFPAGE_SET ),
175     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_REFERENCE_PAGE_GET, FIELD_ID_REFPAGE_GET ),
176 
177     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NEXT, FIELD_ID_DATABASE_NEXT ),
178     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_SELECT, FIELD_ID_DATABASE_SELECT ),
179     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NUMBER, FIELD_ID_DATABASE_NUMBER ),
180     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_DISPLAY, FIELD_ID_DATABASE_DISPLAY ),
181     // workaround for #no-bug#: Database/DataBase
182     ENUM_STRING_MAP_ENTRY( "DataBase", FIELD_ID_DATABASE_DISPLAY ),
183     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DB_NAME, FIELD_ID_DATABASE_NAME ),
184 
185     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR, FIELD_ID_DOCINFO_CREATION_AUTHOR ),
186     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_AUTHOR2, FIELD_ID_DOCINFO_CREATION_AUTHOR ),
187     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME, FIELD_ID_DOCINFO_CREATION_TIME),
188     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CREATE_DATE_TIME2, FIELD_ID_DOCINFO_CREATION_TIME),
189     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR, FIELD_ID_DOCINFO_SAVE_AUTHOR ),
190     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_AUTHOR2, FIELD_ID_DOCINFO_SAVE_AUTHOR ),
191     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME, FIELD_ID_DOCINFO_SAVE_TIME ),
192     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CHANGE_DATE_TIME2, FIELD_ID_DOCINFO_SAVE_TIME ),
193     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_EDIT_TIME, FIELD_ID_DOCINFO_EDIT_DURATION ),
194     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_EDIT_TIME2, FIELD_ID_DOCINFO_EDIT_DURATION ),
195     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_DESCRIPTION, FIELD_ID_DOCINFO_DESCRIPTION ),
196     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_DESCRIPTION2, FIELD_ID_DOCINFO_DESCRIPTION ),
197     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CUSTOM, FIELD_ID_DOCINFO_CUSTOM ),
198     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_CUSTOM2, FIELD_ID_DOCINFO_CUSTOM ),
199     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR, FIELD_ID_DOCINFO_PRINT_AUTHOR ),
200     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_AUTHOR2, FIELD_ID_DOCINFO_PRINT_AUTHOR ),
201     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME, FIELD_ID_DOCINFO_PRINT_TIME ),
202     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_PRINT_DATE_TIME2, FIELD_ID_DOCINFO_PRINT_TIME ),
203     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_KEY_WORDS, FIELD_ID_DOCINFO_KEYWORDS ),
204     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_KEY_WORDS2, FIELD_ID_DOCINFO_KEYWORDS ),
205     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_SUBJECT, FIELD_ID_DOCINFO_SUBJECT ),
206     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_SUBJECT2, FIELD_ID_DOCINFO_SUBJECT ),
207     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_TITLE, FIELD_ID_DOCINFO_TITLE ),
208     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_TITLE2, FIELD_ID_DOCINFO_TITLE ),
209     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_REVISION, FIELD_ID_DOCINFO_REVISION ),
210     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DOC_INFO_REVISION2, FIELD_ID_DOCINFO_REVISION ),
211 
212     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CONDITIONAL_TEXT, FIELD_ID_CONDITIONAL_TEXT ),
213     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_HIDDEN_TEXT, FIELD_ID_HIDDEN_TEXT ),
214     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_HIDDEN_PARAGRAPH, FIELD_ID_HIDDEN_PARAGRAPH ),
215 
216     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_FILE_NAME, FIELD_ID_FILE_NAME ),
217     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CHAPTER, FIELD_ID_CHAPTER ),
218     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TEMPLATE_NAME, FIELD_ID_TEMPLATE_NAME ),
219 
220     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PAGE_COUNT, FIELD_ID_COUNT_PAGES ),
221     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_PARAGRAPH_COUNT, FIELD_ID_COUNT_PARAGRAPHS ),
222     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_WORD_COUNT, FIELD_ID_COUNT_WORDS ),
223     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_CHARACTER_COUNT, FIELD_ID_COUNT_CHARACTERS ),
224     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TABLE_COUNT, FIELD_ID_COUNT_TABLES ),
225     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GRAPHIC_COUNT, FIELD_ID_COUNT_GRAPHICS ),
226     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_OBJECT_COUNT, FIELD_ID_COUNT_OBJECTS ),
227 
228     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_MACRO, FIELD_ID_MACRO ),
229     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_GET_REFERENCE, FIELD_ID_REF_REFERENCE ),
230     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DDE, FIELD_ID_DDE ),
231 
232     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_BIBLIOGRAPHY, FIELD_ID_BIBLIOGRAPHY ),
233 
234     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SCRIPT, FIELD_ID_SCRIPT ),
235     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_ANNOTATION, FIELD_ID_ANNOTATION ),
236 
237     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_COMBINED_CHARACTERS, FIELD_ID_COMBINED_CHARACTERS ),
238     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_META, FIELD_ID_META ),
239 
240     // non-writer fields
241     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_SHEET_NAME, FIELD_ID_SHEET_NAME ),
242     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_URL, FIELD_ID_URL ),
243     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_MEASURE, FIELD_ID_MEASURE ),
244 
245     // deprecated fields
246     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_TABLE_FORMULA, FIELD_ID_TABLE_FORMULA ),
247     ENUM_STRING_MAP_ENTRY( FIELD_SERVICE_DROP_DOWN, FIELD_ID_DROP_DOWN ),
248 
249     ENUM_STRING_MAP_END()
250 };
251 
252 
253 
254 // property accessor helper functions
255 inline sal_Bool GetBoolProperty(const OUString&,
256                                       const Reference<XPropertySet> &);
257 inline sal_Bool GetOptionalBoolProperty(const OUString&,
258                                               const Reference<XPropertySet> &,
259                                               const Reference<XPropertySetInfo> &,
260                                               sal_Bool bDefault);
261 inline double GetDoubleProperty(const OUString&,
262                                       const Reference<XPropertySet> &);
263 inline OUString const GetStringProperty(const OUString&,
264                                         const Reference<XPropertySet> &);
265 inline sal_Int32 GetIntProperty(const OUString&,
266                                       const Reference<XPropertySet> &);
267 inline sal_Int16 GetInt16Property(const OUString&,
268                                         const Reference<XPropertySet> &);
269 inline sal_Int8 GetInt8Property(const OUString&,
270                                       const Reference<XPropertySet> &);
271 inline DateTime const GetDateTimeProperty( const OUString& sPropName,
272                                            const Reference<XPropertySet> & xPropSet);
273 inline Date const GetDateProperty( const OUString& sPropName,
274                                    const Reference<XPropertySet> & xPropSet);
275 inline Sequence<OUString> const GetStringSequenceProperty(
276                                    const OUString& sPropName,
277                                    const Reference<XPropertySet> & xPropSet);
278 
279 
280 
281 XMLTextFieldExport::XMLTextFieldExport( SvXMLExport& rExp,
282                                         XMLPropertyState* pCombinedCharState)
283     : rExport(rExp),
284       pUsedMasters(NULL),
285       sServicePrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.")),
286       sFieldMasterPrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.FieldMaster.")),
287       sPresentationServicePrefix(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.TextField.")),
288 
289     sPropertyAdjust(RTL_CONSTASCII_USTRINGPARAM("Adjust")),
290     sPropertyAuthor(RTL_CONSTASCII_USTRINGPARAM("Author")),
291     sPropertyChapterFormat(RTL_CONSTASCII_USTRINGPARAM("ChapterFormat")),
292     sPropertyChapterNumberingLevel(RTL_CONSTASCII_USTRINGPARAM("ChapterNumberingLevel")),
293     sPropertyCharStyleNames(RTL_CONSTASCII_USTRINGPARAM("CharStyleNames")),
294     sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM("Condition")),
295     sPropertyContent(RTL_CONSTASCII_USTRINGPARAM("Content")),
296     sPropertyDataBaseName(RTL_CONSTASCII_USTRINGPARAM("DataBaseName")),
297     sPropertyDataBaseURL(RTL_CONSTASCII_USTRINGPARAM("DataBaseURL")),
298     sPropertyDataColumnName(RTL_CONSTASCII_USTRINGPARAM("DataColumnName")),
299     sPropertyDataCommandType(RTL_CONSTASCII_USTRINGPARAM("DataCommandType")),
300     sPropertyDataTableName(RTL_CONSTASCII_USTRINGPARAM("DataTableName")),
301     sPropertyDate(RTL_CONSTASCII_USTRINGPARAM("Date")),
302     sPropertyDateTime(RTL_CONSTASCII_USTRINGPARAM("DateTime")),
303     sPropertyDateTimeValue(RTL_CONSTASCII_USTRINGPARAM("DateTimeValue")),
304     sPropertyDDECommandElement(RTL_CONSTASCII_USTRINGPARAM("DDECommandElement")),
305     sPropertyDDECommandFile(RTL_CONSTASCII_USTRINGPARAM("DDECommandFile")),
306     sPropertyDDECommandType(RTL_CONSTASCII_USTRINGPARAM("DDECommandType")),
307     sPropertyDependentTextFields(RTL_CONSTASCII_USTRINGPARAM("DependentTextFields")),
308     sPropertyFalseContent(RTL_CONSTASCII_USTRINGPARAM("FalseContent")),
309     sPropertyFields(RTL_CONSTASCII_USTRINGPARAM("Fields")),
310     sPropertyFieldSubType(RTL_CONSTASCII_USTRINGPARAM("UserDataType")),
311     sPropertyFileFormat(RTL_CONSTASCII_USTRINGPARAM("FileFormat")),
312     sPropertyFullName(RTL_CONSTASCII_USTRINGPARAM("FullName")),
313     sPropertyHint(RTL_CONSTASCII_USTRINGPARAM("Hint")),
314     sPropertyInstanceName(RTL_CONSTASCII_USTRINGPARAM("InstanceName")),
315     sPropertyIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM("IsAutomaticUpdate")),
316     sPropertyIsConditionTrue(RTL_CONSTASCII_USTRINGPARAM("IsConditionTrue")),
317     sPropertyIsDataBaseFormat(RTL_CONSTASCII_USTRINGPARAM("DataBaseFormat")),
318     sPropertyIsDate(RTL_CONSTASCII_USTRINGPARAM("IsDate")),
319     sPropertyIsExpression(RTL_CONSTASCII_USTRINGPARAM("IsExpression")),
320     sPropertyIsFixed(RTL_CONSTASCII_USTRINGPARAM("IsFixed")),
321     sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM("IsFixedLanguage")),
322     sPropertyIsHidden(RTL_CONSTASCII_USTRINGPARAM("IsHidden")),
323     sPropertyIsInput(RTL_CONSTASCII_USTRINGPARAM("Input")),
324     sPropertyIsShowFormula(RTL_CONSTASCII_USTRINGPARAM("IsShowFormula")),
325     sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM("IsVisible")),
326     sPropertyItems(RTL_CONSTASCII_USTRINGPARAM("Items")),
327     sPropertyLevel(RTL_CONSTASCII_USTRINGPARAM("Level")),
328     sPropertyMacro(RTL_CONSTASCII_USTRINGPARAM("Macro")),
329     sPropertyMeasureKind(RTL_CONSTASCII_USTRINGPARAM("Kind")),
330     sPropertyName(RTL_CONSTASCII_USTRINGPARAM("Name")),
331     sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")),
332     sPropertyNumberingSeparator(RTL_CONSTASCII_USTRINGPARAM("NumberingSeparator")),
333     sPropertyNumberingType(RTL_CONSTASCII_USTRINGPARAM("NumberingType")),
334     sPropertyOffset(RTL_CONSTASCII_USTRINGPARAM("Offset")),
335     sPropertyOn(RTL_CONSTASCII_USTRINGPARAM("On")),
336     sPropertyPlaceholder(RTL_CONSTASCII_USTRINGPARAM("PlaceHolder")),
337     sPropertyPlaceholderType(RTL_CONSTASCII_USTRINGPARAM("PlaceHolderType")),
338     sPropertyReferenceFieldPart(RTL_CONSTASCII_USTRINGPARAM("ReferenceFieldPart")),
339     sPropertyReferenceFieldSource(RTL_CONSTASCII_USTRINGPARAM("ReferenceFieldSource")),
340     sPropertyReferenceFieldType(RTL_CONSTASCII_USTRINGPARAM("ReferenceFieldType")),
341     sPropertyRevision(RTL_CONSTASCII_USTRINGPARAM("Revision")),
342     sPropertyScriptType(RTL_CONSTASCII_USTRINGPARAM("ScriptType")),
343     sPropertySelectedItem(RTL_CONSTASCII_USTRINGPARAM("SelectedItem")),
344     sPropertySequenceNumber(RTL_CONSTASCII_USTRINGPARAM("SequenceNumber")),
345     sPropertySequenceValue(RTL_CONSTASCII_USTRINGPARAM("SequenceValue")),
346     sPropertySetNumber(RTL_CONSTASCII_USTRINGPARAM("SetNumber")),
347     sPropertySourceName(RTL_CONSTASCII_USTRINGPARAM("SourceName")),
348     sPropertySubType(RTL_CONSTASCII_USTRINGPARAM("SubType")),
349     sPropertyTargetFrame(RTL_CONSTASCII_USTRINGPARAM("TargetFrame")),
350     sPropertyTrueContent(RTL_CONSTASCII_USTRINGPARAM("TrueContent")),
351     sPropertyURL(RTL_CONSTASCII_USTRINGPARAM("URL")),
352     sPropertyURLContent(RTL_CONSTASCII_USTRINGPARAM("URLContent")),
353     sPropertyUserText(RTL_CONSTASCII_USTRINGPARAM("UserText")),
354     sPropertyValue(RTL_CONSTASCII_USTRINGPARAM("Value")),
355     sPropertyVariableName(RTL_CONSTASCII_USTRINGPARAM("VariableName")),
356     sPropertyVariableSubType(RTL_CONSTASCII_USTRINGPARAM("VariableSubtype")),
357       sPropertyHelp(RTL_CONSTASCII_USTRINGPARAM("Help")),
358       sPropertyTooltip(RTL_CONSTASCII_USTRINGPARAM("Tooltip")),
359       sPropertyTextRange(RTL_CONSTASCII_USTRINGPARAM("TextRange")),
360       pCombinedCharactersPropertyState(pCombinedCharState)
361 {
362     SetExportOnlyUsedFieldDeclarations();
363 }
364 
365 XMLTextFieldExport::~XMLTextFieldExport()
366 {
367     delete pCombinedCharactersPropertyState;
368     delete pUsedMasters;
369 }
370 
371 /// get the field ID (as in FieldIDEnum) from XTextField
372 enum FieldIdEnum XMLTextFieldExport::GetFieldID(
373     const Reference<XTextField> & rTextField,
374     const Reference<XPropertySet> & xPropSet)
375 {
376     // get service names for rTextField (via XServiceInfo service)
377     Reference<XServiceInfo> xService(rTextField, UNO_QUERY);
378     const Sequence<OUString> aServices = xService->getSupportedServiceNames();
379     const OUString* pNames = aServices.getConstArray();
380     sal_Int32 nCount = aServices.getLength();
381 
382     OUString sFieldName;    // service name postfix of current field
383 
384     // search for TextField service name
385     while( nCount-- )
386     {
387         if (pNames->matchIgnoreAsciiCase(sServicePrefix))
388         {
389             // TextField found => postfix is field type!
390             sFieldName = pNames->copy(sServicePrefix.getLength());
391             break;
392         }
393 
394         ++pNames;
395     }
396 
397     // if this is not a normal text field, check if its a presentation text field
398     if( sFieldName.getLength() == 0 )
399     {
400         const OUString* pNames2 = aServices.getConstArray();
401         sal_Int32 nCount2 = aServices.getLength();
402         // search for TextField service name
403         while( nCount2-- )
404         {
405             if( 0 == pNames2->compareTo(sPresentationServicePrefix, sPresentationServicePrefix.getLength()))
406             {
407                 // TextField found => postfix is field type!
408                 sFieldName = pNames2->copy(sPresentationServicePrefix.getLength());
409                 break;
410             }
411 
412             ++pNames2;
413         }
414 
415         if( sFieldName.getLength() != 0 )
416         {
417             if( sFieldName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "Header" ) ) == 0 )
418             {
419                 return FIELD_ID_DRAW_HEADER;
420             }
421             else if( sFieldName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "Footer" ) ) == 0 )
422             {
423                 return FIELD_ID_DRAW_FOOTER;
424             }
425             else if( sFieldName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM( "DateTime" ) ) == 0 )
426             {
427                 return FIELD_ID_DRAW_DATE_TIME;
428             }
429         }
430     }
431 
432     // map postfix of service name to field ID
433     DBG_ASSERT(sFieldName.getLength()>0, "no TextField service found!");
434     return MapFieldName(sFieldName, xPropSet);
435 }
436 
437 enum FieldIdEnum XMLTextFieldExport::MapFieldName(
438     const OUString& sFieldName,             // field (master) name
439     const Reference<XPropertySet> & xPropSet)   // for subtype
440 {
441     // we'll proceed in 2 steps:
442     // a) map service name to preliminary FIELD_ID
443     // b) map those prelim. FIELD_IDs that correspond to several field types
444     //    (in our (XML) world) to final FIELD IDs
445 
446 
447     // a) find prelim. FIELD_ID via aFieldServiceMapping
448 
449     // check for non-empty service name
450     DBG_ASSERT(sFieldName.getLength()>0, "no valid service name!");
451     enum FieldIdEnum nToken = FIELD_ID_UNKNOWN;
452     if (sFieldName.getLength() > 0)
453     {
454         // map name to prelim. ID
455         sal_uInt16 nTmp;
456         sal_Bool bRet = GetExport().GetMM100UnitConverter().convertEnum(
457             nTmp, sFieldName, aFieldServiceNameMapping);
458 
459         // check return
460         DBG_ASSERT(bRet, "Unknown field service name encountered!");
461         if (! bRet)
462         {
463             nToken = FIELD_ID_UNKNOWN;
464         }
465         else
466         {
467             nToken = (enum FieldIdEnum)nTmp;
468         }
469     } else {
470         // invalid service name
471         nToken = FIELD_ID_UNKNOWN;
472     }
473 
474     // b) map prelim. to final FIELD_IDs
475     switch (nToken) {
476         case FIELD_ID_VARIABLE_SET:
477             if (GetBoolProperty(sPropertyIsInput, xPropSet))
478             {
479                 nToken = FIELD_ID_VARIABLE_INPUT;
480             }
481             else
482             {
483                 switch (GetIntProperty(sPropertySubType, xPropSet))
484                 {
485                     case SetVariableType::STRING:   // text field
486                     case SetVariableType::VAR:      // num field
487                         nToken = FIELD_ID_VARIABLE_SET;
488                         break;
489                     case SetVariableType::SEQUENCE:
490                         nToken = FIELD_ID_SEQUENCE;
491                         break;
492                     case SetVariableType::FORMULA:
493                     default:
494                         nToken = FIELD_ID_UNKNOWN;
495                         break;
496                 }
497             }
498             break;
499 
500         case FIELD_ID_VARIABLE_GET:
501             switch (GetIntProperty(sPropertySubType, xPropSet))
502             {
503                 case SetVariableType::STRING:   // text field
504                 case SetVariableType::VAR:      // num field
505                     nToken = FIELD_ID_VARIABLE_GET;
506                     break;
507                 case SetVariableType::FORMULA:
508                     nToken = FIELD_ID_EXPRESSION;
509                     break;
510                 case SetVariableType::SEQUENCE:
511                 default:
512                     nToken = FIELD_ID_UNKNOWN;
513                     break;
514             }
515             break;
516 
517         case FIELD_ID_TIME:
518             if (GetBoolProperty(sPropertyIsDate, xPropSet))
519             {
520                 nToken = FIELD_ID_DATE;
521             }
522             break;
523 
524         case FIELD_ID_PAGENUMBER:
525             // NumberingType not available in non-Writer apps
526             if (xPropSet->getPropertySetInfo()->
527                 hasPropertyByName(sPropertyNumberingType))
528             {
529                 if (NumberingType::CHAR_SPECIAL == GetIntProperty(
530                                             sPropertyNumberingType, xPropSet))
531                 {
532                     nToken = FIELD_ID_PAGESTRING;
533                 }
534             }
535             break;
536 
537         case FIELD_ID_DOCINFO_CREATION_TIME:
538             if (GetBoolProperty(sPropertyIsDate, xPropSet))
539             {
540                 nToken = FIELD_ID_DOCINFO_CREATION_DATE;
541             }
542             break;
543 
544         case FIELD_ID_DOCINFO_PRINT_TIME:
545             if (GetBoolProperty(sPropertyIsDate, xPropSet))
546             {
547                 nToken = FIELD_ID_DOCINFO_PRINT_DATE;
548             }
549             break;
550 
551         case FIELD_ID_DOCINFO_SAVE_TIME:
552             if (GetBoolProperty(sPropertyIsDate, xPropSet))
553             {
554                 nToken = FIELD_ID_DOCINFO_SAVE_DATE;
555             }
556             break;
557 
558         case FIELD_ID_REF_REFERENCE:
559             switch (GetInt16Property(sPropertyReferenceFieldSource, xPropSet))
560             {
561                 case ReferenceFieldSource::REFERENCE_MARK:
562                     nToken = FIELD_ID_REF_REFERENCE;
563                     break;
564                 case ReferenceFieldSource::SEQUENCE_FIELD:
565                     nToken = FIELD_ID_REF_SEQUENCE;
566                     break;
567                 case ReferenceFieldSource::BOOKMARK:
568                     nToken = FIELD_ID_REF_BOOKMARK;
569                     break;
570                 case ReferenceFieldSource::FOOTNOTE:
571                     nToken = FIELD_ID_REF_FOOTNOTE;
572                     break;
573                 case ReferenceFieldSource::ENDNOTE:
574                     nToken = FIELD_ID_REF_ENDNOTE;
575                     break;
576                 default:
577                     nToken = FIELD_ID_UNKNOWN;
578                     break;
579             }
580             break;
581 
582         case FIELD_ID_COMBINED_CHARACTERS:
583         case FIELD_ID_SCRIPT:
584         case FIELD_ID_ANNOTATION:
585         case FIELD_ID_BIBLIOGRAPHY:
586         case FIELD_ID_DDE:
587         case FIELD_ID_MACRO:
588         case FIELD_ID_REFPAGE_SET:
589         case FIELD_ID_REFPAGE_GET:
590         case FIELD_ID_COUNT_PAGES:
591         case FIELD_ID_COUNT_PARAGRAPHS:
592         case FIELD_ID_COUNT_WORDS:
593         case FIELD_ID_COUNT_CHARACTERS:
594         case FIELD_ID_COUNT_TABLES:
595         case FIELD_ID_COUNT_GRAPHICS:
596         case FIELD_ID_COUNT_OBJECTS:
597         case FIELD_ID_CONDITIONAL_TEXT:
598         case FIELD_ID_HIDDEN_TEXT:
599         case FIELD_ID_HIDDEN_PARAGRAPH:
600         case FIELD_ID_DOCINFO_CREATION_AUTHOR:
601         case FIELD_ID_DOCINFO_DESCRIPTION:
602         case FIELD_ID_DOCINFO_CUSTOM:
603         case FIELD_ID_DOCINFO_PRINT_AUTHOR:
604         case FIELD_ID_DOCINFO_TITLE:
605         case FIELD_ID_DOCINFO_SUBJECT:
606         case FIELD_ID_DOCINFO_KEYWORDS:
607         case FIELD_ID_DOCINFO_REVISION:
608         case FIELD_ID_DOCINFO_EDIT_DURATION:
609         case FIELD_ID_DOCINFO_SAVE_AUTHOR:
610         case FIELD_ID_TEXT_INPUT:
611         case FIELD_ID_USER_INPUT:
612         case FIELD_ID_AUTHOR:
613         case FIELD_ID_SENDER:
614         case FIELD_ID_PLACEHOLDER:
615         case FIELD_ID_USER_GET:
616         case FIELD_ID_DATABASE_NEXT:
617         case FIELD_ID_DATABASE_SELECT:
618         case FIELD_ID_DATABASE_DISPLAY:
619         case FIELD_ID_DATABASE_NAME:
620         case FIELD_ID_DATABASE_NUMBER:
621         case FIELD_ID_TEMPLATE_NAME:
622         case FIELD_ID_CHAPTER:
623         case FIELD_ID_FILE_NAME:
624         case FIELD_ID_META:
625         case FIELD_ID_SHEET_NAME:
626         case FIELD_ID_MEASURE:
627         case FIELD_ID_URL:
628         case FIELD_ID_TABLE_FORMULA:
629         case FIELD_ID_DROP_DOWN:
630             ; // these field IDs are final
631             break;
632 
633         default:
634             nToken = FIELD_ID_UNKNOWN;
635     }
636 
637     // ... and return final FIELD_ID
638     return nToken;
639 }
640 
641 // is string or numeric field?
642 sal_Bool XMLTextFieldExport::IsStringField(
643     FieldIdEnum nFieldType,
644     const Reference<XPropertySet> & xPropSet)
645 {
646     switch (nFieldType) {
647 
648     case FIELD_ID_VARIABLE_GET:
649     case FIELD_ID_VARIABLE_SET:
650     case FIELD_ID_VARIABLE_INPUT:
651     {
652         // depends on field sub type
653         return ( GetIntProperty(sPropertySubType, xPropSet) ==
654                  SetVariableType::STRING                    );
655     }
656 
657     case FIELD_ID_USER_GET:
658     case FIELD_ID_USER_INPUT:
659     {
660         Reference<XTextField> xTextField(xPropSet, UNO_QUERY);
661         DBG_ASSERT(xTextField.is(), "field is no XTextField!");
662         sal_Bool bRet = GetBoolProperty(sPropertyIsExpression,
663                                         GetMasterPropertySet(xTextField));
664         return !bRet;
665     }
666 
667     case FIELD_ID_META:
668         return 0 > GetIntProperty(sPropertyNumberFormat, xPropSet);
669 
670     case FIELD_ID_DATABASE_DISPLAY:
671         // TODO: depends on... ???
672         // workaround #no-bug#: no data type
673         return 5100 == GetIntProperty(sPropertyNumberFormat, xPropSet);
674 
675     case FIELD_ID_TABLE_FORMULA:
676         // legacy field: always a number field (because it always has
677         // a number format)
678         return sal_False;
679 
680     case FIELD_ID_COUNT_PAGES:
681     case FIELD_ID_COUNT_PARAGRAPHS:
682     case FIELD_ID_COUNT_WORDS:
683     case FIELD_ID_COUNT_CHARACTERS:
684     case FIELD_ID_COUNT_TABLES:
685     case FIELD_ID_COUNT_GRAPHICS:
686     case FIELD_ID_COUNT_OBJECTS:
687     case FIELD_ID_DOCINFO_SAVE_TIME:
688     case FIELD_ID_DOCINFO_SAVE_DATE:
689     case FIELD_ID_DOCINFO_CREATION_DATE:
690     case FIELD_ID_DOCINFO_CREATION_TIME:
691     case FIELD_ID_DOCINFO_PRINT_TIME:
692     case FIELD_ID_DOCINFO_PRINT_DATE:
693     case FIELD_ID_DOCINFO_EDIT_DURATION:
694     case FIELD_ID_DOCINFO_REVISION:
695     case FIELD_ID_DATABASE_NUMBER:
696     case FIELD_ID_EXPRESSION:
697     case FIELD_ID_SEQUENCE:
698     case FIELD_ID_DATE:
699     case FIELD_ID_TIME:
700     case FIELD_ID_PAGENUMBER:
701     case FIELD_ID_REFPAGE_SET:
702     case FIELD_ID_REFPAGE_GET:
703     case FIELD_ID_DOCINFO_CUSTOM:
704         // always number
705         return sal_False;
706 
707     case FIELD_ID_COMBINED_CHARACTERS:
708     case FIELD_ID_BIBLIOGRAPHY:
709     case FIELD_ID_DDE:
710     case FIELD_ID_REF_REFERENCE:
711     case FIELD_ID_REF_SEQUENCE:
712     case FIELD_ID_REF_BOOKMARK:
713     case FIELD_ID_REF_FOOTNOTE:
714     case FIELD_ID_REF_ENDNOTE:
715     case FIELD_ID_MACRO:
716     case FIELD_ID_TEMPLATE_NAME:
717     case FIELD_ID_CHAPTER:
718     case FIELD_ID_FILE_NAME:
719     case FIELD_ID_CONDITIONAL_TEXT:
720     case FIELD_ID_HIDDEN_TEXT:
721     case FIELD_ID_HIDDEN_PARAGRAPH:
722     case FIELD_ID_DOCINFO_CREATION_AUTHOR:
723     case FIELD_ID_DOCINFO_DESCRIPTION:
724     case FIELD_ID_DOCINFO_PRINT_AUTHOR:
725     case FIELD_ID_DOCINFO_TITLE:
726     case FIELD_ID_DOCINFO_SUBJECT:
727     case FIELD_ID_DOCINFO_KEYWORDS:
728     case FIELD_ID_DOCINFO_SAVE_AUTHOR:
729     case FIELD_ID_DATABASE_NAME:
730     case FIELD_ID_TEXT_INPUT:
731     case FIELD_ID_SENDER:
732     case FIELD_ID_AUTHOR:
733     case FIELD_ID_PAGESTRING:
734     case FIELD_ID_SHEET_NAME:
735     case FIELD_ID_MEASURE:
736     case FIELD_ID_URL:
737     case FIELD_ID_DROP_DOWN:
738         // always string:
739         return sal_True;
740 
741     case FIELD_ID_SCRIPT:
742     case FIELD_ID_ANNOTATION:
743     case FIELD_ID_DATABASE_NEXT:
744     case FIELD_ID_DATABASE_SELECT:
745     case FIELD_ID_VARIABLE_DECL:
746     case FIELD_ID_USER_DECL:
747     case FIELD_ID_SEQUENCE_DECL:
748     case FIELD_ID_PLACEHOLDER:
749     case FIELD_ID_UNKNOWN:
750     case FIELD_ID_DRAW_HEADER:
751     case FIELD_ID_DRAW_FOOTER:
752     case FIELD_ID_DRAW_DATE_TIME:
753     default:
754         DBG_ERROR("unkown field type/field has no content");
755         return sal_True; // invalid info; string in case of doubt
756     }
757 }
758 
759 /// export the styles needed by the given field. Called on first pass
760 /// through document
761 void XMLTextFieldExport::ExportFieldAutoStyle(
762     const Reference<XTextField> & rTextField, const sal_Bool bProgress,
763     const sal_Bool bRecursive )
764 {
765     // get property set
766     Reference<XPropertySet> xPropSet(rTextField, UNO_QUERY);
767 
768     // add field master to list of used field masters (if desired)
769     if (NULL != pUsedMasters)
770     {
771         Reference<XDependentTextField> xDepField(rTextField, UNO_QUERY);
772         if (xDepField.is())
773         {
774             Reference<XText> xOurText = rTextField->getAnchor()->getText();
775 
776             map<Reference<XText>, set<OUString> >::iterator aMapIter =
777                 pUsedMasters->find(xOurText);
778 
779             // insert a list for our XText (if necessary)
780             if (aMapIter == pUsedMasters->end())
781             {
782                 set<OUString> aSet;
783                 (*pUsedMasters)[xOurText] = aSet;
784                 aMapIter = pUsedMasters->find(xOurText);
785             }
786 
787             // insert this text field master
788             OUString sFieldMasterName = GetStringProperty(
789                 sPropertyInstanceName, xDepField->getTextFieldMaster());
790             if (sFieldMasterName.getLength() > 0)
791                 aMapIter->second.insert( sFieldMasterName );
792         }
793         // else: no dependent field -> no master -> ignore
794     }
795 
796     // get Field ID
797     FieldIdEnum nToken = GetFieldID(rTextField, xPropSet);
798 
799     // export the character style for all fields
800     // with one exception: combined character fields export their own
801     //                     text style below
802     Reference <XPropertySet> xRangePropSet(rTextField->getAnchor(), UNO_QUERY);
803     if (FIELD_ID_COMBINED_CHARACTERS != nToken)
804     {
805         GetExport().GetTextParagraphExport()->Add(
806             XML_STYLE_FAMILY_TEXT_TEXT, xRangePropSet);
807     }
808 
809     // process special styles for each field (e.g. data styles)
810     switch (nToken) {
811 
812     case FIELD_ID_DATABASE_DISPLAY:
813     {
814         sal_Int32 nFormat = GetIntProperty(sPropertyNumberFormat, xPropSet);
815         // workaround: #no-bug#; see IsStringField(...)
816         if ( (5100 != nFormat) &&
817              !GetBoolProperty(sPropertyIsDataBaseFormat, xPropSet) )
818         {
819                 GetExport().addDataStyle(nFormat);
820         }
821         break;
822     }
823 
824     case FIELD_ID_DATE:
825     case FIELD_ID_TIME:
826         {
827             // date and time fields are always number fields, but the
828             // NumberFormat property is optional (e.g. Calc doesn't
829             // support it)
830             Reference<XPropertySetInfo> xPropSetInfo(
831                 xPropSet->getPropertySetInfo() );
832             if ( xPropSetInfo->hasPropertyByName( sPropertyNumberFormat ) )
833             {
834                 sal_Int32 nFormat =
835                     GetIntProperty(sPropertyNumberFormat, xPropSet);
836 
837                 // nFormat may be -1 for numeric fields that display their
838                 //  variable name. (Maybe this should be a field type, then?)
839                 if (nFormat != -1)
840                 {
841                     if( ! GetOptionalBoolProperty(
842                             sPropertyIsFixedLanguage,
843                             xPropSet, xPropSetInfo, sal_False ) )
844                     {
845                         nFormat =
846                             GetExport().dataStyleForceSystemLanguage(nFormat);
847                     }
848 
849                     GetExport().addDataStyle( nFormat,
850                                               nToken == FIELD_ID_TIME );
851                 }
852             }
853         }
854         break;
855 
856     case FIELD_ID_META:
857         // recurse into content (does not export element, so can be done first)
858         if (bRecursive)
859         {
860             ExportMetaField(xPropSet, true, bProgress);
861         }
862         // fall-through: for the meta-field itself!
863     case FIELD_ID_DOCINFO_PRINT_TIME:
864     case FIELD_ID_DOCINFO_PRINT_DATE:
865     case FIELD_ID_DOCINFO_CREATION_DATE:
866     case FIELD_ID_DOCINFO_CREATION_TIME:
867     case FIELD_ID_DOCINFO_SAVE_TIME:
868     case FIELD_ID_DOCINFO_SAVE_DATE:
869     case FIELD_ID_DOCINFO_EDIT_DURATION:
870     case FIELD_ID_VARIABLE_SET:
871     case FIELD_ID_VARIABLE_GET:
872     case FIELD_ID_VARIABLE_INPUT:
873     case FIELD_ID_USER_GET:
874     case FIELD_ID_EXPRESSION:
875     case FIELD_ID_TABLE_FORMULA:
876     case FIELD_ID_DOCINFO_CUSTOM:
877         // register number format, if this is a numeric field
878         if (! IsStringField(nToken, xPropSet)) {
879 
880             sal_Int32 nFormat =
881                 GetIntProperty(sPropertyNumberFormat, xPropSet);
882 
883             // nFormat may be -1 for numeric fields that display their
884             //  variable name. (Maybe this should be a field type, then?)
885             if (nFormat != -1)
886             {
887                 // handle formats for fixed language fields
888                 // for all these fields (except table formula)
889                 if( ( nToken != FIELD_ID_TABLE_FORMULA ) &&
890                     ! GetOptionalBoolProperty(
891                           sPropertyIsFixedLanguage,
892                           xPropSet, xPropSet->getPropertySetInfo(),
893                           sal_False ) )
894                 {
895                     nFormat =
896                         GetExport().dataStyleForceSystemLanguage(nFormat);
897                 }
898 
899                 GetExport().addDataStyle(nFormat);
900             }
901         }
902         break;
903 
904     case FIELD_ID_COMBINED_CHARACTERS:
905     {
906         // export text style with the addition of the combined characters
907         DBG_ASSERT(NULL != pCombinedCharactersPropertyState,
908                    "need proper PropertyState for combined characters");
909         const XMLPropertyState *aStates[] = { pCombinedCharactersPropertyState, 0 };
910         GetExport().GetTextParagraphExport()->Add(
911             XML_STYLE_FAMILY_TEXT_TEXT, xRangePropSet,
912             aStates);
913         break;
914     }
915 
916     case FIELD_ID_SCRIPT:
917     case FIELD_ID_ANNOTATION:
918     case FIELD_ID_BIBLIOGRAPHY:
919     case FIELD_ID_DDE:
920     case FIELD_ID_REF_REFERENCE:
921     case FIELD_ID_REF_SEQUENCE:
922     case FIELD_ID_REF_BOOKMARK:
923     case FIELD_ID_REF_FOOTNOTE:
924     case FIELD_ID_REF_ENDNOTE:
925     case FIELD_ID_MACRO:
926     case FIELD_ID_REFPAGE_SET:
927     case FIELD_ID_REFPAGE_GET:
928     case FIELD_ID_COUNT_PAGES:
929     case FIELD_ID_COUNT_PARAGRAPHS:
930     case FIELD_ID_COUNT_WORDS:
931     case FIELD_ID_COUNT_CHARACTERS:
932     case FIELD_ID_COUNT_TABLES:
933     case FIELD_ID_COUNT_GRAPHICS:
934     case FIELD_ID_COUNT_OBJECTS:
935     case FIELD_ID_CONDITIONAL_TEXT:
936     case FIELD_ID_HIDDEN_TEXT:
937     case FIELD_ID_HIDDEN_PARAGRAPH:
938     case FIELD_ID_DOCINFO_CREATION_AUTHOR:
939     case FIELD_ID_DOCINFO_DESCRIPTION:
940     case FIELD_ID_DOCINFO_PRINT_AUTHOR:
941     case FIELD_ID_DOCINFO_TITLE:
942     case FIELD_ID_DOCINFO_SUBJECT:
943     case FIELD_ID_DOCINFO_KEYWORDS:
944     case FIELD_ID_DOCINFO_REVISION:
945     case FIELD_ID_DOCINFO_SAVE_AUTHOR:
946     case FIELD_ID_SEQUENCE:
947     case FIELD_ID_PAGENUMBER:
948     case FIELD_ID_PAGESTRING:
949     case FIELD_ID_AUTHOR:
950     case FIELD_ID_SENDER:
951     case FIELD_ID_PLACEHOLDER:
952     case FIELD_ID_USER_INPUT:
953     case FIELD_ID_TEXT_INPUT:
954     case FIELD_ID_DATABASE_NEXT:
955     case FIELD_ID_DATABASE_SELECT:
956     case FIELD_ID_DATABASE_NAME:
957     case FIELD_ID_DATABASE_NUMBER:
958     case FIELD_ID_TEMPLATE_NAME:
959     case FIELD_ID_CHAPTER:
960     case FIELD_ID_FILE_NAME:
961     case FIELD_ID_SHEET_NAME:
962     case FIELD_ID_MEASURE:
963     case FIELD_ID_URL:
964     case FIELD_ID_DROP_DOWN:
965     case FIELD_ID_DRAW_DATE_TIME:
966     case FIELD_ID_DRAW_FOOTER:
967     case FIELD_ID_DRAW_HEADER:
968         ; // no formats for these fields!
969         break;
970 
971     case FIELD_ID_UNKNOWN:
972     default:
973         DBG_ERROR("unkown field type!");
974         // ignore -> no format for unkowns
975         break;
976     }
977 }
978 
979 /// export the given field to XML. Called on second pass through document
980 void XMLTextFieldExport::ExportField(
981     const Reference<XTextField> & rTextField, sal_Bool bProgress )
982 {
983     // get property set
984     Reference<XPropertySet> xPropSet(rTextField, UNO_QUERY);
985 
986     // get property set of range (for the attributes)
987     Reference <XPropertySet> xRangePropSet(rTextField->getAnchor(), UNO_QUERY);
988 
989     // get Field ID
990     enum FieldIdEnum nToken = GetFieldID(rTextField, xPropSet);
991 
992     // special treatment for combined characters field, because it is
993     // exported as a style
994     const XMLPropertyState* aStates[] = { pCombinedCharactersPropertyState, 0 };
995     const XMLPropertyState **pStates =
996                 FIELD_ID_COMBINED_CHARACTERS == nToken
997                     ? aStates
998                     : 0;
999 
1000     // find out whether we need to set the style or hyperlink
1001     sal_Bool bHasHyperlink;
1002     sal_Bool bIsUICharStyle;
1003     sal_Bool bHasAutoStyle;
1004     OUString sStyle = GetExport().GetTextParagraphExport()->
1005         FindTextStyleAndHyperlink( xRangePropSet, bHasHyperlink, bIsUICharStyle,
1006                                    bHasAutoStyle, pStates );
1007     sal_Bool bHasStyle = (sStyle.getLength() > 0);
1008 
1009     // export hyperlink (if we have one)
1010     Reference < XPropertySetInfo > xRangePropSetInfo;
1011     if( bHasHyperlink )
1012     {
1013         Reference<XPropertyState> xRangePropState( xRangePropSet, UNO_QUERY );
1014         xRangePropSetInfo = xRangePropSet->getPropertySetInfo();
1015         bHasHyperlink =
1016             GetExport().GetTextParagraphExport()->addHyperlinkAttributes(
1017                 xRangePropSet, xRangePropState,
1018                 xRangePropSetInfo );
1019     }
1020     SvXMLElementExport aHyperlink( GetExport(), bHasHyperlink,
1021                                    XML_NAMESPACE_TEXT, XML_A,
1022                                    sal_False, sal_False );
1023 
1024     if( bHasHyperlink )
1025     {
1026         // export events (if supported)
1027         OUString sHyperLinkEvents(RTL_CONSTASCII_USTRINGPARAM(
1028             "HyperLinkEvents"));
1029         if (xRangePropSetInfo->hasPropertyByName(sHyperLinkEvents))
1030         {
1031             Any aAny = xRangePropSet->getPropertyValue(sHyperLinkEvents);
1032             Reference<XNameReplace> xName;
1033             aAny >>= xName;
1034             GetExport().GetEventExport().Export(xName, sal_False);
1035         }
1036     }
1037 
1038     {
1039         XMLTextCharStyleNamesElementExport aCharStylesExport(
1040             GetExport(), bIsUICharStyle &&
1041                          GetExport().GetTextParagraphExport()
1042                             ->GetCharStyleNamesPropInfoCache().hasProperty(
1043                                         xRangePropSet, xRangePropSetInfo ), bHasAutoStyle,
1044             xRangePropSet, sPropertyCharStyleNames );
1045 
1046         // export span with style (if necessary)
1047         // (except for combined characters field)
1048         if( bHasStyle )
1049         {
1050             // export <text:span> element
1051             GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME,
1052                             GetExport().EncodeStyleName( sStyle ) );
1053         }
1054         SvXMLElementExport aSpan( GetExport(), bHasStyle,
1055                                   XML_NAMESPACE_TEXT, XML_SPAN,
1056                                   sal_False, sal_False);
1057 
1058         // finally, export the field itself
1059         ExportFieldHelper( rTextField, xPropSet, xRangePropSet, nToken,
1060             bProgress );
1061     }
1062 }
1063 
1064 /// export the given field to XML. Called on second pass through document
1065 void XMLTextFieldExport::ExportFieldHelper(
1066     const Reference<XTextField> & rTextField,
1067     const Reference<XPropertySet> & rPropSet,
1068     const Reference<XPropertySet> &,
1069     enum FieldIdEnum nToken,
1070     sal_Bool bProgress )
1071 {
1072     // get property set info (because some attributes are not support
1073     // in all implementations)
1074     Reference<XPropertySetInfo> xPropSetInfo(rPropSet->getPropertySetInfo());
1075 
1076     OUString sPresentation = rTextField->getPresentation(sal_False);
1077 
1078     // process each field type
1079     switch (nToken) {
1080     case FIELD_ID_AUTHOR:
1081         // author field: fixed, field (sub-)type
1082         ProcessBoolean(XML_FIXED,
1083                        GetBoolProperty(sPropertyIsFixed, rPropSet), sal_True);
1084         ExportElement(MapAuthorFieldName(rPropSet), sPresentation);
1085         break;
1086 
1087     case FIELD_ID_SENDER:
1088         // sender field: fixed, field (sub-)type
1089         ProcessBoolean(XML_FIXED,
1090                        GetBoolProperty(sPropertyIsFixed, rPropSet), sal_True);
1091         ExportElement(MapSenderFieldName(rPropSet), sPresentation);
1092         break;
1093 
1094     case FIELD_ID_PLACEHOLDER:
1095         // placeholder field: type, name, description
1096         ProcessString(XML_PLACEHOLDER_TYPE,
1097                       MapPlaceholderType(
1098                         GetInt16Property(sPropertyPlaceholderType, rPropSet)));
1099         ProcessString(XML_DESCRIPTION,
1100                       GetStringProperty(sPropertyHint,rPropSet), sal_True);
1101         ExportElement(XML_PLACEHOLDER, sPresentation);
1102         break;
1103 
1104     case FIELD_ID_VARIABLE_SET:
1105     {
1106         // variable set field: name, visible, format&value
1107         ProcessString(XML_NAME,
1108                       GetStringProperty(sPropertyVariableName, rPropSet));
1109         ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet),
1110                        sal_False);
1111         ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW,
1112                       GetStringProperty(sPropertyContent, rPropSet),
1113                       sPresentation);
1114         ProcessValueAndType(IsStringField(nToken, rPropSet),
1115                             GetIntProperty(sPropertyNumberFormat, rPropSet),
1116                             GetStringProperty(sPropertyContent, rPropSet),
1117                             sPresentation,
1118                             GetDoubleProperty(sPropertyValue, rPropSet),
1119                             sal_True, sal_True, sal_True,
1120                             ! GetOptionalBoolProperty(
1121                                  sPropertyIsFixedLanguage,
1122                                  rPropSet, xPropSetInfo, sal_False ) );
1123         ExportElement(XML_VARIABLE_SET, sPresentation);
1124         break;
1125     }
1126     case FIELD_ID_VARIABLE_GET:
1127     {
1128         // variable get field: name, format&value
1129         ProcessString(XML_NAME,
1130                       GetStringProperty(sPropertyContent, rPropSet));
1131         sal_Bool bCmd = GetBoolProperty(sPropertyIsShowFormula, rPropSet);
1132         ProcessDisplay(sal_True, bCmd);
1133         // #i81766# for older versions export of the value-type
1134         sal_Bool bExportValueType = !bCmd && ( GetExport().getExportFlags() & EXPORT_SAVEBACKWARDCOMPATIBLE );
1135         // show style, unless name will be shown
1136         ProcessValueAndType(IsStringField(nToken, rPropSet),
1137                             GetIntProperty(sPropertyNumberFormat, rPropSet),
1138                             sEmpty, sEmpty, 0.0, // values not used
1139                             sal_False,
1140                             bExportValueType,
1141                             !bCmd,
1142                             ! GetOptionalBoolProperty(
1143                                  sPropertyIsFixedLanguage,
1144                                  rPropSet, xPropSetInfo, sal_False ) );
1145         ExportElement(XML_VARIABLE_GET, sPresentation);
1146         break;
1147     }
1148     case FIELD_ID_VARIABLE_INPUT:
1149         // variable input field: name, description, format&value
1150         ProcessString(XML_NAME,
1151                       GetStringProperty(sPropertyVariableName, rPropSet));
1152         ProcessString(XML_DESCRIPTION,
1153                       GetStringProperty(sPropertyHint , rPropSet));
1154         ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet),
1155                        sal_False);
1156         ProcessString(XML_FORMULA, XML_NAMESPACE_OOOW,
1157                       GetStringProperty(sPropertyContent, rPropSet),
1158                       sPresentation);
1159         ProcessValueAndType(IsStringField(nToken, rPropSet),
1160                             GetIntProperty(sPropertyNumberFormat, rPropSet),
1161                             GetStringProperty(sPropertyContent, rPropSet),
1162                             sPresentation,
1163                             GetDoubleProperty(sPropertyValue, rPropSet),
1164                             sal_True, sal_True, sal_True,
1165                             ! GetOptionalBoolProperty(
1166                                  sPropertyIsFixedLanguage,
1167                                  rPropSet, xPropSetInfo, sal_False ) );
1168         ExportElement(XML_VARIABLE_INPUT, sPresentation);
1169         break;
1170 
1171     case FIELD_ID_USER_GET:
1172         // user field: name, hidden, style
1173     {
1174         sal_Bool bCmd = GetBoolProperty(sPropertyIsShowFormula, rPropSet);
1175         ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet),
1176                        bCmd);
1177         ProcessValueAndType(IsStringField(nToken, rPropSet),
1178                             GetIntProperty(sPropertyNumberFormat, rPropSet),
1179                             sEmpty, sEmpty, 0.0, // values not used
1180                             sal_False, sal_False, !bCmd,
1181                             ! GetOptionalBoolProperty(
1182                                  sPropertyIsFixedLanguage,
1183                                  rPropSet, xPropSetInfo, sal_False ) );
1184 
1185         // name from FieldMaster
1186         ProcessString(XML_NAME,
1187                       GetStringProperty(sPropertyName,
1188                                         GetMasterPropertySet(rTextField)));
1189         ExportElement(XML_USER_FIELD_GET, sPresentation);
1190         break;
1191     }
1192 
1193     case FIELD_ID_USER_INPUT:
1194         // user input field: name (from FieldMaster), description
1195 //      ProcessString(XML_NAME,
1196 //                    GetStringProperty(sPropertyName,
1197 //                                      GetMasterPropertySet(rTextField)));
1198         ProcessString(XML_NAME,
1199                       GetStringProperty(sPropertyContent, rPropSet));
1200         ProcessString(XML_DESCRIPTION,
1201                       GetStringProperty(sPropertyHint, rPropSet));
1202         ExportElement(XML_USER_FIELD_INPUT, sPresentation);
1203         break;
1204 
1205     case FIELD_ID_SEQUENCE:
1206     {
1207         // sequence field: name, formula, seq-format
1208         OUString sName = GetStringProperty(sPropertyVariableName, rPropSet);
1209         // TODO: use reference name only if actually beeing referenced.
1210         ProcessString(XML_REF_NAME,
1211                       MakeSequenceRefName(
1212                           GetInt16Property(sPropertySequenceValue, rPropSet),
1213                           sName));
1214         ProcessString(XML_NAME, sName);
1215         ProcessString(XML_FORMULA,  XML_NAMESPACE_OOOW,
1216                       GetStringProperty(sPropertyContent, rPropSet),
1217                       sPresentation);
1218         ProcessNumberingType(GetInt16Property(sPropertyNumberingType,
1219                                               rPropSet));
1220         ExportElement(XML_SEQUENCE, sPresentation);
1221         break;
1222     }
1223 
1224     case FIELD_ID_EXPRESSION:
1225     {
1226         // formula field: formula, format&value
1227         sal_Bool bCmd = GetBoolProperty(sPropertyIsShowFormula, rPropSet);
1228         ProcessString(XML_FORMULA,  XML_NAMESPACE_OOOW,
1229                       GetStringProperty(sPropertyContent, rPropSet),
1230                       sPresentation);
1231         ProcessDisplay(sal_True, bCmd);
1232         ProcessValueAndType(IsStringField(nToken, rPropSet),
1233                             GetIntProperty(sPropertyNumberFormat, rPropSet),
1234                             GetStringProperty(sPropertyContent, rPropSet),
1235                             sPresentation,
1236                             GetDoubleProperty(sPropertyValue, rPropSet),
1237                             !bCmd, !bCmd, !bCmd,
1238                             ! GetOptionalBoolProperty(
1239                                  sPropertyIsFixedLanguage,
1240                                  rPropSet, xPropSetInfo, sal_False ) );
1241         ExportElement(XML_EXPRESSION, sPresentation);
1242         break;
1243     }
1244 
1245     case FIELD_ID_TEXT_INPUT:
1246         // text input field: description and string-value
1247         ProcessString(XML_DESCRIPTION,
1248                       GetStringProperty(sPropertyHint, rPropSet));
1249         ProcessString(XML_HELP,
1250                       GetStringProperty(sPropertyHelp, rPropSet), true);
1251         ProcessString(XML_HINT,
1252                       GetStringProperty(sPropertyTooltip, rPropSet), true);
1253         ExportElement(XML_TEXT_INPUT, sPresentation);
1254         break;
1255 
1256     case FIELD_ID_TIME:
1257         // all properties (except IsDate) are optional!
1258         if (xPropSetInfo->hasPropertyByName(sPropertyNumberFormat))
1259         {
1260             ProcessValueAndType(sal_False,
1261                                 GetIntProperty(sPropertyNumberFormat,rPropSet),
1262                                 sEmpty, sEmpty, 0.0, // not used
1263                                 sal_False, sal_False, sal_True,
1264                                 ! GetOptionalBoolProperty(
1265                                     sPropertyIsFixedLanguage,
1266                                     rPropSet, xPropSetInfo, sal_False ),
1267                                 sal_True);
1268         }
1269         if (xPropSetInfo->hasPropertyByName(sPropertyDateTimeValue))
1270         {
1271             // no value -> current time
1272             ProcessDateTime(XML_TIME_VALUE,
1273                             GetDateTimeProperty(sPropertyDateTimeValue,
1274                                                 rPropSet),
1275                             sal_False );
1276         }
1277         if (xPropSetInfo->hasPropertyByName(sPropertyDateTime))
1278         {
1279             // no value -> current time
1280             ProcessDateTime(XML_TIME_VALUE,
1281                             GetDateTimeProperty(sPropertyDateTime,rPropSet),
1282                             sal_False );
1283         }
1284         if (xPropSetInfo->hasPropertyByName(sPropertyIsFixed))
1285         {
1286             ProcessBoolean(XML_FIXED,
1287                            GetBoolProperty(sPropertyIsFixed, rPropSet),
1288                            sal_False);
1289         }
1290         if (xPropSetInfo->hasPropertyByName(sPropertyAdjust))
1291         {
1292             // adjust value given as integer in minutes
1293             ProcessDateTime(XML_TIME_ADJUST,
1294                             GetIntProperty(sPropertyAdjust, rPropSet),
1295                             sal_False, sal_True, sal_True);
1296         }
1297         ExportElement(XML_TIME, sPresentation);
1298         break;
1299 
1300     case FIELD_ID_DATE:
1301         // all properties (except IsDate) are optional!
1302         if (xPropSetInfo->hasPropertyByName(sPropertyNumberFormat))
1303         {
1304             ProcessValueAndType(sal_False,
1305                                 GetIntProperty(sPropertyNumberFormat,rPropSet),
1306                                 sEmpty, sEmpty, 0.0, // not used
1307                                 sal_False, sal_False, sal_True,
1308                                 ! GetOptionalBoolProperty(
1309                                     sPropertyIsFixedLanguage,
1310                                     rPropSet, xPropSetInfo, sal_False ) );
1311         }
1312         if (xPropSetInfo->hasPropertyByName(sPropertyDateTimeValue))
1313         {
1314             // no value -> current date
1315             ProcessDateTime(XML_DATE_VALUE,
1316                             GetDateTimeProperty(sPropertyDateTimeValue,
1317                                                 rPropSet),
1318                             // #96457#: date fields should also save time
1319                             sal_False);
1320         }
1321         // TODO: remove double-handling after SRC614
1322         else if (xPropSetInfo->hasPropertyByName(sPropertyDateTime))
1323         {
1324             ProcessDateTime(XML_DATE_VALUE,
1325                             GetDateTimeProperty(sPropertyDateTime,rPropSet),
1326                             // #96457#: date fields should also save time
1327                             sal_False);
1328         }
1329         if (xPropSetInfo->hasPropertyByName(sPropertyIsFixed))
1330         {
1331             ProcessBoolean(XML_FIXED,
1332                            GetBoolProperty(sPropertyIsFixed, rPropSet),
1333                            sal_False);
1334         }
1335         if (xPropSetInfo->hasPropertyByName(sPropertyAdjust))
1336         {
1337             // adjust value given as number of days
1338             ProcessDateTime(XML_DATE_ADJUST,
1339                             GetIntProperty(sPropertyAdjust, rPropSet),
1340                             sal_True, sal_True, sal_True);
1341         }
1342         ExportElement(XML_DATE, sPresentation);
1343         break;
1344 
1345     case FIELD_ID_PAGENUMBER:
1346         // all properties are optional
1347         if (xPropSetInfo->hasPropertyByName(sPropertyNumberingType))
1348         {
1349             ProcessNumberingType(GetInt16Property(sPropertyNumberingType,
1350                                                   rPropSet));
1351         }
1352         if (xPropSetInfo->hasPropertyByName(sPropertyOffset))
1353         {
1354             sal_Int32 nAdjust = GetIntProperty(sPropertyOffset, rPropSet);
1355 
1356             if (xPropSetInfo->hasPropertyByName(sPropertySubType))
1357             {
1358                 // property SubType used in MapPageNumebrName
1359                 ProcessString(XML_SELECT_PAGE,
1360                               MapPageNumberName(rPropSet, nAdjust));
1361             }
1362             ProcessIntegerDef(XML_PAGE_ADJUST, nAdjust, 0);
1363         }
1364         ExportElement(XML_PAGE_NUMBER, sPresentation);
1365         break;
1366 
1367     case FIELD_ID_PAGESTRING:
1368     {
1369         ProcessString(XML_STRING_VALUE,
1370                       GetStringProperty(sPropertyUserText, rPropSet),
1371                       sPresentation);
1372         sal_Int32 nDummy = 0; // MapPageNumberName need int
1373         ProcessString(XML_SELECT_PAGE, MapPageNumberName(rPropSet, nDummy));
1374         if( 0 == ( GetExport().getExportFlags() & EXPORT_SAVEBACKWARDCOMPATIBLE ) )
1375             ExportElement(XML_PAGE_CONTINUATION, sPresentation);
1376         else
1377             ExportElement(XML_PAGE_CONTINUATION_STRING, sPresentation);
1378         break;
1379     }
1380 
1381     case FIELD_ID_DATABASE_NAME:
1382         ProcessString(XML_TABLE_NAME,
1383                       GetStringProperty(sPropertyDataTableName, rPropSet));
1384         ProcessCommandType(GetIntProperty(sPropertyDataCommandType, rPropSet));
1385         ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet),
1386                        sal_False);
1387         ExportDataBaseElement(XML_DATABASE_NAME, sPresentation,
1388                               rPropSet, xPropSetInfo);
1389         break;
1390 
1391     case FIELD_ID_DATABASE_NUMBER:
1392         ProcessString(XML_TABLE_NAME,
1393                       GetStringProperty(sPropertyDataTableName, rPropSet));
1394         ProcessCommandType(GetIntProperty(sPropertyDataCommandType, rPropSet));
1395         ProcessNumberingType(
1396             GetInt16Property(sPropertyNumberingType,rPropSet));
1397         ProcessInteger(XML_VALUE,
1398                        GetIntProperty(sPropertySetNumber, rPropSet));
1399         ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet),
1400                        sal_False);
1401         ExportDataBaseElement(XML_DATABASE_ROW_NUMBER, sPresentation,
1402                               rPropSet, xPropSetInfo);
1403         break;
1404 
1405     case FIELD_ID_DATABASE_NEXT:
1406         ProcessString(XML_TABLE_NAME,
1407                       GetStringProperty(sPropertyDataTableName, rPropSet));
1408         ProcessCommandType(GetIntProperty(sPropertyDataCommandType, rPropSet));
1409         ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1410                       GetStringProperty(sPropertyCondition, rPropSet));
1411         DBG_ASSERT(sPresentation.equals(sEmpty),
1412                    "Unexpected presentation for database next field");
1413         ExportDataBaseElement(XML_DATABASE_NEXT, OUString(),
1414                               rPropSet, xPropSetInfo);
1415         break;
1416 
1417     case FIELD_ID_DATABASE_SELECT:
1418         ProcessString(XML_TABLE_NAME,
1419                       GetStringProperty(sPropertyDataTableName, rPropSet));
1420         ProcessCommandType(GetIntProperty(sPropertyDataCommandType, rPropSet));
1421         ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1422                       GetStringProperty(sPropertyCondition, rPropSet));
1423         ProcessInteger(XML_ROW_NUMBER,
1424                        GetIntProperty(sPropertySetNumber, rPropSet));
1425         DBG_ASSERT(sPresentation.equals(sEmpty),
1426                    "Unexpected presentation for database select field");
1427         ExportDataBaseElement(XML_DATABASE_ROW_SELECT, OUString(),
1428                               rPropSet, xPropSetInfo);
1429         break;
1430 
1431     case FIELD_ID_DATABASE_DISPLAY:
1432     {
1433         // get database, table and column name from field master
1434         const Reference<XPropertySet> & xMaster = GetMasterPropertySet(rTextField);
1435         ProcessString(XML_TABLE_NAME,
1436                       GetStringProperty(sPropertyDataTableName, xMaster));
1437         ProcessCommandType(GetIntProperty(sPropertyDataCommandType, xMaster));
1438         ProcessString(XML_COLUMN_NAME,
1439                       GetStringProperty(sPropertyDataColumnName, xMaster));
1440         // export number format if available (happens only for numbers!)
1441         if (!GetBoolProperty(sPropertyIsDataBaseFormat, rPropSet))
1442         {
1443             ProcessValueAndType(sal_False,  // doesn't happen for text
1444                                 GetIntProperty(sPropertyNumberFormat,rPropSet),
1445                                 sEmpty, sEmpty, 0.0, // not used
1446                                 sal_False, sal_False, sal_True, sal_False);
1447         }
1448         ProcessDisplay(GetBoolProperty(sPropertyIsVisible, rPropSet),
1449                        sal_False);
1450         ExportDataBaseElement(XML_DATABASE_DISPLAY, sPresentation,
1451                               xMaster, xMaster->getPropertySetInfo());
1452         break;
1453     }
1454 
1455     case FIELD_ID_DOCINFO_REVISION:
1456         ProcessBoolean(XML_FIXED,
1457                        GetBoolProperty(sPropertyIsFixed, rPropSet), sal_False);
1458         ExportElement(MapDocInfoFieldName(nToken), sPresentation);
1459         break;
1460 
1461     case FIELD_ID_DOCINFO_EDIT_DURATION:
1462     case FIELD_ID_DOCINFO_SAVE_TIME:
1463     case FIELD_ID_DOCINFO_CREATION_TIME:
1464     case FIELD_ID_DOCINFO_PRINT_TIME:
1465     case FIELD_ID_DOCINFO_SAVE_DATE:
1466     case FIELD_ID_DOCINFO_CREATION_DATE:
1467     case FIELD_ID_DOCINFO_PRINT_DATE:
1468         ProcessValueAndType(sal_False,
1469                             GetIntProperty(sPropertyNumberFormat, rPropSet),
1470                             sEmpty, sEmpty, 0.0,
1471                             sal_False, sal_False, sal_True,
1472                             ! GetOptionalBoolProperty(
1473                                     sPropertyIsFixedLanguage,
1474                                     rPropSet, xPropSetInfo, sal_False ) );
1475 
1476         // todo: export date/time value, but values not available -> core bug
1477         ProcessBoolean(XML_FIXED,
1478                        GetBoolProperty(sPropertyIsFixed, rPropSet), sal_False);
1479         ExportElement(MapDocInfoFieldName(nToken), sPresentation);
1480         break;
1481 
1482     case FIELD_ID_DOCINFO_CREATION_AUTHOR:
1483     case FIELD_ID_DOCINFO_DESCRIPTION:
1484     case FIELD_ID_DOCINFO_PRINT_AUTHOR:
1485     case FIELD_ID_DOCINFO_TITLE:
1486     case FIELD_ID_DOCINFO_SUBJECT:
1487     case FIELD_ID_DOCINFO_KEYWORDS:
1488     case FIELD_ID_DOCINFO_SAVE_AUTHOR:
1489         if (xPropSetInfo->hasPropertyByName(sPropertyIsFixed))
1490         {
1491             ProcessBoolean(XML_FIXED,
1492                            GetBoolProperty(sPropertyIsFixed, rPropSet), sal_False);
1493         }
1494         ExportElement(MapDocInfoFieldName(nToken), sPresentation);
1495         break;
1496 
1497     case FIELD_ID_DOCINFO_CUSTOM:
1498     {
1499         ProcessValueAndType(sal_False,  // doesn't happen for text
1500                                 GetIntProperty(sPropertyNumberFormat,rPropSet),
1501                                 sEmpty, sEmpty, 0.0, // not used
1502                                 sal_False, sal_False, sal_True,
1503                                 ! GetOptionalBoolProperty(
1504                                     sPropertyIsFixedLanguage,
1505                                     rPropSet, xPropSetInfo, sal_False ));
1506         uno::Any aAny = rPropSet->getPropertyValue( sPropertyName );
1507         ::rtl::OUString sName;
1508         aAny >>= sName;
1509         ProcessString(XML_NAME, sName);
1510         ProcessBoolean(XML_FIXED, GetBoolProperty(sPropertyIsFixed, rPropSet), sal_False);
1511         ExportElement(XML_USER_DEFINED, sPresentation);
1512         break;
1513     }
1514 
1515     case FIELD_ID_COUNT_PAGES:
1516     case FIELD_ID_COUNT_PARAGRAPHS:
1517     case FIELD_ID_COUNT_WORDS:
1518     case FIELD_ID_COUNT_CHARACTERS:
1519     case FIELD_ID_COUNT_TABLES:
1520     case FIELD_ID_COUNT_GRAPHICS:
1521     case FIELD_ID_COUNT_OBJECTS:
1522         // all properties optional (applies to pages only, but I'll do
1523         // it for all for sake of common implementation)
1524         if (xPropSetInfo->hasPropertyByName(sPropertyNumberingType))
1525         {
1526             ProcessNumberingType(GetInt16Property(sPropertyNumberingType,
1527                                                   rPropSet));
1528         }
1529         ExportElement(MapCountFieldName(nToken), sPresentation);
1530         break;
1531 
1532     case FIELD_ID_CONDITIONAL_TEXT:
1533         ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1534                       GetStringProperty(sPropertyCondition, rPropSet));
1535         ProcessString(XML_STRING_VALUE_IF_TRUE,
1536                       GetStringProperty(sPropertyTrueContent, rPropSet));
1537         ProcessString(XML_STRING_VALUE_IF_FALSE,
1538                       GetStringProperty(sPropertyFalseContent, rPropSet));
1539         ProcessBoolean(XML_CURRENT_VALUE,
1540                        GetBoolProperty(sPropertyIsConditionTrue, rPropSet),
1541                        sal_False);
1542         ExportElement(XML_CONDITIONAL_TEXT, sPresentation);
1543         break;
1544 
1545     case FIELD_ID_HIDDEN_TEXT:
1546         ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1547                       GetStringProperty(sPropertyCondition, rPropSet));
1548         ProcessString(XML_STRING_VALUE,
1549                       GetStringProperty(sPropertyContent, rPropSet));
1550         ProcessBoolean(XML_IS_HIDDEN,
1551                        GetBoolProperty(sPropertyIsHidden, rPropSet),
1552                        sal_False);
1553         ExportElement(XML_HIDDEN_TEXT, sPresentation);
1554         break;
1555 
1556     case FIELD_ID_HIDDEN_PARAGRAPH:
1557         ProcessString(XML_CONDITION, XML_NAMESPACE_OOOW,
1558                       GetStringProperty(sPropertyCondition, rPropSet));
1559         ProcessBoolean(XML_IS_HIDDEN,
1560                        GetBoolProperty(sPropertyIsHidden, rPropSet),
1561                        sal_False);
1562         DBG_ASSERT(sPresentation.equals(sEmpty),
1563                    "Unexpected presentation for hidden paragraph field");
1564         ExportElement(XML_HIDDEN_PARAGRAPH);
1565         break;
1566 
1567     case FIELD_ID_TEMPLATE_NAME:
1568         ProcessString(XML_DISPLAY,
1569                       MapTemplateDisplayFormat(
1570                           GetInt16Property(sPropertyFileFormat, rPropSet)));
1571         ExportElement(XML_TEMPLATE_NAME, sPresentation);
1572         break;
1573 
1574     case FIELD_ID_CHAPTER:
1575         ProcessString(XML_DISPLAY,
1576                       MapChapterDisplayFormat(
1577                           GetInt16Property(sPropertyChapterFormat, rPropSet)));
1578         // API numbers 0..9, we number 1..10
1579         ProcessInteger(XML_OUTLINE_LEVEL,
1580                        GetInt8Property(sPropertyLevel, rPropSet) + 1);
1581         ExportElement(XML_CHAPTER, sPresentation);
1582         break;
1583 
1584     case FIELD_ID_FILE_NAME:
1585         // all properties are optional
1586         if (xPropSetInfo->hasPropertyByName(sPropertyFileFormat))
1587         {
1588             ProcessString(XML_DISPLAY,
1589                           MapFilenameDisplayFormat(
1590                              GetInt16Property(sPropertyFileFormat, rPropSet)));
1591         }
1592         if (xPropSetInfo->hasPropertyByName(sPropertyIsFixed))
1593         {
1594             ProcessBoolean(XML_FIXED,
1595                            GetBoolProperty(sPropertyIsFixed, rPropSet),
1596                            sal_False);
1597         }
1598         ExportElement(XML_FILE_NAME, sPresentation);
1599         break;
1600 
1601     case FIELD_ID_REFPAGE_SET:
1602         ProcessBoolean(XML_ACTIVE,
1603                        GetBoolProperty(sPropertyOn, rPropSet), sal_True);
1604         ProcessIntegerDef(XML_PAGE_ADJUST,
1605                        GetInt16Property(sPropertyOffset, rPropSet), 0);
1606         DBG_ASSERT(sPresentation.equals(sEmpty),
1607                    "Unexpected presentation page variable field");
1608         ExportElement(XML_PAGE_VARIABLE_SET);
1609         break;
1610 
1611     case FIELD_ID_REFPAGE_GET:
1612         ProcessNumberingType(
1613             GetInt16Property(sPropertyNumberingType, rPropSet));
1614         ExportElement(XML_PAGE_VARIABLE_GET, sPresentation);
1615         break;
1616 
1617     case FIELD_ID_MACRO:
1618         ExportMacro( rPropSet, sPresentation );
1619         break;
1620 
1621     case FIELD_ID_REF_SEQUENCE:
1622         // reference to sequence: format, name, find value (and element)
1623         // was: if (nSeqNumber != -1) ...
1624         ProcessString(XML_REFERENCE_FORMAT,
1625                       MapReferenceType(GetInt16Property(
1626                           sPropertyReferenceFieldPart, rPropSet)),
1627                       XML_TEMPLATE);
1628         ProcessString(XML_REF_NAME,
1629                       MakeSequenceRefName(
1630                           GetInt16Property(sPropertySequenceNumber, rPropSet),
1631                           GetStringProperty(sPropertySourceName, rPropSet) ) );
1632         ExportElement(
1633             MapReferenceSource(
1634                 GetInt16Property(sPropertyReferenceFieldSource, rPropSet)),
1635             sPresentation);
1636         break;
1637 
1638     case FIELD_ID_REF_REFERENCE:
1639     case FIELD_ID_REF_BOOKMARK:
1640         // reference to bookmarks, references: format, name (and element)
1641         ProcessString(XML_REFERENCE_FORMAT,
1642                       MapReferenceType(GetInt16Property(
1643                           sPropertyReferenceFieldPart, rPropSet)),
1644                       XML_TEMPLATE);
1645         ProcessString(XML_REF_NAME,
1646                       GetStringProperty(sPropertySourceName, rPropSet));
1647         ExportElement(
1648             MapReferenceSource(GetInt16Property(
1649                 sPropertyReferenceFieldSource, rPropSet)),
1650             sPresentation);
1651         break;
1652 
1653     case FIELD_ID_REF_FOOTNOTE:
1654     case FIELD_ID_REF_ENDNOTE:
1655         // reference to end-/footnote: format, generate name, (and element)
1656         GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_NOTE_CLASS,
1657             FIELD_ID_REF_ENDNOTE==nToken ? XML_ENDNOTE : XML_FOOTNOTE );
1658         ProcessString(XML_REFERENCE_FORMAT,
1659                       MapReferenceType(GetInt16Property(
1660                           sPropertyReferenceFieldPart, rPropSet)),
1661                       XML_TEMPLATE);
1662         ProcessString(XML_REF_NAME,
1663                       MakeFootnoteRefName(GetInt16Property(
1664                           sPropertySequenceNumber, rPropSet)));
1665         ExportElement(
1666             MapReferenceSource(GetInt16Property(
1667                 sPropertyReferenceFieldSource, rPropSet)),
1668             sPresentation);
1669         break;
1670 
1671     case FIELD_ID_DDE:
1672         // name from field master
1673         ProcessString(XML_CONNECTION_NAME,
1674 
1675                       GetStringProperty(sPropertyName,
1676                                         GetMasterPropertySet(rTextField)));
1677         ExportElement(XML_DDE_CONNECTION, sPresentation);
1678         break;
1679 
1680     case FIELD_ID_SHEET_NAME:
1681         // name of spreadsheet (Calc only)
1682         ExportElement(XML_SHEET_NAME, sPresentation);
1683         break;
1684 
1685     case FIELD_ID_URL:
1686     {
1687         // this field is a special case because it gets mapped onto a
1688         // hyperlink, rather than one of the regular text field.
1689         ProcessString(XML_HREF, GetExport().GetRelativeReference(GetStringProperty(sPropertyURL, rPropSet)),
1690                       sal_False, XML_NAMESPACE_XLINK);
1691         ProcessString(XML_TARGET_FRAME_NAME,
1692                       GetStringProperty(sPropertyTargetFrame,rPropSet),
1693                       sal_True, XML_NAMESPACE_OFFICE);
1694         SvXMLElementExport aUrlField(rExport, XML_NAMESPACE_TEXT, XML_A,
1695                                      sal_False, sal_False);
1696         GetExport().Characters(sPresentation);
1697         break;
1698     }
1699 
1700     case FIELD_ID_BIBLIOGRAPHY:
1701     {
1702         ProcessBibliographyData(rPropSet);
1703         ExportElement(XML_BIBLIOGRAPHY_MARK, sPresentation);
1704         break;
1705     }
1706 
1707     case FIELD_ID_SCRIPT:
1708         ProcessString(XML_LANGUAGE,
1709                       GetStringProperty(sPropertyScriptType, rPropSet),
1710                       sal_True, XML_NAMESPACE_SCRIPT);
1711         DBG_ASSERT(sPresentation.equals(sEmpty),
1712                    "Unexpected presentation for script field");
1713         if (GetBoolProperty(sPropertyURLContent, rPropSet))
1714         {
1715             ProcessString(XML_HREF,
1716                           GetExport().GetRelativeReference(GetStringProperty(sPropertyContent, rPropSet)),
1717                           sal_False, XML_NAMESPACE_XLINK);
1718             ExportElement(XML_SCRIPT);
1719         }
1720         else
1721         {
1722             ExportElement(XML_SCRIPT,
1723                           GetStringProperty(sPropertyContent, rPropSet));
1724         }
1725         break;
1726 
1727     case FIELD_ID_ANNOTATION:
1728     {
1729         // check for empty presentation (just in case)
1730         DBG_ASSERT(sPresentation.equals(sEmpty),
1731                    "Unexpected presentation for annotation field");
1732 
1733         // annotation element + content
1734         SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_OFFICE,
1735                                  XML_ANNOTATION, sal_False, sal_True);
1736 
1737         // author
1738         OUString aAuthor( GetStringProperty(sPropertyAuthor, rPropSet) );
1739         if( aAuthor.getLength() )
1740         {
1741             SvXMLElementExport aCreatorElem( GetExport(), XML_NAMESPACE_DC,
1742                                               XML_CREATOR, sal_True,
1743                                               sal_False );
1744             GetExport().Characters(aAuthor);
1745         }
1746 
1747         // date time
1748         DateTime aDate( GetDateTimeProperty(sPropertyDateTimeValue, rPropSet) );
1749         {
1750             OUStringBuffer aBuffer;
1751             GetExport().GetMM100UnitConverter().convertDateTime(aBuffer,
1752                                                                 aDate,
1753                                                                 sal_True);
1754             SvXMLElementExport aDateElem( GetExport(), XML_NAMESPACE_DC,
1755                                               XML_DATE, sal_True,
1756                                               sal_False );
1757             GetExport().Characters(aBuffer.makeStringAndClear());
1758         }
1759 
1760         com::sun::star::uno::Reference < com::sun::star::text::XText > xText;
1761         try
1762         {
1763             com::sun::star::uno::Any aRet = rPropSet->getPropertyValue(sPropertyTextRange);
1764             aRet >>= xText;
1765         }
1766         catch ( com::sun::star::uno::Exception& )
1767         {}
1768 
1769         if ( xText.is() )
1770             GetExport().GetTextParagraphExport()->exportText( xText );
1771         else
1772             ProcessParagraphSequence(GetStringProperty(sPropertyContent,rPropSet));
1773         break;
1774     }
1775 
1776     case FIELD_ID_COMBINED_CHARACTERS:
1777     {
1778         // The style with the combined characters attribute has
1779         // already been handled in the ExportField method. So all that
1780         // is left to do now is to export the characters.
1781         GetExport().Characters(sPresentation);
1782         break;
1783     }
1784 
1785     case FIELD_ID_META:
1786     {
1787         ExportMetaField(rPropSet, false, bProgress);
1788         break;
1789     }
1790 
1791     case FIELD_ID_MEASURE:
1792     {
1793         ProcessString(XML_KIND, MapMeasureKind(GetInt16Property(sPropertyMeasureKind, rPropSet)));
1794         ExportElement( XML_MEASURE, sPresentation );
1795         break;
1796     }
1797 
1798     case FIELD_ID_TABLE_FORMULA:
1799         ProcessString( XML_FORMULA,  XML_NAMESPACE_OOOW,
1800                        GetStringProperty(sPropertyContent, rPropSet) );
1801         ProcessDisplay( sal_True,
1802                         GetBoolProperty(sPropertyIsShowFormula, rPropSet),
1803                         sal_True );
1804         ProcessValueAndType( sal_False,
1805                              GetIntProperty(sPropertyNumberFormat, rPropSet),
1806                              sEmpty, sEmpty, 0.0f,
1807                              sal_False, sal_False, sal_True,
1808                              sal_False, sal_False );
1809         ExportElement( XML_TABLE_FORMULA, sPresentation );
1810         break;
1811 
1812     case FIELD_ID_DROP_DOWN:
1813     {
1814         ProcessString(XML_NAME, GetStringProperty(sPropertyName, rPropSet));
1815         ProcessString(XML_HELP,
1816                       GetStringProperty(sPropertyHelp, rPropSet), true);
1817         ProcessString(XML_HINT,
1818                       GetStringProperty(sPropertyTooltip, rPropSet), true);
1819         SvXMLElementExport aElem( GetExport(),
1820                                   XML_NAMESPACE_TEXT, XML_DROPDOWN,
1821                                   sal_False, sal_False );
1822         ProcessStringSequence
1823             (GetStringSequenceProperty( sPropertyItems, rPropSet ),
1824              GetStringProperty( sPropertySelectedItem, rPropSet ) );
1825 
1826         GetExport().Characters( sPresentation );
1827     }
1828     break;
1829 
1830     case FIELD_ID_DRAW_HEADER:
1831     {
1832         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_HEADER, sal_False, sal_False );
1833     }
1834     break;
1835 
1836     case FIELD_ID_DRAW_FOOTER:
1837     {
1838         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_FOOTER, sal_False, sal_False );
1839     }
1840     break;
1841 
1842     case FIELD_ID_DRAW_DATE_TIME:
1843     {
1844         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_PRESENTATION, XML_DATE_TIME, sal_False, sal_False );
1845     }
1846     break;
1847 
1848     case FIELD_ID_UNKNOWN:
1849     default:
1850         DBG_ERROR("unkown field type encountered!");
1851         // always export content
1852         GetExport().Characters(sPresentation);
1853     }
1854 }
1855 
1856 
1857 /// export field declarations / field masters
1858 void XMLTextFieldExport::ExportFieldDeclarations()
1859 {
1860     Reference<XText> xEmptyText;
1861     ExportFieldDeclarations(xEmptyText);
1862 }
1863 
1864 /// export field declarations / field masters
1865 void XMLTextFieldExport::ExportFieldDeclarations(
1866     const Reference<XText> & rText )
1867 {
1868     // store lists for decl elements
1869     vector<OUString>                    aVarName;
1870     vector<OUString>                    aUserName;
1871     vector<OUString>                    aSeqName;
1872     vector<OUString>                    aDdeName;
1873 
1874     // get text fields supplier and field master name access
1875     Reference<XTextFieldsSupplier> xTextFieldsSupp(GetExport().GetModel(),
1876                                                    UNO_QUERY);
1877     if( !xTextFieldsSupp.is() )
1878         return;
1879 
1880     Reference<container::XNameAccess> xFieldMasterNameAccess(
1881         xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY);
1882 
1883     // where to get the text field masters from?
1884     // a) we get a specific XText: then use pUsedMasters
1885     // b) the XText is empty: then export all text fields
1886     Sequence<OUString> aFieldMasters;
1887     if (rText.is())
1888     {
1889         // export only used masters
1890         DBG_ASSERT(NULL != pUsedMasters,
1891                    "field masters must be recorded in order to be "
1892                    "written out separatly" );
1893         if (NULL != pUsedMasters)
1894         {
1895             map<Reference<XText>, set<OUString> > ::iterator aMapIter =
1896                 pUsedMasters->find(rText);
1897             if (aMapIter != pUsedMasters->end())
1898             {
1899                 // found the set of used field masters
1900                 set<OUString> & rOurMasters = aMapIter->second;
1901 
1902                 // copy set to sequence
1903                 aFieldMasters.realloc( rOurMasters.size() );
1904                 sal_Int32 i = 0;
1905                 for( set<OUString>::iterator aSetIter = rOurMasters.begin();
1906                      aSetIter != rOurMasters.end();
1907                      aSetIter++, i++ )
1908                 {
1909                     aFieldMasters[i] = *aSetIter;
1910                 }
1911 
1912                 pUsedMasters->erase(rText);
1913             }
1914             // else: XText not found -> ignore
1915         }
1916         // else: no field masters have been recorded -> ignore
1917     }
1918     else
1919     {
1920         // no XText: export all!
1921         aFieldMasters = xFieldMasterNameAccess->getElementNames();
1922     }
1923 
1924     for(sal_Int32 i=0; i<aFieldMasters.getLength(); i++) {
1925 
1926         // get field master name
1927         OUString sFieldMaster = aFieldMasters[i];
1928 
1929         // workaround for #no-bug#
1930         static const sal_Char sDB[] =
1931             "com.sun.star.text.FieldMaster.DataBase.";
1932         if ( sFieldMaster.matchIgnoreAsciiCaseAsciiL( sDB, sizeof(sDB)-1) )
1933         {
1934             continue;
1935         }
1936 
1937 
1938         OUString sFieldMasterType;
1939         OUString sVarName;
1940         ExplodeFieldMasterName(sFieldMaster, sFieldMasterType, sVarName);
1941 
1942         // get XPropertySet of this field master
1943         Reference<XPropertySet> xPropSet;
1944         Any aAny = xFieldMasterNameAccess->getByName(sFieldMaster);
1945         aAny >>= xPropSet;
1946 
1947         // save interesting field masters
1948         if (0 == sFieldMasterType.compareToAscii(FIELD_SERVICE_SETEXP))
1949         {
1950             sal_Int32 nType = GetIntProperty(sPropertySubType, xPropSet);
1951 
1952             // sequence or variable?
1953             if ( SetVariableType::SEQUENCE == nType )
1954             {
1955                 aSeqName.push_back( sFieldMaster );
1956             }
1957             else
1958             {
1959                 aVarName.push_back( sFieldMaster );
1960             }
1961         }
1962         else if (0 == sFieldMasterType.compareToAscii(FIELD_SERVICE_USER))
1963         {
1964             aUserName.push_back( sFieldMaster );
1965         }
1966         else if (0 == sFieldMasterType.compareToAscii(FIELD_SERVICE_DDE))
1967         {
1968             aDdeName.push_back( sFieldMaster );
1969         }
1970         else
1971         {
1972             ; // ignore
1973         }
1974     }
1975 
1976     // now process fields:
1977 
1978     // variable field masters:
1979     if ( !aVarName.empty() )
1980     {
1981         SvXMLElementExport aElem( GetExport(),
1982                                   XML_NAMESPACE_TEXT,
1983                                   XML_VARIABLE_DECLS,
1984                                   sal_True, sal_True );
1985 
1986         for (vector<OUString>::iterator aVarIter = aVarName.begin();
1987              aVarIter != aVarName.end();
1988              aVarIter++) {
1989 
1990             OUString sName = *aVarIter;
1991 
1992             // get field master property set
1993             Reference<XPropertySet> xPropSet;
1994             Any aAny = xFieldMasterNameAccess->getByName(sName);
1995             aAny >>= xPropSet;
1996 
1997             // field name and type
1998             OUString sFieldMasterType;
1999             OUString sVarName;
2000             ExplodeFieldMasterName(sName, sFieldMasterType, sVarName);
2001 
2002             // determine string/numeric field
2003             sal_Bool bIsString = ( GetIntProperty(sPropertySubType, xPropSet)
2004                                    == SetVariableType::STRING );
2005 
2006             // get dependent field property set
2007             Reference<XPropertySet> xFieldPropSet;
2008             if (GetDependentFieldPropertySet(xPropSet, xFieldPropSet))
2009             {
2010                 // process value and type.
2011                 ProcessValueAndType(
2012                     bIsString,
2013                     GetIntProperty(sPropertyNumberFormat, xFieldPropSet),
2014                     sEmpty, sEmpty, 0.0,
2015                     sal_False, sal_True, sal_False, sal_False);
2016             }
2017             else
2018             {
2019                 // If no dependent field is found, only string and
2020                 // float types can be supported
2021 
2022                 // number format: 0 is default number format for 1st
2023                 // language. should be: getDefaultNumberFormat(Locale)
2024                 // from NumberFormats
2025                 ProcessValueAndType(
2026                     bIsString,
2027                     0, sEmpty, sEmpty, 0.0,
2028                     sal_False, sal_True, sal_False, sal_False);
2029             }
2030 
2031             ProcessString(XML_NAME, sVarName);
2032             ExportElement(XML_VARIABLE_DECL, sal_True);
2033         }
2034     }
2035     // else: no declarations element
2036 
2037     // sequence field masters:
2038     if ( !aSeqName.empty() )
2039     {
2040         SvXMLElementExport aElem( GetExport(),
2041                                   XML_NAMESPACE_TEXT,
2042                                   XML_SEQUENCE_DECLS,
2043                                   sal_True, sal_True );
2044 
2045         for (vector<OUString>::iterator aSeqIter = aSeqName.begin();
2046              aSeqIter != aSeqName.end();
2047              aSeqIter++) {
2048 
2049             OUString sName = *aSeqIter;
2050 
2051             // get field master property set
2052             Reference<XPropertySet> xPropSet;
2053             Any aAny = xFieldMasterNameAccess->getByName(sName);
2054             aAny >>= xPropSet;
2055 
2056             // field name and type
2057             OUString sFieldMasterType;
2058             OUString sVarName;
2059             ExplodeFieldMasterName(sName, sFieldMasterType, sVarName);
2060 
2061             // outline level
2062             sal_Int32 nLevel = 1 + GetIntProperty(
2063                 sPropertyChapterNumberingLevel, xPropSet);
2064             DBG_ASSERT(nLevel >= 0, "illegal outline level");
2065             DBG_ASSERT(nLevel < 127, "possible illegal outline level");
2066             ProcessInteger(XML_DISPLAY_OUTLINE_LEVEL, nLevel);
2067 
2068             // separation character
2069             if (nLevel > 0) {
2070                 ProcessString(XML_SEPARATION_CHARACTER, GetStringProperty(
2071                     sPropertyNumberingSeparator, xPropSet));
2072             }
2073             ProcessString(XML_NAME, sVarName);
2074             ExportElement(XML_SEQUENCE_DECL, sal_True);
2075         }
2076     }
2077     // else: no declarations element
2078 
2079     // user field field masters:
2080     if ( !aUserName.empty() )
2081     {
2082         SvXMLElementExport aElem( GetExport(),
2083                                   XML_NAMESPACE_TEXT,
2084                                   XML_USER_FIELD_DECLS,
2085                                   sal_True, sal_True );
2086 
2087         for (vector<OUString>::iterator aUserIter = aUserName.begin();
2088              aUserIter != aUserName.end();
2089              aUserIter++) {
2090 
2091             OUString sName = *aUserIter;
2092 
2093             // get field master property set
2094             Reference<XPropertySet> xPropSet;
2095             Any aAny = xFieldMasterNameAccess->getByName(sName);
2096             aAny >>= xPropSet;
2097 
2098             // field name and type
2099             OUString sFieldMasterType;
2100             OUString sVarName;
2101             ExplodeFieldMasterName(sName, sFieldMasterType, sVarName);
2102 
2103             if (GetBoolProperty(sPropertyIsExpression, xPropSet))
2104             {
2105                 // expression:
2106                 ProcessValueAndType(
2107                     sal_False,
2108                     0, sEmpty, sEmpty,
2109                     GetDoubleProperty(sPropertyValue, xPropSet),
2110                     sal_True,
2111                     sal_True,
2112                     sal_False,
2113                     sal_False);
2114             }
2115             else
2116             {
2117                 // string: write regardless of default
2118                 ProcessString(XML_VALUE_TYPE, XML_STRING, sal_False,
2119                               XML_NAMESPACE_OFFICE);
2120                 ProcessString(XML_STRING_VALUE,
2121                               GetStringProperty(sPropertyContent, xPropSet),
2122                               sal_False, XML_NAMESPACE_OFFICE );
2123             }
2124             ProcessString(XML_NAME, sVarName);
2125             ExportElement(XML_USER_FIELD_DECL, sal_True);
2126         }
2127     }
2128     // else: no declarations element
2129 
2130     // DDE field field masters:
2131     if ( !aDdeName.empty() )
2132     {
2133         SvXMLElementExport aElem( GetExport(),
2134                                   XML_NAMESPACE_TEXT,
2135                                   XML_DDE_CONNECTION_DECLS,
2136                                   sal_True, sal_True );
2137 
2138         for (vector<OUString>::iterator aDdeIter = aDdeName.begin();
2139              aDdeIter != aDdeName.end();
2140              aDdeIter++)
2141         {
2142             OUString sName = *aDdeIter;
2143 
2144             // get field master property set
2145             Reference<XPropertySet> xPropSet;
2146             Any aAny = xFieldMasterNameAccess->getByName(sName);
2147             aAny >>= xPropSet;
2148 
2149             // check if this connection is being used by a field
2150             Reference<XPropertySet> xDummy;
2151             if (GetDependentFieldPropertySet(xPropSet, xDummy))
2152             {
2153 
2154                 ProcessString(XML_NAME,
2155                               GetStringProperty(sPropertyName, xPropSet),
2156                               sal_False, XML_NAMESPACE_OFFICE);
2157 
2158                 // export elements; can't use ProcessString because
2159                 // elements are in office namespace
2160                 ProcessString(XML_DDE_APPLICATION,
2161                               GetStringProperty(sPropertyDDECommandType,
2162                                                 xPropSet),
2163                               sal_False, XML_NAMESPACE_OFFICE);
2164                 ProcessString(XML_DDE_TOPIC,
2165                               GetStringProperty(sPropertyDDECommandFile,
2166                                                 xPropSet),
2167                               sal_False, XML_NAMESPACE_OFFICE);
2168                 ProcessString(XML_DDE_ITEM,
2169                               GetStringProperty(sPropertyDDECommandElement,
2170                                                 xPropSet),
2171                               sal_False, XML_NAMESPACE_OFFICE);
2172                 sal_Bool bIsAutomaticUpdate = GetBoolProperty(
2173                     sPropertyIsAutomaticUpdate, xPropSet);
2174                 if (bIsAutomaticUpdate)
2175                 {
2176                     GetExport().AddAttribute(XML_NAMESPACE_OFFICE,
2177                                              XML_AUTOMATIC_UPDATE,
2178                                              XML_TRUE);
2179                 }
2180 
2181                 ExportElement(XML_DDE_CONNECTION_DECL, sal_True);
2182             }
2183             // else: no dependent field -> no export of field declaration
2184         }
2185     }
2186     // else: no declarations element
2187 }
2188 
2189 void XMLTextFieldExport::SetExportOnlyUsedFieldDeclarations(
2190     sal_Bool bExportOnlyUsed)
2191 {
2192     delete pUsedMasters;
2193     pUsedMasters = NULL;
2194 
2195     // create used masters set (if none is used)
2196     if (bExportOnlyUsed)
2197         pUsedMasters = new map<Reference<XText>, set<OUString> > ;
2198 }
2199 
2200 void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
2201                                        sal_Bool bAddSpace)
2202 {
2203     // can't call ExportElement(eElementName, const OUString&) with empty
2204     // string because xmlprinter only uses empty tags if no content
2205     // (not even empty content) was written.
2206 
2207     DBG_ASSERT(XML_TOKEN_INVALID != eElementName, "invalid element name!");
2208     if (XML_TOKEN_INVALID != eElementName)
2209     {
2210         // Element
2211         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
2212                                   eElementName, bAddSpace, bAddSpace );
2213     } // else: ignore
2214 }
2215 
2216 void XMLTextFieldExport::ExportElement(enum XMLTokenEnum eElementName,
2217                                        const OUString& sContent,
2218                                        sal_Bool bAddSpace)
2219 {
2220     DBG_ASSERT(eElementName != XML_TOKEN_INVALID, "invalid element name!");
2221     if (eElementName != XML_TOKEN_INVALID)
2222     {
2223         // Element
2224         SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
2225                                   eElementName, bAddSpace, bAddSpace );
2226         // export content
2227         GetExport().Characters(sContent);
2228     } else {
2229         // always export content
2230         GetExport().Characters(sContent);
2231     }
2232 }
2233 
2234 void XMLTextFieldExport::ExportMacro(
2235     const Reference<XPropertySet> & rPropSet,
2236     const OUString& rContent )
2237 {
2238     // some strings we'll need
2239     OUString sEventType( RTL_CONSTASCII_USTRINGPARAM( "EventType" ));
2240     OUString sStarBasic( RTL_CONSTASCII_USTRINGPARAM( "StarBasic" ));
2241     OUString sScript( RTL_CONSTASCII_USTRINGPARAM( "Script" ));
2242     OUString sLibrary( RTL_CONSTASCII_USTRINGPARAM( "Library" ));
2243     OUString sMacroName( RTL_CONSTASCII_USTRINGPARAM( "MacroName" ));
2244     OUString sOnClick( RTL_CONSTASCII_USTRINGPARAM( "OnClick" ));
2245     OUString sPropertyMacroLibrary( RTL_CONSTASCII_USTRINGPARAM( "MacroLibrary" ));
2246     OUString sPropertyMacroName( RTL_CONSTASCII_USTRINGPARAM( "MacroName" ));
2247     OUString sPropertyScriptURL( RTL_CONSTASCII_USTRINGPARAM( "ScriptURL" ));
2248 
2249 
2250     // the description attribute
2251     ProcessString(XML_DESCRIPTION,
2252                   GetStringProperty(sPropertyHint, rPropSet),
2253                   rContent);
2254 
2255     // the element
2256     SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_TEXT,
2257                               XML_EXECUTE_MACRO, sal_False, sal_False );
2258 
2259     // the <office:events>-macro:
2260 
2261     // 1) build sequence of PropertyValues
2262     Sequence<PropertyValue> aSeq;
2263     OUString sName;
2264     rPropSet->getPropertyValue( sPropertyScriptURL ) >>= sName;
2265 
2266     // if the ScriptURL property is not empty then this is a Scripting
2267     // Framework URL, otherwise treat it as a Basic Macro
2268     if (sName.getLength() != 0)
2269     {
2270         aSeq = Sequence<PropertyValue> (2);
2271         PropertyValue* pArr = aSeq.getArray();
2272         pArr[0].Name = sEventType;
2273         pArr[0].Value <<= sScript;
2274         pArr[1].Name = sScript;
2275         pArr[1].Value = rPropSet->getPropertyValue( sPropertyScriptURL );
2276     }
2277     else
2278     {
2279         aSeq = Sequence<PropertyValue> (3);
2280         PropertyValue* pArr = aSeq.getArray();
2281         pArr[0].Name = sEventType;
2282         pArr[0].Value <<= sStarBasic;
2283         pArr[1].Name = sLibrary;
2284         pArr[1].Value = rPropSet->getPropertyValue( sPropertyMacroLibrary );
2285         pArr[2].Name = sMacroName;
2286         pArr[2].Value = rPropSet->getPropertyValue( sPropertyMacroName );
2287     }
2288 
2289     // 2) export the sequence
2290     GetExport().GetEventExport().ExportSingleEvent( aSeq, sOnClick, sal_False );
2291 
2292     // and finally, the field presentation
2293     GetExport().Characters(rContent);
2294 }
2295 
2296 void XMLTextFieldExport::ExportMetaField(
2297     const Reference<XPropertySet> & i_xMeta,
2298     bool i_bAutoStyles, sal_Bool i_bProgress )
2299 {
2300     bool doExport(!i_bAutoStyles); // do not export element if autostyles
2301     // check version >= 1.2
2302     switch (GetExport().getDefaultVersion()) {
2303         case SvtSaveOptions::ODFVER_011: // fall thru
2304         case SvtSaveOptions::ODFVER_010: doExport = false; break;
2305         default: break;
2306     }
2307 
2308     const Reference < XEnumerationAccess > xEA( i_xMeta, UNO_QUERY_THROW );
2309     const Reference < XEnumeration > xTextEnum( xEA->createEnumeration() );
2310 
2311     if (doExport)
2312     {
2313         const Reference<rdf::XMetadatable> xMeta( i_xMeta, UNO_QUERY_THROW );
2314 
2315         // style:data-style-name
2316         ProcessValueAndType(sal_False,
2317             GetIntProperty(sPropertyNumberFormat, i_xMeta),
2318             sEmpty, sEmpty, 0.0, sal_False, sal_False, sal_True,
2319             sal_False, sal_False /*, sal_False*/ );
2320 
2321         // text:meta-field without xml:id is invalid
2322         xMeta->ensureMetadataReference();
2323 
2324         // xml:id for RDF metadata
2325         GetExport().AddAttributeXmlId(xMeta);
2326     }
2327 
2328     SvXMLElementExport aElem( GetExport(), doExport,
2329         XML_NAMESPACE_TEXT, XML_META_FIELD, sal_False, sal_False );
2330 
2331     // recurse to export content
2332     GetExport().GetTextParagraphExport()->
2333         exportTextRangeEnumeration( xTextEnum, i_bAutoStyles, i_bProgress );
2334 }
2335 
2336 /// export all data-style related attributes
2337 void XMLTextFieldExport::ProcessValueAndType(
2338     sal_Bool bIsString,     /// do we process a string or a number?
2339     sal_Int32 nFormatKey,   /// format key for NumberFormatter; inv. if string
2340     const OUString& sContent,   /// string content; possibly invalid
2341     const OUString& sDefault,   /// default string
2342     double fValue,          /// float content; possibly invalid
2343     sal_Bool bExportValue,  /// export value attribute?
2344     sal_Bool bExportValueType,  /// export value-type attribute?
2345     sal_Bool bExportStyle,  /// export style-sttribute?
2346     sal_Bool bForceSystemLanguage, /// export language attributes?
2347     sal_Bool bTimeStyle)    // exporting a time style?
2348 {
2349     // String or number?
2350     if (bIsString)
2351     {
2352 
2353         // string: attributes value-type=string, string-value=...
2354 
2355         if (bExportValue || bExportValueType)
2356         {
2357             XMLNumberFormatAttributesExportHelper::SetNumberFormatAttributes(
2358                 GetExport(), sContent, sDefault, bExportValue);
2359         }
2360 
2361     }
2362     else
2363     {
2364 
2365         // number: value-type=..., value...=..., data-style-name=...
2366 
2367         DBG_ASSERT(bExportValueType || !bExportValue, "value w/o value type not supported!");
2368 
2369         // take care of illegal formats
2370         // (shouldn't happen, but does if document is corrupted)
2371         if (-1 != nFormatKey)
2372         {
2373             if (bExportValue || bExportValueType)
2374             {
2375                 XMLNumberFormatAttributesExportHelper::
2376                     SetNumberFormatAttributes(
2377                         GetExport(), nFormatKey, fValue, bExportValue);
2378             }
2379 
2380             if (bExportStyle)
2381             {
2382                 // don't export language (if desired)
2383                 if( bForceSystemLanguage )
2384                     nFormatKey =
2385                         GetExport().dataStyleForceSystemLanguage( nFormatKey );
2386 
2387                 OUString sDataStyleName =
2388                     GetExport().getDataStyleName(nFormatKey, bTimeStyle);
2389                 if( sDataStyleName.getLength() > 0 )
2390                 {
2391                     GetExport().AddAttribute( XML_NAMESPACE_STYLE,
2392                                               XML_DATA_STYLE_NAME,
2393                                               sDataStyleName );
2394                 } // else: ignore (no valid number format)
2395             }  // else: ignore (no number format)
2396         }
2397     }
2398 }
2399 
2400 
2401 
2402 /// process display related properties
2403 void XMLTextFieldExport::ProcessDisplay(sal_Bool bIsVisible,
2404                                         sal_Bool bIsCommand,
2405                                         sal_Bool bValueDefault)
2406 {
2407     enum XMLTokenEnum eValue;
2408 
2409     if (bIsVisible)
2410     {
2411         eValue = bIsCommand ? XML_FORMULA : XML_VALUE;
2412     }
2413     else
2414     {
2415         eValue = XML_NONE;
2416     }
2417 
2418     // omit attribute if default
2419     if (!bValueDefault || (eValue != XML_VALUE))
2420     {
2421         GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_DISPLAY, eValue);
2422     }
2423 }
2424 
2425 
2426 
2427 /// export boolean property
2428 void XMLTextFieldExport::ProcessBoolean(enum XMLTokenEnum eName,
2429                                         sal_Bool bBool, sal_Bool bDefault)
2430 {
2431     DBG_ASSERT( eName != XML_TOKEN_INVALID, "invalid element token");
2432     if ( XML_TOKEN_INVALID == eName )
2433         return;
2434 
2435     // write attribute (if different than default)
2436     // negate to force 0/1 values (and make sal_Bool comparable)
2437     if ((!bBool) != (!bDefault)) {
2438         GetExport().AddAttribute(XML_NAMESPACE_TEXT, eName,
2439                                  (bBool ? XML_TRUE : XML_FALSE) );
2440     }
2441 }
2442 
2443 
2444 
2445 
2446 /// export string attribute
2447 void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
2448                                        const OUString& sValue,
2449                                        sal_Bool bOmitEmpty,
2450                                        sal_uInt16 nPrefix)
2451 {
2452     DBG_ASSERT( eName != XML_TOKEN_INVALID, "invalid element token");
2453     if ( XML_TOKEN_INVALID == eName )
2454         return;
2455 
2456     // check for empty string, if applicable
2457     if ( bOmitEmpty && (sValue.getLength()==0) )
2458         return;
2459 
2460     // write attribute
2461     GetExport().AddAttribute(nPrefix, eName, sValue);
2462 }
2463 
2464 void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
2465                                        sal_uInt16 nValuePrefix,
2466                                        const OUString& sValue,
2467                                        sal_Bool bOmitEmpty,
2468                                        sal_uInt16 nPrefix)
2469 {
2470     OUString sQValue =
2471         GetExport().GetNamespaceMap().GetQNameByKey( nValuePrefix, sValue, sal_False );
2472     ProcessString( eName, sQValue, bOmitEmpty, nPrefix );
2473 }
2474 
2475 /// export a string attribute
2476 void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
2477                                        const ::rtl::OUString& sValue,
2478                                        const ::rtl::OUString& sDefault,
2479                                        sal_uInt16 nPrefix)
2480 {
2481     if (sValue != sDefault)
2482     {
2483         ProcessString(eName, sValue, sal_False, nPrefix);
2484     }
2485 }
2486 
2487 /// export a string attribute
2488 void XMLTextFieldExport::ProcessString(enum XMLTokenEnum eName,
2489                                        sal_uInt16 nValuePrefix,
2490                                        const ::rtl::OUString& sValue,
2491                                        const ::rtl::OUString& sDefault,
2492                                        sal_uInt16 nPrefix)
2493 {
2494     if (sValue != sDefault)
2495     {
2496         ProcessString(eName, nValuePrefix, sValue, sal_False, nPrefix);
2497     }
2498 }
2499 
2500 
2501 /// export string attribute
2502 void XMLTextFieldExport::ProcessString(
2503     enum XMLTokenEnum eName,
2504     enum XMLTokenEnum eValue,
2505     sal_Bool bOmitEmpty,
2506     sal_uInt16 nPrefix)
2507 {
2508     DBG_ASSERT( eName != XML_TOKEN_INVALID, "invalid element token" );
2509     DBG_ASSERT( bOmitEmpty || (eValue != XML_TOKEN_INVALID),
2510                 "invalid value token" );
2511     if ( XML_TOKEN_INVALID == eName )
2512         return;
2513 
2514     // check for empty string, if applicable
2515     if (bOmitEmpty && (eValue == XML_TOKEN_INVALID))
2516         return;
2517 
2518     GetExport().AddAttribute(nPrefix, eName, eValue);
2519 }
2520 
2521 /// export a string attribute
2522 void XMLTextFieldExport::ProcessString(
2523     enum XMLTokenEnum eName,
2524     enum XMLTokenEnum eValue,
2525     enum XMLTokenEnum eDefault,
2526     sal_uInt16 nPrefix)
2527 {
2528     if ( eValue != eDefault )
2529         ProcessString( eName, eValue, sal_False, nPrefix);
2530 }
2531 
2532 
2533 /// export a string as a sequence of paragraphs
2534 void XMLTextFieldExport::ProcessParagraphSequence(
2535     const ::rtl::OUString& sParagraphSequence)
2536 {
2537     // iterate over all string-pieces separated by return (0x0a) and
2538     // put each inside a paragraph element.
2539     SvXMLTokenEnumerator aEnumerator(sParagraphSequence, sal_Char(0x0a));
2540     OUString aSubString;
2541     while (aEnumerator.getNextToken(aSubString))
2542     {
2543         SvXMLElementExport aParagraph(
2544             GetExport(), XML_NAMESPACE_TEXT, XML_P, sal_True, sal_False);
2545         GetExport().Characters(aSubString);
2546     }
2547 }
2548 
2549 // export an integer attribute
2550 void XMLTextFieldExport::ProcessInteger(enum XMLTokenEnum eName,
2551                                         sal_Int32 nNum)
2552 {
2553     DBG_ASSERT( eName != XML_TOKEN_INVALID, "invalid element token");
2554     if ( XML_TOKEN_INVALID == eName )
2555         return;
2556 
2557     GetExport().AddAttribute(XML_NAMESPACE_TEXT, eName,
2558                              OUString::valueOf(nNum));
2559 }
2560 
2561 /// export an integer attribute, omit if default
2562 void XMLTextFieldExport::ProcessIntegerDef(enum XMLTokenEnum eName,
2563                                         sal_Int32 nNum, sal_Int32 nDefault)
2564 {
2565     if (nNum != nDefault)
2566         ProcessInteger(eName, nNum);
2567 }
2568 
2569 
2570 
2571 /// export a numbering type
2572 void XMLTextFieldExport::ProcessNumberingType(sal_Int16 nNumberingType)
2573 {
2574     // process only if real format (not: like page descriptor)
2575     if (NumberingType::PAGE_DESCRIPTOR != nNumberingType)
2576     {
2577         OUStringBuffer sTmp( 10 );
2578         // number type: num format
2579         GetExport().GetMM100UnitConverter().convertNumFormat( sTmp,
2580                                                               nNumberingType );
2581         GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_FORMAT,
2582                                       sTmp.makeStringAndClear() );
2583         // and letter sync, if applicable
2584         GetExport().GetMM100UnitConverter().convertNumLetterSync( sTmp,
2585                                                               nNumberingType );
2586 
2587         if (sTmp.getLength())
2588         {
2589             GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_NUM_LETTER_SYNC,
2590                                      sTmp.makeStringAndClear() );
2591         }
2592     }
2593     // else: like page descriptor => ignore
2594 }
2595 
2596 
2597 /// export a date, time, or duration
2598 void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
2599                                          double dValue,
2600                                          sal_Bool bIsDate,
2601                                          sal_Bool bIsDuration,
2602                                          sal_Bool bOmitDurationIfZero,
2603                                          sal_uInt16 nPrefix)
2604 {
2605     // truncate for date granularity
2606     if (bIsDate)
2607     {
2608         dValue = ::rtl::math::approxFloor(dValue);
2609     }
2610 
2611     OUStringBuffer aBuffer;
2612     if (bIsDuration)
2613     {
2614         // date/time durationM handle bOmitDurationIfZero
2615         if (!bOmitDurationIfZero || !::rtl::math::approxEqual(dValue, 0.0))
2616         {
2617             rExport.GetMM100UnitConverter().convertTime(aBuffer, dValue);
2618         }
2619     }
2620     else
2621     {
2622         // date/time value
2623         rExport.GetMM100UnitConverter().convertDateTime(aBuffer, dValue);
2624     }
2625 
2626     // output attribute
2627     ProcessString(eName, aBuffer.makeStringAndClear(), sal_True, nPrefix);
2628 }
2629 
2630 /// export a date or time
2631 void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
2632                                          const DateTime& rTime,
2633                                          sal_Bool bIsDate,
2634                                          sal_uInt16 nPrefix)
2635 {
2636     OUStringBuffer aBuffer;
2637 
2638     DateTime aDateTime(rTime);
2639 
2640     // truncate dates
2641     if(bIsDate)
2642     {
2643         aDateTime.HundredthSeconds = 0;
2644         aDateTime.Seconds = 0;
2645         aDateTime.Minutes = 0;
2646         aDateTime.Hours = 0;
2647     }
2648 
2649     // date/time value
2650     rExport.GetMM100UnitConverter().convertDateTime(aBuffer, aDateTime);
2651 
2652     // output attribute
2653     ProcessString(eName, aBuffer.makeStringAndClear(), sal_True, nPrefix);
2654 }
2655 
2656 /// export date according to ISO 8601
2657 void XMLTextFieldExport::ProcessDate(
2658     enum XMLTokenEnum eName,
2659     const ::com::sun::star::util::Date& rDate,
2660     sal_uInt16 nPrefix)
2661 {
2662     // the easiest way: delegate to ProcessDateTime (as date)
2663     DateTime aDateTime;
2664     aDateTime.Day = rDate.Day;
2665     aDateTime.Month = rDate.Month;
2666     aDateTime.Year = rDate.Year;
2667     ProcessDateTime(eName, aDateTime, sal_True, nPrefix);
2668 }
2669 
2670 
2671 /// export a date, time, or duration
2672 void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName,
2673                                          sal_Int32 nMinutes,
2674                                          sal_Bool bIsDate,
2675                                          sal_Bool bIsDuration,
2676                                          sal_Bool bOmitDurationIfZero,
2677                                          sal_uInt16 nPrefix)
2678 {
2679     // handle bOmitDurationIfZero here, because we can precisely compare ints
2680     if (!(bIsDuration && bOmitDurationIfZero && (nMinutes==0)))
2681     {
2682         ProcessDateTime(eName, (double)nMinutes / (double)(24*60),
2683                         bIsDate, bIsDuration, bOmitDurationIfZero, nPrefix);
2684     }
2685 }
2686 
2687 
2688 SvXMLEnumMapEntry __READONLY_DATA aBibliographyDataTypeMap[] =
2689 {
2690     { XML_ARTICLE,          BibliographyDataType::ARTICLE },
2691     { XML_BOOK,             BibliographyDataType::BOOK },
2692     { XML_BOOKLET,          BibliographyDataType::BOOKLET },
2693     { XML_CONFERENCE,       BibliographyDataType::CONFERENCE },
2694     { XML_CUSTOM1,          BibliographyDataType::CUSTOM1 },
2695     { XML_CUSTOM2,          BibliographyDataType::CUSTOM2 },
2696     { XML_CUSTOM3,          BibliographyDataType::CUSTOM3 },
2697     { XML_CUSTOM4,          BibliographyDataType::CUSTOM4 },
2698     { XML_CUSTOM5,          BibliographyDataType::CUSTOM5 },
2699     { XML_EMAIL,            BibliographyDataType::EMAIL },
2700     { XML_INBOOK,           BibliographyDataType::INBOOK },
2701     { XML_INCOLLECTION,     BibliographyDataType::INCOLLECTION },
2702     { XML_INPROCEEDINGS,    BibliographyDataType::INPROCEEDINGS },
2703     { XML_JOURNAL,          BibliographyDataType::JOURNAL },
2704     { XML_MANUAL,           BibliographyDataType::MANUAL },
2705     { XML_MASTERSTHESIS,    BibliographyDataType::MASTERSTHESIS },
2706     { XML_MISC,             BibliographyDataType::MISC },
2707     { XML_PHDTHESIS,        BibliographyDataType::PHDTHESIS },
2708     { XML_PROCEEDINGS,      BibliographyDataType::PROCEEDINGS },
2709     { XML_TECHREPORT,       BibliographyDataType::TECHREPORT },
2710     { XML_UNPUBLISHED,      BibliographyDataType::UNPUBLISHED },
2711     { XML_WWW,              BibliographyDataType::WWW },
2712     { XML_TOKEN_INVALID, 0 }
2713 };
2714 
2715 
2716 
2717 void XMLTextFieldExport::ProcessBibliographyData(
2718     const Reference<XPropertySet>& rPropSet)
2719 {
2720     // get the values
2721     Any aAny = rPropSet->getPropertyValue(sPropertyFields);
2722     Sequence<PropertyValue> aValues;
2723     aAny >>= aValues;
2724 
2725     // one attribute per value (unless empty)
2726     sal_Int32 nLength = aValues.getLength();
2727     for (sal_Int32 i = 0; i < nLength; i++)
2728     {
2729         if (aValues[i].Name.equalsAsciiL("BibiliographicType",
2730                                          sizeof("BibiliographicType")-1))
2731         {
2732             sal_Int16 nTypeId = 0;
2733             aValues[i].Value >>= nTypeId;
2734             OUStringBuffer sBuf;
2735 
2736             if (SvXMLUnitConverter::convertEnum(sBuf, nTypeId,
2737                                                 aBibliographyDataTypeMap))
2738             {
2739                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
2740                                      XML_BIBLIOGRAPHY_TYPE,
2741                                      sBuf.makeStringAndClear());
2742             }
2743             // else: ignore this argument
2744         }
2745         else
2746         {
2747             OUString sStr;
2748             aValues[i].Value >>= sStr;
2749 
2750             if (sStr.getLength() > 0)
2751             {
2752                 rExport.AddAttribute(XML_NAMESPACE_TEXT,
2753                                      MapBibliographyFieldName(aValues[i].Name),
2754                                      sStr);
2755             }
2756         }
2757     }
2758 }
2759 
2760 /// export CommandTypeAttribute
2761 void XMLTextFieldExport::ProcessCommandType(
2762     sal_Int32 nCommandType)
2763 {
2764     enum XMLTokenEnum eToken = XML_TOKEN_INVALID;
2765     switch( nCommandType )
2766     {
2767         case sdb::CommandType::TABLE:   eToken = XML_TABLE; break;
2768         case sdb::CommandType::QUERY:   eToken = XML_QUERY; break;
2769         case sdb::CommandType::COMMAND: eToken = XML_COMMAND; break;
2770     }
2771 
2772     if( eToken != XML_TOKEN_INVALID )
2773         rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_TABLE_TYPE, eToken );
2774 }
2775 
2776 
2777 void XMLTextFieldExport::ProcessStringSequence(
2778     const Sequence<OUString>& rSequence,
2779     const OUString sSelected )
2780 {
2781     // find selected element
2782     sal_Int32 nSelected = -1;
2783     sal_Int32 nLength = rSequence.getLength();
2784     const OUString* pSequence = rSequence.getConstArray();
2785     for( sal_Int32 i = 0; i < nLength; i++ )
2786     {
2787         if( pSequence[i] == sSelected )
2788             nSelected = i;
2789     }
2790 
2791     // delegate to ProcessStringSequence(OUString,sal_Int32)
2792     ProcessStringSequence( rSequence, nSelected );
2793 }
2794 
2795 void XMLTextFieldExport::ProcessStringSequence(
2796     const Sequence<OUString>& rSequence,
2797     sal_Int32 nSelected )
2798 {
2799     sal_Int32 nLength = rSequence.getLength();
2800     const OUString* pSequence = rSequence.getConstArray();
2801     for( sal_Int32 i = 0; i < nLength; i++ )
2802     {
2803         if( i == nSelected )
2804             rExport.AddAttribute( XML_NAMESPACE_TEXT,
2805                                   XML_CURRENT_SELECTED, XML_TRUE );
2806         rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_VALUE, pSequence[i] );
2807         SvXMLElementExport aElement( rExport, XML_NAMESPACE_TEXT, XML_LABEL,
2808                                      sal_False, sal_False );
2809     }
2810 }
2811 
2812 void XMLTextFieldExport::ExportDataBaseElement(
2813     enum XMLTokenEnum eElementName,
2814     const OUString& sPresentation,
2815     const Reference<XPropertySet>& rPropertySet,
2816     const Reference<XPropertySetInfo>& rPropertySetInfo )
2817 {
2818     DBG_ASSERT( eElementName != XML_TOKEN_INVALID, "need token" );
2819     DBG_ASSERT( rPropertySet.is(), "need property set" );
2820     DBG_ASSERT( rPropertySetInfo.is(), "need property set info" );
2821 
2822     // get database properties
2823     OUString sDataBaseName;
2824     OUString sDataBaseURL;
2825     OUString sStr;
2826     if( ( rPropertySet->getPropertyValue( sPropertyDataBaseName ) >>= sStr )
2827         && ( sStr.getLength() > 0 ) )
2828     {
2829         sDataBaseName = sStr;
2830     }
2831     else if( rPropertySetInfo->hasPropertyByName( sPropertyDataBaseURL ) &&
2832              (rPropertySet->getPropertyValue( sPropertyDataBaseURL ) >>= sStr) &&
2833              (sStr.getLength() > 0) )
2834     {
2835         sDataBaseURL = sStr;
2836     }
2837 
2838     // add database name property (if present)
2839     if( sDataBaseName.getLength() > 0 )
2840         rExport.AddAttribute( XML_NAMESPACE_TEXT, XML_DATABASE_NAME,
2841                               sDataBaseName );
2842     SvXMLElementExport aDataBaseElement( GetExport(),
2843                                          XML_NAMESPACE_TEXT, eElementName,
2844                                          sal_False, sal_False );
2845 
2846     // write URL as children
2847     if( sDataBaseURL.getLength() > 0 )
2848     {
2849         rExport.AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sDataBaseURL );
2850         SvXMLElementExport aDataSourceElement(
2851             GetExport(), XML_NAMESPACE_FORM, XML_CONNECTION_RESOURCE,
2852             sal_False, sal_False );
2853     }
2854 
2855     // write presentation
2856     rExport.Characters( sPresentation );
2857 }
2858 
2859 
2860 
2861 // explode a field master name into field type and field name
2862 sal_Bool XMLTextFieldExport::ExplodeFieldMasterName(
2863     const OUString& sMasterName, OUString& sFieldType, OUString& sVarName)
2864 {
2865     sal_Int32 nLength = sFieldMasterPrefix.getLength();
2866     sal_Int32 nSeparator = sMasterName.indexOf('.', nLength);
2867     sal_Bool bReturn = sal_True;
2868 
2869 #ifdef DBG_UTIL
2870     // check for service name
2871     bReturn &= (0 == sFieldMasterPrefix.compareTo(sMasterName, nLength));
2872 #endif
2873 
2874     // '.' found?
2875     if (nSeparator <= nLength) {
2876         nSeparator = sMasterName.getLength();
2877         DBG_WARNING("no field var name!");
2878         bReturn = sal_False;
2879     }
2880     else
2881     {
2882         sFieldType = sMasterName.copy(nLength, nSeparator-nLength);
2883         sVarName = sMasterName.copy(nSeparator+1);
2884     }
2885 
2886     return bReturn;
2887 }
2888 
2889 
2890 // for XDependentTextFields, get PropertySet of FieldMaster
2891 Reference<XPropertySet> XMLTextFieldExport::GetMasterPropertySet(
2892     const Reference<XTextField> & rTextField)
2893 {
2894     // name, value => get Property set of TextFieldMaster
2895     Reference<XDependentTextField> xDep(rTextField, UNO_QUERY);
2896     return xDep->getTextFieldMaster();
2897 }
2898 
2899 // get PropertySet of (any; the first) dependent field
2900 sal_Bool XMLTextFieldExport::GetDependentFieldPropertySet(
2901     const Reference<XPropertySet> & xMaster,
2902     Reference<XPropertySet> & xField)
2903 {
2904     Any aAny;
2905     Sequence<Reference<XDependentTextField> > aFields;
2906     aAny = xMaster->getPropertyValue(sPropertyDependentTextFields);
2907     aAny >>= aFields;
2908 
2909     // any fields?
2910     if (aFields.getLength() > 0)
2911     {
2912         // get first one and return
2913         Reference<XDependentTextField> xTField = aFields[0];
2914         xField = Reference<XPropertySet>(xTField, UNO_QUERY);
2915         DBG_ASSERT(xField.is(),
2916                   "Surprisinlgy, this TextField refuses to be a PropertySet!");
2917         return sal_True;
2918     }
2919     else
2920     {
2921         return sal_False;
2922     }
2923 }
2924 
2925 
2926 /// map placeholder type
2927 enum XMLTokenEnum XMLTextFieldExport::MapPlaceholderType(sal_uInt16 nType)
2928 {
2929     enum XMLTokenEnum eType = XML_TEXT;
2930 
2931     switch (nType)
2932     {
2933         case PlaceholderType::TEXT:
2934             eType = XML_TEXT;
2935             break;
2936 
2937         case PlaceholderType::TABLE:
2938             eType = XML_TABLE;
2939             break;
2940 
2941         case PlaceholderType::TEXTFRAME:
2942             eType = XML_TEXT_BOX;
2943             break;
2944 
2945         case PlaceholderType::GRAPHIC:
2946             eType = XML_IMAGE;
2947             break;
2948 
2949         case PlaceholderType::OBJECT:
2950             eType = XML_OBJECT;
2951             break;
2952 
2953         default:
2954             // unkown placeholder: XML_TEXT
2955             DBG_ERROR("unkown placeholder type");
2956     }
2957 
2958     return eType;
2959 }
2960 
2961 
2962 /// element name for author fields
2963 enum XMLTokenEnum XMLTextFieldExport::MapAuthorFieldName(
2964     const Reference<XPropertySet> & xPropSet)
2965 {
2966     // Initalen oder voller Name?
2967     return GetBoolProperty(sPropertyFullName, xPropSet)
2968         ? XML_AUTHOR_NAME : XML_AUTHOR_INITIALS;
2969 }
2970 
2971 enum XMLTokenEnum XMLTextFieldExport::MapPageNumberName(
2972     const Reference<XPropertySet> & xPropSet,
2973     sal_Int32& nOffset)
2974 {
2975     enum XMLTokenEnum eName = XML_TOKEN_INVALID;
2976     PageNumberType ePage;
2977     Any aAny = xPropSet->getPropertyValue(sPropertySubType);
2978     ePage = *(PageNumberType*)aAny.getValue();
2979 
2980     switch (ePage)
2981     {
2982         case PageNumberType_PREV:
2983             eName = XML_PREVIOUS;
2984             nOffset += 1;
2985             break;
2986         case PageNumberType_CURRENT:
2987             eName = XML_CURRENT;
2988             break;
2989         case PageNumberType_NEXT:
2990             eName = XML_NEXT;
2991             nOffset -= 1;
2992             break;
2993         default:
2994             DBG_ERROR("unknown page number type");
2995             eName = XML_TOKEN_INVALID;
2996             break;
2997     }
2998 
2999     return eName;
3000 }
3001 
3002 /// map TemplateDisplayFormat to XML
3003 enum XMLTokenEnum XMLTextFieldExport::MapTemplateDisplayFormat(sal_Int16 nFormat)
3004 {
3005     enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3006 
3007     switch (nFormat)
3008     {
3009         case TemplateDisplayFormat::FULL:
3010             eName = XML_FULL;
3011             break;
3012         case TemplateDisplayFormat::PATH:
3013             eName = XML_PATH;
3014             break;
3015         case TemplateDisplayFormat::NAME:
3016             eName = XML_NAME;
3017             break;
3018         case TemplateDisplayFormat::NAME_AND_EXT:
3019             eName = XML_NAME_AND_EXTENSION;
3020             break;
3021         case TemplateDisplayFormat::AREA:
3022             eName = XML_AREA;
3023             break;
3024         case TemplateDisplayFormat::TITLE:
3025             eName = XML_TITLE;
3026             break;
3027         default:
3028             DBG_ERROR("unknown template display format");
3029             eName = XML_TOKEN_INVALID;
3030             break;
3031     }
3032 
3033     return eName;
3034 }
3035 
3036 /// map count/statistics field token to XML name
3037 enum XMLTokenEnum XMLTextFieldExport::MapCountFieldName(FieldIdEnum nToken)
3038 {
3039     enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
3040 
3041     switch (nToken)
3042     {
3043         case FIELD_ID_COUNT_PAGES:
3044             eElement = XML_PAGE_COUNT;
3045             break;
3046         case FIELD_ID_COUNT_PARAGRAPHS:
3047             eElement = XML_PARAGRAPH_COUNT;
3048             break;
3049         case FIELD_ID_COUNT_WORDS:
3050             eElement = XML_WORD_COUNT;
3051             break;
3052         case FIELD_ID_COUNT_CHARACTERS:
3053             eElement = XML_CHARACTER_COUNT;
3054             break;
3055         case FIELD_ID_COUNT_TABLES:
3056             eElement = XML_TABLE_COUNT;
3057             break;
3058         case FIELD_ID_COUNT_GRAPHICS:
3059             eElement = XML_IMAGE_COUNT;
3060             break;
3061         case FIELD_ID_COUNT_OBJECTS:
3062             eElement = XML_OBJECT_COUNT;
3063             break;
3064         default:
3065             DBG_ERROR("no count field token");
3066             eElement = XML_TOKEN_INVALID;
3067             break;
3068     }
3069 
3070     return eElement;
3071 }
3072 
3073 /// map ChapterDisplayFormat to XML string
3074 enum XMLTokenEnum XMLTextFieldExport::MapChapterDisplayFormat(sal_Int16 nFormat)
3075 {
3076     enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3077 
3078     switch (nFormat)
3079     {
3080         case ChapterFormat::NAME:
3081             eName = XML_NAME;
3082             break;
3083         case ChapterFormat::NUMBER:
3084             eName = XML_NUMBER;
3085             break;
3086         case ChapterFormat::NAME_NUMBER:
3087             eName = XML_NUMBER_AND_NAME;
3088             break;
3089         case ChapterFormat::NO_PREFIX_SUFFIX:
3090             eName = XML_PLAIN_NUMBER_AND_NAME;
3091             break;
3092         case ChapterFormat::DIGIT:
3093             eName = XML_PLAIN_NUMBER;
3094             break;
3095         default:
3096             DBG_ERROR("unkown chapter display format");
3097             eName = XML_TOKEN_INVALID;
3098             break;
3099     }
3100 
3101     return eName;
3102 }
3103 
3104 
3105 /// map FilenameDisplayFormat to XML attribute names
3106 enum XMLTokenEnum XMLTextFieldExport::MapFilenameDisplayFormat(sal_Int16 nFormat)
3107 {
3108     enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3109 
3110     switch (nFormat)
3111     {
3112         case FilenameDisplayFormat::FULL:
3113             eName = XML_FULL;
3114             break;
3115         case FilenameDisplayFormat::PATH:
3116             eName = XML_PATH;
3117             break;
3118         case FilenameDisplayFormat::NAME:
3119             eName = XML_NAME;
3120             break;
3121         case FilenameDisplayFormat::NAME_AND_EXT:
3122             eName = XML_NAME_AND_EXTENSION;
3123             break;
3124         default:
3125             DBG_ERROR("unknown filename display format");
3126     }
3127 
3128     return eName;
3129 }
3130 
3131 
3132 /// map ReferenceFieldPart to XML string
3133 enum XMLTokenEnum XMLTextFieldExport::MapReferenceType(sal_Int16 nType)
3134 {
3135     enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
3136 
3137     switch (nType)
3138     {
3139         case ReferenceFieldPart::PAGE:
3140             eElement = XML_PAGE;
3141             break;
3142         case ReferenceFieldPart::CHAPTER:
3143             eElement = XML_CHAPTER;
3144             break;
3145         case ReferenceFieldPart::TEXT:
3146             eElement = XML_TEXT;
3147             break;
3148         case ReferenceFieldPart::UP_DOWN:
3149             eElement = XML_DIRECTION;
3150             break;
3151         case ReferenceFieldPart::CATEGORY_AND_NUMBER:
3152             eElement = XML_CATEGORY_AND_VALUE;
3153             break;
3154         case ReferenceFieldPart::ONLY_CAPTION:
3155             eElement = XML_CAPTION;
3156             break;
3157         case ReferenceFieldPart::ONLY_SEQUENCE_NUMBER:
3158             eElement = XML_VALUE;
3159             break;
3160         case ReferenceFieldPart::PAGE_DESC:
3161             // small hack: this value never gets written, because
3162             // XML_TEMPLATE is default
3163             eElement = XML_TEMPLATE;
3164             break;
3165         // --> OD 2007-09-14 #i81002#
3166         case ReferenceFieldPart::NUMBER:
3167             eElement = XML_NUMBER;
3168             break;
3169         case ReferenceFieldPart::NUMBER_NO_CONTEXT:
3170             eElement = XML_NUMBER_NO_SUPERIOR;
3171             break;
3172         case ReferenceFieldPart::NUMBER_FULL_CONTEXT:
3173             eElement = XML_NUMBER_ALL_SUPERIOR;
3174             break;
3175         // <--
3176         default:
3177             DBG_ERROR("unknown reference type");
3178             eElement = XML_TEMPLATE;
3179             break;
3180     }
3181 
3182     return eElement;
3183 }
3184 
3185 /// map ReferenceFieldPart to XML string
3186 enum XMLTokenEnum XMLTextFieldExport::MapReferenceSource(sal_Int16 nType)
3187 {
3188     enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
3189 
3190     switch (nType)
3191     {
3192         case ReferenceFieldSource::REFERENCE_MARK:
3193             eElement = XML_REFERENCE_REF;
3194             break;
3195         case ReferenceFieldSource::SEQUENCE_FIELD:
3196             eElement = XML_SEQUENCE_REF;
3197             break;
3198         case ReferenceFieldSource::BOOKMARK:
3199             eElement = XML_BOOKMARK_REF;
3200             break;
3201         case ReferenceFieldSource::FOOTNOTE:
3202         case ReferenceFieldSource::ENDNOTE:
3203             eElement = XML_NOTE_REF;
3204             break;
3205         default:
3206             DBG_ERROR("unkown reference source");
3207             break;
3208     }
3209 
3210     return eElement;
3211 }
3212 
3213 
3214 /// element name for sender fields
3215 enum XMLTokenEnum XMLTextFieldExport::MapSenderFieldName(
3216     const Reference<XPropertySet> & xPropSet)
3217 {
3218     enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3219 
3220     // sub-field type
3221     switch (GetInt16Property(sPropertyFieldSubType, xPropSet))
3222     {
3223         case UserDataPart::COMPANY :
3224             eName = XML_SENDER_COMPANY;
3225             break;
3226         case UserDataPart::FIRSTNAME :
3227             eName = XML_SENDER_FIRSTNAME;
3228             break;
3229         case UserDataPart::NAME :
3230             eName = XML_SENDER_LASTNAME;
3231             break;
3232         case UserDataPart::SHORTCUT :
3233             eName = XML_SENDER_INITIALS;
3234             break;
3235         case UserDataPart::STREET :
3236             eName = XML_SENDER_STREET;
3237             break;
3238         case UserDataPart::COUNTRY :
3239             eName = XML_SENDER_COUNTRY;
3240             break;
3241         case UserDataPart::ZIP :
3242             eName = XML_SENDER_POSTAL_CODE;
3243             break;
3244         case UserDataPart::CITY :
3245             eName = XML_SENDER_CITY;
3246             break;
3247         case UserDataPart::TITLE :
3248             eName = XML_SENDER_TITLE;
3249             break;
3250         case UserDataPart::POSITION :
3251             eName = XML_SENDER_POSITION;
3252             break;
3253         case UserDataPart::PHONE_PRIVATE :
3254             eName = XML_SENDER_PHONE_PRIVATE;
3255             break;
3256         case UserDataPart::PHONE_COMPANY :
3257             eName = XML_SENDER_PHONE_WORK;
3258             break;
3259         case UserDataPart::FAX :
3260             eName = XML_SENDER_FAX;
3261             break;
3262         case UserDataPart::EMAIL :
3263             eName = XML_SENDER_EMAIL;
3264             break;
3265         case UserDataPart::STATE :
3266             eName = XML_SENDER_STATE_OR_PROVINCE;
3267             break;
3268         default:
3269             DBG_WARNING("unknown sender type");
3270             eName = XML_TOKEN_INVALID;
3271             break;
3272     }
3273 
3274     return eName;
3275 }
3276 
3277 enum XMLTokenEnum XMLTextFieldExport::MapDocInfoFieldName(
3278     enum FieldIdEnum nToken)
3279 {
3280     enum XMLTokenEnum eElement = XML_TOKEN_INVALID;
3281 
3282     switch (nToken)
3283     {
3284         case FIELD_ID_DOCINFO_CREATION_AUTHOR:
3285             eElement = XML_INITIAL_CREATOR;
3286             break;
3287         case FIELD_ID_DOCINFO_CREATION_DATE:
3288             eElement = XML_CREATION_DATE;
3289             break;
3290         case FIELD_ID_DOCINFO_CREATION_TIME:
3291             eElement = XML_CREATION_TIME;
3292             break;
3293         case FIELD_ID_DOCINFO_DESCRIPTION:
3294             eElement = XML_DESCRIPTION;
3295             break;
3296         case FIELD_ID_DOCINFO_PRINT_TIME:
3297             eElement = XML_PRINT_TIME;
3298             break;
3299         case FIELD_ID_DOCINFO_PRINT_DATE:
3300             eElement = XML_PRINT_DATE;
3301             break;
3302         case FIELD_ID_DOCINFO_PRINT_AUTHOR:
3303             eElement = XML_PRINTED_BY;
3304             break;
3305         case FIELD_ID_DOCINFO_TITLE:
3306             eElement = XML_TITLE;
3307             break;
3308         case FIELD_ID_DOCINFO_SUBJECT:
3309             eElement = XML_SUBJECT;
3310             break;
3311         case FIELD_ID_DOCINFO_KEYWORDS:
3312             eElement = XML_KEYWORDS;
3313             break;
3314         case FIELD_ID_DOCINFO_REVISION:
3315             eElement = XML_EDITING_CYCLES;
3316             break;
3317         case FIELD_ID_DOCINFO_EDIT_DURATION:
3318             eElement = XML_EDITING_DURATION;
3319             break;
3320         case FIELD_ID_DOCINFO_SAVE_TIME:
3321             eElement = XML_MODIFICATION_TIME;
3322             break;
3323         case FIELD_ID_DOCINFO_SAVE_DATE:
3324             eElement = XML_MODIFICATION_DATE;
3325             break;
3326         case FIELD_ID_DOCINFO_SAVE_AUTHOR:
3327             eElement = XML_CREATOR;
3328             break;
3329         default:
3330             DBG_WARNING("unknown docinfo field type!");
3331             eElement = XML_TOKEN_INVALID;
3332             break;
3333     }
3334 
3335     return eElement;
3336 }
3337 
3338 enum XMLTokenEnum XMLTextFieldExport::MapBibliographyFieldName(OUString sName)
3339 {
3340     enum XMLTokenEnum eName = XML_TOKEN_INVALID;
3341 
3342     if (sName.equalsAsciiL("Identifier", sizeof("Identifier")-1))
3343     {
3344         eName = XML_IDENTIFIER;
3345     }
3346     else if (sName.equalsAsciiL("BibiliographicType",
3347                                 sizeof("BibiliographicType")-1))
3348     {
3349         eName = XML_BIBLIOGRAPHY_TYPE;
3350     }
3351     else if (sName.equalsAsciiL("Address", sizeof("Address")-1))
3352     {
3353         eName = XML_ADDRESS;
3354     }
3355     else if (sName.equalsAsciiL("Annote", sizeof("Annote")-1))
3356     {
3357         eName = XML_ANNOTE;
3358     }
3359     else if (sName.equalsAsciiL("Author", sizeof("Author")-1))
3360     {
3361         eName = XML_AUTHOR;
3362     }
3363     else if (sName.equalsAsciiL("Booktitle", sizeof("Booktitle")-1))
3364     {
3365         eName = XML_BOOKTITLE;
3366     }
3367     else if (sName.equalsAsciiL("Chapter", sizeof("Chapter")-1))
3368     {
3369         eName = XML_CHAPTER;
3370     }
3371     else if (sName.equalsAsciiL("Edition", sizeof("Edition")-1))
3372     {
3373         eName = XML_EDITION;
3374     }
3375     else if (sName.equalsAsciiL("Editor", sizeof("Editor")-1))
3376     {
3377         eName = XML_EDITOR;
3378     }
3379     else if (sName.equalsAsciiL("Howpublished", sizeof("Howpublished")-1))
3380     {
3381         eName = XML_HOWPUBLISHED;
3382     }
3383     else if (sName.equalsAsciiL("Institution", sizeof("Institution")-1))
3384     {
3385         eName = XML_INSTITUTION;
3386     }
3387     else if (sName.equalsAsciiL("Journal", sizeof("Journal")-1))
3388     {
3389         eName = XML_JOURNAL;
3390     }
3391     else if (sName.equalsAsciiL("Month", sizeof("Month")-1))
3392     {
3393         eName = XML_MONTH;
3394     }
3395     else if (sName.equalsAsciiL("Note", sizeof("Note")-1))
3396     {
3397         eName = XML_NOTE;
3398     }
3399     else if (sName.equalsAsciiL("Number", sizeof("Number")-1))
3400     {
3401         eName = XML_NUMBER;
3402     }
3403     else if (sName.equalsAsciiL("Organizations", sizeof("Organizations")-1))
3404     {
3405         eName = XML_ORGANIZATIONS;
3406     }
3407     else if (sName.equalsAsciiL("Pages", sizeof("Pages")-1))
3408     {
3409         eName = XML_PAGES;
3410     }
3411     else if (sName.equalsAsciiL("Publisher", sizeof("Publisher")-1))
3412     {
3413         eName = XML_PUBLISHER;
3414     }
3415     else if (sName.equalsAsciiL("School", sizeof("School")-1))
3416     {
3417         eName = XML_SCHOOL;
3418     }
3419     else if (sName.equalsAsciiL("Series", sizeof("Series")-1))
3420     {
3421         eName = XML_SERIES;
3422     }
3423     else if (sName.equalsAsciiL("Title", sizeof("Title")-1))
3424     {
3425         eName = XML_TITLE;
3426     }
3427     else if (sName.equalsAsciiL("Report_Type", sizeof("Report_Type")-1))
3428     {
3429         eName = XML_REPORT_TYPE;
3430     }
3431     else if (sName.equalsAsciiL("Volume", sizeof("Volume")-1))
3432     {
3433         eName = XML_VOLUME;
3434     }
3435     else if (sName.equalsAsciiL("Year", sizeof("Year")-1))
3436     {
3437         eName = XML_YEAR;
3438     }
3439     else if (sName.equalsAsciiL("URL", sizeof("URL")-1))
3440     {
3441         eName = XML_URL;
3442     }
3443     else if (sName.equalsAsciiL("Custom1", sizeof("Custom1")-1))
3444     {
3445         eName = XML_CUSTOM1;
3446     }
3447     else if (sName.equalsAsciiL("Custom2", sizeof("Custom2")-1))
3448     {
3449         eName = XML_CUSTOM2;
3450     }
3451     else if (sName.equalsAsciiL("Custom3", sizeof("Custom3")-1))
3452     {
3453         eName = XML_CUSTOM3;
3454     }
3455     else if (sName.equalsAsciiL("Custom4", sizeof("Custom4")-1))
3456     {
3457         eName = XML_CUSTOM4;
3458     }
3459     else if (sName.equalsAsciiL("Custom5", sizeof("Custom5")-1))
3460     {
3461         eName = XML_CUSTOM5;
3462     }
3463     else if (sName.equalsAsciiL("ISBN", sizeof("ISBN")-1))
3464     {
3465         eName = XML_ISBN;
3466     }
3467     else
3468     {
3469         DBG_ERROR("Unknown bibliography info data");
3470         eName = XML_TOKEN_INVALID;
3471     }
3472 
3473     return eName;
3474 }
3475 
3476 enum XMLTokenEnum XMLTextFieldExport::MapMeasureKind(sal_Int16 nKind)
3477 {
3478     switch( nKind )
3479     {
3480     case 0:
3481         return XML_VALUE;
3482     case 1:
3483         return XML_UNIT;
3484     }
3485     return XML_GAP;
3486 }
3487 
3488 OUString XMLTextFieldExport::MakeFootnoteRefName(
3489     sal_Int16 nSeqNo)
3490 {
3491     // generate foot-/endnote ID
3492     OUStringBuffer aBuf;
3493     aBuf.appendAscii("ftn");
3494     aBuf.append((sal_Int32)nSeqNo);
3495     return aBuf.makeStringAndClear();
3496 }
3497 
3498 OUString XMLTextFieldExport::MakeSequenceRefName(
3499     sal_Int16 nSeqNo,
3500     const OUString& rSeqName)
3501 {
3502     // generate foot-/endnote ID
3503     OUStringBuffer aBuf;
3504     aBuf.appendAscii("ref");
3505     aBuf.append(rSeqName);
3506     aBuf.append((sal_Int32)nSeqNo);
3507     return aBuf.makeStringAndClear();
3508 }
3509 
3510 //
3511 // Property accessor helper functions
3512 //
3513 
3514 // to be relegated (does that word exist?) to a more appropriate place
3515 //
3516 
3517 
3518 inline sal_Bool GetBoolProperty(
3519     const OUString& sPropName,
3520     const Reference<XPropertySet> & xPropSet)
3521 {
3522     Any aAny = xPropSet->getPropertyValue(sPropName);
3523     sal_Bool bBool = *(sal_Bool *)aAny.getValue();
3524     return bBool;
3525 }
3526 
3527 inline sal_Bool GetOptionalBoolProperty(
3528     const OUString& sPropName,
3529     const Reference<XPropertySet> & xPropSet,
3530     const Reference<XPropertySetInfo> & xPropSetInfo,
3531     sal_Bool bDefault)
3532 {
3533     return xPropSetInfo->hasPropertyByName( sPropName )
3534         ? GetBoolProperty( sPropName, xPropSet ) : bDefault;
3535 }
3536 
3537 inline double GetDoubleProperty(
3538     const OUString& sPropName,
3539     const Reference<XPropertySet> & xPropSet)
3540 {
3541     Any aAny = xPropSet->getPropertyValue(sPropName);
3542     double fDouble = 0.0;
3543     aAny >>= fDouble;
3544     return fDouble;
3545 }
3546 
3547 inline OUString const GetStringProperty(
3548     const OUString& sPropName,
3549     const Reference<XPropertySet> & xPropSet)
3550 {
3551     Any aAny = xPropSet->getPropertyValue(sPropName);
3552     OUString sString;
3553     aAny >>= sString;
3554     return sString;
3555 }
3556 
3557 inline sal_Int32 GetIntProperty(
3558     const OUString& sPropName,
3559     const Reference<XPropertySet> & xPropSet)
3560 {
3561     Any aAny = xPropSet->getPropertyValue(sPropName);
3562     sal_Int32 nInt = 0;
3563     aAny >>= nInt;
3564     return nInt;
3565 }
3566 
3567 inline sal_Int16 GetInt16Property(
3568     const OUString& sPropName,
3569     const Reference<XPropertySet> & xPropSet)
3570 {
3571     Any aAny = xPropSet->getPropertyValue(sPropName);
3572     sal_Int16 nInt = 0;
3573     aAny >>= nInt;
3574     return nInt;
3575 }
3576 
3577 inline sal_Int8 GetInt8Property(
3578     const OUString& sPropName,
3579     const Reference<XPropertySet> & xPropSet)
3580 {
3581     Any aAny = xPropSet->getPropertyValue(sPropName);
3582     sal_Int8 nInt = 0;
3583     aAny >>= nInt;
3584     return nInt;
3585 }
3586 
3587 inline DateTime const GetDateTimeProperty(
3588     const OUString& sPropName,
3589     const Reference<XPropertySet> & xPropSet)
3590 {
3591     Any aAny = xPropSet->getPropertyValue(sPropName);
3592     DateTime aTime;
3593     aAny >>= aTime;
3594     return aTime;
3595 }
3596 
3597 inline Date const GetDateProperty(
3598     const OUString& sPropName,
3599     const Reference<XPropertySet> & xPropSet)
3600 {
3601     Any aAny = xPropSet->getPropertyValue(sPropName);
3602     Date aDate;
3603     aAny >>= aDate;
3604     return aDate;
3605 }
3606 
3607 inline Sequence<OUString> const GetStringSequenceProperty(
3608     const OUString& sPropName,
3609     const Reference<XPropertySet> & xPropSet)
3610 {
3611     Any aAny = xPropSet->getPropertyValue(sPropName);
3612     Sequence<OUString> aSequence;
3613     aAny >>= aSequence;
3614     return aSequence;
3615 }
3616