LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLNumberStyles.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 183 0.0 %
Date: 2014-04-14 Functions: 0 30 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10