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

Generated by: LCOV version 1.10