bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / text / txtfldi.cxx
blobc64ced6f7a2aeb67dc7b43a5807ce8118d9fcade
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 /** @#file
23 * Import of all text fields except those from txtvfldi.cxx
24 * (variable related text fields and database display fields)
26 #include "txtfldi.hxx"
27 #include "txtvfldi.hxx"
28 #include <xmloff/xmlimp.hxx>
29 #include <xmloff/xmlnumi.hxx>
30 #include <xmloff/txtimp.hxx>
31 #include <xmloff/xmlnmspe.hxx>
32 #include <xmloff/nmspmap.hxx>
33 #include <xmloff/xmltoken.hxx>
34 #include <xmloff/xmluconv.hxx>
35 #include <xmloff/xmlement.hxx>
36 #include "XMLStringBufferImportContext.hxx"
37 #include <xmloff/XMLEventsImportContext.hxx>
38 #include <com/sun/star/xml/sax/XAttributeList.hpp>
39 #include <com/sun/star/text/UserDataPart.hpp>
40 #include <com/sun/star/style/NumberingType.hpp>
41 #include <com/sun/star/text/PlaceholderType.hpp>
42 #include <com/sun/star/text/ReferenceFieldPart.hpp>
43 #include <com/sun/star/text/ReferenceFieldSource.hpp>
44 #include <com/sun/star/text/XTextField.hpp>
45 #include <com/sun/star/text/XTextContent.hpp>
46 #include <com/sun/star/beans/XPropertySet.hpp>
47 #include <com/sun/star/beans/XPropertySetInfo.hpp>
48 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
49 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
50 #include <com/sun/star/text/XDependentTextField.hpp>
51 #include <com/sun/star/text/SetVariableType.hpp>
52 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
53 #include <com/sun/star/text/ChapterFormat.hpp>
54 #include <com/sun/star/text/TemplateDisplayFormat.hpp>
55 #include <com/sun/star/beans/PropertyValue.hpp>
56 #include <com/sun/star/text/BibliographyDataType.hpp>
57 #include <com/sun/star/text/BibliographyDataField.hpp>
58 #include <com/sun/star/util/XUpdatable.hpp>
59 #include <com/sun/star/sdb/CommandType.hpp>
61 #include <sax/tools/converter.hxx>
63 #include <rtl/ustring.hxx>
64 #include <rtl/ustrbuf.hxx>
65 #include <rtl/math.hxx>
66 #include <tools/debug.hxx>
67 #include <osl/diagnose.h>
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::uno;
73 using namespace ::com::sun::star::text;
74 using namespace ::com::sun::star::lang;
75 using namespace ::com::sun::star::beans;
76 using namespace ::com::sun::star::document;
77 using namespace ::com::sun::star::util;
78 using namespace ::com::sun::star::xml::sax;
79 using namespace ::xmloff::token;
83 // SO API string constants
86 // service prefix and service anems
87 const sal_Char sAPI_textfield_prefix[] = "com.sun.star.text.TextField.";
88 const sal_Char sAPI_fieldmaster_prefix[] = "com.sun.star.text.FieldMaster.";
89 const sal_Char sAPI_presentation_prefix[] = "com.sun.star.presentation.TextField.";
91 const sal_Char sAPI_extended_user[] = "ExtendedUser";
92 const sal_Char sAPI_user_data_type[] = "UserDataType";
93 const sal_Char sAPI_jump_edit[] = "JumpEdit";
94 const sal_Char sAPI_date_time[] = "DateTime";
95 const sal_Char sAPI_page_number[] = "PageNumber";
96 const sal_Char sAPI_database_next[] = "DatabaseNextSet";
97 const sal_Char sAPI_database_select[] = "DatabaseNumberOfSet";
98 const sal_Char sAPI_database_number[] = "DatabaseSetNumber";
99 const sal_Char sAPI_database_name[] = "DatabaseName";
100 const sal_Char sAPI_docinfo_change_author[] = "DocInfo.ChangeAuthor";
101 const sal_Char sAPI_docinfo_change_date_time[] = "DocInfo.ChangeDateTime";
102 const sal_Char sAPI_docinfo_edit_time[] = "DocInfo.EditTime";
103 const sal_Char sAPI_docinfo_description[] = "DocInfo.Description";
104 const sal_Char sAPI_docinfo_create_author[] = "DocInfo.CreateAuthor";
105 const sal_Char sAPI_docinfo_create_date_time[] = "DocInfo.CreateDateTime";
106 const sal_Char sAPI_docinfo_custom[] = "DocInfo.Custom";
107 const sal_Char sAPI_docinfo_print_author[] = "DocInfo.PrintAuthor";
108 const sal_Char sAPI_docinfo_print_date_time[] = "DocInfo.PrintDateTime";
109 const sal_Char sAPI_docinfo_keywords[] = "DocInfo.KeyWords";
110 const sal_Char sAPI_docinfo_subject[] = "DocInfo.Subject";
111 const sal_Char sAPI_docinfo_title[] = "DocInfo.Title";
112 const sal_Char sAPI_docinfo_revision[] = "DocInfo.Revision";
113 const sal_Char sAPI_hidden_paragraph[] = "HiddenParagraph";
114 const sal_Char sAPI_hidden_text[] = "HiddenText";
115 const sal_Char sAPI_conditional_text[] = "ConditionalText";
116 const sal_Char sAPI_file_name[] = "FileName";
117 const sal_Char sAPI_chapter[] = "Chapter";
118 const sal_Char sAPI_template_name[] = "TemplateName";
119 const sal_Char sAPI_page_count[] = "PageCount";
120 const sal_Char sAPI_paragraph_count[] = "ParagraphCount";
121 const sal_Char sAPI_word_count[] = "WordCount";
122 const sal_Char sAPI_character_count[] = "CharacterCount";
123 const sal_Char sAPI_table_count[] = "TableCount";
124 const sal_Char sAPI_graphic_object_count[] = "GraphicObjectCount";
125 const sal_Char sAPI_embedded_object_count[] = "EmbeddedObjectCount";
126 const sal_Char sAPI_reference_page_set[] = "ReferencePageSet";
127 const sal_Char sAPI_reference_page_get[] = "ReferencePageGet";
128 const sal_Char sAPI_macro[] = "Macro";
129 const sal_Char sAPI_dde[] = "DDE";
130 const sal_Char sAPI_get_reference[] = "GetReference";
131 const sal_Char sAPI_sheet_name[] = "SheetName";
132 const sal_Char sAPI_pagename[] = "PageName";
133 const sal_Char sAPI_url[] = "URL";
134 const sal_Char sAPI_bibliography[] = "Bibliography";
135 const sal_Char sAPI_annotation[] = "Annotation";
136 const sal_Char sAPI_script[] = "Script";
137 const sal_Char sAPI_measure[] = "Measure";
138 const sal_Char sAPI_drop_down[] = "DropDown";
139 const sal_Char sAPI_header[] = "Header";
140 const sal_Char sAPI_footer[] = "Footer";
141 const sal_Char sAPI_datetime[] = "DateTime";
143 // property names
144 const sal_Char sAPI_is_fixed[] = "IsFixed";
145 const sal_Char sAPI_content[] = "Content";
146 const sal_Char sAPI_author[] = "Author";
147 const sal_Char sAPI_initials[] = "Initials";
148 const sal_Char sAPI_full_name[] = "FullName";
149 const sal_Char sAPI_place_holder_type[] = "PlaceHolderType";
150 const sal_Char sAPI_place_holder[] = "PlaceHolder";
151 const sal_Char sAPI_hint[] = "Hint";
152 const sal_Char sAPI_name[] = "Name";
153 const sal_Char sAPI_sub_type[] = "SubType";
154 const sal_Char sAPI_date_time_value[] = "DateTimeValue";
155 const sal_Char sAPI_number_format[] = "NumberFormat";
156 const sal_Char sAPI_user_text[] = "UserText";
157 const sal_Char sAPI_numbering_type[] = "NumberingType";
158 const sal_Char sAPI_offset[] = "Offset";
159 const sal_Char sAPI_data_base_name[] = "DataBaseName";
160 const sal_Char sAPI_data_base_u_r_l[] = "DataBaseURL";
161 const sal_Char sAPI_data_table_name[] = "DataTableName";
162 const sal_Char sAPI_condition[] = "Condition";
163 const sal_Char sAPI_set_number[] = "SetNumber";
164 const sal_Char sAPI_true_content[] = "TrueContent";
165 const sal_Char sAPI_false_content[] = "FalseContent";
166 const sal_Char sAPI_revision[] = "Revision";
167 const sal_Char sAPI_file_format[] = "FileFormat";
168 const sal_Char sAPI_chapter_format[] = "ChapterFormat";
169 const sal_Char sAPI_level[] = "Level";
170 const sal_Char sAPI_is_date[] = "IsDate";
171 const sal_Char sAPI_adjust[] = "Adjust";
172 const sal_Char sAPI_on[] = "On";
173 const sal_Char sAPI_is_automatic_update[] = "IsAutomaticUpdate";
174 const sal_Char sAPI_source_name[] = "SourceName";
175 const sal_Char sAPI_current_presentation[] = "CurrentPresentation";
176 const sal_Char sAPI_reference_field_part[] = "ReferenceFieldPart";
177 const sal_Char sAPI_reference_field_source[] = "ReferenceFieldSource";
178 const sal_Char sAPI_dde_command_type[] = "DDECommandType";
179 const sal_Char sAPI_dde_command_file[] = "DDECommandFile";
180 const sal_Char sAPI_dde_command_element[] = "DDECommandElement";
181 // sAPI_url: also used as service name
182 const sal_Char sAPI_target_frame[] = "TargetFrame";
183 const sal_Char sAPI_representation[] = "Representation";
184 const sal_Char sAPI_url_content[] = "URLContent";
185 const sal_Char sAPI_script_type[] = "ScriptType";
186 const sal_Char sAPI_is_hidden[] = "IsHidden";
187 const sal_Char sAPI_is_condition_true[] = "IsConditionTrue";
188 const sal_Char sAPI_data_command_type[] = "DataCommandType";
189 const sal_Char sAPI_is_fixed_language[] = "IsFixedLanguage";
190 const sal_Char sAPI_is_visible[] = "IsVisible";
191 const sal_Char sAPI_TextRange[] = "TextRange";
193 const sal_Char sAPI_true[] = "TRUE";
196 TYPEINIT1( XMLTextFieldImportContext, SvXMLImportContext);
198 XMLTextFieldImportContext::XMLTextFieldImportContext(
199 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
200 const sal_Char* pService,
201 sal_uInt16 nPrefix, const OUString& rElementName)
202 : SvXMLImportContext( rImport, nPrefix, rElementName )
203 , rTextImportHelper(rHlp)
204 , sServicePrefix(sAPI_textfield_prefix)
205 , bValid(false)
207 DBG_ASSERT(NULL != pService, "Need service name!");
208 sServiceName = OUString::createFromAscii(pService);
211 void XMLTextFieldImportContext::StartElement(
212 const Reference<XAttributeList> & xAttrList)
214 // process attributes
215 sal_Int16 nLength = xAttrList->getLength();
216 for(sal_Int16 i=0; i<nLength; i++) {
218 OUString sLocalName;
219 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
220 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
222 ProcessAttribute(rTextImportHelper.GetTextFieldAttrTokenMap().
223 Get(nPrefix, sLocalName),
224 xAttrList->getValueByIndex(i) );
228 XMLTextFieldImportContext::~XMLTextFieldImportContext() {
231 OUString XMLTextFieldImportContext::GetContent()
233 if (sContent.isEmpty())
235 sContent = sContentBuffer.makeStringAndClear();
238 return sContent;
241 void XMLTextFieldImportContext::EndElement()
243 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
244 if (bValid)
247 // create field/Service
248 Reference<XPropertySet> xPropSet;
249 if (CreateField(xPropSet, sServicePrefix + GetServiceName()))
251 // set field properties
252 PrepareField(xPropSet);
254 // attach field to document
255 Reference<XTextContent> xTextContent(xPropSet, UNO_QUERY);
257 // workaround for #80606#
260 rTextImportHelper.InsertTextContent(xTextContent);
262 catch (const lang::IllegalArgumentException&)
264 // ignore
266 return;
270 // in case of error: write element content
271 rTextImportHelper.InsertString(GetContent());
274 void XMLTextFieldImportContext::Characters(const OUString& rContent)
276 sContentBuffer.append(rContent);
279 bool XMLTextFieldImportContext::CreateField(
280 Reference<XPropertySet> & xField,
281 const OUString& rServiceName)
283 // instantiate new XTextField:
284 // ask import for model, model is factory, ask factory to create service
286 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),UNO_QUERY);
287 if( xFactory.is() )
289 Reference<XInterface> xIfc = xFactory->createInstance(rServiceName);
290 if( xIfc.is() )
292 Reference<XPropertySet> xTmp( xIfc, UNO_QUERY );
294 xField = xTmp;
295 } else {
296 return false; // can't create instance
298 } else {
299 return false; // can't get MultiServiceFactory
302 return true;
305 /// create the appropriate field context from
306 XMLTextFieldImportContext*
307 XMLTextFieldImportContext::CreateTextFieldImportContext(
308 SvXMLImport& rImport,
309 XMLTextImportHelper& rHlp,
310 sal_uInt16 nPrefix,
311 const OUString& rName,
312 sal_uInt16 nToken)
314 XMLTextFieldImportContext* pContext = NULL;
316 switch (nToken)
318 case XML_TOK_TEXT_SENDER_FIRSTNAME:
319 case XML_TOK_TEXT_SENDER_LASTNAME:
320 case XML_TOK_TEXT_SENDER_INITIALS:
321 case XML_TOK_TEXT_SENDER_TITLE:
322 case XML_TOK_TEXT_SENDER_POSITION:
323 case XML_TOK_TEXT_SENDER_EMAIL:
324 case XML_TOK_TEXT_SENDER_PHONE_PRIVATE:
325 case XML_TOK_TEXT_SENDER_FAX:
326 case XML_TOK_TEXT_SENDER_COMPANY:
327 case XML_TOK_TEXT_SENDER_PHONE_WORK:
328 case XML_TOK_TEXT_SENDER_STREET:
329 case XML_TOK_TEXT_SENDER_CITY:
330 case XML_TOK_TEXT_SENDER_POSTAL_CODE:
331 case XML_TOK_TEXT_SENDER_COUNTRY:
332 case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE:
333 pContext =
334 new XMLSenderFieldImportContext( rImport, rHlp,
335 nPrefix, rName, nToken );
336 break;
338 case XML_TOK_TEXT_AUTHOR_NAME:
339 case XML_TOK_TEXT_AUTHOR_INITIALS:
340 pContext =
341 new XMLAuthorFieldImportContext( rImport, rHlp,
342 nPrefix, rName, nToken );
343 break;
345 case XML_TOK_TEXT_PLACEHOLDER:
346 pContext =
347 new XMLPlaceholderFieldImportContext( rImport, rHlp,
348 nPrefix, rName);
349 break;
350 case XML_TOK_TEXT_SEQUENCE:
351 pContext =
352 new XMLSequenceFieldImportContext( rImport, rHlp,
353 nPrefix, rName );
354 break;
355 case XML_TOK_TEXT_TEXT_INPUT:
356 pContext =
357 new XMLTextInputFieldImportContext( rImport, rHlp,
358 nPrefix, rName );
359 break;
360 case XML_TOK_TEXT_EXPRESSION:
361 pContext =
362 new XMLExpressionFieldImportContext( rImport, rHlp,
363 nPrefix, rName );
364 break;
365 case XML_TOK_TEXT_VARIABLE_SET:
366 pContext =
367 new XMLVariableSetFieldImportContext( rImport, rHlp,
368 nPrefix, rName );
369 break;
370 case XML_TOK_TEXT_VARIABLE_INPUT:
371 pContext =
372 new XMLVariableInputFieldImportContext( rImport, rHlp,
373 nPrefix, rName );
374 break;
375 case XML_TOK_TEXT_VARIABLE_GET:
376 pContext =
377 new XMLVariableGetFieldImportContext( rImport, rHlp,
378 nPrefix, rName );
379 break;
380 case XML_TOK_TEXT_USER_FIELD_GET:
381 pContext = new XMLUserFieldImportContext( rImport, rHlp,
382 nPrefix, rName );
383 break;
384 case XML_TOK_TEXT_USER_FIELD_INPUT:
385 pContext = new XMLUserFieldInputImportContext( rImport, rHlp,
386 nPrefix, rName );
387 break;
388 case XML_TOK_TEXT_TIME:
389 pContext = new XMLTimeFieldImportContext( rImport, rHlp,
390 nPrefix, rName );
391 break;
392 case XML_TOK_TEXT_PAGE_CONTINUATION_STRING:
393 case XML_TOK_TEXT_PAGE_CONTINUATION:
394 pContext = new XMLPageContinuationImportContext( rImport, rHlp,
395 nPrefix, rName );
396 break;
398 case XML_TOK_TEXT_PAGE_NUMBER:
399 pContext = new XMLPageNumberImportContext( rImport, rHlp,
400 nPrefix, rName );
401 break;
403 case XML_TOK_TEXT_DATE:
404 pContext = new XMLDateFieldImportContext( rImport, rHlp,
405 nPrefix, rName );
406 break;
408 case XML_TOK_TEXT_DATABASE_NAME:
409 pContext = new XMLDatabaseNameImportContext( rImport, rHlp,
410 nPrefix, rName );
411 break;
412 case XML_TOK_TEXT_DATABASE_NEXT:
413 pContext = new XMLDatabaseNextImportContext( rImport, rHlp,
414 nPrefix, rName );
415 break;
416 case XML_TOK_TEXT_DATABASE_SELECT:
417 pContext = new XMLDatabaseSelectImportContext( rImport, rHlp,
418 nPrefix, rName );
419 break;
420 case XML_TOK_TEXT_DATABASE_ROW_NUMBER:
421 pContext = new XMLDatabaseNumberImportContext( rImport, rHlp,
422 nPrefix, rName );
423 break;
424 case XML_TOK_TEXT_DATABASE_DISPLAY:
425 pContext = new XMLDatabaseDisplayImportContext( rImport, rHlp,
426 nPrefix, rName );
427 break;
428 case XML_TOK_TEXT_CONDITIONAL_TEXT:
429 pContext = new XMLConditionalTextImportContext( rImport, rHlp,
430 nPrefix, rName );
431 break;
432 case XML_TOK_TEXT_HIDDEN_TEXT:
433 pContext = new XMLHiddenTextImportContext( rImport, rHlp,
434 nPrefix, rName );
435 break;
436 case XML_TOK_TEXT_HIDDEN_PARAGRAPH:
437 pContext = new XMLHiddenParagraphImportContext( rImport, rHlp,
438 nPrefix, rName );
439 break;
440 case XML_TOK_TEXT_DOCUMENT_DESCRIPTION:
441 case XML_TOK_TEXT_DOCUMENT_TITLE:
442 case XML_TOK_TEXT_DOCUMENT_SUBJECT:
443 case XML_TOK_TEXT_DOCUMENT_KEYWORDS:
444 pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
445 nPrefix, rName,
446 nToken, true,
447 false );
448 break;
449 case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR:
450 case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR:
451 case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR:
452 pContext = new XMLSimpleDocInfoImportContext( rImport, rHlp,
453 nPrefix, rName,
454 nToken, false,
455 true );
456 break;
458 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
459 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
460 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
461 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
462 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
463 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
464 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
465 pContext = new XMLDateTimeDocInfoImportContext( rImport, rHlp,
466 nPrefix, rName,
467 nToken );
468 break;
470 case XML_TOK_TEXT_DOCUMENT_REVISION:
471 pContext = new XMLRevisionDocInfoImportContext( rImport, rHlp,
472 nPrefix, rName,
473 nToken );
474 break;
476 case XML_TOK_TEXT_DOCUMENT_USER_DEFINED:
477 pContext = new XMLUserDocInfoImportContext( rImport, rHlp,
478 nPrefix, rName,
479 nToken );
480 break;
482 case XML_TOK_TEXT_FILENAME:
483 pContext = new XMLFileNameImportContext( rImport, rHlp,
484 nPrefix, rName );
485 break;
487 case XML_TOK_TEXT_CHAPTER:
488 pContext = new XMLChapterImportContext( rImport, rHlp,
489 nPrefix, rName );
490 break;
492 case XML_TOK_TEXT_TEMPLATENAME:
493 pContext = new XMLTemplateNameImportContext( rImport, rHlp,
494 nPrefix, rName );
495 break;
497 case XML_TOK_TEXT_WORD_COUNT:
498 case XML_TOK_TEXT_PARAGRAPH_COUNT:
499 case XML_TOK_TEXT_TABLE_COUNT:
500 case XML_TOK_TEXT_CHARACTER_COUNT:
501 case XML_TOK_TEXT_IMAGE_COUNT:
502 case XML_TOK_TEXT_OBJECT_COUNT:
503 case XML_TOK_TEXT_PAGE_COUNT:
504 pContext = new XMLCountFieldImportContext( rImport, rHlp,
505 nPrefix, rName, nToken);
506 break;
508 case XML_TOK_TEXT_GET_PAGE_VAR:
509 pContext = new XMLPageVarGetFieldImportContext( rImport, rHlp,
510 nPrefix, rName );
511 break;
513 case XML_TOK_TEXT_SET_PAGE_VAR:
514 pContext = new XMLPageVarSetFieldImportContext( rImport, rHlp,
515 nPrefix, rName );
516 break;
518 case XML_TOK_TEXT_MACRO:
519 pContext = new XMLMacroFieldImportContext( rImport, rHlp,
520 nPrefix, rName );
521 break;
523 case XML_TOK_TEXT_DDE:
524 pContext = new XMLDdeFieldImportContext( rImport, rHlp,
525 nPrefix, rName );
526 break;
528 case XML_TOK_TEXT_REFERENCE_REF:
529 case XML_TOK_TEXT_BOOKMARK_REF:
530 case XML_TOK_TEXT_NOTE_REF:
531 case XML_TOK_TEXT_SEQUENCE_REF:
532 pContext = new XMLReferenceFieldImportContext( rImport, rHlp,
533 nToken,
534 nPrefix, rName );
535 break;
537 case XML_TOK_TEXT_SHEET_NAME:
538 pContext = new XMLSheetNameImportContext( rImport, rHlp,
539 nPrefix, rName );
540 break;
542 case XML_TOK_TEXT_PAGE_NAME:
543 pContext = new XMLPageNameFieldImportContext( rImport, rHlp,
544 nPrefix, rName );
545 break;
547 case XML_TOK_TEXT_BIBLIOGRAPHY_MARK:
548 pContext = new XMLBibliographyFieldImportContext( rImport, rHlp,
549 nPrefix, rName );
550 break;
552 case XML_TOK_TEXT_ANNOTATION:
553 case XML_TOK_TEXT_ANNOTATION_END:
554 pContext = new XMLAnnotationImportContext( rImport, rHlp,
555 nToken,
556 nPrefix, rName);
557 break;
559 case XML_TOK_TEXT_SCRIPT:
560 pContext = new XMLScriptImportContext( rImport, rHlp,
561 nPrefix, rName);
562 break;
564 case XML_TOK_TEXT_MEASURE:
565 pContext = new XMLMeasureFieldImportContext( rImport, rHlp,
566 nPrefix, rName );
567 break;
569 case XML_TOK_TEXT_TABLE_FORMULA:
570 pContext = new XMLTableFormulaImportContext( rImport, rHlp,
571 nPrefix, rName );
572 break;
573 case XML_TOK_TEXT_DROP_DOWN:
574 pContext = new XMLDropDownFieldImportContext( rImport, rHlp,
575 nPrefix, rName );
576 break;
577 case XML_TOK_DRAW_HEADER:
578 pContext = new XMLHeaderFieldImportContext( rImport, rHlp,
579 nPrefix, rName );
580 break;
581 case XML_TOK_DRAW_FOOTER:
582 pContext = new XMLFooterFieldImportContext( rImport, rHlp,
583 nPrefix, rName );
584 break;
585 case XML_TOK_DRAW_DATE_TIME:
586 pContext = new XMLDateTimeFieldImportContext( rImport, rHlp,
587 nPrefix, rName );
588 break;
590 default:
591 // ignore! May not even be a textfield.
592 // (Reminder: This method is called inside default:-branch)
593 pContext = NULL;
594 break;
597 return pContext;
601 void XMLTextFieldImportContext::ForceUpdate(
602 const Reference<XPropertySet> & rPropertySet)
604 // force update
605 Reference<XUpdatable> xUpdate(rPropertySet, UNO_QUERY);
606 if (xUpdate.is())
608 xUpdate->update();
610 else
612 OSL_FAIL("Expected XUpdatable support!");
619 // XMLSenderFieldImportContext
622 TYPEINIT1( XMLSenderFieldImportContext, XMLTextFieldImportContext);
624 XMLSenderFieldImportContext::XMLSenderFieldImportContext(
625 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
626 sal_uInt16 nPrfx, const OUString& sLocalName,
627 sal_uInt16 nToken)
628 : XMLTextFieldImportContext(rImport, rHlp, sAPI_extended_user,nPrfx, sLocalName)
629 , nSubType(0)
630 , sPropertyFixed(sAPI_is_fixed)
631 , sPropertyFieldSubType(sAPI_user_data_type)
632 , sPropertyContent(sAPI_content)
633 , bFixed(true)
634 , nElementToken(nToken)
638 void XMLSenderFieldImportContext::StartElement(
639 const Reference<XAttributeList> & xAttrList)
641 bValid = true;
642 switch (nElementToken) {
643 case XML_TOK_TEXT_SENDER_FIRSTNAME:
644 nSubType = UserDataPart::FIRSTNAME;
645 break;
646 case XML_TOK_TEXT_SENDER_LASTNAME:
647 nSubType = UserDataPart::NAME;
648 break;
649 case XML_TOK_TEXT_SENDER_INITIALS:
650 nSubType = UserDataPart::SHORTCUT;
651 break;
652 case XML_TOK_TEXT_SENDER_TITLE:
653 nSubType = UserDataPart::TITLE;
654 break;
655 case XML_TOK_TEXT_SENDER_POSITION:
656 nSubType = UserDataPart::POSITION;
657 break;
658 case XML_TOK_TEXT_SENDER_EMAIL:
659 nSubType = UserDataPart::EMAIL;
660 break;
661 case XML_TOK_TEXT_SENDER_PHONE_PRIVATE:
662 nSubType = UserDataPart::PHONE_PRIVATE;
663 break;
664 case XML_TOK_TEXT_SENDER_FAX:
665 nSubType = UserDataPart::FAX;
666 break;
667 case XML_TOK_TEXT_SENDER_COMPANY:
668 nSubType = UserDataPart::COMPANY;
669 break;
670 case XML_TOK_TEXT_SENDER_PHONE_WORK:
671 nSubType = UserDataPart::PHONE_COMPANY;
672 break;
673 case XML_TOK_TEXT_SENDER_STREET:
674 nSubType = UserDataPart::STREET;
675 break;
676 case XML_TOK_TEXT_SENDER_CITY:
677 nSubType = UserDataPart::CITY;
678 break;
679 case XML_TOK_TEXT_SENDER_POSTAL_CODE:
680 nSubType = UserDataPart::ZIP;
681 break;
682 case XML_TOK_TEXT_SENDER_COUNTRY:
683 nSubType = UserDataPart::COUNTRY;
684 break;
685 case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE:
686 nSubType = UserDataPart::STATE;
687 break;
688 default:
689 bValid = false;
690 break;
693 // process Attributes
694 XMLTextFieldImportContext::StartElement(xAttrList);
697 void XMLSenderFieldImportContext::ProcessAttribute(
698 sal_uInt16 nAttrToken,
699 const OUString& sAttrValue)
701 if (XML_TOK_TEXTFIELD_FIXED == nAttrToken) {
703 // set bVal
704 bool bVal(false);
705 bool const bRet = ::sax::Converter::convertBool(bVal, sAttrValue);
707 // set bFixed if successful
708 if (bRet) {
709 bFixed = bVal;
714 void XMLSenderFieldImportContext::PrepareField(
715 const Reference<XPropertySet> & rPropSet)
717 // set members
718 Any aAny;
719 aAny <<= nSubType;
720 rPropSet->setPropertyValue(sPropertyFieldSubType, aAny);
722 // set fixed
723 aAny.setValue( &bFixed, cppu::UnoType<bool>::get() );
724 rPropSet->setPropertyValue(sPropertyFixed, aAny);
726 // set content if fixed
727 if (bFixed)
729 // in organizer or styles-only mode: force update
730 if (GetImport().GetTextImport()->IsOrganizerMode() ||
731 GetImport().GetTextImport()->IsStylesOnlyMode() )
733 ForceUpdate(rPropSet);
735 else
737 aAny <<= GetContent();
738 rPropSet->setPropertyValue(sPropertyContent, aAny);
746 // XMLAuthorFieldImportContext
749 TYPEINIT1( XMLAuthorFieldImportContext, XMLSenderFieldImportContext);
751 XMLAuthorFieldImportContext::XMLAuthorFieldImportContext(
752 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
753 sal_uInt16 nPrfx, const OUString& sLocalName,
754 sal_uInt16 nToken)
755 : XMLSenderFieldImportContext(rImport, rHlp, nPrfx, sLocalName, nToken)
756 , bAuthorFullName(true)
757 , sServiceAuthor(sAPI_author)
758 , sPropertyAuthorFullName(sAPI_full_name)
759 , sPropertyFixed(sAPI_is_fixed)
760 , sPropertyContent(sAPI_content)
762 // overwrite service name from XMLSenderFieldImportContext
763 SetServiceName(sServiceAuthor);
766 void XMLAuthorFieldImportContext::StartElement(
767 const Reference<XAttributeList> & xAttrList) {
769 bAuthorFullName = (XML_TOK_TEXT_AUTHOR_INITIALS != nElementToken);
770 bValid = true;
772 // process Attributes
773 XMLTextFieldImportContext::StartElement(xAttrList);
776 void XMLAuthorFieldImportContext::PrepareField(
777 const Reference<XPropertySet> & rPropSet)
779 // set members
780 Any aAny;
781 aAny.setValue( &bAuthorFullName, cppu::UnoType<bool>::get() );
782 rPropSet->setPropertyValue(sPropertyAuthorFullName, aAny);
784 aAny.setValue( &bFixed, cppu::UnoType<bool>::get() );
785 rPropSet->setPropertyValue(sPropertyFixed, aAny);
787 // set content if fixed
788 if (bFixed)
790 // organizer or styles-only mode: force update
791 if (GetImport().GetTextImport()->IsOrganizerMode() ||
792 GetImport().GetTextImport()->IsStylesOnlyMode() )
794 ForceUpdate(rPropSet);
796 else
798 aAny <<= GetContent();
799 rPropSet->setPropertyValue(sPropertyContent, aAny);
806 // page continuation string
809 TYPEINIT1( XMLPageContinuationImportContext, XMLTextFieldImportContext );
811 static SvXMLEnumMapEntry const lcl_aSelectPageAttrMap[] =
813 { XML_PREVIOUS, PageNumberType_PREV },
814 { XML_CURRENT, PageNumberType_CURRENT },
815 { XML_NEXT, PageNumberType_NEXT },
816 { XML_TOKEN_INVALID, 0 },
819 XMLPageContinuationImportContext::XMLPageContinuationImportContext(
820 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
821 const OUString& sLocalName)
822 : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number, nPrfx, sLocalName)
823 , sPropertySubType(sAPI_sub_type)
824 , sPropertyUserText(sAPI_user_text)
825 , sPropertyNumberingType(sAPI_numbering_type)
826 , eSelectPage(PageNumberType_CURRENT)
827 , sStringOK(false)
829 bValid = true;
832 void XMLPageContinuationImportContext::ProcessAttribute(
833 sal_uInt16 nAttrToken, const OUString& sAttrValue )
835 switch(nAttrToken)
837 case XML_TOK_TEXTFIELD_SELECT_PAGE:
839 sal_uInt16 nTmp;
840 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
841 lcl_aSelectPageAttrMap)
842 && (PageNumberType_CURRENT != nTmp) )
844 eSelectPage = (PageNumberType)nTmp;
846 break;
848 case XML_TOK_TEXTFIELD_STRING_VALUE:
849 sString = sAttrValue;
850 sStringOK = true;
851 break;
855 void XMLPageContinuationImportContext::PrepareField(
856 const Reference<XPropertySet> & xPropertySet)
858 Any aAny;
860 aAny <<= eSelectPage;
861 xPropertySet->setPropertyValue(sPropertySubType, aAny);
863 aAny <<= (sStringOK ? sString : GetContent());
864 xPropertySet->setPropertyValue(sPropertyUserText, aAny);
866 aAny <<= style::NumberingType::CHAR_SPECIAL;
867 xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
873 // page number field
876 TYPEINIT1( XMLPageNumberImportContext, XMLTextFieldImportContext );
878 XMLPageNumberImportContext::XMLPageNumberImportContext(
879 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
880 const OUString& sLocalName)
881 : XMLTextFieldImportContext(rImport, rHlp, sAPI_page_number, nPrfx, sLocalName)
882 , sPropertySubType(sAPI_sub_type)
883 , sPropertyNumberingType(sAPI_numbering_type)
884 , sPropertyOffset(sAPI_offset)
885 , sNumberSync(GetXMLToken(XML_FALSE))
886 , nPageAdjust(0)
887 , eSelectPage(PageNumberType_CURRENT)
888 , sNumberFormatOK(false)
890 bValid = true;
893 void XMLPageNumberImportContext::ProcessAttribute(
894 sal_uInt16 nAttrToken,
895 const OUString& sAttrValue )
897 switch (nAttrToken)
899 case XML_TOK_TEXTFIELD_NUM_FORMAT:
900 sNumberFormat = sAttrValue;
901 sNumberFormatOK = true;
902 break;
903 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
904 sNumberSync = sAttrValue;
905 break;
906 case XML_TOK_TEXTFIELD_SELECT_PAGE:
908 sal_uInt16 nTmp;
909 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
910 lcl_aSelectPageAttrMap))
912 eSelectPage = (PageNumberType)nTmp;
914 break;
916 case XML_TOK_TEXTFIELD_PAGE_ADJUST:
918 sal_Int32 nTmp;
919 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
921 nPageAdjust = (sal_Int16)nTmp;
923 break;
928 void XMLPageNumberImportContext::PrepareField(
929 const Reference<XPropertySet> & xPropertySet)
931 Any aAny;
933 // all properties are optional
934 Reference<XPropertySetInfo> xPropertySetInfo(
935 xPropertySet->getPropertySetInfo());
937 if (xPropertySetInfo->hasPropertyByName(sPropertyNumberingType))
939 sal_Int16 nNumType;
940 if( sNumberFormatOK )
942 nNumType= style::NumberingType::ARABIC;
943 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
944 sNumberFormat,
945 sNumberSync );
947 else
948 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
950 aAny <<= nNumType;
951 xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
954 if (xPropertySetInfo->hasPropertyByName(sPropertyOffset))
956 // adjust offset
957 switch (eSelectPage)
959 case PageNumberType_PREV:
960 nPageAdjust--;
961 break;
962 case PageNumberType_CURRENT:
963 break;
964 case PageNumberType_NEXT:
965 nPageAdjust++;
966 break;
967 default:
968 SAL_WARN("xmloff.text", "unknown page number type");
970 aAny <<= nPageAdjust;
971 xPropertySet->setPropertyValue(sPropertyOffset, aAny);
974 if (xPropertySetInfo->hasPropertyByName(sPropertySubType))
976 aAny <<= eSelectPage;
977 xPropertySet->setPropertyValue(sPropertySubType, aAny);
984 // Placeholder
987 TYPEINIT1( XMLPlaceholderFieldImportContext, XMLTextFieldImportContext);
989 XMLPlaceholderFieldImportContext::XMLPlaceholderFieldImportContext(
990 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
991 sal_uInt16 nPrfx, const OUString& sLocalName)
992 : XMLTextFieldImportContext(rImport, rHlp, sAPI_jump_edit,nPrfx, sLocalName)
993 , sPropertyPlaceholderType(sAPI_place_holder_type)
994 , sPropertyPlaceholder(sAPI_place_holder)
995 , sPropertyHint(sAPI_hint)
996 , nPlaceholderType(PlaceholderType::TEXT)
1000 /// process attribute values
1001 void XMLPlaceholderFieldImportContext::ProcessAttribute(
1002 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1004 switch (nAttrToken) {
1005 case XML_TOK_TEXTFIELD_DESCRIPTION:
1006 sDescription = sAttrValue;
1007 break;
1009 case XML_TOK_TEXTFIELD_PLACEHOLDER_TYPE:
1010 bValid = true;
1011 if (IsXMLToken(sAttrValue, XML_TABLE))
1013 nPlaceholderType = PlaceholderType::TABLE;
1015 else if (IsXMLToken(sAttrValue, XML_TEXT))
1017 nPlaceholderType = PlaceholderType::TEXT;
1019 else if (IsXMLToken(sAttrValue, XML_TEXT_BOX))
1021 nPlaceholderType = PlaceholderType::TEXTFRAME;
1023 else if (IsXMLToken(sAttrValue, XML_IMAGE))
1025 nPlaceholderType = PlaceholderType::GRAPHIC;
1027 else if (IsXMLToken(sAttrValue, XML_OBJECT))
1029 nPlaceholderType = PlaceholderType::OBJECT;
1031 else
1033 bValid = false;
1035 break;
1037 default:
1038 ; // ignore
1042 void XMLPlaceholderFieldImportContext::PrepareField(
1043 const Reference<XPropertySet> & xPropertySet) {
1045 Any aAny;
1046 aAny <<= sDescription;
1047 xPropertySet->setPropertyValue(sPropertyHint, aAny);
1049 // remove <...> around content (if present)
1050 OUString aContent = GetContent();
1051 sal_Int32 nStart = 0;
1052 sal_Int32 nLength = aContent.getLength();
1053 if (aContent.startsWith("<"))
1055 --nLength;
1056 ++nStart;
1058 if (aContent.endsWith(">"))
1060 --nLength;
1062 aAny <<= aContent.copy(nStart, nLength);
1063 xPropertySet->setPropertyValue(sPropertyPlaceholder, aAny);
1065 aAny <<= nPlaceholderType;
1066 xPropertySet->setPropertyValue(sPropertyPlaceholderType, aAny);
1071 // time field
1074 TYPEINIT1( XMLTimeFieldImportContext, XMLTextFieldImportContext);
1076 XMLTimeFieldImportContext::XMLTimeFieldImportContext(
1077 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1078 sal_uInt16 nPrfx, const OUString& sLocalName)
1079 : XMLTextFieldImportContext(rImport, rHlp, sAPI_date_time, nPrfx, sLocalName)
1080 , sPropertyNumberFormat(sAPI_number_format)
1081 , sPropertyFixed(sAPI_is_fixed)
1082 , sPropertyDateTimeValue(sAPI_date_time_value)
1083 , sPropertyDateTime(sAPI_date_time)
1084 , sPropertyAdjust(sAPI_adjust)
1085 , sPropertyIsDate(sAPI_is_date)
1086 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1087 , nAdjust(0)
1088 , nFormatKey(0)
1089 , bTimeOK(false)
1090 , bFormatOK(false)
1091 , bFixed(false)
1092 , bIsDate(false)
1093 , bIsDefaultLanguage( true )
1095 bValid = true; // always valid!
1098 void XMLTimeFieldImportContext::ProcessAttribute(
1099 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1101 switch (nAttrToken)
1103 case XML_TOK_TEXTFIELD_TIME_VALUE:
1105 if (::sax::Converter::parseTimeOrDateTime(aDateTimeValue, 0,
1106 sAttrValue))
1108 bTimeOK = true;
1110 break;
1112 case XML_TOK_TEXTFIELD_FIXED:
1114 bool bTmp(false);
1115 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1117 bFixed = bTmp;
1119 break;
1121 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1123 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1124 sAttrValue, &bIsDefaultLanguage);
1125 if (-1 != nKey)
1127 nFormatKey = nKey;
1128 bFormatOK = true;
1130 break;
1132 case XML_TOK_TEXTFIELD_TIME_ADJUST:
1134 double fTmp;
1136 if (::sax::Converter::convertDuration(fTmp, sAttrValue))
1138 // convert to minutes
1139 nAdjust = (sal_Int32)::rtl::math::approxFloor(fTmp * 60 * 24);
1141 break;
1146 void XMLTimeFieldImportContext::PrepareField(
1147 const Reference<XPropertySet> & rPropertySet)
1149 Any aAny;
1151 // all properties are optional (except IsDate)
1152 Reference<XPropertySetInfo> xPropertySetInfo(
1153 rPropertySet->getPropertySetInfo());
1155 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1157 aAny.setValue( &bFixed, cppu::UnoType<bool>::get() );
1158 rPropertySet->setPropertyValue(sPropertyFixed, aAny);
1161 aAny.setValue( &bIsDate, cppu::UnoType<bool>::get() );
1162 rPropertySet->setPropertyValue(sPropertyIsDate, aAny);
1164 if (xPropertySetInfo->hasPropertyByName(sPropertyAdjust))
1166 aAny <<= nAdjust;
1167 rPropertySet->setPropertyValue(sPropertyAdjust, aAny);
1170 // set value
1171 if (bFixed)
1173 // organizer or styles-only mode: force update
1174 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1175 GetImport().GetTextImport()->IsStylesOnlyMode() )
1177 ForceUpdate(rPropertySet);
1179 else
1181 // normal mode: set value (if present)
1182 if (bTimeOK)
1184 if (xPropertySetInfo->hasPropertyByName(sPropertyDateTimeValue))
1186 aAny <<= aDateTimeValue;
1187 rPropertySet->setPropertyValue(sPropertyDateTimeValue,aAny);
1189 else if (xPropertySetInfo->hasPropertyByName(sPropertyDateTime))
1191 aAny <<= aDateTimeValue;
1192 rPropertySet->setPropertyValue(sPropertyDateTime, aAny);
1198 if (bFormatOK &&
1199 xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1201 aAny <<= nFormatKey;
1202 rPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
1204 if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
1206 sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
1207 aAny.setValue( &bIsFixedLanguage, cppu::UnoType<bool>::get() );
1208 rPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
1216 // date field
1219 TYPEINIT1( XMLDateFieldImportContext, XMLTimeFieldImportContext );
1221 XMLDateFieldImportContext::XMLDateFieldImportContext(
1222 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1223 sal_uInt16 nPrfx, const OUString& sLocalName) :
1224 XMLTimeFieldImportContext(rImport, rHlp, nPrfx, sLocalName)
1226 bIsDate = true; // always a date!
1229 void XMLDateFieldImportContext::ProcessAttribute(
1230 sal_uInt16 nAttrToken,
1231 const OUString& sAttrValue )
1233 switch (nAttrToken)
1235 case XML_TOK_TEXTFIELD_DATE_VALUE:
1237 if (::sax::Converter::parseDateTime(aDateTimeValue, 0, sAttrValue))
1239 bTimeOK = true;
1241 break;
1243 case XML_TOK_TEXTFIELD_DATE_ADJUST:
1244 // delegate to superclass, pretending it was a time-adjust attr.
1245 XMLTimeFieldImportContext::ProcessAttribute(
1246 XML_TOK_TEXTFIELD_TIME_ADJUST,
1247 sAttrValue);
1248 break;
1249 case XML_TOK_TEXTFIELD_TIME_VALUE:
1250 case XML_TOK_TEXTFIELD_TIME_ADJUST:
1251 ; // ignore time-adjust and time-value attributes
1252 break;
1253 default:
1254 // all others: delegate to super-class
1255 XMLTimeFieldImportContext::ProcessAttribute(nAttrToken,
1256 sAttrValue);
1257 break;
1265 // database field superclass
1268 TYPEINIT1( XMLDatabaseFieldImportContext, XMLTextFieldImportContext );
1270 XMLDatabaseFieldImportContext::XMLDatabaseFieldImportContext(
1271 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1272 const sal_Char* pServiceName, sal_uInt16 nPrfx,
1273 const OUString& sLocalName, bool bUseDisply)
1274 : XMLTextFieldImportContext(rImport, rHlp, pServiceName, nPrfx, sLocalName)
1275 , sPropertyDataBaseName(sAPI_data_base_name)
1276 , sPropertyDataBaseURL(sAPI_data_base_u_r_l)
1277 , sPropertyTableName(sAPI_data_table_name)
1278 , sPropertyDataCommandType(sAPI_data_command_type)
1279 , sPropertyIsVisible(sAPI_is_visible)
1280 , nCommandType( sdb::CommandType::TABLE )
1281 , bCommandTypeOK(false)
1282 , bDisplay( true )
1283 , bDisplayOK( false )
1284 , bUseDisplay( bUseDisply )
1285 , bDatabaseOK(false)
1286 , bDatabaseNameOK(false)
1287 , bDatabaseURLOK(false)
1288 , bTableOK(false)
1292 void XMLDatabaseFieldImportContext::ProcessAttribute(
1293 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1295 switch (nAttrToken)
1297 case XML_TOK_TEXTFIELD_DATABASE_NAME:
1298 sDatabaseName = sAttrValue;
1299 bDatabaseOK = true;
1300 bDatabaseNameOK = true;
1301 break;
1302 case XML_TOK_TEXTFIELD_TABLE_NAME:
1303 sTableName = sAttrValue;
1304 bTableOK = true;
1305 break;
1306 case XML_TOK_TEXTFIELD_TABLE_TYPE:
1307 if( IsXMLToken( sAttrValue, XML_TABLE ) )
1309 nCommandType = sdb::CommandType::TABLE;
1310 bCommandTypeOK = true;
1312 else if( IsXMLToken( sAttrValue, XML_QUERY ) )
1314 nCommandType = sdb::CommandType::QUERY;
1315 bCommandTypeOK = true;
1317 else if( IsXMLToken( sAttrValue, XML_COMMAND ) )
1319 nCommandType = sdb::CommandType::COMMAND;
1320 bCommandTypeOK = true;
1322 break;
1323 case XML_TOK_TEXTFIELD_DISPLAY:
1324 if( IsXMLToken( sAttrValue, XML_NONE ) )
1326 bDisplay = false;
1327 bDisplayOK = true;
1329 else if( IsXMLToken( sAttrValue, XML_VALUE ) )
1331 bDisplay = true;
1332 bDisplayOK = true;
1334 break;
1338 SvXMLImportContext* XMLDatabaseFieldImportContext::CreateChildContext(
1339 sal_uInt16 p_nPrefix,
1340 const OUString& rLocalName,
1341 const Reference<XAttributeList>& xAttrList )
1343 if( ( p_nPrefix == XML_NAMESPACE_FORM ) &&
1344 IsXMLToken( rLocalName, XML_CONNECTION_RESOURCE ) )
1346 // process attribute list directly
1347 sal_Int16 nLength = xAttrList->getLength();
1348 for( sal_Int16 n = 0; n < nLength; n++ )
1350 OUString sLocalName;
1351 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
1352 GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName );
1354 if( ( nPrefix == XML_NAMESPACE_XLINK ) &&
1355 IsXMLToken( sLocalName, XML_HREF ) )
1357 sDatabaseURL = xAttrList->getValueByIndex(n);
1358 bDatabaseOK = true;
1359 bDatabaseURLOK = true;
1363 // we call ProcessAttribute in order to set bValid appropriately
1364 ProcessAttribute( XML_TOKEN_INVALID, OUString() );
1367 return SvXMLImportContext::CreateChildContext(p_nPrefix, rLocalName,
1368 xAttrList);
1372 void XMLDatabaseFieldImportContext::PrepareField(
1373 const Reference<XPropertySet> & xPropertySet)
1375 Any aAny;
1377 aAny <<= sTableName;
1378 xPropertySet->setPropertyValue(sPropertyTableName, aAny);
1380 if( bDatabaseNameOK )
1382 aAny <<= sDatabaseName;
1383 xPropertySet->setPropertyValue(sPropertyDataBaseName, aAny);
1385 else if( bDatabaseURLOK )
1387 aAny <<= sDatabaseURL;
1388 xPropertySet->setPropertyValue(sPropertyDataBaseURL, aAny);
1391 // #99980# load/save command type for all fields; also load
1392 // old documents without command type
1393 if( bCommandTypeOK )
1395 aAny <<= nCommandType;
1396 xPropertySet->setPropertyValue( sPropertyDataCommandType, aAny );
1399 if( bUseDisplay && bDisplayOK )
1401 aAny.setValue( &bDisplay, cppu::UnoType<bool>::get() );
1402 xPropertySet->setPropertyValue( sPropertyIsVisible, aAny );
1409 // database name field
1412 TYPEINIT1( XMLDatabaseNameImportContext, XMLDatabaseFieldImportContext );
1414 XMLDatabaseNameImportContext::XMLDatabaseNameImportContext(
1415 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1416 sal_uInt16 nPrfx, const OUString& sLocalName) :
1417 XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_name,
1418 nPrfx, sLocalName, true)
1422 void XMLDatabaseNameImportContext::ProcessAttribute(
1423 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1425 // delegate to superclass and check for success
1426 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1427 bValid = bDatabaseOK && bTableOK;
1433 // database next field
1436 TYPEINIT1( XMLDatabaseNextImportContext, XMLDatabaseFieldImportContext );
1438 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1439 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1440 const sal_Char* pServiceName, sal_uInt16 nPrfx,
1441 const OUString& sLocalName) :
1442 XMLDatabaseFieldImportContext(rImport, rHlp, pServiceName,
1443 nPrfx, sLocalName, false),
1444 sPropertyCondition(sAPI_condition),
1445 sTrue(sAPI_true),
1446 sCondition(),
1447 bConditionOK(false)
1451 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1452 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1453 sal_uInt16 nPrfx, const OUString& sLocalName)
1454 : XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_next, nPrfx, sLocalName, false)
1455 , sPropertyCondition(sAPI_condition)
1456 , sTrue(sAPI_true)
1457 , bConditionOK(false)
1461 void XMLDatabaseNextImportContext::ProcessAttribute(
1462 sal_uInt16 nAttrToken, const OUString& sAttrValue )
1464 if (XML_TOK_TEXTFIELD_CONDITION == nAttrToken)
1466 OUString sTmp;
1467 sal_uInt16 nPrefix = GetImport().GetNamespaceMap()._GetKeyByAttrName(
1468 sAttrValue, &sTmp, false );
1469 if( XML_NAMESPACE_OOOW == nPrefix )
1471 sCondition = sTmp;
1472 bConditionOK = true;
1474 else
1475 sCondition = sAttrValue;
1477 else
1479 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1480 sAttrValue);
1483 bValid = bDatabaseOK && bTableOK;
1486 void XMLDatabaseNextImportContext::PrepareField(
1487 const Reference<XPropertySet> & xPropertySet)
1489 Any aAny;
1491 aAny <<= bConditionOK ? sCondition : sTrue;
1492 xPropertySet->setPropertyValue(sPropertyCondition, aAny);
1494 XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1500 // database select field
1503 TYPEINIT1( XMLDatabaseSelectImportContext, XMLDatabaseNextImportContext );
1505 XMLDatabaseSelectImportContext::XMLDatabaseSelectImportContext(
1506 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1507 sal_uInt16 nPrfx, const OUString& sLocalName) :
1508 XMLDatabaseNextImportContext(rImport, rHlp, sAPI_database_select,
1509 nPrfx, sLocalName),
1510 sPropertySetNumber(sAPI_set_number),
1511 nNumber(0),
1512 bNumberOK(false)
1516 void XMLDatabaseSelectImportContext::ProcessAttribute(
1517 sal_uInt16 nAttrToken,
1518 const OUString& sAttrValue )
1520 if (XML_TOK_TEXTFIELD_ROW_NUMBER == nAttrToken)
1522 sal_Int32 nTmp;
1523 if (::sax::Converter::convertNumber( nTmp, sAttrValue
1524 /* , nMin, nMax ??? */ ))
1526 nNumber = nTmp;
1527 bNumberOK = true;
1530 else
1532 XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken, sAttrValue);
1535 bValid = bTableOK && bDatabaseOK && bNumberOK;
1538 void XMLDatabaseSelectImportContext::PrepareField(
1539 const Reference<XPropertySet> & xPropertySet)
1541 Any aAny;
1543 aAny <<= nNumber;
1544 xPropertySet->setPropertyValue(sPropertySetNumber, aAny);
1546 XMLDatabaseNextImportContext::PrepareField(xPropertySet);
1552 // database display row number field
1555 TYPEINIT1( XMLDatabaseNumberImportContext, XMLDatabaseFieldImportContext );
1557 XMLDatabaseNumberImportContext::XMLDatabaseNumberImportContext(
1558 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1559 sal_uInt16 nPrfx, const OUString& sLocalName) :
1560 XMLDatabaseFieldImportContext(rImport, rHlp, sAPI_database_number,
1561 nPrfx, sLocalName, true),
1562 sPropertyNumberingType(
1563 sAPI_numbering_type),
1564 sPropertySetNumber(sAPI_set_number),
1565 sNumberFormat("1"),
1566 sNumberSync(GetXMLToken(XML_FALSE)),
1567 nValue(0),
1568 bValueOK(false)
1572 void XMLDatabaseNumberImportContext::ProcessAttribute(
1573 sal_uInt16 nAttrToken,
1574 const OUString& sAttrValue )
1576 switch (nAttrToken)
1578 case XML_TOK_TEXTFIELD_NUM_FORMAT:
1579 sNumberFormat = sAttrValue;
1580 break;
1581 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
1582 sNumberSync = sAttrValue;
1583 break;
1584 case XML_TOK_TEXTFIELD_VALUE:
1586 sal_Int32 nTmp;
1587 if (::sax::Converter::convertNumber( nTmp, sAttrValue ))
1589 nValue = nTmp;
1590 bValueOK = true;
1592 break;
1594 default:
1595 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken,
1596 sAttrValue);
1597 break;
1600 bValid = bTableOK && bDatabaseOK;
1603 void XMLDatabaseNumberImportContext::PrepareField(
1604 const Reference<XPropertySet> & xPropertySet)
1606 Any aAny;
1608 sal_Int16 nNumType = style::NumberingType::ARABIC;
1609 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
1610 sNumberFormat,
1611 sNumberSync );
1612 aAny <<= nNumType;
1613 xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
1615 if (bValueOK)
1617 aAny <<= nValue;
1618 xPropertySet->setPropertyValue(sPropertySetNumber, aAny);
1621 XMLDatabaseFieldImportContext::PrepareField(xPropertySet);
1627 // Simple doc info fields
1630 TYPEINIT1( XMLSimpleDocInfoImportContext, XMLTextFieldImportContext );
1632 XMLSimpleDocInfoImportContext::XMLSimpleDocInfoImportContext(
1633 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1634 sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken,
1635 bool bContent, bool bAuthor)
1636 : XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nToken),nPrfx, sLocalName)
1637 , sPropertyFixed(sAPI_is_fixed)
1638 , sPropertyContent(sAPI_content)
1639 , sPropertyAuthor(sAPI_author)
1640 , sPropertyCurrentPresentation(sAPI_current_presentation)
1641 , bFixed(false)
1642 , bHasAuthor(bAuthor)
1643 , bHasContent(bContent)
1645 bValid = true;
1648 void XMLSimpleDocInfoImportContext::ProcessAttribute(
1649 sal_uInt16 nAttrToken,
1650 const OUString& sAttrValue )
1652 if (XML_TOK_TEXTFIELD_FIXED == nAttrToken)
1654 bool bTmp(false);
1655 if (::sax::Converter::convertBool(bTmp, sAttrValue))
1657 bFixed = bTmp;
1662 void XMLSimpleDocInfoImportContext::PrepareField(
1663 const Reference<XPropertySet> & rPropertySet)
1665 // title field in Calc has no Fixed property
1666 Reference<XPropertySetInfo> xPropertySetInfo(rPropertySet->getPropertySetInfo());
1667 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
1669 Any aAny;
1670 aAny.setValue(&bFixed, cppu::UnoType<bool>::get() );
1671 rPropertySet->setPropertyValue(sPropertyFixed, aAny);
1673 // set Content and CurrentPresentation (if fixed)
1674 if (bFixed)
1676 // in organizer-mode or styles-only-mode, only force update
1677 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1678 GetImport().GetTextImport()->IsStylesOnlyMode() )
1680 ForceUpdate(rPropertySet);
1682 else
1684 // set content (author, if that's the name) and current
1685 // presentation
1686 aAny <<= GetContent();
1688 if (bFixed && bHasAuthor)
1690 rPropertySet->setPropertyValue(sPropertyAuthor, aAny);
1693 if (bFixed && bHasContent)
1695 rPropertySet->setPropertyValue(sPropertyContent, aAny);
1698 rPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
1704 const sal_Char* XMLSimpleDocInfoImportContext::MapTokenToServiceName(
1705 sal_uInt16 nToken)
1707 const sal_Char* pServiceName = NULL;
1709 switch(nToken)
1711 case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR:
1712 pServiceName = sAPI_docinfo_create_author;
1713 break;
1714 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
1715 pServiceName = sAPI_docinfo_create_date_time;
1716 break;
1717 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
1718 pServiceName = sAPI_docinfo_create_date_time;
1719 break;
1720 case XML_TOK_TEXT_DOCUMENT_DESCRIPTION:
1721 pServiceName = sAPI_docinfo_description;
1722 break;
1723 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
1724 pServiceName = sAPI_docinfo_edit_time;
1725 break;
1726 case XML_TOK_TEXT_DOCUMENT_USER_DEFINED:
1727 pServiceName = sAPI_docinfo_custom;
1728 break;
1729 case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR:
1730 pServiceName = sAPI_docinfo_print_author;
1731 break;
1732 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
1733 pServiceName = sAPI_docinfo_print_date_time;
1734 break;
1735 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
1736 pServiceName = sAPI_docinfo_print_date_time;
1737 break;
1738 case XML_TOK_TEXT_DOCUMENT_KEYWORDS:
1739 pServiceName = sAPI_docinfo_keywords;
1740 break;
1741 case XML_TOK_TEXT_DOCUMENT_SUBJECT:
1742 pServiceName = sAPI_docinfo_subject;
1743 break;
1744 case XML_TOK_TEXT_DOCUMENT_REVISION:
1745 pServiceName = sAPI_docinfo_revision;
1746 break;
1747 case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR:
1748 pServiceName = sAPI_docinfo_change_author;
1749 break;
1750 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
1751 pServiceName = sAPI_docinfo_change_date_time;
1752 break;
1753 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
1754 pServiceName = sAPI_docinfo_change_date_time;
1755 break;
1756 case XML_TOK_TEXT_DOCUMENT_TITLE:
1757 pServiceName = sAPI_docinfo_title;
1758 break;
1760 default:
1761 OSL_FAIL("no docinfo field token");
1762 pServiceName = NULL;
1763 break;
1766 return pServiceName;
1771 // revision field
1774 TYPEINIT1( XMLRevisionDocInfoImportContext, XMLSimpleDocInfoImportContext );
1776 XMLRevisionDocInfoImportContext::XMLRevisionDocInfoImportContext(
1777 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
1778 const OUString& sLocalName, sal_uInt16 nToken) :
1779 XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, sLocalName,
1780 nToken, false, false),
1781 sPropertyRevision(sAPI_revision)
1783 bValid = true;
1786 void XMLRevisionDocInfoImportContext::PrepareField(
1787 const Reference<XPropertySet> & rPropertySet)
1789 XMLSimpleDocInfoImportContext::PrepareField(rPropertySet);
1791 // set revision number
1792 // if fixed, if not in organizer-mode, if not in styles-only-mode
1793 if (bFixed)
1795 if ( GetImport().GetTextImport()->IsOrganizerMode() ||
1796 GetImport().GetTextImport()->IsStylesOnlyMode() )
1798 ForceUpdate(rPropertySet);
1800 else
1802 sal_Int32 nTmp;
1803 if (::sax::Converter::convertNumber(nTmp, GetContent()))
1805 Any aAny;
1806 aAny <<= nTmp;
1807 rPropertySet->setPropertyValue(sPropertyRevision, aAny);
1816 // DocInfo fields with date/time attributes
1819 TYPEINIT1( XMLDateTimeDocInfoImportContext, XMLSimpleDocInfoImportContext );
1821 XMLDateTimeDocInfoImportContext::XMLDateTimeDocInfoImportContext(
1822 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
1823 const OUString& sLocalName, sal_uInt16 nToken)
1824 : XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx, sLocalName,nToken, false, false)
1825 , sPropertyNumberFormat(sAPI_number_format)
1826 , sPropertyIsDate(sAPI_is_date)
1827 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1828 , nFormat(0)
1829 , bFormatOK(false)
1830 , bIsDate(false)
1831 , bHasDateTime(false)
1832 , bIsDefaultLanguage(true)
1834 // we allow processing of EDIT_DURATION here, because import of actual
1835 // is not supported anyway. If it was, we'd need an extra import class
1836 // because times and time durations are presented differently!
1838 bValid = true;
1839 switch (nToken)
1841 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE:
1842 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE:
1843 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE:
1844 bIsDate = true;
1845 bHasDateTime = true;
1846 break;
1847 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME:
1848 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME:
1849 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME:
1850 bIsDate = false;
1851 bHasDateTime = true;
1852 break;
1853 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION:
1854 bIsDate = false;
1855 bHasDateTime = false;
1856 break;
1857 default:
1858 OSL_FAIL(
1859 "XMLDateTimeDocInfoImportContext needs date/time doc. fields");
1860 bValid = false;
1861 break;
1865 void XMLDateTimeDocInfoImportContext::ProcessAttribute(
1866 sal_uInt16 nAttrToken,
1867 const OUString& sAttrValue )
1869 switch (nAttrToken)
1871 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1873 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1874 sAttrValue, &bIsDefaultLanguage);
1875 if (-1 != nKey)
1877 nFormat = nKey;
1878 bFormatOK = true;
1880 break;
1882 case XML_TOK_TEXTFIELD_FIXED:
1883 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1884 sAttrValue);
1885 break;
1886 default:
1887 // ignore -> we can't set date/time value anyway!
1888 break;
1892 void XMLDateTimeDocInfoImportContext::PrepareField(
1893 const Reference<XPropertySet> & xPropertySet)
1895 // process fixed and presentation
1896 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
1898 Any aAny;
1900 if (bHasDateTime)
1902 aAny.setValue( &bIsDate, cppu::UnoType<bool>::get());
1903 xPropertySet->setPropertyValue(sPropertyIsDate, aAny);
1906 if (bFormatOK)
1908 aAny <<= nFormat;
1909 xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
1911 if( xPropertySet->getPropertySetInfo()->
1912 hasPropertyByName( sPropertyIsFixedLanguage ) )
1914 sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
1915 aAny.setValue( &bIsFixedLanguage, cppu::UnoType<bool>::get() );
1916 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
1920 // can't set date/time/duration value! Sorry.
1925 // user defined docinfo fields
1928 TYPEINIT1( XMLUserDocInfoImportContext, XMLSimpleDocInfoImportContext );
1930 XMLUserDocInfoImportContext::XMLUserDocInfoImportContext(
1931 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
1932 sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken) :
1933 XMLSimpleDocInfoImportContext(rImport, rHlp, nPrfx,
1934 sLocalName, nToken,
1935 false, false)
1936 , sPropertyName(sAPI_name)
1937 , sPropertyNumberFormat(sAPI_number_format)
1938 , sPropertyIsFixedLanguage(sAPI_is_fixed_language)
1939 , nFormat(0)
1940 , bFormatOK(false)
1941 , bIsDefaultLanguage( true )
1943 bValid = false;
1946 void XMLUserDocInfoImportContext::ProcessAttribute(
1947 sal_uInt16 nAttrToken,
1948 const OUString& sAttrValue )
1950 switch (nAttrToken)
1952 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME:
1954 sal_Int32 nKey = GetImportHelper().GetDataStyleKey(
1955 sAttrValue, &bIsDefaultLanguage);
1956 if (-1 != nKey)
1958 nFormat = nKey;
1959 bFormatOK = true;
1961 break;
1963 case XML_TOK_TEXTFIELD_NAME:
1965 if (!bValid)
1967 SetServiceName(OUString(sAPI_docinfo_custom ) );
1968 aName = sAttrValue;
1969 bValid = true;
1971 break;
1974 default:
1975 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken,
1976 sAttrValue);
1977 break;
1981 void XMLUserDocInfoImportContext::PrepareField(
1982 const ::com::sun::star::uno::Reference<
1983 ::com::sun::star::beans::XPropertySet> & xPropertySet)
1985 uno::Any aAny;
1986 if ( !aName.isEmpty() )
1988 aAny <<= aName;
1989 xPropertySet->setPropertyValue(sPropertyName, aAny);
1991 Reference<XPropertySetInfo> xPropertySetInfo(
1992 xPropertySet->getPropertySetInfo());
1993 if (bFormatOK &&
1994 xPropertySetInfo->hasPropertyByName(sPropertyNumberFormat))
1996 aAny <<= nFormat;
1997 xPropertySet->setPropertyValue(sPropertyNumberFormat, aAny);
1999 if( xPropertySetInfo->hasPropertyByName( sPropertyIsFixedLanguage ) )
2001 sal_Bool bIsFixedLanguage = ! bIsDefaultLanguage;
2002 aAny.setValue( &bIsFixedLanguage, cppu::UnoType<bool>::get() );
2003 xPropertySet->setPropertyValue( sPropertyIsFixedLanguage, aAny );
2007 // call superclass to handle "fixed"
2008 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet);
2013 // import hidden paragraph fields
2016 TYPEINIT1( XMLHiddenParagraphImportContext, XMLTextFieldImportContext );
2018 XMLHiddenParagraphImportContext::XMLHiddenParagraphImportContext(
2019 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2020 sal_uInt16 nPrfx, const OUString& sLocalName) :
2021 XMLTextFieldImportContext(rImport, rHlp, sAPI_hidden_paragraph,
2022 nPrfx, sLocalName),
2023 sPropertyCondition(sAPI_condition),
2024 sPropertyIsHidden(sAPI_is_hidden),
2025 sCondition(),
2026 bIsHidden(false)
2030 void XMLHiddenParagraphImportContext::ProcessAttribute(
2031 sal_uInt16 nAttrToken,
2032 const OUString& sAttrValue )
2034 if (XML_TOK_TEXTFIELD_CONDITION == nAttrToken)
2036 OUString sTmp;
2037 sal_uInt16 nPrefix = GetImport().GetNamespaceMap()._GetKeyByAttrName(
2038 sAttrValue, &sTmp, false );
2039 if( XML_NAMESPACE_OOOW == nPrefix )
2041 sCondition = sTmp;
2042 bValid = true;
2044 else
2045 sCondition = sAttrValue;
2047 else if (XML_TOK_TEXTFIELD_IS_HIDDEN == nAttrToken)
2049 bool bTmp(false);
2050 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2052 bIsHidden = bTmp;
2057 void XMLHiddenParagraphImportContext::PrepareField(
2058 const Reference<XPropertySet> & xPropertySet)
2060 Any aAny;
2061 aAny <<= sCondition;
2062 xPropertySet->setPropertyValue(sPropertyCondition, aAny);
2064 aAny.setValue( &bIsHidden, cppu::UnoType<bool>::get() );
2065 xPropertySet->setPropertyValue(sPropertyIsHidden, aAny);
2071 // import conditional text (<text:conditional-text>)
2074 TYPEINIT1( XMLConditionalTextImportContext, XMLTextFieldImportContext );
2076 XMLConditionalTextImportContext::XMLConditionalTextImportContext(
2077 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2078 sal_uInt16 nPrfx, const OUString& sLocalName) :
2079 XMLTextFieldImportContext(rImport, rHlp, sAPI_conditional_text,
2080 nPrfx, sLocalName),
2081 sPropertyCondition(sAPI_condition),
2082 sPropertyTrueContent(sAPI_true_content),
2083 sPropertyFalseContent(sAPI_false_content),
2084 sPropertyIsConditionTrue(sAPI_is_condition_true),
2085 sPropertyCurrentPresentation(sAPI_current_presentation),
2086 bConditionOK(false),
2087 bTrueOK(false),
2088 bFalseOK(false),
2089 bCurrentValue(false)
2093 void XMLConditionalTextImportContext::ProcessAttribute(
2094 sal_uInt16 nAttrToken,
2095 const OUString& sAttrValue )
2097 switch (nAttrToken)
2099 case XML_TOK_TEXTFIELD_CONDITION:
2101 OUString sTmp;
2102 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
2103 _GetKeyByAttrName( sAttrValue, &sTmp, false );
2104 if( XML_NAMESPACE_OOOW == nPrefix )
2106 sCondition = sTmp;
2107 bConditionOK = true;
2109 else
2110 sCondition = sAttrValue;
2112 break;
2113 case XML_TOK_TEXTFIELD_STRING_VALUE_IF_FALSE:
2114 sFalseContent = sAttrValue;
2115 bFalseOK = true;
2116 break;
2117 case XML_TOK_TEXTFIELD_STRING_VALUE_IF_TRUE:
2118 sTrueContent = sAttrValue;
2119 bTrueOK = true;
2120 break;
2121 case XML_TOK_TEXTFIELD_CURRENT_VALUE:
2123 bool bTmp(false);
2124 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2126 bCurrentValue = bTmp;
2128 break;
2132 bValid = bConditionOK && bFalseOK && bTrueOK;
2135 void XMLConditionalTextImportContext::PrepareField(
2136 const Reference<XPropertySet> & xPropertySet)
2138 Any aAny;
2140 aAny <<= sCondition;
2141 xPropertySet->setPropertyValue(sPropertyCondition, aAny);
2143 aAny <<= sFalseContent;
2144 xPropertySet->setPropertyValue(sPropertyFalseContent, aAny);
2146 aAny <<= sTrueContent;
2147 xPropertySet->setPropertyValue(sPropertyTrueContent, aAny);
2149 aAny.setValue( &bCurrentValue, cppu::UnoType<bool>::get() );
2150 xPropertySet->setPropertyValue(sPropertyIsConditionTrue, aAny);
2152 aAny <<= GetContent();
2153 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
2159 // hidden text
2162 TYPEINIT1( XMLHiddenTextImportContext, XMLTextFieldImportContext);
2164 XMLHiddenTextImportContext::XMLHiddenTextImportContext(
2165 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2166 sal_uInt16 nPrfx, const OUString& sLocalName) :
2167 XMLTextFieldImportContext(rImport, rHlp, sAPI_hidden_text,
2168 nPrfx, sLocalName),
2169 sPropertyCondition(sAPI_condition),
2170 sPropertyContent(sAPI_content),
2171 sPropertyIsHidden(sAPI_is_hidden),
2172 bConditionOK(false),
2173 bStringOK(false),
2174 bIsHidden(false)
2178 void XMLHiddenTextImportContext::ProcessAttribute(
2179 sal_uInt16 nAttrToken,
2180 const OUString& sAttrValue )
2182 switch (nAttrToken)
2184 case XML_TOK_TEXTFIELD_CONDITION:
2186 OUString sTmp;
2187 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
2188 _GetKeyByAttrName( sAttrValue, &sTmp, false );
2189 if( XML_NAMESPACE_OOOW == nPrefix )
2191 sCondition = sTmp;
2192 bConditionOK = true;
2194 else
2195 sCondition = sAttrValue;
2197 break;
2198 case XML_TOK_TEXTFIELD_STRING_VALUE:
2199 sString = sAttrValue;
2200 bStringOK = true;
2201 break;
2202 case XML_TOK_TEXTFIELD_IS_HIDDEN:
2204 bool bTmp(false);
2205 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2207 bIsHidden = bTmp;
2209 break;
2213 bValid = bConditionOK && bStringOK;
2216 void XMLHiddenTextImportContext::PrepareField(
2217 const Reference<XPropertySet> & xPropertySet)
2219 Any aAny;
2221 aAny <<= sCondition;
2222 xPropertySet->setPropertyValue(sPropertyCondition, aAny);
2224 aAny <<= sString;
2225 xPropertySet->setPropertyValue(sPropertyContent, aAny);
2227 aAny.setValue( &bIsHidden, cppu::UnoType<bool>::get() );
2228 xPropertySet->setPropertyValue(sPropertyIsHidden, aAny);
2234 // file name fields
2237 TYPEINIT1( XMLFileNameImportContext, XMLTextFieldImportContext );
2239 static const SvXMLEnumMapEntry aFilenameDisplayMap[] =
2241 { XML_PATH, FilenameDisplayFormat::PATH },
2242 { XML_NAME, FilenameDisplayFormat::NAME },
2243 { XML_NAME_AND_EXTENSION, FilenameDisplayFormat::NAME_AND_EXT },
2244 { XML_FULL, FilenameDisplayFormat::FULL },
2245 { XML_TOKEN_INVALID, 0 }
2248 XMLFileNameImportContext::XMLFileNameImportContext(
2249 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2250 const OUString& sLocalName) :
2251 XMLTextFieldImportContext(rImport, rHlp, sAPI_file_name,
2252 nPrfx, sLocalName),
2253 sPropertyFixed(sAPI_is_fixed),
2254 sPropertyFileFormat(sAPI_file_format),
2255 sPropertyCurrentPresentation(
2256 sAPI_current_presentation),
2257 nFormat(FilenameDisplayFormat::FULL),
2258 bFixed(false)
2260 bValid = true;
2263 void XMLFileNameImportContext::ProcessAttribute(
2264 sal_uInt16 nAttrToken,
2265 const OUString& sAttrValue )
2267 switch (nAttrToken)
2269 case XML_TOK_TEXTFIELD_FIXED:
2271 bool bTmp(false);
2272 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2274 bFixed = bTmp;
2276 break;
2278 case XML_TOK_TEXTFIELD_DISPLAY:
2280 sal_uInt16 nTmp;
2281 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2282 aFilenameDisplayMap))
2284 nFormat = (sal_uInt16)nTmp;
2286 break;
2288 default:
2289 ; // unknown attribute: ignore
2290 break;
2294 void XMLFileNameImportContext::PrepareField(
2295 const Reference<XPropertySet> & xPropertySet)
2297 Any aAny;
2299 // properties are optional
2300 Reference<XPropertySetInfo> xPropertySetInfo(
2301 xPropertySet->getPropertySetInfo());
2303 if (xPropertySetInfo->hasPropertyByName(sPropertyFixed))
2305 aAny <<= bFixed;
2306 xPropertySet->setPropertyValue(sPropertyFixed, aAny);
2309 if (xPropertySetInfo->hasPropertyByName(sPropertyFileFormat))
2311 aAny <<= nFormat;
2312 xPropertySet->setPropertyValue(sPropertyFileFormat, aAny);
2315 if (xPropertySetInfo->hasPropertyByName(sPropertyCurrentPresentation))
2317 aAny <<= GetContent();
2318 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
2324 // template name field
2327 static const SvXMLEnumMapEntry aTemplateDisplayMap[] =
2329 { XML_FULL, TemplateDisplayFormat::FULL },
2330 { XML_PATH, TemplateDisplayFormat::PATH },
2331 { XML_NAME, TemplateDisplayFormat::NAME },
2332 { XML_NAME_AND_EXTENSION, TemplateDisplayFormat::NAME_AND_EXT },
2333 { XML_AREA, TemplateDisplayFormat::AREA },
2334 { XML_TITLE, TemplateDisplayFormat::TITLE },
2335 { XML_TOKEN_INVALID, 0 }
2338 TYPEINIT1( XMLTemplateNameImportContext, XMLTextFieldImportContext );
2340 XMLTemplateNameImportContext::XMLTemplateNameImportContext(
2341 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2342 const OUString& sLocalName) :
2343 XMLTextFieldImportContext(rImport, rHlp, sAPI_template_name,
2344 nPrfx, sLocalName),
2345 sPropertyFileFormat(sAPI_file_format),
2346 nFormat(TemplateDisplayFormat::FULL)
2348 bValid = true;
2351 void XMLTemplateNameImportContext::ProcessAttribute(
2352 sal_uInt16 nAttrToken,
2353 const OUString& sAttrValue )
2355 switch (nAttrToken)
2357 case XML_TOK_TEXTFIELD_DISPLAY:
2359 sal_uInt16 nTmp;
2360 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2361 aTemplateDisplayMap))
2363 nFormat = (sal_uInt16)nTmp;
2365 break;
2367 default:
2368 ; // unknown attribute: ignore
2369 break;
2373 void XMLTemplateNameImportContext::PrepareField(
2374 const Reference<XPropertySet> & xPropertySet)
2376 Any aAny;
2378 aAny <<= nFormat;
2379 xPropertySet->setPropertyValue(sPropertyFileFormat, aAny);
2384 // import chapter fields
2387 TYPEINIT1( XMLChapterImportContext, XMLTextFieldImportContext );
2389 static const SvXMLEnumMapEntry aChapterDisplayMap[] =
2391 { XML_NAME, ChapterFormat::NAME },
2392 { XML_NUMBER, ChapterFormat::NUMBER },
2393 { XML_NUMBER_AND_NAME, ChapterFormat::NAME_NUMBER },
2394 { XML_PLAIN_NUMBER_AND_NAME, ChapterFormat::NO_PREFIX_SUFFIX },
2395 { XML_PLAIN_NUMBER, ChapterFormat::DIGIT },
2396 { XML_TOKEN_INVALID, 0 }
2399 XMLChapterImportContext::XMLChapterImportContext(
2400 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2401 sal_uInt16 nPrfx, const OUString& sLocalName) :
2402 XMLTextFieldImportContext(rImport, rHlp, sAPI_chapter,
2403 nPrfx, sLocalName),
2404 sPropertyChapterFormat(
2405 sAPI_chapter_format),
2406 sPropertyLevel(sAPI_level),
2407 nFormat(ChapterFormat::NAME_NUMBER),
2408 nLevel(0)
2410 bValid = true;
2413 void XMLChapterImportContext::ProcessAttribute(
2414 sal_uInt16 nAttrToken,
2415 const OUString& sAttrValue )
2417 switch (nAttrToken)
2419 case XML_TOK_TEXTFIELD_DISPLAY:
2421 sal_uInt16 nTmp;
2422 if (SvXMLUnitConverter::convertEnum(nTmp, sAttrValue,
2423 aChapterDisplayMap))
2425 nFormat = (sal_Int16)nTmp;
2427 break;
2429 case XML_TOK_TEXTFIELD_OUTLINE_LEVEL:
2431 sal_Int32 nTmp;
2432 if (::sax::Converter::convertNumber(
2433 nTmp, sAttrValue, 1,
2434 GetImport().GetTextImport()->GetChapterNumbering()->getCount()
2437 // API numbers 0..9, we number 1..10
2438 nLevel = (sal_Int8)nTmp;
2439 nLevel--;
2441 break;
2443 default:
2444 ; // unknown attribute: ignore
2445 break;
2449 void XMLChapterImportContext::PrepareField(
2450 const Reference<XPropertySet> & xPropertySet)
2452 Any aAny;
2454 aAny <<= nFormat;
2455 xPropertySet->setPropertyValue(sPropertyChapterFormat, aAny);
2457 aAny <<= nLevel;
2458 xPropertySet->setPropertyValue(sPropertyLevel, aAny);
2463 // counting fields
2466 TYPEINIT1( XMLCountFieldImportContext, XMLTextFieldImportContext );
2468 XMLCountFieldImportContext::XMLCountFieldImportContext(
2469 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2470 sal_uInt16 nPrfx, const OUString& sLocalName, sal_uInt16 nToken) :
2471 XMLTextFieldImportContext(rImport, rHlp, MapTokenToServiceName(nToken),
2472 nPrfx, sLocalName),
2473 sPropertyNumberingType(
2474 sAPI_numbering_type),
2475 sNumberFormat(),
2476 sLetterSync(),
2477 bNumberFormatOK(false)
2479 bValid = true;
2482 void XMLCountFieldImportContext::ProcessAttribute(
2483 sal_uInt16 nAttrToken,
2484 const OUString& sAttrValue )
2486 switch (nAttrToken)
2488 case XML_TOK_TEXTFIELD_NUM_FORMAT:
2489 sNumberFormat = sAttrValue;
2490 bNumberFormatOK = true;
2491 break;
2492 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
2493 sLetterSync = sAttrValue;
2494 break;
2498 void XMLCountFieldImportContext::PrepareField(
2499 const Reference<XPropertySet> & xPropertySet)
2501 Any aAny;
2503 // properties optional
2504 // (only page count, but do for all to save common implementation)
2506 if (xPropertySet->getPropertySetInfo()->
2507 hasPropertyByName(sPropertyNumberingType))
2509 sal_Int16 nNumType;
2510 if( bNumberFormatOK )
2512 nNumType= style::NumberingType::ARABIC;
2513 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2514 sNumberFormat,
2515 sLetterSync );
2517 else
2518 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2519 aAny <<= nNumType;
2520 xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
2524 const sal_Char* XMLCountFieldImportContext::MapTokenToServiceName(
2525 sal_uInt16 nToken)
2527 const sal_Char* pServiceName = NULL;
2529 switch (nToken)
2531 case XML_TOK_TEXT_WORD_COUNT:
2532 pServiceName = sAPI_word_count;
2533 break;
2534 case XML_TOK_TEXT_PARAGRAPH_COUNT:
2535 pServiceName = sAPI_paragraph_count;
2536 break;
2537 case XML_TOK_TEXT_TABLE_COUNT:
2538 pServiceName = sAPI_table_count;
2539 break;
2540 case XML_TOK_TEXT_CHARACTER_COUNT:
2541 pServiceName = sAPI_character_count;
2542 break;
2543 case XML_TOK_TEXT_IMAGE_COUNT:
2544 pServiceName = sAPI_graphic_object_count;
2545 break;
2546 case XML_TOK_TEXT_OBJECT_COUNT:
2547 pServiceName = sAPI_embedded_object_count;
2548 break;
2549 case XML_TOK_TEXT_PAGE_COUNT:
2550 pServiceName = sAPI_page_count;
2551 break;
2552 default:
2553 pServiceName = NULL;
2554 OSL_FAIL("unknown count field!");
2555 break;
2558 return pServiceName;
2564 // page variable import
2567 TYPEINIT1( XMLPageVarGetFieldImportContext, XMLTextFieldImportContext );
2569 XMLPageVarGetFieldImportContext::XMLPageVarGetFieldImportContext(
2570 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2571 sal_uInt16 nPrfx, const OUString& sLocalName) :
2572 XMLTextFieldImportContext(rImport, rHlp, sAPI_reference_page_get,
2573 nPrfx, sLocalName),
2574 sPropertyNumberingType(
2575 sAPI_numbering_type),
2576 sNumberFormat(),
2577 sLetterSync(),
2578 bNumberFormatOK(false)
2580 bValid = true;
2583 void XMLPageVarGetFieldImportContext::ProcessAttribute(
2584 sal_uInt16 nAttrToken,
2585 const OUString& sAttrValue )
2587 switch (nAttrToken)
2589 case XML_TOK_TEXTFIELD_NUM_FORMAT:
2590 sNumberFormat = sAttrValue;
2591 bNumberFormatOK = true;
2592 break;
2593 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC:
2594 sLetterSync = sAttrValue;
2595 break;
2599 void XMLPageVarGetFieldImportContext::PrepareField(
2600 const Reference<XPropertySet> & xPropertySet)
2602 Any aAny;
2604 sal_Int16 nNumType;
2605 if( bNumberFormatOK )
2607 nNumType= style::NumberingType::ARABIC;
2608 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType,
2609 sNumberFormat,
2610 sLetterSync );
2612 else
2613 nNumType = style::NumberingType::PAGE_DESCRIPTOR;
2614 aAny <<= nNumType;
2615 xPropertySet->setPropertyValue(sPropertyNumberingType, aAny);
2617 // display old content (#96657#)
2618 aAny <<= GetContent();
2619 xPropertySet->setPropertyValue(
2620 OUString(sAPI_current_presentation),
2621 aAny );
2627 // page variable set fields
2630 TYPEINIT1(XMLPageVarSetFieldImportContext, XMLTextFieldImportContext);
2632 XMLPageVarSetFieldImportContext::XMLPageVarSetFieldImportContext(
2633 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2634 const OUString& sLocalName) :
2635 XMLTextFieldImportContext(rImport, rHlp, sAPI_reference_page_set,
2636 nPrfx, sLocalName),
2637 sPropertyOn(sAPI_on),
2638 sPropertyOffset(sAPI_offset),
2639 nAdjust(0),
2640 bActive(true)
2642 bValid = true;
2645 void XMLPageVarSetFieldImportContext::ProcessAttribute(
2646 sal_uInt16 nAttrToken,
2647 const OUString& sAttrValue )
2649 switch (nAttrToken)
2651 case XML_TOK_TEXTFIELD_ACTIVE:
2653 bool bTmp(false);
2654 if (::sax::Converter::convertBool(bTmp, sAttrValue))
2656 bActive = bTmp;
2658 break;
2660 case XML_TOK_TEXTFIELD_PAGE_ADJUST:
2662 sal_Int32 nTmp(0);
2663 if (::sax::Converter::convertNumber(nTmp, sAttrValue))
2665 nAdjust = (sal_Int16)nTmp;
2667 break;
2669 default:
2670 break;
2674 void XMLPageVarSetFieldImportContext::PrepareField(
2675 const Reference<XPropertySet> & xPropertySet)
2677 Any aAny;
2679 aAny.setValue(&bActive, cppu::UnoType<bool>::get());
2680 xPropertySet->setPropertyValue(sPropertyOn, aAny);
2682 aAny <<= nAdjust;
2683 xPropertySet->setPropertyValue(sPropertyOffset, aAny);
2689 // macro fields
2692 TYPEINIT1( XMLMacroFieldImportContext, XMLTextFieldImportContext );
2694 XMLMacroFieldImportContext::XMLMacroFieldImportContext(
2695 SvXMLImport& rImport, XMLTextImportHelper& rHlp, sal_uInt16 nPrfx,
2696 const OUString& sLocalName) :
2697 XMLTextFieldImportContext(rImport, rHlp, sAPI_macro,
2698 nPrfx, sLocalName),
2699 sPropertyHint(sAPI_hint),
2700 sPropertyMacroName("MacroName"),
2701 sPropertyScriptURL("ScriptURL"),
2702 bDescriptionOK(false)
2706 SvXMLImportContext* XMLMacroFieldImportContext::CreateChildContext(
2707 sal_uInt16 nPrefix,
2708 const OUString& rLocalName,
2709 const Reference<XAttributeList> & xAttrList )
2711 SvXMLImportContext* pContext = NULL;
2713 if ( (nPrefix == XML_NAMESPACE_OFFICE) &&
2714 IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
2716 // create events context and remember it!
2717 pContext = new XMLEventsImportContext(
2718 GetImport(), nPrefix, rLocalName );
2719 xEventContext = pContext;
2720 bValid = true;
2722 else
2723 pContext = SvXMLImportContext::CreateChildContext(
2724 nPrefix, rLocalName, xAttrList);
2726 return pContext;
2730 void XMLMacroFieldImportContext::ProcessAttribute(
2731 sal_uInt16 nAttrToken,
2732 const OUString& sAttrValue )
2734 switch (nAttrToken)
2736 case XML_TOK_TEXTFIELD_DESCRIPTION:
2737 sDescription = sAttrValue;
2738 bDescriptionOK = true;
2739 break;
2740 case XML_TOK_TEXTFIELD_NAME:
2741 sMacro = sAttrValue;
2742 bValid = true;
2743 break;
2747 void XMLMacroFieldImportContext::PrepareField(
2748 const Reference<XPropertySet> & xPropertySet)
2750 Any aAny;
2752 OUString sOnClick("OnClick");
2753 OUString sPropertyMacroLibrary("MacroLibrary");
2755 aAny <<= (bDescriptionOK ? sDescription : GetContent());
2756 xPropertySet->setPropertyValue(sPropertyHint, aAny);
2758 // if we have an events child element, we'll look for the OnClick
2759 // event if not, it may be an old (pre-638i) document. Then, we'll
2760 // have to look at the name attribute.
2761 OUString sMacroName;
2762 OUString sLibraryName;
2763 OUString sScriptURL;
2765 if ( xEventContext.Is() )
2767 // get event sequence
2768 XMLEventsImportContext* pEvents =
2769 static_cast<XMLEventsImportContext*>(&xEventContext);
2770 Sequence<PropertyValue> aValues;
2771 pEvents->GetEventSequence( sOnClick, aValues );
2773 sal_Int32 nLength = aValues.getLength();
2774 for( sal_Int32 i = 0; i < nLength; i++ )
2776 if ( aValues[i].Name == "ScriptType" )
2778 // ignore ScriptType
2780 else if ( aValues[i].Name == "Library" )
2782 aValues[i].Value >>= sLibraryName;
2784 else if ( aValues[i].Name == "MacroName" )
2786 aValues[i].Value >>= sMacroName;
2788 if ( aValues[i].Name == "Script" )
2790 aValues[i].Value >>= sScriptURL;
2794 else
2796 // disassemble old-style macro-name: Everything before the
2797 // third-last dot is the library
2798 sal_Int32 nPos = sMacro.getLength() + 1; // the loop starts with nPos--
2799 const sal_Unicode* pBuf = sMacro.getStr();
2800 for( sal_Int32 i = 0; (i < 3) && (nPos > 0); i++ )
2802 nPos--;
2803 while ( (pBuf[nPos] != '.') && (nPos > 0) )
2804 nPos--;
2807 if (nPos > 0)
2809 sLibraryName = sMacro.copy(0, nPos);
2810 sMacroName = sMacro.copy(nPos+1);
2812 else
2813 sMacroName = sMacro;
2816 aAny <<= sScriptURL;
2817 xPropertySet->setPropertyValue(sPropertyScriptURL, aAny);
2819 aAny <<= sMacroName;
2820 xPropertySet->setPropertyValue(sPropertyMacroName, aAny);
2822 aAny <<= sLibraryName;
2823 xPropertySet->setPropertyValue(sPropertyMacroLibrary, aAny);
2829 // reference field import
2832 TYPEINIT1( XMLReferenceFieldImportContext, XMLTextFieldImportContext );
2834 XMLReferenceFieldImportContext::XMLReferenceFieldImportContext(
2835 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
2836 sal_uInt16 nToken, sal_uInt16 nPrfx, const OUString& sLocalName)
2837 : XMLTextFieldImportContext(rImport, rHlp, sAPI_get_reference, nPrfx, sLocalName)
2838 , sPropertyReferenceFieldPart(sAPI_reference_field_part)
2839 , sPropertyReferenceFieldSource(sAPI_reference_field_source)
2840 , sPropertySourceName(sAPI_source_name)
2841 , sPropertyCurrentPresentation(sAPI_current_presentation)
2842 , nElementToken(nToken)
2843 , nSource(0)
2844 , nType(ReferenceFieldPart::PAGE_DESC)
2845 , bNameOK(false)
2846 , bTypeOK(false)
2850 static SvXMLEnumMapEntry const lcl_aReferenceTypeTokenMap[] =
2852 { XML_PAGE, ReferenceFieldPart::PAGE},
2853 { XML_CHAPTER, ReferenceFieldPart::CHAPTER },
2854 { XML_TEXT, ReferenceFieldPart::TEXT },
2855 { XML_DIRECTION, ReferenceFieldPart::UP_DOWN },
2856 { XML_CATEGORY_AND_VALUE, ReferenceFieldPart::CATEGORY_AND_NUMBER },
2857 { XML_CAPTION, ReferenceFieldPart::ONLY_CAPTION },
2858 { XML_VALUE, ReferenceFieldPart::ONLY_SEQUENCE_NUMBER },
2859 // Core implementation for direct cross-references (#i81002#)
2860 { XML_NUMBER, ReferenceFieldPart::NUMBER },
2861 { XML_NUMBER_NO_SUPERIOR, ReferenceFieldPart::NUMBER_NO_CONTEXT },
2862 { XML_NUMBER_ALL_SUPERIOR, ReferenceFieldPart::NUMBER_FULL_CONTEXT },
2863 { XML_TOKEN_INVALID, 0 }
2866 void XMLReferenceFieldImportContext::StartElement(
2867 const Reference<XAttributeList> & xAttrList)
2869 bTypeOK = true;
2870 switch (nElementToken)
2872 case XML_TOK_TEXT_REFERENCE_REF:
2873 nSource = ReferenceFieldSource::REFERENCE_MARK;
2874 break;
2875 case XML_TOK_TEXT_BOOKMARK_REF:
2876 nSource = ReferenceFieldSource::BOOKMARK;
2877 break;
2878 case XML_TOK_TEXT_NOTE_REF:
2879 nSource = ReferenceFieldSource::FOOTNOTE;
2880 break;
2881 case XML_TOK_TEXT_SEQUENCE_REF:
2882 nSource = ReferenceFieldSource::SEQUENCE_FIELD;
2883 break;
2884 default:
2885 bTypeOK = false;
2886 OSL_FAIL("unknown reference field");
2887 break;
2890 XMLTextFieldImportContext::StartElement(xAttrList);
2894 void XMLReferenceFieldImportContext::ProcessAttribute(
2895 sal_uInt16 nAttrToken,
2896 const OUString& sAttrValue )
2898 switch (nAttrToken)
2900 case XML_TOK_TEXTFIELD_NOTE_CLASS:
2901 if( IsXMLToken( sAttrValue, XML_ENDNOTE ) )
2902 nSource = ReferenceFieldSource::ENDNOTE;
2903 break;
2904 case XML_TOK_TEXTFIELD_REF_NAME:
2905 sName = sAttrValue;
2906 bNameOK = true;
2907 break;
2908 case XML_TOK_TEXTFIELD_REFERENCE_FORMAT:
2910 sal_uInt16 nToken;
2911 if (SvXMLUnitConverter::convertEnum(nToken, sAttrValue,
2912 lcl_aReferenceTypeTokenMap))
2914 nType = nToken;
2917 // check for sequence-only-attributes
2918 if ( (XML_TOK_TEXT_SEQUENCE_REF != nElementToken) &&
2919 ( (nType == ReferenceFieldPart::CATEGORY_AND_NUMBER) ||
2920 (nType == ReferenceFieldPart::ONLY_CAPTION) ||
2921 (nType == ReferenceFieldPart::ONLY_SEQUENCE_NUMBER) ) )
2923 nType = ReferenceFieldPart::PAGE_DESC;
2926 break;
2930 // bValid: we need proper element type and name
2931 bValid = bTypeOK && bNameOK;
2934 void XMLReferenceFieldImportContext::PrepareField(
2935 const Reference<XPropertySet> & xPropertySet)
2937 Any aAny;
2939 aAny <<= nType;
2940 xPropertySet->setPropertyValue(sPropertyReferenceFieldPart, aAny);
2942 aAny <<= nSource;
2943 xPropertySet->setPropertyValue(sPropertyReferenceFieldSource, aAny);
2945 switch (nElementToken)
2947 case XML_TOK_TEXT_REFERENCE_REF:
2948 case XML_TOK_TEXT_BOOKMARK_REF:
2949 aAny <<= sName;
2950 xPropertySet->setPropertyValue(sPropertySourceName, aAny);
2951 break;
2953 case XML_TOK_TEXT_NOTE_REF:
2954 GetImportHelper().ProcessFootnoteReference(sName, xPropertySet);
2955 break;
2957 case XML_TOK_TEXT_SEQUENCE_REF:
2958 GetImportHelper().ProcessSequenceReference(sName, xPropertySet);
2959 break;
2962 aAny <<= GetContent();
2963 xPropertySet->setPropertyValue(sPropertyCurrentPresentation, aAny);
2969 // field declarations container
2972 enum DdeFieldDeclAttrs
2974 XML_TOK_DDEFIELD_NAME,
2975 XML_TOK_DDEFIELD_APPLICATION,
2976 XML_TOK_DDEFIELD_TOPIC,
2977 XML_TOK_DDEFIELD_ITEM,
2978 XML_TOK_DDEFIELD_UPDATE
2981 static const SvXMLTokenMapEntry aDdeDeclAttrTokenMap[] =
2983 { XML_NAMESPACE_OFFICE, XML_NAME, XML_TOK_DDEFIELD_NAME },
2984 { XML_NAMESPACE_OFFICE, XML_DDE_APPLICATION, XML_TOK_DDEFIELD_APPLICATION },
2985 { XML_NAMESPACE_OFFICE, XML_DDE_TOPIC, XML_TOK_DDEFIELD_TOPIC },
2986 { XML_NAMESPACE_OFFICE, XML_DDE_ITEM, XML_TOK_DDEFIELD_ITEM },
2987 { XML_NAMESPACE_OFFICE, XML_AUTOMATIC_UPDATE, XML_TOK_DDEFIELD_UPDATE },
2988 XML_TOKEN_MAP_END
2991 TYPEINIT1( XMLDdeFieldDeclsImportContext, SvXMLImportContext );
2993 XMLDdeFieldDeclsImportContext::XMLDdeFieldDeclsImportContext(
2994 SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& sLocalName) :
2995 SvXMLImportContext(rImport, nPrfx, sLocalName),
2996 aTokenMap(aDdeDeclAttrTokenMap)
3000 SvXMLImportContext * XMLDdeFieldDeclsImportContext::CreateChildContext(
3001 sal_uInt16 nPrefix,
3002 const OUString& rLocalName,
3003 const Reference<XAttributeList> & xAttrList )
3005 if ( (XML_NAMESPACE_TEXT == nPrefix) &&
3006 (IsXMLToken(rLocalName, XML_DDE_CONNECTION_DECL)) )
3008 return new XMLDdeFieldDeclImportContext(GetImport(), nPrefix,
3009 rLocalName, aTokenMap);
3011 else
3013 return SvXMLImportContext::CreateChildContext(nPrefix,
3014 rLocalName,
3015 xAttrList);
3022 // import dde field declaration
3025 TYPEINIT1( XMLDdeFieldDeclImportContext, SvXMLImportContext );
3027 XMLDdeFieldDeclImportContext::XMLDdeFieldDeclImportContext(
3028 SvXMLImport& rImport, sal_uInt16 nPrfx,
3029 const OUString& sLocalName, const SvXMLTokenMap& rMap)
3030 : SvXMLImportContext(rImport, nPrfx, sLocalName)
3031 , sPropertyIsAutomaticUpdate(sAPI_is_automatic_update)
3032 , sPropertyName(sAPI_name)
3033 , sPropertyDDECommandType(sAPI_dde_command_type)
3034 , sPropertyDDECommandFile(sAPI_dde_command_file)
3035 , sPropertyDDECommandElement(sAPI_dde_command_element)
3036 , rTokenMap(rMap)
3038 DBG_ASSERT(XML_NAMESPACE_TEXT == nPrfx, "wrong prefix");
3039 DBG_ASSERT(IsXMLToken(sLocalName, XML_DDE_CONNECTION_DECL), "wrong name");
3042 void XMLDdeFieldDeclImportContext::StartElement(
3043 const Reference<XAttributeList> & xAttrList)
3045 OUString sName;
3046 OUString sCommandApplication;
3047 OUString sCommandTopic;
3048 OUString sCommandItem;
3050 sal_Bool bUpdate = sal_False;
3051 bool bNameOK = false;
3052 bool bCommandApplicationOK = false;
3053 bool bCommandTopicOK = false;
3054 bool bCommandItemOK = false;
3056 // process attributes
3057 sal_Int16 nLength = xAttrList->getLength();
3058 for(sal_Int16 i=0; i<nLength; i++)
3061 OUString sLocalName;
3062 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
3063 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
3065 switch (rTokenMap.Get(nPrefix, sLocalName))
3067 case XML_TOK_DDEFIELD_NAME:
3068 sName = xAttrList->getValueByIndex(i);
3069 bNameOK = true;
3070 break;
3071 case XML_TOK_DDEFIELD_APPLICATION:
3072 sCommandApplication = xAttrList->getValueByIndex(i);
3073 bCommandApplicationOK = true;
3074 break;
3075 case XML_TOK_DDEFIELD_TOPIC:
3076 sCommandTopic = xAttrList->getValueByIndex(i);
3077 bCommandTopicOK = true;
3078 break;
3079 case XML_TOK_DDEFIELD_ITEM:
3080 sCommandItem = xAttrList->getValueByIndex(i);
3081 bCommandItemOK = true;
3082 break;
3083 case XML_TOK_DDEFIELD_UPDATE:
3085 bool bTmp(false);
3086 if (::sax::Converter::convertBool(
3087 bTmp, xAttrList->getValueByIndex(i)) )
3089 bUpdate = bTmp;
3091 break;
3096 // valid data?
3097 if (bNameOK && bCommandApplicationOK && bCommandTopicOK && bCommandItemOK)
3099 // make service name
3100 OUStringBuffer sBuf;
3101 sBuf.appendAscii(sAPI_fieldmaster_prefix);
3102 sBuf.appendAscii(sAPI_dde);
3104 // create DDE TextFieldMaster
3105 Reference<XMultiServiceFactory> xFactory(GetImport().GetModel(),
3106 UNO_QUERY);
3107 if( xFactory.is() )
3109 /* #i6432# There might be multiple occurrences of one DDE
3110 declaration if it is used in more than one of
3111 header/footer/body. createInstance will throw an exception if we
3112 try to create the second, third, etc. instance of such a
3113 declaration. Thus we ignore the exception. Otherwise this will
3114 lead to an unloadable document. */
3117 Reference<XInterface> xIfc =
3118 xFactory->createInstance(sBuf.makeStringAndClear());
3119 if( xIfc.is() )
3121 Reference<XPropertySet> xPropSet( xIfc, UNO_QUERY );
3122 if (xPropSet.is() &&
3123 xPropSet->getPropertySetInfo()->hasPropertyByName(
3124 sPropertyDDECommandType))
3126 Any aAny;
3128 aAny <<= sName;
3129 xPropSet->setPropertyValue(sPropertyName, aAny);
3131 aAny <<= sCommandApplication;
3132 xPropSet->setPropertyValue(sPropertyDDECommandType, aAny);
3134 aAny <<= sCommandTopic;
3135 xPropSet->setPropertyValue(sPropertyDDECommandFile, aAny);
3137 aAny <<= sCommandItem;
3138 xPropSet->setPropertyValue(sPropertyDDECommandElement,
3139 aAny);
3141 aAny.setValue(&bUpdate, cppu::UnoType<bool>::get());
3142 xPropSet->setPropertyValue(sPropertyIsAutomaticUpdate,
3143 aAny);
3145 // else: ignore (can't get XPropertySet, or DDE
3146 // properties are not supported)
3148 // else: ignore
3150 catch (const Exception&)
3152 //ignore
3155 // else: ignore
3157 // else: ignore
3163 // DDE field import
3166 TYPEINIT1( XMLDdeFieldImportContext, XMLTextFieldImportContext );
3168 XMLDdeFieldImportContext::XMLDdeFieldImportContext(
3169 SvXMLImport& rImport, XMLTextImportHelper& rHlp,
3170 sal_uInt16 nPrfx, const OUString& sLocalName) :
3171 XMLTextFieldImportContext(rImport, rHlp, sAPI_dde,
3172 nPrfx, sLocalName),
3173 sName()
3174 ,sPropertyContent(sAPI_content)
3178 void XMLDdeFieldImportContext::ProcessAttribute(
3179 sal_uInt16 nAttrToken,
3180 const OUString& sAttrValue )
3182 if (XML_TOK_TEXTFIELD_CONNECTION_NAME == nAttrToken)
3184 sName = sAttrValue;
3185 bValid = true;
3189 void XMLDdeFieldImportContext::EndElement()
3191 if (bValid)
3193 // find master
3194 OUStringBuffer sBuf;
3195 sBuf.appendAscii(sAPI_fieldmaster_prefix);
3196 sBuf.appendAscii(sAPI_dde);
3197 sBuf.append('.');
3198 sBuf.append(sName);
3199 OUString sMasterName = sBuf.makeStringAndClear();
3201 Reference<XTextFieldsSupplier> xTextFieldsSupp(GetImport().GetModel(),
3202 UNO_QUERY);
3203 Reference<container::XNameAccess> xFieldMasterNameAccess(
3204 xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY);
3206 if (xFieldMasterNameAccess->hasByName(sMasterName))
3208 Reference<XPropertySet> xMaster;
3209 Any aAny = xFieldMasterNameAccess->getByName(sMasterName);
3210 aAny >>= xMaster;
3211 //apply the content to the master
3212 xMaster->setPropertyValue( sPropertyContent, uno::makeAny( GetContent()));
3213 // master exists: create text field and attach
3214 Reference<XPropertySet> xField;
3215 sBuf.appendAscii(sAPI_textfield_prefix);
3216 sBuf.appendAscii(sAPI_dde);
3217 if (CreateField(xField, sBuf.makeStringAndClear()))
3219 Reference<XDependentTextField> xDepTextField(xField,UNO_QUERY);
3220 xDepTextField->attachTextFieldMaster(xMaster);
3222 // attach field to document
3223 Reference<XTextContent> xTextContent(xField, UNO_QUERY);
3224 if (xTextContent.is())
3226 GetImportHelper().InsertTextContent(xTextContent);
3228 // we're lucky. nothing else to prepare.
3230 // else: fail, because text content could not be created
3232 // else: fail, because field could not be created
3234 // else: fail, because no master was found (faulty document?!)
3236 // not valid: ignore
3239 void XMLDdeFieldImportContext::PrepareField(
3240 const Reference<XPropertySet> &)
3242 // empty, since not needed.
3247 // sheet name fields
3250 TYPEINIT1(XMLSheetNameImportContext, XMLTextFieldImportContext);
3252 XMLSheetNameImportContext::XMLSheetNameImportContext(
3253 SvXMLImport& rImport,
3254 XMLTextImportHelper& rHlp,
3255 sal_uInt16 nPrfx,
3256 const OUString& sLocalName) :
3257 XMLTextFieldImportContext(rImport, rHlp, sAPI_sheet_name,
3258 nPrfx, sLocalName)
3260 bValid = true; // always valid!
3263 void XMLSheetNameImportContext::ProcessAttribute(
3264 sal_uInt16,
3265 const OUString& )
3267 // no attributes -> nothing to be done
3270 void XMLSheetNameImportContext::PrepareField(
3271 const Reference<XPropertySet> &)
3273 // no attributes -> nothing to be done
3276 /** import page|slide name fields (<text:page-name>) */
3277 TYPEINIT1( XMLPageNameFieldImportContext, XMLTextFieldImportContext );
3279 XMLPageNameFieldImportContext::XMLPageNameFieldImportContext(
3280 SvXMLImport& rImport, /// XML Import
3281 XMLTextImportHelper& rHlp, /// Text import helper
3282 sal_uInt16 nPrfx, /// namespace prefix
3283 const OUString& sLocalName) /// element name w/o prefix
3284 : XMLTextFieldImportContext(rImport, rHlp, sAPI_pagename, nPrfx, sLocalName )
3286 bValid = true;
3289 /// process attribute values
3290 void XMLPageNameFieldImportContext::ProcessAttribute( sal_uInt16,
3291 const OUString& )
3295 /// prepare XTextField for insertion into document
3296 void XMLPageNameFieldImportContext::PrepareField(
3297 const ::com::sun::star::uno::Reference<
3298 ::com::sun::star::beans::XPropertySet> &)
3303 // URL fields (Calc, Impress, Draw)
3306 TYPEINIT1(XMLUrlFieldImportContext, XMLTextFieldImportContext);
3308 XMLUrlFieldImportContext::XMLUrlFieldImportContext(
3309 SvXMLImport& rImport,
3310 XMLTextImportHelper& rHlp,
3311 sal_uInt16 nPrfx,
3312 const OUString& sLocalName) :
3313 XMLTextFieldImportContext(rImport, rHlp, sAPI_url,
3314 nPrfx, sLocalName),
3315 sPropertyURL(sAPI_url),
3316 sPropertyTargetFrame(sAPI_target_frame),
3317 sPropertyRepresentation(
3318 sAPI_representation),
3319 bFrameOK(false)
3323 void XMLUrlFieldImportContext::ProcessAttribute(
3324 sal_uInt16 nAttrToken,
3325 const OUString& sAttrValue )
3327 switch (nAttrToken)
3329 case XML_TOK_TEXTFIELD_HREF:
3330 sURL = GetImport().GetAbsoluteReference( sAttrValue );
3331 bValid = true;
3332 break;
3333 case XML_TOK_TEXTFIELD_TARGET_FRAME:
3334 sFrame = sAttrValue;
3335 bFrameOK = true;
3336 break;
3337 default:
3338 // ignore
3339 break;
3343 void XMLUrlFieldImportContext::PrepareField(
3344 const Reference<XPropertySet> & xPropertySet)
3346 Any aAny;
3348 aAny <<= sURL;
3349 xPropertySet->setPropertyValue(sPropertyURL, aAny);
3351 if (bFrameOK)
3353 aAny <<= sFrame;
3354 xPropertySet->setPropertyValue(sPropertyTargetFrame, aAny);
3357 aAny <<= GetContent();
3358 xPropertySet->setPropertyValue(sPropertyRepresentation, aAny);
3362 TYPEINIT1(XMLBibliographyFieldImportContext, XMLTextFieldImportContext);
3365 XMLBibliographyFieldImportContext::XMLBibliographyFieldImportContext(
3366 SvXMLImport& rImport,
3367 XMLTextImportHelper& rHlp,
3368 sal_uInt16 nPrfx,
3369 const OUString& sLocalName) :
3370 XMLTextFieldImportContext(rImport, rHlp, sAPI_bibliography,
3371 nPrfx, sLocalName),
3372 sPropertyFields("Fields"),
3373 aValues()
3375 bValid = true;
3378 // TODO: this is the same map as is used in the text field export
3379 static SvXMLEnumMapEntry const aBibliographyDataTypeMap[] =
3381 { XML_ARTICLE, BibliographyDataType::ARTICLE },
3382 { XML_BOOK, BibliographyDataType::BOOK },
3383 { XML_BOOKLET, BibliographyDataType::BOOKLET },
3384 { XML_CONFERENCE, BibliographyDataType::CONFERENCE },
3385 { XML_CUSTOM1, BibliographyDataType::CUSTOM1 },
3386 { XML_CUSTOM2, BibliographyDataType::CUSTOM2 },
3387 { XML_CUSTOM3, BibliographyDataType::CUSTOM3 },
3388 { XML_CUSTOM4, BibliographyDataType::CUSTOM4 },
3389 { XML_CUSTOM5, BibliographyDataType::CUSTOM5 },
3390 { XML_EMAIL, BibliographyDataType::EMAIL },
3391 { XML_INBOOK, BibliographyDataType::INBOOK },
3392 { XML_INCOLLECTION, BibliographyDataType::INCOLLECTION },
3393 { XML_INPROCEEDINGS, BibliographyDataType::INPROCEEDINGS },
3394 { XML_JOURNAL, BibliographyDataType::JOURNAL },
3395 { XML_MANUAL, BibliographyDataType::MANUAL },
3396 { XML_MASTERSTHESIS, BibliographyDataType::MASTERSTHESIS },
3397 { XML_MISC, BibliographyDataType::MISC },
3398 { XML_PHDTHESIS, BibliographyDataType::PHDTHESIS },
3399 { XML_PROCEEDINGS, BibliographyDataType::PROCEEDINGS },
3400 { XML_TECHREPORT, BibliographyDataType::TECHREPORT },
3401 { XML_UNPUBLISHED, BibliographyDataType::UNPUBLISHED },
3402 { XML_WWW, BibliographyDataType::WWW },
3403 { XML_TOKEN_INVALID, 0 }
3407 // we'll process attributes on our own and forfit the standard
3408 // tecfield mechanism, because our attributes have zero overlp with
3409 // all the oher textfields.
3410 void XMLBibliographyFieldImportContext::StartElement(
3411 const Reference<XAttributeList> & xAttrList)
3413 // iterate over attributes
3414 sal_Int16 nLength = xAttrList->getLength();
3415 for(sal_Int16 i=0; i<nLength; i++) {
3417 OUString sLocalName;
3418 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
3419 GetKeyByAttrName( xAttrList->getNameByIndex(i), &sLocalName );
3421 if (nPrefix == XML_NAMESPACE_TEXT)
3423 PropertyValue aValue;
3424 aValue.Name = OUString::createFromAscii(
3425 MapBibliographyFieldName(sLocalName));
3426 Any aAny;
3428 // special treatment for bibliography type
3429 // biblio vs bibilio: #96658#; also read old documents
3430 if (IsXMLToken(sLocalName, XML_BIBILIOGRAPHIC_TYPE) ||
3431 IsXMLToken(sLocalName, XML_BIBLIOGRAPHY_TYPE) )
3433 sal_uInt16 nTmp;
3434 if (SvXMLUnitConverter::convertEnum(
3435 nTmp, xAttrList->getValueByIndex(i),
3436 aBibliographyDataTypeMap))
3438 aAny <<= (sal_Int16)nTmp;
3439 aValue.Value = aAny;
3441 aValues.push_back(aValue);
3444 else
3446 aAny <<= xAttrList->getValueByIndex(i);
3447 aValue.Value = aAny;
3449 aValues.push_back(aValue);
3452 // else: unknown namespace -> ignore
3456 void XMLBibliographyFieldImportContext::ProcessAttribute(
3457 sal_uInt16,
3458 const OUString& )
3460 // attributes are handled in StartElement
3461 OSL_FAIL("This should not have happened.");
3465 void XMLBibliographyFieldImportContext::PrepareField(
3466 const Reference<XPropertySet> & xPropertySet)
3468 // convert vector into sequence
3469 sal_Int32 nCount = aValues.size();
3470 Sequence<PropertyValue> aValueSequence(nCount);
3471 for(sal_Int32 i = 0; i < nCount; i++)
3473 aValueSequence[i] = aValues[i];
3476 // set sequence
3477 Any aAny;
3478 aAny <<= aValueSequence;
3479 xPropertySet->setPropertyValue(sPropertyFields, aAny);
3482 const sal_Char* XMLBibliographyFieldImportContext::MapBibliographyFieldName(
3483 const OUString& sName)
3485 const sal_Char* pName = NULL;
3487 if (IsXMLToken(sName, XML_IDENTIFIER))
3489 pName = "Identifier";
3491 else if (IsXMLToken(sName, XML_BIBILIOGRAPHIC_TYPE) ||
3492 IsXMLToken(sName, XML_BIBLIOGRAPHY_TYPE) )
3494 // biblio... vs bibilio...: #96658#: also read old documents
3495 pName = "BibiliographicType";
3497 else if (IsXMLToken(sName, XML_ADDRESS))
3499 pName = "Address";
3501 else if (IsXMLToken(sName, XML_ANNOTE))
3503 pName = "Annote";
3505 else if (IsXMLToken(sName, XML_AUTHOR))
3507 pName = "Author";
3509 else if (IsXMLToken(sName, XML_BOOKTITLE))
3511 pName = "Booktitle";
3513 else if (IsXMLToken(sName, XML_CHAPTER))
3515 pName = "Chapter";
3517 else if (IsXMLToken(sName, XML_EDITION))
3519 pName = "Edition";
3521 else if (IsXMLToken(sName, XML_EDITOR))
3523 pName = "Editor";
3525 else if (IsXMLToken(sName, XML_HOWPUBLISHED))
3527 pName = "Howpublished";
3529 else if (IsXMLToken(sName, XML_INSTITUTION))
3531 pName = "Institution";
3533 else if (IsXMLToken(sName, XML_JOURNAL))
3535 pName = "Journal";
3537 else if (IsXMLToken(sName, XML_MONTH))
3539 pName = "Month";
3541 else if (IsXMLToken(sName, XML_NOTE))
3543 pName = "Note";
3545 else if (IsXMLToken(sName, XML_NUMBER))
3547 pName = "Number";
3549 else if (IsXMLToken(sName, XML_ORGANIZATIONS))
3551 pName = "Organizations";
3553 else if (IsXMLToken(sName, XML_PAGES))
3555 pName = "Pages";
3557 else if (IsXMLToken(sName, XML_PUBLISHER))
3559 pName = "Publisher";
3561 else if (IsXMLToken(sName, XML_SCHOOL))
3563 pName = "School";
3565 else if (IsXMLToken(sName, XML_SERIES))
3567 pName = "Series";
3569 else if (IsXMLToken(sName, XML_TITLE))
3571 pName = "Title";
3573 else if (IsXMLToken(sName, XML_REPORT_TYPE))
3575 pName = "Report_Type";
3577 else if (IsXMLToken(sName, XML_VOLUME))
3579 pName = "Volume";
3581 else if (IsXMLToken(sName, XML_YEAR))
3583 pName = "Year";
3585 else if (IsXMLToken(sName, XML_URL))
3587 pName = "URL";
3589 else if (IsXMLToken(sName, XML_CUSTOM1))
3591 pName = "Custom1";
3593 else if (IsXMLToken(sName, XML_CUSTOM2))
3595 pName = "Custom2";
3597 else if (IsXMLToken(sName, XML_CUSTOM3))
3599 pName = "Custom3";
3601 else if (IsXMLToken(sName, XML_CUSTOM4))
3603 pName = "Custom4";
3605 else if (IsXMLToken(sName, XML_CUSTOM5))
3607 pName = "Custom5";
3609 else if (IsXMLToken(sName, XML_ISBN))
3611 pName = "ISBN";
3613 else
3615 OSL_FAIL("Unknown bibliography info data");
3616 pName = NULL;
3619 return pName;
3624 // Annotation Field
3627 TYPEINIT1(XMLAnnotationImportContext, XMLTextFieldImportContext);
3629 XMLAnnotationImportContext::XMLAnnotationImportContext(
3630 SvXMLImport& rImport,
3631 XMLTextImportHelper& rHlp,
3632 sal_uInt16 nToken,
3633 sal_uInt16 nPrfx,
3634 const OUString& sLocalName) :
3635 XMLTextFieldImportContext(rImport, rHlp, sAPI_annotation,
3636 nPrfx, sLocalName),
3637 sPropertyAuthor(sAPI_author),
3638 sPropertyInitials(sAPI_initials),
3639 sPropertyContent(sAPI_content),
3640 // why is there no UNO_NAME_DATE_TIME, but only UNO_NAME_DATE_TIME_VALUE?
3641 sPropertyDate(sAPI_date_time_value),
3642 sPropertyTextRange(sAPI_TextRange),
3643 sPropertyName(sAPI_name),
3644 m_nToken(nToken)
3646 bValid = true;
3648 // remember old list item and block (#91964#) and reset them
3649 // for the text frame
3650 // do this in the constructor, not in CreateChildContext (#i93392#)
3651 GetImport().GetTextImport()->PushListContext();
3654 void XMLAnnotationImportContext::ProcessAttribute(
3655 sal_uInt16 nToken,
3656 const OUString& rValue )
3658 if (nToken == XML_TOK_TEXT_NAME)
3659 aName = rValue;
3662 SvXMLImportContext* XMLAnnotationImportContext::CreateChildContext(
3663 sal_uInt16 nPrefix,
3664 const OUString& rLocalName,
3665 const Reference<XAttributeList >& xAttrList )
3667 SvXMLImportContext *pContext = 0;
3668 if( XML_NAMESPACE_DC == nPrefix )
3670 if( IsXMLToken( rLocalName, XML_CREATOR ) )
3671 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,
3672 rLocalName, aAuthorBuffer);
3673 else if( IsXMLToken( rLocalName, XML_DATE ) )
3674 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,
3675 rLocalName, aDateBuffer);
3677 else if( XML_NAMESPACE_TEXT == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
3679 if( IsXMLToken( rLocalName, XML_SENDER_INITIALS ) )
3680 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix,
3681 rLocalName, aInitialsBuffer);
3684 if( !pContext )
3688 bool bOK = true;
3689 if ( !mxField.is() )
3690 bOK = CreateField( mxField, sServicePrefix + GetServiceName() );
3691 if (bOK)
3693 Any aAny = mxField->getPropertyValue( sPropertyTextRange );
3694 Reference< XText > xText;
3695 aAny >>= xText;
3696 if( xText.is() )
3698 rtl::Reference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport();
3699 if( !mxCursor.is() )
3701 mxOldCursor = xTxtImport->GetCursor();
3702 mxCursor = xText->createTextCursor();
3705 if( mxCursor.is() )
3707 xTxtImport->SetCursor( mxCursor );
3708 pContext = xTxtImport->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList );
3713 catch (const Exception&)
3717 if( !pContext )
3718 pContext = new XMLStringBufferImportContext(GetImport(), nPrefix, rLocalName, aTextBuffer);
3721 return pContext;
3724 void XMLAnnotationImportContext::EndElement()
3726 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
3727 if( mxCursor.is() )
3729 // delete addition newline
3730 const OUString aEmpty;
3731 mxCursor->gotoEnd( sal_False );
3732 mxCursor->goLeft( 1, sal_True );
3733 mxCursor->setString( aEmpty );
3735 // reset cursor
3736 GetImport().GetTextImport()->ResetCursor();
3739 if( mxOldCursor.is() )
3740 GetImport().GetTextImport()->SetCursor( mxOldCursor );
3742 // reinstall old list item #91964#
3743 GetImport().GetTextImport()->PopListContext();
3745 if ( bValid )
3747 if ( m_nToken == XML_TOK_TEXT_ANNOTATION_END )
3749 // Search for a previous annotation with the same name.
3750 uno::Reference< text::XTextContent > xPrevField;
3752 Reference<XTextFieldsSupplier> xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY);
3753 uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
3754 uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
3755 while (xFields->hasMoreElements())
3757 uno::Reference<beans::XPropertySet> xCurrField(xFields->nextElement(), uno::UNO_QUERY);
3758 uno::Reference<beans::XPropertySetInfo> const xInfo(
3759 xCurrField->getPropertySetInfo());
3760 if (xInfo->hasPropertyByName(sPropertyName))
3762 OUString aFieldName;
3763 xCurrField->getPropertyValue(sPropertyName) >>= aFieldName;
3764 if (aFieldName == aName)
3766 xPrevField.set( xCurrField, uno::UNO_QUERY );
3767 break;
3772 if ( xPrevField.is() )
3774 // So we are ending a previous annotation,
3775 // let's create a text range covering the old and the current position.
3776 uno::Reference<text::XText> xText = GetImportHelper().GetText();
3777 uno::Reference<text::XTextCursor> xCursor =
3778 xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange());
3779 xCursor->gotoRange(xPrevField->getAnchor(), true);
3780 uno::Reference<text::XTextRange> xTextRange(xCursor, uno::UNO_QUERY);
3782 xText->insertTextContent(xTextRange, xPrevField, !xCursor->isCollapsed());
3785 else
3787 if ( mxField.is() || CreateField( mxField, sServicePrefix + GetServiceName() ) )
3789 // set field properties
3790 PrepareField( mxField );
3792 // attach field to document
3793 Reference < XTextContent > xTextContent( mxField, UNO_QUERY );
3795 // workaround for #80606#
3798 GetImportHelper().InsertTextContent( xTextContent );
3800 catch (const lang::IllegalArgumentException&)
3802 // ignore
3807 else
3808 GetImportHelper().InsertString(GetContent());
3811 void XMLAnnotationImportContext::PrepareField(
3812 const Reference<XPropertySet> & xPropertySet )
3814 // import (possibly empty) author
3815 OUString sAuthor( aAuthorBuffer.makeStringAndClear() );
3816 xPropertySet->setPropertyValue(sPropertyAuthor, makeAny(sAuthor));
3818 // import (possibly empty) initials
3819 OUString sInitials( aInitialsBuffer.makeStringAndClear() );
3820 xPropertySet->setPropertyValue(sPropertyInitials, makeAny(sInitials));
3822 util::DateTime aDateTime;
3823 if (::sax::Converter::parseDateTime(aDateTime, 0,
3824 aDateBuffer.makeStringAndClear()))
3827 Date aDate;
3828 aDate.Year = aDateTime.Year;
3829 aDate.Month = aDateTime.Month;
3830 aDate.Day = aDateTime.Day;
3831 xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDate));
3833 xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDateTime));
3836 OUString sBuffer = aTextBuffer.makeStringAndClear();
3837 if ( sBuffer.getLength() )
3839 // delete last paragraph mark (if necessary)
3840 if (sal_Char(0x0a) == sBuffer[sBuffer.getLength()-1])
3841 sBuffer = sBuffer.copy(0, sBuffer.getLength()-1);
3842 xPropertySet->setPropertyValue(sPropertyContent, makeAny(sBuffer));
3845 if (!aName.isEmpty())
3846 xPropertySet->setPropertyValue(sPropertyName, makeAny(aName));
3852 // script field
3855 TYPEINIT1(XMLScriptImportContext, XMLTextFieldImportContext);
3857 XMLScriptImportContext::XMLScriptImportContext(
3858 SvXMLImport& rImport,
3859 XMLTextImportHelper& rHlp,
3860 sal_uInt16 nPrfx,
3861 const OUString& sLocalName)
3862 : XMLTextFieldImportContext(rImport, rHlp, sAPI_script, nPrfx, sLocalName)
3863 , sPropertyScriptType(sAPI_script_type)
3864 , sPropertyURLContent(sAPI_url_content)
3865 , sPropertyContent(sAPI_content)
3866 , bContentOK(false)
3867 , bScriptTypeOK(false)
3871 void XMLScriptImportContext::ProcessAttribute(
3872 sal_uInt16 nAttrToken,
3873 const OUString& sAttrValue )
3875 switch (nAttrToken)
3877 case XML_TOK_TEXTFIELD_HREF:
3878 sContent = GetImport().GetAbsoluteReference( sAttrValue );
3879 bContentOK = true;
3880 break;
3882 case XML_TOK_TEXTFIELD_LANGUAGE:
3883 sScriptType = sAttrValue;
3884 bScriptTypeOK = true;
3885 break;
3887 default:
3888 // ignore
3889 break;
3892 // always valid (even without ScriptType; cf- #96531#)
3893 bValid = true;
3896 void XMLScriptImportContext::PrepareField(
3897 const Reference<XPropertySet> & xPropertySet)
3899 Any aAny;
3901 // if href attribute was present, we use it. Else we use element content
3902 if (! bContentOK)
3904 sContent = GetContent();
3906 aAny <<= sContent;
3907 xPropertySet->setPropertyValue(sPropertyContent, aAny);
3909 // URL or script text? We use URL if we have an href-attribute
3910 aAny.setValue(&bContentOK, cppu::UnoType<bool>::get());
3911 xPropertySet->setPropertyValue(sPropertyURLContent, aAny);
3913 aAny <<= sScriptType;
3914 xPropertySet->setPropertyValue(sPropertyScriptType, aAny);
3918 // measure field
3921 TYPEINIT1(XMLMeasureFieldImportContext, XMLTextFieldImportContext);
3923 XMLMeasureFieldImportContext::XMLMeasureFieldImportContext(
3924 SvXMLImport& rImport,
3925 XMLTextImportHelper& rHlp,
3926 sal_uInt16 nPrfx,
3927 const OUString& sLocalName) :
3928 XMLTextFieldImportContext(rImport, rHlp, sAPI_measure,
3929 nPrfx, sLocalName),
3930 mnKind( 0 )
3934 void XMLMeasureFieldImportContext::ProcessAttribute(
3935 sal_uInt16 nAttrToken,
3936 const OUString& sAttrValue )
3938 switch (nAttrToken)
3940 case XML_TOK_TEXTFIELD_MEASURE_KIND:
3941 if( IsXMLToken( sAttrValue, XML_VALUE ) )
3943 mnKind = 0; bValid = true;
3945 else if( IsXMLToken( sAttrValue, XML_UNIT ) )
3947 mnKind = 1; bValid = true;
3949 else if( IsXMLToken( sAttrValue, XML_GAP ) )
3951 mnKind = 2; bValid = true;
3953 break;
3957 void XMLMeasureFieldImportContext::PrepareField(
3958 const Reference<XPropertySet> & xPropertySet)
3960 Any aAny;
3961 aAny <<= mnKind;
3962 xPropertySet->setPropertyValue("Kind", aAny);
3968 // dropdown field
3972 TYPEINIT1( XMLDropDownFieldImportContext, XMLTextFieldImportContext );
3974 XMLDropDownFieldImportContext::XMLDropDownFieldImportContext(
3975 SvXMLImport& rImport,
3976 XMLTextImportHelper& rHlp,
3977 sal_uInt16 nPrfx,
3978 const OUString& sLocalName) :
3979 XMLTextFieldImportContext( rImport, rHlp, sAPI_drop_down,
3980 nPrfx, sLocalName ),
3981 aLabels(),
3982 sName(),
3983 nSelected( -1 ),
3984 bNameOK( false ),
3985 bHelpOK(false),
3986 bHintOK(false),
3987 sPropertyItems( "Items" ),
3988 sPropertySelectedItem( "SelectedItem" ),
3989 sPropertyName( "Name" ),
3990 sPropertyHelp( "Help" ),
3991 sPropertyToolTip( "Tooltip" )
3993 bValid = true;
3996 static bool lcl_ProcessLabel( const SvXMLImport& rImport,
3997 const Reference<XAttributeList>& xAttrList,
3998 OUString& rLabel,
3999 bool& rIsSelected )
4001 bool bValid = false;
4002 sal_Int16 nLength = xAttrList->getLength();
4003 for( sal_Int16 n = 0; n < nLength; n++ )
4005 OUString sLocalName;
4006 sal_uInt16 nPrefix = rImport.GetNamespaceMap().
4007 GetKeyByAttrName( xAttrList->getNameByIndex(n), &sLocalName );
4008 OUString sValue = xAttrList->getValueByIndex(n);
4010 if( nPrefix == XML_NAMESPACE_TEXT )
4012 if( IsXMLToken( sLocalName, XML_VALUE ) )
4014 rLabel = sValue;
4015 bValid = true;
4017 else if( IsXMLToken( sLocalName, XML_CURRENT_SELECTED ) )
4019 bool bTmp(false);
4020 if (::sax::Converter::convertBool( bTmp, sValue ))
4021 rIsSelected = bTmp;
4025 return bValid;
4028 SvXMLImportContext* XMLDropDownFieldImportContext::CreateChildContext(
4029 sal_uInt16 nPrefix,
4030 const OUString& rLocalName,
4031 const Reference<XAttributeList>& xAttrList )
4033 if( nPrefix == XML_NAMESPACE_TEXT &&
4034 IsXMLToken( rLocalName, XML_LABEL ) )
4036 OUString sLabel;
4037 bool bIsSelected = false;
4038 if( lcl_ProcessLabel( GetImport(), xAttrList, sLabel, bIsSelected ) )
4040 if( bIsSelected )
4041 nSelected = static_cast<sal_Int32>( aLabels.size() );
4042 aLabels.push_back( sLabel );
4045 return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
4048 void XMLDropDownFieldImportContext::ProcessAttribute(
4049 sal_uInt16 nAttrToken,
4050 const OUString& sAttrValue )
4052 if( nAttrToken == XML_TOK_TEXTFIELD_NAME )
4054 sName = sAttrValue;
4055 bNameOK = true;
4057 else if (nAttrToken == XML_TOK_TEXTFIELD_HELP)
4059 sHelp = sAttrValue;
4060 bHelpOK = true;
4062 else if (nAttrToken == XML_TOK_TEXTFIELD_HINT)
4064 sHint = sAttrValue;
4065 bHintOK = true;
4069 void XMLDropDownFieldImportContext::PrepareField(
4070 const Reference<XPropertySet>& xPropertySet)
4072 // create sequence
4073 sal_Int32 nLength = static_cast<sal_Int32>( aLabels.size() );
4074 Sequence<OUString> aSequence( nLength );
4075 OUString* pSequence = aSequence.getArray();
4076 for( sal_Int32 n = 0; n < nLength; n++ )
4077 pSequence[n] = aLabels[n];
4079 // now set values:
4080 Any aAny;
4082 aAny <<= aSequence;
4083 xPropertySet->setPropertyValue( sPropertyItems, aAny );
4085 if( nSelected >= 0 && nSelected < nLength )
4087 aAny <<= pSequence[nSelected];
4088 xPropertySet->setPropertyValue( sPropertySelectedItem, aAny );
4091 // set name
4092 if( bNameOK )
4094 aAny <<= sName;
4095 xPropertySet->setPropertyValue( sPropertyName, aAny );
4097 // set help
4098 if( bHelpOK )
4100 aAny <<= sHelp;
4101 xPropertySet->setPropertyValue( sPropertyHelp, aAny );
4103 // set hint
4104 if( bHintOK )
4106 aAny <<= sHint;
4107 xPropertySet->setPropertyValue( sPropertyToolTip, aAny );
4112 /** import header fields (<draw:header>) */
4113 TYPEINIT1( XMLHeaderFieldImportContext, XMLTextFieldImportContext );
4115 XMLHeaderFieldImportContext::XMLHeaderFieldImportContext(
4116 SvXMLImport& rImport, /// XML Import
4117 XMLTextImportHelper& rHlp, /// Text import helper
4118 sal_uInt16 nPrfx, /// namespace prefix
4119 const OUString& sLocalName) /// element name w/o prefix
4120 : XMLTextFieldImportContext(rImport, rHlp, sAPI_header, nPrfx, sLocalName )
4122 sServicePrefix = sAPI_presentation_prefix;
4123 bValid = true;
4126 /// process attribute values
4127 void XMLHeaderFieldImportContext::ProcessAttribute( sal_uInt16, const OUString& )
4131 /// prepare XTextField for insertion into document
4132 void XMLHeaderFieldImportContext::PrepareField(const Reference<XPropertySet> &)
4136 /** import footer fields (<draw:footer>) */
4137 TYPEINIT1( XMLFooterFieldImportContext, XMLTextFieldImportContext );
4139 XMLFooterFieldImportContext::XMLFooterFieldImportContext(
4140 SvXMLImport& rImport, /// XML Import
4141 XMLTextImportHelper& rHlp, /// Text import helper
4142 sal_uInt16 nPrfx, /// namespace prefix
4143 const OUString& sLocalName) /// element name w/o prefix
4144 : XMLTextFieldImportContext(rImport, rHlp, sAPI_footer, nPrfx, sLocalName )
4146 sServicePrefix = sAPI_presentation_prefix;
4147 bValid = true;
4150 /// process attribute values
4151 void XMLFooterFieldImportContext::ProcessAttribute( sal_uInt16, const OUString& )
4155 /// prepare XTextField for insertion into document
4156 void XMLFooterFieldImportContext::PrepareField(const Reference<XPropertySet> &)
4161 /** import footer fields (<draw:date-and-time>) */
4162 TYPEINIT1( XMLDateTimeFieldImportContext, XMLTextFieldImportContext );
4164 XMLDateTimeFieldImportContext::XMLDateTimeFieldImportContext(
4165 SvXMLImport& rImport, /// XML Import
4166 XMLTextImportHelper& rHlp, /// Text import helper
4167 sal_uInt16 nPrfx, /// namespace prefix
4168 const OUString& sLocalName) /// element name w/o prefix
4169 : XMLTextFieldImportContext(rImport, rHlp, sAPI_datetime, nPrfx, sLocalName )
4171 sServicePrefix = sAPI_presentation_prefix;
4172 bValid = true;
4175 /// process attribute values
4176 void XMLDateTimeFieldImportContext::ProcessAttribute( sal_uInt16,
4177 const OUString& )
4181 /// prepare XTextField for insertion into document
4182 void XMLDateTimeFieldImportContext::PrepareField(
4183 const ::com::sun::star::uno::Reference<
4184 ::com::sun::star::beans::XPropertySet> &)
4188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */