1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
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";
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
)
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
++) {
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();
241 void XMLTextFieldImportContext::EndElement()
243 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
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
&)
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
);
289 Reference
<XInterface
> xIfc
= xFactory
->createInstance(rServiceName
);
292 Reference
<XPropertySet
> xTmp( xIfc
, UNO_QUERY
);
296 return false; // can't create instance
299 return false; // can't get MultiServiceFactory
305 /// create the appropriate field context from
306 XMLTextFieldImportContext
*
307 XMLTextFieldImportContext::CreateTextFieldImportContext(
308 SvXMLImport
& rImport
,
309 XMLTextImportHelper
& rHlp
,
311 const OUString
& rName
,
314 XMLTextFieldImportContext
* pContext
= NULL
;
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
:
334 new XMLSenderFieldImportContext( rImport
, rHlp
,
335 nPrefix
, rName
, nToken
);
338 case XML_TOK_TEXT_AUTHOR_NAME
:
339 case XML_TOK_TEXT_AUTHOR_INITIALS
:
341 new XMLAuthorFieldImportContext( rImport
, rHlp
,
342 nPrefix
, rName
, nToken
);
345 case XML_TOK_TEXT_PLACEHOLDER
:
347 new XMLPlaceholderFieldImportContext( rImport
, rHlp
,
350 case XML_TOK_TEXT_SEQUENCE
:
352 new XMLSequenceFieldImportContext( rImport
, rHlp
,
355 case XML_TOK_TEXT_TEXT_INPUT
:
357 new XMLTextInputFieldImportContext( rImport
, rHlp
,
360 case XML_TOK_TEXT_EXPRESSION
:
362 new XMLExpressionFieldImportContext( rImport
, rHlp
,
365 case XML_TOK_TEXT_VARIABLE_SET
:
367 new XMLVariableSetFieldImportContext( rImport
, rHlp
,
370 case XML_TOK_TEXT_VARIABLE_INPUT
:
372 new XMLVariableInputFieldImportContext( rImport
, rHlp
,
375 case XML_TOK_TEXT_VARIABLE_GET
:
377 new XMLVariableGetFieldImportContext( rImport
, rHlp
,
380 case XML_TOK_TEXT_USER_FIELD_GET
:
381 pContext
= new XMLUserFieldImportContext( rImport
, rHlp
,
384 case XML_TOK_TEXT_USER_FIELD_INPUT
:
385 pContext
= new XMLUserFieldInputImportContext( rImport
, rHlp
,
388 case XML_TOK_TEXT_TIME
:
389 pContext
= new XMLTimeFieldImportContext( rImport
, rHlp
,
392 case XML_TOK_TEXT_PAGE_CONTINUATION_STRING
:
393 case XML_TOK_TEXT_PAGE_CONTINUATION
:
394 pContext
= new XMLPageContinuationImportContext( rImport
, rHlp
,
398 case XML_TOK_TEXT_PAGE_NUMBER
:
399 pContext
= new XMLPageNumberImportContext( rImport
, rHlp
,
403 case XML_TOK_TEXT_DATE
:
404 pContext
= new XMLDateFieldImportContext( rImport
, rHlp
,
408 case XML_TOK_TEXT_DATABASE_NAME
:
409 pContext
= new XMLDatabaseNameImportContext( rImport
, rHlp
,
412 case XML_TOK_TEXT_DATABASE_NEXT
:
413 pContext
= new XMLDatabaseNextImportContext( rImport
, rHlp
,
416 case XML_TOK_TEXT_DATABASE_SELECT
:
417 pContext
= new XMLDatabaseSelectImportContext( rImport
, rHlp
,
420 case XML_TOK_TEXT_DATABASE_ROW_NUMBER
:
421 pContext
= new XMLDatabaseNumberImportContext( rImport
, rHlp
,
424 case XML_TOK_TEXT_DATABASE_DISPLAY
:
425 pContext
= new XMLDatabaseDisplayImportContext( rImport
, rHlp
,
428 case XML_TOK_TEXT_CONDITIONAL_TEXT
:
429 pContext
= new XMLConditionalTextImportContext( rImport
, rHlp
,
432 case XML_TOK_TEXT_HIDDEN_TEXT
:
433 pContext
= new XMLHiddenTextImportContext( rImport
, rHlp
,
436 case XML_TOK_TEXT_HIDDEN_PARAGRAPH
:
437 pContext
= new XMLHiddenParagraphImportContext( rImport
, rHlp
,
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
,
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
,
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
,
470 case XML_TOK_TEXT_DOCUMENT_REVISION
:
471 pContext
= new XMLRevisionDocInfoImportContext( rImport
, rHlp
,
476 case XML_TOK_TEXT_DOCUMENT_USER_DEFINED
:
477 pContext
= new XMLUserDocInfoImportContext( rImport
, rHlp
,
482 case XML_TOK_TEXT_FILENAME
:
483 pContext
= new XMLFileNameImportContext( rImport
, rHlp
,
487 case XML_TOK_TEXT_CHAPTER
:
488 pContext
= new XMLChapterImportContext( rImport
, rHlp
,
492 case XML_TOK_TEXT_TEMPLATENAME
:
493 pContext
= new XMLTemplateNameImportContext( rImport
, rHlp
,
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
);
508 case XML_TOK_TEXT_GET_PAGE_VAR
:
509 pContext
= new XMLPageVarGetFieldImportContext( rImport
, rHlp
,
513 case XML_TOK_TEXT_SET_PAGE_VAR
:
514 pContext
= new XMLPageVarSetFieldImportContext( rImport
, rHlp
,
518 case XML_TOK_TEXT_MACRO
:
519 pContext
= new XMLMacroFieldImportContext( rImport
, rHlp
,
523 case XML_TOK_TEXT_DDE
:
524 pContext
= new XMLDdeFieldImportContext( rImport
, rHlp
,
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
,
537 case XML_TOK_TEXT_SHEET_NAME
:
538 pContext
= new XMLSheetNameImportContext( rImport
, rHlp
,
542 case XML_TOK_TEXT_PAGE_NAME
:
543 pContext
= new XMLPageNameFieldImportContext( rImport
, rHlp
,
547 case XML_TOK_TEXT_BIBLIOGRAPHY_MARK
:
548 pContext
= new XMLBibliographyFieldImportContext( rImport
, rHlp
,
552 case XML_TOK_TEXT_ANNOTATION
:
553 case XML_TOK_TEXT_ANNOTATION_END
:
554 pContext
= new XMLAnnotationImportContext( rImport
, rHlp
,
559 case XML_TOK_TEXT_SCRIPT
:
560 pContext
= new XMLScriptImportContext( rImport
, rHlp
,
564 case XML_TOK_TEXT_MEASURE
:
565 pContext
= new XMLMeasureFieldImportContext( rImport
, rHlp
,
569 case XML_TOK_TEXT_TABLE_FORMULA
:
570 pContext
= new XMLTableFormulaImportContext( rImport
, rHlp
,
573 case XML_TOK_TEXT_DROP_DOWN
:
574 pContext
= new XMLDropDownFieldImportContext( rImport
, rHlp
,
577 case XML_TOK_DRAW_HEADER
:
578 pContext
= new XMLHeaderFieldImportContext( rImport
, rHlp
,
581 case XML_TOK_DRAW_FOOTER
:
582 pContext
= new XMLFooterFieldImportContext( rImport
, rHlp
,
585 case XML_TOK_DRAW_DATE_TIME
:
586 pContext
= new XMLDateTimeFieldImportContext( rImport
, rHlp
,
591 // ignore! May not even be a textfield.
592 // (Reminder: This method is called inside default:-branch)
601 void XMLTextFieldImportContext::ForceUpdate(
602 const Reference
<XPropertySet
> & rPropertySet
)
605 Reference
<XUpdatable
> xUpdate(rPropertySet
, UNO_QUERY
);
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
,
628 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_extended_user
,nPrfx
, sLocalName
)
630 , sPropertyFixed(sAPI_is_fixed
)
631 , sPropertyFieldSubType(sAPI_user_data_type
)
632 , sPropertyContent(sAPI_content
)
634 , nElementToken(nToken
)
638 void XMLSenderFieldImportContext::StartElement(
639 const Reference
<XAttributeList
> & xAttrList
)
642 switch (nElementToken
) {
643 case XML_TOK_TEXT_SENDER_FIRSTNAME
:
644 nSubType
= UserDataPart::FIRSTNAME
;
646 case XML_TOK_TEXT_SENDER_LASTNAME
:
647 nSubType
= UserDataPart::NAME
;
649 case XML_TOK_TEXT_SENDER_INITIALS
:
650 nSubType
= UserDataPart::SHORTCUT
;
652 case XML_TOK_TEXT_SENDER_TITLE
:
653 nSubType
= UserDataPart::TITLE
;
655 case XML_TOK_TEXT_SENDER_POSITION
:
656 nSubType
= UserDataPart::POSITION
;
658 case XML_TOK_TEXT_SENDER_EMAIL
:
659 nSubType
= UserDataPart::EMAIL
;
661 case XML_TOK_TEXT_SENDER_PHONE_PRIVATE
:
662 nSubType
= UserDataPart::PHONE_PRIVATE
;
664 case XML_TOK_TEXT_SENDER_FAX
:
665 nSubType
= UserDataPart::FAX
;
667 case XML_TOK_TEXT_SENDER_COMPANY
:
668 nSubType
= UserDataPart::COMPANY
;
670 case XML_TOK_TEXT_SENDER_PHONE_WORK
:
671 nSubType
= UserDataPart::PHONE_COMPANY
;
673 case XML_TOK_TEXT_SENDER_STREET
:
674 nSubType
= UserDataPart::STREET
;
676 case XML_TOK_TEXT_SENDER_CITY
:
677 nSubType
= UserDataPart::CITY
;
679 case XML_TOK_TEXT_SENDER_POSTAL_CODE
:
680 nSubType
= UserDataPart::ZIP
;
682 case XML_TOK_TEXT_SENDER_COUNTRY
:
683 nSubType
= UserDataPart::COUNTRY
;
685 case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE
:
686 nSubType
= UserDataPart::STATE
;
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
) {
705 bool const bRet
= ::sax::Converter::convertBool(bVal
, sAttrValue
);
707 // set bFixed if successful
714 void XMLSenderFieldImportContext::PrepareField(
715 const Reference
<XPropertySet
> & rPropSet
)
720 rPropSet
->setPropertyValue(sPropertyFieldSubType
, aAny
);
723 aAny
.setValue( &bFixed
, cppu::UnoType
<bool>::get() );
724 rPropSet
->setPropertyValue(sPropertyFixed
, aAny
);
726 // set content if fixed
729 // in organizer or styles-only mode: force update
730 if (GetImport().GetTextImport()->IsOrganizerMode() ||
731 GetImport().GetTextImport()->IsStylesOnlyMode() )
733 ForceUpdate(rPropSet
);
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
,
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
);
772 // process Attributes
773 XMLTextFieldImportContext::StartElement(xAttrList
);
776 void XMLAuthorFieldImportContext::PrepareField(
777 const Reference
<XPropertySet
> & rPropSet
)
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
790 // organizer or styles-only mode: force update
791 if (GetImport().GetTextImport()->IsOrganizerMode() ||
792 GetImport().GetTextImport()->IsStylesOnlyMode() )
794 ForceUpdate(rPropSet
);
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
)
832 void XMLPageContinuationImportContext::ProcessAttribute(
833 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
837 case XML_TOK_TEXTFIELD_SELECT_PAGE
:
840 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
841 lcl_aSelectPageAttrMap
)
842 && (PageNumberType_CURRENT
!= nTmp
) )
844 eSelectPage
= (PageNumberType
)nTmp
;
848 case XML_TOK_TEXTFIELD_STRING_VALUE
:
849 sString
= sAttrValue
;
855 void XMLPageContinuationImportContext::PrepareField(
856 const Reference
<XPropertySet
> & xPropertySet
)
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
);
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
))
887 , eSelectPage(PageNumberType_CURRENT
)
888 , sNumberFormatOK(false)
893 void XMLPageNumberImportContext::ProcessAttribute(
894 sal_uInt16 nAttrToken
,
895 const OUString
& sAttrValue
)
899 case XML_TOK_TEXTFIELD_NUM_FORMAT
:
900 sNumberFormat
= sAttrValue
;
901 sNumberFormatOK
= true;
903 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC
:
904 sNumberSync
= sAttrValue
;
906 case XML_TOK_TEXTFIELD_SELECT_PAGE
:
909 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
910 lcl_aSelectPageAttrMap
))
912 eSelectPage
= (PageNumberType
)nTmp
;
916 case XML_TOK_TEXTFIELD_PAGE_ADJUST
:
919 if (::sax::Converter::convertNumber(nTmp
, sAttrValue
))
921 nPageAdjust
= (sal_Int16
)nTmp
;
928 void XMLPageNumberImportContext::PrepareField(
929 const Reference
<XPropertySet
> & xPropertySet
)
933 // all properties are optional
934 Reference
<XPropertySetInfo
> xPropertySetInfo(
935 xPropertySet
->getPropertySetInfo());
937 if (xPropertySetInfo
->hasPropertyByName(sPropertyNumberingType
))
940 if( sNumberFormatOK
)
942 nNumType
= style::NumberingType::ARABIC
;
943 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
948 nNumType
= style::NumberingType::PAGE_DESCRIPTOR
;
951 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
954 if (xPropertySetInfo
->hasPropertyByName(sPropertyOffset
))
959 case PageNumberType_PREV
:
962 case PageNumberType_CURRENT
:
964 case PageNumberType_NEXT
:
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
);
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
;
1009 case XML_TOK_TEXTFIELD_PLACEHOLDER_TYPE
:
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
;
1042 void XMLPlaceholderFieldImportContext::PrepareField(
1043 const Reference
<XPropertySet
> & xPropertySet
) {
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("<"))
1058 if (aContent
.endsWith(">"))
1062 aAny
<<= aContent
.copy(nStart
, nLength
);
1063 xPropertySet
->setPropertyValue(sPropertyPlaceholder
, aAny
);
1065 aAny
<<= nPlaceholderType
;
1066 xPropertySet
->setPropertyValue(sPropertyPlaceholderType
, aAny
);
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
)
1093 , bIsDefaultLanguage( true )
1095 bValid
= true; // always valid!
1098 void XMLTimeFieldImportContext::ProcessAttribute(
1099 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
1103 case XML_TOK_TEXTFIELD_TIME_VALUE
:
1105 if (::sax::Converter::parseTimeOrDateTime(aDateTimeValue
, 0,
1112 case XML_TOK_TEXTFIELD_FIXED
:
1115 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
1121 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME
:
1123 sal_Int32 nKey
= GetImportHelper().GetDataStyleKey(
1124 sAttrValue
, &bIsDefaultLanguage
);
1132 case XML_TOK_TEXTFIELD_TIME_ADJUST
:
1136 if (::sax::Converter::convertDuration(fTmp
, sAttrValue
))
1138 // convert to minutes
1139 nAdjust
= (sal_Int32
)::rtl::math::approxFloor(fTmp
* 60 * 24);
1146 void XMLTimeFieldImportContext::PrepareField(
1147 const Reference
<XPropertySet
> & rPropertySet
)
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
))
1167 rPropertySet
->setPropertyValue(sPropertyAdjust
, aAny
);
1173 // organizer or styles-only mode: force update
1174 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1175 GetImport().GetTextImport()->IsStylesOnlyMode() )
1177 ForceUpdate(rPropertySet
);
1181 // normal mode: set value (if present)
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
);
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
);
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
)
1235 case XML_TOK_TEXTFIELD_DATE_VALUE
:
1237 if (::sax::Converter::parseDateTime(aDateTimeValue
, 0, sAttrValue
))
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
,
1249 case XML_TOK_TEXTFIELD_TIME_VALUE
:
1250 case XML_TOK_TEXTFIELD_TIME_ADJUST
:
1251 ; // ignore time-adjust and time-value attributes
1254 // all others: delegate to super-class
1255 XMLTimeFieldImportContext::ProcessAttribute(nAttrToken
,
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)
1283 , bDisplayOK( false )
1284 , bUseDisplay( bUseDisply
)
1285 , bDatabaseOK(false)
1286 , bDatabaseNameOK(false)
1287 , bDatabaseURLOK(false)
1292 void XMLDatabaseFieldImportContext::ProcessAttribute(
1293 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
1297 case XML_TOK_TEXTFIELD_DATABASE_NAME
:
1298 sDatabaseName
= sAttrValue
;
1300 bDatabaseNameOK
= true;
1302 case XML_TOK_TEXTFIELD_TABLE_NAME
:
1303 sTableName
= sAttrValue
;
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;
1323 case XML_TOK_TEXTFIELD_DISPLAY
:
1324 if( IsXMLToken( sAttrValue
, XML_NONE
) )
1329 else if( IsXMLToken( sAttrValue
, XML_VALUE
) )
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
);
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
,
1372 void XMLDatabaseFieldImportContext::PrepareField(
1373 const Reference
<XPropertySet
> & xPropertySet
)
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
),
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
)
1457 , bConditionOK(false)
1461 void XMLDatabaseNextImportContext::ProcessAttribute(
1462 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
1464 if (XML_TOK_TEXTFIELD_CONDITION
== nAttrToken
)
1467 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap()._GetKeyByAttrName(
1468 sAttrValue
, &sTmp
, false );
1469 if( XML_NAMESPACE_OOOW
== nPrefix
)
1472 bConditionOK
= true;
1475 sCondition
= sAttrValue
;
1479 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken
,
1483 bValid
= bDatabaseOK
&& bTableOK
;
1486 void XMLDatabaseNextImportContext::PrepareField(
1487 const Reference
<XPropertySet
> & xPropertySet
)
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
,
1510 sPropertySetNumber(sAPI_set_number
),
1516 void XMLDatabaseSelectImportContext::ProcessAttribute(
1517 sal_uInt16 nAttrToken
,
1518 const OUString
& sAttrValue
)
1520 if (XML_TOK_TEXTFIELD_ROW_NUMBER
== nAttrToken
)
1523 if (::sax::Converter::convertNumber( nTmp
, sAttrValue
1524 /* , nMin, nMax ??? */ ))
1532 XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken
, sAttrValue
);
1535 bValid
= bTableOK
&& bDatabaseOK
&& bNumberOK
;
1538 void XMLDatabaseSelectImportContext::PrepareField(
1539 const Reference
<XPropertySet
> & xPropertySet
)
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
),
1566 sNumberSync(GetXMLToken(XML_FALSE
)),
1572 void XMLDatabaseNumberImportContext::ProcessAttribute(
1573 sal_uInt16 nAttrToken
,
1574 const OUString
& sAttrValue
)
1578 case XML_TOK_TEXTFIELD_NUM_FORMAT
:
1579 sNumberFormat
= sAttrValue
;
1581 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC
:
1582 sNumberSync
= sAttrValue
;
1584 case XML_TOK_TEXTFIELD_VALUE
:
1587 if (::sax::Converter::convertNumber( nTmp
, sAttrValue
))
1595 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken
,
1600 bValid
= bTableOK
&& bDatabaseOK
;
1603 void XMLDatabaseNumberImportContext::PrepareField(
1604 const Reference
<XPropertySet
> & xPropertySet
)
1608 sal_Int16 nNumType
= style::NumberingType::ARABIC
;
1609 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
1613 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
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
)
1642 , bHasAuthor(bAuthor
)
1643 , bHasContent(bContent
)
1648 void XMLSimpleDocInfoImportContext::ProcessAttribute(
1649 sal_uInt16 nAttrToken
,
1650 const OUString
& sAttrValue
)
1652 if (XML_TOK_TEXTFIELD_FIXED
== nAttrToken
)
1655 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
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
))
1670 aAny
.setValue(&bFixed
, cppu::UnoType
<bool>::get() );
1671 rPropertySet
->setPropertyValue(sPropertyFixed
, aAny
);
1673 // set Content and CurrentPresentation (if fixed)
1676 // in organizer-mode or styles-only-mode, only force update
1677 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1678 GetImport().GetTextImport()->IsStylesOnlyMode() )
1680 ForceUpdate(rPropertySet
);
1684 // set content (author, if that's the name) and current
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(
1707 const sal_Char
* pServiceName
= NULL
;
1711 case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR
:
1712 pServiceName
= sAPI_docinfo_create_author
;
1714 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE
:
1715 pServiceName
= sAPI_docinfo_create_date_time
;
1717 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME
:
1718 pServiceName
= sAPI_docinfo_create_date_time
;
1720 case XML_TOK_TEXT_DOCUMENT_DESCRIPTION
:
1721 pServiceName
= sAPI_docinfo_description
;
1723 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION
:
1724 pServiceName
= sAPI_docinfo_edit_time
;
1726 case XML_TOK_TEXT_DOCUMENT_USER_DEFINED
:
1727 pServiceName
= sAPI_docinfo_custom
;
1729 case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR
:
1730 pServiceName
= sAPI_docinfo_print_author
;
1732 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE
:
1733 pServiceName
= sAPI_docinfo_print_date_time
;
1735 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME
:
1736 pServiceName
= sAPI_docinfo_print_date_time
;
1738 case XML_TOK_TEXT_DOCUMENT_KEYWORDS
:
1739 pServiceName
= sAPI_docinfo_keywords
;
1741 case XML_TOK_TEXT_DOCUMENT_SUBJECT
:
1742 pServiceName
= sAPI_docinfo_subject
;
1744 case XML_TOK_TEXT_DOCUMENT_REVISION
:
1745 pServiceName
= sAPI_docinfo_revision
;
1747 case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR
:
1748 pServiceName
= sAPI_docinfo_change_author
;
1750 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE
:
1751 pServiceName
= sAPI_docinfo_change_date_time
;
1753 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME
:
1754 pServiceName
= sAPI_docinfo_change_date_time
;
1756 case XML_TOK_TEXT_DOCUMENT_TITLE
:
1757 pServiceName
= sAPI_docinfo_title
;
1761 OSL_FAIL("no docinfo field token");
1762 pServiceName
= NULL
;
1766 return pServiceName
;
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
)
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
1795 if ( GetImport().GetTextImport()->IsOrganizerMode() ||
1796 GetImport().GetTextImport()->IsStylesOnlyMode() )
1798 ForceUpdate(rPropertySet
);
1803 if (::sax::Converter::convertNumber(nTmp
, GetContent()))
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
)
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!
1841 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE
:
1842 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE
:
1843 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE
:
1845 bHasDateTime
= true;
1847 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME
:
1848 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME
:
1849 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME
:
1851 bHasDateTime
= true;
1853 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION
:
1855 bHasDateTime
= false;
1859 "XMLDateTimeDocInfoImportContext needs date/time doc. fields");
1865 void XMLDateTimeDocInfoImportContext::ProcessAttribute(
1866 sal_uInt16 nAttrToken
,
1867 const OUString
& sAttrValue
)
1871 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME
:
1873 sal_Int32 nKey
= GetImportHelper().GetDataStyleKey(
1874 sAttrValue
, &bIsDefaultLanguage
);
1882 case XML_TOK_TEXTFIELD_FIXED
:
1883 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken
,
1887 // ignore -> we can't set date/time value anyway!
1892 void XMLDateTimeDocInfoImportContext::PrepareField(
1893 const Reference
<XPropertySet
> & xPropertySet
)
1895 // process fixed and presentation
1896 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet
);
1902 aAny
.setValue( &bIsDate
, cppu::UnoType
<bool>::get());
1903 xPropertySet
->setPropertyValue(sPropertyIsDate
, aAny
);
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
,
1936 , sPropertyName(sAPI_name
)
1937 , sPropertyNumberFormat(sAPI_number_format
)
1938 , sPropertyIsFixedLanguage(sAPI_is_fixed_language
)
1941 , bIsDefaultLanguage( true )
1946 void XMLUserDocInfoImportContext::ProcessAttribute(
1947 sal_uInt16 nAttrToken
,
1948 const OUString
& sAttrValue
)
1952 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME
:
1954 sal_Int32 nKey
= GetImportHelper().GetDataStyleKey(
1955 sAttrValue
, &bIsDefaultLanguage
);
1963 case XML_TOK_TEXTFIELD_NAME
:
1967 SetServiceName(OUString(sAPI_docinfo_custom
) );
1975 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken
,
1981 void XMLUserDocInfoImportContext::PrepareField(
1982 const ::com::sun::star::uno::Reference
<
1983 ::com::sun::star::beans::XPropertySet
> & xPropertySet
)
1986 if ( !aName
.isEmpty() )
1989 xPropertySet
->setPropertyValue(sPropertyName
, aAny
);
1991 Reference
<XPropertySetInfo
> xPropertySetInfo(
1992 xPropertySet
->getPropertySetInfo());
1994 xPropertySetInfo
->hasPropertyByName(sPropertyNumberFormat
))
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
,
2023 sPropertyCondition(sAPI_condition
),
2024 sPropertyIsHidden(sAPI_is_hidden
),
2030 void XMLHiddenParagraphImportContext::ProcessAttribute(
2031 sal_uInt16 nAttrToken
,
2032 const OUString
& sAttrValue
)
2034 if (XML_TOK_TEXTFIELD_CONDITION
== nAttrToken
)
2037 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap()._GetKeyByAttrName(
2038 sAttrValue
, &sTmp
, false );
2039 if( XML_NAMESPACE_OOOW
== nPrefix
)
2045 sCondition
= sAttrValue
;
2047 else if (XML_TOK_TEXTFIELD_IS_HIDDEN
== nAttrToken
)
2050 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2057 void XMLHiddenParagraphImportContext::PrepareField(
2058 const Reference
<XPropertySet
> & xPropertySet
)
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
,
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),
2089 bCurrentValue(false)
2093 void XMLConditionalTextImportContext::ProcessAttribute(
2094 sal_uInt16 nAttrToken
,
2095 const OUString
& sAttrValue
)
2099 case XML_TOK_TEXTFIELD_CONDITION
:
2102 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
2103 _GetKeyByAttrName( sAttrValue
, &sTmp
, false );
2104 if( XML_NAMESPACE_OOOW
== nPrefix
)
2107 bConditionOK
= true;
2110 sCondition
= sAttrValue
;
2113 case XML_TOK_TEXTFIELD_STRING_VALUE_IF_FALSE
:
2114 sFalseContent
= sAttrValue
;
2117 case XML_TOK_TEXTFIELD_STRING_VALUE_IF_TRUE
:
2118 sTrueContent
= sAttrValue
;
2121 case XML_TOK_TEXTFIELD_CURRENT_VALUE
:
2124 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2126 bCurrentValue
= bTmp
;
2132 bValid
= bConditionOK
&& bFalseOK
&& bTrueOK
;
2135 void XMLConditionalTextImportContext::PrepareField(
2136 const Reference
<XPropertySet
> & xPropertySet
)
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
);
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
,
2169 sPropertyCondition(sAPI_condition
),
2170 sPropertyContent(sAPI_content
),
2171 sPropertyIsHidden(sAPI_is_hidden
),
2172 bConditionOK(false),
2178 void XMLHiddenTextImportContext::ProcessAttribute(
2179 sal_uInt16 nAttrToken
,
2180 const OUString
& sAttrValue
)
2184 case XML_TOK_TEXTFIELD_CONDITION
:
2187 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
2188 _GetKeyByAttrName( sAttrValue
, &sTmp
, false );
2189 if( XML_NAMESPACE_OOOW
== nPrefix
)
2192 bConditionOK
= true;
2195 sCondition
= sAttrValue
;
2198 case XML_TOK_TEXTFIELD_STRING_VALUE
:
2199 sString
= sAttrValue
;
2202 case XML_TOK_TEXTFIELD_IS_HIDDEN
:
2205 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2213 bValid
= bConditionOK
&& bStringOK
;
2216 void XMLHiddenTextImportContext::PrepareField(
2217 const Reference
<XPropertySet
> & xPropertySet
)
2221 aAny
<<= sCondition
;
2222 xPropertySet
->setPropertyValue(sPropertyCondition
, aAny
);
2225 xPropertySet
->setPropertyValue(sPropertyContent
, aAny
);
2227 aAny
.setValue( &bIsHidden
, cppu::UnoType
<bool>::get() );
2228 xPropertySet
->setPropertyValue(sPropertyIsHidden
, aAny
);
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
,
2253 sPropertyFixed(sAPI_is_fixed
),
2254 sPropertyFileFormat(sAPI_file_format
),
2255 sPropertyCurrentPresentation(
2256 sAPI_current_presentation
),
2257 nFormat(FilenameDisplayFormat::FULL
),
2263 void XMLFileNameImportContext::ProcessAttribute(
2264 sal_uInt16 nAttrToken
,
2265 const OUString
& sAttrValue
)
2269 case XML_TOK_TEXTFIELD_FIXED
:
2272 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2278 case XML_TOK_TEXTFIELD_DISPLAY
:
2281 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
2282 aFilenameDisplayMap
))
2284 nFormat
= (sal_uInt16
)nTmp
;
2289 ; // unknown attribute: ignore
2294 void XMLFileNameImportContext::PrepareField(
2295 const Reference
<XPropertySet
> & xPropertySet
)
2299 // properties are optional
2300 Reference
<XPropertySetInfo
> xPropertySetInfo(
2301 xPropertySet
->getPropertySetInfo());
2303 if (xPropertySetInfo
->hasPropertyByName(sPropertyFixed
))
2306 xPropertySet
->setPropertyValue(sPropertyFixed
, aAny
);
2309 if (xPropertySetInfo
->hasPropertyByName(sPropertyFileFormat
))
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
,
2345 sPropertyFileFormat(sAPI_file_format
),
2346 nFormat(TemplateDisplayFormat::FULL
)
2351 void XMLTemplateNameImportContext::ProcessAttribute(
2352 sal_uInt16 nAttrToken
,
2353 const OUString
& sAttrValue
)
2357 case XML_TOK_TEXTFIELD_DISPLAY
:
2360 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
2361 aTemplateDisplayMap
))
2363 nFormat
= (sal_uInt16
)nTmp
;
2368 ; // unknown attribute: ignore
2373 void XMLTemplateNameImportContext::PrepareField(
2374 const Reference
<XPropertySet
> & xPropertySet
)
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
,
2404 sPropertyChapterFormat(
2405 sAPI_chapter_format
),
2406 sPropertyLevel(sAPI_level
),
2407 nFormat(ChapterFormat::NAME_NUMBER
),
2413 void XMLChapterImportContext::ProcessAttribute(
2414 sal_uInt16 nAttrToken
,
2415 const OUString
& sAttrValue
)
2419 case XML_TOK_TEXTFIELD_DISPLAY
:
2422 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
2423 aChapterDisplayMap
))
2425 nFormat
= (sal_Int16
)nTmp
;
2429 case XML_TOK_TEXTFIELD_OUTLINE_LEVEL
:
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
;
2444 ; // unknown attribute: ignore
2449 void XMLChapterImportContext::PrepareField(
2450 const Reference
<XPropertySet
> & xPropertySet
)
2455 xPropertySet
->setPropertyValue(sPropertyChapterFormat
, aAny
);
2458 xPropertySet
->setPropertyValue(sPropertyLevel
, aAny
);
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
),
2473 sPropertyNumberingType(
2474 sAPI_numbering_type
),
2477 bNumberFormatOK(false)
2482 void XMLCountFieldImportContext::ProcessAttribute(
2483 sal_uInt16 nAttrToken
,
2484 const OUString
& sAttrValue
)
2488 case XML_TOK_TEXTFIELD_NUM_FORMAT
:
2489 sNumberFormat
= sAttrValue
;
2490 bNumberFormatOK
= true;
2492 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC
:
2493 sLetterSync
= sAttrValue
;
2498 void XMLCountFieldImportContext::PrepareField(
2499 const Reference
<XPropertySet
> & xPropertySet
)
2503 // properties optional
2504 // (only page count, but do for all to save common implementation)
2506 if (xPropertySet
->getPropertySetInfo()->
2507 hasPropertyByName(sPropertyNumberingType
))
2510 if( bNumberFormatOK
)
2512 nNumType
= style::NumberingType::ARABIC
;
2513 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
2518 nNumType
= style::NumberingType::PAGE_DESCRIPTOR
;
2520 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
2524 const sal_Char
* XMLCountFieldImportContext::MapTokenToServiceName(
2527 const sal_Char
* pServiceName
= NULL
;
2531 case XML_TOK_TEXT_WORD_COUNT
:
2532 pServiceName
= sAPI_word_count
;
2534 case XML_TOK_TEXT_PARAGRAPH_COUNT
:
2535 pServiceName
= sAPI_paragraph_count
;
2537 case XML_TOK_TEXT_TABLE_COUNT
:
2538 pServiceName
= sAPI_table_count
;
2540 case XML_TOK_TEXT_CHARACTER_COUNT
:
2541 pServiceName
= sAPI_character_count
;
2543 case XML_TOK_TEXT_IMAGE_COUNT
:
2544 pServiceName
= sAPI_graphic_object_count
;
2546 case XML_TOK_TEXT_OBJECT_COUNT
:
2547 pServiceName
= sAPI_embedded_object_count
;
2549 case XML_TOK_TEXT_PAGE_COUNT
:
2550 pServiceName
= sAPI_page_count
;
2553 pServiceName
= NULL
;
2554 OSL_FAIL("unknown count field!");
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
,
2574 sPropertyNumberingType(
2575 sAPI_numbering_type
),
2578 bNumberFormatOK(false)
2583 void XMLPageVarGetFieldImportContext::ProcessAttribute(
2584 sal_uInt16 nAttrToken
,
2585 const OUString
& sAttrValue
)
2589 case XML_TOK_TEXTFIELD_NUM_FORMAT
:
2590 sNumberFormat
= sAttrValue
;
2591 bNumberFormatOK
= true;
2593 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC
:
2594 sLetterSync
= sAttrValue
;
2599 void XMLPageVarGetFieldImportContext::PrepareField(
2600 const Reference
<XPropertySet
> & xPropertySet
)
2605 if( bNumberFormatOK
)
2607 nNumType
= style::NumberingType::ARABIC
;
2608 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
2613 nNumType
= style::NumberingType::PAGE_DESCRIPTOR
;
2615 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
2617 // display old content (#96657#)
2618 aAny
<<= GetContent();
2619 xPropertySet
->setPropertyValue(
2620 OUString(sAPI_current_presentation
),
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
,
2637 sPropertyOn(sAPI_on
),
2638 sPropertyOffset(sAPI_offset
),
2645 void XMLPageVarSetFieldImportContext::ProcessAttribute(
2646 sal_uInt16 nAttrToken
,
2647 const OUString
& sAttrValue
)
2651 case XML_TOK_TEXTFIELD_ACTIVE
:
2654 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2660 case XML_TOK_TEXTFIELD_PAGE_ADJUST
:
2663 if (::sax::Converter::convertNumber(nTmp
, sAttrValue
))
2665 nAdjust
= (sal_Int16
)nTmp
;
2674 void XMLPageVarSetFieldImportContext::PrepareField(
2675 const Reference
<XPropertySet
> & xPropertySet
)
2679 aAny
.setValue(&bActive
, cppu::UnoType
<bool>::get());
2680 xPropertySet
->setPropertyValue(sPropertyOn
, aAny
);
2683 xPropertySet
->setPropertyValue(sPropertyOffset
, aAny
);
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
,
2699 sPropertyHint(sAPI_hint
),
2700 sPropertyMacroName("MacroName"),
2701 sPropertyScriptURL("ScriptURL"),
2702 bDescriptionOK(false)
2706 SvXMLImportContext
* XMLMacroFieldImportContext::CreateChildContext(
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
;
2723 pContext
= SvXMLImportContext::CreateChildContext(
2724 nPrefix
, rLocalName
, xAttrList
);
2730 void XMLMacroFieldImportContext::ProcessAttribute(
2731 sal_uInt16 nAttrToken
,
2732 const OUString
& sAttrValue
)
2736 case XML_TOK_TEXTFIELD_DESCRIPTION
:
2737 sDescription
= sAttrValue
;
2738 bDescriptionOK
= true;
2740 case XML_TOK_TEXTFIELD_NAME
:
2741 sMacro
= sAttrValue
;
2747 void XMLMacroFieldImportContext::PrepareField(
2748 const Reference
<XPropertySet
> & xPropertySet
)
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
;
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
++ )
2803 while ( (pBuf
[nPos
] != '.') && (nPos
> 0) )
2809 sLibraryName
= sMacro
.copy(0, nPos
);
2810 sMacroName
= sMacro
.copy(nPos
+1);
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
)
2844 , nType(ReferenceFieldPart::PAGE_DESC
)
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
)
2870 switch (nElementToken
)
2872 case XML_TOK_TEXT_REFERENCE_REF
:
2873 nSource
= ReferenceFieldSource::REFERENCE_MARK
;
2875 case XML_TOK_TEXT_BOOKMARK_REF
:
2876 nSource
= ReferenceFieldSource::BOOKMARK
;
2878 case XML_TOK_TEXT_NOTE_REF
:
2879 nSource
= ReferenceFieldSource::FOOTNOTE
;
2881 case XML_TOK_TEXT_SEQUENCE_REF
:
2882 nSource
= ReferenceFieldSource::SEQUENCE_FIELD
;
2886 OSL_FAIL("unknown reference field");
2890 XMLTextFieldImportContext::StartElement(xAttrList
);
2894 void XMLReferenceFieldImportContext::ProcessAttribute(
2895 sal_uInt16 nAttrToken
,
2896 const OUString
& sAttrValue
)
2900 case XML_TOK_TEXTFIELD_NOTE_CLASS
:
2901 if( IsXMLToken( sAttrValue
, XML_ENDNOTE
) )
2902 nSource
= ReferenceFieldSource::ENDNOTE
;
2904 case XML_TOK_TEXTFIELD_REF_NAME
:
2908 case XML_TOK_TEXTFIELD_REFERENCE_FORMAT
:
2911 if (SvXMLUnitConverter::convertEnum(nToken
, sAttrValue
,
2912 lcl_aReferenceTypeTokenMap
))
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
;
2930 // bValid: we need proper element type and name
2931 bValid
= bTypeOK
&& bNameOK
;
2934 void XMLReferenceFieldImportContext::PrepareField(
2935 const Reference
<XPropertySet
> & xPropertySet
)
2940 xPropertySet
->setPropertyValue(sPropertyReferenceFieldPart
, aAny
);
2943 xPropertySet
->setPropertyValue(sPropertyReferenceFieldSource
, aAny
);
2945 switch (nElementToken
)
2947 case XML_TOK_TEXT_REFERENCE_REF
:
2948 case XML_TOK_TEXT_BOOKMARK_REF
:
2950 xPropertySet
->setPropertyValue(sPropertySourceName
, aAny
);
2953 case XML_TOK_TEXT_NOTE_REF
:
2954 GetImportHelper().ProcessFootnoteReference(sName
, xPropertySet
);
2957 case XML_TOK_TEXT_SEQUENCE_REF
:
2958 GetImportHelper().ProcessSequenceReference(sName
, xPropertySet
);
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
},
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(
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
);
3013 return SvXMLImportContext::CreateChildContext(nPrefix
,
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
)
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
)
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
);
3071 case XML_TOK_DDEFIELD_APPLICATION
:
3072 sCommandApplication
= xAttrList
->getValueByIndex(i
);
3073 bCommandApplicationOK
= true;
3075 case XML_TOK_DDEFIELD_TOPIC
:
3076 sCommandTopic
= xAttrList
->getValueByIndex(i
);
3077 bCommandTopicOK
= true;
3079 case XML_TOK_DDEFIELD_ITEM
:
3080 sCommandItem
= xAttrList
->getValueByIndex(i
);
3081 bCommandItemOK
= true;
3083 case XML_TOK_DDEFIELD_UPDATE
:
3086 if (::sax::Converter::convertBool(
3087 bTmp
, xAttrList
->getValueByIndex(i
)) )
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(),
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());
3121 Reference
<XPropertySet
> xPropSet( xIfc
, UNO_QUERY
);
3122 if (xPropSet
.is() &&
3123 xPropSet
->getPropertySetInfo()->hasPropertyByName(
3124 sPropertyDDECommandType
))
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
,
3141 aAny
.setValue(&bUpdate
, cppu::UnoType
<bool>::get());
3142 xPropSet
->setPropertyValue(sPropertyIsAutomaticUpdate
,
3145 // else: ignore (can't get XPropertySet, or DDE
3146 // properties are not supported)
3150 catch (const Exception
&)
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
,
3174 ,sPropertyContent(sAPI_content
)
3178 void XMLDdeFieldImportContext::ProcessAttribute(
3179 sal_uInt16 nAttrToken
,
3180 const OUString
& sAttrValue
)
3182 if (XML_TOK_TEXTFIELD_CONNECTION_NAME
== nAttrToken
)
3189 void XMLDdeFieldImportContext::EndElement()
3194 OUStringBuffer sBuf
;
3195 sBuf
.appendAscii(sAPI_fieldmaster_prefix
);
3196 sBuf
.appendAscii(sAPI_dde
);
3199 OUString sMasterName
= sBuf
.makeStringAndClear();
3201 Reference
<XTextFieldsSupplier
> xTextFieldsSupp(GetImport().GetModel(),
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
);
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
,
3256 const OUString
& sLocalName
) :
3257 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_sheet_name
,
3260 bValid
= true; // always valid!
3263 void XMLSheetNameImportContext::ProcessAttribute(
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
)
3289 /// process attribute values
3290 void XMLPageNameFieldImportContext::ProcessAttribute( sal_uInt16
,
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
,
3312 const OUString
& sLocalName
) :
3313 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_url
,
3315 sPropertyURL(sAPI_url
),
3316 sPropertyTargetFrame(sAPI_target_frame
),
3317 sPropertyRepresentation(
3318 sAPI_representation
),
3323 void XMLUrlFieldImportContext::ProcessAttribute(
3324 sal_uInt16 nAttrToken
,
3325 const OUString
& sAttrValue
)
3329 case XML_TOK_TEXTFIELD_HREF
:
3330 sURL
= GetImport().GetAbsoluteReference( sAttrValue
);
3333 case XML_TOK_TEXTFIELD_TARGET_FRAME
:
3334 sFrame
= sAttrValue
;
3343 void XMLUrlFieldImportContext::PrepareField(
3344 const Reference
<XPropertySet
> & xPropertySet
)
3349 xPropertySet
->setPropertyValue(sPropertyURL
, aAny
);
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
,
3369 const OUString
& sLocalName
) :
3370 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_bibliography
,
3372 sPropertyFields("Fields"),
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
));
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
) )
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
);
3446 aAny
<<= xAttrList
->getValueByIndex(i
);
3447 aValue
.Value
= aAny
;
3449 aValues
.push_back(aValue
);
3452 // else: unknown namespace -> ignore
3456 void XMLBibliographyFieldImportContext::ProcessAttribute(
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
];
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
))
3501 else if (IsXMLToken(sName
, XML_ANNOTE
))
3505 else if (IsXMLToken(sName
, XML_AUTHOR
))
3509 else if (IsXMLToken(sName
, XML_BOOKTITLE
))
3511 pName
= "Booktitle";
3513 else if (IsXMLToken(sName
, XML_CHAPTER
))
3517 else if (IsXMLToken(sName
, XML_EDITION
))
3521 else if (IsXMLToken(sName
, XML_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
))
3537 else if (IsXMLToken(sName
, XML_MONTH
))
3541 else if (IsXMLToken(sName
, XML_NOTE
))
3545 else if (IsXMLToken(sName
, XML_NUMBER
))
3549 else if (IsXMLToken(sName
, XML_ORGANIZATIONS
))
3551 pName
= "Organizations";
3553 else if (IsXMLToken(sName
, XML_PAGES
))
3557 else if (IsXMLToken(sName
, XML_PUBLISHER
))
3559 pName
= "Publisher";
3561 else if (IsXMLToken(sName
, XML_SCHOOL
))
3565 else if (IsXMLToken(sName
, XML_SERIES
))
3569 else if (IsXMLToken(sName
, XML_TITLE
))
3573 else if (IsXMLToken(sName
, XML_REPORT_TYPE
))
3575 pName
= "Report_Type";
3577 else if (IsXMLToken(sName
, XML_VOLUME
))
3581 else if (IsXMLToken(sName
, XML_YEAR
))
3585 else if (IsXMLToken(sName
, XML_URL
))
3589 else if (IsXMLToken(sName
, XML_CUSTOM1
))
3593 else if (IsXMLToken(sName
, XML_CUSTOM2
))
3597 else if (IsXMLToken(sName
, XML_CUSTOM3
))
3601 else if (IsXMLToken(sName
, XML_CUSTOM4
))
3605 else if (IsXMLToken(sName
, XML_CUSTOM5
))
3609 else if (IsXMLToken(sName
, XML_ISBN
))
3615 OSL_FAIL("Unknown bibliography info data");
3627 TYPEINIT1(XMLAnnotationImportContext
, XMLTextFieldImportContext
);
3629 XMLAnnotationImportContext::XMLAnnotationImportContext(
3630 SvXMLImport
& rImport
,
3631 XMLTextImportHelper
& rHlp
,
3634 const OUString
& sLocalName
) :
3635 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_annotation
,
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
),
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(
3656 const OUString
& rValue
)
3658 if (nToken
== XML_TOK_TEXT_NAME
)
3662 SvXMLImportContext
* XMLAnnotationImportContext::CreateChildContext(
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
);
3689 if ( !mxField
.is() )
3690 bOK
= CreateField( mxField
, sServicePrefix
+ GetServiceName() );
3693 Any aAny
= mxField
->getPropertyValue( sPropertyTextRange
);
3694 Reference
< XText
> xText
;
3698 rtl::Reference
< XMLTextImportHelper
> xTxtImport
= GetImport().GetTextImport();
3699 if( !mxCursor
.is() )
3701 mxOldCursor
= xTxtImport
->GetCursor();
3702 mxCursor
= xText
->createTextCursor();
3707 xTxtImport
->SetCursor( mxCursor
);
3708 pContext
= xTxtImport
->CreateTextChildContext( GetImport(), nPrefix
, rLocalName
, xAttrList
);
3713 catch (const Exception
&)
3718 pContext
= new XMLStringBufferImportContext(GetImport(), nPrefix
, rLocalName
, aTextBuffer
);
3724 void XMLAnnotationImportContext::EndElement()
3726 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
3729 // delete addition newline
3730 const OUString aEmpty
;
3731 mxCursor
->gotoEnd( sal_False
);
3732 mxCursor
->goLeft( 1, sal_True
);
3733 mxCursor
->setString( aEmpty
);
3736 GetImport().GetTextImport()->ResetCursor();
3739 if( mxOldCursor
.is() )
3740 GetImport().GetTextImport()->SetCursor( mxOldCursor
);
3742 // reinstall old list item #91964#
3743 GetImport().GetTextImport()->PopListContext();
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
);
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());
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
&)
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()))
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
));
3855 TYPEINIT1(XMLScriptImportContext
, XMLTextFieldImportContext
);
3857 XMLScriptImportContext::XMLScriptImportContext(
3858 SvXMLImport
& rImport
,
3859 XMLTextImportHelper
& rHlp
,
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
)
3867 , bScriptTypeOK(false)
3871 void XMLScriptImportContext::ProcessAttribute(
3872 sal_uInt16 nAttrToken
,
3873 const OUString
& sAttrValue
)
3877 case XML_TOK_TEXTFIELD_HREF
:
3878 sContent
= GetImport().GetAbsoluteReference( sAttrValue
);
3882 case XML_TOK_TEXTFIELD_LANGUAGE
:
3883 sScriptType
= sAttrValue
;
3884 bScriptTypeOK
= true;
3892 // always valid (even without ScriptType; cf- #96531#)
3896 void XMLScriptImportContext::PrepareField(
3897 const Reference
<XPropertySet
> & xPropertySet
)
3901 // if href attribute was present, we use it. Else we use element content
3904 sContent
= GetContent();
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
);
3921 TYPEINIT1(XMLMeasureFieldImportContext
, XMLTextFieldImportContext
);
3923 XMLMeasureFieldImportContext::XMLMeasureFieldImportContext(
3924 SvXMLImport
& rImport
,
3925 XMLTextImportHelper
& rHlp
,
3927 const OUString
& sLocalName
) :
3928 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_measure
,
3934 void XMLMeasureFieldImportContext::ProcessAttribute(
3935 sal_uInt16 nAttrToken
,
3936 const OUString
& sAttrValue
)
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;
3957 void XMLMeasureFieldImportContext::PrepareField(
3958 const Reference
<XPropertySet
> & xPropertySet
)
3962 xPropertySet
->setPropertyValue("Kind", aAny
);
3972 TYPEINIT1( XMLDropDownFieldImportContext
, XMLTextFieldImportContext
);
3974 XMLDropDownFieldImportContext::XMLDropDownFieldImportContext(
3975 SvXMLImport
& rImport
,
3976 XMLTextImportHelper
& rHlp
,
3978 const OUString
& sLocalName
) :
3979 XMLTextFieldImportContext( rImport
, rHlp
, sAPI_drop_down
,
3980 nPrfx
, sLocalName
),
3987 sPropertyItems( "Items" ),
3988 sPropertySelectedItem( "SelectedItem" ),
3989 sPropertyName( "Name" ),
3990 sPropertyHelp( "Help" ),
3991 sPropertyToolTip( "Tooltip" )
3996 static bool lcl_ProcessLabel( const SvXMLImport
& rImport
,
3997 const Reference
<XAttributeList
>& xAttrList
,
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
) )
4017 else if( IsXMLToken( sLocalName
, XML_CURRENT_SELECTED
) )
4020 if (::sax::Converter::convertBool( bTmp
, sValue
))
4028 SvXMLImportContext
* XMLDropDownFieldImportContext::CreateChildContext(
4030 const OUString
& rLocalName
,
4031 const Reference
<XAttributeList
>& xAttrList
)
4033 if( nPrefix
== XML_NAMESPACE_TEXT
&&
4034 IsXMLToken( rLocalName
, XML_LABEL
) )
4037 bool bIsSelected
= false;
4038 if( lcl_ProcessLabel( GetImport(), xAttrList
, sLabel
, 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
)
4057 else if (nAttrToken
== XML_TOK_TEXTFIELD_HELP
)
4062 else if (nAttrToken
== XML_TOK_TEXTFIELD_HINT
)
4069 void XMLDropDownFieldImportContext::PrepareField(
4070 const Reference
<XPropertySet
>& xPropertySet
)
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
];
4083 xPropertySet
->setPropertyValue( sPropertyItems
, aAny
);
4085 if( nSelected
>= 0 && nSelected
< nLength
)
4087 aAny
<<= pSequence
[nSelected
];
4088 xPropertySet
->setPropertyValue( sPropertySelectedItem
, aAny
);
4095 xPropertySet
->setPropertyValue( sPropertyName
, aAny
);
4101 xPropertySet
->setPropertyValue( sPropertyHelp
, aAny
);
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
;
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
;
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
;
4175 /// process attribute values
4176 void XMLDateTimeFieldImportContext::ProcessAttribute( sal_uInt16
,
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: */