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