xref: /trunk/main/xmloff/source/text/txtfldi.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 /** @#file
32  *
33  *  Import of all text fields except those from txtvfldi.cxx
34  *  (variable related text fields and database display fields)
35  */
36 #include "txtfldi.hxx"
37 #include "txtvfldi.hxx"
38 #include <xmloff/xmlimp.hxx>
39 #include <xmloff/xmlnumi.hxx>
40 #include <xmloff/txtimp.hxx>
41 #include "xmloff/xmlnmspe.hxx"
42 #include <xmloff/nmspmap.hxx>
43 #include <xmloff/xmltoken.hxx>
44 #include <xmloff/xmluconv.hxx>
45 #include <xmloff/xmlement.hxx>
46 #include "XMLStringBufferImportContext.hxx"
47 #include <xmloff/XMLEventsImportContext.hxx>
48 #include <com/sun/star/xml/sax/XAttributeList.hpp>
49 #include <com/sun/star/text/UserDataPart.hpp>
50 #include <com/sun/star/style/NumberingType.hpp>
51 #include <com/sun/star/text/PlaceholderType.hpp>
52 #include <com/sun/star/text/ReferenceFieldPart.hpp>
53 #include <com/sun/star/text/ReferenceFieldSource.hpp>
54 #include <com/sun/star/text/XTextField.hpp>
55 #include <com/sun/star/text/XTextContent.hpp>
56 #include <com/sun/star/beans/XPropertySet.hpp>
57 #include <com/sun/star/beans/XPropertySetInfo.hpp>
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
60 #include <com/sun/star/text/XDependentTextField.hpp>
61 #include <com/sun/star/text/SetVariableType.hpp>
62 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
63 #include <com/sun/star/text/ChapterFormat.hpp>
64 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
65 #include <com/sun/star/beans/PropertyValue.hpp>
66 #include <com/sun/star/text/BibliographyDataType.hpp>
67 #include <com/sun/star/text/BibliographyDataField.hpp>
68 #include <com/sun/star/util/XUpdatable.hpp>
69 #include <com/sun/star/sdb/CommandType.hpp>
70 
71 #include <rtl/ustring.hxx>
72 #include <rtl/ustrbuf.hxx>
73 #include <rtl/math.hxx>
74 #include <tools/debug.hxx>
75 
76 
77 using ::rtl::OUString;
78 using ::rtl::OUStringBuffer;
79 
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::document;
86 using namespace ::com::sun::star::util;
87 using namespace ::com::sun::star::xml::sax;
88 using namespace ::xmloff::token;
89 
90 
91 //
92 // SO API string constants
93 //
94 
95 // service prefix and service anems
96 const sal_Char sAPI_textfield_prefix[]  = "com.sun.star.text.TextField.";
97 const sal_Char sAPI_fieldmaster_prefix[] = "com.sun.star.text.FieldMaster.";
98 const sal_Char sAPI_presentation_prefix[] = "com.sun.star.presentation.TextField.";
99 
100 const sal_Char sAPI_extended_user[]             = "ExtendedUser";
101 const sal_Char sAPI_user_data_type[]            = "UserDataType";
102 const sal_Char sAPI_jump_edit[]                 = "JumpEdit";
103 const sal_Char sAPI_get_expression[]            = "GetExpression";
104 const sal_Char sAPI_set_expression[]            = "SetExpression";
105 const sal_Char sAPI_user[]                      = "User";
106 const sal_Char sAPI_date_time[]                 = "DateTime";
107 const sal_Char sAPI_page_number[]               = "PageNumber";
108 const sal_Char sAPI_database_next[]             = "DatabaseNextSet";
109 const sal_Char sAPI_database_select[]           = "DatabaseNumberOfSet";
110 const sal_Char sAPI_database_number[]           = "DatabaseSetNumber";
111 const sal_Char sAPI_database[]                  = "Database";
112 const sal_Char sAPI_database_name[]             = "DatabaseName";
113 const sal_Char sAPI_docinfo_change_author[]     = "DocInfo.ChangeAuthor";
114 const sal_Char sAPI_docinfo_change_date_time[]  = "DocInfo.ChangeDateTime";
115 const sal_Char sAPI_docinfo_edit_time[]         = "DocInfo.EditTime";
116 const sal_Char sAPI_docinfo_description[]       = "DocInfo.Description";
117 const sal_Char sAPI_docinfo_create_author[]     = "DocInfo.CreateAuthor";
118 const sal_Char sAPI_docinfo_create_date_time[]  = "DocInfo.CreateDateTime";
119 const sal_Char sAPI_docinfo_custom[]            = "DocInfo.Custom";
120 const sal_Char sAPI_docinfo_print_author[]      = "DocInfo.PrintAuthor";
121 const sal_Char sAPI_docinfo_print_date_time[]   = "DocInfo.PrintDateTime";
122 const sal_Char sAPI_docinfo_keywords[]          = "DocInfo.KeyWords";
123 const sal_Char sAPI_docinfo_subject[]           = "DocInfo.Subject";
124 const sal_Char sAPI_docinfo_title[]             = "DocInfo.Title";
125 const sal_Char sAPI_docinfo_revision[]          = "DocInfo.Revision";
126 const sal_Char sAPI_hidden_paragraph[]          = "HiddenParagraph";
127 const sal_Char sAPI_hidden_text[]               = "HiddenText";
128 const sal_Char sAPI_conditional_text[]          = "ConditionalText";
129 const sal_Char sAPI_file_name[]                 = "FileName";
130 const sal_Char sAPI_chapter[]                   = "Chapter";
131 const sal_Char sAPI_template_name[]             = "TemplateName";
132 const sal_Char sAPI_page_count[]                = "PageCount";
133 const sal_Char sAPI_paragraph_count[]           = "ParagraphCount";
134 const sal_Char sAPI_word_count[]                = "WordCount";
135 const sal_Char sAPI_character_count[]           = "CharacterCount";
136 const sal_Char sAPI_table_count[]               = "TableCount";
137 const sal_Char sAPI_graphic_object_count[]      = "GraphicObjectCount";
138 const sal_Char sAPI_embedded_object_count[]     = "EmbeddedObjectCount";
139 const sal_Char sAPI_reference_page_set[]        = "ReferencePageSet";
140 const sal_Char sAPI_reference_page_get[]        = "ReferencePageGet";
141 const sal_Char sAPI_macro[]                     = "Macro";
142 const sal_Char sAPI_dde[]                       = "DDE";
143 const sal_Char sAPI_get_reference[]             = "GetReference";
144 const sal_Char sAPI_sheet_name[]                = "SheetName";
145 const sal_Char sAPI_url[]                       = "URL";
146 const sal_Char sAPI_bibliography[]              = "Bibliography";
147 const sal_Char sAPI_annotation[]                = "Annotation";
148 const sal_Char sAPI_script[]                    = "Script";
149 const sal_Char sAPI_measure[]                   = "Measure";
150 const sal_Char sAPI_drop_down[]                 = "DropDown";
151 const sal_Char sAPI_header[]                    = "Header";
152 const sal_Char sAPI_footer[]                    = "Footer";
153 const sal_Char sAPI_datetime[]                  = "DateTime";
154 
155 // property names
156 const sal_Char sAPI_is_fixed[]          = "IsFixed";
157 const sal_Char sAPI_content[]           = "Content";
158 const sal_Char sAPI_value[]             = "Value";
159 const sal_Char sAPI_author[]            = "Author";
160 const sal_Char sAPI_full_name[]         = "FullName";
161 const sal_Char sAPI_place_holder_type[] = "PlaceHolderType";
162 const sal_Char sAPI_place_holder[]      = "PlaceHolder";
163 const sal_Char sAPI_hint[]              = "Hint";
164 const sal_Char sAPI_variable_name[]     = "VariableName";
165 const sal_Char sAPI_name[]              = "Name";
166 const sal_Char sAPI_sub_type[]          = "SubType";
167 const sal_Char sAPI_numbering_separator[] = "NumberingSeparator";
168 const sal_Char sAPI_chapter_numbering_level[] = "ChapterNumberingLevel";
169 const sal_Char sAPI_variable_subtype[]  = "VariableSubtype";
170 const sal_Char sAPI_formula[]           = "Formula";
171 const sal_Char sAPI_date_time_value[]   = "DateTimeValue";
172 const sal_Char sAPI_number_format[]     = "NumberFormat";
173 const sal_Char sAPI_user_text[]         = "UserText";
174 const sal_Char sAPI_numbering_type[]    = "NumberingType";
175 const sal_Char sAPI_offset[]            = "Offset";
176 const sal_Char sAPI_data_base_name[]    = "DataBaseName";
177 const sal_Char sAPI_data_base_u_r_l[]   = "DataBaseURL";
178 const sal_Char sAPI_data_table_name[]   = "DataTableName";
179 const sal_Char sAPI_condition[]         = "Condition";
180 const sal_Char sAPI_set_number[]        = "SetNumber";
181 const sal_Char sAPI_is_data_base_format[] = "DataBaseFormat";
182 const sal_Char sAPI_true_content[]      = "TrueContent";
183 const sal_Char sAPI_false_content[]     = "FalseContent";
184 const sal_Char sAPI_revision[]          = "Revision";
185 const sal_Char sAPI_file_format[]       = "FileFormat";
186 const sal_Char sAPI_chapter_format[]    = "ChapterFormat";
187 const sal_Char sAPI_level[]             = "Level";
188 const sal_Char sAPI_is_date[]           = "IsDate";
189 const sal_Char sAPI_adjust[]            = "Adjust";
190 const sal_Char sAPI_on[]                = "On";
191 const sal_Char sAPI_is_automatic_update[] = "IsAutomaticUpdate";
192 const sal_Char sAPI_source_name[]       = "SourceName";
193 const sal_Char sAPI_current_presentation[] = "CurrentPresentation";
194 const sal_Char sAPI_reference_field_part[] = "ReferenceFieldPart";
195 const sal_Char sAPI_reference_field_source[] = "ReferenceFieldSource";
196 const sal_Char sAPI_dde_command_type[]  = "DDECommandType";
197 const sal_Char sAPI_dde_command_file[]  = "DDECommandFile";
198 const sal_Char sAPI_dde_command_element[] = "DDECommandElement";
199 // sAPI_url: also used as service name
200 const sal_Char sAPI_target_frame[]      = "TargetFrame";
201 const sal_Char sAPI_representation[]    = "Representation";
202 const sal_Char sAPI_date[]              = "Date";
203 const sal_Char sAPI_url_content[]       = "URLContent";
204 const sal_Char sAPI_script_type[]       = "ScriptType";
205 const sal_Char sAPI_is_hidden[]         = "IsHidden";
206 const sal_Char sAPI_is_condition_true[] = "IsConditionTrue";
207 const sal_Char sAPI_data_command_type[] = "DataCommandType";
208 const sal_Char sAPI_is_fixed_language[] = "IsFixedLanguage";
209 const sal_Char sAPI_is_visible[]        = "IsVisible";
210 const sal_Char sAPI_TextRange[]         = "TextRange";
211 
212 const sal_Char sAPI_true[] = "sal_True";
213 
214 
215 TYPEINIT1( XMLTextFieldImportContext, SvXMLImportContext);
216 
217 XMLTextFieldImportContext::XMLTextFieldImportContext(
218     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
219     const sal_Char* pService,
220     sal_uInt16 nPrefix, const OUString& rElementName)
221 :   SvXMLImportContext( rImport, nPrefix, rElementName )
222 ,   sIsFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed))
223 ,   rTextImportHelper(rHlp)
224 ,   sServicePrefix(RTL_CONSTASCII_USTRINGPARAM(sAPI_textfield_prefix))
225 ,   bValid(sal_False)
226 {
227     DBG_ASSERT(NULL != pService, "Need service name!");
228     sServiceName = OUString::createFromAscii(pService);
229 }
230 
231 void XMLTextFieldImportContext::StartElement(
232     const Reference<XAttributeList> & xAttrList)
233 {
234     // process attributes
235     sal_Int16 nLength = xAttrList->getLength();
236     for(sal_Int16 i=0; i<nLength; i++) {
237 
238         OUString sLocalName;
239         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
240             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
241 
242         ProcessAttribute(rTextImportHelper.GetTextFieldAttrTokenMap().
243                             Get(nPrefix, sLocalName),
244                          xAttrList->getValueByIndex(i) );
245     }
246 }
247 
248 XMLTextFieldImportContext::~XMLTextFieldImportContext() {
249 }
250 
251 OUString XMLTextFieldImportContext::GetContent()
252 {
253     if (sContent.getLength()==0)
254     {
255         sContent = sContentBuffer.makeStringAndClear();
256     }
257 
258     return sContent;
259 }
260 
261 void XMLTextFieldImportContext::EndElement()
262 {
263     DBG_ASSERT(GetServiceName().getLength()>0, "no service name for element!");
264     if (bValid)
265     {
266 
267         // create field/Service
268         Reference<XPropertySet> xPropSet;
269         if (CreateField(xPropSet, sServicePrefix + GetServiceName()))
270         {
271             // set field properties
272             PrepareField(xPropSet);
273 
274             // attach field to document
275             Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
276 
277             // workaround for #80606#
278             try
279             {
280                 rTextImportHelper.InsertTextContent(xTextContent);
281             }
282             catch (lang::IllegalArgumentException e)
283             {
284                 // ignore
285             }
286             return;
287         }
288     }
289 
290     // in case of error: write element content
291     rTextImportHelper.InsertString(GetContent());
292 }
293 
294 void XMLTextFieldImportContext::Characters(const OUString& rContent)
295 {
296     sContentBuffer.append(rContent);
297 }
298 
299 sal_Bool XMLTextFieldImportContext::CreateField(
300     Reference<XPropertySet> & xField,
301     const OUString& rServiceName)
302 {
303     // instantiate new XTextField:
304     // ask import for model, model is factory, ask factory to create service
305 
306     Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
307     if( xFactory.is() )
308     {
309         Reference<XInterface> xIfc = xFactory->createInstance(rServiceName);
310         if( xIfc.is() )
311         {
312             Reference<XPropertySet> xTmp( xIfc, UNO_QUERY );
313 
314             xField = xTmp;
315         } else {
316             return sal_False;   // can't create instance
317         }
318     } else {
319         return sal_False;   // can't get MultiServiceFactory
320     }
321 
322     return sal_True;
323 }
324 
325 /// create the appropriate field context from
326 XMLTextFieldImportContext*
327 XMLTextFieldImportContext::CreateTextFieldImportContext(
328     SvXMLImport& rImport,
329     XMLTextImportHelper& rHlp,
330     sal_uInt16 nPrefix,
331     const OUString& rName,
332     sal_uInt16 nToken)
333 {
334     XMLTextFieldImportContext* pContext = NULL;
335 
336     switch (nToken)
337     {
338         case XML_TOK_TEXT_SENDER_FIRSTNAME:
339         case XML_TOK_TEXT_SENDER_LASTNAME:
340         case XML_TOK_TEXT_SENDER_INITIALS:
341         case XML_TOK_TEXT_SENDER_TITLE:
342         case XML_TOK_TEXT_SENDER_POSITION:
343         case XML_TOK_TEXT_SENDER_EMAIL:
344         case XML_TOK_TEXT_SENDER_PHONE_PRIVATE:
345         case XML_TOK_TEXT_SENDER_FAX:
346         case XML_TOK_TEXT_SENDER_COMPANY:
347         case XML_TOK_TEXT_SENDER_PHONE_WORK:
348         case XML_TOK_TEXT_SENDER_STREET:
349         case XML_TOK_TEXT_SENDER_CITY:
350         case XML_TOK_TEXT_SENDER_POSTAL_CODE:
351         case XML_TOK_TEXT_SENDER_COUNTRY:
352         case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE:
353             pContext =
354                 new XMLSenderFieldImportContext( rImport, rHlp,
355                                                  nPrefix, rName, nToken );
356             break;
357 
358         case XML_TOK_TEXT_AUTHOR_NAME:
359         case XML_TOK_TEXT_AUTHOR_INITIALS:
360             pContext =
361                 new XMLAuthorFieldImportContext( rImport, rHlp,
362                                                  nPrefix, rName, nToken );
363             break;
364 
365         case XML_TOK_TEXT_PLACEHOLDER:
366             pContext =
367                 new XMLPlaceholderFieldImportContext( rImport, rHlp,
368                                                       nPrefix, rName);
369             break;
370         case XML_TOK_TEXT_SEQUENCE:
371             pContext =
372                 new XMLSequenceFieldImportContext( rImport, rHlp,
373                                                    nPrefix, rName );
374             break;
375         case XML_TOK_TEXT_TEXT_INPUT:
376             pContext =
377                 new XMLTextInputFieldImportContext( rImport, rHlp,
378                                                     nPrefix, rName );
379             break;
380         case XML_TOK_TEXT_EXPRESSION:
381             pContext =
382                 new XMLExpressionFieldImportContext( rImport, rHlp,
383                                                      nPrefix, rName );
384             break;
385         case XML_TOK_TEXT_VARIABLE_SET:
386             pContext =
387                 new XMLVariableSetFieldImportContext( rImport, rHlp,
388                                                       nPrefix, rName );
389             break;
390         case XML_TOK_TEXT_VARIABLE_INPUT:
391             pContext =
392                 new XMLVariableInputFieldImportContext( rImport, rHlp,
393                                                         nPrefix, rName );
394             break;
395         case XML_TOK_TEXT_VARIABLE_GET:
396             pContext =
397                 new XMLVariableGetFieldImportContext( rImport, rHlp,
398                                                       nPrefix, rName );
399             break;
400         case XML_TOK_TEXT_USER_FIELD_GET:
401             pContext = new XMLUserFieldImportContext( rImport, rHlp,
402                                                       nPrefix, rName );
403             break;
404         case XML_TOK_TEXT_USER_FIELD_INPUT:
405             pContext = new XMLUserFieldInputImportContext( rImport, rHlp,
406                                                            nPrefix, rName );
407             break;
408         case XML_TOK_TEXT_TIME:
409             pContext = new XMLTimeFieldImportContext( rImport, rHlp,
410                                                       nPrefix, rName );
411             break;
412         case XML_TOK_TEXT_PAGE_CONTINUATION_STRING:
413         case XML_TOK_TEXT_PAGE_CONTINUATION:
414             pContext = new XMLPageContinuationImportContext( rImport, rHlp,
415                                                              nPrefix, rName );
416             break;
417 
418         case XML_TOK_TEXT_PAGE_NUMBER:
419             pContext = new XMLPageNumberImportContext( rImport, rHlp,
420                                                        nPrefix, rName );
421             break;
422 
423         case XML_TOK_TEXT_DATE:
424             pContext = new XMLDateFieldImportContext( rImport, rHlp,
425                                                       nPrefix, rName );
426             break;
427 
428         case XML_TOK_TEXT_DATABASE_NAME:
429             pContext = new XMLDatabaseNameImportContext( rImport, rHlp,
430                                                          nPrefix, rName );
431             break;
432         case XML_TOK_TEXT_DATABASE_NEXT:
433             pContext = new XMLDatabaseNextImportContext( rImport, rHlp,
434                                                          nPrefix, rName );
435             break;
436         case XML_TOK_TEXT_DATABASE_SELECT:
437             pContext = new XMLDatabaseSelectImportContext( rImport, rHlp,
438                                                            nPrefix, rName );
439             break;
440         case XML_TOK_TEXT_DATABASE_ROW_NUMBER:
441             pContext = new XMLDatabaseNumberImportContext( rImport, rHlp,
442                                                            nPrefix, rName );
443             break;
444         case XML_TOK_TEXT_DATABASE_DISPLAY:
445             pContext = new XMLDatabaseDisplayImportContext( rImport, rHlp,
446                                                             nPrefix, rName );
447             break;
448         case XML_TOK_TEXT_CONDITIONAL_TEXT:
449             pContext = new XMLConditionalTextImportContext( rImport, rHlp,
450                                                             nPrefix, rName );
451             break;
452         case XML_TOK_TEXT_HIDDEN_TEXT:
453             pContext = new XMLHiddenTextImportContext( rImport, rHlp,
454                                                        nPrefix, rName );
455             break;
456         case XML_TOK_TEXT_HIDDEN_PARAGRAPH:
457             pContext = new XMLHiddenParagraphImportContext( rImport, rHlp,
458                                                             nPrefix, rName );
459             break;
460         case XML_TOK_TEXT_DOCUMENT_DESCRIPTION:
461         case XML_TOK_TEXT_DOCUMENT_TITLE:
462         case XML_TOK_TEXT_DOCUMENT_SUBJECT:
463         case XML_TOK_TEXT_DOCUMENT_KEYWORDS:
464             pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
465                                                           nPrefix, rName,
466                                                           nToken, sal_True,
467                                                           sal_False );
468             break;
469         case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR:
470         case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR:
471         case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR:
472             pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
473                                                           nPrefix, rName,
474                                                           nToken, sal_False,
475                                                           sal_True );
476             break;
477 
478         case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
479         case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
480         case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
481         case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
482         case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
483         case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
484         case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
485             pContext = new XMLDateTimeDocInfoImportContext( rImport, rHlp,
486                                                             nPrefix, rName,
487                                                             nToken );
488             break;
489 
490         case XML_TOK_TEXT_DOCUMENT_REVISION:
491             pContext = new XMLRevisionDocInfoImportContext( rImport, rHlp,
492                                                             nPrefix, rName,
493                                                             nToken );
494             break;
495 
496         case XML_TOK_TEXT_DOCUMENT_USER_DEFINED:
497             pContext = new XMLUserDocInfoImportContext( rImport, rHlp,
498                                                         nPrefix, rName,
499                                                         nToken );
500             break;
501 
502         case XML_TOK_TEXT_FILENAME:
503             pContext = new XMLFileNameImportContext( rImport, rHlp,
504                                                      nPrefix, rName );
505             break;
506 
507         case XML_TOK_TEXT_CHAPTER:
508             pContext = new XMLChapterImportContext( rImport, rHlp,
509                                                     nPrefix, rName );
510             break;
511 
512         case XML_TOK_TEXT_TEMPLATENAME:
513             pContext = new XMLTemplateNameImportContext( rImport, rHlp,
514                                                          nPrefix, rName );
515             break;
516 
517         case XML_TOK_TEXT_WORD_COUNT:
518         case XML_TOK_TEXT_PARAGRAPH_COUNT:
519         case XML_TOK_TEXT_TABLE_COUNT:
520         case XML_TOK_TEXT_CHARACTER_COUNT:
521         case XML_TOK_TEXT_IMAGE_COUNT:
522         case XML_TOK_TEXT_OBJECT_COUNT:
523         case XML_TOK_TEXT_PAGE_COUNT:
524             pContext = new XMLCountFieldImportContext( rImport, rHlp,
525                                                        nPrefix, rName, nToken);
526             break;
527 
528         case XML_TOK_TEXT_GET_PAGE_VAR:
529             pContext = new XMLPageVarGetFieldImportContext( rImport, rHlp,
530                                                             nPrefix, rName );
531             break;
532 
533         case XML_TOK_TEXT_SET_PAGE_VAR:
534             pContext = new XMLPageVarSetFieldImportContext( rImport, rHlp,
535                                                             nPrefix, rName );
536             break;
537 
538         case XML_TOK_TEXT_MACRO:
539             pContext = new XMLMacroFieldImportContext( rImport, rHlp,
540                                                        nPrefix, rName );
541             break;
542 
543         case XML_TOK_TEXT_DDE:
544             pContext = new XMLDdeFieldImportContext( rImport, rHlp,
545                                                      nPrefix, rName );
546             break;
547 
548         case XML_TOK_TEXT_REFERENCE_REF:
549         case XML_TOK_TEXT_BOOKMARK_REF:
550         case XML_TOK_TEXT_NOTE_REF:
551         case XML_TOK_TEXT_SEQUENCE_REF:
552             pContext = new XMLReferenceFieldImportContext( rImport, rHlp,
553                                                            nToken,
554                                                            nPrefix, rName );
555             break;
556 
557         case XML_TOK_TEXT_SHEET_NAME:
558             pContext = new XMLSheetNameImportContext( rImport, rHlp,
559                                                       nPrefix, rName );
560             break;
561 
562         case XML_TOK_TEXT_BIBLIOGRAPHY_MARK:
563             pContext = new XMLBibliographyFieldImportContext( rImport, rHlp,
564                                                               nPrefix, rName );
565             break;
566 
567         case XML_TOK_TEXT_ANNOTATION:
568             pContext = new XMLAnnotationImportContext( rImport, rHlp,
569                                                        nPrefix, rName);
570             break;
571 
572         case XML_TOK_TEXT_SCRIPT:
573             pContext = new XMLScriptImportContext( rImport, rHlp,
574                                                    nPrefix, rName);
575             break;
576 
577         case XML_TOK_TEXT_MEASURE:
578             pContext = new XMLMeasureFieldImportContext( rImport, rHlp,
579                                                          nPrefix, rName );
580             break;
581 
582         case XML_TOK_TEXT_TABLE_FORMULA:
583             pContext = new XMLTableFormulaImportContext( rImport, rHlp,
584                                                          nPrefix, rName );
585             break;
586         case XML_TOK_TEXT_DROPDOWN:
587             pContext = new XMLDropDownFieldImportContext( rImport, rHlp,
588                                                           nPrefix, rName );
589             break;
590         case XML_TOK_DRAW_HEADER:
591             pContext = new XMLHeaderFieldImportContext( rImport, rHlp,
592                                                           nPrefix, rName );
593             break;
594         case XML_TOK_DRAW_FOOTER:
595             pContext = new XMLFooterFieldImportContext( rImport, rHlp,
596                                                           nPrefix, rName );
597             break;
598         case XML_TOK_DRAW_DATE_TIME:
599             pContext = new XMLDateTimeFieldImportContext( rImport, rHlp,
600                                                           nPrefix, rName );
601             break;
602 
603         default:
604             // ignore! May not even be a textfield.
605             // (Reminder: This method is called inside default:-branch)
606             pContext = NULL;
607             break;
608     }
609 
610     return pContext;
611 }
612 
613 
614 void XMLTextFieldImportContext::ForceUpdate(
615     const Reference<XPropertySet> & rPropertySet)
616 {
617     // force update
618     Reference<XUpdatable> xUpdate(rPropertySet, UNO_QUERY);
619     if (xUpdate.is())
620     {
621         xUpdate->update();
622     }
623     else
624     {
625         DBG_ERROR("Expected XUpdatable support!");
626     }
627 }
628 
629 
630 
631 //
632 // XMLSenderFieldImportContext
633 //
634 
635 TYPEINIT1( XMLSenderFieldImportContext, XMLTextFieldImportContext);
636 
637 XMLSenderFieldImportContext::XMLSenderFieldImportContext(
638     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
639     sal_uInt16 nPrfx, const OUString& sLocalName,
640     sal_uInt16 nToken)
641 :   XMLTextFieldImportContext(rImport, rHlp, sAPI_extended_user,nPrfx, sLocalName)
642 ,   sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed))
643 ,   sPropertyFieldSubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_user_data_type))
644 ,   sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content))
645 ,   bFixed(sal_True)
646 ,   nElementToken(nToken)
647 {
648 }
649 
650 void XMLSenderFieldImportContext::StartElement(
651     const Reference<XAttributeList> & xAttrList)
652 {
653     bValid = sal_True;
654     switch (nElementToken) {
655     case XML_TOK_TEXT_SENDER_FIRSTNAME:
656         nSubType = UserDataPart::FIRSTNAME;
657         break;
658     case XML_TOK_TEXT_SENDER_LASTNAME:
659         nSubType = UserDataPart::NAME;
660         break;
661     case XML_TOK_TEXT_SENDER_INITIALS:
662         nSubType = UserDataPart::SHORTCUT;
663         break;
664     case XML_TOK_TEXT_SENDER_TITLE:
665         nSubType = UserDataPart::TITLE;
666         break;
667     case XML_TOK_TEXT_SENDER_POSITION:
668         nSubType = UserDataPart::POSITION;
669         break;
670     case XML_TOK_TEXT_SENDER_EMAIL:
671         nSubType = UserDataPart::EMAIL;
672         break;
673     case XML_TOK_TEXT_SENDER_PHONE_PRIVATE:
674         nSubType = UserDataPart::PHONE_PRIVATE;
675         break;
676     case XML_TOK_TEXT_SENDER_FAX:
677         nSubType = UserDataPart::FAX;
678         break;
679     case XML_TOK_TEXT_SENDER_COMPANY:
680         nSubType = UserDataPart::COMPANY;
681         break;
682     case XML_TOK_TEXT_SENDER_PHONE_WORK:
683         nSubType = UserDataPart::PHONE_COMPANY;
684         break;
685     case XML_TOK_TEXT_SENDER_STREET:
686         nSubType = UserDataPart::STREET;
687         break;
688     case XML_TOK_TEXT_SENDER_CITY:
689         nSubType = UserDataPart::CITY;
690         break;
691     case XML_TOK_TEXT_SENDER_POSTAL_CODE:
692         nSubType = UserDataPart::ZIP;
693         break;
694     case XML_TOK_TEXT_SENDER_COUNTRY:
695         nSubType = UserDataPart::COUNTRY;
696         break;
697     case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE:
698         nSubType = UserDataPart::STATE;
699         break;
700     default:
701         bValid = sal_False;
702         break;
703     }
704 
705     // process Attributes
706     XMLTextFieldImportContext::StartElement(xAttrList);
707 }
708 
709 void XMLSenderFieldImportContext::ProcessAttribute(
710     sal_uInt16 nAttrToken,
711     const OUString& sAttrValue)
712 {
713     if (XML_TOK_TEXTFIELD_FIXED == nAttrToken) {
714 
715         // set bVal
716         sal_Bool bVal;
717         sal_Bool bRet = GetImport().GetMM100UnitConverter().
718             convertBool(bVal, sAttrValue);
719 
720         // set bFixed if successfull
721         if (bRet) {
722             bFixed = bVal;
723         }
724     }
725 }
726 
727 void XMLSenderFieldImportContext::PrepareField(
728     const Reference<XPropertySet> & rPropSet)
729 {
730     // set members
731     Any aAny;
732     aAny <<= nSubType;
733     rPropSet->setPropertyValue(sPropertyFieldSubType, aAny);
734 
735     // set fixed
736     aAny.setValue( &bFixed, ::getBooleanCppuType() );
737     rPropSet->setPropertyValue(sPropertyFixed, aAny);
738 
739     // set content if fixed
740     if (bFixed)
741     {
742         // in organizer or styles-only mode: force update
743         if (GetImport().GetTextImport()->IsOrganizerMode() ||
744             GetImport().GetTextImport()->IsStylesOnlyMode()   )
745         {
746             ForceUpdate(rPropSet);
747         }
748         else
749         {
750             aAny <<= GetContent();
751             rPropSet->setPropertyValue(sPropertyContent, aAny);
752         }
753     }
754 }
755 
756 
757 
758 //
759 // XMLAuthorFieldImportContext
760 //
761 
762 TYPEINIT1( XMLAuthorFieldImportContext, XMLSenderFieldImportContext);
763 
764 XMLAuthorFieldImportContext::XMLAuthorFieldImportContext(
765     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
766     sal_uInt16 nPrfx, const OUString& sLocalName,
767     sal_uInt16 nToken)
768 :   XMLSenderFieldImportContext(rImport, rHlp, nPrfx, sLocalName, nToken)
769 ,   bAuthorFullName(sal_True)
770 ,   sServiceAuthor(RTL_CONSTASCII_USTRINGPARAM(sAPI_author))
771 ,   sPropertyAuthorFullName(RTL_CONSTASCII_USTRINGPARAM(sAPI_full_name))
772 ,   sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed))
773 ,   sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content))
774 {
775     // overwrite service name from XMLSenderFieldImportContext
776     SetServiceName(sServiceAuthor);
777 }
778 
779 void XMLAuthorFieldImportContext::StartElement(
780     const Reference<XAttributeList> & xAttrList) {
781 
782     bAuthorFullName = (XML_TOK_TEXT_AUTHOR_INITIALS != nElementToken);
783     bValid = sal_True;
784 
785     // process Attributes
786     XMLTextFieldImportContext::StartElement(xAttrList);
787 }
788 
789 void XMLAuthorFieldImportContext::PrepareField(
790     const Reference<XPropertySet> & rPropSet)
791 {
792     // set members
793     Any aAny;
794     aAny.setValue( &bAuthorFullName, ::getBooleanCppuType() );
795     rPropSet->setPropertyValue(sPropertyAuthorFullName, aAny);
796 
797     aAny.setValue( &bFixed, ::getBooleanCppuType() );
798     rPropSet->setPropertyValue(sPropertyFixed, aAny);
799 
800     // set content if fixed
801     if (bFixed)
802     {
803         // organizer or styles-only mode: force update
804         if (GetImport().GetTextImport()->IsOrganizerMode() ||
805             GetImport().GetTextImport()->IsStylesOnlyMode()   )
806         {
807             ForceUpdate(rPropSet);
808         }
809         else
810         {
811             aAny <<= GetContent();
812             rPropSet->setPropertyValue(sPropertyContent, aAny);
813         }
814     }
815 }
816 
817 
818 //
819 // page continuation string
820 //
821 
822 TYPEINIT1( XMLPageContinuationImportContext, XMLTextFieldImportContext );
823 
824 static SvXMLEnumMapEntry __READONLY_DATA lcl_aSelectPageAttrMap[] =
825 {
826     { XML_PREVIOUS,     PageNumberType_PREV },
827     { XML_CURRENT,      PageNumberType_CURRENT },
828     { XML_NEXT,         PageNumberType_NEXT },
829     { XML_TOKEN_INVALID, 0 },
830 };
831 
832 XMLPageContinuationImportContext::XMLPageContinuationImportContext(
833     SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
834     const OUString& sLocalName)
835 :   XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number, nPrfx, sLocalName)
836 ,   sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
837 ,   sPropertyUserText(RTL_CONSTASCII_USTRINGPARAM(sAPI_user_text))
838 ,   sPropertyNumberingType(RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type))
839 ,   eSelectPage(PageNumberType_CURRENT)
840 ,   sStringOK(sal_False)
841 {
842     bValid = sal_True;
843 }
844 
845 void XMLPageContinuationImportContext::ProcessAttribute(
846     sal_uInt16 nAttrToken, const OUString& sAttrValue )
847 {
848     switch(nAttrToken)
849     {
850         case XML_TOK_TEXTFIELD_SELECT_PAGE:
851         {
852             sal_uInt16 nTmp;
853             if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
854                                                 lcl_aSelectPageAttrMap)
855                 && (PageNumberType_CURRENT != nTmp) )
856             {
857                 eSelectPage = (PageNumberType)nTmp;
858             }
859             break;
860         }
861         case XML_TOK_TEXTFIELD_STRING_VALUE:
862             sString = sAttrValue;
863             sStringOK = sal_True;
864             break;
865     }
866 }
867 
868 void XMLPageContinuationImportContext::PrepareField(
869     const Reference<XPropertySet> & xPropertySet)
870 {
871     Any aAny;
872 
873     aAny <<= eSelectPage;
874     xPropertySet->setPropertyValue(sPropertySubType, aAny);
875 
876     aAny <<= (sStringOK ? sString : GetContent());
877     xPropertySet->setPropertyValue(sPropertyUserText, aAny);
878 
879     aAny <<= style::NumberingType::CHAR_SPECIAL;
880     xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
881 }
882 
883 
884 
885 //
886 // page number field
887 //
888 
889 TYPEINIT1( XMLPageNumberImportContext, XMLTextFieldImportContext );
890 
891 XMLPageNumberImportContext::XMLPageNumberImportContext(
892     SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
893     const OUString& sLocalName)
894 :   XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number, nPrfx, sLocalName)
895 ,   sPropertySubType(RTL_CONSTASCII_USTRINGPARAM(sAPI_sub_type))
896 ,   sPropertyNumberingType(RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type))
897 ,   sPropertyOffset(RTL_CONSTASCII_USTRINGPARAM(sAPI_offset))
898 ,   sNumberSync(GetXMLToken(XML_FALSE))
899 ,   nPageAdjust(0)
900 ,   eSelectPage(PageNumberType_CURRENT)
901 ,   sNumberFormatOK(sal_False)
902 {
903     bValid = sal_True;
904 }
905 
906 void XMLPageNumberImportContext::ProcessAttribute(
907     sal_uInt16 nAttrToken,
908     const OUString& sAttrValue )
909 {
910     switch (nAttrToken)
911     {
912         case XML_TOK_TEXTFIELD_NUM_FORMAT:
913             sNumberFormat = sAttrValue;
914             sNumberFormatOK = sal_True;
915             break;
916         case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
917             sNumberSync = sAttrValue;
918             break;
919         case XML_TOK_TEXTFIELD_SELECT_PAGE:
920         {
921             sal_uInt16 nTmp;
922             if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
923                                                 lcl_aSelectPageAttrMap))
924             {
925                 eSelectPage = (PageNumberType)nTmp;
926             }
927             break;
928         }
929         case XML_TOK_TEXTFIELD_PAGE_ADJUST:
930         {
931             sal_Int32 nTmp;
932             if (SvXMLUnitConverter::convertNumber(nTmp, sAttrValue))
933             {
934                 nPageAdjust = (sal_Int16)nTmp;
935             }
936             break;
937         }
938     }
939 }
940 
941 void XMLPageNumberImportContext::PrepareField(
942         const Reference<XPropertySet> & xPropertySet)
943 {
944     Any aAny;
945 
946     // all properties are optional
947     Reference<XPropertySetInfo> xPropertySetInfo(
948         xPropertySet->getPropertySetInfo());
949 
950     if (xPropertySetInfo->hasPropertyByName(sPropertyNumberingType))
951     {
952         sal_Int16 nNumType;
953         if( sNumberFormatOK )
954         {
955             nNumType= style::NumberingType::ARABIC;
956             GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
957                                                     sNumberFormat,
958                                                     sNumberSync );
959         }
960         else
961             nNumType = style::NumberingType::PAGE_DESCRIPTOR;
962 
963         aAny <<= nNumType;
964         xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
965     }
966 
967     if (xPropertySetInfo->hasPropertyByName(sPropertyOffset))
968     {
969         // adjust offset
970         switch (eSelectPage)
971         {
972             case PageNumberType_PREV:
973                 nPageAdjust--;
974                 break;
975             case PageNumberType_CURRENT:
976                 break;
977             case PageNumberType_NEXT:
978                 nPageAdjust++;
979                 break;
980             default:
981                 DBG_WARNING("unknown page number type");
982         }
983         aAny <<= nPageAdjust;
984         xPropertySet->setPropertyValue(sPropertyOffset, aAny);
985     }
986 
987     if (xPropertySetInfo->hasPropertyByName(sPropertySubType))
988     {
989         aAny <<= eSelectPage;
990         xPropertySet->setPropertyValue(sPropertySubType, aAny);
991     }
992 }
993 
994 
995 
996 //
997 // Placeholder
998 //
999 
1000 TYPEINIT1( XMLPlaceholderFieldImportContext, XMLTextFieldImportContext);
1001 
1002 XMLPlaceholderFieldImportContext::XMLPlaceholderFieldImportContext(
1003     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1004     sal_uInt16 nPrfx, const OUString& sLocalName)
1005 :   XMLTextFieldImportContext(rImport, rHlp, sAPI_jump_edit,nPrfx, sLocalName)
1006 ,   sPropertyPlaceholderType(RTL_CONSTASCII_USTRINGPARAM(sAPI_place_holder_type))
1007 ,   sPropertyPlaceholder(RTL_CONSTASCII_USTRINGPARAM(sAPI_place_holder))
1008 ,   sPropertyHint(RTL_CONSTASCII_USTRINGPARAM(sAPI_hint))
1009 {
1010 }
1011 
1012 /// process attribute values
1013 void XMLPlaceholderFieldImportContext::ProcessAttribute(
1014     sal_uInt16 nAttrToken, const OUString& sAttrValue )
1015 {
1016     switch (nAttrToken) {
1017     case XML_TOK_TEXTFIELD_DESCRIPTION:
1018         sDescription = sAttrValue;
1019         break;
1020 
1021     case XML_TOK_TEXTFIELD_PLACEHOLDER_TYPE:
1022         bValid = sal_True;
1023         if (IsXMLToken(sAttrValue, XML_TABLE))
1024         {
1025             nPlaceholderType = PlaceholderType::TABLE;
1026         }
1027         else if (IsXMLToken(sAttrValue, XML_TEXT))
1028         {
1029             nPlaceholderType = PlaceholderType::TEXT;
1030         }
1031         else if (IsXMLToken(sAttrValue, XML_TEXT_BOX))
1032         {
1033             nPlaceholderType = PlaceholderType::TEXTFRAME;
1034         }
1035         else if (IsXMLToken(sAttrValue, XML_IMAGE))
1036         {
1037             nPlaceholderType = PlaceholderType::GRAPHIC;
1038         }
1039         else if (IsXMLToken(sAttrValue, XML_OBJECT))
1040         {
1041             nPlaceholderType = PlaceholderType::OBJECT;
1042         }
1043         else
1044         {
1045             bValid = sal_False;
1046         }
1047         break;
1048 
1049     default:
1050         ; // ignore
1051     }
1052 }
1053 
1054 void XMLPlaceholderFieldImportContext::PrepareField(
1055     const Reference<XPropertySet> & xPropertySet) {
1056 
1057     Any aAny;
1058     aAny <<= sDescription;
1059     xPropertySet->setPropertyValue(sPropertyHint, aAny);
1060 
1061     // remove <...> around content (if present)
1062     OUString aContent = GetContent();
1063     sal_Int32 nStart = 0;
1064     sal_Int32 nLength = aContent.getLength();
1065     if ((nLength > 0) && (aContent.getStr()[0] == '<'))
1066     {
1067         --nLength;
1068         ++nStart;
1069     }
1070     if ((nLength > 0) && (aContent.getStr()[aContent.getLength()-1] == '>'))
1071     {
1072         --nLength;
1073     }
1074     aAny <<= aContent.copy(nStart, nLength);
1075     xPropertySet->setPropertyValue(sPropertyPlaceholder, aAny);
1076 
1077     aAny <<= nPlaceholderType;
1078     xPropertySet->setPropertyValue(sPropertyPlaceholderType, aAny);
1079 }
1080 
1081 
1082 //
1083 // time field
1084 //
1085 
1086 TYPEINIT1( XMLTimeFieldImportContext, XMLTextFieldImportContext);
1087 
1088 XMLTimeFieldImportContext::XMLTimeFieldImportContext(
1089     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1090     sal_uInt16 nPrfx, const OUString& sLocalName)
1091 :   XMLTextFieldImportContext(rImport, rHlp, sAPI_date_time, nPrfx, sLocalName)
1092 ,   sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format))
1093 ,   sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed))
1094 ,   sPropertyDateTimeValue(RTL_CONSTASCII_USTRINGPARAM(sAPI_date_time_value))
1095 ,   sPropertyDateTime(RTL_CONSTASCII_USTRINGPARAM(sAPI_date_time))
1096 ,   sPropertyAdjust(RTL_CONSTASCII_USTRINGPARAM(sAPI_adjust))
1097 ,   sPropertyIsDate(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_date))
1098 ,   sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language))
1099 ,   fTimeValue(0.0)
1100 ,   nAdjust(0)
1101 ,   nFormatKey(0)
1102 ,   bTimeOK(sal_False)
1103 ,   bFormatOK(sal_False)
1104 ,   bFixed(sal_False)
1105 ,   bIsDate(sal_False)
1106 ,   bIsDefaultLanguage( sal_True )
1107 {
1108     bValid = sal_True;  // always valid!
1109 }
1110 
1111 void XMLTimeFieldImportContext::ProcessAttribute(
1112     sal_uInt16 nAttrToken, const OUString& sAttrValue )
1113 {
1114     switch (nAttrToken)
1115     {
1116         case XML_TOK_TEXTFIELD_TIME_VALUE:
1117         {
1118             double fTmp;
1119             if (GetImport().GetMM100UnitConverter().
1120                 convertDateTime(fTmp, sAttrValue))
1121             {
1122                 fTimeValue = fTmp;
1123                 bTimeOK = sal_True;
1124             }
1125 
1126             if (GetImport().GetMM100UnitConverter().
1127                 convertDateTime(aDateTimeValue, sAttrValue ))
1128             {
1129                 bTimeOK = sal_True;
1130             }
1131             break;
1132         }
1133         case XML_TOK_TEXTFIELD_FIXED:
1134         {
1135             sal_Bool bTmp;
1136             if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue))
1137             {
1138                 bFixed = bTmp;
1139             }
1140             break;
1141         }
1142         case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1143         {
1144             sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1145                                                sAttrValue, &bIsDefaultLanguage);
1146             if (-1 != nKey)
1147             {
1148                 nFormatKey = nKey;
1149                 bFormatOK = sal_True;
1150             }
1151             break;
1152         }
1153         case XML_TOK_TEXTFIELD_TIME_ADJUST:
1154         {
1155             double fTmp;
1156 
1157             if (SvXMLUnitConverter::convertTime(fTmp, sAttrValue))
1158             {
1159                 // convert to minutes
1160                 nAdjust = (sal_Int32)::rtl::math::approxFloor(fTmp * 60 * 24);
1161             }
1162             break;
1163         }
1164     }
1165 }
1166 
1167 void XMLTimeFieldImportContext::PrepareField(
1168     const Reference<XPropertySet> & rPropertySet)
1169 {
1170     Any aAny;
1171 
1172     // all properties are optional (except IsDate)
1173     Reference<XPropertySetInfo> xPropertySetInfo(
1174         rPropertySet->getPropertySetInfo());
1175 
1176     if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1177     {
1178         aAny.setValue( &bFixed, ::getBooleanCppuType() );
1179         rPropertySet->setPropertyValue(sPropertyFixed, aAny);
1180     }
1181 
1182     aAny.setValue( &bIsDate, ::getBooleanCppuType() );
1183     rPropertySet->setPropertyValue(sPropertyIsDate, aAny);
1184 
1185     if (xPropertySetInfo->hasPropertyByName(sPropertyAdjust))
1186     {
1187         aAny <<= nAdjust;
1188         rPropertySet->setPropertyValue(sPropertyAdjust, aAny);
1189     }
1190 
1191     // set value
1192     if (bFixed)
1193     {
1194         // organizer or styles-only mode: force update
1195         if (GetImport().GetTextImport()->IsOrganizerMode() ||
1196             GetImport().GetTextImport()->IsStylesOnlyMode()   )
1197         {
1198             ForceUpdate(rPropertySet);
1199         }
1200         else
1201         {
1202             // normal mode: set value (if present)
1203             if (bTimeOK)
1204             {
1205                if (xPropertySetInfo->hasPropertyByName(sPropertyDateTimeValue))
1206                {
1207                    aAny <<= aDateTimeValue;
1208                    rPropertySet->setPropertyValue(sPropertyDateTimeValue,aAny);
1209                }
1210                else if (xPropertySetInfo->hasPropertyByName(sPropertyDateTime))
1211                {
1212                    aAny <<= aDateTimeValue;
1213                    rPropertySet->setPropertyValue(sPropertyDateTime, aAny);
1214                }
1215             }
1216         }
1217     }
1218 
1219     if (bFormatOK &&
1220         xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1221     {
1222         aAny <<= nFormatKey;
1223         rPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
1224 
1225         if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
1226         {
1227             sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
1228             aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() );
1229             rPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
1230         }
1231     }
1232 }
1233 
1234 
1235 
1236 //
1237 // date field
1238 //
1239 
1240 TYPEINIT1( XMLDateFieldImportContext, XMLTimeFieldImportContext );
1241 
1242 XMLDateFieldImportContext::XMLDateFieldImportContext(
1243     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1244     sal_uInt16 nPrfx, const OUString& sLocalName) :
1245         XMLTimeFieldImportContext(rImport, rHlp, nPrfx, sLocalName)
1246 {
1247     bIsDate = sal_True; // always a date!
1248 }
1249 
1250 void XMLDateFieldImportContext::ProcessAttribute(
1251     sal_uInt16 nAttrToken,
1252     const ::rtl::OUString& sAttrValue )
1253 {
1254     switch (nAttrToken)
1255     {
1256         case XML_TOK_TEXTFIELD_DATE_VALUE:
1257         {
1258             double fTmp;
1259 
1260             if (GetImport().GetMM100UnitConverter().
1261                 convertDateTime(fTmp, sAttrValue))
1262             {
1263                 // #96457#: don't truncate in order to read date+time
1264                 fTimeValue = fTmp;
1265                 bTimeOK = sal_True;
1266             }
1267 
1268             if (GetImport().GetMM100UnitConverter().
1269                 convertDateTime(aDateTimeValue, sAttrValue ))
1270             {
1271                 bTimeOK = sal_True;
1272             }
1273             break;
1274         }
1275         case XML_TOK_TEXTFIELD_DATE_ADJUST:
1276             // delegate to superclass, pretending it was a time-adjust attr.
1277             XMLTimeFieldImportContext::ProcessAttribute(
1278                 XML_TOK_TEXTFIELD_TIME_ADJUST,
1279                 sAttrValue);
1280             break;
1281         case XML_TOK_TEXTFIELD_TIME_VALUE:
1282         case XML_TOK_TEXTFIELD_TIME_ADJUST:
1283             ; // ignore time-adjust and time-value attributes
1284             break;
1285         default:
1286             // all others: delegate to super-class
1287             XMLTimeFieldImportContext::ProcessAttribute(nAttrToken,
1288                                                         sAttrValue);
1289             break;
1290     }
1291 }
1292 
1293 
1294 
1295 
1296 //
1297 // database field superclass
1298 //
1299 
1300 TYPEINIT1( XMLDatabaseFieldImportContext, XMLTextFieldImportContext );
1301 
1302 XMLDatabaseFieldImportContext::XMLDatabaseFieldImportContext(
1303     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1304     const sal_Char* pServiceName, sal_uInt16 nPrfx,
1305     const OUString& sLocalName, bool bUseDisply)
1306 :   XMLTextFieldImportContext(rImport, rHlp, pServiceName, nPrfx, sLocalName)
1307 ,   sPropertyDataBaseName(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_base_name))
1308 ,   sPropertyDataBaseURL(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_base_u_r_l))
1309 ,   sPropertyTableName(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_table_name))
1310 ,   sPropertyDataCommandType(RTL_CONSTASCII_USTRINGPARAM(sAPI_data_command_type))
1311 ,   sPropertyIsVisible(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_visible))
1312 ,   nCommandType( sdb::CommandType::TABLE )
1313 ,   bCommandTypeOK(sal_False)
1314 ,   bDisplay( sal_True )
1315 ,   bDisplayOK( false )
1316 ,   bUseDisplay( bUseDisply )
1317 ,   bDatabaseOK(sal_False)
1318 ,   bDatabaseNameOK(sal_False)
1319 ,   bDatabaseURLOK(sal_False)
1320 ,   bTableOK(sal_False)
1321 {
1322 }
1323 
1324 void XMLDatabaseFieldImportContext::ProcessAttribute(
1325     sal_uInt16 nAttrToken, const OUString& sAttrValue )
1326 {
1327     switch (nAttrToken)
1328     {
1329         case XML_TOK_TEXTFIELD_DATABASE_NAME:
1330             sDatabaseName = sAttrValue;
1331             bDatabaseOK = sal_True;
1332             bDatabaseNameOK = sal_True;
1333             break;
1334         case XML_TOK_TEXTFIELD_TABLE_NAME:
1335             sTableName = sAttrValue;
1336             bTableOK = sal_True;
1337             break;
1338         case XML_TOK_TEXTFIELD_TABLE_TYPE:
1339             if( IsXMLToken( sAttrValue, XML_TABLE ) )
1340             {
1341                 nCommandType = sdb::CommandType::TABLE;
1342                 bCommandTypeOK = sal_True;
1343             }
1344             else if( IsXMLToken( sAttrValue, XML_QUERY ) )
1345             {
1346                 nCommandType = sdb::CommandType::QUERY;
1347                 bCommandTypeOK = sal_True;
1348             }
1349             else if( IsXMLToken( sAttrValue, XML_COMMAND ) )
1350             {
1351                 nCommandType = sdb::CommandType::COMMAND;
1352                 bCommandTypeOK = sal_True;
1353             }
1354             break;
1355         case XML_TOK_TEXTFIELD_DISPLAY:
1356             if( IsXMLToken( sAttrValue, XML_NONE ) )
1357             {
1358                 bDisplay = sal_False;
1359                 bDisplayOK = true;
1360             }
1361             else if( IsXMLToken( sAttrValue, XML_VALUE ) )
1362             {
1363                 bDisplay = sal_True;
1364                 bDisplayOK = true;
1365             }
1366             break;
1367     }
1368 }
1369 
1370 SvXMLImportContext* XMLDatabaseFieldImportContext::CreateChildContext(
1371     sal_uInt16 p_nPrefix,
1372     const OUString& rLocalName,
1373     const Reference<XAttributeList>& xAttrList )
1374 {
1375     if( ( p_nPrefix == XML_NAMESPACE_FORM ) &&
1376         IsXMLToken( rLocalName, XML_CONNECTION_RESOURCE ) )
1377     {
1378         // process attribute list directly
1379         sal_Int16 nLength = xAttrList->getLength();
1380         for( sal_Int16 n = 0; n < nLength; n++ )
1381         {
1382             OUString sLocalName;
1383             sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1384                 GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName );
1385 
1386             if( ( nPrefix == XML_NAMESPACE_XLINK ) &&
1387                 IsXMLToken( sLocalName, XML_HREF ) )
1388             {
1389                 sDatabaseURL = xAttrList->getValueByIndex(n);
1390                 bDatabaseOK = sal_True;
1391                 bDatabaseURLOK = sal_True;
1392             }
1393         }
1394 
1395         // we call ProcessAttribute in order to set bValid appropriatly
1396         ProcessAttribute( XML_TOKEN_INVALID, OUString() );
1397     }
1398 
1399     return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName,
1400                                                   xAttrList);
1401 }
1402 
1403 
1404 void XMLDatabaseFieldImportContext::PrepareField(
1405         const Reference<XPropertySet> & xPropertySet)
1406 {
1407     Any aAny;
1408 
1409     aAny <<= sTableName;
1410     xPropertySet->setPropertyValue(sPropertyTableName, aAny);
1411 
1412     if( bDatabaseNameOK )
1413     {
1414         aAny <<= sDatabaseName;
1415         xPropertySet->setPropertyValue(sPropertyDataBaseName, aAny);
1416     }
1417     else if( bDatabaseURLOK )
1418     {
1419         aAny <<= sDatabaseURL;
1420         xPropertySet->setPropertyValue(sPropertyDataBaseURL, aAny);
1421     }
1422 
1423     // #99980# load/save command type for all fields; also load
1424     //         old documents without command type
1425     if( bCommandTypeOK )
1426     {
1427         aAny <<= nCommandType;
1428         xPropertySet->setPropertyValue( sPropertyDataCommandType, aAny );
1429     }
1430 
1431     if( bUseDisplay && bDisplayOK )
1432     {
1433         aAny.setValue( &bDisplay, ::getBooleanCppuType() );
1434         xPropertySet->setPropertyValue( sPropertyIsVisible, aAny );
1435     }
1436 }
1437 
1438 
1439 
1440 //
1441 // database name field
1442 //
1443 
1444 TYPEINIT1( XMLDatabaseNameImportContext, XMLDatabaseFieldImportContext );
1445 
1446 XMLDatabaseNameImportContext::XMLDatabaseNameImportContext(
1447     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1448     sal_uInt16 nPrfx, const OUString& sLocalName) :
1449         XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_name,
1450                                       nPrfx, sLocalName, true)
1451 {
1452 }
1453 
1454 void XMLDatabaseNameImportContext::ProcessAttribute(
1455     sal_uInt16 nAttrToken, const OUString& sAttrValue )
1456 {
1457     // delegate to superclass and check for success
1458     XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1459     bValid = bDatabaseOK && bTableOK;
1460 }
1461 
1462 
1463 
1464 //
1465 // database next field
1466 //
1467 
1468 TYPEINIT1( XMLDatabaseNextImportContext, XMLDatabaseFieldImportContext );
1469 
1470 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1471     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1472     const sal_Char* pServiceName, sal_uInt16 nPrfx,
1473     const OUString& sLocalName) :
1474         XMLDatabaseFieldImportContext(rImport, rHlp, pServiceName,
1475                                       nPrfx, sLocalName, false),
1476         sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)),
1477         sTrue(RTL_CONSTASCII_USTRINGPARAM(sAPI_true)),
1478         sCondition(),
1479         bConditionOK(sal_False)
1480 {
1481 }
1482 
1483 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1484     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1485     sal_uInt16 nPrfx, const OUString& sLocalName)
1486 : XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_next, nPrfx, sLocalName, false)
1487 ,   sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition))
1488 ,   sTrue(RTL_CONSTASCII_USTRINGPARAM(sAPI_true))
1489 ,   bConditionOK(sal_False)
1490 {
1491 }
1492 
1493 void XMLDatabaseNextImportContext::ProcessAttribute(
1494     sal_uInt16 nAttrToken, const OUString& sAttrValue )
1495 {
1496     if (XML_TOK_TEXTFIELD_CONDITION == nAttrToken)
1497     {
1498         OUString sTmp;
1499         sal_uInt16 nPrefix = GetImport().GetNamespaceMap()._GetKeyByAttrName(
1500                                     sAttrValue, &sTmp, sal_False );
1501         if( XML_NAMESPACE_OOOW == nPrefix )
1502         {
1503             sCondition = sTmp;
1504             bConditionOK = sal_True;
1505         }
1506         else
1507             sCondition = sAttrValue;
1508     }
1509     else
1510     {
1511         XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1512                                                         sAttrValue);
1513     }
1514 
1515     bValid = bDatabaseOK && bTableOK;
1516 }
1517 
1518 void XMLDatabaseNextImportContext::PrepareField(
1519     const Reference<XPropertySet> & xPropertySet)
1520 {
1521     Any aAny;
1522 
1523     aAny <<= bConditionOK ? sCondition : sTrue;
1524     xPropertySet->setPropertyValue(sPropertyCondition, aAny);
1525 
1526     XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1527 }
1528 
1529 
1530 
1531 //
1532 // database select field
1533 //
1534 
1535 TYPEINIT1( XMLDatabaseSelectImportContext, XMLDatabaseNextImportContext );
1536 
1537 XMLDatabaseSelectImportContext::XMLDatabaseSelectImportContext(
1538     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1539     sal_uInt16 nPrfx, const ::rtl::OUString& sLocalName) :
1540         XMLDatabaseNextImportContext(rImport, rHlp, sAPI_database_select,
1541                                      nPrfx, sLocalName),
1542         sPropertySetNumber(RTL_CONSTASCII_USTRINGPARAM(sAPI_set_number)),
1543         nNumber(0),
1544         bNumberOK(sal_False)
1545 {
1546 }
1547 
1548 void XMLDatabaseSelectImportContext::ProcessAttribute(
1549     sal_uInt16 nAttrToken,
1550     const ::rtl::OUString& sAttrValue )
1551 {
1552     if (XML_TOK_TEXTFIELD_ROW_NUMBER == nAttrToken)
1553     {
1554         sal_Int32 nTmp;
1555         if (SvXMLUnitConverter::convertNumber( nTmp, sAttrValue
1556                                                /* , nMin, nMax ??? */ ))
1557         {
1558             nNumber = nTmp;
1559             bNumberOK = sal_True;
1560         }
1561     }
1562     else
1563     {
1564         XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1565     }
1566 
1567     bValid = bTableOK && bDatabaseOK && bNumberOK;
1568 }
1569 
1570 void XMLDatabaseSelectImportContext::PrepareField(
1571     const Reference<XPropertySet> & xPropertySet)
1572 {
1573     Any aAny;
1574 
1575     aAny <<= nNumber;
1576     xPropertySet->setPropertyValue(sPropertySetNumber, aAny);
1577 
1578     XMLDatabaseNextImportContext::PrepareField(xPropertySet);
1579 }
1580 
1581 
1582 
1583 //
1584 // database display row number field
1585 //
1586 
1587 TYPEINIT1( XMLDatabaseNumberImportContext, XMLDatabaseFieldImportContext );
1588 
1589 XMLDatabaseNumberImportContext::XMLDatabaseNumberImportContext(
1590     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1591     sal_uInt16 nPrfx, const OUString& sLocalName) :
1592         XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_number,
1593                                       nPrfx, sLocalName, true),
1594         sPropertyNumberingType(
1595             RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type)),
1596         sPropertySetNumber(RTL_CONSTASCII_USTRINGPARAM(sAPI_set_number)),
1597         sNumberFormat(RTL_CONSTASCII_USTRINGPARAM("1")),
1598         sNumberSync(GetXMLToken(XML_FALSE)),
1599         nValue(0),
1600         bValueOK(sal_False)
1601 {
1602 }
1603 
1604 void XMLDatabaseNumberImportContext::ProcessAttribute(
1605     sal_uInt16 nAttrToken,
1606     const OUString& sAttrValue )
1607 {
1608     switch (nAttrToken)
1609     {
1610         case XML_TOK_TEXTFIELD_NUM_FORMAT:
1611             sNumberFormat = sAttrValue;
1612             break;
1613         case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
1614             sNumberSync = sAttrValue;
1615             break;
1616         case XML_TOK_TEXTFIELD_VALUE:
1617         {
1618             sal_Int32 nTmp;
1619             if (SvXMLUnitConverter::convertNumber( nTmp, sAttrValue ))
1620             {
1621                 nValue = nTmp;
1622                 bValueOK = sal_True;
1623             }
1624             break;
1625         }
1626         default:
1627             XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1628                                                             sAttrValue);
1629             break;
1630     }
1631 
1632     bValid = bTableOK && bDatabaseOK;
1633 }
1634 
1635 void XMLDatabaseNumberImportContext::PrepareField(
1636     const Reference<XPropertySet> & xPropertySet)
1637 {
1638     Any aAny;
1639 
1640     sal_Int16 nNumType = style::NumberingType::ARABIC;
1641     GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
1642                                                     sNumberFormat,
1643                                                     sNumberSync );
1644     aAny <<= nNumType;
1645     xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
1646 
1647     if (bValueOK)
1648     {
1649         aAny <<= nValue;
1650         xPropertySet->setPropertyValue(sPropertySetNumber, aAny);
1651     }
1652 
1653     XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1654 }
1655 
1656 
1657 
1658 //
1659 // Simple doc info fields
1660 //
1661 
1662 TYPEINIT1( XMLSimpleDocInfoImportContext, XMLTextFieldImportContext );
1663 
1664 XMLSimpleDocInfoImportContext::XMLSimpleDocInfoImportContext(
1665     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1666     sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken,
1667     sal_Bool bContent, sal_Bool bAuthor)
1668 :   XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nToken),nPrfx, sLocalName)
1669 ,   sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed))
1670 ,   sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content))
1671 ,   sPropertyAuthor(RTL_CONSTASCII_USTRINGPARAM(sAPI_author))
1672 ,   sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation))
1673 ,   bFixed(sal_False)
1674 ,   bHasAuthor(bAuthor)
1675 ,   bHasContent(bContent)
1676 {
1677     bValid = sal_True;
1678 }
1679 
1680 void XMLSimpleDocInfoImportContext::ProcessAttribute(
1681     sal_uInt16 nAttrToken,
1682     const OUString& sAttrValue )
1683 {
1684     if (XML_TOK_TEXTFIELD_FIXED == nAttrToken)
1685     {
1686         sal_Bool bTmp;
1687         if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue))
1688         {
1689             bFixed = bTmp;
1690         }
1691     }
1692 }
1693 
1694 void XMLSimpleDocInfoImportContext::PrepareField(
1695     const Reference<XPropertySet> & rPropertySet)
1696 {
1697     //  title field in Calc has no Fixed property
1698     Reference<XPropertySetInfo> xPropertySetInfo(rPropertySet->getPropertySetInfo());
1699     if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1700     {
1701         Any aAny;
1702         aAny.setValue(&bFixed, ::getBooleanCppuType() );
1703         rPropertySet->setPropertyValue(sPropertyFixed, aAny);
1704 
1705         // set Content and CurrentPresentation (if fixed)
1706         if (bFixed)
1707         {
1708             // in organizer-mode or styles-only-mode, only force update
1709             if (GetImport().GetTextImport()->IsOrganizerMode() ||
1710                 GetImport().GetTextImport()->IsStylesOnlyMode()   )
1711             {
1712                 ForceUpdate(rPropertySet);
1713             }
1714             else
1715             {
1716                 // set content (author, if that's the name) and current
1717                 // presentation
1718                 aAny <<= GetContent();
1719 
1720                 if (bFixed && bHasAuthor)
1721                 {
1722                     rPropertySet->setPropertyValue(sPropertyAuthor, aAny);
1723                 }
1724 
1725                 if (bFixed && bHasContent)
1726                 {
1727                     rPropertySet->setPropertyValue(sPropertyContent, aAny);
1728                 }
1729 
1730                 rPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
1731             }
1732         }
1733     }
1734 }
1735 
1736 const sal_Char* XMLSimpleDocInfoImportContext::MapTokenToServiceName(
1737     sal_uInt16 nToken)
1738 {
1739     const sal_Char* pServiceName = NULL;
1740 
1741     switch(nToken)
1742     {
1743         case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR:
1744             pServiceName = sAPI_docinfo_create_author;
1745             break;
1746         case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
1747             pServiceName = sAPI_docinfo_create_date_time;
1748             break;
1749         case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
1750             pServiceName = sAPI_docinfo_create_date_time;
1751             break;
1752         case XML_TOK_TEXT_DOCUMENT_DESCRIPTION:
1753             pServiceName = sAPI_docinfo_description;
1754             break;
1755         case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
1756             pServiceName = sAPI_docinfo_edit_time;
1757             break;
1758         case XML_TOK_TEXT_DOCUMENT_USER_DEFINED:
1759             pServiceName = sAPI_docinfo_custom;
1760             break;
1761         case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR:
1762             pServiceName = sAPI_docinfo_print_author;
1763             break;
1764         case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
1765             pServiceName = sAPI_docinfo_print_date_time;
1766             break;
1767         case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
1768             pServiceName = sAPI_docinfo_print_date_time;
1769             break;
1770         case XML_TOK_TEXT_DOCUMENT_KEYWORDS:
1771             pServiceName = sAPI_docinfo_keywords;
1772             break;
1773         case XML_TOK_TEXT_DOCUMENT_SUBJECT:
1774             pServiceName = sAPI_docinfo_subject;
1775             break;
1776         case XML_TOK_TEXT_DOCUMENT_REVISION:
1777             pServiceName = sAPI_docinfo_revision;
1778             break;
1779         case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR:
1780             pServiceName = sAPI_docinfo_change_author;
1781             break;
1782         case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
1783             pServiceName = sAPI_docinfo_change_date_time;
1784             break;
1785         case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
1786             pServiceName = sAPI_docinfo_change_date_time;
1787             break;
1788         case XML_TOK_TEXT_DOCUMENT_TITLE:
1789             pServiceName = sAPI_docinfo_title;
1790             break;
1791 
1792         default:
1793             DBG_ERROR("no docinfo field token");
1794             pServiceName = NULL;
1795             break;
1796     }
1797 
1798     return pServiceName;
1799 }
1800 
1801 
1802 //
1803 // revision field
1804 //
1805 
1806 TYPEINIT1( XMLRevisionDocInfoImportContext, XMLSimpleDocInfoImportContext );
1807 
1808 XMLRevisionDocInfoImportContext::XMLRevisionDocInfoImportContext(
1809     SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
1810     const OUString& sLocalName, sal_uInt16 nToken) :
1811         XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, sLocalName,
1812                                       nToken, sal_False, sal_False),
1813         sPropertyRevision(RTL_CONSTASCII_USTRINGPARAM(sAPI_revision))
1814 {
1815     bValid = sal_True;
1816 }
1817 
1818 void XMLRevisionDocInfoImportContext::PrepareField(
1819     const Reference<XPropertySet> & rPropertySet)
1820 {
1821     XMLSimpleDocInfoImportContext::PrepareField(rPropertySet);
1822 
1823     // set revision number
1824     // if fixed, if not in organizer-mode, if not in styles-only-mode
1825     if (bFixed)
1826     {
1827         if ( GetImport().GetTextImport()->IsOrganizerMode() ||
1828              GetImport().GetTextImport()->IsStylesOnlyMode()   )
1829         {
1830             ForceUpdate(rPropertySet);
1831         }
1832         else
1833         {
1834             sal_Int32 nTmp;
1835             if (SvXMLUnitConverter::convertNumber(nTmp, GetContent()))
1836             {
1837                 Any aAny;
1838                 aAny <<= nTmp;
1839                 rPropertySet->setPropertyValue(sPropertyRevision, aAny);
1840             }
1841         }
1842     }
1843 }
1844 
1845 
1846 
1847 //
1848 // DocInfo fields with date/time attributes
1849 //
1850 
1851 TYPEINIT1( XMLDateTimeDocInfoImportContext, XMLSimpleDocInfoImportContext );
1852 
1853 XMLDateTimeDocInfoImportContext::XMLDateTimeDocInfoImportContext(
1854     SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
1855     const OUString& sLocalName, sal_uInt16 nToken)
1856 :   XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, sLocalName,nToken, sal_False, sal_False)
1857 ,   sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format))
1858 ,   sPropertyIsDate(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_date))
1859 ,   sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language))
1860 ,   nFormat(0)
1861 ,   bFormatOK(sal_False)
1862 ,   bIsDefaultLanguage(sal_True)
1863 {
1864     // we allow processing of EDIT_DURATION here, because import of actual
1865     // is not supported anyway. If it was, we'd need an extra import class
1866     // because times and time durations are presented differently!
1867 
1868     bValid = sal_True;
1869     switch (nToken)
1870     {
1871         case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
1872         case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
1873         case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
1874             bIsDate = sal_True;
1875             bHasDateTime = sal_True;
1876             break;
1877         case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
1878         case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
1879         case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
1880             bIsDate = sal_False;
1881             bHasDateTime = sal_True;
1882             break;
1883         case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
1884             bIsDate = sal_False;
1885             bHasDateTime = sal_False;
1886             break;
1887         default:
1888             DBG_ERROR(
1889                 "XMLDateTimeDocInfoImportContext needs date/time doc. fields");
1890             bValid = sal_False;
1891             break;
1892     }
1893 }
1894 
1895 void XMLDateTimeDocInfoImportContext::ProcessAttribute(
1896     sal_uInt16 nAttrToken,
1897     const OUString& sAttrValue )
1898 {
1899     switch (nAttrToken)
1900     {
1901         case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1902         {
1903             sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1904                                                sAttrValue, &bIsDefaultLanguage);
1905             if (-1 != nKey)
1906             {
1907                 nFormat = nKey;
1908                 bFormatOK = sal_True;
1909             }
1910             break;
1911         }
1912         case XML_TOK_TEXTFIELD_FIXED:
1913             XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1914                                                             sAttrValue);
1915             break;
1916         default:
1917             // ignore -> we can't set date/time value anyway!
1918             break;
1919     }
1920 }
1921 
1922 void XMLDateTimeDocInfoImportContext::PrepareField(
1923     const Reference<XPropertySet> & xPropertySet)
1924 {
1925     // process fixed and presentation
1926     XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
1927 
1928     Any aAny;
1929 
1930     if (bHasDateTime)
1931     {
1932         aAny.setValue( &bIsDate, ::getBooleanCppuType());
1933         xPropertySet->setPropertyValue(sPropertyIsDate, aAny);
1934     }
1935 
1936     if (bFormatOK)
1937     {
1938         aAny <<= nFormat;
1939         xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
1940 
1941         if( xPropertySet->getPropertySetInfo()->
1942                 hasPropertyByName( sPropertyIsFixedLanguage ) )
1943         {
1944             sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
1945             aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() );
1946             xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
1947         }
1948     }
1949 
1950     // can't set date/time/duration value! Sorry.
1951 }
1952 
1953 
1954 //
1955 // user defined docinfo fields
1956 //
1957 
1958 TYPEINIT1( XMLUserDocInfoImportContext, XMLSimpleDocInfoImportContext );
1959 
1960 XMLUserDocInfoImportContext::XMLUserDocInfoImportContext(
1961     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1962     sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken) :
1963         XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx,
1964                                       sLocalName, nToken,
1965                                       sal_False, sal_False)
1966     , sPropertyName(RTL_CONSTASCII_USTRINGPARAM(sAPI_name))
1967     , sPropertyNumberFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_number_format))
1968     , sPropertyIsFixedLanguage(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed_language))
1969     , nFormat(0)
1970     , bFormatOK(sal_False)
1971     , bIsDefaultLanguage( sal_True )
1972 {
1973     bValid = sal_False;
1974 }
1975 
1976 void XMLUserDocInfoImportContext::ProcessAttribute(
1977     sal_uInt16 nAttrToken,
1978     const OUString& sAttrValue )
1979 {
1980     switch (nAttrToken)
1981     {
1982         case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1983         {
1984             sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1985                                                sAttrValue, &bIsDefaultLanguage);
1986             if (-1 != nKey)
1987             {
1988                 nFormat = nKey;
1989                 bFormatOK = sal_True;
1990             }
1991             break;
1992         }
1993         case XML_TOK_TEXTFIELD_NAME:
1994         {
1995             if (!bValid)
1996             {
1997                 SetServiceName(OUString::createFromAscii( sAPI_docinfo_custom ) );
1998                 aName = sAttrValue;
1999                 bValid = sal_True;
2000             }
2001             break;
2002         }
2003 
2004         default:
2005             XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
2006                                                             sAttrValue);
2007             break;
2008     }
2009 }
2010 
2011 void XMLUserDocInfoImportContext::PrepareField(
2012         const ::com::sun::star::uno::Reference<
2013         ::com::sun::star::beans::XPropertySet> & xPropertySet)
2014 {
2015     uno::Any aAny;
2016     if ( aName.getLength() )
2017     {
2018         aAny <<= aName;
2019         xPropertySet->setPropertyValue(sPropertyName, aAny);
2020     }
2021     Reference<XPropertySetInfo> xPropertySetInfo(
2022         xPropertySet->getPropertySetInfo());
2023     if (bFormatOK &&
2024         xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
2025     {
2026         aAny <<= nFormat;
2027         xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
2028 
2029         if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
2030         {
2031             sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
2032             aAny.setValue( &bIsFixedLanguage, ::getBooleanCppuType() );
2033             xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
2034         }
2035     }
2036 
2037     // call superclass to handle "fixed"
2038     XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
2039 }
2040 
2041 
2042 //
2043 // import hidden paragraph fields
2044 //
2045 
2046 TYPEINIT1( XMLHiddenParagraphImportContext, XMLTextFieldImportContext );
2047 
2048 XMLHiddenParagraphImportContext::XMLHiddenParagraphImportContext(
2049     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2050     sal_uInt16 nPrfx, const OUString& sLocalName) :
2051         XMLTextFieldImportContext(rImport, rHlp, sAPI_hidden_paragraph,
2052                                   nPrfx, sLocalName),
2053         sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)),
2054         sPropertyIsHidden(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_hidden)),
2055         sCondition(),
2056         bIsHidden(sal_False)
2057 {
2058 }
2059 
2060 void XMLHiddenParagraphImportContext::ProcessAttribute(
2061     sal_uInt16 nAttrToken,
2062     const OUString& sAttrValue )
2063 {
2064     if (XML_TOK_TEXTFIELD_CONDITION == nAttrToken)
2065     {
2066         OUString sTmp;
2067         sal_uInt16 nPrefix = GetImport().GetNamespaceMap()._GetKeyByAttrName(
2068                                     sAttrValue, &sTmp, sal_False );
2069         if( XML_NAMESPACE_OOOW == nPrefix )
2070         {
2071             sCondition = sTmp;
2072             bValid = sal_True;
2073         }
2074         else
2075             sCondition = sAttrValue;
2076     }
2077     else if (XML_TOK_TEXTFIELD_IS_HIDDEN == nAttrToken)
2078     {
2079         sal_Bool bTmp;
2080         if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue))
2081         {
2082             bIsHidden = bTmp;
2083         }
2084     }
2085 }
2086 
2087 void XMLHiddenParagraphImportContext::PrepareField(
2088     const Reference<XPropertySet> & xPropertySet)
2089 {
2090     Any aAny;
2091     aAny <<= sCondition;
2092     xPropertySet->setPropertyValue(sPropertyCondition, aAny);
2093 
2094     aAny.setValue( &bIsHidden, ::getBooleanCppuType() );
2095     xPropertySet->setPropertyValue(sPropertyIsHidden, aAny);
2096 }
2097 
2098 
2099 
2100 //
2101 // import conditional text (<text:conditional-text>)
2102 //
2103 
2104 TYPEINIT1( XMLConditionalTextImportContext, XMLTextFieldImportContext );
2105 
2106 XMLConditionalTextImportContext::XMLConditionalTextImportContext(
2107     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2108     sal_uInt16 nPrfx, const OUString& sLocalName) :
2109         XMLTextFieldImportContext(rImport, rHlp, sAPI_conditional_text,
2110                                   nPrfx, sLocalName),
2111         sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)),
2112         sPropertyTrueContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_true_content)),
2113         sPropertyFalseContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_false_content)),
2114         sPropertyIsConditionTrue(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_condition_true)),
2115         sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
2116         bConditionOK(sal_False),
2117         bTrueOK(sal_False),
2118         bFalseOK(sal_False),
2119         bCurrentValue(sal_False)
2120 {
2121 }
2122 
2123 void XMLConditionalTextImportContext::ProcessAttribute(
2124     sal_uInt16 nAttrToken,
2125     const OUString& sAttrValue )
2126 {
2127     switch (nAttrToken)
2128     {
2129         case XML_TOK_TEXTFIELD_CONDITION:
2130             {
2131                 OUString sTmp;
2132                 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
2133                         _GetKeyByAttrName( sAttrValue, &sTmp, sal_False );
2134                 if( XML_NAMESPACE_OOOW == nPrefix )
2135                 {
2136                     sCondition = sTmp;
2137                     bConditionOK = sal_True;
2138                 }
2139                 else
2140                     sCondition = sAttrValue;
2141             }
2142             break;
2143         case XML_TOK_TEXTFIELD_STRING_VALUE_IF_FALSE:
2144             sFalseContent = sAttrValue;
2145             bFalseOK = sal_True;
2146             break;
2147         case XML_TOK_TEXTFIELD_STRING_VALUE_IF_TRUE:
2148             sTrueContent = sAttrValue;
2149             bTrueOK = sal_True;
2150             break;
2151         case XML_TOK_TEXTFIELD_CURRENT_VALUE:
2152         {
2153             sal_Bool bTmp;
2154             if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue))
2155             {
2156                 bCurrentValue = bTmp;
2157             }
2158             break;
2159         }
2160     }
2161 
2162     bValid = bConditionOK && bFalseOK && bTrueOK;
2163 }
2164 
2165 void XMLConditionalTextImportContext::PrepareField(
2166     const Reference<XPropertySet> & xPropertySet)
2167 {
2168     Any aAny;
2169 
2170     aAny <<= sCondition;
2171     xPropertySet->setPropertyValue(sPropertyCondition, aAny);
2172 
2173     aAny <<= sFalseContent;
2174     xPropertySet->setPropertyValue(sPropertyFalseContent, aAny);
2175 
2176     aAny <<= sTrueContent;
2177     xPropertySet->setPropertyValue(sPropertyTrueContent, aAny);
2178 
2179     aAny.setValue( &bCurrentValue, ::getBooleanCppuType() );
2180     xPropertySet->setPropertyValue(sPropertyIsConditionTrue, aAny);
2181 
2182     aAny <<= GetContent();
2183     xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
2184 }
2185 
2186 
2187 
2188 //
2189 // hidden text
2190 //
2191 
2192 TYPEINIT1( XMLHiddenTextImportContext, XMLTextFieldImportContext);
2193 
2194 XMLHiddenTextImportContext::XMLHiddenTextImportContext(
2195     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2196     sal_uInt16 nPrfx, const OUString& sLocalName) :
2197         XMLTextFieldImportContext(rImport, rHlp, sAPI_hidden_text,
2198                                   nPrfx, sLocalName),
2199         sPropertyCondition(RTL_CONSTASCII_USTRINGPARAM(sAPI_condition)),
2200         sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)),
2201         sPropertyIsHidden(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_hidden)),
2202         bConditionOK(sal_False),
2203         bStringOK(sal_False),
2204         bIsHidden(sal_False)
2205 {
2206 }
2207 
2208 void XMLHiddenTextImportContext::ProcessAttribute(
2209     sal_uInt16 nAttrToken,
2210     const OUString& sAttrValue )
2211 {
2212     switch (nAttrToken)
2213     {
2214         case XML_TOK_TEXTFIELD_CONDITION:
2215             {
2216                 OUString sTmp;
2217                 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
2218                                         _GetKeyByAttrName( sAttrValue, &sTmp, sal_False );
2219                 if( XML_NAMESPACE_OOOW == nPrefix )
2220                 {
2221                     sCondition = sTmp;
2222                     bConditionOK = sal_True;
2223                 }
2224                 else
2225                     sCondition = sAttrValue;
2226             }
2227             break;
2228         case XML_TOK_TEXTFIELD_STRING_VALUE:
2229             sString = sAttrValue;
2230             bStringOK = sal_True;
2231             break;
2232         case XML_TOK_TEXTFIELD_IS_HIDDEN:
2233         {
2234             sal_Bool bTmp;
2235             if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue))
2236             {
2237                 bIsHidden = bTmp;
2238             }
2239             break;
2240         }
2241     }
2242 
2243     bValid = bConditionOK && bStringOK;
2244 }
2245 
2246 void XMLHiddenTextImportContext::PrepareField(
2247         const Reference<XPropertySet> & xPropertySet)
2248 {
2249     Any aAny;
2250 
2251     aAny <<= sCondition;
2252     xPropertySet->setPropertyValue(sPropertyCondition, aAny);
2253 
2254     aAny <<= sString;
2255     xPropertySet->setPropertyValue(sPropertyContent, aAny);
2256 
2257     aAny.setValue( &bIsHidden, ::getBooleanCppuType() );
2258     xPropertySet->setPropertyValue(sPropertyIsHidden, aAny);
2259 }
2260 
2261 
2262 
2263 //
2264 // file name fields
2265 //
2266 
2267 TYPEINIT1( XMLFileNameImportContext, XMLTextFieldImportContext );
2268 
2269 static const SvXMLEnumMapEntry aFilenameDisplayMap[] =
2270 {
2271     { XML_PATH,                 FilenameDisplayFormat::PATH },
2272     { XML_NAME,                 FilenameDisplayFormat::NAME },
2273     { XML_NAME_AND_EXTENSION,   FilenameDisplayFormat::NAME_AND_EXT },
2274     { XML_FULL,                 FilenameDisplayFormat::FULL },
2275     { XML_TOKEN_INVALID, 0 }
2276 };
2277 
2278 XMLFileNameImportContext::XMLFileNameImportContext(
2279     SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2280     const OUString& sLocalName) :
2281         XMLTextFieldImportContext(rImport, rHlp, sAPI_file_name,
2282                                   nPrfx, sLocalName),
2283         sPropertyFixed(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_fixed)),
2284         sPropertyFileFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_file_format)),
2285         sPropertyCurrentPresentation(
2286             RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
2287         nFormat(FilenameDisplayFormat::FULL),
2288         bFixed(sal_False)
2289 {
2290     bValid = sal_True;
2291 }
2292 
2293 void XMLFileNameImportContext::ProcessAttribute(
2294     sal_uInt16 nAttrToken,
2295     const ::rtl::OUString& sAttrValue )
2296 {
2297     switch (nAttrToken)
2298     {
2299         case XML_TOK_TEXTFIELD_FIXED:
2300         {
2301             sal_Bool bTmp;
2302             if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue))
2303             {
2304                 bFixed = bTmp;
2305             }
2306             break;
2307         }
2308         case XML_TOK_TEXTFIELD_DISPLAY:
2309         {
2310             sal_uInt16 nTmp;
2311             if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2312                                                 aFilenameDisplayMap))
2313             {
2314                 nFormat = (sal_uInt16)nTmp;
2315             }
2316             break;
2317         }
2318         default:
2319             ; // unkown attribute: ignore
2320             break;
2321     }
2322 }
2323 
2324 void XMLFileNameImportContext::PrepareField(
2325     const Reference<XPropertySet> & xPropertySet)
2326 {
2327     Any aAny;
2328 
2329     // properties are optional
2330     Reference<XPropertySetInfo> xPropertySetInfo(
2331         xPropertySet->getPropertySetInfo());
2332 
2333     if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
2334     {
2335         aAny <<= bFixed;
2336         xPropertySet->setPropertyValue(sPropertyFixed, aAny);
2337     }
2338 
2339     if (xPropertySetInfo->hasPropertyByName(sPropertyFileFormat))
2340     {
2341         aAny <<= nFormat;
2342         xPropertySet->setPropertyValue(sPropertyFileFormat, aAny);
2343     }
2344 
2345     if (xPropertySetInfo->hasPropertyByName(sPropertyCurrentPresentation))
2346     {
2347         aAny <<= GetContent();
2348         xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
2349     }
2350 }
2351 
2352 
2353 //
2354 // template name field
2355 //
2356 
2357 static const SvXMLEnumMapEntry aTemplateDisplayMap[] =
2358 {
2359     { XML_FULL,                 TemplateDisplayFormat::FULL },
2360     { XML_PATH,                 TemplateDisplayFormat::PATH },
2361     { XML_NAME,                 TemplateDisplayFormat::NAME },
2362     { XML_NAME_AND_EXTENSION,   TemplateDisplayFormat::NAME_AND_EXT },
2363     { XML_AREA,                 TemplateDisplayFormat::AREA },
2364     { XML_TITLE,                TemplateDisplayFormat::TITLE },
2365     { XML_TOKEN_INVALID, 0 }
2366 };
2367 
2368 TYPEINIT1( XMLTemplateNameImportContext, XMLTextFieldImportContext );
2369 
2370 XMLTemplateNameImportContext::XMLTemplateNameImportContext(
2371     SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2372     const OUString& sLocalName) :
2373         XMLTextFieldImportContext(rImport, rHlp, sAPI_template_name,
2374                                   nPrfx, sLocalName),
2375         sPropertyFileFormat(RTL_CONSTASCII_USTRINGPARAM(sAPI_file_format)),
2376         nFormat(TemplateDisplayFormat::FULL)
2377 {
2378     bValid = sal_True;
2379 }
2380 
2381 void XMLTemplateNameImportContext::ProcessAttribute(
2382     sal_uInt16 nAttrToken,
2383     const OUString& sAttrValue )
2384 {
2385     switch (nAttrToken)
2386     {
2387         case XML_TOK_TEXTFIELD_DISPLAY:
2388         {
2389             sal_uInt16 nTmp;
2390             if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2391                                                 aTemplateDisplayMap))
2392             {
2393                 nFormat = (sal_uInt16)nTmp;
2394             }
2395             break;
2396         }
2397         default:
2398             ; // unknown attribute: ignore
2399             break;
2400     }
2401 }
2402 
2403 void XMLTemplateNameImportContext::PrepareField(
2404     const Reference<XPropertySet> & xPropertySet)
2405 {
2406     Any aAny;
2407 
2408     aAny <<= nFormat;
2409     xPropertySet->setPropertyValue(sPropertyFileFormat, aAny);
2410 }
2411 
2412 
2413 //
2414 // import chapter fields
2415 //
2416 
2417 TYPEINIT1( XMLChapterImportContext, XMLTextFieldImportContext );
2418 
2419 static const SvXMLEnumMapEntry aChapterDisplayMap[] =
2420 {
2421     { XML_NAME,                     ChapterFormat::NAME },
2422     { XML_NUMBER,                   ChapterFormat::NUMBER },
2423     { XML_NUMBER_AND_NAME,          ChapterFormat::NAME_NUMBER },
2424     { XML_PLAIN_NUMBER_AND_NAME,    ChapterFormat::NO_PREFIX_SUFFIX },
2425     { XML_PLAIN_NUMBER,             ChapterFormat::DIGIT },
2426     { XML_TOKEN_INVALID, 0 }
2427 };
2428 
2429 XMLChapterImportContext::XMLChapterImportContext(
2430     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2431     sal_uInt16 nPrfx, const OUString& sLocalName) :
2432         XMLTextFieldImportContext(rImport, rHlp, sAPI_chapter,
2433                                   nPrfx, sLocalName),
2434         sPropertyChapterFormat(
2435             RTL_CONSTASCII_USTRINGPARAM(sAPI_chapter_format)),
2436         sPropertyLevel(RTL_CONSTASCII_USTRINGPARAM(sAPI_level)),
2437         nFormat(ChapterFormat::NAME_NUMBER),
2438         nLevel(0)
2439 {
2440     bValid = sal_True;
2441 }
2442 
2443 void XMLChapterImportContext::ProcessAttribute(
2444     sal_uInt16 nAttrToken,
2445     const OUString& sAttrValue )
2446 {
2447     switch (nAttrToken)
2448     {
2449         case XML_TOK_TEXTFIELD_DISPLAY:
2450         {
2451             sal_uInt16 nTmp;
2452             if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2453                                                 aChapterDisplayMap))
2454             {
2455                 nFormat = (sal_Int16)nTmp;
2456             }
2457             break;
2458         }
2459         case XML_TOK_TEXTFIELD_OUTLINE_LEVEL:
2460         {
2461             sal_Int32 nTmp;
2462             if (SvXMLUnitConverter::convertNumber(
2463                 nTmp, sAttrValue, 1,
2464                 GetImport().GetTextImport()->GetChapterNumbering()->getCount()
2465                 ))
2466             {
2467                 // API numbers 0..9, we number 1..10
2468                 nLevel = (sal_Int8)nTmp;
2469                 nLevel--;
2470             }
2471             break;
2472         }
2473         default:
2474             ; // unknown attribute: ignore
2475             break;
2476     }
2477 }
2478 
2479 void XMLChapterImportContext::PrepareField(
2480         const Reference<XPropertySet> & xPropertySet)
2481 {
2482     Any aAny;
2483 
2484     aAny <<= nFormat;
2485     xPropertySet->setPropertyValue(sPropertyChapterFormat, aAny);
2486 
2487     aAny <<= nLevel;
2488     xPropertySet->setPropertyValue(sPropertyLevel, aAny);
2489 }
2490 
2491 
2492 //
2493 // counting fields
2494 //
2495 
2496 TYPEINIT1( XMLCountFieldImportContext, XMLTextFieldImportContext );
2497 
2498 XMLCountFieldImportContext::XMLCountFieldImportContext(
2499     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2500     sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken) :
2501         XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nToken),
2502                                   nPrfx, sLocalName),
2503         sPropertyNumberingType(
2504             RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type)),
2505         sNumberFormat(),
2506         sLetterSync(),
2507         bNumberFormatOK(sal_False)
2508 {
2509     bValid = sal_True;
2510 }
2511 
2512 void XMLCountFieldImportContext::ProcessAttribute(
2513     sal_uInt16 nAttrToken,
2514     const OUString& sAttrValue )
2515 {
2516     switch (nAttrToken)
2517     {
2518         case XML_TOK_TEXTFIELD_NUM_FORMAT:
2519             sNumberFormat = sAttrValue;
2520             bNumberFormatOK = sal_True;
2521             break;
2522         case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
2523             sLetterSync = sAttrValue;
2524             break;
2525     }
2526 }
2527 
2528 void XMLCountFieldImportContext::PrepareField(
2529     const Reference<XPropertySet> & xPropertySet)
2530 {
2531     Any aAny;
2532 
2533     // properties optional
2534     // (only page count, but do for all to save common implementation)
2535 
2536     if (xPropertySet->getPropertySetInfo()->
2537         hasPropertyByName(sPropertyNumberingType))
2538     {
2539         sal_Int16 nNumType;
2540         if( bNumberFormatOK )
2541         {
2542             nNumType= style::NumberingType::ARABIC;
2543             GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2544                                                     sNumberFormat,
2545                                                     sLetterSync );
2546         }
2547         else
2548             nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2549         aAny <<= nNumType;
2550         xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
2551     }
2552 }
2553 
2554 const sal_Char* XMLCountFieldImportContext::MapTokenToServiceName(
2555     sal_uInt16 nToken)
2556 {
2557     const sal_Char* pServiceName = NULL;
2558 
2559     switch (nToken)
2560     {
2561         case XML_TOK_TEXT_WORD_COUNT:
2562             pServiceName = sAPI_word_count;
2563             break;
2564         case XML_TOK_TEXT_PARAGRAPH_COUNT:
2565             pServiceName = sAPI_paragraph_count;
2566             break;
2567         case XML_TOK_TEXT_TABLE_COUNT:
2568             pServiceName = sAPI_table_count;
2569             break;
2570         case XML_TOK_TEXT_CHARACTER_COUNT:
2571             pServiceName = sAPI_character_count;
2572             break;
2573         case XML_TOK_TEXT_IMAGE_COUNT:
2574             pServiceName = sAPI_graphic_object_count;
2575             break;
2576         case XML_TOK_TEXT_OBJECT_COUNT:
2577             pServiceName = sAPI_embedded_object_count;
2578             break;
2579         case XML_TOK_TEXT_PAGE_COUNT:
2580             pServiceName = sAPI_page_count;
2581             break;
2582         default:
2583             pServiceName = NULL;
2584             DBG_ERROR("unknown count field!");
2585             break;
2586     }
2587 
2588     return pServiceName;
2589 }
2590 
2591 
2592 
2593 //
2594 // page variable import
2595 //
2596 
2597 TYPEINIT1( XMLPageVarGetFieldImportContext, XMLTextFieldImportContext );
2598 
2599 XMLPageVarGetFieldImportContext::XMLPageVarGetFieldImportContext(
2600     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2601     sal_uInt16 nPrfx, const OUString& sLocalName) :
2602         XMLTextFieldImportContext(rImport, rHlp, sAPI_reference_page_get,
2603                                   nPrfx, sLocalName),
2604         sPropertyNumberingType(
2605             RTL_CONSTASCII_USTRINGPARAM(sAPI_numbering_type)),
2606         sNumberFormat(),
2607         sLetterSync(),
2608         bNumberFormatOK(sal_False)
2609 {
2610     bValid = sal_True;
2611 }
2612 
2613 void XMLPageVarGetFieldImportContext::ProcessAttribute(
2614     sal_uInt16 nAttrToken,
2615     const OUString& sAttrValue )
2616 {
2617     switch (nAttrToken)
2618     {
2619         case XML_TOK_TEXTFIELD_NUM_FORMAT:
2620             sNumberFormat = sAttrValue;
2621             bNumberFormatOK = sal_True;
2622             break;
2623         case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
2624             sLetterSync = sAttrValue;
2625             break;
2626     }
2627 }
2628 
2629 void XMLPageVarGetFieldImportContext::PrepareField(
2630     const Reference<XPropertySet> & xPropertySet)
2631 {
2632     Any aAny;
2633 
2634     sal_Int16 nNumType;
2635     if( bNumberFormatOK )
2636     {
2637         nNumType= style::NumberingType::ARABIC;
2638         GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2639                                                     sNumberFormat,
2640                                                     sLetterSync );
2641     }
2642     else
2643         nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2644     aAny <<= nNumType;
2645     xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
2646 
2647     // display old content (#96657#)
2648     aAny <<= GetContent();
2649     xPropertySet->setPropertyValue(
2650         OUString(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation)),
2651         aAny );
2652 }
2653 
2654 
2655 
2656 //
2657 // page variable set fields
2658 //
2659 
2660 TYPEINIT1(XMLPageVarSetFieldImportContext, XMLTextFieldImportContext);
2661 
2662 XMLPageVarSetFieldImportContext::XMLPageVarSetFieldImportContext(
2663     SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2664     const OUString& sLocalName) :
2665         XMLTextFieldImportContext(rImport, rHlp, sAPI_reference_page_set,
2666                                   nPrfx, sLocalName),
2667         sPropertyOn(RTL_CONSTASCII_USTRINGPARAM(sAPI_on)),
2668         sPropertyOffset(RTL_CONSTASCII_USTRINGPARAM(sAPI_offset)),
2669         nAdjust(0),
2670         bActive(sal_True)
2671 {
2672     bValid = sal_True;
2673 }
2674 
2675 void XMLPageVarSetFieldImportContext::ProcessAttribute(
2676     sal_uInt16 nAttrToken,
2677     const ::rtl::OUString& sAttrValue )
2678 {
2679     switch (nAttrToken)
2680     {
2681         case XML_TOK_TEXTFIELD_ACTIVE:
2682         {
2683             sal_Bool bTmp;
2684             if (SvXMLUnitConverter::convertBool(bTmp, sAttrValue))
2685             {
2686                 bActive = bTmp;
2687             }
2688         }
2689         case XML_TOK_TEXTFIELD_PAGE_ADJUST:
2690         {
2691             sal_Int32 nTmp;
2692             if (SvXMLUnitConverter::convertNumber(nTmp, sAttrValue))
2693             {
2694                 nAdjust = (sal_Int16)nTmp;
2695             }
2696         }
2697     }
2698 }
2699 
2700 void XMLPageVarSetFieldImportContext::PrepareField(
2701     const Reference<XPropertySet> & xPropertySet)
2702 {
2703     Any aAny;
2704 
2705     aAny.setValue(&bActive, ::getBooleanCppuType());
2706     xPropertySet->setPropertyValue(sPropertyOn, aAny);
2707 
2708     aAny <<= nAdjust;
2709     xPropertySet->setPropertyValue(sPropertyOffset, aAny);
2710 }
2711 
2712 
2713 
2714 //
2715 // macro fields
2716 //
2717 
2718 TYPEINIT1( XMLMacroFieldImportContext, XMLTextFieldImportContext );
2719 
2720 XMLMacroFieldImportContext::XMLMacroFieldImportContext(
2721     SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2722     const OUString& sLocalName) :
2723         XMLTextFieldImportContext(rImport, rHlp, sAPI_macro,
2724                                   nPrfx, sLocalName),
2725         sPropertyHint(RTL_CONSTASCII_USTRINGPARAM(sAPI_hint)),
2726         sPropertyMacroName(RTL_CONSTASCII_USTRINGPARAM("MacroName")),
2727         sPropertyScriptURL(RTL_CONSTASCII_USTRINGPARAM("ScriptURL")),
2728         bDescriptionOK(sal_False)
2729 {
2730 }
2731 
2732 SvXMLImportContext* XMLMacroFieldImportContext::CreateChildContext(
2733     sal_uInt16 nPrefix,
2734     const OUString& rLocalName,
2735     const Reference<XAttributeList> & xAttrList )
2736 {
2737     SvXMLImportContext* pContext = NULL;
2738 
2739     if ( (nPrefix == XML_NAMESPACE_OFFICE) &&
2740          IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
2741     {
2742         // create events context and remember it!
2743         pContext = new XMLEventsImportContext(
2744             GetImport(), nPrefix, rLocalName );
2745         xEventContext = pContext;
2746         bValid = sal_True;
2747     }
2748     else
2749         pContext = SvXMLImportContext::CreateChildContext(
2750             nPrefix, rLocalName, xAttrList);
2751 
2752     return pContext;
2753 }
2754 
2755 
2756 void XMLMacroFieldImportContext::ProcessAttribute(
2757     sal_uInt16 nAttrToken,
2758     const OUString& sAttrValue )
2759 {
2760     switch (nAttrToken)
2761     {
2762         case XML_TOK_TEXTFIELD_DESCRIPTION:
2763             sDescription = sAttrValue;
2764             bDescriptionOK = sal_True;
2765             break;
2766         case XML_TOK_TEXTFIELD_NAME:
2767             sMacro = sAttrValue;
2768             bValid = sal_True;
2769             break;
2770     }
2771 }
2772 
2773 void XMLMacroFieldImportContext::PrepareField(
2774     const Reference<XPropertySet> & xPropertySet)
2775 {
2776     Any aAny;
2777 
2778     OUString sOnClick(RTL_CONSTASCII_USTRINGPARAM("OnClick"));
2779     OUString sPropertyMacroLibrary(RTL_CONSTASCII_USTRINGPARAM("MacroLibrary"));
2780 
2781     aAny <<= (bDescriptionOK ? sDescription : GetContent());
2782     xPropertySet->setPropertyValue(sPropertyHint, aAny);
2783 
2784     // if we have an events child element, we'll look for the OnClick
2785     // event if not, it may be an old (pre-638i) document. Then, we'll
2786     // have to look at the name attribute.
2787     OUString sMacroName;
2788     OUString sLibraryName;
2789     OUString sScriptURL;
2790 
2791     if ( xEventContext.Is() )
2792     {
2793         // get event sequence
2794         XMLEventsImportContext* pEvents =
2795             (XMLEventsImportContext*)&xEventContext;
2796         Sequence<PropertyValue> aValues;
2797         pEvents->GetEventSequence( sOnClick, aValues );
2798 
2799         sal_Int32 nLength = aValues.getLength();
2800         for( sal_Int32 i = 0; i < nLength; i++ )
2801         {
2802             if ( aValues[i].Name.equalsAsciiL( "ScriptType",
2803                                                sizeof("ScriptType")-1 ) )
2804             {
2805                 // ignore ScriptType
2806             }
2807             else if ( aValues[i].Name.equalsAsciiL( "Library",
2808                                                     sizeof("Library")-1 ) )
2809             {
2810                 aValues[i].Value >>= sLibraryName;
2811             }
2812             else if ( aValues[i].Name.equalsAsciiL( "MacroName",
2813                                                     sizeof("MacroName")-1 ) )
2814             {
2815                 aValues[i].Value >>= sMacroName;
2816             }
2817             if ( aValues[i].Name.equalsAsciiL( "Script",
2818                                                sizeof("Script")-1 ) )
2819             {
2820                 aValues[i].Value >>= sScriptURL;
2821             }
2822         }
2823     }
2824     else
2825     {
2826         // disassemble old-style macro-name: Everything before the
2827         // third-last dot is the library
2828         sal_Int32 nPos = sMacro.getLength() + 1;    // the loop starts with nPos--
2829         const sal_Unicode* pBuf = sMacro.getStr();
2830         for( sal_Int32 i = 0; (i < 3) && (nPos > 0); i++ )
2831         {
2832             nPos--;
2833             while ( (pBuf[nPos] != '.') && (nPos > 0) )
2834                 nPos--;
2835         }
2836 
2837         if (nPos > 0)
2838         {
2839             sLibraryName = sMacro.copy(0, nPos);
2840             sMacroName = sMacro.copy(nPos+1);
2841         }
2842         else
2843             sMacroName = sMacro;
2844     }
2845 
2846     aAny <<= sScriptURL;
2847     xPropertySet->setPropertyValue(sPropertyScriptURL, aAny);
2848 
2849     aAny <<= sMacroName;
2850     xPropertySet->setPropertyValue(sPropertyMacroName, aAny);
2851 
2852     aAny <<= sLibraryName;
2853     xPropertySet->setPropertyValue(sPropertyMacroLibrary, aAny);
2854 }
2855 
2856 
2857 
2858 //
2859 // reference field import
2860 //
2861 
2862 TYPEINIT1( XMLReferenceFieldImportContext, XMLTextFieldImportContext );
2863 
2864 XMLReferenceFieldImportContext::XMLReferenceFieldImportContext(
2865     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2866     sal_uInt16 nToken, sal_uInt16 nPrfx, const OUString& sLocalName)
2867 :   XMLTextFieldImportContext(rImport, rHlp, sAPI_get_reference, nPrfx, sLocalName)
2868 ,   sPropertyReferenceFieldPart(RTL_CONSTASCII_USTRINGPARAM(sAPI_reference_field_part))
2869 ,   sPropertyReferenceFieldSource(RTL_CONSTASCII_USTRINGPARAM(sAPI_reference_field_source))
2870 ,   sPropertySourceName(RTL_CONSTASCII_USTRINGPARAM(sAPI_source_name))
2871 ,   sPropertyCurrentPresentation(RTL_CONSTASCII_USTRINGPARAM(sAPI_current_presentation))
2872 ,   nElementToken(nToken)
2873 ,   nType(ReferenceFieldPart::PAGE_DESC)
2874 ,   bNameOK(sal_False)
2875 ,   bTypeOK(sal_False)
2876 ,   bSeqNumberOK(sal_False)
2877 {
2878 }
2879 
2880 static SvXMLEnumMapEntry __READONLY_DATA lcl_aReferenceTypeTokenMap[] =
2881 {
2882     { XML_PAGE,         ReferenceFieldPart::PAGE},
2883     { XML_CHAPTER,      ReferenceFieldPart::CHAPTER },
2884     { XML_TEXT,         ReferenceFieldPart::TEXT },
2885     { XML_DIRECTION,    ReferenceFieldPart::UP_DOWN },
2886     { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
2887     { XML_CAPTION,      ReferenceFieldPart::ONLY_CAPTION },
2888     { XML_VALUE,        ReferenceFieldPart::ONLY_SEQUENCE_NUMBER },
2889     // --> OD 2007-09-14 #i81002#
2890     { XML_NUMBER,               ReferenceFieldPart::NUMBER },
2891     { XML_NUMBER_NO_SUPERIOR,   ReferenceFieldPart::NUMBER_NO_CONTEXT },
2892     { XML_NUMBER_ALL_SUPERIOR,  ReferenceFieldPart::NUMBER_FULL_CONTEXT },
2893     // <--
2894     { XML_TOKEN_INVALID, 0 }
2895 };
2896 
2897 void XMLReferenceFieldImportContext::StartElement(
2898     const Reference<XAttributeList> & xAttrList)
2899 {
2900     bTypeOK = sal_True;
2901     switch (nElementToken)
2902     {
2903         case XML_TOK_TEXT_REFERENCE_REF:
2904             nSource = ReferenceFieldSource::REFERENCE_MARK;
2905             break;
2906         case XML_TOK_TEXT_BOOKMARK_REF:
2907             nSource = ReferenceFieldSource::BOOKMARK;
2908             break;
2909         case XML_TOK_TEXT_NOTE_REF:
2910             nSource = ReferenceFieldSource::FOOTNOTE;
2911             break;
2912         case XML_TOK_TEXT_SEQUENCE_REF:
2913             nSource = ReferenceFieldSource::SEQUENCE_FIELD;
2914             break;
2915         default:
2916             bTypeOK = sal_False;
2917             DBG_ERROR("unknown reference field");
2918             break;
2919     }
2920 
2921     XMLTextFieldImportContext::StartElement(xAttrList);
2922 }
2923 
2924 
2925 void XMLReferenceFieldImportContext::ProcessAttribute(
2926     sal_uInt16 nAttrToken,
2927     const OUString& sAttrValue )
2928 {
2929     switch (nAttrToken)
2930     {
2931         case XML_TOK_TEXTFIELD_NOTE_CLASS:
2932             if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
2933                 nSource = ReferenceFieldSource::ENDNOTE;
2934             break;
2935         case XML_TOK_TEXTFIELD_REF_NAME:
2936             sName = sAttrValue;
2937             bNameOK = sal_True;
2938             break;
2939         case XML_TOK_TEXTFIELD_REFERENCE_FORMAT:
2940         {
2941             sal_uInt16 nToken;
2942             if (SvXMLUnitConverter::convertEnum(nToken, sAttrValue,
2943                                                 lcl_aReferenceTypeTokenMap))
2944             {
2945                 nType = nToken;
2946             }
2947 
2948             // check for sequence-only-attributes
2949             if ( (XML_TOK_TEXT_SEQUENCE_REF != nElementToken) &&
2950                  ( (nType == ReferenceFieldPart::CATEGORY_AND_NUMBER) ||
2951                    (nType == ReferenceFieldPart::ONLY_CAPTION) ||
2952                    (nType == ReferenceFieldPart::ONLY_SEQUENCE_NUMBER) ) )
2953             {
2954                 nType = ReferenceFieldPart::PAGE_DESC;
2955             }
2956 
2957             break;
2958         }
2959     }
2960 
2961     // bValid: we need proper element type and name
2962     bValid = bTypeOK && bNameOK;
2963 }
2964 
2965 void XMLReferenceFieldImportContext::PrepareField(
2966     const Reference<XPropertySet> & xPropertySet)
2967 {
2968     Any aAny;
2969 
2970     aAny <<= nType;
2971     xPropertySet->setPropertyValue(sPropertyReferenceFieldPart, aAny);
2972 
2973     aAny <<= nSource;
2974     xPropertySet->setPropertyValue(sPropertyReferenceFieldSource, aAny);
2975 
2976     switch (nElementToken)
2977     {
2978         case XML_TOK_TEXT_REFERENCE_REF:
2979         case XML_TOK_TEXT_BOOKMARK_REF:
2980             aAny <<= sName;
2981             xPropertySet->setPropertyValue(sPropertySourceName, aAny);
2982             break;
2983 
2984         case XML_TOK_TEXT_NOTE_REF:
2985             GetImportHelper().ProcessFootnoteReference(sName, xPropertySet);
2986             break;
2987 
2988         case XML_TOK_TEXT_SEQUENCE_REF:
2989             GetImportHelper().ProcessSequenceReference(sName, xPropertySet);
2990             break;
2991     }
2992 
2993     aAny <<= GetContent();
2994     xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
2995 }
2996 
2997 
2998 
2999 //
3000 // field declarations container
3001 //
3002 
3003 enum DdeFieldDeclAttrs
3004 {
3005     XML_TOK_DDEFIELD_NAME,
3006     XML_TOK_DDEFIELD_APPLICATION,
3007     XML_TOK_DDEFIELD_TOPIC,
3008     XML_TOK_DDEFIELD_ITEM,
3009     XML_TOK_DDEFIELD_UPDATE
3010 };
3011 
3012 static __FAR_DATA SvXMLTokenMapEntry aDdeDeclAttrTokenMap[] =
3013 {
3014     { XML_NAMESPACE_OFFICE, XML_NAME, XML_TOK_DDEFIELD_NAME },
3015     { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, XML_TOK_DDEFIELD_APPLICATION },
3016     { XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, XML_TOK_DDEFIELD_TOPIC },
3017     { XML_NAMESPACE_OFFICE, XML_DDE_ITEM, XML_TOK_DDEFIELD_ITEM },
3018     { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE, XML_TOK_DDEFIELD_UPDATE },
3019     XML_TOKEN_MAP_END
3020 };
3021 
3022 TYPEINIT1( XMLDdeFieldDeclsImportContext, SvXMLImportContext );
3023 
3024 XMLDdeFieldDeclsImportContext::XMLDdeFieldDeclsImportContext(
3025     SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& sLocalName) :
3026         SvXMLImportContext(rImport, nPrfx, sLocalName),
3027         aTokenMap(aDdeDeclAttrTokenMap)
3028 {
3029 }
3030 
3031 SvXMLImportContext * XMLDdeFieldDeclsImportContext::CreateChildContext(
3032     sal_uInt16 nPrefix,
3033     const OUString& rLocalName,
3034     const Reference<XAttributeList> & xAttrList )
3035 {
3036     if ( (XML_NAMESPACE_TEXT == nPrefix) &&
3037          (IsXMLToken(rLocalName, XML_DDE_CONNECTION_DECL)) )
3038     {
3039         return new XMLDdeFieldDeclImportContext(GetImport(), nPrefix,
3040                                                 rLocalName, aTokenMap);
3041     }
3042     else
3043     {
3044         return SvXMLImportContext::CreateChildContext(nPrefix,
3045                                                       rLocalName,
3046                                                       xAttrList);
3047     }
3048 }
3049 
3050 
3051 
3052 //
3053 // import dde field declaration
3054 //
3055 
3056 TYPEINIT1( XMLDdeFieldDeclImportContext, SvXMLImportContext );
3057 
3058 XMLDdeFieldDeclImportContext::XMLDdeFieldDeclImportContext(
3059     SvXMLImport& rImport, sal_uInt16 nPrfx,
3060     const OUString& sLocalName, const SvXMLTokenMap& rMap)
3061 :   SvXMLImportContext(rImport, nPrfx, sLocalName)
3062 ,   sPropertyIsAutomaticUpdate(RTL_CONSTASCII_USTRINGPARAM(sAPI_is_automatic_update))
3063 ,   sPropertyName(RTL_CONSTASCII_USTRINGPARAM(sAPI_name))
3064 ,   sPropertyDDECommandType(RTL_CONSTASCII_USTRINGPARAM(sAPI_dde_command_type))
3065 ,   sPropertyDDECommandFile(RTL_CONSTASCII_USTRINGPARAM(sAPI_dde_command_file))
3066 ,   sPropertyDDECommandElement(RTL_CONSTASCII_USTRINGPARAM(sAPI_dde_command_element))
3067 ,   rTokenMap(rMap)
3068 {
3069     DBG_ASSERT(XML_NAMESPACE_TEXT == nPrfx, "wrong prefix");
3070     DBG_ASSERT(IsXMLToken(sLocalName, XML_DDE_CONNECTION_DECL), "wrong name");
3071 }
3072 
3073 void XMLDdeFieldDeclImportContext::StartElement(
3074     const Reference<XAttributeList> & xAttrList)
3075 {
3076     OUString sName;
3077     OUString sCommandApplication;
3078     OUString sCommandTopic;
3079     OUString sCommandItem;
3080 
3081     sal_Bool bUpdate = sal_False;
3082     sal_Bool bNameOK = sal_False;
3083     sal_Bool bCommandApplicationOK = sal_False;
3084     sal_Bool bCommandTopicOK = sal_False;
3085     sal_Bool bCommandItemOK = sal_False;
3086 
3087     // process attributes
3088     sal_Int16 nLength = xAttrList->getLength();
3089     for(sal_Int16 i=0; i<nLength; i++)
3090     {
3091 
3092         OUString sLocalName;
3093         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
3094             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
3095 
3096         switch (rTokenMap.Get(nPrefix, sLocalName))
3097         {
3098             case XML_TOK_DDEFIELD_NAME:
3099                 sName = xAttrList->getValueByIndex(i);
3100                 bNameOK = sal_True;
3101                 break;
3102             case XML_TOK_DDEFIELD_APPLICATION:
3103                 sCommandApplication = xAttrList->getValueByIndex(i);
3104                 bCommandApplicationOK = sal_True;
3105                 break;
3106             case XML_TOK_DDEFIELD_TOPIC:
3107                 sCommandTopic = xAttrList->getValueByIndex(i);
3108                 bCommandTopicOK = sal_True;
3109                 break;
3110             case XML_TOK_DDEFIELD_ITEM:
3111                 sCommandItem = xAttrList->getValueByIndex(i);
3112                 bCommandItemOK = sal_True;
3113                 break;
3114             case XML_TOK_DDEFIELD_UPDATE:
3115             {
3116                 sal_Bool bTmp;
3117                 if ( SvXMLUnitConverter::convertBool(
3118                     bTmp, xAttrList->getValueByIndex(i)) )
3119                 {
3120                     bUpdate = bTmp;
3121                 }
3122                 break;
3123             }
3124         }
3125     }
3126 
3127     // valid data?
3128     if (bNameOK && bCommandApplicationOK && bCommandTopicOK && bCommandItemOK)
3129     {
3130         // make service name
3131         OUStringBuffer sBuf;
3132         sBuf.appendAscii(sAPI_fieldmaster_prefix);
3133         sBuf.appendAscii(sAPI_dde);
3134 
3135         // create DDE TextFieldMaster
3136         Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),
3137                                                  UNO_QUERY);
3138         if( xFactory.is() )
3139         {
3140             /* #i6432# There might be multiple occurances of one DDE
3141                declaration if it is used in more than one of
3142                header/footer/body. createInstance will throw an exception if we
3143                try to create the second, third, etc. instance of such a
3144                declaration. Thus we ignore the exception. Otherwise this will
3145                lead to an unloadable document. */
3146             try
3147             {
3148                 Reference<XInterface> xIfc =
3149                     xFactory->createInstance(sBuf.makeStringAndClear());
3150                 if( xIfc.is() )
3151                 {
3152                     Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
3153                     if (xPropSet.is() &&
3154                         xPropSet->getPropertySetInfo()->hasPropertyByName(
3155                                                                           sPropertyDDECommandType))
3156                     {
3157                         Any aAny;
3158 
3159                         aAny <<= sName;
3160                         xPropSet->setPropertyValue(sPropertyName, aAny);
3161 
3162                         aAny <<= sCommandApplication;
3163                         xPropSet->setPropertyValue(sPropertyDDECommandType, aAny);
3164 
3165                         aAny <<= sCommandTopic;
3166                         xPropSet->setPropertyValue(sPropertyDDECommandFile, aAny);
3167 
3168                         aAny <<= sCommandItem;
3169                         xPropSet->setPropertyValue(sPropertyDDECommandElement,
3170                                                    aAny);
3171 
3172                         aAny.setValue(&bUpdate, ::getBooleanCppuType());
3173                         xPropSet->setPropertyValue(sPropertyIsAutomaticUpdate,
3174                                                    aAny);
3175                     }
3176                     // else: ignore (can't get XPropertySet, or DDE
3177                     //               properties are not supported)
3178                 }
3179                 // else: ignore
3180             }
3181             catch ( const Exception& )
3182             {
3183                 //ignore
3184             }
3185         }
3186         // else: ignore
3187     }
3188     // else: ignore
3189 }
3190 
3191 
3192 
3193 //
3194 // DDE field import
3195 //
3196 
3197 TYPEINIT1( XMLDdeFieldImportContext, XMLTextFieldImportContext );
3198 
3199 XMLDdeFieldImportContext::XMLDdeFieldImportContext(
3200     SvXMLImport& rImport, XMLTextImportHelper& rHlp,
3201     sal_uInt16 nPrfx, const OUString& sLocalName) :
3202         XMLTextFieldImportContext(rImport, rHlp, sAPI_dde,
3203                                   nPrfx, sLocalName),
3204         sName()
3205         ,sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content))
3206 {
3207 }
3208 
3209 void XMLDdeFieldImportContext::ProcessAttribute(
3210     sal_uInt16 nAttrToken,
3211     const ::rtl::OUString& sAttrValue )
3212 {
3213     if (XML_TOK_TEXTFIELD_CONNECTION_NAME == nAttrToken)
3214     {
3215         sName = sAttrValue;
3216         bValid = sal_True;
3217     }
3218 }
3219 
3220 void XMLDdeFieldImportContext::EndElement()
3221 {
3222     if (bValid)
3223     {
3224         // find master
3225         OUStringBuffer sBuf;
3226         sBuf.appendAscii(sAPI_fieldmaster_prefix);
3227         sBuf.appendAscii(sAPI_dde);
3228         sBuf.append(sal_Unicode('.'));
3229         sBuf.append(sName);
3230         OUString sMasterName = sBuf.makeStringAndClear();
3231 
3232         Reference<XTextFieldsSupplier> xTextFieldsSupp(GetImport().GetModel(),
3233                                                        UNO_QUERY);
3234         Reference<container::XNameAccess> xFieldMasterNameAccess(
3235             xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY);
3236 
3237         if (xFieldMasterNameAccess->hasByName(sMasterName))
3238         {
3239             Reference<XPropertySet> xMaster;
3240             Any aAny = xFieldMasterNameAccess->getByName(sMasterName);
3241             aAny >>= xMaster;
3242             //apply the content to the master
3243             xMaster->setPropertyValue( sPropertyContent, uno::makeAny( GetContent()));
3244             // master exists: create text field and attach
3245             Reference<XPropertySet> xField;
3246             sBuf.appendAscii(sAPI_textfield_prefix);
3247             sBuf.appendAscii(sAPI_dde);
3248             if (CreateField(xField, sBuf.makeStringAndClear()))
3249             {
3250                 Reference<XDependentTextField> xDepTextField(xField,UNO_QUERY);
3251                 xDepTextField->attachTextFieldMaster(xMaster);
3252 
3253                 // attach field to document
3254                 Reference<XTextContent> xTextContent(xField, UNO_QUERY);
3255                 if (xTextContent.is())
3256                 {
3257                     GetImportHelper().InsertTextContent(xTextContent);
3258 
3259                     // we're lucky. nothing else to prepare.
3260                 }
3261                 // else: fail, because text content could not be created
3262             }
3263             // else: fail, because field could not be created
3264         }
3265         // else: fail, because no master was found (faulty document?!)
3266     }
3267     // not valid: ignore
3268 }
3269 
3270 void XMLDdeFieldImportContext::PrepareField(
3271     const Reference<XPropertySet> &)
3272 {
3273     // empty, since not needed.
3274 }
3275 
3276 
3277 //
3278 // sheet name fields
3279 //
3280 
3281 TYPEINIT1(XMLSheetNameImportContext, XMLTextFieldImportContext);
3282 
3283 XMLSheetNameImportContext::XMLSheetNameImportContext(
3284     SvXMLImport& rImport,
3285     XMLTextImportHelper& rHlp,
3286     sal_uInt16 nPrfx,
3287     const OUString& sLocalName) :
3288         XMLTextFieldImportContext(rImport, rHlp, sAPI_sheet_name,
3289                                   nPrfx, sLocalName)
3290 {
3291     bValid = sal_True;  // always valid!
3292 }
3293 
3294 void XMLSheetNameImportContext::ProcessAttribute(
3295     sal_uInt16,
3296     const ::rtl::OUString& )
3297 {
3298     // no attributes -> nothing to be done
3299 }
3300 
3301 void XMLSheetNameImportContext::PrepareField(
3302     const Reference<XPropertySet> &)
3303 {
3304     // no attributes -> nothing to be done
3305 }
3306 
3307 
3308 //
3309 // URL fields (Calc, Impress, Draw)
3310 //
3311 
3312 TYPEINIT1(XMLUrlFieldImportContext, XMLTextFieldImportContext);
3313 
3314 XMLUrlFieldImportContext::XMLUrlFieldImportContext(
3315     SvXMLImport& rImport,
3316     XMLTextImportHelper& rHlp,
3317     sal_uInt16 nPrfx,
3318     const OUString& sLocalName) :
3319         XMLTextFieldImportContext(rImport, rHlp, sAPI_url,
3320                                   nPrfx, sLocalName),
3321         sPropertyURL(RTL_CONSTASCII_USTRINGPARAM(sAPI_url)),
3322         sPropertyTargetFrame(RTL_CONSTASCII_USTRINGPARAM(sAPI_target_frame)),
3323         sPropertyRepresentation(RTL_CONSTASCII_USTRINGPARAM(
3324             sAPI_representation)),
3325         bFrameOK(sal_False)
3326 {
3327 }
3328 
3329 void XMLUrlFieldImportContext::ProcessAttribute(
3330     sal_uInt16 nAttrToken,
3331     const OUString& sAttrValue )
3332 {
3333     switch (nAttrToken)
3334     {
3335         case XML_TOK_TEXTFIELD_HREF:
3336             sURL = GetImport().GetAbsoluteReference( sAttrValue );
3337             bValid = sal_True;
3338             break;
3339         case XML_TOK_TEXTFIELD_TARGET_FRAME:
3340             sFrame = sAttrValue;
3341             bFrameOK = sal_True;
3342             break;
3343         default:
3344             // ignore
3345             break;
3346     }
3347 }
3348 
3349 void XMLUrlFieldImportContext::PrepareField(
3350     const Reference<XPropertySet> & xPropertySet)
3351 {
3352     Any aAny;
3353 
3354     aAny <<= sURL;
3355     xPropertySet->setPropertyValue(sPropertyURL, aAny);
3356 
3357     if (bFrameOK)
3358     {
3359         aAny <<= sFrame;
3360         xPropertySet->setPropertyValue(sPropertyTargetFrame, aAny);
3361     }
3362 
3363     aAny <<= GetContent();
3364     xPropertySet->setPropertyValue(sPropertyRepresentation, aAny);
3365 }
3366 
3367 
3368 TYPEINIT1(XMLBibliographyFieldImportContext, XMLTextFieldImportContext);
3369 
3370 
3371 XMLBibliographyFieldImportContext::XMLBibliographyFieldImportContext(
3372     SvXMLImport& rImport,
3373     XMLTextImportHelper& rHlp,
3374     sal_uInt16 nPrfx,
3375     const OUString& sLocalName) :
3376         XMLTextFieldImportContext(rImport, rHlp, sAPI_bibliography,
3377                                   nPrfx, sLocalName),
3378         sPropertyFields(RTL_CONSTASCII_USTRINGPARAM("Fields")),
3379         aValues()
3380 {
3381     bValid = sal_True;
3382 }
3383 
3384 // TODO: this is the same map as is used in the text field export
3385 SvXMLEnumMapEntry __READONLY_DATA aBibliographyDataTypeMap[] =
3386 {
3387     { XML_ARTICLE,          BibliographyDataType::ARTICLE },
3388     { XML_BOOK,             BibliographyDataType::BOOK },
3389     { XML_BOOKLET,          BibliographyDataType::BOOKLET },
3390     { XML_CONFERENCE,       BibliographyDataType::CONFERENCE },
3391     { XML_CUSTOM1,          BibliographyDataType::CUSTOM1 },
3392     { XML_CUSTOM2,          BibliographyDataType::CUSTOM2 },
3393     { XML_CUSTOM3,          BibliographyDataType::CUSTOM3 },
3394     { XML_CUSTOM4,          BibliographyDataType::CUSTOM4 },
3395     { XML_CUSTOM5,          BibliographyDataType::CUSTOM5 },
3396     { XML_EMAIL,            BibliographyDataType::EMAIL },
3397     { XML_INBOOK,           BibliographyDataType::INBOOK },
3398     { XML_INCOLLECTION,     BibliographyDataType::INCOLLECTION },
3399     { XML_INPROCEEDINGS,    BibliographyDataType::INPROCEEDINGS },
3400     { XML_JOURNAL,          BibliographyDataType::JOURNAL },
3401     { XML_MANUAL,           BibliographyDataType::MANUAL },
3402     { XML_MASTERSTHESIS,    BibliographyDataType::MASTERSTHESIS },
3403     { XML_MISC,             BibliographyDataType::MISC },
3404     { XML_PHDTHESIS,        BibliographyDataType::PHDTHESIS },
3405     { XML_PROCEEDINGS,      BibliographyDataType::PROCEEDINGS },
3406     { XML_TECHREPORT,       BibliographyDataType::TECHREPORT },
3407     { XML_UNPUBLISHED,      BibliographyDataType::UNPUBLISHED },
3408     { XML_WWW,              BibliographyDataType::WWW },
3409     { XML_TOKEN_INVALID, 0 }
3410 };
3411 
3412 
3413 // we'll process attributes on our own and forfit the standard
3414 // tecfield mechanism, because our attributes have zero overlp with
3415 // all the oher textfields.
3416 void XMLBibliographyFieldImportContext::StartElement(
3417         const Reference<XAttributeList> & xAttrList)
3418 {
3419     // iterate over attributes
3420     sal_Int16 nLength = xAttrList->getLength();
3421     for(sal_Int16 i=0; i<nLength; i++) {
3422 
3423         OUString sLocalName;
3424         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
3425             GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
3426 
3427         if (nPrefix == XML_NAMESPACE_TEXT)
3428         {
3429             PropertyValue aValue;
3430             aValue.Name = OUString::createFromAscii(
3431                 MapBibliographyFieldName(sLocalName));
3432             Any aAny;
3433 
3434             // special treatment for bibliography type
3435             // biblio vs bibilio: #96658#; also read old documents
3436             if (IsXMLToken(sLocalName, XML_BIBILIOGRAPHIC_TYPE) ||
3437                 IsXMLToken(sLocalName, XML_BIBLIOGRAPHY_TYPE)    )
3438             {
3439                 sal_uInt16 nTmp;
3440                 if (SvXMLUnitConverter::convertEnum(
3441                     nTmp, xAttrList->getValueByIndex(i),
3442                     aBibliographyDataTypeMap))
3443                 {
3444                     aAny <<= (sal_Int16)nTmp;
3445                     aValue.Value = aAny;
3446 
3447                     aValues.push_back(aValue);
3448                 }
3449             }
3450             else
3451             {
3452                 aAny <<= xAttrList->getValueByIndex(i);
3453                 aValue.Value = aAny;
3454 
3455                 aValues.push_back(aValue);
3456             }
3457         }
3458         // else: unknown namespace -> ignore
3459     }
3460 }
3461 
3462 void XMLBibliographyFieldImportContext::ProcessAttribute(
3463     sal_uInt16,
3464     const OUString& )
3465 {
3466     // attributes are handled in StartElement
3467     DBG_ERROR("This should not have happened.");
3468 }
3469 
3470 
3471 void XMLBibliographyFieldImportContext::PrepareField(
3472     const Reference<XPropertySet> & xPropertySet)
3473 {
3474     // convert vector into sequence
3475     sal_Int32 nCount = aValues.size();
3476     Sequence<PropertyValue> aValueSequence(nCount);
3477     for(sal_Int32 i = 0; i < nCount; i++)
3478     {
3479         aValueSequence[i] = aValues[i];
3480     }
3481 
3482     // set sequence
3483     Any aAny;
3484     aAny <<= aValueSequence;
3485     xPropertySet->setPropertyValue(sPropertyFields, aAny);
3486 }
3487 
3488 const sal_Char* XMLBibliographyFieldImportContext::MapBibliographyFieldName(
3489     OUString sName)
3490 {
3491     const sal_Char* pName = NULL;
3492 
3493     if (IsXMLToken(sName, XML_IDENTIFIER))
3494     {
3495         pName = "Identifier";
3496     }
3497     else if (IsXMLToken(sName, XML_BIBILIOGRAPHIC_TYPE) ||
3498              IsXMLToken(sName, XML_BIBLIOGRAPHY_TYPE)     )
3499     {
3500         // biblio... vs bibilio...: #96658#: also read old documents
3501         pName = "BibiliographicType";
3502     }
3503     else if (IsXMLToken(sName, XML_ADDRESS))
3504     {
3505         pName = "Address";
3506     }
3507     else if (IsXMLToken(sName, XML_ANNOTE))
3508     {
3509         pName = "Annote";
3510     }
3511     else if (IsXMLToken(sName, XML_AUTHOR))
3512     {
3513         pName = "Author";
3514     }
3515     else if (IsXMLToken(sName, XML_BOOKTITLE))
3516     {
3517         pName = "Booktitle";
3518     }
3519     else if (IsXMLToken(sName, XML_CHAPTER))
3520     {
3521         pName = "Chapter";
3522     }
3523     else if (IsXMLToken(sName, XML_EDITION))
3524     {
3525         pName = "Edition";
3526     }
3527     else if (IsXMLToken(sName, XML_EDITOR))
3528     {
3529         pName = "Editor";
3530     }
3531     else if (IsXMLToken(sName, XML_HOWPUBLISHED))
3532     {
3533         pName = "Howpublished";
3534     }
3535     else if (IsXMLToken(sName, XML_INSTITUTION))
3536     {
3537         pName = "Institution";
3538     }
3539     else if (IsXMLToken(sName, XML_JOURNAL))
3540     {
3541         pName = "Journal";
3542     }
3543     else if (IsXMLToken(sName, XML_MONTH))
3544     {
3545         pName = "Month";
3546     }
3547     else if (IsXMLToken(sName, XML_NOTE))
3548     {
3549         pName = "Note";
3550     }
3551     else if (IsXMLToken(sName, XML_NUMBER))
3552     {
3553         pName = "Number";
3554     }
3555     else if (IsXMLToken(sName, XML_ORGANIZATIONS))
3556     {
3557         pName = "Organizations";
3558     }
3559     else if (IsXMLToken(sName, XML_PAGES))
3560     {
3561         pName = "Pages";
3562     }
3563     else if (IsXMLToken(sName, XML_PUBLISHER))
3564     {
3565         pName = "Publisher";
3566     }
3567     else if (IsXMLToken(sName, XML_SCHOOL))
3568     {
3569         pName = "School";
3570     }
3571     else if (IsXMLToken(sName, XML_SERIES))
3572     {
3573         pName = "Series";
3574     }
3575     else if (IsXMLToken(sName, XML_TITLE))
3576     {
3577         pName = "Title";
3578     }
3579     else if (IsXMLToken(sName, XML_REPORT_TYPE))
3580     {
3581         pName = "Report_Type";
3582     }
3583     else if (IsXMLToken(sName, XML_VOLUME))
3584     {
3585         pName = "Volume";
3586     }
3587     else if (IsXMLToken(sName, XML_YEAR))
3588     {
3589         pName = "Year";
3590     }
3591     else if (IsXMLToken(sName, XML_URL))
3592     {
3593         pName = "URL";
3594     }
3595     else if (IsXMLToken(sName, XML_CUSTOM1))
3596     {
3597         pName = "Custom1";
3598     }
3599     else if (IsXMLToken(sName, XML_CUSTOM2))
3600     {
3601         pName = "Custom2";
3602     }
3603     else if (IsXMLToken(sName, XML_CUSTOM3))
3604     {
3605         pName = "Custom3";
3606     }
3607     else if (IsXMLToken(sName, XML_CUSTOM4))
3608     {
3609         pName = "Custom4";
3610     }
3611     else if (IsXMLToken(sName, XML_CUSTOM5))
3612     {
3613         pName = "Custom5";
3614     }
3615     else if (IsXMLToken(sName, XML_ISBN))
3616     {
3617         pName = "ISBN";
3618     }
3619     else
3620     {
3621         DBG_ERROR("Unknown bibliography info data");
3622         pName = NULL;
3623     }
3624 
3625     return pName;
3626 }
3627 
3628 
3629 //
3630 // Annotation Field
3631 //
3632 
3633 TYPEINIT1(XMLAnnotationImportContext, XMLTextFieldImportContext);
3634 
3635 XMLAnnotationImportContext::XMLAnnotationImportContext(
3636     SvXMLImport& rImport,
3637     XMLTextImportHelper& rHlp,
3638     sal_uInt16 nPrfx,
3639     const OUString& sLocalName) :
3640         XMLTextFieldImportContext(rImport, rHlp, sAPI_annotation,
3641                                   nPrfx, sLocalName),
3642         sPropertyAuthor(RTL_CONSTASCII_USTRINGPARAM(sAPI_author)),
3643         sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content)),
3644         // why is there no UNO_NAME_DATE_TIME, but only UNO_NAME_DATE_TIME_VALUE?
3645         sPropertyDate(RTL_CONSTASCII_USTRINGPARAM(sAPI_date_time_value)),
3646         sPropertyTextRange(RTL_CONSTASCII_USTRINGPARAM(sAPI_TextRange))
3647 {
3648     bValid = sal_True;
3649 
3650     // remember old list item and block (#91964#) and reset them
3651     // for the text frame
3652     // do this in the constructor, not in CreateChildContext (#i93392#)
3653     GetImport().GetTextImport()->PushListContext();
3654 }
3655 
3656 void XMLAnnotationImportContext::ProcessAttribute(
3657     sal_uInt16,
3658     const OUString& )
3659 {
3660     // ignore
3661 }
3662 
3663 SvXMLImportContext* XMLAnnotationImportContext::CreateChildContext(
3664     sal_uInt16 nPrefix,
3665     const OUString& rLocalName,
3666     const Reference<XAttributeList >& xAttrList )
3667 {
3668     SvXMLImportContext *pContext = 0;
3669     if( XML_NAMESPACE_DC == nPrefix )
3670     {
3671         if( IsXMLToken( rLocalName, XML_CREATOR ) )
3672             pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,
3673                                             rLocalName, aAuthorBuffer);
3674         else if( IsXMLToken( rLocalName, XML_DATE ) )
3675             pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,
3676                                             rLocalName, aDateBuffer);
3677     }
3678 
3679     if( !pContext )
3680     {
3681         try
3682         {
3683             if ( !mxField.is() )
3684                 CreateField( mxField, sServicePrefix + GetServiceName() );
3685             Any aAny = mxField->getPropertyValue( sPropertyTextRange );
3686             Reference< XText > xText;
3687             aAny >>= xText;
3688             if( xText.is() )
3689             {
3690                 UniReference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport();
3691                 if( !mxCursor.is() )
3692                 {
3693                     mxOldCursor = xTxtImport->GetCursor();
3694                     mxCursor = xText->createTextCursor();
3695                 }
3696 
3697                 if( mxCursor.is() )
3698                 {
3699                     xTxtImport->SetCursor( mxCursor );
3700                     pContext = xTxtImport->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
3701                 }
3702             }
3703         }
3704         catch ( Exception& )
3705         {}
3706 
3707         if( !pContext )
3708             pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,  rLocalName, aTextBuffer);
3709     }
3710 
3711     return pContext;
3712 }
3713 
3714 void XMLAnnotationImportContext::EndElement()
3715 {
3716     DBG_ASSERT(GetServiceName().getLength()>0, "no service name for element!");
3717     if( mxCursor.is() )
3718     {
3719         // delete addition newline
3720         const OUString aEmpty;
3721         mxCursor->gotoEnd( sal_False );
3722         mxCursor->goLeft( 1, sal_True );
3723         mxCursor->setString( aEmpty );
3724 
3725         // reset cursor
3726         GetImport().GetTextImport()->ResetCursor();
3727     }
3728 
3729     if( mxOldCursor.is() )
3730         GetImport().GetTextImport()->SetCursor( mxOldCursor );
3731 
3732     // reinstall old list item #91964#
3733     GetImport().GetTextImport()->PopListContext();
3734 
3735     if ( bValid )
3736     {
3737         if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) )
3738         {
3739             // set field properties
3740             PrepareField( mxField );
3741 
3742             // attach field to document
3743             Reference < XTextContent > xTextContent( mxField, UNO_QUERY );
3744 
3745             // workaround for #80606#
3746             try
3747             {
3748                 GetImportHelper().InsertTextContent( xTextContent );
3749             }
3750             catch (lang::IllegalArgumentException)
3751             {
3752                 // ignore
3753             }
3754         }
3755     }
3756     else
3757         GetImportHelper().InsertString(GetContent());
3758 }
3759 
3760 void XMLAnnotationImportContext::PrepareField(
3761     const Reference<XPropertySet> & xPropertySet)
3762 {
3763     // import (possibly empty) author
3764     OUString sAuthor( aAuthorBuffer.makeStringAndClear() );
3765     xPropertySet->setPropertyValue(sPropertyAuthor, makeAny(sAuthor));
3766 
3767     DateTime aDateTime;
3768     if (SvXMLUnitConverter::convertDateTime(aDateTime,
3769                                             aDateBuffer.makeStringAndClear()))
3770     {
3771         /*
3772         Date aDate;
3773         aDate.Year = aDateTime.Year;
3774         aDate.Month = aDateTime.Month;
3775         aDate.Day = aDateTime.Day;
3776         xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDate));
3777         */
3778         xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDateTime));
3779     }
3780 
3781     OUString sBuffer = aTextBuffer.makeStringAndClear();
3782     if ( sBuffer.getLength() )
3783     {
3784         // delete last paragraph mark (if necessary)
3785         if (sal_Char(0x0a) == sBuffer.getStr()[sBuffer.getLength()-1])
3786             sBuffer = sBuffer.copy(0, sBuffer.getLength()-1);
3787         xPropertySet->setPropertyValue(sPropertyContent, makeAny(sBuffer));
3788     }
3789 }
3790 
3791 
3792 
3793 //
3794 // script field
3795 //
3796 
3797 TYPEINIT1(XMLScriptImportContext, XMLTextFieldImportContext);
3798 
3799 XMLScriptImportContext::XMLScriptImportContext(
3800     SvXMLImport& rImport,
3801     XMLTextImportHelper& rHlp,
3802     sal_uInt16 nPrfx,
3803     const OUString& sLocalName)
3804 :   XMLTextFieldImportContext(rImport, rHlp, sAPI_script, nPrfx, sLocalName)
3805 ,   sPropertyScriptType(RTL_CONSTASCII_USTRINGPARAM(sAPI_script_type))
3806 ,   sPropertyURLContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_url_content))
3807 ,   sPropertyContent(RTL_CONSTASCII_USTRINGPARAM(sAPI_content))
3808 ,   bContentOK(sal_False)
3809 ,   bScriptTypeOK(sal_False)
3810 ,   bUrlContent(sal_False)
3811 {
3812 }
3813 
3814 void XMLScriptImportContext::ProcessAttribute(
3815     sal_uInt16 nAttrToken,
3816     const OUString& sAttrValue )
3817 {
3818     switch (nAttrToken)
3819     {
3820         case XML_TOK_TEXTFIELD_HREF:
3821             sContent = GetImport().GetAbsoluteReference( sAttrValue );
3822             bContentOK = sal_True;
3823             break;
3824 
3825         case XML_TOK_TEXTFIELD_LANGUAGE:
3826             sScriptType = sAttrValue;
3827             bScriptTypeOK = sal_True;
3828             break;
3829 
3830         default:
3831             // ignore
3832             break;
3833     }
3834 
3835     // always valid (even without ScriptType; cf- #96531#)
3836     bValid = sal_True;
3837 }
3838 
3839 void XMLScriptImportContext::PrepareField(
3840     const Reference<XPropertySet> & xPropertySet)
3841 {
3842     Any aAny;
3843 
3844     // if href attribute was present, we use it. Else we use element content
3845     if (! bContentOK)
3846     {
3847         sContent = GetContent();
3848     }
3849     aAny <<= sContent;
3850     xPropertySet->setPropertyValue(sPropertyContent, aAny);
3851 
3852     // URL or script text? We use URL if we have an href-attribute
3853     aAny.setValue(&bContentOK, ::getBooleanCppuType());
3854     xPropertySet->setPropertyValue(sPropertyURLContent, aAny);
3855 
3856     aAny <<= sScriptType;
3857     xPropertySet->setPropertyValue(sPropertyScriptType, aAny);
3858 }
3859 
3860 //
3861 // measure field
3862 //
3863 
3864 TYPEINIT1(XMLMeasureFieldImportContext, XMLTextFieldImportContext);
3865 
3866 XMLMeasureFieldImportContext::XMLMeasureFieldImportContext(
3867     SvXMLImport& rImport,
3868     XMLTextImportHelper& rHlp,
3869     sal_uInt16 nPrfx,
3870     const OUString& sLocalName) :
3871         XMLTextFieldImportContext(rImport, rHlp, sAPI_measure,
3872                                   nPrfx, sLocalName),
3873         mnKind( 0 )
3874 {
3875 }
3876 
3877 void XMLMeasureFieldImportContext::ProcessAttribute(
3878     sal_uInt16 nAttrToken,
3879     const OUString& sAttrValue )
3880 {
3881     switch (nAttrToken)
3882     {
3883         case XML_TOK_TEXTFIELD_MEASURE_KIND:
3884             if( IsXMLToken( sAttrValue, XML_VALUE ) )
3885             {
3886                 mnKind = 0; bValid = sal_True;
3887             }
3888             else if( IsXMLToken( sAttrValue, XML_UNIT ) )
3889             {
3890                 mnKind = 1; bValid = sal_True;
3891             }
3892             else if( IsXMLToken( sAttrValue, XML_GAP ) )
3893             {
3894                 mnKind = 2; bValid = sal_True;
3895             }
3896             break;
3897     }
3898 }
3899 
3900 void XMLMeasureFieldImportContext::PrepareField(
3901     const Reference<XPropertySet> & xPropertySet)
3902 {
3903     Any aAny;
3904     aAny <<= mnKind;
3905     xPropertySet->setPropertyValue(OUString::createFromAscii("Kind"), aAny);
3906 }
3907 
3908 
3909 
3910 //
3911 // dropdown field
3912 //
3913 
3914 
3915 TYPEINIT1( XMLDropDownFieldImportContext, XMLTextFieldImportContext );
3916 
3917 XMLDropDownFieldImportContext::XMLDropDownFieldImportContext(
3918         SvXMLImport& rImport,
3919         XMLTextImportHelper& rHlp,
3920         sal_uInt16 nPrfx,
3921         const ::rtl::OUString& sLocalName) :
3922     XMLTextFieldImportContext( rImport, rHlp, sAPI_drop_down,
3923                                nPrfx, sLocalName ),
3924     aLabels(),
3925     sName(),
3926     nSelected( -1 ),
3927     bNameOK( false ),
3928     bHelpOK(false),
3929     bHintOK(false),
3930     sPropertyItems( RTL_CONSTASCII_USTRINGPARAM( "Items" ) ),
3931     sPropertySelectedItem( RTL_CONSTASCII_USTRINGPARAM( "SelectedItem" ) ),
3932     sPropertyName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ),
3933     sPropertyHelp( RTL_CONSTASCII_USTRINGPARAM( "Help" ) ),
3934     sPropertyToolTip( RTL_CONSTASCII_USTRINGPARAM( "Tooltip" ) )
3935 {
3936     bValid = sal_True;
3937 }
3938 
3939 bool lcl_ProcessLabel( const SvXMLImport& rImport,
3940                        const Reference<XAttributeList>& xAttrList,
3941                        OUString& rLabel,
3942                        bool& rIsSelected )
3943 {
3944     bool bValid = false;
3945     sal_Int16 nLength = xAttrList->getLength();
3946     for( sal_Int16 n = 0; n < nLength; n++ )
3947     {
3948         OUString sLocalName;
3949         sal_uInt16 nPrefix = rImport.GetNamespaceMap().
3950             GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName );
3951         OUString sValue = xAttrList->getValueByIndex(n);
3952 
3953         if( nPrefix == XML_NAMESPACE_TEXT )
3954         {
3955             if( IsXMLToken( sLocalName, XML_VALUE ) )
3956             {
3957                 rLabel = sValue;
3958                 bValid = true;
3959             }
3960             else if( IsXMLToken( sLocalName, XML_CURRENT_SELECTED ) )
3961             {
3962                 sal_Bool bTmp;
3963                 if( SvXMLUnitConverter::convertBool( bTmp, sValue ) )
3964                     rIsSelected = bTmp;
3965             }
3966         }
3967     }
3968     return bValid;
3969 }
3970 
3971 SvXMLImportContext* XMLDropDownFieldImportContext::CreateChildContext(
3972     sal_uInt16 nPrefix,
3973     const OUString& rLocalName,
3974     const Reference<XAttributeList>& xAttrList )
3975 {
3976     if( nPrefix == XML_NAMESPACE_TEXT  &&
3977         IsXMLToken( rLocalName, XML_LABEL ) )
3978     {
3979         OUString sLabel;
3980         bool bIsSelected = sal_False;
3981         if( lcl_ProcessLabel( GetImport(), xAttrList, sLabel, bIsSelected ) )
3982         {
3983             if( bIsSelected )
3984                 nSelected = static_cast<sal_Int32>( aLabels.size() );
3985             aLabels.push_back( sLabel );
3986         }
3987     }
3988     return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
3989 }
3990 
3991 void XMLDropDownFieldImportContext::ProcessAttribute(
3992     sal_uInt16 nAttrToken,
3993     const ::rtl::OUString& sAttrValue )
3994 {
3995     if( nAttrToken == XML_TOK_TEXTFIELD_NAME )
3996     {
3997         sName = sAttrValue;
3998         bNameOK = true;
3999     }
4000     else if (nAttrToken == XML_TOK_TEXTFIELD_HELP)
4001     {
4002         sHelp = sAttrValue;
4003         bHelpOK = true;
4004     }
4005     else if (nAttrToken == XML_TOK_TEXTFIELD_HINT)
4006     {
4007         sHint = sAttrValue;
4008         bHintOK = true;
4009     }
4010 }
4011 
4012 void XMLDropDownFieldImportContext::PrepareField(
4013     const Reference<XPropertySet>& xPropertySet)
4014 {
4015     // create sequence
4016     sal_Int32 nLength = static_cast<sal_Int32>( aLabels.size() );
4017     Sequence<OUString> aSequence( nLength );
4018     OUString* pSequence = aSequence.getArray();
4019     for( sal_Int32 n = 0; n < nLength; n++ )
4020         pSequence[n] = aLabels[n];
4021 
4022     // now set values:
4023     Any aAny;
4024 
4025     aAny <<= aSequence;
4026     xPropertySet->setPropertyValue( sPropertyItems, aAny );
4027 
4028     if( nSelected >= 0  &&  nSelected < nLength )
4029     {
4030         aAny <<= pSequence[nSelected];
4031         xPropertySet->setPropertyValue( sPropertySelectedItem, aAny );
4032     }
4033 
4034     // set name
4035     if( bNameOK )
4036     {
4037         aAny <<= sName;
4038         xPropertySet->setPropertyValue( sPropertyName, aAny );
4039     }
4040     // set help
4041     if( bHelpOK )
4042     {
4043         aAny <<= sHelp;
4044         xPropertySet->setPropertyValue( sPropertyHelp, aAny );
4045     }
4046     // set hint
4047     if( bHintOK )
4048     {
4049         aAny <<= sHint;
4050         xPropertySet->setPropertyValue( sPropertyToolTip, aAny );
4051     }
4052 
4053 }
4054 
4055 /** import header fields (<draw:header>) */
4056 TYPEINIT1( XMLHeaderFieldImportContext, XMLTextFieldImportContext );
4057 
4058 XMLHeaderFieldImportContext::XMLHeaderFieldImportContext(
4059         SvXMLImport& rImport,                   /// XML Import
4060         XMLTextImportHelper& rHlp,              /// Text import helper
4061         sal_uInt16 nPrfx,                       /// namespace prefix
4062         const ::rtl::OUString& sLocalName)      /// element name w/o prefix
4063 : XMLTextFieldImportContext(rImport, rHlp, sAPI_header, nPrfx, sLocalName )
4064 {
4065     sServicePrefix = OUString::createFromAscii( sAPI_presentation_prefix );
4066     bValid = sal_True;
4067 }
4068 
4069 /// process attribute values
4070 void XMLHeaderFieldImportContext::ProcessAttribute( sal_uInt16, const ::rtl::OUString& )
4071 {
4072 }
4073 
4074 /// prepare XTextField for insertion into document
4075 void XMLHeaderFieldImportContext::PrepareField(const Reference<XPropertySet> &)
4076 {
4077 }
4078 
4079 /** import footer fields (<draw:footer>) */
4080 TYPEINIT1( XMLFooterFieldImportContext, XMLTextFieldImportContext );
4081 
4082 XMLFooterFieldImportContext::XMLFooterFieldImportContext(
4083         SvXMLImport& rImport,                   /// XML Import
4084         XMLTextImportHelper& rHlp,              /// Text import helper
4085         sal_uInt16 nPrfx,                       /// namespace prefix
4086         const ::rtl::OUString& sLocalName)      /// element name w/o prefix
4087 : XMLTextFieldImportContext(rImport, rHlp, sAPI_footer, nPrfx, sLocalName )
4088 {
4089     sServicePrefix = OUString::createFromAscii( sAPI_presentation_prefix );
4090     bValid = sal_True;
4091 }
4092 
4093 /// process attribute values
4094 void XMLFooterFieldImportContext::ProcessAttribute( sal_uInt16, const ::rtl::OUString& )
4095 {
4096 }
4097 
4098 /// prepare XTextField for insertion into document
4099 void XMLFooterFieldImportContext::PrepareField(const Reference<XPropertySet> &)
4100 {
4101 }
4102 
4103 
4104 /** import footer fields (<draw:date-and-time>) */
4105 TYPEINIT1( XMLDateTimeFieldImportContext, XMLTextFieldImportContext );
4106 
4107 XMLDateTimeFieldImportContext::XMLDateTimeFieldImportContext(
4108         SvXMLImport& rImport,                   /// XML Import
4109         XMLTextImportHelper& rHlp,              /// Text import helper
4110         sal_uInt16 nPrfx,                       /// namespace prefix
4111         const ::rtl::OUString& sLocalName)      /// element name w/o prefix
4112 : XMLTextFieldImportContext(rImport, rHlp, sAPI_datetime, nPrfx, sLocalName )
4113 {
4114     sServicePrefix = OUString::createFromAscii( sAPI_presentation_prefix );
4115     bValid = sal_True;
4116 }
4117 
4118 /// process attribute values
4119 void XMLDateTimeFieldImportContext::ProcessAttribute( sal_uInt16,
4120                                    const ::rtl::OUString& )
4121 {
4122 }
4123 
4124 /// prepare XTextField for insertion into document
4125 void XMLDateTimeFieldImportContext::PrepareField(
4126         const ::com::sun::star::uno::Reference<
4127         ::com::sun::star::beans::XPropertySet> &)
4128 {
4129 }
4130