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

Generated by: LCOV version 1.10