1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 /** @#file 29 * 30 * XML import of all variable related text fields plus database display field 31 */ 32 33 #ifndef _XMLOFF_TXTVFLDI_HXX 34 #define _XMLOFF_TXTVFLDI_HXX 35 36 #include "txtvfldi.hxx" 37 #include "txtfldi.hxx" 38 #include <com/sun/star/beans/XPropertySet.hpp> 39 #include <com/sun/star/beans/XPropertySetInfo.hpp> 40 41 42 43 /// variable type (for XMLSetVarFieldImportContext) 44 enum VarType 45 { 46 VarTypeSimple, 47 VarTypeUserField, 48 VarTypeSequence 49 }; 50 51 52 53 /** helper class: parses value-type and associated value attributes */ 54 class XMLValueImportHelper 55 { 56 57 const ::rtl::OUString sPropertyContent; 58 const ::rtl::OUString sPropertyValue; 59 const ::rtl::OUString sPropertyFormula; 60 const ::rtl::OUString sPropertyNumberFormat; 61 const ::rtl::OUString sPropertyIsFixedLanguage; 62 63 SvXMLImport& rImport; 64 XMLTextImportHelper& rHelper; 65 66 ::rtl::OUString sValue; /// string value (only valid if bStringValueOK) 67 double fValue; /// double value (only valid if bFloatValueOK) 68 sal_Int32 nFormatKey; /// format key (only valid of bFormatOK) 69 ::rtl::OUString sFormula; /// formula string 70 ::rtl::OUString sDefault; /// default (see bStringDefault/bFormulaDef.) 71 sal_Bool bIsDefaultLanguage;/// format (of nFormatKey) has system language? 72 73 sal_Bool bStringType; /// is this a string (or a float) type? 74 sal_Bool bFormatOK; /// have we read a style:data-style-name attr.? 75 sal_Bool bTypeOK; /// have we read a value-type attribute? 76 sal_Bool bStringValueOK; /// have we read a string-value attr.? 77 sal_Bool bFloatValueOK; /// have we read any of the float attr.s? 78 sal_Bool bFormulaOK; /// have we read the formula attribute? 79 80 const sal_Bool bSetType; /// should PrepareField set the SetExp subtype? 81 const sal_Bool bSetValue; /// should PrepareField set content/value? 82 const sal_Bool bSetStyle; /// should PrepareField set NumberFormat? 83 const sal_Bool bSetFormula; /// should PrepareField set Formula? 84 85 const sal_Bool bStringDefault; /// default: string-value = content 86 const sal_Bool bFormulaDefault; /// default: formula = content 87 88 public: 89 XMLValueImportHelper( 90 SvXMLImport& rImprt, /// XML Import 91 XMLTextImportHelper& rHlp, /// text import helper 92 sal_Bool bType, /// process type (PrepareField) 93 sal_Bool bStyle, /// process data style (P.F.) 94 sal_Bool bValue, /// process value (Prep.Field) 95 sal_Bool bFormula); /// process formula (Prep.F.) 96 97 virtual ~XMLValueImportHelper(); 98 99 /// process attribute values 100 virtual void ProcessAttribute( sal_uInt16 nAttrToken, 101 const ::rtl::OUString& sAttrValue ); 102 103 /// prepare XTextField for insertion into document 104 virtual void PrepareField( 105 const ::com::sun::star::uno::Reference< 106 ::com::sun::star::beans::XPropertySet> & xPropertySet); 107 108 /// is value a string (rather than double)? 109 inline sal_Bool IsStringValue() { return bStringType; } 110 111 /// has format been read? 112 inline sal_Bool IsFormatOK() { return bFormatOK; } 113 114 inline void SetDefault(const ::rtl::OUString& sStr) { sDefault = sStr; } 115 }; 116 117 118 119 /** 120 * abstract parent class for all variable related fields 121 * - variable-set/get/decl (not -decls), 122 * - user-field-get/decl (not -decls), 123 * - sequence/-decl (not -decls), 124 * - expression, 125 * - text-input 126 * 127 * Processes the following attributes: 128 * - name 129 * - formula 130 * - display 131 * - value, value-type, data-style-name (via XMLValueImportHelper) 132 * - description. 133 * 134 * Each attribute has a corresponding member, a bool variable to indicate 135 * whether it was set or not, and a bool variable whether it should be set 136 * using the standard property name. 137 * 138 * bValid is set true, when name is found! 139 * (Most variable related fields are valid, if a name is 140 * found. However, some are always valid. In this case, setting bValid 141 * does not matter.) 142 */ 143 class XMLVarFieldImportContext : public XMLTextFieldImportContext 144 { 145 protected: 146 const ::rtl::OUString sPropertyContent; 147 const ::rtl::OUString sPropertyHint; 148 const ::rtl::OUString sPropertyHelp; 149 const ::rtl::OUString sPropertyTooltip; 150 const ::rtl::OUString sPropertyIsVisible; 151 const ::rtl::OUString sPropertyIsDisplayFormula; 152 const ::rtl::OUString sPropertyCurrentPresentation; 153 154 private: 155 ::rtl::OUString sName; /// name attribute 156 ::rtl::OUString sFormula; /// formula attribute 157 ::rtl::OUString sDescription; /// description 158 ::rtl::OUString sHelp; /// help text 159 ::rtl::OUString sHint; /// hint 160 XMLValueImportHelper aValueHelper; /// value, value-type, and style 161 sal_Bool bDisplayFormula; /// display formula?(rather than value) 162 sal_Bool bDisplayNone; /// hide field? 163 164 sal_Bool bNameOK; /// sName was set 165 sal_Bool bFormulaOK; /// sFormula was set 166 sal_Bool bDescriptionOK; /// sDescription was set 167 sal_Bool bHelpOK; /// sHelp was set 168 sal_Bool bHintOK; /// sHint was set 169 sal_Bool bDisplayOK; /// sDisplayFormula/-None were set 170 171 sal_Bool bSetName; /// set sName with ???-property 172 sal_Bool bSetFormula; /// set Formula property 173 sal_Bool bSetFormulaDefault; /// use content as default for formula 174 sal_Bool bSetDescription; /// set sDescription with Hint-property 175 sal_Bool bSetHelp; 176 sal_Bool bSetHint; 177 sal_Bool bSetVisible; /// set IsVisible 178 sal_Bool bSetDisplayFormula; /// set DisplayFormula (sub type???) 179 sal_Bool bSetPresentation; /// set presentation frm elem. content? 180 181 public: 182 183 TYPEINFO(); 184 185 XMLVarFieldImportContext( 186 // for XMLTextFieldImportContext: 187 SvXMLImport& rImport, /// XML Import 188 XMLTextImportHelper& rHlp, /// text import helper 189 const sal_Char* pServiceName, /// name of SO API service 190 sal_uInt16 nPrfx, /// namespace prefix 191 const ::rtl::OUString& rLocalName, /// element name w/o prefix 192 // config variables for PrepareField behavior: 193 sal_Bool bName, /// set sName with ???-property 194 sal_Bool bFormula, /// set Formula property 195 sal_Bool bFormulaDefault, /// use content as default for formula 196 sal_Bool bDescription, /// set sDescription with Hint-property 197 sal_Bool bHelp, 198 sal_Bool bHint, 199 sal_Bool bVisible, /// set IsVisible (display attr) 200 sal_Bool bDisplayFormula, /// set ??? (display attr.) 201 sal_Bool bType, /// set value type with ???-property 202 sal_Bool bStyle, /// set data style (NumberFormat-Prop.) 203 sal_Bool bValue, /// set value with Content/Value-Prop. 204 sal_Bool bPresentation); /// set presentation from elem. content 205 206 protected: 207 /// process attribute values 208 virtual void ProcessAttribute( sal_uInt16 nAttrToken, 209 const ::rtl::OUString& sAttrValue ); 210 211 /// prepare XTextField for insertion into document 212 virtual void PrepareField( 213 const ::com::sun::star::uno::Reference< 214 ::com::sun::star::beans::XPropertySet> & xPropertySet); 215 216 // various accessor methods: 217 inline ::rtl::OUString GetName() { return sName; } 218 inline sal_Bool IsStringValue() { return aValueHelper.IsStringValue();} 219 inline sal_Bool IsNameOK() { return bNameOK; } 220 inline sal_Bool IsFormulaOK() { return bFormulaOK; } 221 inline sal_Bool IsDescriptionOK() { return bDescriptionOK; } 222 inline sal_Bool IsDisplayOK() { return bDisplayOK; } 223 }; 224 225 226 227 /** import variable get fields (<text:variable-get>) */ 228 class XMLVariableGetFieldImportContext : public XMLVarFieldImportContext 229 { 230 const ::rtl::OUString sPropertySubType; 231 232 public: 233 234 TYPEINFO(); 235 236 XMLVariableGetFieldImportContext( 237 SvXMLImport& rImport, /// XML Import 238 XMLTextImportHelper& rHlp, /// Text import helper 239 sal_uInt16 nPrfx, /// namespace prefix 240 const ::rtl::OUString& rLocalName); /// element name w/o prefix 241 242 243 protected: 244 /// prepare XTextField for insertion into document 245 virtual void PrepareField( 246 const ::com::sun::star::uno::Reference< 247 ::com::sun::star::beans::XPropertySet> & xPropertySet); 248 }; 249 250 251 252 /** import expression fields (<text:expression>) */ 253 class XMLExpressionFieldImportContext : public XMLVarFieldImportContext 254 { 255 const ::rtl::OUString sPropertySubType; 256 257 public: 258 259 TYPEINFO(); 260 261 XMLExpressionFieldImportContext( 262 SvXMLImport& rImport, /// XML Import 263 XMLTextImportHelper& rHlp, /// Text import helper 264 sal_uInt16 nPrfx, /// namespace prefix 265 const ::rtl::OUString& sLocalName); /// element name w/o prefix 266 267 protected: 268 virtual void PrepareField( 269 const ::com::sun::star::uno::Reference< 270 ::com::sun::star::beans::XPropertySet> & xPropertySet); 271 }; 272 273 /*** import text input fields (<text:text-input>) */ 274 class XMLTextInputFieldImportContext : public XMLVarFieldImportContext 275 { 276 const ::rtl::OUString sPropertyContent; 277 278 public: 279 280 TYPEINFO(); 281 282 XMLTextInputFieldImportContext( 283 SvXMLImport& rImport, /// XML Import 284 XMLTextImportHelper& rHlp, /// Text import helper 285 sal_uInt16 nPrfx, /// namespace prefix 286 const ::rtl::OUString& sLocalName); /// element name w/o prefix 287 288 protected: 289 virtual void PrepareField( 290 const ::com::sun::star::uno::Reference< 291 ::com::sun::star::beans::XPropertySet> & xPropertySet); 292 }; 293 294 295 296 297 298 299 /** 300 * uperclass for variable/user-set, var/user-input, and sequence fields 301 * inds field master of appropriate type and attaches field to it. 302 */ 303 class XMLSetVarFieldImportContext : public XMLVarFieldImportContext 304 { 305 const VarType eFieldType; 306 307 public: 308 309 TYPEINFO(); 310 311 XMLSetVarFieldImportContext( 312 // for XMLTextFieldImportContext: 313 SvXMLImport& rImport, /// see XMLTextFieldImportContext 314 XMLTextImportHelper& rHlp, /// see XMLTextFieldImportContext 315 const sal_Char* pServiceName, /// see XMLTextFieldImportContext 316 sal_uInt16 nPrfx, /// see XMLTextFieldImportContext 317 const ::rtl::OUString& rLocalName, /// see XMLTextFieldImportContext 318 // for finding appropriate field master (see EndElement()) 319 VarType eVarType, /// variable type 320 // config variables: 321 sal_Bool bName, /// see XMLTextFieldImportContext 322 sal_Bool bFormula, /// see XMLTextFieldImportContext 323 sal_Bool bFormulaDefault, /// see XMLTextFieldImportContext 324 sal_Bool bDescription, /// see XMLTextFieldImportContext 325 sal_Bool bHelp, /// see XMLTextFieldImportContext 326 sal_Bool bHint, /// see XMLTextFieldImportContext 327 sal_Bool bVisible, /// see XMLTextFieldImportContext 328 sal_Bool bDisplayFormula, /// see XMLTextFieldImportContext 329 sal_Bool bType, /// see XMLTextFieldImportContext 330 sal_Bool bStyle, /// see XMLTextFieldImportContext 331 sal_Bool bValue, /// see XMLTextFieldImportContext 332 sal_Bool bPresentation); /// see XMLTextFieldImportContext 333 334 protected: 335 336 /// create XTextField, attach master and insert into document; 337 /// also calls PrepareTextField 338 virtual void EndElement(); 339 340 /// find appropriate field master 341 sal_Bool FindFieldMaster( 342 ::com::sun::star::uno::Reference< 343 ::com::sun::star::beans::XPropertySet> & xMaster); 344 }; 345 346 347 348 /** import variable set fields (<text:variable-set>) */ 349 class XMLVariableSetFieldImportContext : public XMLSetVarFieldImportContext 350 { 351 const ::rtl::OUString sPropertySubType; 352 353 public: 354 355 TYPEINFO(); 356 357 XMLVariableSetFieldImportContext( 358 SvXMLImport& rImport, /// XML Import 359 XMLTextImportHelper& rHlp, /// Text import helper 360 sal_uInt16 nPrfx, /// namespace prefix 361 const ::rtl::OUString& rLocalName); /// element name w/o prefix 362 363 protected: 364 /// prepare XTextField for insertion into document 365 virtual void PrepareField( 366 const ::com::sun::star::uno::Reference< 367 ::com::sun::star::beans::XPropertySet> & xPropertySet); 368 }; 369 370 371 372 /** variable input fields (<text:variable-input>) */ 373 class XMLVariableInputFieldImportContext : public XMLSetVarFieldImportContext 374 { 375 const ::rtl::OUString sPropertySubType; 376 const ::rtl::OUString sPropertyIsInput; 377 378 public: 379 380 TYPEINFO(); 381 382 XMLVariableInputFieldImportContext( 383 SvXMLImport& rImport, /// XML Import 384 XMLTextImportHelper& rHlp, /// Text import helper 385 sal_uInt16 nPrfx, /// namespace prefix 386 const ::rtl::OUString& rLocalName); /// element name w/o prefix 387 388 protected: 389 390 /// prepare XTextField for insertion into document 391 virtual void PrepareField( 392 const ::com::sun::star::uno::Reference< 393 ::com::sun::star::beans::XPropertySet> & xPropertySet); 394 }; 395 396 397 398 /** user fields (<text:user-field-get>) */ 399 class XMLUserFieldImportContext : public XMLSetVarFieldImportContext 400 { 401 402 public: 403 404 TYPEINFO(); 405 406 XMLUserFieldImportContext( 407 SvXMLImport& rImport, /// XML Import 408 XMLTextImportHelper& rHlp, /// Text import helper 409 sal_uInt16 nPrfx, /// namespace prefix 410 const ::rtl::OUString& rLocalName); /// element name w/o prefix 411 }; 412 413 /** user input fields (<text:user-field-input>) */ 414 class XMLUserFieldInputImportContext : public XMLVarFieldImportContext 415 { 416 417 public: 418 419 TYPEINFO(); 420 421 XMLUserFieldInputImportContext( 422 SvXMLImport& rImport, /// XML Import 423 XMLTextImportHelper& rHlp, /// Text import helper 424 sal_uInt16 nPrfx, /// namespace prefix 425 const ::rtl::OUString& rLocalName); /// element name w/o prefix 426 427 virtual void PrepareField( 428 const ::com::sun::star::uno::Reference< 429 ::com::sun::star::beans::XPropertySet> & xPropertySet); 430 }; 431 432 433 434 /** sequence fields (<text:sequence>) */ 435 class XMLSequenceFieldImportContext : public XMLSetVarFieldImportContext 436 { 437 const ::rtl::OUString sPropertyFormula; 438 const ::rtl::OUString sPropertyNumberFormat; 439 const ::rtl::OUString sPropertySequenceValue; 440 ::rtl::OUString sFormula; 441 ::rtl::OUString sNumFormat; 442 ::rtl::OUString sNumFormatSync; 443 ::rtl::OUString sRefName; 444 445 sal_Bool bRefNameOK; 446 447 public: 448 449 TYPEINFO(); 450 451 XMLSequenceFieldImportContext( 452 SvXMLImport& rImport, /// XML Import 453 XMLTextImportHelper& rHlp, /// Text import helper 454 sal_uInt16 nPrfx, /// namespace prefix 455 const ::rtl::OUString& rLocalName); /// element name w/o prefix 456 457 protected: 458 459 /// process attribute values 460 virtual void ProcessAttribute( sal_uInt16 nAttrToken, 461 const ::rtl::OUString& sAttrValue ); 462 463 /// prepare XTextField for insertion into document 464 virtual void PrepareField( 465 const ::com::sun::star::uno::Reference< 466 ::com::sun::star::beans::XPropertySet> & xPropertySet); 467 }; 468 469 470 471 472 473 474 /** 475 * variable declaration container for all variable fields 476 * (variable-decls, user-field-decls, sequence-decls) 477 */ 478 class XMLVariableDeclsImportContext : public SvXMLImportContext 479 { 480 enum VarType eVarDeclsContextType; 481 XMLTextImportHelper& rImportHelper; 482 483 public: 484 485 TYPEINFO(); 486 487 XMLVariableDeclsImportContext( 488 SvXMLImport& rImport, /// XML Import 489 XMLTextImportHelper& rHlp, /// text import helper 490 sal_uInt16 nPrfx, /// namespace prefix 491 const ::rtl::OUString& rLocalName, /// element name w/o prefix 492 enum VarType eVarType); /// variable type 493 494 virtual SvXMLImportContext *CreateChildContext( 495 sal_uInt16 nPrefix, 496 const ::rtl::OUString& rLocalName, 497 const ::com::sun::star::uno::Reference< 498 ::com::sun::star::xml::sax::XAttributeList> & xAttrList ); 499 }; 500 501 /** 502 * variable field declarations 503 * (variable-decl, user-field-decl, sequence-decl) 504 */ 505 class XMLVariableDeclImportContext : public SvXMLImportContext 506 { 507 const ::rtl::OUString sPropertyName; 508 const ::rtl::OUString sPropertySubType; 509 const ::rtl::OUString sPropertyNumberingLevel; 510 const ::rtl::OUString sPropertyNumberingSeparator; 511 const ::rtl::OUString sPropertyIsExpression; 512 513 ::rtl::OUString sName; 514 XMLValueImportHelper aValueHelper; 515 sal_Int8 nNumLevel; 516 sal_Unicode cSeparationChar; 517 518 public: 519 520 TYPEINFO(); 521 522 XMLVariableDeclImportContext( 523 SvXMLImport& rImport, /// XML Import 524 XMLTextImportHelper& rHlp, /// text import helper 525 sal_uInt16 nPrfx, /// namespace prefix 526 const ::rtl::OUString& rLocalName, /// element name w/o prefix 527 const ::com::sun::star::uno::Reference< /// list of element attributes 528 ::com::sun::star::xml::sax::XAttributeList> & xAttrList, 529 enum VarType eVarType); /// variable type 530 531 /// get field master for name and rename if appropriate 532 static sal_Bool FindFieldMaster(::com::sun::star::uno::Reference< 533 ::com::sun::star::beans::XPropertySet> & xMaster, 534 SvXMLImport& rImport, 535 XMLTextImportHelper& rHelper, 536 const ::rtl::OUString& sVarName, 537 enum VarType eVarType); 538 }; 539 540 541 542 /** import table formula fields (deprecated; for Writer 2.0 compatibility) */ 543 class XMLTableFormulaImportContext : public XMLTextFieldImportContext 544 { 545 const ::rtl::OUString sPropertyNumberFormat; 546 const ::rtl::OUString sPropertyContent; 547 const ::rtl::OUString sPropertyIsShowFormula; 548 const ::rtl::OUString sPropertyCurrentPresentation; 549 550 XMLValueImportHelper aValueHelper; 551 552 ::rtl::OUString sFormula; 553 sal_Bool bFormulaOK; 554 555 sal_Bool bIsShowFormula; 556 557 public: 558 559 TYPEINFO(); 560 561 XMLTableFormulaImportContext( 562 SvXMLImport& rImport, /// XML Import 563 XMLTextImportHelper& rHlp, /// text import helper 564 sal_uInt16 nPrfx, /// namespace prefix 565 const ::rtl::OUString& rLocalName); /// element name w/o prefix 566 virtual ~XMLTableFormulaImportContext(); 567 568 protected: 569 570 /// process attribute values 571 virtual void ProcessAttribute( sal_uInt16 nAttrToken, 572 const ::rtl::OUString& sAttrValue ); 573 574 /// prepare XTextField for insertion into document 575 virtual void PrepareField( 576 const ::com::sun::star::uno::Reference< 577 ::com::sun::star::beans::XPropertySet> & xPropertySet); 578 }; 579 580 581 582 /** import database display fields (<text:database-display>) */ 583 class XMLDatabaseDisplayImportContext : public XMLDatabaseFieldImportContext 584 { 585 const ::rtl::OUString sPropertyColumnName; 586 const ::rtl::OUString sPropertyDatabaseFormat; 587 const ::rtl::OUString sPropertyCurrentPresentation; 588 const ::rtl::OUString sPropertyIsVisible; 589 590 XMLValueImportHelper aValueHelper; 591 592 ::rtl::OUString sColumnName; 593 sal_Bool bColumnOK; 594 595 sal_Bool bDisplay; 596 sal_Bool bDisplayOK; 597 598 public: 599 600 TYPEINFO(); 601 602 XMLDatabaseDisplayImportContext( 603 SvXMLImport& rImport, /// XML Import 604 XMLTextImportHelper& rHlp, /// text import helper 605 sal_uInt16 nPrfx, /// namespace prefix 606 const ::rtl::OUString& rLocalName); /// element name w/o prefix 607 608 protected: 609 610 /// process attribute values 611 virtual void ProcessAttribute( sal_uInt16 nAttrToken, 612 const ::rtl::OUString& sAttrValue ); 613 614 /// create, prepare and insert database field master and database field 615 virtual void EndElement(); 616 }; 617 618 #endif 619