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