LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLNumberStyles.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 120 183 65.6 %
Date: 2014-04-11 Functions: 20 30 66.7 %
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           5 : static void SdXMLExportDataStyleNumber( SdXMLExport& rExport, SdXMLDataStyleNumber& rElement )
     316             : {
     317           5 :     if( rElement.mbDecimal02 )
     318             :     {
     319           0 :         rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_DECIMAL_PLACES, XML_2 );
     320             :     }
     321             : 
     322           5 :     if( rElement.mbLong )
     323             :     {
     324           3 :         rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_STYLE, XML_LONG );
     325             :     }
     326             : 
     327           5 :     if( rElement.mbTextual )
     328             :     {
     329           0 :         rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_TEXTUAL, XML_TRUE );
     330             :     }
     331             : 
     332           5 :     SvXMLElementExport aNumberStyle( rExport, XML_NAMESPACE_NUMBER, rElement.meNumberStyle, true, false );
     333           5 :     if( rElement.mpText )
     334             :     {
     335           2 :         OUString sAttrValue( OUString::createFromAscii( rElement.mpText ) );
     336           2 :         rExport.GetDocHandler()->characters( sAttrValue );
     337           5 :     }
     338           5 : }
     339             : 
     340           1 : static void SdXMLExportStyle( SdXMLExport& rExport, const SdXMLFixedDataStyle* pStyle, const SdXMLFixedDataStyle* pStyle2 = NULL )
     341             : {
     342           1 :     OUString sAttrValue;
     343             : 
     344             :     // name
     345           1 :     sAttrValue = OUString::createFromAscii( pStyle->mpName );
     346           1 :     if( pStyle2 )
     347           0 :         sAttrValue += OUString::createFromAscii( pStyle2->mpName );
     348             : 
     349           1 :     rExport.AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, sAttrValue );
     350             : 
     351           1 :     if( pStyle->mbAutomatic )
     352             :     {
     353           1 :         rExport.AddAttribute( XML_NAMESPACE_NUMBER, XML_AUTOMATIC_ORDER, XML_TRUE );
     354             :     }
     355             : 
     356           2 :     SvXMLElementExport aElement( rExport, XML_NAMESPACE_NUMBER, pStyle->mbDateStyle ? XML_DATE_STYLE : XML_TIME_STYLE, true, true );
     357             : 
     358           1 :     do
     359             :     {
     360             : 
     361           1 :         const sal_uInt8* pElements = (const sal_uInt8*)&pStyle->mpFormat[0];
     362             : 
     363           7 :         while( *pElements )
     364             :         {
     365           5 :             SdXMLDataStyleNumber& rElement = aSdXMLDataStyleNumbers[ (*pElements++) - 1 ];
     366           5 :             SdXMLExportDataStyleNumber( rExport, rElement );
     367             :         }
     368             : 
     369           1 :         if( pStyle2 )
     370             :         {
     371           0 :             SdXMLDataStyleNumber& rElement = aSdXMLDataStyleNumbers[ DATA_STYLE_NUMBER_TEXT_SPACE - 1 ];
     372           0 :             SdXMLExportDataStyleNumber( rExport, rElement );
     373             :         }
     374             : 
     375           1 :         pStyle = pStyle2;
     376           1 :         pStyle2 = NULL;
     377             :     }
     378           1 :     while( pStyle );
     379           1 : }
     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           1 : void SdXMLNumberStylesExporter::exportDateStyle( SdXMLExport& rExport, sal_Int32 nStyle )
     389             : {
     390           1 :     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           1 :         if( (nStyle >= 0) && (nStyle < SdXMLDateFormatCount) )
     431           1 :             SdXMLExportStyle( rExport, aSdXMLFixedDateFormats[ nStyle ] );
     432             :     }
     433           1 : }
     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           1 : OUString SdXMLNumberStylesExporter::getDateStyleName(const sal_Int32 nDateFormat )
     452             : {
     453           1 :     sal_Int32 nFormat = nDateFormat;
     454             : 
     455           1 :     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           1 :     if( nFormat > 1 )
     465           1 :         nFormat -= 2;
     466             : 
     467           1 :     if( (nFormat >= 0) && (nFormat < SdXMLDateFormatCount) )
     468             :     {
     469           1 :         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           5 : 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           5 :     mpSlaveContext( pSlaveContext )
     520             : {
     521           5 :     mbLong = sal_False;
     522           5 :     mbTextual = sal_False;
     523           5 :     mbDecimal02 = sal_False;
     524             : 
     525           5 :     const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     526           8 :     for(sal_Int16 i=0; i < nAttrCount; i++)
     527             :     {
     528           3 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     529           6 :         OUString aLocalName;
     530           3 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     531           6 :         OUString sValue = xAttrList->getValueByIndex( i );
     532             : 
     533           3 :         if( nPrefix == XML_NAMESPACE_NUMBER )
     534             :         {
     535           3 :             if( IsXMLToken( aLocalName, XML_DECIMAL_PLACES ) )
     536             :             {
     537           0 :                 mbDecimal02 =  IsXMLToken( sValue, XML_2 );
     538             :             }
     539           3 :             else if( IsXMLToken( aLocalName, XML_STYLE ) )
     540             :             {
     541           3 :                 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           3 :     }
     549             : 
     550           5 : }
     551             : 
     552          10 : SdXMLNumberFormatMemberImportContext::~SdXMLNumberFormatMemberImportContext()
     553             : {
     554          10 : }
     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           5 : void SdXMLNumberFormatMemberImportContext::StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList )
     564             : {
     565           5 :     mpSlaveContext->StartElement( xAttrList );
     566           5 : }
     567             : 
     568           5 : void SdXMLNumberFormatMemberImportContext::EndElement()
     569             : {
     570           5 :     mpSlaveContext->EndElement();
     571             : 
     572           5 :     if( mpParent )
     573           5 :         mpParent->add( maNumberStyle, mbLong, mbTextual, mbDecimal02, maText );
     574           5 : }
     575             : 
     576           2 : void SdXMLNumberFormatMemberImportContext::Characters( const OUString& rChars )
     577             : {
     578           2 :     mpSlaveContext->Characters( rChars );
     579           2 :     maText += rChars;
     580           2 : }
     581             : 
     582          17 : TYPEINIT1( SdXMLNumberFormatImportContext, SvXMLImportContext );
     583             : 
     584           1 : 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           1 :     mnKey( -1 )
     589             : {
     590           1 :     mbTimeStyle = IsXMLToken( rLocalName, XML_TIME_STYLE );
     591             : 
     592           1 :     const sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
     593           3 :     for(sal_Int16 i=0; i < nAttrCount; i++)
     594             :     {
     595           2 :         OUString sAttrName = xAttrList->getNameByIndex( i );
     596           4 :         OUString aLocalName;
     597           2 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     598           4 :         OUString sValue = xAttrList->getValueByIndex( i );
     599             : 
     600           2 :         if( nPrefix == XML_NAMESPACE_NUMBER )
     601             :         {
     602           1 :             if( IsXMLToken( aLocalName, XML_AUTOMATIC_ORDER ) )
     603             :             {
     604           1 :                 mbAutomatic = IsXMLToken( sValue, XML_TRUE );
     605             :             }
     606             :         }
     607           2 :     }
     608           1 : }
     609             : 
     610           2 : SdXMLNumberFormatImportContext::~SdXMLNumberFormatImportContext()
     611             : {
     612           2 : }
     613             : 
     614           5 : void SdXMLNumberFormatImportContext::add( OUString& rNumberStyle, sal_Bool bLong, sal_Bool bTextual, sal_Bool   bDecimal02, OUString& rText )
     615             : {
     616           5 :     if( mnIndex == -1 || mnIndex == 16 )
     617             :     {
     618           0 :         mnIndex = -1;
     619           0 :         return;
     620             :     }
     621             : 
     622           5 :     const SdXMLDataStyleNumber* pStyleMember = aSdXMLDataStyleNumbers;
     623          32 :     for( sal_uInt8 nIndex = 0; pStyleMember->meNumberStyle != XML_TOKEN_INVALID; nIndex++, pStyleMember++ )
     624             :     {
     625          71 :         if( (IsXMLToken(rNumberStyle, pStyleMember->meNumberStyle) &&
     626          12 :             (pStyleMember->mbLong == bLong) &&
     627          10 :             (pStyleMember->mbTextual == bTextual) &&
     628          47 :             (pStyleMember->mbDecimal02 == bDecimal02) &&
     629           8 :             ( ( (pStyleMember->mpText == NULL) && (rText.isEmpty()) ) ||
     630           2 :               ( pStyleMember->mpText && (rText.equalsAscii( pStyleMember->mpText ) ) ) ) ) )
     631             :         {
     632           5 :             mnElements[mnIndex++] = nIndex + 1;
     633           5 :             return;
     634             :         }
     635             :     }
     636             : }
     637             : 
     638           1 : bool SdXMLNumberFormatImportContext::compareStyle( const SdXMLFixedDataStyle* pStyle, sal_Int16& nIndex ) const
     639             : {
     640           1 :     if( (pStyle->mbAutomatic != mbAutomatic) && (nIndex == 0))
     641           0 :         return false;
     642             : 
     643             :     sal_Int16 nCompareIndex;
     644           9 :     for( nCompareIndex = 0; nCompareIndex < 8; nIndex++, nCompareIndex++ )
     645             :     {
     646           8 :         if( pStyle->mpFormat[nCompareIndex] != mnElements[nIndex] )
     647           0 :             return false;
     648             :     }
     649             : 
     650           1 :     return true;
     651             : }
     652             : 
     653           1 : void SdXMLNumberFormatImportContext::EndElement()
     654             : {
     655           1 :     SvXMLNumFormatContext::EndElement();
     656             : 
     657          12 :     for( ; mnIndex < 16; mnIndex++ )
     658             :     {
     659          11 :         mnElements[mnIndex] = 0;
     660             :     }
     661             : 
     662           1 :     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           2 :         for( sal_Int16 nFormat = 0; nFormat < SdXMLDateFormatCount; nFormat++ )
     679             :         {
     680           1 :             sal_Int16 nIndex = 0;
     681           1 :             if( compareStyle( aSdXMLFixedDateFormats[nFormat], nIndex ) )
     682             :             {
     683           1 :                 mnKey = nFormat + 2;
     684           2 :                 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           1 :         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           1 : }
     717             : 
     718           5 : SvXMLImportContext * SdXMLNumberFormatImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList )
     719             : {
     720           5 :     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