LCOV - code coverage report
Current view: top level - oox/source/docprop - docprophandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 157 288 54.5 %
Date: 2012-08-25 Functions: 14 21 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 157 522 30.1 %

           Branch data     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 "docprophandler.hxx"
      21                 :            : 
      22                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      23                 :            : #include <com/sun/star/beans/PropertyExistException.hpp>
      24                 :            : #include <com/sun/star/lang/Locale.hpp>
      25                 :            : 
      26                 :            : #include <osl/time.h>
      27                 :            : 
      28                 :            : #include "oox/helper/attributelist.hxx"
      29                 :            : 
      30                 :            : using namespace ::com::sun::star;
      31                 :            : 
      32                 :            : namespace oox {
      33                 :            : namespace docprop {
      34                 :            : 
      35                 :            : // ------------------------------------------------
      36                 :        215 : OOXMLDocPropHandler::OOXMLDocPropHandler( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< document::XDocumentProperties > xDocProp )
      37                 :            : : m_xContext( xContext )
      38                 :            : , m_xDocProp( xDocProp )
      39                 :            : , m_nState( 0 )
      40                 :            : , m_nBlock( 0 )
      41                 :            : , m_nType( 0 )
      42                 :        215 : , m_nInBlock( 0 )
      43                 :            : {
      44 [ -  + ][ -  + ]:        215 :     if ( !xContext.is() || !xDocProp.is() )
                 [ +  - ]
      45         [ #  # ]:          0 :         throw uno::RuntimeException();
      46                 :        215 : }
      47                 :            : 
      48                 :            : // ------------------------------------------------
      49                 :        215 : OOXMLDocPropHandler::~OOXMLDocPropHandler()
      50                 :            : {
      51         [ -  + ]:        430 : }
      52                 :            : 
      53                 :            : // ------------------------------------------------
      54                 :        430 : void OOXMLDocPropHandler::InitNew()
      55                 :            : {
      56                 :        430 :     m_nState = 0;
      57                 :        430 :     m_nBlock = 0;
      58                 :        430 :     m_aCustomPropertyName = ::rtl::OUString();
      59                 :        430 :     m_nType = 0;
      60                 :        430 :     m_nInBlock = 0;
      61                 :        430 : }
      62                 :            : 
      63                 :            : // ------------------------------------------------
      64                 :        569 : void OOXMLDocPropHandler::AddCustomProperty( const uno::Any& aAny )
      65                 :            : {
      66         [ +  - ]:        569 :     if ( !m_aCustomPropertyName.isEmpty() )
      67                 :            :     {
      68                 :            :         const uno::Reference< beans::XPropertyContainer > xUserProps =
      69 [ +  - ][ +  - ]:        569 :             m_xDocProp->getUserDefinedProperties();
      70         [ -  + ]:        569 :         if ( !xUserProps.is() )
      71         [ #  # ]:          0 :             throw uno::RuntimeException();
              [ #  #  # ]
      72                 :            : 
      73                 :            :         try
      74                 :            :         {
      75         [ +  - ]:        569 :             xUserProps->addProperty( m_aCustomPropertyName,
      76         [ +  - ]:        569 :                     beans::PropertyAttribute::REMOVEABLE, aAny );
      77                 :            :         }
      78         [ #  # ]:          0 :         catch( beans::PropertyExistException& )
      79                 :            :         {
      80                 :            :             // conflicts with core and extended properties are possible
      81                 :            :         }
      82         [ #  # ]:          0 :         catch( uno::Exception& )
      83                 :            :         {
      84                 :            :             OSL_FAIL( "Can not add custom property!" );
      85                 :        569 :         }
      86                 :            :     }
      87                 :        569 : }
      88                 :            : 
      89                 :            : // ------------------------------------------------
      90                 :        334 : util::DateTime OOXMLDocPropHandler::GetDateTimeFromW3CDTF( const ::rtl::OUString& aChars )
      91                 :            : {
      92                 :        334 :     oslDateTime aOslDTime = { 0, 0, 0, 0, 0, 0, 0, 0 };
      93                 :        334 :     sal_Int32 nLen = aChars.getLength();
      94         [ +  - ]:        334 :     if ( nLen >= 4 )
      95                 :            :     {
      96                 :        334 :         aOslDTime.Year = (sal_uInt16)aChars.copy( 0, 4 ).toInt32();
      97                 :            : 
      98 [ +  - ][ +  - ]:        334 :         if ( nLen >= 7 && aChars.getStr()[4] == (sal_Unicode)'-' )
                 [ +  - ]
      99                 :            :         {
     100                 :        334 :             aOslDTime.Month = (sal_uInt16)aChars.copy( 5, 2 ).toInt32();
     101                 :            : 
     102 [ +  - ][ +  - ]:        334 :             if ( nLen >= 10 && aChars.getStr()[7] == (sal_Unicode)'-' )
                 [ +  - ]
     103                 :            :             {
     104                 :        334 :                 aOslDTime.Day = (sal_uInt16)aChars.copy( 8, 2 ).toInt32();
     105                 :            : 
     106 [ +  - ][ +  - ]:        334 :                 if ( nLen >= 16 && aChars.getStr()[10] == (sal_Unicode)'T' && aChars.getStr()[13] == (sal_Unicode)':' )
         [ +  - ][ +  - ]
     107                 :            :                 {
     108                 :        334 :                     aOslDTime.Hours = (sal_uInt16)aChars.copy( 11, 2 ).toInt32();
     109                 :        334 :                     aOslDTime.Minutes = (sal_uInt16)aChars.copy( 14, 2 ).toInt32();
     110                 :            : 
     111                 :        334 :                     sal_Int32 nOptTime = 0;
     112 [ +  - ][ +  - ]:        334 :                     if ( nLen >= 19 && aChars.getStr()[16] == (sal_Unicode)':' )
                 [ +  - ]
     113                 :            :                     {
     114                 :        334 :                         aOslDTime.Seconds = (sal_uInt16)aChars.copy( 17, 2 ).toInt32();
     115                 :        334 :                         nOptTime += 3;
     116 [ +  - ][ +  + ]:        334 :                         if ( nLen >= 21 && aChars.getStr()[19] == (sal_Unicode)'.' )
                 [ +  + ]
     117                 :            :                         {
     118                 :        159 :                             aOslDTime.NanoSeconds = (sal_uInt32)(aChars.copy( 20, 1 ).toInt32() * 10e8);
     119                 :        159 :                             nOptTime += 2;
     120                 :            :                         }
     121                 :            :                     }
     122                 :            : 
     123                 :        334 :                     sal_Int32 nModif = 0;
     124         [ -  + ]:        334 :                     if ( nLen >= 16 + nOptTime + 6 )
     125                 :            :                     {
     126         [ #  # ]:          0 :                         if ( ( aChars.getStr()[16 + nOptTime] == (sal_Unicode)'+' || aChars.getStr()[16 + nOptTime] == (sal_Unicode)'-' )
           [ #  #  #  # ]
                 [ #  # ]
     127                 :          0 :                           && aChars.getStr()[16 + nOptTime + 3] == (sal_Unicode)':' )
     128                 :            : 
     129                 :            :                         {
     130                 :          0 :                             nModif = aChars.copy( 16 + nOptTime + 1, 2 ).toInt32() * 3600;
     131                 :          0 :                             nModif += aChars.copy( 16 + nOptTime + 4, 2 ).toInt32() * 60;
     132         [ #  # ]:          0 :                             if ( aChars.getStr()[16 + nOptTime] == (sal_Unicode)'-' )
     133                 :          0 :                                 nModif *= -1;
     134                 :            :                         }
     135                 :            :                     }
     136                 :            : 
     137         [ -  + ]:        334 :                     if ( nModif )
     138                 :            :                     {
     139                 :            :                         // convert to UTC time
     140                 :            :                         TimeValue aTmp;
     141 [ #  # ][ #  # ]:          0 :                         if ( osl_getTimeValueFromDateTime( &aOslDTime, &aTmp ) )
     142                 :            :                         {
     143                 :          0 :                             aTmp.Seconds += nModif;
     144         [ #  # ]:          0 :                             osl_getDateTimeFromTimeValue( &aTmp, &aOslDTime );
     145                 :            :                         }
     146                 :            :                     }
     147                 :            :                 }
     148                 :            :             }
     149                 :            :         }
     150                 :            :     }
     151                 :            : 
     152                 :        334 :     return util::DateTime( (sal_uInt16)( aOslDTime.NanoSeconds / 1e7 ), aOslDTime.Seconds, aOslDTime.Minutes, aOslDTime.Hours, aOslDTime.Day, aOslDTime.Month, aOslDTime.Year );
     153                 :            : }
     154                 :            : 
     155                 :            : // ------------------------------------------------
     156                 :          0 : uno::Sequence< ::rtl::OUString > OOXMLDocPropHandler::GetKeywordsSet( const ::rtl::OUString& aChars )
     157                 :            : {
     158         [ #  # ]:          0 :     if ( !aChars.isEmpty() )
     159                 :            :     {
     160         [ #  # ]:          0 :         uno::Sequence< ::rtl::OUString > aResult( 20 );
     161                 :          0 :         sal_Int32 nCounter = 0;
     162                 :            : 
     163                 :          0 :         const sal_Unicode* pStr = aChars.getStr();
     164 [ #  # ][ #  # ]:          0 :         for( sal_Int32 nInd = 0; nInd < aChars.getLength() && pStr[nInd] != 0; nInd++ )
                 [ #  # ]
     165                 :            :         {
     166         [ #  # ]:          0 :             switch( pStr[nInd] )
     167                 :            :             {
     168                 :            :                 case (sal_Unicode)' ':
     169                 :            :                 case (sal_Unicode)',':
     170                 :            :                 case (sal_Unicode)';':
     171                 :            :                 case (sal_Unicode)':':
     172                 :            :                 case (sal_Unicode)'\t':
     173                 :            :                     // this is a delimiter
     174                 :            :                     // unfortunately I did not find any specification for the possible delimiters
     175 [ #  # ][ #  # ]:          0 :                     if ( !aResult[nCounter].isEmpty() )
     176                 :            :                     {
     177         [ #  # ]:          0 :                         if ( nCounter >= aResult.getLength() )
     178         [ #  # ]:          0 :                             aResult.realloc( nCounter + 10 );
     179                 :          0 :                         nCounter++;
     180                 :            :                     }
     181                 :          0 :                     break;
     182                 :            : 
     183                 :            :                 default:
     184                 :            :                     // this should be a part of keyword
     185         [ #  # ]:          0 :                         aResult[nCounter] += ::rtl::OUString( (sal_Unicode)pStr[nInd] );
     186                 :            :             }
     187                 :            :         }
     188                 :            : 
     189         [ #  # ]:          0 :         aResult.realloc( nCounter + 1 );
     190 [ #  # ][ #  # ]:          0 :         return aResult;
     191                 :            :     }
     192                 :            : 
     193                 :          0 :     return uno::Sequence< ::rtl::OUString >();
     194                 :            : }
     195                 :            : // ------------------------------------------------
     196                 :          0 : lang::Locale OOXMLDocPropHandler::GetLanguage( const ::rtl::OUString& aChars )
     197                 :            : {
     198                 :          0 :     lang::Locale aResult;
     199         [ #  # ]:          0 :     if ( aChars.getLength() >= 2 )
     200                 :            :     {
     201                 :          0 :         aResult.Language = aChars.copy( 0, 2 );
     202 [ #  # ][ #  # ]:          0 :         if ( aChars.getLength() >= 5 && aChars.getStr()[2] == (sal_Unicode)'-' )
                 [ #  # ]
     203                 :          0 :             aResult.Country = aChars.copy( 3, 2 );
     204                 :            : 
     205                 :            :         // TODO/LATER: the variant could be also detected
     206                 :            :     }
     207                 :            : 
     208                 :          0 :     return aResult;
     209                 :            : }
     210                 :            : 
     211                 :            : // ------------------------------------------------
     212                 :        332 : void OOXMLDocPropHandler::UpdateDocStatistic( const ::rtl::OUString& aChars )
     213                 :            : {
     214 [ +  - ][ +  - ]:        332 :     uno::Sequence< beans::NamedValue > aSet = m_xDocProp->getDocumentStatistics();
     215                 :        332 :     ::rtl::OUString aName;
     216                 :            : 
     217   [ +  +  +  +  :        332 :     switch( m_nBlock )
                      - ]
     218                 :            :     {
     219                 :            :         case EXTPR_TOKEN( Characters ):
     220         [ +  - ]:         83 :             aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharacterCount" ) );
     221                 :         83 :             break;
     222                 :            : 
     223                 :            :         case EXTPR_TOKEN( Pages ):
     224         [ +  - ]:         83 :             aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PageCount" ) );
     225                 :         83 :             break;
     226                 :            : 
     227                 :            :         case EXTPR_TOKEN( Words ):
     228         [ +  - ]:         83 :             aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "WordCount" ) );
     229                 :         83 :             break;
     230                 :            : 
     231                 :            :         case EXTPR_TOKEN( Paragraphs ):
     232         [ +  - ]:         83 :             aName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphCount" ) );
     233                 :         83 :             break;
     234                 :            : 
     235                 :            :         default:
     236                 :            :             OSL_FAIL( "Unexpected statistic!" );
     237                 :          0 :             break;
     238                 :            :     }
     239                 :            : 
     240         [ +  - ]:        332 :     if ( !aName.isEmpty() )
     241                 :            :     {
     242                 :        332 :         sal_Bool bFound = sal_False;
     243                 :        332 :         sal_Int32 nLen = aSet.getLength();
     244         [ +  + ]:        830 :         for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ )
     245 [ +  - ][ -  + ]:        498 :             if ( aSet[nInd].Name.equals( aName ) )
     246                 :            :             {
     247 [ #  # ][ #  # ]:          0 :                 aSet[nInd].Value = uno::makeAny( aChars.toInt32() );
     248                 :          0 :                 bFound = sal_True;
     249                 :          0 :                 break;
     250                 :            :             }
     251                 :            : 
     252         [ +  - ]:        332 :         if ( !bFound )
     253                 :            :         {
     254         [ +  - ]:        332 :             aSet.realloc( nLen + 1 );
     255         [ +  - ]:        332 :             aSet[nLen].Name = aName;
     256 [ +  - ][ +  - ]:        332 :             aSet[nLen].Value = uno::makeAny( aChars.toInt32() );
     257                 :            :         }
     258                 :            : 
     259 [ +  - ][ +  - ]:        332 :         m_xDocProp->setDocumentStatistics( aSet );
     260         [ +  - ]:        332 :     }
     261                 :        332 : }
     262                 :            : 
     263                 :            : // ------------------------------------------------
     264                 :            : // com.sun.star.xml.sax.XFastDocumentHandler
     265                 :            : // ------------------------------------------------
     266                 :        430 : void SAL_CALL OOXMLDocPropHandler::startDocument()
     267                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     268                 :            : {
     269                 :        430 : }
     270                 :            : 
     271                 :            : // ------------------------------------------------
     272                 :        430 : void SAL_CALL OOXMLDocPropHandler::endDocument()
     273                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     274                 :            : {
     275                 :        430 :     InitNew();
     276                 :        430 : }
     277                 :            : 
     278                 :            : // ------------------------------------------------
     279                 :        430 : void SAL_CALL OOXMLDocPropHandler::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& )
     280                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     281                 :            : {
     282                 :        430 : }
     283                 :            : 
     284                 :            : 
     285                 :            : // com.sun.star.xml.sax.XFastContextHandler
     286                 :            : // ------------------------------------------------
     287                 :       3183 : void SAL_CALL OOXMLDocPropHandler::startFastElement( ::sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttribs )
     288                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     289                 :            : {
     290 [ +  + ][ +  - ]:       3183 :     if ( !m_nInBlock && !m_nState )
     291                 :            :     {
     292 [ +  + ][ -  + ]:        860 :         if ( nElement == COREPR_TOKEN( coreProperties )
                 [ #  # ]
     293                 :            :           || nElement == EXTPR_TOKEN( Properties )
     294                 :            :           || nElement == CUSTPR_TOKEN( Properties ) )
     295                 :            :         {
     296                 :        430 :             m_nState = nElement;
     297                 :            :         }
     298                 :            :         else
     299                 :            :         {
     300                 :            :                 OSL_FAIL( "Unexpected file format!" );
     301                 :            :         }
     302                 :            :     }
     303 [ +  - ][ +  + ]:       2753 :     else if ( m_nState && m_nInBlock == 1 ) // that tag should contain the property name
     304                 :            :     {
     305                 :            :         // Currently the attributes are ignored for the core properties since the only
     306                 :            :         // known attribute is xsi:type that can only be used with dcterms:created and
     307                 :            :         // dcterms:modified, and this element is allowed currently to have only one value dcterms:W3CDTF
     308                 :       2538 :         m_nBlock = nElement;
     309                 :            : 
     310 [ +  - ][ -  + ]:       2538 :         if ( xAttribs.is() && xAttribs->hasAttribute( XML_name ) )
                 [ -  + ]
     311                 :          0 :             m_aCustomPropertyName = xAttribs->getValue( XML_name );
     312                 :            :     }
     313 [ +  - ][ +  - ]:        215 :     else if ( m_nState && m_nInBlock && m_nInBlock == 2 && getNamespace( nElement ) == NMSP_officeDocPropsVT )
         [ +  + ][ +  - ]
                 [ +  + ]
     314                 :            :     {
     315                 :         58 :         m_nType = nElement;
     316                 :            :     }
     317                 :            :     else
     318                 :            :     {
     319                 :            :         OSL_FAIL( "For now unexpected tags are ignored!" );
     320                 :            :     }
     321                 :            : 
     322         [ -  + ]:       3183 :     if ( m_nInBlock == SAL_MAX_INT32 )
     323         [ #  # ]:          0 :         throw uno::RuntimeException();
     324                 :            : 
     325                 :       3183 :     m_nInBlock++;
     326                 :       3183 : }
     327                 :            : 
     328                 :            : // ------------------------------------------------
     329                 :          0 : void SAL_CALL OOXMLDocPropHandler::startUnknownElement( const ::rtl::OUString& aNamespace, const ::rtl::OUString& aName, const uno::Reference< xml::sax::XFastAttributeList >& )
     330                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     331                 :            : {
     332         [ #  # ]:          0 :     ::rtl::OUString aUnknown = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unknown element" ) );
     333                 :          0 :     aUnknown += aNamespace;
     334         [ #  # ]:          0 :     aUnknown += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":" ) );
     335                 :          0 :     aUnknown += aName;
     336                 :            :     OSL_FAIL( ::rtl::OUStringToOString( aUnknown, RTL_TEXTENCODING_UTF8 ).getStr() );
     337                 :            : 
     338         [ #  # ]:          0 :     if ( m_nInBlock == SAL_MAX_INT32 )
     339         [ #  # ]:          0 :         throw uno::RuntimeException();
     340                 :            : 
     341                 :          0 :     m_nInBlock++;
     342                 :          0 : }
     343                 :            : 
     344                 :            : // ------------------------------------------------
     345                 :       3183 : void SAL_CALL OOXMLDocPropHandler::endFastElement( ::sal_Int32 )
     346                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     347                 :            : {
     348         [ +  - ]:       3183 :     if ( m_nInBlock )
     349                 :            :     {
     350                 :       3183 :         m_nInBlock--;
     351                 :            : 
     352         [ +  + ]:       3183 :         if ( !m_nInBlock )
     353                 :        430 :             m_nState = 0;
     354         [ +  + ]:       2753 :         else if ( m_nInBlock == 1 )
     355                 :            :         {
     356                 :       2538 :             m_nBlock = 0;
     357                 :       2538 :             m_aCustomPropertyName = ::rtl::OUString();
     358                 :            :         }
     359         [ +  + ]:        215 :         else if ( m_nInBlock == 2 )
     360                 :         58 :             m_nType = 0;
     361                 :            :     }
     362                 :       3183 : }
     363                 :            : 
     364                 :            : // ------------------------------------------------
     365                 :          0 : void SAL_CALL OOXMLDocPropHandler::endUnknownElement( const ::rtl::OUString&, const ::rtl::OUString& )
     366                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     367                 :            : {
     368         [ #  # ]:          0 :     if ( m_nInBlock )
     369                 :          0 :         m_nInBlock--;
     370                 :          0 : }
     371                 :            : 
     372                 :            : // ------------------------------------------------
     373                 :       3183 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createFastChildContext( ::sal_Int32, const uno::Reference< xml::sax::XFastAttributeList >& )
     374                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     375                 :            : {
     376                 :            :     // Should the arguments be parsed?
     377                 :       3183 :     return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) );
     378                 :            : }
     379                 :            : 
     380                 :            : // ------------------------------------------------
     381                 :          0 : uno::Reference< xml::sax::XFastContextHandler > SAL_CALL OOXMLDocPropHandler::createUnknownChildContext( const ::rtl::OUString&, const ::rtl::OUString&, const uno::Reference< xml::sax::XFastAttributeList >& )
     382                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     383                 :            : {
     384                 :          0 :     return uno::Reference< xml::sax::XFastContextHandler >( static_cast< xml::sax::XFastContextHandler* >( this ) );
     385                 :            : }
     386                 :            : 
     387                 :            : // ------------------------------------------------
     388                 :       2362 : void SAL_CALL OOXMLDocPropHandler::characters( const ::rtl::OUString& aChars )
     389                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     390                 :            : {
     391                 :            :     try
     392                 :            :     {
     393 [ +  + ][ -  + ]:       2362 :         if ( (m_nInBlock == 2) || ((m_nInBlock == 3) && m_nType) )
                 [ #  # ]
     394                 :            :         {
     395         [ +  + ]:       2277 :             if ( m_nState == COREPR_TOKEN( coreProperties ) )
     396                 :            :             {
     397   [ -  -  -  -  :        772 :                 switch( m_nBlock )
          -  +  +  -  -  
          -  +  +  +  +  
                +  +  - ]
     398                 :            :                 {
     399                 :            :                     case COREPR_TOKEN( category ):
     400         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "category" ) );
     401 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     402                 :          0 :                         break;
     403                 :            : 
     404                 :            :                     case COREPR_TOKEN( contentStatus ):
     405         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentStatus" ) );
     406 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     407                 :          0 :                         break;
     408                 :            : 
     409                 :            :                     case COREPR_TOKEN( contentType ):
     410         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "contentType" ) );
     411 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     412                 :          0 :                         break;
     413                 :            : 
     414                 :            :                     case COREPR_TOKEN( identifier ):
     415         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "identifier" ) );
     416 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     417                 :          0 :                         break;
     418                 :            : 
     419                 :            :                     case COREPR_TOKEN( version ):
     420         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "version" ) );
     421 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     422                 :          0 :                         break;
     423                 :            : 
     424                 :            :                     case DCT_TOKEN( created ):
     425         [ +  - ]:        212 :                         if ( aChars.getLength() >= 4 )
     426 [ +  - ][ +  - ]:        212 :                             m_xDocProp->setCreationDate( GetDateTimeFromW3CDTF( aChars ) );
                 [ +  - ]
     427                 :        212 :                         break;
     428                 :            : 
     429                 :            :                     case DC_TOKEN( creator ):
     430 [ +  - ][ +  - ]:        104 :                         m_xDocProp->setAuthor( aChars );
     431                 :        104 :                         break;
     432                 :            : 
     433                 :            :                     case DC_TOKEN( description ):
     434 [ #  # ][ #  # ]:          0 :                         m_xDocProp->setDescription( aChars );
     435                 :          0 :                         break;
     436                 :            : 
     437                 :            :                     case COREPR_TOKEN( keywords ):
     438 [ #  # ][ #  # ]:          0 :                         m_xDocProp->setKeywords( GetKeywordsSet( aChars ) );
         [ #  # ][ #  # ]
     439                 :          0 :                         break;
     440                 :            : 
     441                 :            :                     case DC_TOKEN( language ):
     442         [ #  # ]:          0 :                         if ( aChars.getLength() >= 2 )
     443 [ #  # ][ #  # ]:          0 :                             m_xDocProp->setLanguage( GetLanguage( aChars ) );
     444                 :          0 :                         break;
     445                 :            : 
     446                 :            :                     case COREPR_TOKEN( lastModifiedBy ):
     447 [ +  - ][ +  - ]:        110 :                         m_xDocProp->setModifiedBy( aChars );
     448                 :        110 :                         break;
     449                 :            : 
     450                 :            :                     case COREPR_TOKEN( lastPrinted ):
     451         [ +  - ]:          3 :                         if ( aChars.getLength() >= 4 )
     452 [ +  - ][ +  - ]:          3 :                             m_xDocProp->setPrintDate( GetDateTimeFromW3CDTF( aChars ) );
                 [ +  - ]
     453                 :          3 :                         break;
     454                 :            : 
     455                 :            :                     case DCT_TOKEN( modified ):
     456         [ +  - ]:        119 :                         if ( aChars.getLength() >= 4 )
     457 [ +  - ][ +  - ]:        119 :                             m_xDocProp->setModificationDate( GetDateTimeFromW3CDTF( aChars ) );
         [ +  - ][ #  # ]
     458                 :        119 :                         break;
     459                 :            : 
     460                 :            :                     case COREPR_TOKEN( revision ):
     461                 :            :                         try
     462                 :            :                         {
     463         [ +  - ]:        212 :                             m_xDocProp->setEditingCycles(
     464         [ +  - ]:        212 :                                 static_cast<sal_Int16>(aChars.toInt32()) );
     465                 :            :                         }
     466   [ #  #  #  # ]:          0 :                         catch (lang::IllegalArgumentException &)
     467                 :            :                         {
     468                 :            :                             // ignore
     469                 :            :                         }
     470                 :        212 :                         break;
     471                 :            : 
     472                 :            :                     case DC_TOKEN( subject ):
     473 [ +  - ][ +  - ]:          3 :                         m_xDocProp->setSubject( aChars );
     474                 :          3 :                         break;
     475                 :            : 
     476                 :            :                     case DC_TOKEN( title ):
     477 [ +  - ][ +  - ]:          9 :                         m_xDocProp->setTitle( aChars );
     478                 :        772 :                         break;
     479                 :            : 
     480                 :            :                     default:
     481                 :            :                         OSL_FAIL( "Unexpected core property!" );
     482                 :            :                 }
     483                 :            :             }
     484         [ +  - ]:       1505 :             else if ( m_nState == EXTPR_TOKEN( Properties ) )
     485                 :            :             {
     486   [ +  +  +  +  :       1505 :                 switch( m_nBlock )
          +  +  +  +  +  
          -  -  -  -  +  
          +  -  -  -  +  
                      - ]
     487                 :            :                 {
     488                 :            :                     case EXTPR_TOKEN( Application ):
     489 [ +  - ][ +  - ]:        134 :                         m_xDocProp->setGenerator( aChars );
     490                 :        134 :                         break;
     491                 :            : 
     492                 :            :                     case EXTPR_TOKEN( Template ):
     493 [ +  - ][ +  - ]:         92 :                         m_xDocProp->setTemplateName( aChars );
     494                 :         92 :                         break;
     495                 :            : 
     496                 :            :                     case EXTPR_TOKEN( TotalTime ):
     497                 :            :                         try
     498                 :            :                         {
     499 [ +  - ][ +  - ]:        212 :                             m_xDocProp->setEditingDuration( aChars.toInt32() );
     500                 :            :                         }
     501         [ #  # ]:          0 :                         catch (lang::IllegalArgumentException &)
     502                 :            :                         {
     503                 :            :                             // ignore
     504                 :            :                         }
     505                 :        212 :                         break;
     506                 :            : 
     507                 :            :                     case EXTPR_TOKEN( Characters ):
     508                 :            :                     case EXTPR_TOKEN( Pages ):
     509                 :            :                     case EXTPR_TOKEN( Words ):
     510                 :            :                     case EXTPR_TOKEN( Paragraphs ):
     511         [ +  - ]:        332 :                         UpdateDocStatistic( aChars );
     512                 :        332 :                         break;
     513                 :            : 
     514                 :            :                     case EXTPR_TOKEN( HyperlinksChanged ):
     515         [ +  - ]:         89 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinksChanged" ) );
     516 [ +  - ][ +  - ]:         89 :                         AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
     517                 :         89 :                         break;
     518                 :            : 
     519                 :            :                     case EXTPR_TOKEN( LinksUpToDate ):
     520         [ +  - ]:         89 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LinksUpToDate" ) );
     521 [ +  - ][ +  - ]:         89 :                         AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
     522                 :         89 :                         break;
     523                 :            : 
     524                 :            :                     case EXTPR_TOKEN( ScaleCrop ):
     525         [ +  - ]:         89 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScaleCrop" ) );
     526 [ +  - ][ +  - ]:         89 :                         AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
     527                 :         89 :                         break;
     528                 :            : 
     529                 :            :                     case EXTPR_TOKEN( SharedDoc ):
     530         [ +  - ]:         89 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ShareDoc" ) );
     531 [ +  - ][ +  - ]:         89 :                         AddCustomProperty( uno::makeAny( aChars.toBoolean() ) ); // the property has boolean type
     532                 :         89 :                         break;
     533                 :            : 
     534                 :            :                     case EXTPR_TOKEN( DocSecurity ):
     535         [ +  - ]:         89 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DocSecurity" ) );
     536 [ +  - ][ +  - ]:         89 :                         AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
     537                 :         89 :                         break;
     538                 :            : 
     539                 :            :                     case EXTPR_TOKEN( HiddenSlides ):
     540         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HiddenSlides" ) );
     541 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
     542                 :          0 :                         break;
     543                 :            : 
     544                 :            :                     case EXTPR_TOKEN( MMClips ):
     545         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MMClips" ) );
     546 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
     547                 :          0 :                         break;
     548                 :            : 
     549                 :            :                     case EXTPR_TOKEN( Notes ):
     550         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Notes" ) );
     551 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
     552                 :          0 :                         break;
     553                 :            : 
     554                 :            :                     case EXTPR_TOKEN( Slides ):
     555         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Slides" ) );
     556 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars.toInt32() ) ); // the property has sal_Int32 type
     557                 :          0 :                         break;
     558                 :            : 
     559                 :            :                     case EXTPR_TOKEN( AppVersion ):
     560         [ +  - ]:         89 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AppVersion" ) );
     561 [ +  - ][ +  - ]:         89 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     562                 :         89 :                         break;
     563                 :            : 
     564                 :            :                     case EXTPR_TOKEN( Company ):
     565         [ +  - ]:         35 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Company" ) );
     566 [ +  - ][ +  - ]:         35 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     567                 :         35 :                         break;
     568                 :            : 
     569                 :            :                     case EXTPR_TOKEN( HyperlinkBase ):
     570         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HyperlinkBase" ) );
     571 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     572                 :          0 :                         break;
     573                 :            : 
     574                 :            :                     case EXTPR_TOKEN( Manager ):
     575         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Manager" ) );
     576 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     577                 :          0 :                         break;
     578                 :            : 
     579                 :            :                     case EXTPR_TOKEN( PresentationFormat ):
     580         [ #  # ]:          0 :                         m_aCustomPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PresentationFormat" ) );
     581 [ #  # ][ #  # ]:          0 :                         AddCustomProperty( uno::makeAny( aChars ) ); // the property has string type
     582                 :          0 :                         break;
     583                 :            : 
     584                 :            :                     case EXTPR_TOKEN( CharactersWithSpaces ):
     585                 :            :                     case EXTPR_TOKEN( Lines ):
     586                 :            :                     case EXTPR_TOKEN( DigSig ):
     587                 :            :                     case EXTPR_TOKEN( HeadingPairs ):
     588                 :            :                     case EXTPR_TOKEN( HLinks ):
     589                 :            :                     case EXTPR_TOKEN( TitlesOfParts ):
     590                 :            :                         // ignored during the import currently
     591                 :       1505 :                         break;
     592                 :            : 
     593                 :            :                     default:
     594                 :            :                         OSL_FAIL( "Unexpected extended property!" );
     595                 :            :                 }
     596                 :            :             }
     597         [ #  # ]:          0 :             else if ( m_nState == CUSTPR_TOKEN( Properties ) )
     598                 :            :             {
     599         [ #  # ]:          0 :                 if ( m_nBlock == CUSTPR_TOKEN( property ) )
     600                 :            :                 {
     601                 :            :                     // this is a custom property
     602   [ #  #  #  #  :          0 :                     switch( m_nType )
             #  #  #  #  
                      # ]
     603                 :            :                     {
     604                 :            :                         case VT_TOKEN( bool ):
     605 [ #  # ][ #  # ]:          0 :                             AddCustomProperty( uno::makeAny( aChars.toBoolean() ) );
     606                 :          0 :                             break;
     607                 :            : 
     608                 :            :                         case VT_TOKEN( bstr ):
     609                 :            :                         case VT_TOKEN( lpstr ):
     610                 :            :                         case VT_TOKEN( lpwstr ):
     611 [ #  # ][ #  # ]:          0 :                             AddCustomProperty( uno::makeAny( AttributeConversion::decodeXString( aChars ) ) ); // the property has string type
                 [ #  # ]
     612                 :          0 :                             break;
     613                 :            : 
     614                 :            :                         case VT_TOKEN( date ):
     615                 :            :                         case VT_TOKEN( filetime ):
     616 [ #  # ][ #  # ]:          0 :                             AddCustomProperty( uno::makeAny( GetDateTimeFromW3CDTF( aChars ) ) );
                 [ #  # ]
     617                 :            : 
     618                 :            :                         case VT_TOKEN( i1 ):
     619                 :            :                         case VT_TOKEN( i2 ):
     620 [ #  # ][ #  # ]:          0 :                             AddCustomProperty( uno::makeAny( (sal_Int16)aChars.toInt32() ) );
     621                 :          0 :                             break;
     622                 :            : 
     623                 :            :                         case VT_TOKEN( i4 ):
     624                 :            :                         case VT_TOKEN( int ):
     625 [ #  # ][ #  # ]:          0 :                             AddCustomProperty( uno::makeAny( aChars.toInt32() ) );
     626                 :          0 :                             break;
     627                 :            : 
     628                 :            :                         case VT_TOKEN( i8 ):
     629 [ #  # ][ #  # ]:          0 :                             AddCustomProperty( uno::makeAny( aChars.toInt64() ) );
     630                 :          0 :                             break;
     631                 :            : 
     632                 :            :                         case VT_TOKEN( r4 ):
     633 [ #  # ][ #  # ]:          0 :                             AddCustomProperty( uno::makeAny( aChars.toFloat() ) );
     634                 :          0 :                             break;
     635                 :            : 
     636                 :            :                         case VT_TOKEN( r8 ):
     637 [ #  # ][ #  # ]:          0 :                             AddCustomProperty( uno::makeAny( aChars.toDouble() ) );
     638                 :          0 :                             break;
     639                 :            : 
     640                 :            :                         default:
     641                 :            :                             // all the other types are ignored;
     642                 :          0 :                             break;
     643                 :            :                     }
     644                 :            :                 }
     645                 :            :                 else
     646                 :            :                 {
     647                 :            :                     OSL_FAIL( "Unexpected tag in custom property!" );
     648                 :            :                 }
     649                 :            :             }
     650                 :            :         }
     651                 :            :     }
     652                 :          0 :     catch( uno::RuntimeException& )
     653                 :            :     {
     654                 :          0 :         throw;
     655                 :            :     }
     656                 :          0 :     catch( xml::sax::SAXException& )
     657                 :            :     {
     658                 :          0 :         throw;
     659                 :            :     }
     660   [ #  #  #  # ]:          0 :     catch( uno::Exception& e )
     661                 :            :     {
     662                 :            :         throw xml::sax::SAXException(
     663                 :            :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Error while setting document property!" ) ),
     664                 :            :             uno::Reference< uno::XInterface >(),
     665   [ #  #  #  #  :          0 :             uno::makeAny( e ) );
                   #  # ]
     666                 :            :     }
     667                 :       2362 : }
     668                 :            : 
     669                 :            : // ------------------------------------------------
     670                 :          0 : void SAL_CALL OOXMLDocPropHandler::ignorableWhitespace( const ::rtl::OUString& )
     671                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     672                 :            : {
     673                 :          0 : }
     674                 :            : 
     675                 :            : // ------------------------------------------------
     676                 :          0 : void SAL_CALL OOXMLDocPropHandler::processingInstruction( const ::rtl::OUString&, const ::rtl::OUString& )
     677                 :            :     throw (xml::sax::SAXException, uno::RuntimeException)
     678                 :            : {
     679                 :          0 : }
     680                 :            : 
     681                 :            : } // namespace docprop
     682                 :            : } // namespace oox
     683                 :            : 
     684                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10