Update ooo320-m1
[ooovba.git] / xmloff / source / draw / XMLNumberStyles.cxx
blob34b89764fdce91fbdcd71bb1e683670132f61dce
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLNumberStyles.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <tools/debug.hxx>
34 #include <XMLNumberStylesExport.hxx>
35 #include <XMLNumberStylesImport.hxx>
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmlimp.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <xmloff/xmltoken.hxx>
41 #include "sdxmlexp_impl.hxx"
42 #include "sdxmlimp_impl.hxx"
44 using namespace rtl;
45 using namespace ::xmloff::token;
47 struct SdXMLDataStyleNumber
49 enum XMLTokenEnum meNumberStyle;
50 sal_Bool mbLong;
51 sal_Bool mbTextual;
52 sal_Bool mbDecimal02;
53 const char* mpText;
55 aSdXMLDataStyleNumbers[] =
57 { XML_DAY, sal_False, sal_False, sal_False, NULL },
58 { XML_DAY, sal_True, sal_False, sal_False, NULL },
59 { XML_MONTH, sal_True, sal_False, sal_False, NULL },
60 { XML_MONTH, sal_False, sal_True, sal_False, NULL },
61 { XML_MONTH, sal_True, sal_True, sal_False, NULL },
62 { XML_YEAR, sal_False, sal_False, sal_False, NULL },
63 { XML_YEAR, sal_True, sal_False, sal_False, NULL },
64 { XML_DAY_OF_WEEK, sal_False, sal_False, sal_False, NULL },
65 { XML_DAY_OF_WEEK, sal_True, sal_False, sal_False, NULL },
66 { XML_TEXT, sal_False, sal_False, sal_False, "." },
67 { XML_TEXT, sal_False, sal_False, sal_False, " " },
68 { XML_TEXT, sal_False, sal_False, sal_False, ", " },
69 { XML_TEXT, sal_False, sal_False, sal_False, ". " },
70 { XML_HOURS, sal_False, sal_False, sal_False, NULL },
71 { XML_MINUTES, sal_False, sal_False, sal_False, NULL },
72 { XML_TEXT, sal_False, sal_False, sal_False, ":" },
73 { XML_AM_PM, sal_False, sal_False, sal_False, NULL },
74 { XML_SECONDS, sal_False, sal_False, sal_False, NULL },
75 { XML_SECONDS, sal_False, sal_False, sal_True, NULL },
76 { XML_TOKEN_INVALID, 0, 0, 0, NULL }
79 // date
81 #define DATA_STYLE_NUMBER_END 0
82 #define DATA_STYLE_NUMBER_DAY 1 // <number:day/>
83 #define DATA_STYLE_NUMBER_DAY_LONG 2 // <number:day number:style="long"/>
84 #define DATA_STYLE_NUMBER_MONTH_LONG 3 // <number:month number:style="long"/>
85 #define DATA_STYLE_NUMBER_MONTH_TEXT 4 // <number:month number:textual="true"/>
86 #define DATA_STYLE_NUMBER_MONTH_LONG_TEXT 5 // <number:month number:style="long" number:textual="true"/>
87 #define DATA_STYLE_NUMBER_YEAR 6 // <number:year/>
88 #define DATA_STYLE_NUMBER_YEAR_LONG 7 // <number:year number:style="long"/>
89 #define DATA_STYLE_NUMBER_DAYOFWEEK 8 // <number:day-of-week/>
90 #define DATA_STYLE_NUMBER_DAYOFWEEK_LONG 9 // <number:day-of-week number:style="long"/>
91 #define DATA_STYLE_NUMBER_TEXT_POINT 10 // <number:text>.</number:text>
92 #define DATA_STYLE_NUMBER_TEXT_SPACE 11 // <number:text> </number:text>
93 #define DATA_STYLE_NUMBER_TEXT_COMMASPACE 12 // <number:text>, </number:text>
94 #define DATA_STYLE_NUMBER_TEXT_POINTSPACE 13 // <number:text>. </number:text>
95 #define DATA_STYLE_NUMBER_HOURS 14 // <number:hours/>
96 #define DATA_STYLE_NUMBER_MINUTES 15 // <number:minutes/>
97 #define DATA_STYLE_NUMBER_TEXT_COLON 16 // <number:text>:</number:text>
98 #define DATA_STYLE_NUMBER_AMPM 17 // <number:am-pm/>
99 #define DATA_STYLE_NUMBER_SECONDS 18 // <number:seconds/>
100 #define DATA_STYLE_NUMBER_SECONDS_02 19 // <number:seconds number:/>
103 struct SdXMLFixedDataStyle
105 const char* mpName;
106 sal_Bool mbAutomatic;
107 sal_Bool mbDateStyle;
108 sal_uInt8 mpFormat[8];
111 const SdXMLFixedDataStyle aSdXML_Standard_Short =
113 "D1", sal_True, sal_True,
115 DATA_STYLE_NUMBER_DAY_LONG,
116 DATA_STYLE_NUMBER_TEXT_POINT,
117 DATA_STYLE_NUMBER_MONTH_LONG,
118 DATA_STYLE_NUMBER_TEXT_POINT,
119 DATA_STYLE_NUMBER_YEAR_LONG,
120 0, 0, 0
124 const SdXMLFixedDataStyle aSdXML_Standard_Long =
126 "D2", sal_True, sal_True,
128 DATA_STYLE_NUMBER_DAYOFWEEK_LONG,
129 DATA_STYLE_NUMBER_TEXT_COMMASPACE,
130 DATA_STYLE_NUMBER_DAY,
131 DATA_STYLE_NUMBER_TEXT_POINTSPACE,
132 DATA_STYLE_NUMBER_MONTH_LONG_TEXT,
133 DATA_STYLE_NUMBER_TEXT_SPACE,
134 DATA_STYLE_NUMBER_YEAR_LONG,
139 const SdXMLFixedDataStyle aSdXML_DateStyle_1 =
141 "D3", sal_False, sal_True,
143 DATA_STYLE_NUMBER_DAY_LONG,
144 DATA_STYLE_NUMBER_TEXT_POINT,
145 DATA_STYLE_NUMBER_MONTH_LONG,
146 DATA_STYLE_NUMBER_TEXT_POINT,
147 DATA_STYLE_NUMBER_YEAR,
148 0, 0, 0
152 const SdXMLFixedDataStyle aSdXML_DateStyle_2 =
154 "D4", sal_False, sal_True,
156 DATA_STYLE_NUMBER_DAY_LONG,
157 DATA_STYLE_NUMBER_TEXT_POINT,
158 DATA_STYLE_NUMBER_MONTH_LONG,
159 DATA_STYLE_NUMBER_TEXT_POINT,
160 DATA_STYLE_NUMBER_YEAR_LONG,
161 0, 0, 0
165 const SdXMLFixedDataStyle aSdXML_DateStyle_3 =
167 "D5", sal_False, sal_True,
169 DATA_STYLE_NUMBER_DAY,
170 DATA_STYLE_NUMBER_TEXT_POINTSPACE,
171 DATA_STYLE_NUMBER_MONTH_TEXT,
172 DATA_STYLE_NUMBER_TEXT_SPACE,
173 DATA_STYLE_NUMBER_YEAR_LONG,
174 0, 0, 0
178 const SdXMLFixedDataStyle aSdXML_DateStyle_4 =
180 "D6", sal_False, sal_True,
182 DATA_STYLE_NUMBER_DAY,
183 DATA_STYLE_NUMBER_TEXT_POINTSPACE,
184 DATA_STYLE_NUMBER_MONTH_LONG_TEXT,
185 DATA_STYLE_NUMBER_TEXT_SPACE,
186 DATA_STYLE_NUMBER_YEAR_LONG,
187 0, 0, 0
191 const SdXMLFixedDataStyle aSdXML_DateStyle_5 =
193 "D7", sal_False, sal_True,
195 DATA_STYLE_NUMBER_DAYOFWEEK,
196 DATA_STYLE_NUMBER_TEXT_COMMASPACE,
197 DATA_STYLE_NUMBER_DAY,
198 DATA_STYLE_NUMBER_TEXT_POINTSPACE,
199 DATA_STYLE_NUMBER_MONTH_LONG_TEXT,
200 DATA_STYLE_NUMBER_TEXT_SPACE,
201 DATA_STYLE_NUMBER_YEAR_LONG,
206 const SdXMLFixedDataStyle aSdXML_DateStyle_6 =
208 "D8", sal_False, sal_True,
210 DATA_STYLE_NUMBER_DAYOFWEEK_LONG,
211 DATA_STYLE_NUMBER_TEXT_COMMASPACE,
212 DATA_STYLE_NUMBER_DAY,
213 DATA_STYLE_NUMBER_TEXT_POINTSPACE,
214 DATA_STYLE_NUMBER_MONTH_LONG_TEXT,
215 DATA_STYLE_NUMBER_TEXT_SPACE,
216 DATA_STYLE_NUMBER_YEAR_LONG,
221 const SdXMLFixedDataStyle aSdXML_TimeStyle_1 =
222 { "T1", sal_True, sal_False,
224 DATA_STYLE_NUMBER_HOURS,
225 DATA_STYLE_NUMBER_TEXT_COLON,
226 DATA_STYLE_NUMBER_MINUTES,
227 DATA_STYLE_NUMBER_TEXT_COLON,
228 DATA_STYLE_NUMBER_SECONDS,
229 DATA_STYLE_NUMBER_AMPM,
230 0, 0,
234 const SdXMLFixedDataStyle aSdXML_TimeStyle_2 =
235 { "T2", sal_False, sal_False,
237 DATA_STYLE_NUMBER_HOURS,
238 DATA_STYLE_NUMBER_TEXT_COLON,
239 DATA_STYLE_NUMBER_MINUTES,
240 0, 0, 0, 0, 0
244 const SdXMLFixedDataStyle aSdXML_TimeStyle_3 =
245 { "T3", sal_False, sal_False,
247 DATA_STYLE_NUMBER_HOURS,
248 DATA_STYLE_NUMBER_TEXT_COLON,
249 DATA_STYLE_NUMBER_MINUTES,
250 DATA_STYLE_NUMBER_TEXT_COLON,
251 DATA_STYLE_NUMBER_SECONDS,
252 0, 0, 0
256 const SdXMLFixedDataStyle aSdXML_TimeStyle_4 =
257 { "T4", sal_False, sal_False,
259 DATA_STYLE_NUMBER_HOURS,
260 DATA_STYLE_NUMBER_TEXT_COLON,
261 DATA_STYLE_NUMBER_MINUTES,
262 DATA_STYLE_NUMBER_TEXT_COLON,
263 DATA_STYLE_NUMBER_SECONDS_02,
264 0, 0, 0
268 const SdXMLFixedDataStyle aSdXML_TimeStyle_5 =
269 { "T5", sal_False, sal_False,
271 DATA_STYLE_NUMBER_HOURS,
272 DATA_STYLE_NUMBER_TEXT_COLON,
273 DATA_STYLE_NUMBER_MINUTES,
274 DATA_STYLE_NUMBER_AMPM,
275 0, 0, 0, 0
279 const SdXMLFixedDataStyle aSdXML_TimeStyle_6 =
280 { "T6", sal_False, sal_False,
282 DATA_STYLE_NUMBER_HOURS,
283 DATA_STYLE_NUMBER_TEXT_COLON,
284 DATA_STYLE_NUMBER_MINUTES,
285 DATA_STYLE_NUMBER_TEXT_COLON,
286 DATA_STYLE_NUMBER_SECONDS,
287 DATA_STYLE_NUMBER_AMPM,
288 0, 0
292 const SdXMLFixedDataStyle aSdXML_TimeStyle_7 =
293 { "T7", sal_False, sal_False,
295 DATA_STYLE_NUMBER_HOURS,
296 DATA_STYLE_NUMBER_TEXT_COLON,
297 DATA_STYLE_NUMBER_MINUTES,
298 DATA_STYLE_NUMBER_TEXT_COLON,
299 DATA_STYLE_NUMBER_SECONDS_02,
300 DATA_STYLE_NUMBER_AMPM,
301 0, 0
305 const SdXMLFixedDataStyle* aSdXMLFixedDateFormats[SdXMLDateFormatCount] =
307 &aSdXML_Standard_Short,
308 &aSdXML_Standard_Long,
309 &aSdXML_DateStyle_1,
310 &aSdXML_DateStyle_2,
311 &aSdXML_DateStyle_3,
312 &aSdXML_DateStyle_4,
313 &aSdXML_DateStyle_5,
314 &aSdXML_DateStyle_6,
317 const SdXMLFixedDataStyle* aSdXMLFixedTimeFormats[SdXMLTimeFormatCount] =
319 &aSdXML_TimeStyle_1,
320 &aSdXML_TimeStyle_2,
321 &aSdXML_TimeStyle_3,
322 &aSdXML_TimeStyle_4,
323 &aSdXML_TimeStyle_5,
324 &aSdXML_TimeStyle_6,
325 &aSdXML_TimeStyle_7
329 ///////////////////////////////////////////////////////////////////////
330 // export
332 #ifndef SVX_LIGHT
334 static void SdXMLExportDataStyleNumber( SdXMLExport& rExport, SdXMLDataStyleNumber& rElement )
336 if( rElement.mbDecimal02 )
338 rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, XML_2 );
341 if( rElement.mbLong )
343 rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_STYLE, XML_LONG );
346 if( rElement.mbTextual )
348 rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TEXTUAL, XML_TRUE );
351 SvXMLElementExport aNumberStyle( rExport, XML_NAMESPACE_NUMBER, rElement.meNumberStyle, sal_True, sal_False );
352 if( rElement.mpText )
354 OUString sAttrValue( OUString::createFromAscii( rElement.mpText ) );
355 rExport.GetDocHandler()->characters( sAttrValue );
359 static void SdXMLExportStyle( SdXMLExport& rExport, const SdXMLFixedDataStyle* pStyle, const SdXMLFixedDataStyle* pStyle2 = NULL )
361 OUString sAttrValue;
363 // name
364 sAttrValue = OUString::createFromAscii( pStyle->mpName );
365 if( pStyle2 )
366 sAttrValue += OUString::createFromAscii( pStyle2->mpName );
368 rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, sAttrValue );
370 if( pStyle->mbAutomatic )
372 rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_AUTOMATIC_ORDER, XML_TRUE );
375 SvXMLElementExport aElement( rExport, XML_NAMESPACE_NUMBER, pStyle->mbDateStyle ? XML_DATE_STYLE : XML_TIME_STYLE, sal_True, sal_True );
380 const sal_uInt8* pElements = (const sal_uInt8*)&pStyle->mpFormat[0];
382 while( *pElements )
384 SdXMLDataStyleNumber& rElement = aSdXMLDataStyleNumbers[ (*pElements++) - 1 ];
385 SdXMLExportDataStyleNumber( rExport, rElement );
388 if( pStyle2 )
390 SdXMLDataStyleNumber& rElement = aSdXMLDataStyleNumbers[ DATA_STYLE_NUMBER_TEXT_SPACE - 1 ];
391 SdXMLExportDataStyleNumber( rExport, rElement );
394 pStyle = pStyle2;
395 pStyle2 = NULL;
397 while( pStyle );
400 void SdXMLNumberStylesExporter::exportTimeStyle( SdXMLExport& rExport, sal_Int32 nStyle )
402 DBG_ASSERT( (nStyle >= 0) && (nStyle < SdXMLTimeFormatCount), "Unknown time style!" );
403 if( (nStyle >= 0) && (nStyle < SdXMLTimeFormatCount) )
404 SdXMLExportStyle( rExport, aSdXMLFixedTimeFormats[ nStyle ] );
407 void SdXMLNumberStylesExporter::exportDateStyle( SdXMLExport& rExport, sal_Int32 nStyle )
409 if( nStyle > 0x0f )
411 int nDateStyle = nStyle & 0x0f;
412 bool bHasDate = nDateStyle != 0;
414 if( nDateStyle > 1 )
415 nDateStyle -= 2;
417 DBG_ASSERT( (nDateStyle >= 0) && (nDateStyle < SdXMLDateFormatCount), "unknown date style!" );
419 int nTimeStyle = (nStyle >> 4) & 0x0f;
420 bool bHasTime = nTimeStyle != 0;
422 if( nTimeStyle > 1 )
423 nTimeStyle -= 2;
425 DBG_ASSERT( (nTimeStyle >= 0) && (nTimeStyle < SdXMLTimeFormatCount), "Unknown time style!" );
427 if( (nDateStyle >= 0) && (nDateStyle < SdXMLDateFormatCount) && (nTimeStyle >= 0) && (nTimeStyle < SdXMLTimeFormatCount) )
429 if( bHasDate )
431 if( bHasTime )
433 SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nDateStyle ], aSdXMLFixedTimeFormats[ nTimeStyle ] );
435 else
437 SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nDateStyle ] );
440 else if( bHasTime )
442 SdXMLExportStyle( rExport, aSdXMLFixedTimeFormats[ nTimeStyle ] );
446 else
448 DBG_ASSERT( (nStyle >= 0) && (nStyle < SdXMLDateFormatCount), "unknown date style!" );
449 if( (nStyle >= 0) && (nStyle < SdXMLDateFormatCount) )
450 SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nStyle ] );
454 OUString SdXMLNumberStylesExporter::getTimeStyleName(const sal_Int32 nTimeFormat )
456 sal_Int32 nFormat = nTimeFormat;
457 if( nFormat > 1 )
458 nFormat -= 2;
460 if( (nFormat >= 0) && (nFormat < SdXMLTimeFormatCount) )
462 return OUString::createFromAscii(aSdXMLFixedTimeFormats[nFormat]->mpName );
464 else
466 return OUString();
470 OUString SdXMLNumberStylesExporter::getDateStyleName(const sal_Int32 nDateFormat )
472 sal_Int32 nFormat = nDateFormat;
474 if( nFormat > 0x0f )
476 OUString aStr;
477 if( nFormat & 0x0f )
478 aStr = getDateStyleName( nFormat & 0x0f );
479 aStr += getTimeStyleName( (nFormat >> 4) & 0x0f );
480 return aStr;
483 if( nFormat > 1 )
484 nFormat -= 2;
486 if( (nFormat >= 0) && (nFormat < SdXMLDateFormatCount) )
488 return OUString::createFromAscii(aSdXMLFixedDateFormats[nFormat]->mpName );
490 else
492 return OUString();
496 #endif // #ifndef SVX_LIGHT
499 ///////////////////////////////////////////////////////////////////////
500 // import
502 class SdXMLNumberFormatMemberImportContext : public SvXMLImportContext
504 private:
505 SdXMLNumberFormatImportContext* mpParent;
507 OUString maNumberStyle;
508 sal_Bool mbLong;
509 sal_Bool mbTextual;
510 sal_Bool mbDecimal02;
511 OUString maText;
512 SvXMLImportContext* mpSlaveContext;
514 public:
515 TYPEINFO();
517 SdXMLNumberFormatMemberImportContext( SvXMLImport& rImport,
518 sal_uInt16 nPrfx,
519 const rtl::OUString& rLocalName,
520 const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList,
521 SdXMLNumberFormatImportContext* pParent,
522 SvXMLImportContext* pSlaveContext );
523 virtual ~SdXMLNumberFormatMemberImportContext();
525 virtual SvXMLImportContext *CreateChildContext( USHORT nPrefix,
526 const ::rtl::OUString& rLocalName,
527 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
529 virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
531 virtual void EndElement();
533 virtual void Characters( const ::rtl::OUString& rChars );
536 TYPEINIT1( SdXMLNumberFormatMemberImportContext, SvXMLImportContext );
538 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 )
539 : SvXMLImportContext(rImport, nPrfx, rLocalName),
540 mpParent( pParent ),
541 maNumberStyle( rLocalName ),
542 mpSlaveContext( pSlaveContext )
544 mbLong = sal_False;
545 mbTextual = sal_False;
546 mbDecimal02 = sal_False;
548 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
549 for(sal_Int16 i=0; i < nAttrCount; i++)
551 OUString sAttrName = xAttrList->getNameByIndex( i );
552 OUString aLocalName;
553 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
554 OUString sValue = xAttrList->getValueByIndex( i );
556 if( nPrefix == XML_NAMESPACE_NUMBER )
558 if( IsXMLToken( aLocalName, XML_DECIMAL_PLACES ) )
560 mbDecimal02 = IsXMLToken( sValue, XML_2 );
562 else if( IsXMLToken( aLocalName, XML_STYLE ) )
564 mbLong = IsXMLToken( sValue, XML_LONG );
566 else if( IsXMLToken( aLocalName, XML_TEXTUAL ) )
568 mbTextual = IsXMLToken( sValue, XML_TRUE );
575 SdXMLNumberFormatMemberImportContext::~SdXMLNumberFormatMemberImportContext()
579 SvXMLImportContext *SdXMLNumberFormatMemberImportContext::CreateChildContext( USHORT nPrefix,
580 const ::rtl::OUString& rLocalName,
581 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
583 return mpSlaveContext->CreateChildContext( nPrefix, rLocalName, xAttrList );
586 void SdXMLNumberFormatMemberImportContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
588 mpSlaveContext->StartElement( xAttrList );
591 void SdXMLNumberFormatMemberImportContext::EndElement()
593 mpSlaveContext->EndElement();
595 if( mpParent )
596 mpParent->add( maNumberStyle, mbLong, mbTextual, mbDecimal02, maText );
599 void SdXMLNumberFormatMemberImportContext::Characters( const ::rtl::OUString& rChars )
601 mpSlaveContext->Characters( rChars );
602 maText += rChars;
605 TYPEINIT1( SdXMLNumberFormatImportContext, SvXMLImportContext );
608 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)
609 : SvXMLNumFormatContext(rImport, nPrfx, rLocalName, pNewData, nNewType, xAttrList, rStyles),
610 mrImport( rImport ),
611 mbAutomatic( sal_False ),
612 mnIndex(0),
613 mnKey( -1 )
615 mbTimeStyle = IsXMLToken( rLocalName, XML_TIME_STYLE );
617 const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
618 for(sal_Int16 i=0; i < nAttrCount; i++)
620 OUString sAttrName = xAttrList->getNameByIndex( i );
621 OUString aLocalName;
622 sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
623 OUString sValue = xAttrList->getValueByIndex( i );
625 if( nPrefix == XML_NAMESPACE_NUMBER )
627 if( IsXMLToken( aLocalName, XML_AUTOMATIC_ORDER ) )
629 mbAutomatic = IsXMLToken( sValue, XML_TRUE );
635 SdXMLNumberFormatImportContext::~SdXMLNumberFormatImportContext()
639 void SdXMLNumberFormatImportContext::add( OUString& rNumberStyle, sal_Bool bLong, sal_Bool bTextual, sal_Bool bDecimal02, OUString& rText )
641 if( mnIndex == -1 || mnIndex == 16 )
643 mnIndex = -1;
644 return;
647 const SdXMLDataStyleNumber* pStyleMember = aSdXMLDataStyleNumbers;
648 for( sal_uInt8 nIndex = 0; pStyleMember->meNumberStyle != XML_TOKEN_INVALID; nIndex++, pStyleMember++ )
650 if( (IsXMLToken(rNumberStyle, pStyleMember->meNumberStyle) &&
651 (pStyleMember->mbLong == bLong) &&
652 (pStyleMember->mbTextual == bTextual) &&
653 (pStyleMember->mbDecimal02 == bDecimal02) &&
654 ( ( (pStyleMember->mpText == NULL) && (rText.getLength() == 0) ) ||
655 ( pStyleMember->mpText && (rText.compareToAscii( pStyleMember->mpText ) == 0 )) ) ) )
657 mnElements[mnIndex++] = nIndex + 1;
658 return;
663 bool SdXMLNumberFormatImportContext::compareStyle( const SdXMLFixedDataStyle* pStyle, sal_Int16& nIndex ) const
665 if( (pStyle->mbAutomatic != mbAutomatic) && (nIndex == 0))
666 return sal_False;
668 sal_Int16 nCompareIndex;
669 for( nCompareIndex = 0; nCompareIndex < 8; nIndex++, nCompareIndex++ )
671 if( pStyle->mpFormat[nCompareIndex] != mnElements[nIndex] )
672 return sal_False;
675 return sal_True;
678 void SdXMLNumberFormatImportContext::EndElement()
680 SvXMLNumFormatContext::EndElement();
682 for( ; mnIndex < 16; mnIndex++ )
684 mnElements[mnIndex] = 0;
687 if( mbTimeStyle )
689 // compare import with all time styles
690 for( sal_Int16 nFormat = 0; nFormat < SdXMLTimeFormatCount; nFormat++ )
692 sal_Int16 nIndex = 0;
693 if( compareStyle( aSdXMLFixedTimeFormats[nFormat], nIndex ) )
695 mnKey = nFormat + 2;
696 break;
700 else
702 // compare import with all date styles
703 for( sal_Int16 nFormat = 0; nFormat < SdXMLDateFormatCount; nFormat++ )
705 sal_Int16 nIndex = 0;
706 if( compareStyle( aSdXMLFixedDateFormats[nFormat], nIndex ) )
708 mnKey = nFormat + 2;
709 break;
711 else if( mnElements[nIndex] == DATA_STYLE_NUMBER_TEXT_SPACE )
713 // if its a valid date ending with a space, see if a time style follows
714 for( sal_Int16 nTimeFormat = 0; nTimeFormat < SdXMLTimeFormatCount; nTimeFormat++ )
716 sal_Int16 nIndex2 = nIndex + 1;
717 if( compareStyle( aSdXMLFixedTimeFormats[nTimeFormat], nIndex2 ) )
719 mnKey = (nFormat + 2) | ((nTimeFormat + 2) << 4);
720 break;
726 // no date style found? maybe its an extended time style
727 if( mnKey == -1 )
729 // compare import with all time styles
730 for( sal_Int16 nFormat = 0; nFormat < SdXMLTimeFormatCount; nFormat++ )
732 sal_Int16 nIndex = 0;
733 if( compareStyle( aSdXMLFixedTimeFormats[nFormat], nIndex ) )
735 mnKey = (nFormat + 2) << 4;
736 break;
743 SvXMLImportContext * SdXMLNumberFormatImportContext::CreateChildContext( USHORT nPrefix, const ::rtl::OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
745 return new SdXMLNumberFormatMemberImportContext( GetImport(), nPrefix, rLocalName, xAttrList, this, SvXMLNumFormatContext::CreateChildContext( nPrefix, rLocalName, xAttrList ) );