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>
70 using namespace ::com::sun::star
;
71 using namespace ::com::sun::star::uno
;
72 using namespace ::com::sun::star::text
;
73 using namespace ::com::sun::star::lang
;
74 using namespace ::com::sun::star::beans
;
75 using namespace ::com::sun::star::document
;
76 using namespace ::com::sun::star::util
;
77 using namespace ::com::sun::star::xml::sax
;
78 using namespace ::xmloff::token
;
82 // SO API string constants
85 // service prefix and service anems
86 const sal_Char sAPI_textfield_prefix
[] = "com.sun.star.text.TextField.";
87 const sal_Char sAPI_fieldmaster_prefix
[] = "com.sun.star.text.FieldMaster.";
88 const sal_Char sAPI_presentation_prefix
[] = "com.sun.star.presentation.TextField.";
90 const sal_Char sAPI_extended_user
[] = "ExtendedUser";
91 const sal_Char sAPI_user_data_type
[] = "UserDataType";
92 const sal_Char sAPI_jump_edit
[] = "JumpEdit";
93 const sal_Char sAPI_get_expression
[] = "GetExpression";
94 const sal_Char sAPI_set_expression
[] = "SetExpression";
95 const sal_Char sAPI_user
[] = "User";
96 const sal_Char sAPI_date_time
[] = "DateTime";
97 const sal_Char sAPI_page_number
[] = "PageNumber";
98 const sal_Char sAPI_database_next
[] = "DatabaseNextSet";
99 const sal_Char sAPI_database_select
[] = "DatabaseNumberOfSet";
100 const sal_Char sAPI_database_number
[] = "DatabaseSetNumber";
101 const sal_Char sAPI_database
[] = "Database";
102 const sal_Char sAPI_database_name
[] = "DatabaseName";
103 const sal_Char sAPI_docinfo_change_author
[] = "DocInfo.ChangeAuthor";
104 const sal_Char sAPI_docinfo_change_date_time
[] = "DocInfo.ChangeDateTime";
105 const sal_Char sAPI_docinfo_edit_time
[] = "DocInfo.EditTime";
106 const sal_Char sAPI_docinfo_description
[] = "DocInfo.Description";
107 const sal_Char sAPI_docinfo_create_author
[] = "DocInfo.CreateAuthor";
108 const sal_Char sAPI_docinfo_create_date_time
[] = "DocInfo.CreateDateTime";
109 const sal_Char sAPI_docinfo_custom
[] = "DocInfo.Custom";
110 const sal_Char sAPI_docinfo_print_author
[] = "DocInfo.PrintAuthor";
111 const sal_Char sAPI_docinfo_print_date_time
[] = "DocInfo.PrintDateTime";
112 const sal_Char sAPI_docinfo_keywords
[] = "DocInfo.KeyWords";
113 const sal_Char sAPI_docinfo_subject
[] = "DocInfo.Subject";
114 const sal_Char sAPI_docinfo_title
[] = "DocInfo.Title";
115 const sal_Char sAPI_docinfo_revision
[] = "DocInfo.Revision";
116 const sal_Char sAPI_hidden_paragraph
[] = "HiddenParagraph";
117 const sal_Char sAPI_hidden_text
[] = "HiddenText";
118 const sal_Char sAPI_conditional_text
[] = "ConditionalText";
119 const sal_Char sAPI_file_name
[] = "FileName";
120 const sal_Char sAPI_chapter
[] = "Chapter";
121 const sal_Char sAPI_template_name
[] = "TemplateName";
122 const sal_Char sAPI_page_count
[] = "PageCount";
123 const sal_Char sAPI_paragraph_count
[] = "ParagraphCount";
124 const sal_Char sAPI_word_count
[] = "WordCount";
125 const sal_Char sAPI_character_count
[] = "CharacterCount";
126 const sal_Char sAPI_table_count
[] = "TableCount";
127 const sal_Char sAPI_graphic_object_count
[] = "GraphicObjectCount";
128 const sal_Char sAPI_embedded_object_count
[] = "EmbeddedObjectCount";
129 const sal_Char sAPI_reference_page_set
[] = "ReferencePageSet";
130 const sal_Char sAPI_reference_page_get
[] = "ReferencePageGet";
131 const sal_Char sAPI_macro
[] = "Macro";
132 const sal_Char sAPI_dde
[] = "DDE";
133 const sal_Char sAPI_get_reference
[] = "GetReference";
134 const sal_Char sAPI_sheet_name
[] = "SheetName";
135 const sal_Char sAPI_url
[] = "URL";
136 const sal_Char sAPI_bibliography
[] = "Bibliography";
137 const sal_Char sAPI_annotation
[] = "Annotation";
138 const sal_Char sAPI_script
[] = "Script";
139 const sal_Char sAPI_measure
[] = "Measure";
140 const sal_Char sAPI_drop_down
[] = "DropDown";
141 const sal_Char sAPI_header
[] = "Header";
142 const sal_Char sAPI_footer
[] = "Footer";
143 const sal_Char sAPI_datetime
[] = "DateTime";
146 const sal_Char sAPI_is_fixed
[] = "IsFixed";
147 const sal_Char sAPI_content
[] = "Content";
148 const sal_Char sAPI_value
[] = "Value";
149 const sal_Char sAPI_author
[] = "Author";
150 const sal_Char sAPI_initials
[] = "Initials";
151 const sal_Char sAPI_full_name
[] = "FullName";
152 const sal_Char sAPI_place_holder_type
[] = "PlaceHolderType";
153 const sal_Char sAPI_place_holder
[] = "PlaceHolder";
154 const sal_Char sAPI_hint
[] = "Hint";
155 const sal_Char sAPI_name
[] = "Name";
156 const sal_Char sAPI_sub_type
[] = "SubType";
157 const sal_Char sAPI_numbering_separator
[] = "NumberingSeparator";
158 const sal_Char sAPI_chapter_numbering_level
[] = "ChapterNumberingLevel";
159 const sal_Char sAPI_variable_subtype
[] = "VariableSubtype";
160 const sal_Char sAPI_formula
[] = "Formula";
161 const sal_Char sAPI_date_time_value
[] = "DateTimeValue";
162 const sal_Char sAPI_number_format
[] = "NumberFormat";
163 const sal_Char sAPI_user_text
[] = "UserText";
164 const sal_Char sAPI_numbering_type
[] = "NumberingType";
165 const sal_Char sAPI_offset
[] = "Offset";
166 const sal_Char sAPI_data_base_name
[] = "DataBaseName";
167 const sal_Char sAPI_data_base_u_r_l
[] = "DataBaseURL";
168 const sal_Char sAPI_data_table_name
[] = "DataTableName";
169 const sal_Char sAPI_condition
[] = "Condition";
170 const sal_Char sAPI_set_number
[] = "SetNumber";
171 const sal_Char sAPI_is_data_base_format
[] = "DataBaseFormat";
172 const sal_Char sAPI_true_content
[] = "TrueContent";
173 const sal_Char sAPI_false_content
[] = "FalseContent";
174 const sal_Char sAPI_revision
[] = "Revision";
175 const sal_Char sAPI_file_format
[] = "FileFormat";
176 const sal_Char sAPI_chapter_format
[] = "ChapterFormat";
177 const sal_Char sAPI_level
[] = "Level";
178 const sal_Char sAPI_is_date
[] = "IsDate";
179 const sal_Char sAPI_adjust
[] = "Adjust";
180 const sal_Char sAPI_on
[] = "On";
181 const sal_Char sAPI_is_automatic_update
[] = "IsAutomaticUpdate";
182 const sal_Char sAPI_source_name
[] = "SourceName";
183 const sal_Char sAPI_current_presentation
[] = "CurrentPresentation";
184 const sal_Char sAPI_reference_field_part
[] = "ReferenceFieldPart";
185 const sal_Char sAPI_reference_field_source
[] = "ReferenceFieldSource";
186 const sal_Char sAPI_dde_command_type
[] = "DDECommandType";
187 const sal_Char sAPI_dde_command_file
[] = "DDECommandFile";
188 const sal_Char sAPI_dde_command_element
[] = "DDECommandElement";
189 // sAPI_url: also used as service name
190 const sal_Char sAPI_target_frame
[] = "TargetFrame";
191 const sal_Char sAPI_representation
[] = "Representation";
192 const sal_Char sAPI_date
[] = "Date";
193 const sal_Char sAPI_url_content
[] = "URLContent";
194 const sal_Char sAPI_script_type
[] = "ScriptType";
195 const sal_Char sAPI_is_hidden
[] = "IsHidden";
196 const sal_Char sAPI_is_condition_true
[] = "IsConditionTrue";
197 const sal_Char sAPI_data_command_type
[] = "DataCommandType";
198 const sal_Char sAPI_is_fixed_language
[] = "IsFixedLanguage";
199 const sal_Char sAPI_is_visible
[] = "IsVisible";
200 const sal_Char sAPI_TextRange
[] = "TextRange";
202 const sal_Char sAPI_true
[] = "TRUE";
205 TYPEINIT1( XMLTextFieldImportContext
, SvXMLImportContext
);
207 XMLTextFieldImportContext::XMLTextFieldImportContext(
208 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
209 const sal_Char
* pService
,
210 sal_uInt16 nPrefix
, const OUString
& rElementName
)
211 : SvXMLImportContext( rImport
, nPrefix
, rElementName
)
212 , sIsFixed(sAPI_is_fixed
)
213 , rTextImportHelper(rHlp
)
214 , sServicePrefix(sAPI_textfield_prefix
)
217 DBG_ASSERT(NULL
!= pService
, "Need service name!");
218 sServiceName
= OUString::createFromAscii(pService
);
221 void XMLTextFieldImportContext::StartElement(
222 const Reference
<XAttributeList
> & xAttrList
)
224 // process attributes
225 sal_Int16 nLength
= xAttrList
->getLength();
226 for(sal_Int16 i
=0; i
<nLength
; i
++) {
229 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
230 GetKeyByAttrName( xAttrList
->getNameByIndex(i
), &sLocalName
);
232 ProcessAttribute(rTextImportHelper
.GetTextFieldAttrTokenMap().
233 Get(nPrefix
, sLocalName
),
234 xAttrList
->getValueByIndex(i
) );
238 XMLTextFieldImportContext::~XMLTextFieldImportContext() {
241 OUString
XMLTextFieldImportContext::GetContent()
243 if (sContent
.isEmpty())
245 sContent
= sContentBuffer
.makeStringAndClear();
251 void XMLTextFieldImportContext::EndElement()
253 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
257 // create field/Service
258 Reference
<XPropertySet
> xPropSet
;
259 if (CreateField(xPropSet
, sServicePrefix
+ GetServiceName()))
261 // set field properties
262 PrepareField(xPropSet
);
264 // attach field to document
265 Reference
<XTextContent
> xTextContent(xPropSet
, UNO_QUERY
);
267 // workaround for #80606#
270 rTextImportHelper
.InsertTextContent(xTextContent
);
272 catch (const lang::IllegalArgumentException
&)
280 // in case of error: write element content
281 rTextImportHelper
.InsertString(GetContent());
284 void XMLTextFieldImportContext::Characters(const OUString
& rContent
)
286 sContentBuffer
.append(rContent
);
289 sal_Bool
XMLTextFieldImportContext::CreateField(
290 Reference
<XPropertySet
> & xField
,
291 const OUString
& rServiceName
)
293 // instantiate new XTextField:
294 // ask import for model, model is factory, ask factory to create service
296 Reference
<XMultiServiceFactory
> xFactory(GetImport().GetModel(),UNO_QUERY
);
299 Reference
<XInterface
> xIfc
= xFactory
->createInstance(rServiceName
);
302 Reference
<XPropertySet
> xTmp( xIfc
, UNO_QUERY
);
306 return sal_False
; // can't create instance
309 return sal_False
; // can't get MultiServiceFactory
315 /// create the appropriate field context from
316 XMLTextFieldImportContext
*
317 XMLTextFieldImportContext::CreateTextFieldImportContext(
318 SvXMLImport
& rImport
,
319 XMLTextImportHelper
& rHlp
,
321 const OUString
& rName
,
324 XMLTextFieldImportContext
* pContext
= NULL
;
328 case XML_TOK_TEXT_SENDER_FIRSTNAME
:
329 case XML_TOK_TEXT_SENDER_LASTNAME
:
330 case XML_TOK_TEXT_SENDER_INITIALS
:
331 case XML_TOK_TEXT_SENDER_TITLE
:
332 case XML_TOK_TEXT_SENDER_POSITION
:
333 case XML_TOK_TEXT_SENDER_EMAIL
:
334 case XML_TOK_TEXT_SENDER_PHONE_PRIVATE
:
335 case XML_TOK_TEXT_SENDER_FAX
:
336 case XML_TOK_TEXT_SENDER_COMPANY
:
337 case XML_TOK_TEXT_SENDER_PHONE_WORK
:
338 case XML_TOK_TEXT_SENDER_STREET
:
339 case XML_TOK_TEXT_SENDER_CITY
:
340 case XML_TOK_TEXT_SENDER_POSTAL_CODE
:
341 case XML_TOK_TEXT_SENDER_COUNTRY
:
342 case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE
:
344 new XMLSenderFieldImportContext( rImport
, rHlp
,
345 nPrefix
, rName
, nToken
);
348 case XML_TOK_TEXT_AUTHOR_NAME
:
349 case XML_TOK_TEXT_AUTHOR_INITIALS
:
351 new XMLAuthorFieldImportContext( rImport
, rHlp
,
352 nPrefix
, rName
, nToken
);
355 case XML_TOK_TEXT_PLACEHOLDER
:
357 new XMLPlaceholderFieldImportContext( rImport
, rHlp
,
360 case XML_TOK_TEXT_SEQUENCE
:
362 new XMLSequenceFieldImportContext( rImport
, rHlp
,
365 case XML_TOK_TEXT_TEXT_INPUT
:
367 new XMLTextInputFieldImportContext( rImport
, rHlp
,
370 case XML_TOK_TEXT_EXPRESSION
:
372 new XMLExpressionFieldImportContext( rImport
, rHlp
,
375 case XML_TOK_TEXT_VARIABLE_SET
:
377 new XMLVariableSetFieldImportContext( rImport
, rHlp
,
380 case XML_TOK_TEXT_VARIABLE_INPUT
:
382 new XMLVariableInputFieldImportContext( rImport
, rHlp
,
385 case XML_TOK_TEXT_VARIABLE_GET
:
387 new XMLVariableGetFieldImportContext( rImport
, rHlp
,
390 case XML_TOK_TEXT_USER_FIELD_GET
:
391 pContext
= new XMLUserFieldImportContext( rImport
, rHlp
,
394 case XML_TOK_TEXT_USER_FIELD_INPUT
:
395 pContext
= new XMLUserFieldInputImportContext( rImport
, rHlp
,
398 case XML_TOK_TEXT_TIME
:
399 pContext
= new XMLTimeFieldImportContext( rImport
, rHlp
,
402 case XML_TOK_TEXT_PAGE_CONTINUATION_STRING
:
403 case XML_TOK_TEXT_PAGE_CONTINUATION
:
404 pContext
= new XMLPageContinuationImportContext( rImport
, rHlp
,
408 case XML_TOK_TEXT_PAGE_NUMBER
:
409 pContext
= new XMLPageNumberImportContext( rImport
, rHlp
,
413 case XML_TOK_TEXT_DATE
:
414 pContext
= new XMLDateFieldImportContext( rImport
, rHlp
,
418 case XML_TOK_TEXT_DATABASE_NAME
:
419 pContext
= new XMLDatabaseNameImportContext( rImport
, rHlp
,
422 case XML_TOK_TEXT_DATABASE_NEXT
:
423 pContext
= new XMLDatabaseNextImportContext( rImport
, rHlp
,
426 case XML_TOK_TEXT_DATABASE_SELECT
:
427 pContext
= new XMLDatabaseSelectImportContext( rImport
, rHlp
,
430 case XML_TOK_TEXT_DATABASE_ROW_NUMBER
:
431 pContext
= new XMLDatabaseNumberImportContext( rImport
, rHlp
,
434 case XML_TOK_TEXT_DATABASE_DISPLAY
:
435 pContext
= new XMLDatabaseDisplayImportContext( rImport
, rHlp
,
438 case XML_TOK_TEXT_CONDITIONAL_TEXT
:
439 pContext
= new XMLConditionalTextImportContext( rImport
, rHlp
,
442 case XML_TOK_TEXT_HIDDEN_TEXT
:
443 pContext
= new XMLHiddenTextImportContext( rImport
, rHlp
,
446 case XML_TOK_TEXT_HIDDEN_PARAGRAPH
:
447 pContext
= new XMLHiddenParagraphImportContext( rImport
, rHlp
,
450 case XML_TOK_TEXT_DOCUMENT_DESCRIPTION
:
451 case XML_TOK_TEXT_DOCUMENT_TITLE
:
452 case XML_TOK_TEXT_DOCUMENT_SUBJECT
:
453 case XML_TOK_TEXT_DOCUMENT_KEYWORDS
:
454 pContext
= new XMLSimpleDocInfoImportContext( rImport
, rHlp
,
459 case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR
:
460 case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR
:
461 case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR
:
462 pContext
= new XMLSimpleDocInfoImportContext( rImport
, rHlp
,
468 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE
:
469 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME
:
470 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE
:
471 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME
:
472 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE
:
473 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME
:
474 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION
:
475 pContext
= new XMLDateTimeDocInfoImportContext( rImport
, rHlp
,
480 case XML_TOK_TEXT_DOCUMENT_REVISION
:
481 pContext
= new XMLRevisionDocInfoImportContext( rImport
, rHlp
,
486 case XML_TOK_TEXT_DOCUMENT_USER_DEFINED
:
487 pContext
= new XMLUserDocInfoImportContext( rImport
, rHlp
,
492 case XML_TOK_TEXT_FILENAME
:
493 pContext
= new XMLFileNameImportContext( rImport
, rHlp
,
497 case XML_TOK_TEXT_CHAPTER
:
498 pContext
= new XMLChapterImportContext( rImport
, rHlp
,
502 case XML_TOK_TEXT_TEMPLATENAME
:
503 pContext
= new XMLTemplateNameImportContext( rImport
, rHlp
,
507 case XML_TOK_TEXT_WORD_COUNT
:
508 case XML_TOK_TEXT_PARAGRAPH_COUNT
:
509 case XML_TOK_TEXT_TABLE_COUNT
:
510 case XML_TOK_TEXT_CHARACTER_COUNT
:
511 case XML_TOK_TEXT_IMAGE_COUNT
:
512 case XML_TOK_TEXT_OBJECT_COUNT
:
513 case XML_TOK_TEXT_PAGE_COUNT
:
514 pContext
= new XMLCountFieldImportContext( rImport
, rHlp
,
515 nPrefix
, rName
, nToken
);
518 case XML_TOK_TEXT_GET_PAGE_VAR
:
519 pContext
= new XMLPageVarGetFieldImportContext( rImport
, rHlp
,
523 case XML_TOK_TEXT_SET_PAGE_VAR
:
524 pContext
= new XMLPageVarSetFieldImportContext( rImport
, rHlp
,
528 case XML_TOK_TEXT_MACRO
:
529 pContext
= new XMLMacroFieldImportContext( rImport
, rHlp
,
533 case XML_TOK_TEXT_DDE
:
534 pContext
= new XMLDdeFieldImportContext( rImport
, rHlp
,
538 case XML_TOK_TEXT_REFERENCE_REF
:
539 case XML_TOK_TEXT_BOOKMARK_REF
:
540 case XML_TOK_TEXT_NOTE_REF
:
541 case XML_TOK_TEXT_SEQUENCE_REF
:
542 pContext
= new XMLReferenceFieldImportContext( rImport
, rHlp
,
547 case XML_TOK_TEXT_SHEET_NAME
:
548 pContext
= new XMLSheetNameImportContext( rImport
, rHlp
,
552 case XML_TOK_TEXT_BIBLIOGRAPHY_MARK
:
553 pContext
= new XMLBibliographyFieldImportContext( rImport
, rHlp
,
557 case XML_TOK_TEXT_ANNOTATION
:
558 case XML_TOK_TEXT_ANNOTATION_END
:
559 pContext
= new XMLAnnotationImportContext( rImport
, rHlp
,
564 case XML_TOK_TEXT_SCRIPT
:
565 pContext
= new XMLScriptImportContext( rImport
, rHlp
,
569 case XML_TOK_TEXT_MEASURE
:
570 pContext
= new XMLMeasureFieldImportContext( rImport
, rHlp
,
574 case XML_TOK_TEXT_TABLE_FORMULA
:
575 pContext
= new XMLTableFormulaImportContext( rImport
, rHlp
,
578 case XML_TOK_TEXT_DROPDOWN
:
579 pContext
= new XMLDropDownFieldImportContext( rImport
, rHlp
,
582 case XML_TOK_DRAW_HEADER
:
583 pContext
= new XMLHeaderFieldImportContext( rImport
, rHlp
,
586 case XML_TOK_DRAW_FOOTER
:
587 pContext
= new XMLFooterFieldImportContext( rImport
, rHlp
,
590 case XML_TOK_DRAW_DATE_TIME
:
591 pContext
= new XMLDateTimeFieldImportContext( rImport
, rHlp
,
596 // ignore! May not even be a textfield.
597 // (Reminder: This method is called inside default:-branch)
606 void XMLTextFieldImportContext::ForceUpdate(
607 const Reference
<XPropertySet
> & rPropertySet
)
610 Reference
<XUpdatable
> xUpdate(rPropertySet
, UNO_QUERY
);
617 OSL_FAIL("Expected XUpdatable support!");
624 // XMLSenderFieldImportContext
627 TYPEINIT1( XMLSenderFieldImportContext
, XMLTextFieldImportContext
);
629 XMLSenderFieldImportContext::XMLSenderFieldImportContext(
630 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
631 sal_uInt16 nPrfx
, const OUString
& sLocalName
,
633 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_extended_user
,nPrfx
, sLocalName
)
634 , sPropertyFixed(sAPI_is_fixed
)
635 , sPropertyFieldSubType(sAPI_user_data_type
)
636 , sPropertyContent(sAPI_content
)
638 , nElementToken(nToken
)
642 void XMLSenderFieldImportContext::StartElement(
643 const Reference
<XAttributeList
> & xAttrList
)
646 switch (nElementToken
) {
647 case XML_TOK_TEXT_SENDER_FIRSTNAME
:
648 nSubType
= UserDataPart::FIRSTNAME
;
650 case XML_TOK_TEXT_SENDER_LASTNAME
:
651 nSubType
= UserDataPart::NAME
;
653 case XML_TOK_TEXT_SENDER_INITIALS
:
654 nSubType
= UserDataPart::SHORTCUT
;
656 case XML_TOK_TEXT_SENDER_TITLE
:
657 nSubType
= UserDataPart::TITLE
;
659 case XML_TOK_TEXT_SENDER_POSITION
:
660 nSubType
= UserDataPart::POSITION
;
662 case XML_TOK_TEXT_SENDER_EMAIL
:
663 nSubType
= UserDataPart::EMAIL
;
665 case XML_TOK_TEXT_SENDER_PHONE_PRIVATE
:
666 nSubType
= UserDataPart::PHONE_PRIVATE
;
668 case XML_TOK_TEXT_SENDER_FAX
:
669 nSubType
= UserDataPart::FAX
;
671 case XML_TOK_TEXT_SENDER_COMPANY
:
672 nSubType
= UserDataPart::COMPANY
;
674 case XML_TOK_TEXT_SENDER_PHONE_WORK
:
675 nSubType
= UserDataPart::PHONE_COMPANY
;
677 case XML_TOK_TEXT_SENDER_STREET
:
678 nSubType
= UserDataPart::STREET
;
680 case XML_TOK_TEXT_SENDER_CITY
:
681 nSubType
= UserDataPart::CITY
;
683 case XML_TOK_TEXT_SENDER_POSTAL_CODE
:
684 nSubType
= UserDataPart::ZIP
;
686 case XML_TOK_TEXT_SENDER_COUNTRY
:
687 nSubType
= UserDataPart::COUNTRY
;
689 case XML_TOK_TEXT_SENDER_STATE_OR_PROVINCE
:
690 nSubType
= UserDataPart::STATE
;
697 // process Attributes
698 XMLTextFieldImportContext::StartElement(xAttrList
);
701 void XMLSenderFieldImportContext::ProcessAttribute(
702 sal_uInt16 nAttrToken
,
703 const OUString
& sAttrValue
)
705 if (XML_TOK_TEXTFIELD_FIXED
== nAttrToken
) {
709 bool const bRet
= ::sax::Converter::convertBool(bVal
, sAttrValue
);
711 // set bFixed if successful
718 void XMLSenderFieldImportContext::PrepareField(
719 const Reference
<XPropertySet
> & rPropSet
)
724 rPropSet
->setPropertyValue(sPropertyFieldSubType
, aAny
);
727 aAny
.setValue( &bFixed
, ::getBooleanCppuType() );
728 rPropSet
->setPropertyValue(sPropertyFixed
, aAny
);
730 // set content if fixed
733 // in organizer or styles-only mode: force update
734 if (GetImport().GetTextImport()->IsOrganizerMode() ||
735 GetImport().GetTextImport()->IsStylesOnlyMode() )
737 ForceUpdate(rPropSet
);
741 aAny
<<= GetContent();
742 rPropSet
->setPropertyValue(sPropertyContent
, aAny
);
750 // XMLAuthorFieldImportContext
753 TYPEINIT1( XMLAuthorFieldImportContext
, XMLSenderFieldImportContext
);
755 XMLAuthorFieldImportContext::XMLAuthorFieldImportContext(
756 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
757 sal_uInt16 nPrfx
, const OUString
& sLocalName
,
759 : XMLSenderFieldImportContext(rImport
, rHlp
, nPrfx
, sLocalName
, nToken
)
760 , bAuthorFullName(sal_True
)
761 , sServiceAuthor(sAPI_author
)
762 , sPropertyAuthorFullName(sAPI_full_name
)
763 , sPropertyFixed(sAPI_is_fixed
)
764 , sPropertyContent(sAPI_content
)
766 // overwrite service name from XMLSenderFieldImportContext
767 SetServiceName(sServiceAuthor
);
770 void XMLAuthorFieldImportContext::StartElement(
771 const Reference
<XAttributeList
> & xAttrList
) {
773 bAuthorFullName
= (XML_TOK_TEXT_AUTHOR_INITIALS
!= nElementToken
);
776 // process Attributes
777 XMLTextFieldImportContext::StartElement(xAttrList
);
780 void XMLAuthorFieldImportContext::PrepareField(
781 const Reference
<XPropertySet
> & rPropSet
)
785 aAny
.setValue( &bAuthorFullName
, ::getBooleanCppuType() );
786 rPropSet
->setPropertyValue(sPropertyAuthorFullName
, aAny
);
788 aAny
.setValue( &bFixed
, ::getBooleanCppuType() );
789 rPropSet
->setPropertyValue(sPropertyFixed
, aAny
);
791 // set content if fixed
794 // organizer or styles-only mode: force update
795 if (GetImport().GetTextImport()->IsOrganizerMode() ||
796 GetImport().GetTextImport()->IsStylesOnlyMode() )
798 ForceUpdate(rPropSet
);
802 aAny
<<= GetContent();
803 rPropSet
->setPropertyValue(sPropertyContent
, aAny
);
810 // page continuation string
813 TYPEINIT1( XMLPageContinuationImportContext
, XMLTextFieldImportContext
);
815 static SvXMLEnumMapEntry
const lcl_aSelectPageAttrMap
[] =
817 { XML_PREVIOUS
, PageNumberType_PREV
},
818 { XML_CURRENT
, PageNumberType_CURRENT
},
819 { XML_NEXT
, PageNumberType_NEXT
},
820 { XML_TOKEN_INVALID
, 0 },
823 XMLPageContinuationImportContext::XMLPageContinuationImportContext(
824 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
, sal_uInt16 nPrfx
,
825 const OUString
& sLocalName
)
826 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_page_number
, nPrfx
, sLocalName
)
827 , sPropertySubType(sAPI_sub_type
)
828 , sPropertyUserText(sAPI_user_text
)
829 , sPropertyNumberingType(sAPI_numbering_type
)
830 , eSelectPage(PageNumberType_CURRENT
)
831 , sStringOK(sal_False
)
836 void XMLPageContinuationImportContext::ProcessAttribute(
837 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
841 case XML_TOK_TEXTFIELD_SELECT_PAGE
:
844 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
845 lcl_aSelectPageAttrMap
)
846 && (PageNumberType_CURRENT
!= nTmp
) )
848 eSelectPage
= (PageNumberType
)nTmp
;
852 case XML_TOK_TEXTFIELD_STRING_VALUE
:
853 sString
= sAttrValue
;
854 sStringOK
= sal_True
;
859 void XMLPageContinuationImportContext::PrepareField(
860 const Reference
<XPropertySet
> & xPropertySet
)
864 aAny
<<= eSelectPage
;
865 xPropertySet
->setPropertyValue(sPropertySubType
, aAny
);
867 aAny
<<= (sStringOK
? sString
: GetContent());
868 xPropertySet
->setPropertyValue(sPropertyUserText
, aAny
);
870 aAny
<<= style::NumberingType::CHAR_SPECIAL
;
871 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
880 TYPEINIT1( XMLPageNumberImportContext
, XMLTextFieldImportContext
);
882 XMLPageNumberImportContext::XMLPageNumberImportContext(
883 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
, sal_uInt16 nPrfx
,
884 const OUString
& sLocalName
)
885 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_page_number
, nPrfx
, sLocalName
)
886 , sPropertySubType(sAPI_sub_type
)
887 , sPropertyNumberingType(sAPI_numbering_type
)
888 , sPropertyOffset(sAPI_offset
)
889 , sNumberSync(GetXMLToken(XML_FALSE
))
891 , eSelectPage(PageNumberType_CURRENT
)
892 , sNumberFormatOK(sal_False
)
897 void XMLPageNumberImportContext::ProcessAttribute(
898 sal_uInt16 nAttrToken
,
899 const OUString
& sAttrValue
)
903 case XML_TOK_TEXTFIELD_NUM_FORMAT
:
904 sNumberFormat
= sAttrValue
;
905 sNumberFormatOK
= sal_True
;
907 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC
:
908 sNumberSync
= sAttrValue
;
910 case XML_TOK_TEXTFIELD_SELECT_PAGE
:
913 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
914 lcl_aSelectPageAttrMap
))
916 eSelectPage
= (PageNumberType
)nTmp
;
920 case XML_TOK_TEXTFIELD_PAGE_ADJUST
:
923 if (::sax::Converter::convertNumber(nTmp
, sAttrValue
))
925 nPageAdjust
= (sal_Int16
)nTmp
;
932 void XMLPageNumberImportContext::PrepareField(
933 const Reference
<XPropertySet
> & xPropertySet
)
937 // all properties are optional
938 Reference
<XPropertySetInfo
> xPropertySetInfo(
939 xPropertySet
->getPropertySetInfo());
941 if (xPropertySetInfo
->hasPropertyByName(sPropertyNumberingType
))
944 if( sNumberFormatOK
)
946 nNumType
= style::NumberingType::ARABIC
;
947 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
952 nNumType
= style::NumberingType::PAGE_DESCRIPTOR
;
955 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
958 if (xPropertySetInfo
->hasPropertyByName(sPropertyOffset
))
963 case PageNumberType_PREV
:
966 case PageNumberType_CURRENT
:
968 case PageNumberType_NEXT
:
972 DBG_WARNING("unknown page number type");
974 aAny
<<= nPageAdjust
;
975 xPropertySet
->setPropertyValue(sPropertyOffset
, aAny
);
978 if (xPropertySetInfo
->hasPropertyByName(sPropertySubType
))
980 aAny
<<= eSelectPage
;
981 xPropertySet
->setPropertyValue(sPropertySubType
, aAny
);
991 TYPEINIT1( XMLPlaceholderFieldImportContext
, XMLTextFieldImportContext
);
993 XMLPlaceholderFieldImportContext::XMLPlaceholderFieldImportContext(
994 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
995 sal_uInt16 nPrfx
, const OUString
& sLocalName
)
996 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_jump_edit
,nPrfx
, sLocalName
)
997 , sPropertyPlaceholderType(sAPI_place_holder_type
)
998 , sPropertyPlaceholder(sAPI_place_holder
)
999 , sPropertyHint(sAPI_hint
)
1003 /// process attribute values
1004 void XMLPlaceholderFieldImportContext::ProcessAttribute(
1005 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
1007 switch (nAttrToken
) {
1008 case XML_TOK_TEXTFIELD_DESCRIPTION
:
1009 sDescription
= sAttrValue
;
1012 case XML_TOK_TEXTFIELD_PLACEHOLDER_TYPE
:
1014 if (IsXMLToken(sAttrValue
, XML_TABLE
))
1016 nPlaceholderType
= PlaceholderType::TABLE
;
1018 else if (IsXMLToken(sAttrValue
, XML_TEXT
))
1020 nPlaceholderType
= PlaceholderType::TEXT
;
1022 else if (IsXMLToken(sAttrValue
, XML_TEXT_BOX
))
1024 nPlaceholderType
= PlaceholderType::TEXTFRAME
;
1026 else if (IsXMLToken(sAttrValue
, XML_IMAGE
))
1028 nPlaceholderType
= PlaceholderType::GRAPHIC
;
1030 else if (IsXMLToken(sAttrValue
, XML_OBJECT
))
1032 nPlaceholderType
= PlaceholderType::OBJECT
;
1045 void XMLPlaceholderFieldImportContext::PrepareField(
1046 const Reference
<XPropertySet
> & xPropertySet
) {
1049 aAny
<<= sDescription
;
1050 xPropertySet
->setPropertyValue(sPropertyHint
, aAny
);
1052 // remove <...> around content (if present)
1053 OUString aContent
= GetContent();
1054 sal_Int32 nStart
= 0;
1055 sal_Int32 nLength
= aContent
.getLength();
1056 if ((nLength
> 0) && (aContent
.getStr()[0] == '<'))
1061 if ((nLength
> 0) && (aContent
.getStr()[aContent
.getLength()-1] == '>'))
1065 aAny
<<= aContent
.copy(nStart
, nLength
);
1066 xPropertySet
->setPropertyValue(sPropertyPlaceholder
, aAny
);
1068 aAny
<<= nPlaceholderType
;
1069 xPropertySet
->setPropertyValue(sPropertyPlaceholderType
, aAny
);
1077 TYPEINIT1( XMLTimeFieldImportContext
, XMLTextFieldImportContext
);
1079 XMLTimeFieldImportContext::XMLTimeFieldImportContext(
1080 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1081 sal_uInt16 nPrfx
, const OUString
& sLocalName
)
1082 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_date_time
, nPrfx
, sLocalName
)
1083 , sPropertyNumberFormat(sAPI_number_format
)
1084 , sPropertyFixed(sAPI_is_fixed
)
1085 , sPropertyDateTimeValue(sAPI_date_time_value
)
1086 , sPropertyDateTime(sAPI_date_time
)
1087 , sPropertyAdjust(sAPI_adjust
)
1088 , sPropertyIsDate(sAPI_is_date
)
1089 , sPropertyIsFixedLanguage(sAPI_is_fixed_language
)
1093 , bTimeOK(sal_False
)
1094 , bFormatOK(sal_False
)
1096 , bIsDate(sal_False
)
1097 , bIsDefaultLanguage( sal_True
)
1099 bValid
= sal_True
; // always valid!
1102 void XMLTimeFieldImportContext::ProcessAttribute(
1103 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
1107 case XML_TOK_TEXTFIELD_TIME_VALUE
:
1109 // FIXME double appears unused?
1111 if (GetImport().GetMM100UnitConverter().
1112 convertDateTime(fTmp
, sAttrValue
))
1118 if (::sax::Converter::parseTimeOrDateTime(aDateTimeValue
,
1125 case XML_TOK_TEXTFIELD_FIXED
:
1128 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
1134 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME
:
1136 sal_Int32 nKey
= GetImportHelper().GetDataStyleKey(
1137 sAttrValue
, &bIsDefaultLanguage
);
1141 bFormatOK
= sal_True
;
1145 case XML_TOK_TEXTFIELD_TIME_ADJUST
:
1149 if (::sax::Converter::convertDuration(fTmp
, sAttrValue
))
1151 // convert to minutes
1152 nAdjust
= (sal_Int32
)::rtl::math::approxFloor(fTmp
* 60 * 24);
1159 void XMLTimeFieldImportContext::PrepareField(
1160 const Reference
<XPropertySet
> & rPropertySet
)
1164 // all properties are optional (except IsDate)
1165 Reference
<XPropertySetInfo
> xPropertySetInfo(
1166 rPropertySet
->getPropertySetInfo());
1168 if (xPropertySetInfo
->hasPropertyByName(sPropertyFixed
))
1170 aAny
.setValue( &bFixed
, ::getBooleanCppuType() );
1171 rPropertySet
->setPropertyValue(sPropertyFixed
, aAny
);
1174 aAny
.setValue( &bIsDate
, ::getBooleanCppuType() );
1175 rPropertySet
->setPropertyValue(sPropertyIsDate
, aAny
);
1177 if (xPropertySetInfo
->hasPropertyByName(sPropertyAdjust
))
1180 rPropertySet
->setPropertyValue(sPropertyAdjust
, aAny
);
1186 // organizer or styles-only mode: force update
1187 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1188 GetImport().GetTextImport()->IsStylesOnlyMode() )
1190 ForceUpdate(rPropertySet
);
1194 // normal mode: set value (if present)
1197 if (xPropertySetInfo
->hasPropertyByName(sPropertyDateTimeValue
))
1199 aAny
<<= aDateTimeValue
;
1200 rPropertySet
->setPropertyValue(sPropertyDateTimeValue
,aAny
);
1202 else if (xPropertySetInfo
->hasPropertyByName(sPropertyDateTime
))
1204 aAny
<<= aDateTimeValue
;
1205 rPropertySet
->setPropertyValue(sPropertyDateTime
, aAny
);
1212 xPropertySetInfo
->hasPropertyByName(sPropertyNumberFormat
))
1214 aAny
<<= nFormatKey
;
1215 rPropertySet
->setPropertyValue(sPropertyNumberFormat
, aAny
);
1217 if( xPropertySetInfo
->hasPropertyByName( sPropertyIsFixedLanguage
) )
1219 sal_Bool bIsFixedLanguage
= ! bIsDefaultLanguage
;
1220 aAny
.setValue( &bIsFixedLanguage
, ::getBooleanCppuType() );
1221 rPropertySet
->setPropertyValue( sPropertyIsFixedLanguage
, aAny
);
1232 TYPEINIT1( XMLDateFieldImportContext
, XMLTimeFieldImportContext
);
1234 XMLDateFieldImportContext::XMLDateFieldImportContext(
1235 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1236 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
1237 XMLTimeFieldImportContext(rImport
, rHlp
, nPrfx
, sLocalName
)
1239 bIsDate
= sal_True
; // always a date!
1242 void XMLDateFieldImportContext::ProcessAttribute(
1243 sal_uInt16 nAttrToken
,
1244 const OUString
& sAttrValue
)
1248 case XML_TOK_TEXTFIELD_DATE_VALUE
:
1252 if (GetImport().GetMM100UnitConverter().
1253 convertDateTime(fTmp
, sAttrValue
))
1255 // #96457#: don't truncate in order to read date+time
1260 if (::sax::Converter::convertDateTime(aDateTimeValue
, sAttrValue
))
1266 case XML_TOK_TEXTFIELD_DATE_ADJUST
:
1267 // delegate to superclass, pretending it was a time-adjust attr.
1268 XMLTimeFieldImportContext::ProcessAttribute(
1269 XML_TOK_TEXTFIELD_TIME_ADJUST
,
1272 case XML_TOK_TEXTFIELD_TIME_VALUE
:
1273 case XML_TOK_TEXTFIELD_TIME_ADJUST
:
1274 ; // ignore time-adjust and time-value attributes
1277 // all others: delegate to super-class
1278 XMLTimeFieldImportContext::ProcessAttribute(nAttrToken
,
1288 // database field superclass
1291 TYPEINIT1( XMLDatabaseFieldImportContext
, XMLTextFieldImportContext
);
1293 XMLDatabaseFieldImportContext::XMLDatabaseFieldImportContext(
1294 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1295 const sal_Char
* pServiceName
, sal_uInt16 nPrfx
,
1296 const OUString
& sLocalName
, bool bUseDisply
)
1297 : XMLTextFieldImportContext(rImport
, rHlp
, pServiceName
, nPrfx
, sLocalName
)
1298 , sPropertyDataBaseName(sAPI_data_base_name
)
1299 , sPropertyDataBaseURL(sAPI_data_base_u_r_l
)
1300 , sPropertyTableName(sAPI_data_table_name
)
1301 , sPropertyDataCommandType(sAPI_data_command_type
)
1302 , sPropertyIsVisible(sAPI_is_visible
)
1303 , nCommandType( sdb::CommandType::TABLE
)
1304 , bCommandTypeOK(sal_False
)
1305 , bDisplay( sal_True
)
1306 , bDisplayOK( false )
1307 , bUseDisplay( bUseDisply
)
1308 , bDatabaseOK(sal_False
)
1309 , bDatabaseNameOK(sal_False
)
1310 , bDatabaseURLOK(sal_False
)
1311 , bTableOK(sal_False
)
1315 void XMLDatabaseFieldImportContext::ProcessAttribute(
1316 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
1320 case XML_TOK_TEXTFIELD_DATABASE_NAME
:
1321 sDatabaseName
= sAttrValue
;
1322 bDatabaseOK
= sal_True
;
1323 bDatabaseNameOK
= sal_True
;
1325 case XML_TOK_TEXTFIELD_TABLE_NAME
:
1326 sTableName
= sAttrValue
;
1327 bTableOK
= sal_True
;
1329 case XML_TOK_TEXTFIELD_TABLE_TYPE
:
1330 if( IsXMLToken( sAttrValue
, XML_TABLE
) )
1332 nCommandType
= sdb::CommandType::TABLE
;
1333 bCommandTypeOK
= sal_True
;
1335 else if( IsXMLToken( sAttrValue
, XML_QUERY
) )
1337 nCommandType
= sdb::CommandType::QUERY
;
1338 bCommandTypeOK
= sal_True
;
1340 else if( IsXMLToken( sAttrValue
, XML_COMMAND
) )
1342 nCommandType
= sdb::CommandType::COMMAND
;
1343 bCommandTypeOK
= sal_True
;
1346 case XML_TOK_TEXTFIELD_DISPLAY
:
1347 if( IsXMLToken( sAttrValue
, XML_NONE
) )
1349 bDisplay
= sal_False
;
1352 else if( IsXMLToken( sAttrValue
, XML_VALUE
) )
1354 bDisplay
= sal_True
;
1361 SvXMLImportContext
* XMLDatabaseFieldImportContext::CreateChildContext(
1362 sal_uInt16 p_nPrefix
,
1363 const OUString
& rLocalName
,
1364 const Reference
<XAttributeList
>& xAttrList
)
1366 if( ( p_nPrefix
== XML_NAMESPACE_FORM
) &&
1367 IsXMLToken( rLocalName
, XML_CONNECTION_RESOURCE
) )
1369 // process attribute list directly
1370 sal_Int16 nLength
= xAttrList
->getLength();
1371 for( sal_Int16 n
= 0; n
< nLength
; n
++ )
1373 OUString sLocalName
;
1374 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
1375 GetKeyByAttrName( xAttrList
->getNameByIndex(n
), &sLocalName
);
1377 if( ( nPrefix
== XML_NAMESPACE_XLINK
) &&
1378 IsXMLToken( sLocalName
, XML_HREF
) )
1380 sDatabaseURL
= xAttrList
->getValueByIndex(n
);
1381 bDatabaseOK
= sal_True
;
1382 bDatabaseURLOK
= sal_True
;
1386 // we call ProcessAttribute in order to set bValid appropriatly
1387 ProcessAttribute( XML_TOKEN_INVALID
, OUString() );
1390 return SvXMLImportContext::CreateChildContext(p_nPrefix
, rLocalName
,
1395 void XMLDatabaseFieldImportContext::PrepareField(
1396 const Reference
<XPropertySet
> & xPropertySet
)
1400 aAny
<<= sTableName
;
1401 xPropertySet
->setPropertyValue(sPropertyTableName
, aAny
);
1403 if( bDatabaseNameOK
)
1405 aAny
<<= sDatabaseName
;
1406 xPropertySet
->setPropertyValue(sPropertyDataBaseName
, aAny
);
1408 else if( bDatabaseURLOK
)
1410 aAny
<<= sDatabaseURL
;
1411 xPropertySet
->setPropertyValue(sPropertyDataBaseURL
, aAny
);
1414 // #99980# load/save command type for all fields; also load
1415 // old documents without command type
1416 if( bCommandTypeOK
)
1418 aAny
<<= nCommandType
;
1419 xPropertySet
->setPropertyValue( sPropertyDataCommandType
, aAny
);
1422 if( bUseDisplay
&& bDisplayOK
)
1424 aAny
.setValue( &bDisplay
, ::getBooleanCppuType() );
1425 xPropertySet
->setPropertyValue( sPropertyIsVisible
, aAny
);
1432 // database name field
1435 TYPEINIT1( XMLDatabaseNameImportContext
, XMLDatabaseFieldImportContext
);
1437 XMLDatabaseNameImportContext::XMLDatabaseNameImportContext(
1438 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1439 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
1440 XMLDatabaseFieldImportContext(rImport
, rHlp
, sAPI_database_name
,
1441 nPrfx
, sLocalName
, true)
1445 void XMLDatabaseNameImportContext::ProcessAttribute(
1446 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
1448 // delegate to superclass and check for success
1449 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken
, sAttrValue
);
1450 bValid
= bDatabaseOK
&& bTableOK
;
1456 // database next field
1459 TYPEINIT1( XMLDatabaseNextImportContext
, XMLDatabaseFieldImportContext
);
1461 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1462 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1463 const sal_Char
* pServiceName
, sal_uInt16 nPrfx
,
1464 const OUString
& sLocalName
) :
1465 XMLDatabaseFieldImportContext(rImport
, rHlp
, pServiceName
,
1466 nPrfx
, sLocalName
, false),
1467 sPropertyCondition(sAPI_condition
),
1470 bConditionOK(sal_False
)
1474 XMLDatabaseNextImportContext::XMLDatabaseNextImportContext(
1475 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1476 sal_uInt16 nPrfx
, const OUString
& sLocalName
)
1477 : XMLDatabaseFieldImportContext(rImport
, rHlp
, sAPI_database_next
, nPrfx
, sLocalName
, false)
1478 , sPropertyCondition(sAPI_condition
)
1480 , bConditionOK(sal_False
)
1484 void XMLDatabaseNextImportContext::ProcessAttribute(
1485 sal_uInt16 nAttrToken
, const OUString
& sAttrValue
)
1487 if (XML_TOK_TEXTFIELD_CONDITION
== nAttrToken
)
1490 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap()._GetKeyByAttrName(
1491 sAttrValue
, &sTmp
, sal_False
);
1492 if( XML_NAMESPACE_OOOW
== nPrefix
)
1495 bConditionOK
= sal_True
;
1498 sCondition
= sAttrValue
;
1502 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken
,
1506 bValid
= bDatabaseOK
&& bTableOK
;
1509 void XMLDatabaseNextImportContext::PrepareField(
1510 const Reference
<XPropertySet
> & xPropertySet
)
1514 aAny
<<= bConditionOK
? sCondition
: sTrue
;
1515 xPropertySet
->setPropertyValue(sPropertyCondition
, aAny
);
1517 XMLDatabaseFieldImportContext::PrepareField(xPropertySet
);
1523 // database select field
1526 TYPEINIT1( XMLDatabaseSelectImportContext
, XMLDatabaseNextImportContext
);
1528 XMLDatabaseSelectImportContext::XMLDatabaseSelectImportContext(
1529 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1530 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
1531 XMLDatabaseNextImportContext(rImport
, rHlp
, sAPI_database_select
,
1533 sPropertySetNumber(sAPI_set_number
),
1535 bNumberOK(sal_False
)
1539 void XMLDatabaseSelectImportContext::ProcessAttribute(
1540 sal_uInt16 nAttrToken
,
1541 const OUString
& sAttrValue
)
1543 if (XML_TOK_TEXTFIELD_ROW_NUMBER
== nAttrToken
)
1546 if (::sax::Converter::convertNumber( nTmp
, sAttrValue
1547 /* , nMin, nMax ??? */ ))
1550 bNumberOK
= sal_True
;
1555 XMLDatabaseNextImportContext::ProcessAttribute(nAttrToken
, sAttrValue
);
1558 bValid
= bTableOK
&& bDatabaseOK
&& bNumberOK
;
1561 void XMLDatabaseSelectImportContext::PrepareField(
1562 const Reference
<XPropertySet
> & xPropertySet
)
1567 xPropertySet
->setPropertyValue(sPropertySetNumber
, aAny
);
1569 XMLDatabaseNextImportContext::PrepareField(xPropertySet
);
1575 // database display row number field
1578 TYPEINIT1( XMLDatabaseNumberImportContext
, XMLDatabaseFieldImportContext
);
1580 XMLDatabaseNumberImportContext::XMLDatabaseNumberImportContext(
1581 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1582 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
1583 XMLDatabaseFieldImportContext(rImport
, rHlp
, sAPI_database_number
,
1584 nPrfx
, sLocalName
, true),
1585 sPropertyNumberingType(
1586 sAPI_numbering_type
),
1587 sPropertySetNumber(sAPI_set_number
),
1589 sNumberSync(GetXMLToken(XML_FALSE
)),
1595 void XMLDatabaseNumberImportContext::ProcessAttribute(
1596 sal_uInt16 nAttrToken
,
1597 const OUString
& sAttrValue
)
1601 case XML_TOK_TEXTFIELD_NUM_FORMAT
:
1602 sNumberFormat
= sAttrValue
;
1604 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC
:
1605 sNumberSync
= sAttrValue
;
1607 case XML_TOK_TEXTFIELD_VALUE
:
1610 if (::sax::Converter::convertNumber( nTmp
, sAttrValue
))
1613 bValueOK
= sal_True
;
1618 XMLDatabaseFieldImportContext::ProcessAttribute(nAttrToken
,
1623 bValid
= bTableOK
&& bDatabaseOK
;
1626 void XMLDatabaseNumberImportContext::PrepareField(
1627 const Reference
<XPropertySet
> & xPropertySet
)
1631 sal_Int16 nNumType
= style::NumberingType::ARABIC
;
1632 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
1636 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
1641 xPropertySet
->setPropertyValue(sPropertySetNumber
, aAny
);
1644 XMLDatabaseFieldImportContext::PrepareField(xPropertySet
);
1650 // Simple doc info fields
1653 TYPEINIT1( XMLSimpleDocInfoImportContext
, XMLTextFieldImportContext
);
1655 XMLSimpleDocInfoImportContext::XMLSimpleDocInfoImportContext(
1656 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1657 sal_uInt16 nPrfx
, const OUString
& sLocalName
, sal_uInt16 nToken
,
1658 sal_Bool bContent
, sal_Bool bAuthor
)
1659 : XMLTextFieldImportContext(rImport
, rHlp
, MapTokenToServiceName(nToken
),nPrfx
, sLocalName
)
1660 , sPropertyFixed(sAPI_is_fixed
)
1661 , sPropertyContent(sAPI_content
)
1662 , sPropertyAuthor(sAPI_author
)
1663 , sPropertyCurrentPresentation(sAPI_current_presentation
)
1665 , bHasAuthor(bAuthor
)
1666 , bHasContent(bContent
)
1671 void XMLSimpleDocInfoImportContext::ProcessAttribute(
1672 sal_uInt16 nAttrToken
,
1673 const OUString
& sAttrValue
)
1675 if (XML_TOK_TEXTFIELD_FIXED
== nAttrToken
)
1678 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
1685 void XMLSimpleDocInfoImportContext::PrepareField(
1686 const Reference
<XPropertySet
> & rPropertySet
)
1688 // title field in Calc has no Fixed property
1689 Reference
<XPropertySetInfo
> xPropertySetInfo(rPropertySet
->getPropertySetInfo());
1690 if (xPropertySetInfo
->hasPropertyByName(sPropertyFixed
))
1693 aAny
.setValue(&bFixed
, ::getBooleanCppuType() );
1694 rPropertySet
->setPropertyValue(sPropertyFixed
, aAny
);
1696 // set Content and CurrentPresentation (if fixed)
1699 // in organizer-mode or styles-only-mode, only force update
1700 if (GetImport().GetTextImport()->IsOrganizerMode() ||
1701 GetImport().GetTextImport()->IsStylesOnlyMode() )
1703 ForceUpdate(rPropertySet
);
1707 // set content (author, if that's the name) and current
1709 aAny
<<= GetContent();
1711 if (bFixed
&& bHasAuthor
)
1713 rPropertySet
->setPropertyValue(sPropertyAuthor
, aAny
);
1716 if (bFixed
&& bHasContent
)
1718 rPropertySet
->setPropertyValue(sPropertyContent
, aAny
);
1721 rPropertySet
->setPropertyValue(sPropertyCurrentPresentation
, aAny
);
1727 const sal_Char
* XMLSimpleDocInfoImportContext::MapTokenToServiceName(
1730 const sal_Char
* pServiceName
= NULL
;
1734 case XML_TOK_TEXT_DOCUMENT_CREATION_AUTHOR
:
1735 pServiceName
= sAPI_docinfo_create_author
;
1737 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE
:
1738 pServiceName
= sAPI_docinfo_create_date_time
;
1740 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME
:
1741 pServiceName
= sAPI_docinfo_create_date_time
;
1743 case XML_TOK_TEXT_DOCUMENT_DESCRIPTION
:
1744 pServiceName
= sAPI_docinfo_description
;
1746 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION
:
1747 pServiceName
= sAPI_docinfo_edit_time
;
1749 case XML_TOK_TEXT_DOCUMENT_USER_DEFINED
:
1750 pServiceName
= sAPI_docinfo_custom
;
1752 case XML_TOK_TEXT_DOCUMENT_PRINT_AUTHOR
:
1753 pServiceName
= sAPI_docinfo_print_author
;
1755 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE
:
1756 pServiceName
= sAPI_docinfo_print_date_time
;
1758 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME
:
1759 pServiceName
= sAPI_docinfo_print_date_time
;
1761 case XML_TOK_TEXT_DOCUMENT_KEYWORDS
:
1762 pServiceName
= sAPI_docinfo_keywords
;
1764 case XML_TOK_TEXT_DOCUMENT_SUBJECT
:
1765 pServiceName
= sAPI_docinfo_subject
;
1767 case XML_TOK_TEXT_DOCUMENT_REVISION
:
1768 pServiceName
= sAPI_docinfo_revision
;
1770 case XML_TOK_TEXT_DOCUMENT_SAVE_AUTHOR
:
1771 pServiceName
= sAPI_docinfo_change_author
;
1773 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE
:
1774 pServiceName
= sAPI_docinfo_change_date_time
;
1776 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME
:
1777 pServiceName
= sAPI_docinfo_change_date_time
;
1779 case XML_TOK_TEXT_DOCUMENT_TITLE
:
1780 pServiceName
= sAPI_docinfo_title
;
1784 OSL_FAIL("no docinfo field token");
1785 pServiceName
= NULL
;
1789 return pServiceName
;
1797 TYPEINIT1( XMLRevisionDocInfoImportContext
, XMLSimpleDocInfoImportContext
);
1799 XMLRevisionDocInfoImportContext::XMLRevisionDocInfoImportContext(
1800 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
, sal_uInt16 nPrfx
,
1801 const OUString
& sLocalName
, sal_uInt16 nToken
) :
1802 XMLSimpleDocInfoImportContext(rImport
, rHlp
, nPrfx
, sLocalName
,
1803 nToken
, sal_False
, sal_False
),
1804 sPropertyRevision(sAPI_revision
)
1809 void XMLRevisionDocInfoImportContext::PrepareField(
1810 const Reference
<XPropertySet
> & rPropertySet
)
1812 XMLSimpleDocInfoImportContext::PrepareField(rPropertySet
);
1814 // set revision number
1815 // if fixed, if not in organizer-mode, if not in styles-only-mode
1818 if ( GetImport().GetTextImport()->IsOrganizerMode() ||
1819 GetImport().GetTextImport()->IsStylesOnlyMode() )
1821 ForceUpdate(rPropertySet
);
1826 if (::sax::Converter::convertNumber(nTmp
, GetContent()))
1830 rPropertySet
->setPropertyValue(sPropertyRevision
, aAny
);
1839 // DocInfo fields with date/time attributes
1842 TYPEINIT1( XMLDateTimeDocInfoImportContext
, XMLSimpleDocInfoImportContext
);
1844 XMLDateTimeDocInfoImportContext::XMLDateTimeDocInfoImportContext(
1845 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
, sal_uInt16 nPrfx
,
1846 const OUString
& sLocalName
, sal_uInt16 nToken
)
1847 : XMLSimpleDocInfoImportContext(rImport
, rHlp
, nPrfx
, sLocalName
,nToken
, sal_False
, sal_False
)
1848 , sPropertyNumberFormat(sAPI_number_format
)
1849 , sPropertyIsDate(sAPI_is_date
)
1850 , sPropertyIsFixedLanguage(sAPI_is_fixed_language
)
1852 , bFormatOK(sal_False
)
1853 , bIsDefaultLanguage(sal_True
)
1855 // we allow processing of EDIT_DURATION here, because import of actual
1856 // is not supported anyway. If it was, we'd need an extra import class
1857 // because times and time durations are presented differently!
1862 case XML_TOK_TEXT_DOCUMENT_CREATION_DATE
:
1863 case XML_TOK_TEXT_DOCUMENT_PRINT_DATE
:
1864 case XML_TOK_TEXT_DOCUMENT_SAVE_DATE
:
1866 bHasDateTime
= sal_True
;
1868 case XML_TOK_TEXT_DOCUMENT_CREATION_TIME
:
1869 case XML_TOK_TEXT_DOCUMENT_PRINT_TIME
:
1870 case XML_TOK_TEXT_DOCUMENT_SAVE_TIME
:
1871 bIsDate
= sal_False
;
1872 bHasDateTime
= sal_True
;
1874 case XML_TOK_TEXT_DOCUMENT_EDIT_DURATION
:
1875 bIsDate
= sal_False
;
1876 bHasDateTime
= sal_False
;
1880 "XMLDateTimeDocInfoImportContext needs date/time doc. fields");
1886 void XMLDateTimeDocInfoImportContext::ProcessAttribute(
1887 sal_uInt16 nAttrToken
,
1888 const OUString
& sAttrValue
)
1892 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME
:
1894 sal_Int32 nKey
= GetImportHelper().GetDataStyleKey(
1895 sAttrValue
, &bIsDefaultLanguage
);
1899 bFormatOK
= sal_True
;
1903 case XML_TOK_TEXTFIELD_FIXED
:
1904 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken
,
1908 // ignore -> we can't set date/time value anyway!
1913 void XMLDateTimeDocInfoImportContext::PrepareField(
1914 const Reference
<XPropertySet
> & xPropertySet
)
1916 // process fixed and presentation
1917 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet
);
1923 aAny
.setValue( &bIsDate
, ::getBooleanCppuType());
1924 xPropertySet
->setPropertyValue(sPropertyIsDate
, aAny
);
1930 xPropertySet
->setPropertyValue(sPropertyNumberFormat
, aAny
);
1932 if( xPropertySet
->getPropertySetInfo()->
1933 hasPropertyByName( sPropertyIsFixedLanguage
) )
1935 sal_Bool bIsFixedLanguage
= ! bIsDefaultLanguage
;
1936 aAny
.setValue( &bIsFixedLanguage
, ::getBooleanCppuType() );
1937 xPropertySet
->setPropertyValue( sPropertyIsFixedLanguage
, aAny
);
1941 // can't set date/time/duration value! Sorry.
1946 // user defined docinfo fields
1949 TYPEINIT1( XMLUserDocInfoImportContext
, XMLSimpleDocInfoImportContext
);
1951 XMLUserDocInfoImportContext::XMLUserDocInfoImportContext(
1952 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
1953 sal_uInt16 nPrfx
, const OUString
& sLocalName
, sal_uInt16 nToken
) :
1954 XMLSimpleDocInfoImportContext(rImport
, rHlp
, nPrfx
,
1956 sal_False
, sal_False
)
1957 , sPropertyName(sAPI_name
)
1958 , sPropertyNumberFormat(sAPI_number_format
)
1959 , sPropertyIsFixedLanguage(sAPI_is_fixed_language
)
1961 , bFormatOK(sal_False
)
1962 , bIsDefaultLanguage( sal_True
)
1967 void XMLUserDocInfoImportContext::ProcessAttribute(
1968 sal_uInt16 nAttrToken
,
1969 const OUString
& sAttrValue
)
1973 case XML_TOK_TEXTFIELD_DATA_STYLE_NAME
:
1975 sal_Int32 nKey
= GetImportHelper().GetDataStyleKey(
1976 sAttrValue
, &bIsDefaultLanguage
);
1980 bFormatOK
= sal_True
;
1984 case XML_TOK_TEXTFIELD_NAME
:
1988 SetServiceName(OUString(sAPI_docinfo_custom
) );
1996 XMLSimpleDocInfoImportContext::ProcessAttribute(nAttrToken
,
2002 void XMLUserDocInfoImportContext::PrepareField(
2003 const ::com::sun::star::uno::Reference
<
2004 ::com::sun::star::beans::XPropertySet
> & xPropertySet
)
2007 if ( !aName
.isEmpty() )
2010 xPropertySet
->setPropertyValue(sPropertyName
, aAny
);
2012 Reference
<XPropertySetInfo
> xPropertySetInfo(
2013 xPropertySet
->getPropertySetInfo());
2015 xPropertySetInfo
->hasPropertyByName(sPropertyNumberFormat
))
2018 xPropertySet
->setPropertyValue(sPropertyNumberFormat
, aAny
);
2020 if( xPropertySetInfo
->hasPropertyByName( sPropertyIsFixedLanguage
) )
2022 sal_Bool bIsFixedLanguage
= ! bIsDefaultLanguage
;
2023 aAny
.setValue( &bIsFixedLanguage
, ::getBooleanCppuType() );
2024 xPropertySet
->setPropertyValue( sPropertyIsFixedLanguage
, aAny
);
2028 // call superclass to handle "fixed"
2029 XMLSimpleDocInfoImportContext::PrepareField(xPropertySet
);
2034 // import hidden paragraph fields
2037 TYPEINIT1( XMLHiddenParagraphImportContext
, XMLTextFieldImportContext
);
2039 XMLHiddenParagraphImportContext::XMLHiddenParagraphImportContext(
2040 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
2041 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
2042 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_hidden_paragraph
,
2044 sPropertyCondition(sAPI_condition
),
2045 sPropertyIsHidden(sAPI_is_hidden
),
2047 bIsHidden(sal_False
)
2051 void XMLHiddenParagraphImportContext::ProcessAttribute(
2052 sal_uInt16 nAttrToken
,
2053 const OUString
& sAttrValue
)
2055 if (XML_TOK_TEXTFIELD_CONDITION
== nAttrToken
)
2058 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap()._GetKeyByAttrName(
2059 sAttrValue
, &sTmp
, sal_False
);
2060 if( XML_NAMESPACE_OOOW
== nPrefix
)
2066 sCondition
= sAttrValue
;
2068 else if (XML_TOK_TEXTFIELD_IS_HIDDEN
== nAttrToken
)
2071 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2078 void XMLHiddenParagraphImportContext::PrepareField(
2079 const Reference
<XPropertySet
> & xPropertySet
)
2082 aAny
<<= sCondition
;
2083 xPropertySet
->setPropertyValue(sPropertyCondition
, aAny
);
2085 aAny
.setValue( &bIsHidden
, ::getBooleanCppuType() );
2086 xPropertySet
->setPropertyValue(sPropertyIsHidden
, aAny
);
2092 // import conditional text (<text:conditional-text>)
2095 TYPEINIT1( XMLConditionalTextImportContext
, XMLTextFieldImportContext
);
2097 XMLConditionalTextImportContext::XMLConditionalTextImportContext(
2098 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
2099 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
2100 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_conditional_text
,
2102 sPropertyCondition(sAPI_condition
),
2103 sPropertyTrueContent(sAPI_true_content
),
2104 sPropertyFalseContent(sAPI_false_content
),
2105 sPropertyIsConditionTrue(sAPI_is_condition_true
),
2106 sPropertyCurrentPresentation(sAPI_current_presentation
),
2107 bConditionOK(sal_False
),
2109 bFalseOK(sal_False
),
2110 bCurrentValue(sal_False
)
2114 void XMLConditionalTextImportContext::ProcessAttribute(
2115 sal_uInt16 nAttrToken
,
2116 const OUString
& sAttrValue
)
2120 case XML_TOK_TEXTFIELD_CONDITION
:
2123 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
2124 _GetKeyByAttrName( sAttrValue
, &sTmp
, sal_False
);
2125 if( XML_NAMESPACE_OOOW
== nPrefix
)
2128 bConditionOK
= sal_True
;
2131 sCondition
= sAttrValue
;
2134 case XML_TOK_TEXTFIELD_STRING_VALUE_IF_FALSE
:
2135 sFalseContent
= sAttrValue
;
2136 bFalseOK
= sal_True
;
2138 case XML_TOK_TEXTFIELD_STRING_VALUE_IF_TRUE
:
2139 sTrueContent
= sAttrValue
;
2142 case XML_TOK_TEXTFIELD_CURRENT_VALUE
:
2145 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2147 bCurrentValue
= bTmp
;
2153 bValid
= bConditionOK
&& bFalseOK
&& bTrueOK
;
2156 void XMLConditionalTextImportContext::PrepareField(
2157 const Reference
<XPropertySet
> & xPropertySet
)
2161 aAny
<<= sCondition
;
2162 xPropertySet
->setPropertyValue(sPropertyCondition
, aAny
);
2164 aAny
<<= sFalseContent
;
2165 xPropertySet
->setPropertyValue(sPropertyFalseContent
, aAny
);
2167 aAny
<<= sTrueContent
;
2168 xPropertySet
->setPropertyValue(sPropertyTrueContent
, aAny
);
2170 aAny
.setValue( &bCurrentValue
, ::getBooleanCppuType() );
2171 xPropertySet
->setPropertyValue(sPropertyIsConditionTrue
, aAny
);
2173 aAny
<<= GetContent();
2174 xPropertySet
->setPropertyValue(sPropertyCurrentPresentation
, aAny
);
2183 TYPEINIT1( XMLHiddenTextImportContext
, XMLTextFieldImportContext
);
2185 XMLHiddenTextImportContext::XMLHiddenTextImportContext(
2186 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
2187 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
2188 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_hidden_text
,
2190 sPropertyCondition(sAPI_condition
),
2191 sPropertyContent(sAPI_content
),
2192 sPropertyIsHidden(sAPI_is_hidden
),
2193 bConditionOK(sal_False
),
2194 bStringOK(sal_False
),
2195 bIsHidden(sal_False
)
2199 void XMLHiddenTextImportContext::ProcessAttribute(
2200 sal_uInt16 nAttrToken
,
2201 const OUString
& sAttrValue
)
2205 case XML_TOK_TEXTFIELD_CONDITION
:
2208 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
2209 _GetKeyByAttrName( sAttrValue
, &sTmp
, sal_False
);
2210 if( XML_NAMESPACE_OOOW
== nPrefix
)
2213 bConditionOK
= sal_True
;
2216 sCondition
= sAttrValue
;
2219 case XML_TOK_TEXTFIELD_STRING_VALUE
:
2220 sString
= sAttrValue
;
2221 bStringOK
= sal_True
;
2223 case XML_TOK_TEXTFIELD_IS_HIDDEN
:
2226 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2234 bValid
= bConditionOK
&& bStringOK
;
2237 void XMLHiddenTextImportContext::PrepareField(
2238 const Reference
<XPropertySet
> & xPropertySet
)
2242 aAny
<<= sCondition
;
2243 xPropertySet
->setPropertyValue(sPropertyCondition
, aAny
);
2246 xPropertySet
->setPropertyValue(sPropertyContent
, aAny
);
2248 aAny
.setValue( &bIsHidden
, ::getBooleanCppuType() );
2249 xPropertySet
->setPropertyValue(sPropertyIsHidden
, aAny
);
2258 TYPEINIT1( XMLFileNameImportContext
, XMLTextFieldImportContext
);
2260 static const SvXMLEnumMapEntry aFilenameDisplayMap
[] =
2262 { XML_PATH
, FilenameDisplayFormat::PATH
},
2263 { XML_NAME
, FilenameDisplayFormat::NAME
},
2264 { XML_NAME_AND_EXTENSION
, FilenameDisplayFormat::NAME_AND_EXT
},
2265 { XML_FULL
, FilenameDisplayFormat::FULL
},
2266 { XML_TOKEN_INVALID
, 0 }
2269 XMLFileNameImportContext::XMLFileNameImportContext(
2270 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
, sal_uInt16 nPrfx
,
2271 const OUString
& sLocalName
) :
2272 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_file_name
,
2274 sPropertyFixed(sAPI_is_fixed
),
2275 sPropertyFileFormat(sAPI_file_format
),
2276 sPropertyCurrentPresentation(
2277 sAPI_current_presentation
),
2278 nFormat(FilenameDisplayFormat::FULL
),
2284 void XMLFileNameImportContext::ProcessAttribute(
2285 sal_uInt16 nAttrToken
,
2286 const OUString
& sAttrValue
)
2290 case XML_TOK_TEXTFIELD_FIXED
:
2293 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2299 case XML_TOK_TEXTFIELD_DISPLAY
:
2302 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
2303 aFilenameDisplayMap
))
2305 nFormat
= (sal_uInt16
)nTmp
;
2310 ; // unknown attribute: ignore
2315 void XMLFileNameImportContext::PrepareField(
2316 const Reference
<XPropertySet
> & xPropertySet
)
2320 // properties are optional
2321 Reference
<XPropertySetInfo
> xPropertySetInfo(
2322 xPropertySet
->getPropertySetInfo());
2324 if (xPropertySetInfo
->hasPropertyByName(sPropertyFixed
))
2327 xPropertySet
->setPropertyValue(sPropertyFixed
, aAny
);
2330 if (xPropertySetInfo
->hasPropertyByName(sPropertyFileFormat
))
2333 xPropertySet
->setPropertyValue(sPropertyFileFormat
, aAny
);
2336 if (xPropertySetInfo
->hasPropertyByName(sPropertyCurrentPresentation
))
2338 aAny
<<= GetContent();
2339 xPropertySet
->setPropertyValue(sPropertyCurrentPresentation
, aAny
);
2345 // template name field
2348 static const SvXMLEnumMapEntry aTemplateDisplayMap
[] =
2350 { XML_FULL
, TemplateDisplayFormat::FULL
},
2351 { XML_PATH
, TemplateDisplayFormat::PATH
},
2352 { XML_NAME
, TemplateDisplayFormat::NAME
},
2353 { XML_NAME_AND_EXTENSION
, TemplateDisplayFormat::NAME_AND_EXT
},
2354 { XML_AREA
, TemplateDisplayFormat::AREA
},
2355 { XML_TITLE
, TemplateDisplayFormat::TITLE
},
2356 { XML_TOKEN_INVALID
, 0 }
2359 TYPEINIT1( XMLTemplateNameImportContext
, XMLTextFieldImportContext
);
2361 XMLTemplateNameImportContext::XMLTemplateNameImportContext(
2362 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
, sal_uInt16 nPrfx
,
2363 const OUString
& sLocalName
) :
2364 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_template_name
,
2366 sPropertyFileFormat(sAPI_file_format
),
2367 nFormat(TemplateDisplayFormat::FULL
)
2372 void XMLTemplateNameImportContext::ProcessAttribute(
2373 sal_uInt16 nAttrToken
,
2374 const OUString
& sAttrValue
)
2378 case XML_TOK_TEXTFIELD_DISPLAY
:
2381 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
2382 aTemplateDisplayMap
))
2384 nFormat
= (sal_uInt16
)nTmp
;
2389 ; // unknown attribute: ignore
2394 void XMLTemplateNameImportContext::PrepareField(
2395 const Reference
<XPropertySet
> & xPropertySet
)
2400 xPropertySet
->setPropertyValue(sPropertyFileFormat
, aAny
);
2405 // import chapter fields
2408 TYPEINIT1( XMLChapterImportContext
, XMLTextFieldImportContext
);
2410 static const SvXMLEnumMapEntry aChapterDisplayMap
[] =
2412 { XML_NAME
, ChapterFormat::NAME
},
2413 { XML_NUMBER
, ChapterFormat::NUMBER
},
2414 { XML_NUMBER_AND_NAME
, ChapterFormat::NAME_NUMBER
},
2415 { XML_PLAIN_NUMBER_AND_NAME
, ChapterFormat::NO_PREFIX_SUFFIX
},
2416 { XML_PLAIN_NUMBER
, ChapterFormat::DIGIT
},
2417 { XML_TOKEN_INVALID
, 0 }
2420 XMLChapterImportContext::XMLChapterImportContext(
2421 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
2422 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
2423 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_chapter
,
2425 sPropertyChapterFormat(
2426 sAPI_chapter_format
),
2427 sPropertyLevel(sAPI_level
),
2428 nFormat(ChapterFormat::NAME_NUMBER
),
2434 void XMLChapterImportContext::ProcessAttribute(
2435 sal_uInt16 nAttrToken
,
2436 const OUString
& sAttrValue
)
2440 case XML_TOK_TEXTFIELD_DISPLAY
:
2443 if (SvXMLUnitConverter::convertEnum(nTmp
, sAttrValue
,
2444 aChapterDisplayMap
))
2446 nFormat
= (sal_Int16
)nTmp
;
2450 case XML_TOK_TEXTFIELD_OUTLINE_LEVEL
:
2453 if (::sax::Converter::convertNumber(
2454 nTmp
, sAttrValue
, 1,
2455 GetImport().GetTextImport()->GetChapterNumbering()->getCount()
2458 // API numbers 0..9, we number 1..10
2459 nLevel
= (sal_Int8
)nTmp
;
2465 ; // unknown attribute: ignore
2470 void XMLChapterImportContext::PrepareField(
2471 const Reference
<XPropertySet
> & xPropertySet
)
2476 xPropertySet
->setPropertyValue(sPropertyChapterFormat
, aAny
);
2479 xPropertySet
->setPropertyValue(sPropertyLevel
, aAny
);
2487 TYPEINIT1( XMLCountFieldImportContext
, XMLTextFieldImportContext
);
2489 XMLCountFieldImportContext::XMLCountFieldImportContext(
2490 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
2491 sal_uInt16 nPrfx
, const OUString
& sLocalName
, sal_uInt16 nToken
) :
2492 XMLTextFieldImportContext(rImport
, rHlp
, MapTokenToServiceName(nToken
),
2494 sPropertyNumberingType(
2495 sAPI_numbering_type
),
2498 bNumberFormatOK(sal_False
)
2503 void XMLCountFieldImportContext::ProcessAttribute(
2504 sal_uInt16 nAttrToken
,
2505 const OUString
& sAttrValue
)
2509 case XML_TOK_TEXTFIELD_NUM_FORMAT
:
2510 sNumberFormat
= sAttrValue
;
2511 bNumberFormatOK
= sal_True
;
2513 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC
:
2514 sLetterSync
= sAttrValue
;
2519 void XMLCountFieldImportContext::PrepareField(
2520 const Reference
<XPropertySet
> & xPropertySet
)
2524 // properties optional
2525 // (only page count, but do for all to save common implementation)
2527 if (xPropertySet
->getPropertySetInfo()->
2528 hasPropertyByName(sPropertyNumberingType
))
2531 if( bNumberFormatOK
)
2533 nNumType
= style::NumberingType::ARABIC
;
2534 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
2539 nNumType
= style::NumberingType::PAGE_DESCRIPTOR
;
2541 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
2545 const sal_Char
* XMLCountFieldImportContext::MapTokenToServiceName(
2548 const sal_Char
* pServiceName
= NULL
;
2552 case XML_TOK_TEXT_WORD_COUNT
:
2553 pServiceName
= sAPI_word_count
;
2555 case XML_TOK_TEXT_PARAGRAPH_COUNT
:
2556 pServiceName
= sAPI_paragraph_count
;
2558 case XML_TOK_TEXT_TABLE_COUNT
:
2559 pServiceName
= sAPI_table_count
;
2561 case XML_TOK_TEXT_CHARACTER_COUNT
:
2562 pServiceName
= sAPI_character_count
;
2564 case XML_TOK_TEXT_IMAGE_COUNT
:
2565 pServiceName
= sAPI_graphic_object_count
;
2567 case XML_TOK_TEXT_OBJECT_COUNT
:
2568 pServiceName
= sAPI_embedded_object_count
;
2570 case XML_TOK_TEXT_PAGE_COUNT
:
2571 pServiceName
= sAPI_page_count
;
2574 pServiceName
= NULL
;
2575 OSL_FAIL("unknown count field!");
2579 return pServiceName
;
2585 // page variable import
2588 TYPEINIT1( XMLPageVarGetFieldImportContext
, XMLTextFieldImportContext
);
2590 XMLPageVarGetFieldImportContext::XMLPageVarGetFieldImportContext(
2591 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
2592 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
2593 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_reference_page_get
,
2595 sPropertyNumberingType(
2596 sAPI_numbering_type
),
2599 bNumberFormatOK(sal_False
)
2604 void XMLPageVarGetFieldImportContext::ProcessAttribute(
2605 sal_uInt16 nAttrToken
,
2606 const OUString
& sAttrValue
)
2610 case XML_TOK_TEXTFIELD_NUM_FORMAT
:
2611 sNumberFormat
= sAttrValue
;
2612 bNumberFormatOK
= sal_True
;
2614 case XML_TOK_TEXTFIELD_NUM_LETTER_SYNC
:
2615 sLetterSync
= sAttrValue
;
2620 void XMLPageVarGetFieldImportContext::PrepareField(
2621 const Reference
<XPropertySet
> & xPropertySet
)
2626 if( bNumberFormatOK
)
2628 nNumType
= style::NumberingType::ARABIC
;
2629 GetImport().GetMM100UnitConverter().convertNumFormat( nNumType
,
2634 nNumType
= style::NumberingType::PAGE_DESCRIPTOR
;
2636 xPropertySet
->setPropertyValue(sPropertyNumberingType
, aAny
);
2638 // display old content (#96657#)
2639 aAny
<<= GetContent();
2640 xPropertySet
->setPropertyValue(
2641 OUString(sAPI_current_presentation
),
2648 // page variable set fields
2651 TYPEINIT1(XMLPageVarSetFieldImportContext
, XMLTextFieldImportContext
);
2653 XMLPageVarSetFieldImportContext::XMLPageVarSetFieldImportContext(
2654 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
, sal_uInt16 nPrfx
,
2655 const OUString
& sLocalName
) :
2656 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_reference_page_set
,
2658 sPropertyOn(sAPI_on
),
2659 sPropertyOffset(sAPI_offset
),
2666 void XMLPageVarSetFieldImportContext::ProcessAttribute(
2667 sal_uInt16 nAttrToken
,
2668 const OUString
& sAttrValue
)
2672 case XML_TOK_TEXTFIELD_ACTIVE
:
2675 if (::sax::Converter::convertBool(bTmp
, sAttrValue
))
2681 case XML_TOK_TEXTFIELD_PAGE_ADJUST
:
2684 if (::sax::Converter::convertNumber(nTmp
, sAttrValue
))
2686 nAdjust
= (sal_Int16
)nTmp
;
2695 void XMLPageVarSetFieldImportContext::PrepareField(
2696 const Reference
<XPropertySet
> & xPropertySet
)
2700 aAny
.setValue(&bActive
, ::getBooleanCppuType());
2701 xPropertySet
->setPropertyValue(sPropertyOn
, aAny
);
2704 xPropertySet
->setPropertyValue(sPropertyOffset
, aAny
);
2713 TYPEINIT1( XMLMacroFieldImportContext
, XMLTextFieldImportContext
);
2715 XMLMacroFieldImportContext::XMLMacroFieldImportContext(
2716 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
, sal_uInt16 nPrfx
,
2717 const OUString
& sLocalName
) :
2718 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_macro
,
2720 sPropertyHint(sAPI_hint
),
2721 sPropertyMacroName("MacroName"),
2722 sPropertyScriptURL("ScriptURL"),
2723 bDescriptionOK(sal_False
)
2727 SvXMLImportContext
* XMLMacroFieldImportContext::CreateChildContext(
2729 const OUString
& rLocalName
,
2730 const Reference
<XAttributeList
> & xAttrList
)
2732 SvXMLImportContext
* pContext
= NULL
;
2734 if ( (nPrefix
== XML_NAMESPACE_OFFICE
) &&
2735 IsXMLToken( rLocalName
, XML_EVENT_LISTENERS
) )
2737 // create events context and remember it!
2738 pContext
= new XMLEventsImportContext(
2739 GetImport(), nPrefix
, rLocalName
);
2740 xEventContext
= pContext
;
2744 pContext
= SvXMLImportContext::CreateChildContext(
2745 nPrefix
, rLocalName
, xAttrList
);
2751 void XMLMacroFieldImportContext::ProcessAttribute(
2752 sal_uInt16 nAttrToken
,
2753 const OUString
& sAttrValue
)
2757 case XML_TOK_TEXTFIELD_DESCRIPTION
:
2758 sDescription
= sAttrValue
;
2759 bDescriptionOK
= sal_True
;
2761 case XML_TOK_TEXTFIELD_NAME
:
2762 sMacro
= sAttrValue
;
2768 void XMLMacroFieldImportContext::PrepareField(
2769 const Reference
<XPropertySet
> & xPropertySet
)
2773 OUString
sOnClick("OnClick");
2774 OUString
sPropertyMacroLibrary("MacroLibrary");
2776 aAny
<<= (bDescriptionOK
? sDescription
: GetContent());
2777 xPropertySet
->setPropertyValue(sPropertyHint
, aAny
);
2779 // if we have an events child element, we'll look for the OnClick
2780 // event if not, it may be an old (pre-638i) document. Then, we'll
2781 // have to look at the name attribute.
2782 OUString sMacroName
;
2783 OUString sLibraryName
;
2784 OUString sScriptURL
;
2786 if ( xEventContext
.Is() )
2788 // get event sequence
2789 XMLEventsImportContext
* pEvents
=
2790 (XMLEventsImportContext
*)&xEventContext
;
2791 Sequence
<PropertyValue
> aValues
;
2792 pEvents
->GetEventSequence( sOnClick
, aValues
);
2794 sal_Int32 nLength
= aValues
.getLength();
2795 for( sal_Int32 i
= 0; i
< nLength
; i
++ )
2797 if ( aValues
[i
].Name
== "ScriptType" )
2799 // ignore ScriptType
2801 else if ( aValues
[i
].Name
== "Library" )
2803 aValues
[i
].Value
>>= sLibraryName
;
2805 else if ( aValues
[i
].Name
== "MacroName" )
2807 aValues
[i
].Value
>>= sMacroName
;
2809 if ( aValues
[i
].Name
== "Script" )
2811 aValues
[i
].Value
>>= sScriptURL
;
2817 // disassemble old-style macro-name: Everything before the
2818 // third-last dot is the library
2819 sal_Int32 nPos
= sMacro
.getLength() + 1; // the loop starts with nPos--
2820 const sal_Unicode
* pBuf
= sMacro
.getStr();
2821 for( sal_Int32 i
= 0; (i
< 3) && (nPos
> 0); i
++ )
2824 while ( (pBuf
[nPos
] != '.') && (nPos
> 0) )
2830 sLibraryName
= sMacro
.copy(0, nPos
);
2831 sMacroName
= sMacro
.copy(nPos
+1);
2834 sMacroName
= sMacro
;
2837 aAny
<<= sScriptURL
;
2838 xPropertySet
->setPropertyValue(sPropertyScriptURL
, aAny
);
2840 aAny
<<= sMacroName
;
2841 xPropertySet
->setPropertyValue(sPropertyMacroName
, aAny
);
2843 aAny
<<= sLibraryName
;
2844 xPropertySet
->setPropertyValue(sPropertyMacroLibrary
, aAny
);
2850 // reference field import
2853 TYPEINIT1( XMLReferenceFieldImportContext
, XMLTextFieldImportContext
);
2855 XMLReferenceFieldImportContext::XMLReferenceFieldImportContext(
2856 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
2857 sal_uInt16 nToken
, sal_uInt16 nPrfx
, const OUString
& sLocalName
)
2858 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_get_reference
, nPrfx
, sLocalName
)
2859 , sPropertyReferenceFieldPart(sAPI_reference_field_part
)
2860 , sPropertyReferenceFieldSource(sAPI_reference_field_source
)
2861 , sPropertySourceName(sAPI_source_name
)
2862 , sPropertyCurrentPresentation(sAPI_current_presentation
)
2863 , nElementToken(nToken
)
2864 , nType(ReferenceFieldPart::PAGE_DESC
)
2865 , bNameOK(sal_False
)
2866 , bTypeOK(sal_False
)
2870 static SvXMLEnumMapEntry
const lcl_aReferenceTypeTokenMap
[] =
2872 { XML_PAGE
, ReferenceFieldPart::PAGE
},
2873 { XML_CHAPTER
, ReferenceFieldPart::CHAPTER
},
2874 { XML_TEXT
, ReferenceFieldPart::TEXT
},
2875 { XML_DIRECTION
, ReferenceFieldPart::UP_DOWN
},
2876 { XML_CATEGORY_AND_VALUE
, ReferenceFieldPart::CATEGORY_AND_NUMBER
},
2877 { XML_CAPTION
, ReferenceFieldPart::ONLY_CAPTION
},
2878 { XML_VALUE
, ReferenceFieldPart::ONLY_SEQUENCE_NUMBER
},
2879 // Core implementation for direct cross-references (#i81002#)
2880 { XML_NUMBER
, ReferenceFieldPart::NUMBER
},
2881 { XML_NUMBER_NO_SUPERIOR
, ReferenceFieldPart::NUMBER_NO_CONTEXT
},
2882 { XML_NUMBER_ALL_SUPERIOR
, ReferenceFieldPart::NUMBER_FULL_CONTEXT
},
2883 { XML_TOKEN_INVALID
, 0 }
2886 void XMLReferenceFieldImportContext::StartElement(
2887 const Reference
<XAttributeList
> & xAttrList
)
2890 switch (nElementToken
)
2892 case XML_TOK_TEXT_REFERENCE_REF
:
2893 nSource
= ReferenceFieldSource::REFERENCE_MARK
;
2895 case XML_TOK_TEXT_BOOKMARK_REF
:
2896 nSource
= ReferenceFieldSource::BOOKMARK
;
2898 case XML_TOK_TEXT_NOTE_REF
:
2899 nSource
= ReferenceFieldSource::FOOTNOTE
;
2901 case XML_TOK_TEXT_SEQUENCE_REF
:
2902 nSource
= ReferenceFieldSource::SEQUENCE_FIELD
;
2905 bTypeOK
= sal_False
;
2906 OSL_FAIL("unknown reference field");
2910 XMLTextFieldImportContext::StartElement(xAttrList
);
2914 void XMLReferenceFieldImportContext::ProcessAttribute(
2915 sal_uInt16 nAttrToken
,
2916 const OUString
& sAttrValue
)
2920 case XML_TOK_TEXTFIELD_NOTE_CLASS
:
2921 if( IsXMLToken( sAttrValue
, XML_ENDNOTE
) )
2922 nSource
= ReferenceFieldSource::ENDNOTE
;
2924 case XML_TOK_TEXTFIELD_REF_NAME
:
2928 case XML_TOK_TEXTFIELD_REFERENCE_FORMAT
:
2931 if (SvXMLUnitConverter::convertEnum(nToken
, sAttrValue
,
2932 lcl_aReferenceTypeTokenMap
))
2937 // check for sequence-only-attributes
2938 if ( (XML_TOK_TEXT_SEQUENCE_REF
!= nElementToken
) &&
2939 ( (nType
== ReferenceFieldPart::CATEGORY_AND_NUMBER
) ||
2940 (nType
== ReferenceFieldPart::ONLY_CAPTION
) ||
2941 (nType
== ReferenceFieldPart::ONLY_SEQUENCE_NUMBER
) ) )
2943 nType
= ReferenceFieldPart::PAGE_DESC
;
2950 // bValid: we need proper element type and name
2951 bValid
= bTypeOK
&& bNameOK
;
2954 void XMLReferenceFieldImportContext::PrepareField(
2955 const Reference
<XPropertySet
> & xPropertySet
)
2960 xPropertySet
->setPropertyValue(sPropertyReferenceFieldPart
, aAny
);
2963 xPropertySet
->setPropertyValue(sPropertyReferenceFieldSource
, aAny
);
2965 switch (nElementToken
)
2967 case XML_TOK_TEXT_REFERENCE_REF
:
2968 case XML_TOK_TEXT_BOOKMARK_REF
:
2970 xPropertySet
->setPropertyValue(sPropertySourceName
, aAny
);
2973 case XML_TOK_TEXT_NOTE_REF
:
2974 GetImportHelper().ProcessFootnoteReference(sName
, xPropertySet
);
2977 case XML_TOK_TEXT_SEQUENCE_REF
:
2978 GetImportHelper().ProcessSequenceReference(sName
, xPropertySet
);
2982 aAny
<<= GetContent();
2983 xPropertySet
->setPropertyValue(sPropertyCurrentPresentation
, aAny
);
2989 // field declarations container
2992 enum DdeFieldDeclAttrs
2994 XML_TOK_DDEFIELD_NAME
,
2995 XML_TOK_DDEFIELD_APPLICATION
,
2996 XML_TOK_DDEFIELD_TOPIC
,
2997 XML_TOK_DDEFIELD_ITEM
,
2998 XML_TOK_DDEFIELD_UPDATE
3001 static SvXMLTokenMapEntry aDdeDeclAttrTokenMap
[] =
3003 { XML_NAMESPACE_OFFICE
, XML_NAME
, XML_TOK_DDEFIELD_NAME
},
3004 { XML_NAMESPACE_OFFICE
, XML_DDE_APPLICATION
, XML_TOK_DDEFIELD_APPLICATION
},
3005 { XML_NAMESPACE_OFFICE
, XML_DDE_TOPIC
, XML_TOK_DDEFIELD_TOPIC
},
3006 { XML_NAMESPACE_OFFICE
, XML_DDE_ITEM
, XML_TOK_DDEFIELD_ITEM
},
3007 { XML_NAMESPACE_OFFICE
, XML_AUTOMATIC_UPDATE
, XML_TOK_DDEFIELD_UPDATE
},
3011 TYPEINIT1( XMLDdeFieldDeclsImportContext
, SvXMLImportContext
);
3013 XMLDdeFieldDeclsImportContext::XMLDdeFieldDeclsImportContext(
3014 SvXMLImport
& rImport
, sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
3015 SvXMLImportContext(rImport
, nPrfx
, sLocalName
),
3016 aTokenMap(aDdeDeclAttrTokenMap
)
3020 SvXMLImportContext
* XMLDdeFieldDeclsImportContext::CreateChildContext(
3022 const OUString
& rLocalName
,
3023 const Reference
<XAttributeList
> & xAttrList
)
3025 if ( (XML_NAMESPACE_TEXT
== nPrefix
) &&
3026 (IsXMLToken(rLocalName
, XML_DDE_CONNECTION_DECL
)) )
3028 return new XMLDdeFieldDeclImportContext(GetImport(), nPrefix
,
3029 rLocalName
, aTokenMap
);
3033 return SvXMLImportContext::CreateChildContext(nPrefix
,
3042 // import dde field declaration
3045 TYPEINIT1( XMLDdeFieldDeclImportContext
, SvXMLImportContext
);
3047 XMLDdeFieldDeclImportContext::XMLDdeFieldDeclImportContext(
3048 SvXMLImport
& rImport
, sal_uInt16 nPrfx
,
3049 const OUString
& sLocalName
, const SvXMLTokenMap
& rMap
)
3050 : SvXMLImportContext(rImport
, nPrfx
, sLocalName
)
3051 , sPropertyIsAutomaticUpdate(sAPI_is_automatic_update
)
3052 , sPropertyName(sAPI_name
)
3053 , sPropertyDDECommandType(sAPI_dde_command_type
)
3054 , sPropertyDDECommandFile(sAPI_dde_command_file
)
3055 , sPropertyDDECommandElement(sAPI_dde_command_element
)
3058 DBG_ASSERT(XML_NAMESPACE_TEXT
== nPrfx
, "wrong prefix");
3059 DBG_ASSERT(IsXMLToken(sLocalName
, XML_DDE_CONNECTION_DECL
), "wrong name");
3062 void XMLDdeFieldDeclImportContext::StartElement(
3063 const Reference
<XAttributeList
> & xAttrList
)
3066 OUString sCommandApplication
;
3067 OUString sCommandTopic
;
3068 OUString sCommandItem
;
3070 sal_Bool bUpdate
= sal_False
;
3071 sal_Bool bNameOK
= sal_False
;
3072 sal_Bool bCommandApplicationOK
= sal_False
;
3073 sal_Bool bCommandTopicOK
= sal_False
;
3074 sal_Bool bCommandItemOK
= sal_False
;
3076 // process attributes
3077 sal_Int16 nLength
= xAttrList
->getLength();
3078 for(sal_Int16 i
=0; i
<nLength
; i
++)
3081 OUString sLocalName
;
3082 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
3083 GetKeyByAttrName( xAttrList
->getNameByIndex(i
), &sLocalName
);
3085 switch (rTokenMap
.Get(nPrefix
, sLocalName
))
3087 case XML_TOK_DDEFIELD_NAME
:
3088 sName
= xAttrList
->getValueByIndex(i
);
3091 case XML_TOK_DDEFIELD_APPLICATION
:
3092 sCommandApplication
= xAttrList
->getValueByIndex(i
);
3093 bCommandApplicationOK
= sal_True
;
3095 case XML_TOK_DDEFIELD_TOPIC
:
3096 sCommandTopic
= xAttrList
->getValueByIndex(i
);
3097 bCommandTopicOK
= sal_True
;
3099 case XML_TOK_DDEFIELD_ITEM
:
3100 sCommandItem
= xAttrList
->getValueByIndex(i
);
3101 bCommandItemOK
= sal_True
;
3103 case XML_TOK_DDEFIELD_UPDATE
:
3106 if (::sax::Converter::convertBool(
3107 bTmp
, xAttrList
->getValueByIndex(i
)) )
3117 if (bNameOK
&& bCommandApplicationOK
&& bCommandTopicOK
&& bCommandItemOK
)
3119 // make service name
3120 OUStringBuffer sBuf
;
3121 sBuf
.appendAscii(sAPI_fieldmaster_prefix
);
3122 sBuf
.appendAscii(sAPI_dde
);
3124 // create DDE TextFieldMaster
3125 Reference
<XMultiServiceFactory
> xFactory(GetImport().GetModel(),
3129 /* #i6432# There might be multiple occurrences of one DDE
3130 declaration if it is used in more than one of
3131 header/footer/body. createInstance will throw an exception if we
3132 try to create the second, third, etc. instance of such a
3133 declaration. Thus we ignore the exception. Otherwise this will
3134 lead to an unloadable document. */
3137 Reference
<XInterface
> xIfc
=
3138 xFactory
->createInstance(sBuf
.makeStringAndClear());
3141 Reference
<XPropertySet
> xPropSet( xIfc
, UNO_QUERY
);
3142 if (xPropSet
.is() &&
3143 xPropSet
->getPropertySetInfo()->hasPropertyByName(
3144 sPropertyDDECommandType
))
3149 xPropSet
->setPropertyValue(sPropertyName
, aAny
);
3151 aAny
<<= sCommandApplication
;
3152 xPropSet
->setPropertyValue(sPropertyDDECommandType
, aAny
);
3154 aAny
<<= sCommandTopic
;
3155 xPropSet
->setPropertyValue(sPropertyDDECommandFile
, aAny
);
3157 aAny
<<= sCommandItem
;
3158 xPropSet
->setPropertyValue(sPropertyDDECommandElement
,
3161 aAny
.setValue(&bUpdate
, ::getBooleanCppuType());
3162 xPropSet
->setPropertyValue(sPropertyIsAutomaticUpdate
,
3165 // else: ignore (can't get XPropertySet, or DDE
3166 // properties are not supported)
3170 catch (const Exception
&)
3186 TYPEINIT1( XMLDdeFieldImportContext
, XMLTextFieldImportContext
);
3188 XMLDdeFieldImportContext::XMLDdeFieldImportContext(
3189 SvXMLImport
& rImport
, XMLTextImportHelper
& rHlp
,
3190 sal_uInt16 nPrfx
, const OUString
& sLocalName
) :
3191 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_dde
,
3194 ,sPropertyContent(sAPI_content
)
3198 void XMLDdeFieldImportContext::ProcessAttribute(
3199 sal_uInt16 nAttrToken
,
3200 const OUString
& sAttrValue
)
3202 if (XML_TOK_TEXTFIELD_CONNECTION_NAME
== nAttrToken
)
3209 void XMLDdeFieldImportContext::EndElement()
3214 OUStringBuffer sBuf
;
3215 sBuf
.appendAscii(sAPI_fieldmaster_prefix
);
3216 sBuf
.appendAscii(sAPI_dde
);
3217 sBuf
.append(sal_Unicode('.'));
3219 OUString sMasterName
= sBuf
.makeStringAndClear();
3221 Reference
<XTextFieldsSupplier
> xTextFieldsSupp(GetImport().GetModel(),
3223 Reference
<container::XNameAccess
> xFieldMasterNameAccess(
3224 xTextFieldsSupp
->getTextFieldMasters(), UNO_QUERY
);
3226 if (xFieldMasterNameAccess
->hasByName(sMasterName
))
3228 Reference
<XPropertySet
> xMaster
;
3229 Any aAny
= xFieldMasterNameAccess
->getByName(sMasterName
);
3231 //apply the content to the master
3232 xMaster
->setPropertyValue( sPropertyContent
, uno::makeAny( GetContent()));
3233 // master exists: create text field and attach
3234 Reference
<XPropertySet
> xField
;
3235 sBuf
.appendAscii(sAPI_textfield_prefix
);
3236 sBuf
.appendAscii(sAPI_dde
);
3237 if (CreateField(xField
, sBuf
.makeStringAndClear()))
3239 Reference
<XDependentTextField
> xDepTextField(xField
,UNO_QUERY
);
3240 xDepTextField
->attachTextFieldMaster(xMaster
);
3242 // attach field to document
3243 Reference
<XTextContent
> xTextContent(xField
, UNO_QUERY
);
3244 if (xTextContent
.is())
3246 GetImportHelper().InsertTextContent(xTextContent
);
3248 // we're lucky. nothing else to prepare.
3250 // else: fail, because text content could not be created
3252 // else: fail, because field could not be created
3254 // else: fail, because no master was found (faulty document?!)
3256 // not valid: ignore
3259 void XMLDdeFieldImportContext::PrepareField(
3260 const Reference
<XPropertySet
> &)
3262 // empty, since not needed.
3267 // sheet name fields
3270 TYPEINIT1(XMLSheetNameImportContext
, XMLTextFieldImportContext
);
3272 XMLSheetNameImportContext::XMLSheetNameImportContext(
3273 SvXMLImport
& rImport
,
3274 XMLTextImportHelper
& rHlp
,
3276 const OUString
& sLocalName
) :
3277 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_sheet_name
,
3280 bValid
= sal_True
; // always valid!
3283 void XMLSheetNameImportContext::ProcessAttribute(
3287 // no attributes -> nothing to be done
3290 void XMLSheetNameImportContext::PrepareField(
3291 const Reference
<XPropertySet
> &)
3293 // no attributes -> nothing to be done
3298 // URL fields (Calc, Impress, Draw)
3301 TYPEINIT1(XMLUrlFieldImportContext
, XMLTextFieldImportContext
);
3303 XMLUrlFieldImportContext::XMLUrlFieldImportContext(
3304 SvXMLImport
& rImport
,
3305 XMLTextImportHelper
& rHlp
,
3307 const OUString
& sLocalName
) :
3308 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_url
,
3310 sPropertyURL(sAPI_url
),
3311 sPropertyTargetFrame(sAPI_target_frame
),
3312 sPropertyRepresentation(
3313 sAPI_representation
),
3318 void XMLUrlFieldImportContext::ProcessAttribute(
3319 sal_uInt16 nAttrToken
,
3320 const OUString
& sAttrValue
)
3324 case XML_TOK_TEXTFIELD_HREF
:
3325 sURL
= GetImport().GetAbsoluteReference( sAttrValue
);
3328 case XML_TOK_TEXTFIELD_TARGET_FRAME
:
3329 sFrame
= sAttrValue
;
3330 bFrameOK
= sal_True
;
3338 void XMLUrlFieldImportContext::PrepareField(
3339 const Reference
<XPropertySet
> & xPropertySet
)
3344 xPropertySet
->setPropertyValue(sPropertyURL
, aAny
);
3349 xPropertySet
->setPropertyValue(sPropertyTargetFrame
, aAny
);
3352 aAny
<<= GetContent();
3353 xPropertySet
->setPropertyValue(sPropertyRepresentation
, aAny
);
3357 TYPEINIT1(XMLBibliographyFieldImportContext
, XMLTextFieldImportContext
);
3360 XMLBibliographyFieldImportContext::XMLBibliographyFieldImportContext(
3361 SvXMLImport
& rImport
,
3362 XMLTextImportHelper
& rHlp
,
3364 const OUString
& sLocalName
) :
3365 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_bibliography
,
3367 sPropertyFields("Fields"),
3373 // TODO: this is the same map as is used in the text field export
3374 SvXMLEnumMapEntry
const aBibliographyDataTypeMap
[] =
3376 { XML_ARTICLE
, BibliographyDataType::ARTICLE
},
3377 { XML_BOOK
, BibliographyDataType::BOOK
},
3378 { XML_BOOKLET
, BibliographyDataType::BOOKLET
},
3379 { XML_CONFERENCE
, BibliographyDataType::CONFERENCE
},
3380 { XML_CUSTOM1
, BibliographyDataType::CUSTOM1
},
3381 { XML_CUSTOM2
, BibliographyDataType::CUSTOM2
},
3382 { XML_CUSTOM3
, BibliographyDataType::CUSTOM3
},
3383 { XML_CUSTOM4
, BibliographyDataType::CUSTOM4
},
3384 { XML_CUSTOM5
, BibliographyDataType::CUSTOM5
},
3385 { XML_EMAIL
, BibliographyDataType::EMAIL
},
3386 { XML_INBOOK
, BibliographyDataType::INBOOK
},
3387 { XML_INCOLLECTION
, BibliographyDataType::INCOLLECTION
},
3388 { XML_INPROCEEDINGS
, BibliographyDataType::INPROCEEDINGS
},
3389 { XML_JOURNAL
, BibliographyDataType::JOURNAL
},
3390 { XML_MANUAL
, BibliographyDataType::MANUAL
},
3391 { XML_MASTERSTHESIS
, BibliographyDataType::MASTERSTHESIS
},
3392 { XML_MISC
, BibliographyDataType::MISC
},
3393 { XML_PHDTHESIS
, BibliographyDataType::PHDTHESIS
},
3394 { XML_PROCEEDINGS
, BibliographyDataType::PROCEEDINGS
},
3395 { XML_TECHREPORT
, BibliographyDataType::TECHREPORT
},
3396 { XML_UNPUBLISHED
, BibliographyDataType::UNPUBLISHED
},
3397 { XML_WWW
, BibliographyDataType::WWW
},
3398 { XML_TOKEN_INVALID
, 0 }
3402 // we'll process attributes on our own and forfit the standard
3403 // tecfield mechanism, because our attributes have zero overlp with
3404 // all the oher textfields.
3405 void XMLBibliographyFieldImportContext::StartElement(
3406 const Reference
<XAttributeList
> & xAttrList
)
3408 // iterate over attributes
3409 sal_Int16 nLength
= xAttrList
->getLength();
3410 for(sal_Int16 i
=0; i
<nLength
; i
++) {
3412 OUString sLocalName
;
3413 sal_uInt16 nPrefix
= GetImport().GetNamespaceMap().
3414 GetKeyByAttrName( xAttrList
->getNameByIndex(i
), &sLocalName
);
3416 if (nPrefix
== XML_NAMESPACE_TEXT
)
3418 PropertyValue aValue
;
3419 aValue
.Name
= OUString::createFromAscii(
3420 MapBibliographyFieldName(sLocalName
));
3423 // special treatment for bibliography type
3424 // biblio vs bibilio: #96658#; also read old documents
3425 if (IsXMLToken(sLocalName
, XML_BIBILIOGRAPHIC_TYPE
) ||
3426 IsXMLToken(sLocalName
, XML_BIBLIOGRAPHY_TYPE
) )
3429 if (SvXMLUnitConverter::convertEnum(
3430 nTmp
, xAttrList
->getValueByIndex(i
),
3431 aBibliographyDataTypeMap
))
3433 aAny
<<= (sal_Int16
)nTmp
;
3434 aValue
.Value
= aAny
;
3436 aValues
.push_back(aValue
);
3441 aAny
<<= xAttrList
->getValueByIndex(i
);
3442 aValue
.Value
= aAny
;
3444 aValues
.push_back(aValue
);
3447 // else: unknown namespace -> ignore
3451 void XMLBibliographyFieldImportContext::ProcessAttribute(
3455 // attributes are handled in StartElement
3456 OSL_FAIL("This should not have happened.");
3460 void XMLBibliographyFieldImportContext::PrepareField(
3461 const Reference
<XPropertySet
> & xPropertySet
)
3463 // convert vector into sequence
3464 sal_Int32 nCount
= aValues
.size();
3465 Sequence
<PropertyValue
> aValueSequence(nCount
);
3466 for(sal_Int32 i
= 0; i
< nCount
; i
++)
3468 aValueSequence
[i
] = aValues
[i
];
3473 aAny
<<= aValueSequence
;
3474 xPropertySet
->setPropertyValue(sPropertyFields
, aAny
);
3477 const sal_Char
* XMLBibliographyFieldImportContext::MapBibliographyFieldName(
3480 const sal_Char
* pName
= NULL
;
3482 if (IsXMLToken(sName
, XML_IDENTIFIER
))
3484 pName
= "Identifier";
3486 else if (IsXMLToken(sName
, XML_BIBILIOGRAPHIC_TYPE
) ||
3487 IsXMLToken(sName
, XML_BIBLIOGRAPHY_TYPE
) )
3489 // biblio... vs bibilio...: #96658#: also read old documents
3490 pName
= "BibiliographicType";
3492 else if (IsXMLToken(sName
, XML_ADDRESS
))
3496 else if (IsXMLToken(sName
, XML_ANNOTE
))
3500 else if (IsXMLToken(sName
, XML_AUTHOR
))
3504 else if (IsXMLToken(sName
, XML_BOOKTITLE
))
3506 pName
= "Booktitle";
3508 else if (IsXMLToken(sName
, XML_CHAPTER
))
3512 else if (IsXMLToken(sName
, XML_EDITION
))
3516 else if (IsXMLToken(sName
, XML_EDITOR
))
3520 else if (IsXMLToken(sName
, XML_HOWPUBLISHED
))
3522 pName
= "Howpublished";
3524 else if (IsXMLToken(sName
, XML_INSTITUTION
))
3526 pName
= "Institution";
3528 else if (IsXMLToken(sName
, XML_JOURNAL
))
3532 else if (IsXMLToken(sName
, XML_MONTH
))
3536 else if (IsXMLToken(sName
, XML_NOTE
))
3540 else if (IsXMLToken(sName
, XML_NUMBER
))
3544 else if (IsXMLToken(sName
, XML_ORGANIZATIONS
))
3546 pName
= "Organizations";
3548 else if (IsXMLToken(sName
, XML_PAGES
))
3552 else if (IsXMLToken(sName
, XML_PUBLISHER
))
3554 pName
= "Publisher";
3556 else if (IsXMLToken(sName
, XML_SCHOOL
))
3560 else if (IsXMLToken(sName
, XML_SERIES
))
3564 else if (IsXMLToken(sName
, XML_TITLE
))
3568 else if (IsXMLToken(sName
, XML_REPORT_TYPE
))
3570 pName
= "Report_Type";
3572 else if (IsXMLToken(sName
, XML_VOLUME
))
3576 else if (IsXMLToken(sName
, XML_YEAR
))
3580 else if (IsXMLToken(sName
, XML_URL
))
3584 else if (IsXMLToken(sName
, XML_CUSTOM1
))
3588 else if (IsXMLToken(sName
, XML_CUSTOM2
))
3592 else if (IsXMLToken(sName
, XML_CUSTOM3
))
3596 else if (IsXMLToken(sName
, XML_CUSTOM4
))
3600 else if (IsXMLToken(sName
, XML_CUSTOM5
))
3604 else if (IsXMLToken(sName
, XML_ISBN
))
3610 OSL_FAIL("Unknown bibliography info data");
3622 TYPEINIT1(XMLAnnotationImportContext
, XMLTextFieldImportContext
);
3624 XMLAnnotationImportContext::XMLAnnotationImportContext(
3625 SvXMLImport
& rImport
,
3626 XMLTextImportHelper
& rHlp
,
3629 const OUString
& sLocalName
) :
3630 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_annotation
,
3632 sPropertyAuthor(sAPI_author
),
3633 sPropertyInitials(sAPI_initials
),
3634 sPropertyContent(sAPI_content
),
3635 // why is there no UNO_NAME_DATE_TIME, but only UNO_NAME_DATE_TIME_VALUE?
3636 sPropertyDate(sAPI_date_time_value
),
3637 sPropertyTextRange(sAPI_TextRange
),
3638 sPropertyName(sAPI_name
),
3643 // remember old list item and block (#91964#) and reset them
3644 // for the text frame
3645 // do this in the constructor, not in CreateChildContext (#i93392#)
3646 GetImport().GetTextImport()->PushListContext();
3649 void XMLAnnotationImportContext::ProcessAttribute(
3651 const OUString
& rValue
)
3653 if (nToken
== XML_TOK_TEXT_NAME
)
3657 SvXMLImportContext
* XMLAnnotationImportContext::CreateChildContext(
3659 const OUString
& rLocalName
,
3660 const Reference
<XAttributeList
>& xAttrList
)
3662 SvXMLImportContext
*pContext
= 0;
3663 if( XML_NAMESPACE_DC
== nPrefix
)
3665 if( IsXMLToken( rLocalName
, XML_CREATOR
) )
3666 pContext
= new XMLStringBufferImportContext(GetImport(), nPrefix
,
3667 rLocalName
, aAuthorBuffer
);
3668 else if( IsXMLToken( rLocalName
, XML_DATE
) )
3669 pContext
= new XMLStringBufferImportContext(GetImport(), nPrefix
,
3670 rLocalName
, aDateBuffer
);
3672 else if( XML_NAMESPACE_TEXT
== nPrefix
|| XML_NAMESPACE_LO_EXT
== nPrefix
)
3674 if( IsXMLToken( rLocalName
, XML_SENDER_INITIALS
) )
3675 pContext
= new XMLStringBufferImportContext(GetImport(), nPrefix
,
3676 rLocalName
, aInitialsBuffer
);
3683 if ( !mxField
.is() )
3684 CreateField( mxField
, sServicePrefix
+ GetServiceName() );
3685 Any aAny
= mxField
->getPropertyValue( sPropertyTextRange
);
3686 Reference
< XText
> xText
;
3690 UniReference
< XMLTextImportHelper
> xTxtImport
= GetImport().GetTextImport();
3691 if( !mxCursor
.is() )
3693 mxOldCursor
= xTxtImport
->GetCursor();
3694 mxCursor
= xText
->createTextCursor();
3699 xTxtImport
->SetCursor( mxCursor
);
3700 pContext
= xTxtImport
->CreateTextChildContext( GetImport(), nPrefix
, rLocalName
, xAttrList
);
3704 catch (const Exception
&)
3709 pContext
= new XMLStringBufferImportContext(GetImport(), nPrefix
, rLocalName
, aTextBuffer
);
3715 void XMLAnnotationImportContext::EndElement()
3717 DBG_ASSERT(!GetServiceName().isEmpty(), "no service name for element!");
3720 // delete addition newline
3721 const OUString aEmpty
;
3722 mxCursor
->gotoEnd( sal_False
);
3723 mxCursor
->goLeft( 1, sal_True
);
3724 mxCursor
->setString( aEmpty
);
3727 GetImport().GetTextImport()->ResetCursor();
3730 if( mxOldCursor
.is() )
3731 GetImport().GetTextImport()->SetCursor( mxOldCursor
);
3733 // reinstall old list item #91964#
3734 GetImport().GetTextImport()->PopListContext();
3738 if ( mxField
.is() || CreateField( mxField
, sServicePrefix
+ GetServiceName() ) )
3740 // set field properties
3741 PrepareField( mxField
);
3743 // attach field to document
3744 Reference
< XTextContent
> xTextContent( mxField
, UNO_QUERY
);
3746 // workaround for #80606#
3749 if (m_nToken
== XML_TOK_TEXT_ANNOTATION_END
&& m_xStart
.is())
3751 // So we are ending a previous annotation, let's create a
3752 // text range covering the old and the current position.
3753 uno::Reference
<text::XText
> xText
= GetImportHelper().GetText();
3754 uno::Reference
<text::XTextCursor
> xCursor
= xText
->createTextCursorByRange(m_xStart
->getAnchor());
3755 xCursor
->gotoRange(GetImportHelper().GetCursorAsRange(), true);
3756 uno::Reference
<text::XTextRange
> xTextRange(xCursor
, uno::UNO_QUERY
);
3757 xText
->insertTextContent(xTextRange
, xTextContent
, !xCursor
->isCollapsed());
3759 // Now we can delete the old annotation with the incorrect position.
3760 uno::Reference
<lang::XComponent
>(m_xStart
, uno::UNO_QUERY
)->dispose();
3763 GetImportHelper().InsertTextContent( xTextContent
);
3765 catch (const lang::IllegalArgumentException
&)
3772 GetImportHelper().InsertString(GetContent());
3775 void XMLAnnotationImportContext::PrepareField(
3776 const Reference
<XPropertySet
> & xPropertySet
)
3778 if (m_nToken
== XML_TOK_TEXT_ANNOTATION_END
&& !aName
.isEmpty())
3780 // Search for a previous annotation with the same name.
3781 Reference
<XTextFieldsSupplier
> xTextFieldsSupplier(GetImport().GetModel(), UNO_QUERY
);
3782 uno::Reference
<container::XEnumerationAccess
> xFieldsAccess(xTextFieldsSupplier
->getTextFields());
3783 uno::Reference
<container::XEnumeration
> xFields(xFieldsAccess
->createEnumeration());
3784 uno::Reference
<beans::XPropertySet
> xPrevField
;
3785 while (xFields
->hasMoreElements())
3787 uno::Reference
<beans::XPropertySet
> xCurrField(xFields
->nextElement(), uno::UNO_QUERY
);
3788 uno::Reference
<beans::XPropertySetInfo
> xPropsInfo(xCurrField
->getPropertySetInfo());
3790 if (!xPropsInfo
->hasPropertyByName(sPropertyName
))
3793 OUString aFieldName
;
3794 xCurrField
->getPropertyValue(sPropertyName
) >>= aFieldName
;
3795 if (aFieldName
== aName
)
3797 xPrevField
= xCurrField
;
3801 if (xPrevField
.is())
3803 // Found? Then copy over the properties.
3804 xPropertySet
->setPropertyValue(sPropertyAuthor
, xPrevField
->getPropertyValue(sPropertyAuthor
));
3805 xPropertySet
->setPropertyValue(sPropertyInitials
, xPrevField
->getPropertyValue(sPropertyInitials
));
3806 xPropertySet
->setPropertyValue(sPropertyDate
, xPrevField
->getPropertyValue(sPropertyDate
));
3807 xPropertySet
->setPropertyValue(sPropertyName
, xPrevField
->getPropertyValue(sPropertyName
));
3808 xPropertySet
->setPropertyValue(sPropertyContent
, xPrevField
->getPropertyValue(sPropertyContent
));
3810 // And save a reference to it, so we can delete it later.
3811 m_xStart
.set(xPrevField
, uno::UNO_QUERY
);
3816 // import (possibly empty) author
3817 OUString
sAuthor( aAuthorBuffer
.makeStringAndClear() );
3818 xPropertySet
->setPropertyValue(sPropertyAuthor
, makeAny(sAuthor
));
3820 // import (possibly empty) initials
3821 OUString
sInitials( aInitialsBuffer
.makeStringAndClear() );
3822 xPropertySet
->setPropertyValue(sPropertyInitials
, makeAny(sInitials
));
3824 util::DateTime aDateTime
;
3825 if (::sax::Converter::convertDateTime(aDateTime
,
3826 aDateBuffer
.makeStringAndClear()))
3830 aDate.Year = aDateTime.Year;
3831 aDate.Month = aDateTime.Month;
3832 aDate.Day = aDateTime.Day;
3833 xPropertySet->setPropertyValue(sPropertyDate, makeAny(aDate));
3835 xPropertySet
->setPropertyValue(sPropertyDate
, makeAny(aDateTime
));
3838 OUString sBuffer
= aTextBuffer
.makeStringAndClear();
3839 if ( sBuffer
.getLength() )
3841 // delete last paragraph mark (if necessary)
3842 if (sal_Char(0x0a) == sBuffer
.getStr()[sBuffer
.getLength()-1])
3843 sBuffer
= sBuffer
.copy(0, sBuffer
.getLength()-1);
3844 xPropertySet
->setPropertyValue(sPropertyContent
, makeAny(sBuffer
));
3847 if (!aName
.isEmpty())
3848 xPropertySet
->setPropertyValue(sPropertyName
, makeAny(aName
));
3857 TYPEINIT1(XMLScriptImportContext
, XMLTextFieldImportContext
);
3859 XMLScriptImportContext::XMLScriptImportContext(
3860 SvXMLImport
& rImport
,
3861 XMLTextImportHelper
& rHlp
,
3863 const OUString
& sLocalName
)
3864 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_script
, nPrfx
, sLocalName
)
3865 , sPropertyScriptType(sAPI_script_type
)
3866 , sPropertyURLContent(sAPI_url_content
)
3867 , sPropertyContent(sAPI_content
)
3868 , bContentOK(sal_False
)
3869 , bScriptTypeOK(sal_False
)
3873 void XMLScriptImportContext::ProcessAttribute(
3874 sal_uInt16 nAttrToken
,
3875 const OUString
& sAttrValue
)
3879 case XML_TOK_TEXTFIELD_HREF
:
3880 sContent
= GetImport().GetAbsoluteReference( sAttrValue
);
3881 bContentOK
= sal_True
;
3884 case XML_TOK_TEXTFIELD_LANGUAGE
:
3885 sScriptType
= sAttrValue
;
3886 bScriptTypeOK
= sal_True
;
3894 // always valid (even without ScriptType; cf- #96531#)
3898 void XMLScriptImportContext::PrepareField(
3899 const Reference
<XPropertySet
> & xPropertySet
)
3903 // if href attribute was present, we use it. Else we use element content
3906 sContent
= GetContent();
3909 xPropertySet
->setPropertyValue(sPropertyContent
, aAny
);
3911 // URL or script text? We use URL if we have an href-attribute
3912 aAny
.setValue(&bContentOK
, ::getBooleanCppuType());
3913 xPropertySet
->setPropertyValue(sPropertyURLContent
, aAny
);
3915 aAny
<<= sScriptType
;
3916 xPropertySet
->setPropertyValue(sPropertyScriptType
, aAny
);
3923 TYPEINIT1(XMLMeasureFieldImportContext
, XMLTextFieldImportContext
);
3925 XMLMeasureFieldImportContext::XMLMeasureFieldImportContext(
3926 SvXMLImport
& rImport
,
3927 XMLTextImportHelper
& rHlp
,
3929 const OUString
& sLocalName
) :
3930 XMLTextFieldImportContext(rImport
, rHlp
, sAPI_measure
,
3936 void XMLMeasureFieldImportContext::ProcessAttribute(
3937 sal_uInt16 nAttrToken
,
3938 const OUString
& sAttrValue
)
3942 case XML_TOK_TEXTFIELD_MEASURE_KIND
:
3943 if( IsXMLToken( sAttrValue
, XML_VALUE
) )
3945 mnKind
= 0; bValid
= sal_True
;
3947 else if( IsXMLToken( sAttrValue
, XML_UNIT
) )
3949 mnKind
= 1; bValid
= sal_True
;
3951 else if( IsXMLToken( sAttrValue
, XML_GAP
) )
3953 mnKind
= 2; bValid
= sal_True
;
3959 void XMLMeasureFieldImportContext::PrepareField(
3960 const Reference
<XPropertySet
> & xPropertySet
)
3964 xPropertySet
->setPropertyValue(OUString("Kind"), aAny
);
3974 TYPEINIT1( XMLDropDownFieldImportContext
, XMLTextFieldImportContext
);
3976 XMLDropDownFieldImportContext::XMLDropDownFieldImportContext(
3977 SvXMLImport
& rImport
,
3978 XMLTextImportHelper
& rHlp
,
3980 const OUString
& sLocalName
) :
3981 XMLTextFieldImportContext( rImport
, rHlp
, sAPI_drop_down
,
3982 nPrfx
, sLocalName
),
3989 sPropertyItems( "Items" ),
3990 sPropertySelectedItem( "SelectedItem" ),
3991 sPropertyName( "Name" ),
3992 sPropertyHelp( "Help" ),
3993 sPropertyToolTip( "Tooltip" )
3998 static bool lcl_ProcessLabel( const SvXMLImport
& rImport
,
3999 const Reference
<XAttributeList
>& xAttrList
,
4003 bool bValid
= false;
4004 sal_Int16 nLength
= xAttrList
->getLength();
4005 for( sal_Int16 n
= 0; n
< nLength
; n
++ )
4007 OUString sLocalName
;
4008 sal_uInt16 nPrefix
= rImport
.GetNamespaceMap().
4009 GetKeyByAttrName( xAttrList
->getNameByIndex(n
), &sLocalName
);
4010 OUString sValue
= xAttrList
->getValueByIndex(n
);
4012 if( nPrefix
== XML_NAMESPACE_TEXT
)
4014 if( IsXMLToken( sLocalName
, XML_VALUE
) )
4019 else if( IsXMLToken( sLocalName
, XML_CURRENT_SELECTED
) )
4022 if (::sax::Converter::convertBool( bTmp
, sValue
))
4030 SvXMLImportContext
* XMLDropDownFieldImportContext::CreateChildContext(
4032 const OUString
& rLocalName
,
4033 const Reference
<XAttributeList
>& xAttrList
)
4035 if( nPrefix
== XML_NAMESPACE_TEXT
&&
4036 IsXMLToken( rLocalName
, XML_LABEL
) )
4039 bool bIsSelected
= sal_False
;
4040 if( lcl_ProcessLabel( GetImport(), xAttrList
, sLabel
, bIsSelected
) )
4043 nSelected
= static_cast<sal_Int32
>( aLabels
.size() );
4044 aLabels
.push_back( sLabel
);
4047 return new SvXMLImportContext( GetImport(), nPrefix
, rLocalName
);
4050 void XMLDropDownFieldImportContext::ProcessAttribute(
4051 sal_uInt16 nAttrToken
,
4052 const OUString
& sAttrValue
)
4054 if( nAttrToken
== XML_TOK_TEXTFIELD_NAME
)
4059 else if (nAttrToken
== XML_TOK_TEXTFIELD_HELP
)
4064 else if (nAttrToken
== XML_TOK_TEXTFIELD_HINT
)
4071 void XMLDropDownFieldImportContext::PrepareField(
4072 const Reference
<XPropertySet
>& xPropertySet
)
4075 sal_Int32 nLength
= static_cast<sal_Int32
>( aLabels
.size() );
4076 Sequence
<OUString
> aSequence( nLength
);
4077 OUString
* pSequence
= aSequence
.getArray();
4078 for( sal_Int32 n
= 0; n
< nLength
; n
++ )
4079 pSequence
[n
] = aLabels
[n
];
4085 xPropertySet
->setPropertyValue( sPropertyItems
, aAny
);
4087 if( nSelected
>= 0 && nSelected
< nLength
)
4089 aAny
<<= pSequence
[nSelected
];
4090 xPropertySet
->setPropertyValue( sPropertySelectedItem
, aAny
);
4097 xPropertySet
->setPropertyValue( sPropertyName
, aAny
);
4103 xPropertySet
->setPropertyValue( sPropertyHelp
, aAny
);
4109 xPropertySet
->setPropertyValue( sPropertyToolTip
, aAny
);
4114 /** import header fields (<draw:header>) */
4115 TYPEINIT1( XMLHeaderFieldImportContext
, XMLTextFieldImportContext
);
4117 XMLHeaderFieldImportContext::XMLHeaderFieldImportContext(
4118 SvXMLImport
& rImport
, /// XML Import
4119 XMLTextImportHelper
& rHlp
, /// Text import helper
4120 sal_uInt16 nPrfx
, /// namespace prefix
4121 const OUString
& sLocalName
) /// element name w/o prefix
4122 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_header
, nPrfx
, sLocalName
)
4124 sServicePrefix
= OUString(sAPI_presentation_prefix
);
4128 /// process attribute values
4129 void XMLHeaderFieldImportContext::ProcessAttribute( sal_uInt16
, const OUString
& )
4133 /// prepare XTextField for insertion into document
4134 void XMLHeaderFieldImportContext::PrepareField(const Reference
<XPropertySet
> &)
4138 /** import footer fields (<draw:footer>) */
4139 TYPEINIT1( XMLFooterFieldImportContext
, XMLTextFieldImportContext
);
4141 XMLFooterFieldImportContext::XMLFooterFieldImportContext(
4142 SvXMLImport
& rImport
, /// XML Import
4143 XMLTextImportHelper
& rHlp
, /// Text import helper
4144 sal_uInt16 nPrfx
, /// namespace prefix
4145 const OUString
& sLocalName
) /// element name w/o prefix
4146 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_footer
, nPrfx
, sLocalName
)
4148 sServicePrefix
= OUString(sAPI_presentation_prefix
);
4152 /// process attribute values
4153 void XMLFooterFieldImportContext::ProcessAttribute( sal_uInt16
, const OUString
& )
4157 /// prepare XTextField for insertion into document
4158 void XMLFooterFieldImportContext::PrepareField(const Reference
<XPropertySet
> &)
4163 /** import footer fields (<draw:date-and-time>) */
4164 TYPEINIT1( XMLDateTimeFieldImportContext
, XMLTextFieldImportContext
);
4166 XMLDateTimeFieldImportContext::XMLDateTimeFieldImportContext(
4167 SvXMLImport
& rImport
, /// XML Import
4168 XMLTextImportHelper
& rHlp
, /// Text import helper
4169 sal_uInt16 nPrfx
, /// namespace prefix
4170 const OUString
& sLocalName
) /// element name w/o prefix
4171 : XMLTextFieldImportContext(rImport
, rHlp
, sAPI_datetime
, nPrfx
, sLocalName
)
4173 sServicePrefix
= OUString(sAPI_presentation_prefix
);
4177 /// process attribute values
4178 void XMLDateTimeFieldImportContext::ProcessAttribute( sal_uInt16
,
4183 /// prepare XTextField for insertion into document
4184 void XMLDateTimeFieldImportContext::PrepareField(
4185 const ::com::sun::star::uno::Reference
<
4186 ::com::sun::star::beans::XPropertySet
> &)
4190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */