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 #include <tools/debug.hxx> 27 #include <XMLNumberStylesExport.hxx> 28 #include <XMLNumberStylesImport.hxx> 29 #include "xmloff/xmlnmspe.hxx" 30 #include <xmloff/xmlimp.hxx> 31 #include <xmloff/nmspmap.hxx> 32 #include <xmloff/xmltoken.hxx> 33 34 #include "sdxmlexp_impl.hxx" 35 #include "sdxmlimp_impl.hxx" 36 37 using namespace rtl; 38 using namespace ::xmloff::token; 39 40 struct SdXMLDataStyleNumber 41 { 42 enum XMLTokenEnum meNumberStyle; 43 sal_Bool mbLong; 44 sal_Bool mbTextual; 45 sal_Bool mbDecimal02; 46 const char* mpText; 47 } 48 aSdXMLDataStyleNumbers[] = 49 { 50 { XML_DAY, sal_False, sal_False, sal_False, NULL }, 51 { XML_DAY, sal_True, sal_False, sal_False, NULL }, 52 { XML_MONTH, sal_True, sal_False, sal_False, NULL }, 53 { XML_MONTH, sal_False, sal_True, sal_False, NULL }, 54 { XML_MONTH, sal_True, sal_True, sal_False, NULL }, 55 { XML_YEAR, sal_False, sal_False, sal_False, NULL }, 56 { XML_YEAR, sal_True, sal_False, sal_False, NULL }, 57 { XML_DAY_OF_WEEK, sal_False, sal_False, sal_False, NULL }, 58 { XML_DAY_OF_WEEK, sal_True, sal_False, sal_False, NULL }, 59 { XML_TEXT, sal_False, sal_False, sal_False, "." }, 60 { XML_TEXT, sal_False, sal_False, sal_False, " " }, 61 { XML_TEXT, sal_False, sal_False, sal_False, ", " }, 62 { XML_TEXT, sal_False, sal_False, sal_False, ". " }, 63 { XML_HOURS, sal_False, sal_False, sal_False, NULL }, 64 { XML_MINUTES, sal_False, sal_False, sal_False, NULL }, 65 { XML_TEXT, sal_False, sal_False, sal_False, ":" }, 66 { XML_AM_PM, sal_False, sal_False, sal_False, NULL }, 67 { XML_SECONDS, sal_False, sal_False, sal_False, NULL }, 68 { XML_SECONDS, sal_False, sal_False, sal_True, NULL }, 69 { XML_TOKEN_INVALID, 0, 0, 0, NULL } 70 }; 71 72 // date 73 74 #define DATA_STYLE_NUMBER_END 0 75 #define DATA_STYLE_NUMBER_DAY 1 // <number:day/> 76 #define DATA_STYLE_NUMBER_DAY_LONG 2 // <number:day number:style="long"/> 77 #define DATA_STYLE_NUMBER_MONTH_LONG 3 // <number:month number:style="long"/> 78 #define DATA_STYLE_NUMBER_MONTH_TEXT 4 // <number:month number:textual="true"/> 79 #define DATA_STYLE_NUMBER_MONTH_LONG_TEXT 5 // <number:month number:style="long" number:textual="true"/> 80 #define DATA_STYLE_NUMBER_YEAR 6 // <number:year/> 81 #define DATA_STYLE_NUMBER_YEAR_LONG 7 // <number:year number:style="long"/> 82 #define DATA_STYLE_NUMBER_DAYOFWEEK 8 // <number:day-of-week/> 83 #define DATA_STYLE_NUMBER_DAYOFWEEK_LONG 9 // <number:day-of-week number:style="long"/> 84 #define DATA_STYLE_NUMBER_TEXT_POINT 10 // <number:text>.</number:text> 85 #define DATA_STYLE_NUMBER_TEXT_SPACE 11 // <number:text> </number:text> 86 #define DATA_STYLE_NUMBER_TEXT_COMMASPACE 12 // <number:text>, </number:text> 87 #define DATA_STYLE_NUMBER_TEXT_POINTSPACE 13 // <number:text>. </number:text> 88 #define DATA_STYLE_NUMBER_HOURS 14 // <number:hours/> 89 #define DATA_STYLE_NUMBER_MINUTES 15 // <number:minutes/> 90 #define DATA_STYLE_NUMBER_TEXT_COLON 16 // <number:text>:</number:text> 91 #define DATA_STYLE_NUMBER_AMPM 17 // <number:am-pm/> 92 #define DATA_STYLE_NUMBER_SECONDS 18 // <number:seconds/> 93 #define DATA_STYLE_NUMBER_SECONDS_02 19 // <number:seconds number:/> 94 95 96 struct SdXMLFixedDataStyle 97 { 98 const char* mpName; 99 sal_Bool mbAutomatic; 100 sal_Bool mbDateStyle; 101 sal_uInt8 mpFormat[8]; 102 }; 103 104 const SdXMLFixedDataStyle aSdXML_Standard_Short = 105 { 106 "D1", sal_True, sal_True, 107 { 108 DATA_STYLE_NUMBER_DAY_LONG, 109 DATA_STYLE_NUMBER_TEXT_POINT, 110 DATA_STYLE_NUMBER_MONTH_LONG, 111 DATA_STYLE_NUMBER_TEXT_POINT, 112 DATA_STYLE_NUMBER_YEAR_LONG, 113 0, 0, 0 114 } 115 }; 116 117 const SdXMLFixedDataStyle aSdXML_Standard_Long = 118 { 119 "D2", sal_True, sal_True, 120 { 121 DATA_STYLE_NUMBER_DAYOFWEEK_LONG, 122 DATA_STYLE_NUMBER_TEXT_COMMASPACE, 123 DATA_STYLE_NUMBER_DAY, 124 DATA_STYLE_NUMBER_TEXT_POINTSPACE, 125 DATA_STYLE_NUMBER_MONTH_LONG_TEXT, 126 DATA_STYLE_NUMBER_TEXT_SPACE, 127 DATA_STYLE_NUMBER_YEAR_LONG, 128 0 129 } 130 }; 131 132 const SdXMLFixedDataStyle aSdXML_DateStyle_1 = 133 { 134 "D3", sal_False, sal_True, 135 { 136 DATA_STYLE_NUMBER_DAY_LONG, 137 DATA_STYLE_NUMBER_TEXT_POINT, 138 DATA_STYLE_NUMBER_MONTH_LONG, 139 DATA_STYLE_NUMBER_TEXT_POINT, 140 DATA_STYLE_NUMBER_YEAR, 141 0, 0, 0 142 } 143 }; 144 145 const SdXMLFixedDataStyle aSdXML_DateStyle_2 = 146 { 147 "D4", sal_False, sal_True, 148 { 149 DATA_STYLE_NUMBER_DAY_LONG, 150 DATA_STYLE_NUMBER_TEXT_POINT, 151 DATA_STYLE_NUMBER_MONTH_LONG, 152 DATA_STYLE_NUMBER_TEXT_POINT, 153 DATA_STYLE_NUMBER_YEAR_LONG, 154 0, 0, 0 155 } 156 }; 157 158 const SdXMLFixedDataStyle aSdXML_DateStyle_3 = 159 { 160 "D5", sal_False, sal_True, 161 { 162 DATA_STYLE_NUMBER_DAY, 163 DATA_STYLE_NUMBER_TEXT_POINTSPACE, 164 DATA_STYLE_NUMBER_MONTH_TEXT, 165 DATA_STYLE_NUMBER_TEXT_SPACE, 166 DATA_STYLE_NUMBER_YEAR_LONG, 167 0, 0, 0 168 } 169 }; 170 171 const SdXMLFixedDataStyle aSdXML_DateStyle_4 = 172 { 173 "D6", sal_False, sal_True, 174 { 175 DATA_STYLE_NUMBER_DAY, 176 DATA_STYLE_NUMBER_TEXT_POINTSPACE, 177 DATA_STYLE_NUMBER_MONTH_LONG_TEXT, 178 DATA_STYLE_NUMBER_TEXT_SPACE, 179 DATA_STYLE_NUMBER_YEAR_LONG, 180 0, 0, 0 181 } 182 }; 183 184 const SdXMLFixedDataStyle aSdXML_DateStyle_5 = 185 { 186 "D7", sal_False, sal_True, 187 { 188 DATA_STYLE_NUMBER_DAYOFWEEK, 189 DATA_STYLE_NUMBER_TEXT_COMMASPACE, 190 DATA_STYLE_NUMBER_DAY, 191 DATA_STYLE_NUMBER_TEXT_POINTSPACE, 192 DATA_STYLE_NUMBER_MONTH_LONG_TEXT, 193 DATA_STYLE_NUMBER_TEXT_SPACE, 194 DATA_STYLE_NUMBER_YEAR_LONG, 195 0 196 } 197 }; 198 199 const SdXMLFixedDataStyle aSdXML_DateStyle_6 = 200 { 201 "D8", sal_False, sal_True, 202 { 203 DATA_STYLE_NUMBER_DAYOFWEEK_LONG, 204 DATA_STYLE_NUMBER_TEXT_COMMASPACE, 205 DATA_STYLE_NUMBER_DAY, 206 DATA_STYLE_NUMBER_TEXT_POINTSPACE, 207 DATA_STYLE_NUMBER_MONTH_LONG_TEXT, 208 DATA_STYLE_NUMBER_TEXT_SPACE, 209 DATA_STYLE_NUMBER_YEAR_LONG, 210 0 211 } 212 }; 213 214 const SdXMLFixedDataStyle aSdXML_TimeStyle_1 = 215 { "T1", sal_True, sal_False, 216 { 217 DATA_STYLE_NUMBER_HOURS, 218 DATA_STYLE_NUMBER_TEXT_COLON, 219 DATA_STYLE_NUMBER_MINUTES, 220 DATA_STYLE_NUMBER_TEXT_COLON, 221 DATA_STYLE_NUMBER_SECONDS, 222 DATA_STYLE_NUMBER_AMPM, 223 0, 0, 224 } 225 }; 226 227 const SdXMLFixedDataStyle aSdXML_TimeStyle_2 = 228 { "T2", sal_False, sal_False, 229 { 230 DATA_STYLE_NUMBER_HOURS, 231 DATA_STYLE_NUMBER_TEXT_COLON, 232 DATA_STYLE_NUMBER_MINUTES, 233 0, 0, 0, 0, 0 234 } 235 }; 236 237 const SdXMLFixedDataStyle aSdXML_TimeStyle_3 = 238 { "T3", sal_False, sal_False, 239 { 240 DATA_STYLE_NUMBER_HOURS, 241 DATA_STYLE_NUMBER_TEXT_COLON, 242 DATA_STYLE_NUMBER_MINUTES, 243 DATA_STYLE_NUMBER_TEXT_COLON, 244 DATA_STYLE_NUMBER_SECONDS, 245 0, 0, 0 246 } 247 }; 248 249 const SdXMLFixedDataStyle aSdXML_TimeStyle_4 = 250 { "T4", sal_False, sal_False, 251 { 252 DATA_STYLE_NUMBER_HOURS, 253 DATA_STYLE_NUMBER_TEXT_COLON, 254 DATA_STYLE_NUMBER_MINUTES, 255 DATA_STYLE_NUMBER_TEXT_COLON, 256 DATA_STYLE_NUMBER_SECONDS_02, 257 0, 0, 0 258 } 259 }; 260 261 const SdXMLFixedDataStyle aSdXML_TimeStyle_5 = 262 { "T5", sal_False, sal_False, 263 { 264 DATA_STYLE_NUMBER_HOURS, 265 DATA_STYLE_NUMBER_TEXT_COLON, 266 DATA_STYLE_NUMBER_MINUTES, 267 DATA_STYLE_NUMBER_AMPM, 268 0, 0, 0, 0 269 } 270 }; 271 272 const SdXMLFixedDataStyle aSdXML_TimeStyle_6 = 273 { "T6", sal_False, sal_False, 274 { 275 DATA_STYLE_NUMBER_HOURS, 276 DATA_STYLE_NUMBER_TEXT_COLON, 277 DATA_STYLE_NUMBER_MINUTES, 278 DATA_STYLE_NUMBER_TEXT_COLON, 279 DATA_STYLE_NUMBER_SECONDS, 280 DATA_STYLE_NUMBER_AMPM, 281 0, 0 282 } 283 }; 284 285 const SdXMLFixedDataStyle aSdXML_TimeStyle_7 = 286 { "T7", sal_False, sal_False, 287 { 288 DATA_STYLE_NUMBER_HOURS, 289 DATA_STYLE_NUMBER_TEXT_COLON, 290 DATA_STYLE_NUMBER_MINUTES, 291 DATA_STYLE_NUMBER_TEXT_COLON, 292 DATA_STYLE_NUMBER_SECONDS_02, 293 DATA_STYLE_NUMBER_AMPM, 294 0, 0 295 } 296 }; 297 298 const SdXMLFixedDataStyle* aSdXMLFixedDateFormats[SdXMLDateFormatCount] = 299 { 300 &aSdXML_Standard_Short, 301 &aSdXML_Standard_Long, 302 &aSdXML_DateStyle_1, 303 &aSdXML_DateStyle_2, 304 &aSdXML_DateStyle_3, 305 &aSdXML_DateStyle_4, 306 &aSdXML_DateStyle_5, 307 &aSdXML_DateStyle_6, 308 }; 309 310 const SdXMLFixedDataStyle* aSdXMLFixedTimeFormats[SdXMLTimeFormatCount] = 311 { 312 &aSdXML_TimeStyle_1, 313 &aSdXML_TimeStyle_2, 314 &aSdXML_TimeStyle_3, 315 &aSdXML_TimeStyle_4, 316 &aSdXML_TimeStyle_5, 317 &aSdXML_TimeStyle_6, 318 &aSdXML_TimeStyle_7 319 }; 320 321 322 /////////////////////////////////////////////////////////////////////// 323 // export 324 325 #ifndef SVX_LIGHT 326 327 static void SdXMLExportDataStyleNumber( SdXMLExport& rExport, SdXMLDataStyleNumber& rElement ) 328 { 329 if( rElement.mbDecimal02 ) 330 { 331 rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, XML_2 ); 332 } 333 334 if( rElement.mbLong ) 335 { 336 rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_STYLE, XML_LONG ); 337 } 338 339 if( rElement.mbTextual ) 340 { 341 rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TEXTUAL, XML_TRUE ); 342 } 343 344 SvXMLElementExport aNumberStyle( rExport, XML_NAMESPACE_NUMBER, rElement.meNumberStyle, sal_True, sal_False ); 345 if( rElement.mpText ) 346 { 347 OUString sAttrValue( OUString::createFromAscii( rElement.mpText ) ); 348 rExport.GetDocHandler()->characters( sAttrValue ); 349 } 350 } 351 352 static void SdXMLExportStyle( SdXMLExport& rExport, const SdXMLFixedDataStyle* pStyle, const SdXMLFixedDataStyle* pStyle2 = NULL ) 353 { 354 OUString sAttrValue; 355 356 // name 357 sAttrValue = OUString::createFromAscii( pStyle->mpName ); 358 if( pStyle2 ) 359 sAttrValue += OUString::createFromAscii( pStyle2->mpName ); 360 361 rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, sAttrValue ); 362 363 if( pStyle->mbAutomatic ) 364 { 365 rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_AUTOMATIC_ORDER, XML_TRUE ); 366 } 367 368 SvXMLElementExport aElement( rExport, XML_NAMESPACE_NUMBER, pStyle->mbDateStyle ? XML_DATE_STYLE : XML_TIME_STYLE, sal_True, sal_True ); 369 370 do 371 { 372 373 const sal_uInt8* pElements = (const sal_uInt8*)&pStyle->mpFormat[0]; 374 375 while( *pElements ) 376 { 377 SdXMLDataStyleNumber& rElement = aSdXMLDataStyleNumbers[ (*pElements++) - 1 ]; 378 SdXMLExportDataStyleNumber( rExport, rElement ); 379 } 380 381 if( pStyle2 ) 382 { 383 SdXMLDataStyleNumber& rElement = aSdXMLDataStyleNumbers[ DATA_STYLE_NUMBER_TEXT_SPACE - 1 ]; 384 SdXMLExportDataStyleNumber( rExport, rElement ); 385 } 386 387 pStyle = pStyle2; 388 pStyle2 = NULL; 389 } 390 while( pStyle ); 391 } 392 393 void SdXMLNumberStylesExporter::exportTimeStyle( SdXMLExport& rExport, sal_Int32 nStyle ) 394 { 395 DBG_ASSERT( (nStyle >= 0) && (nStyle < SdXMLTimeFormatCount), "Unknown time style!" ); 396 if( (nStyle >= 0) && (nStyle < SdXMLTimeFormatCount) ) 397 SdXMLExportStyle( rExport, aSdXMLFixedTimeFormats[ nStyle ] ); 398 } 399 400 void SdXMLNumberStylesExporter::exportDateStyle( SdXMLExport& rExport, sal_Int32 nStyle ) 401 { 402 if( nStyle > 0x0f ) 403 { 404 int nDateStyle = nStyle & 0x0f; 405 bool bHasDate = nDateStyle != 0; 406 407 if( nDateStyle > 1 ) 408 nDateStyle -= 2; 409 410 DBG_ASSERT( (nDateStyle >= 0) && (nDateStyle < SdXMLDateFormatCount), "unknown date style!" ); 411 412 int nTimeStyle = (nStyle >> 4) & 0x0f; 413 bool bHasTime = nTimeStyle != 0; 414 415 if( nTimeStyle > 1 ) 416 nTimeStyle -= 2; 417 418 DBG_ASSERT( (nTimeStyle >= 0) && (nTimeStyle < SdXMLTimeFormatCount), "Unknown time style!" ); 419 420 if( (nDateStyle >= 0) && (nDateStyle < SdXMLDateFormatCount) && (nTimeStyle >= 0) && (nTimeStyle < SdXMLTimeFormatCount) ) 421 { 422 if( bHasDate ) 423 { 424 if( bHasTime ) 425 { 426 SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nDateStyle ], aSdXMLFixedTimeFormats[ nTimeStyle ] ); 427 } 428 else 429 { 430 SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nDateStyle ] ); 431 } 432 } 433 else if( bHasTime ) 434 { 435 SdXMLExportStyle( rExport, aSdXMLFixedTimeFormats[ nTimeStyle ] ); 436 } 437 } 438 } 439 else 440 { 441 DBG_ASSERT( (nStyle >= 0) && (nStyle < SdXMLDateFormatCount), "unknown date style!" ); 442 if( (nStyle >= 0) && (nStyle < SdXMLDateFormatCount) ) 443 SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nStyle ] ); 444 } 445 } 446 447 OUString SdXMLNumberStylesExporter::getTimeStyleName(const sal_Int32 nTimeFormat ) 448 { 449 sal_Int32 nFormat = nTimeFormat; 450 if( nFormat > 1 ) 451 nFormat -= 2; 452 453 if( (nFormat >= 0) && (nFormat < SdXMLTimeFormatCount) ) 454 { 455 return OUString::createFromAscii(aSdXMLFixedTimeFormats[nFormat]->mpName ); 456 } 457 else 458 { 459 return OUString(); 460 } 461 } 462 463 OUString SdXMLNumberStylesExporter::getDateStyleName(const sal_Int32 nDateFormat ) 464 { 465 sal_Int32 nFormat = nDateFormat; 466 467 if( nFormat > 0x0f ) 468 { 469 OUString aStr; 470 if( nFormat & 0x0f ) 471 aStr = getDateStyleName( nFormat & 0x0f ); 472 aStr += getTimeStyleName( (nFormat >> 4) & 0x0f ); 473 return aStr; 474 } 475 476 if( nFormat > 1 ) 477 nFormat -= 2; 478 479 if( (nFormat >= 0) && (nFormat < SdXMLDateFormatCount) ) 480 { 481 return OUString::createFromAscii(aSdXMLFixedDateFormats[nFormat]->mpName ); 482 } 483 else 484 { 485 return OUString(); 486 } 487 } 488 489 #endif // #ifndef SVX_LIGHT 490 491 492 /////////////////////////////////////////////////////////////////////// 493 // import 494 495 class SdXMLNumberFormatMemberImportContext : public SvXMLImportContext 496 { 497 private: 498 SdXMLNumberFormatImportContext* mpParent; 499 500 OUString maNumberStyle; 501 sal_Bool mbLong; 502 sal_Bool mbTextual; 503 sal_Bool mbDecimal02; 504 OUString maText; 505 SvXMLImportContext* mpSlaveContext; 506 507 public: 508 TYPEINFO(); 509 510 SdXMLNumberFormatMemberImportContext( SvXMLImport& rImport, 511 sal_uInt16 nPrfx, 512 const rtl::OUString& rLocalName, 513 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, 514 SdXMLNumberFormatImportContext* pParent, 515 SvXMLImportContext* pSlaveContext ); 516 virtual ~SdXMLNumberFormatMemberImportContext(); 517 518 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, 519 const ::rtl::OUString& rLocalName, 520 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); 521 522 virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ); 523 524 virtual void EndElement(); 525 526 virtual void Characters( const ::rtl::OUString& rChars ); 527 }; 528 529 TYPEINIT1( SdXMLNumberFormatMemberImportContext, SvXMLImportContext ); 530 531 SdXMLNumberFormatMemberImportContext::SdXMLNumberFormatMemberImportContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, SdXMLNumberFormatImportContext* pParent, SvXMLImportContext* pSlaveContext ) 532 : SvXMLImportContext(rImport, nPrfx, rLocalName), 533 mpParent( pParent ), 534 maNumberStyle( rLocalName ), 535 mpSlaveContext( pSlaveContext ) 536 { 537 mbLong = sal_False; 538 mbTextual = sal_False; 539 mbDecimal02 = sal_False; 540 541 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 542 for(sal_Int16 i=0; i < nAttrCount; i++) 543 { 544 OUString sAttrName = xAttrList->getNameByIndex( i ); 545 OUString aLocalName; 546 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 547 OUString sValue = xAttrList->getValueByIndex( i ); 548 549 if( nPrefix == XML_NAMESPACE_NUMBER ) 550 { 551 if( IsXMLToken( aLocalName, XML_DECIMAL_PLACES ) ) 552 { 553 mbDecimal02 = IsXMLToken( sValue, XML_2 ); 554 } 555 else if( IsXMLToken( aLocalName, XML_STYLE ) ) 556 { 557 mbLong = IsXMLToken( sValue, XML_LONG ); 558 } 559 else if( IsXMLToken( aLocalName, XML_TEXTUAL ) ) 560 { 561 mbTextual = IsXMLToken( sValue, XML_TRUE ); 562 } 563 } 564 } 565 566 } 567 568 SdXMLNumberFormatMemberImportContext::~SdXMLNumberFormatMemberImportContext() 569 { 570 } 571 572 SvXMLImportContext *SdXMLNumberFormatMemberImportContext::CreateChildContext( sal_uInt16 nPrefix, 573 const ::rtl::OUString& rLocalName, 574 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) 575 { 576 return mpSlaveContext->CreateChildContext( nPrefix, rLocalName, xAttrList ); 577 } 578 579 void SdXMLNumberFormatMemberImportContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList ) 580 { 581 mpSlaveContext->StartElement( xAttrList ); 582 } 583 584 void SdXMLNumberFormatMemberImportContext::EndElement() 585 { 586 mpSlaveContext->EndElement(); 587 588 if( mpParent ) 589 mpParent->add( maNumberStyle, mbLong, mbTextual, mbDecimal02, maText ); 590 } 591 592 void SdXMLNumberFormatMemberImportContext::Characters( const ::rtl::OUString& rChars ) 593 { 594 mpSlaveContext->Characters( rChars ); 595 maText += rChars; 596 } 597 598 TYPEINIT1( SdXMLNumberFormatImportContext, SvXMLImportContext ); 599 600 601 SdXMLNumberFormatImportContext::SdXMLNumberFormatImportContext( SdXMLImport& rImport, sal_uInt16 nPrfx, const rtl::OUString& rLocalName, SvXMLNumImpData* pNewData, sal_uInt16 nNewType, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList, SvXMLStylesContext& rStyles) 602 : SvXMLNumFormatContext(rImport, nPrfx, rLocalName, pNewData, nNewType, xAttrList, rStyles), 603 mrImport( rImport ), 604 mbAutomatic( sal_False ), 605 mnIndex(0), 606 mnKey( -1 ) 607 { 608 mbTimeStyle = IsXMLToken( rLocalName, XML_TIME_STYLE ); 609 610 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; 611 for(sal_Int16 i=0; i < nAttrCount; i++) 612 { 613 OUString sAttrName = xAttrList->getNameByIndex( i ); 614 OUString aLocalName; 615 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); 616 OUString sValue = xAttrList->getValueByIndex( i ); 617 618 if( nPrefix == XML_NAMESPACE_NUMBER ) 619 { 620 if( IsXMLToken( aLocalName, XML_AUTOMATIC_ORDER ) ) 621 { 622 mbAutomatic = IsXMLToken( sValue, XML_TRUE ); 623 } 624 } 625 } 626 } 627 628 SdXMLNumberFormatImportContext::~SdXMLNumberFormatImportContext() 629 { 630 } 631 632 void SdXMLNumberFormatImportContext::add( OUString& rNumberStyle, sal_Bool bLong, sal_Bool bTextual, sal_Bool bDecimal02, OUString& rText ) 633 { 634 if( mnIndex == -1 || mnIndex == 16 ) 635 { 636 mnIndex = -1; 637 return; 638 } 639 640 const SdXMLDataStyleNumber* pStyleMember = aSdXMLDataStyleNumbers; 641 for( sal_uInt8 nIndex = 0; pStyleMember->meNumberStyle != XML_TOKEN_INVALID; nIndex++, pStyleMember++ ) 642 { 643 if( (IsXMLToken(rNumberStyle, pStyleMember->meNumberStyle) && 644 (pStyleMember->mbLong == bLong) && 645 (pStyleMember->mbTextual == bTextual) && 646 (pStyleMember->mbDecimal02 == bDecimal02) && 647 ( ( (pStyleMember->mpText == NULL) && (rText.getLength() == 0) ) || 648 ( pStyleMember->mpText && (rText.compareToAscii( pStyleMember->mpText ) == 0 )) ) ) ) 649 { 650 mnElements[mnIndex++] = nIndex + 1; 651 return; 652 } 653 } 654 } 655 656 bool SdXMLNumberFormatImportContext::compareStyle( const SdXMLFixedDataStyle* pStyle, sal_Int16& nIndex ) const 657 { 658 if( (pStyle->mbAutomatic != mbAutomatic) && (nIndex == 0)) 659 return sal_False; 660 661 sal_Int16 nCompareIndex; 662 for( nCompareIndex = 0; nCompareIndex < 8; nIndex++, nCompareIndex++ ) 663 { 664 if( pStyle->mpFormat[nCompareIndex] != mnElements[nIndex] ) 665 return sal_False; 666 } 667 668 return sal_True; 669 } 670 671 void SdXMLNumberFormatImportContext::EndElement() 672 { 673 SvXMLNumFormatContext::EndElement(); 674 675 for( ; mnIndex < 16; mnIndex++ ) 676 { 677 mnElements[mnIndex] = 0; 678 } 679 680 if( mbTimeStyle ) 681 { 682 // compare import with all time styles 683 for( sal_Int16 nFormat = 0; nFormat < SdXMLTimeFormatCount; nFormat++ ) 684 { 685 sal_Int16 nIndex = 0; 686 if( compareStyle( aSdXMLFixedTimeFormats[nFormat], nIndex ) ) 687 { 688 mnKey = nFormat + 2; 689 break; 690 } 691 } 692 } 693 else 694 { 695 // compare import with all date styles 696 for( sal_Int16 nFormat = 0; nFormat < SdXMLDateFormatCount; nFormat++ ) 697 { 698 sal_Int16 nIndex = 0; 699 if( compareStyle( aSdXMLFixedDateFormats[nFormat], nIndex ) ) 700 { 701 mnKey = nFormat + 2; 702 break; 703 } 704 else if( mnElements[nIndex] == DATA_STYLE_NUMBER_TEXT_SPACE ) 705 { 706 // if its a valid date ending with a space, see if a time style follows 707 for( sal_Int16 nTimeFormat = 0; nTimeFormat < SdXMLTimeFormatCount; nTimeFormat++ ) 708 { 709 sal_Int16 nIndex2 = nIndex + 1; 710 if( compareStyle( aSdXMLFixedTimeFormats[nTimeFormat], nIndex2 ) ) 711 { 712 mnKey = (nFormat + 2) | ((nTimeFormat + 2) << 4); 713 break; 714 } 715 } 716 } 717 } 718 719 // no date style found? maybe its an extended time style 720 if( mnKey == -1 ) 721 { 722 // compare import with all time styles 723 for( sal_Int16 nFormat = 0; nFormat < SdXMLTimeFormatCount; nFormat++ ) 724 { 725 sal_Int16 nIndex = 0; 726 if( compareStyle( aSdXMLFixedTimeFormats[nFormat], nIndex ) ) 727 { 728 mnKey = (nFormat + 2) << 4; 729 break; 730 } 731 } 732 } 733 } 734 } 735 736 SvXMLImportContext * SdXMLNumberFormatImportContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList ) 737 { 738 return new SdXMLNumberFormatMemberImportContext( GetImport(), nPrefix, rLocalName, xAttrList, this, SvXMLNumFormatContext::CreateChildContext( nPrefix, rLocalName, xAttrList ) ); 739 } 740