LCOV - code coverage report
Current view: top level - xmlscript/source/xmllib_imexp - imp_share.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 23 52.2 %
Date: 2012-08-25 Functions: 8 9 88.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 22 18.2 %

           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 <xmlscript/xmllib_imexp.hxx>
      21                 :            : 
      22                 :            : #include <cppuhelper/implbase1.hxx>
      23                 :            : 
      24                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      26                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      27                 :            : 
      28                 :            : #include <com/sun/star/awt/XControlModel.hpp>
      29                 :            : #include <com/sun/star/awt/FontDescriptor.hpp>
      30                 :            : 
      31                 :            : #include <com/sun/star/xml/input/XRoot.hpp>
      32                 :            : 
      33                 :            : #include <vector>
      34                 :            : 
      35                 :            : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
      36                 :            : 
      37                 :            : 
      38                 :            : using namespace ::rtl;
      39                 :            : using namespace ::std;
      40                 :            : using namespace ::com::sun::star;
      41                 :            : using namespace ::com::sun::star::uno;
      42                 :            : 
      43                 :            : namespace xmlscript
      44                 :            : {
      45                 :            : inline sal_Int32 toInt32( OUString const & rStr ) SAL_THROW(())
      46                 :            : {
      47                 :            :     sal_Int32 nVal;
      48                 :            :     if (rStr.getLength() > 2 && rStr[ 0 ] == '0' && rStr[ 1 ] == 'x')
      49                 :            :     {
      50                 :            :         nVal = rStr.copy( 2 ).toInt32( 16 );
      51                 :            :     }
      52                 :            :     else
      53                 :            :     {
      54                 :            :         nVal = rStr.toInt32();
      55                 :            :     }
      56                 :            :     return nVal;
      57                 :            : }
      58                 :          0 : inline bool getBoolAttr(
      59                 :            :     sal_Bool * pRet, OUString const & rAttrName,
      60                 :            :     Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid )
      61                 :            : {
      62                 :            :     OUString aValue(
      63 [ #  # ][ #  # ]:          0 :         xAttributes->getValueByUidName( uid, rAttrName ) );
      64         [ #  # ]:          0 :     if (!aValue.isEmpty())
      65                 :            :     {
      66         [ #  # ]:          0 :         if ( aValue == "true" )
      67                 :            :         {
      68                 :          0 :             *pRet = sal_True;
      69                 :          0 :             return true;
      70                 :            :         }
      71         [ #  # ]:          0 :         else if ( aValue == "false" )
      72                 :            :         {
      73                 :          0 :             *pRet = sal_False;
      74                 :          0 :             return true;
      75                 :            :         }
      76                 :            :         else
      77                 :            :         {
      78                 :            :             throw xml::sax::SAXException(
      79                 :            :                 rAttrName +
      80                 :            :                 OUString( RTL_CONSTASCII_USTRINGPARAM(
      81                 :            :                               ": no boolean value (true|false)!") ),
      82 [ #  # ][ #  # ]:          0 :                 Reference< XInterface >(), Any() );
      83                 :            :         }
      84                 :            :     }
      85                 :          0 :     return false;
      86                 :            : }
      87                 :            : 
      88                 :            : inline bool getStringAttr(
      89                 :            :     OUString * pRet, OUString const & rAttrName,
      90                 :            :     Reference< xml::input::XAttributes > const & xAttributes, sal_Int32 uid )
      91                 :            : {
      92                 :            :     *pRet = xAttributes->getValueByUidName( uid, rAttrName );
      93                 :            :     return (!pRet->isEmpty());
      94                 :            : }
      95                 :            : 
      96                 :            : inline bool getLongAttr(
      97                 :            :     sal_Int32 * pRet, OUString const & rAttrName,
      98                 :            :     Reference< xml::input::XAttributes > const & xAttributes,
      99                 :            :     sal_Int32 uid )
     100                 :            : {
     101                 :            :     OUString aValue(
     102                 :            :         xAttributes->getValueByUidName( uid, rAttrName ) );
     103                 :            :     if (!aValue.isEmpty())
     104                 :            :     {
     105                 :            :         *pRet = toInt32( aValue );
     106                 :            :         return true;
     107                 :            :     }
     108                 :            :     return false;
     109                 :            : }
     110                 :            : 
     111                 :            : //==================================================================================================
     112                 :            : // Library import
     113                 :            : 
     114                 :            : //==================================================================================================
     115                 :            : struct LibraryImport
     116                 :            :     : public ::cppu::WeakImplHelper1< xml::input::XRoot >
     117                 :            : {
     118                 :            :     friend class LibrariesElement;
     119                 :            :     friend class LibraryElement;
     120                 :            : 
     121                 :            :     LibDescriptorArray* mpLibArray;
     122                 :            :     LibDescriptor*      mpLibDesc;      // Single library mode
     123                 :            : 
     124                 :            :     sal_Int32 XMLNS_LIBRARY_UID;
     125                 :            :     sal_Int32 XMLNS_XLINK_UID;
     126                 :            : 
     127                 :            : public:
     128                 :        254 :     inline LibraryImport( LibDescriptorArray* pLibArray )
     129                 :            :         SAL_THROW(())
     130                 :            :         : mpLibArray( pLibArray )
     131                 :        254 :         , mpLibDesc( NULL ) {}
     132                 :            :     // Single library mode
     133                 :       1494 :     inline LibraryImport( LibDescriptor* pLibDesc )
     134                 :            :         SAL_THROW(())
     135                 :            :         : mpLibArray( NULL )
     136                 :       1494 :         , mpLibDesc( pLibDesc ) {}
     137                 :            :     virtual ~LibraryImport()
     138                 :            :         SAL_THROW(());
     139                 :            : 
     140                 :            :     // XRoot
     141                 :            :     virtual void SAL_CALL startDocument(
     142                 :            :         Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
     143                 :            :         throw (xml::sax::SAXException, RuntimeException);
     144                 :            :     virtual void SAL_CALL endDocument()
     145                 :            :         throw (xml::sax::SAXException, RuntimeException);
     146                 :            :     virtual void SAL_CALL processingInstruction(
     147                 :            :         OUString const & rTarget, OUString const & rData )
     148                 :            :         throw (xml::sax::SAXException, RuntimeException);
     149                 :            :     virtual void SAL_CALL setDocumentLocator(
     150                 :            :         Reference< xml::sax::XLocator > const & xLocator )
     151                 :            :         throw (xml::sax::SAXException, RuntimeException);
     152                 :            :     virtual Reference< xml::input::XElement > SAL_CALL startRootElement(
     153                 :            :         sal_Int32 nUid, OUString const & rLocalName,
     154                 :            :         Reference< xml::input::XAttributes > const & xAttributes )
     155                 :            :         throw (xml::sax::SAXException, RuntimeException);
     156                 :            : };
     157                 :            : 
     158                 :            : //==================================================================================================
     159                 :            : class LibElementBase
     160                 :            :     : public ::cppu::WeakImplHelper1< xml::input::XElement >
     161                 :            : {
     162                 :            : protected:
     163                 :            :     LibraryImport * _pImport;
     164                 :            :     LibElementBase * _pParent;
     165                 :            : 
     166                 :            :     OUString _aLocalName;
     167                 :            :     Reference< xml::input::XAttributes > _xAttributes;
     168                 :            : 
     169                 :            : public:
     170                 :            :     LibElementBase(
     171                 :            :         OUString const & rLocalName,
     172                 :            :         Reference< xml::input::XAttributes > const & xAttributes,
     173                 :            :         LibElementBase * pParent, LibraryImport * pImport )
     174                 :            :         SAL_THROW(());
     175                 :            :     virtual ~LibElementBase()
     176                 :            :         SAL_THROW(());
     177                 :            : 
     178                 :            :     // XElement
     179                 :            :     virtual Reference< xml::input::XElement > SAL_CALL getParent()
     180                 :            :         throw (RuntimeException);
     181                 :            :     virtual OUString SAL_CALL getLocalName()
     182                 :            :         throw (RuntimeException);
     183                 :            :     virtual sal_Int32 SAL_CALL getUid()
     184                 :            :         throw (RuntimeException);
     185                 :            :     virtual Reference< xml::input::XAttributes > SAL_CALL getAttributes()
     186                 :            :         throw (RuntimeException);
     187                 :            :     virtual void SAL_CALL ignorableWhitespace(
     188                 :            :         OUString const & rWhitespaces )
     189                 :            :         throw (xml::sax::SAXException, RuntimeException);
     190                 :            :     virtual void SAL_CALL characters( OUString const & rChars )
     191                 :            :         throw (xml::sax::SAXException, RuntimeException);
     192                 :            :     virtual void SAL_CALL processingInstruction(
     193                 :            :         OUString const & rTarget, OUString const & rData )
     194                 :            :         throw (xml::sax::SAXException, RuntimeException);
     195                 :            :     virtual void SAL_CALL endElement()
     196                 :            :         throw (xml::sax::SAXException, RuntimeException);
     197                 :            :     virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
     198                 :            :         sal_Int32 nUid, OUString const & rLocalName,
     199                 :            :         Reference< xml::input::XAttributes > const & xAttributes )
     200                 :            :         throw (xml::sax::SAXException, RuntimeException);
     201                 :            : };
     202                 :            : 
     203                 :            : //==================================================================================================
     204                 :            : 
     205         [ -  + ]:        508 : class LibrariesElement : public LibElementBase
     206                 :            : {
     207                 :            :     friend class LibraryElement;
     208                 :            : 
     209                 :            : protected:
     210                 :            :     vector< LibDescriptor > mLibDescriptors;
     211                 :            : 
     212                 :            : public:
     213                 :            :     virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
     214                 :            :         sal_Int32 nUid, OUString const & rLocalName,
     215                 :            :         Reference< xml::input::XAttributes > const & xAttributes )
     216                 :            :         throw (xml::sax::SAXException, RuntimeException);
     217                 :            :     virtual void SAL_CALL endElement()
     218                 :            :         throw (xml::sax::SAXException, RuntimeException);
     219                 :            : 
     220                 :        254 :     LibrariesElement(
     221                 :            :         OUString const & rLocalName,
     222                 :            :         Reference< xml::input::XAttributes > const & xAttributes,
     223                 :            :         LibElementBase * pParent, LibraryImport * pImport )
     224                 :            :         SAL_THROW(())
     225         [ +  - ]:        254 :         : LibElementBase( rLocalName, xAttributes, pParent, pImport )
     226                 :        254 :         {}
     227                 :            : };
     228                 :            : 
     229                 :            : //==================================================================================================
     230                 :            : 
     231         [ -  + ]:       5232 : class LibraryElement : public LibElementBase
     232                 :            : {
     233                 :            : protected:
     234                 :            :     vector< OUString > mElements;
     235                 :            : 
     236                 :            : public:
     237                 :            : 
     238                 :            :     virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
     239                 :            :         sal_Int32 nUid, OUString const & rLocalName,
     240                 :            :         Reference< xml::input::XAttributes > const & xAttributes )
     241                 :            :         throw (xml::sax::SAXException, RuntimeException);
     242                 :            :     virtual void SAL_CALL endElement()
     243                 :            :         throw (xml::sax::SAXException, RuntimeException);
     244                 :            : 
     245                 :       2616 :     LibraryElement(
     246                 :            :         OUString const & rLocalName,
     247                 :            :         Reference< xml::input::XAttributes > const & xAttributes,
     248                 :            :         LibElementBase * pParent, LibraryImport * pImport )
     249                 :            :         SAL_THROW(())
     250         [ +  - ]:       2616 :         : LibElementBase( rLocalName, xAttributes, pParent, pImport )
     251                 :       2616 :     {}
     252                 :            : };
     253                 :            : 
     254                 :            : }
     255                 :            : 
     256                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10