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

Generated by: LCOV version 1.11