LCOV - code coverage report
Current view: top level - xmlscript/source/xmllib_imexp - xmllib_import.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 107 0.0 %
Date: 2014-04-14 Functions: 0 27 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 "imp_share.hxx"
      21             : #include "xml_import.hxx"
      22             : 
      23             : namespace xmlscript
      24             : {
      25             : 
      26           0 : Reference< xml::input::XElement > LibElementBase::getParent()
      27             :     throw (RuntimeException, std::exception)
      28             : {
      29           0 :     return static_cast< xml::input::XElement * >( _pParent );
      30             : }
      31             : 
      32           0 : OUString LibElementBase::getLocalName()
      33             :     throw (RuntimeException, std::exception)
      34             : {
      35           0 :     return _aLocalName;
      36             : }
      37             : 
      38           0 : sal_Int32 LibElementBase::getUid()
      39             :     throw (RuntimeException, std::exception)
      40             : {
      41           0 :     return _pImport->XMLNS_LIBRARY_UID;
      42             : }
      43             : 
      44           0 : Reference< xml::input::XAttributes > LibElementBase::getAttributes()
      45             :     throw (RuntimeException, std::exception)
      46             : {
      47           0 :     return _xAttributes;
      48             : }
      49             : 
      50           0 : void LibElementBase::ignorableWhitespace(
      51             :     OUString const & /*rWhitespaces*/ )
      52             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
      53             : {
      54           0 : }
      55             : 
      56           0 : void LibElementBase::characters( OUString const & /*rChars*/ )
      57             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
      58             : {
      59             :     // not used, all characters ignored
      60           0 : }
      61             : 
      62           0 : void LibElementBase::processingInstruction(
      63             :     OUString const & /*rTarget*/, OUString const & /*rData*/ )
      64             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
      65             : {
      66           0 : }
      67             : 
      68           0 : void LibElementBase::endElement()
      69             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
      70             : {
      71           0 : }
      72           0 : Reference< xml::input::XElement > LibElementBase::startChildElement(
      73             :     sal_Int32 /*nUid*/, OUString const & /*rLocalName*/,
      74             :     Reference< xml::input::XAttributes > const & /*xAttributes*/ )
      75             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
      76             : {
      77           0 :     throw xml::sax::SAXException("unexpected element!", Reference< XInterface >(), Any() );
      78             : }
      79             : 
      80           0 : LibElementBase::LibElementBase(
      81             :     OUString const & rLocalName,
      82             :     Reference< xml::input::XAttributes > const & xAttributes,
      83             :     LibElementBase * pParent, LibraryImport * pImport )
      84             :     SAL_THROW(())
      85             :     : _pImport( pImport )
      86             :     , _pParent( pParent )
      87             :     , _aLocalName( rLocalName )
      88           0 :     , _xAttributes( xAttributes )
      89             : {
      90           0 :     _pImport->acquire();
      91             : 
      92           0 :     if (_pParent)
      93             :     {
      94           0 :         _pParent->acquire();
      95             :     }
      96           0 : }
      97             : 
      98           0 : LibElementBase::~LibElementBase()
      99             :     SAL_THROW(())
     100             : {
     101           0 :     _pImport->release();
     102             : 
     103           0 :     if (_pParent)
     104             :     {
     105           0 :         _pParent->release();
     106             :     }
     107             : 
     108             : #if OSL_DEBUG_LEVEL > 1
     109             :     OString aStr( OUStringToOString( _aLocalName, RTL_TEXTENCODING_ASCII_US ) );
     110             :     SAL_INFO("xmlscript.xmllib", "LibElementBase::~LibElementBase(): " << aStr.getStr() );
     111             : #endif
     112           0 : }
     113             : 
     114             : // XRoot
     115             : 
     116           0 : void LibraryImport::startDocument(
     117             :     Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
     118             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     119             : {
     120           0 :     XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri( XMLNS_LIBRARY_URI );
     121           0 :     XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri( XMLNS_XLINK_URI );
     122           0 : }
     123             : 
     124           0 : void LibraryImport::endDocument()
     125             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     126             : {
     127           0 : }
     128             : 
     129           0 : void LibraryImport::processingInstruction(
     130             :     OUString const & /*rTarget*/, OUString const & /*rData*/ )
     131             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     132             : {
     133           0 : }
     134             : 
     135           0 : void LibraryImport::setDocumentLocator(
     136             :     Reference< xml::sax::XLocator > const & /*xLocator*/ )
     137             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     138             : {
     139           0 : }
     140             : 
     141           0 : Reference< xml::input::XElement > LibraryImport::startRootElement(
     142             :     sal_Int32 nUid, OUString const & rLocalName,
     143             :     Reference< xml::input::XAttributes > const & xAttributes )
     144             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     145             : {
     146           0 :     if (XMLNS_LIBRARY_UID != nUid)
     147             :     {
     148           0 :         throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     149             :     }
     150           0 :     else if ( mpLibArray && rLocalName == "libraries" )
     151             :     {
     152           0 :         return new LibrariesElement( rLocalName, xAttributes, 0, this );
     153             :     }
     154           0 :     else if ( mpLibDesc && rLocalName == "library" )
     155             :     {
     156           0 :         LibDescriptor& aDesc = *mpLibDesc;
     157           0 :         aDesc.bLink = aDesc.bReadOnly = aDesc.bPasswordProtected = aDesc.bPreload = false;
     158             : 
     159           0 :         aDesc.aName = xAttributes->getValueByUidName(XMLNS_LIBRARY_UID, "name" );
     160           0 :         getBoolAttr( &aDesc.bReadOnly, "readonly", xAttributes, XMLNS_LIBRARY_UID );
     161           0 :         getBoolAttr( &aDesc.bPasswordProtected, "passwordprotected", xAttributes, XMLNS_LIBRARY_UID );
     162           0 :         getBoolAttr( &aDesc.bPreload, "preload", xAttributes, XMLNS_LIBRARY_UID );
     163             : 
     164           0 :         return new LibraryElement( rLocalName, xAttributes, 0, this );
     165             :     }
     166             :     else
     167             :     {
     168           0 :         throw xml::sax::SAXException( "illegal root element (expected libraries) given: " + rLocalName, Reference< XInterface >(), Any() );
     169             :     }
     170             : }
     171             : 
     172           0 : LibraryImport::~LibraryImport()
     173             :     SAL_THROW(())
     174             : {
     175             : #if OSL_DEBUG_LEVEL > 1
     176             :     SAL_INFO("xmlscript.xmllib", "LibraryImport::~LibraryImport()." );
     177             : #endif
     178           0 : }
     179             : 
     180             : // libraries
     181           0 : Reference< xml::input::XElement > LibrariesElement::startChildElement(
     182             :     sal_Int32 nUid, OUString const & rLocalName,
     183             :     Reference< xml::input::XAttributes > const & xAttributes )
     184             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     185             : {
     186           0 :     if (_pImport->XMLNS_LIBRARY_UID != nUid)
     187             :     {
     188           0 :         throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     189             :     }
     190             :     // library
     191           0 :     else if ( rLocalName == "library" )
     192             :     {
     193           0 :         LibDescriptor aDesc;
     194           0 :         aDesc.bLink = aDesc.bReadOnly = aDesc.bPasswordProtected = aDesc.bPreload = false;
     195             : 
     196           0 :         aDesc.aName = xAttributes->getValueByUidName(_pImport->XMLNS_LIBRARY_UID, "name" );
     197           0 :         aDesc.aStorageURL = xAttributes->getValueByUidName( _pImport->XMLNS_XLINK_UID, "href" );
     198           0 :         getBoolAttr(&aDesc.bLink, "link", xAttributes, _pImport->XMLNS_LIBRARY_UID );
     199           0 :         getBoolAttr(&aDesc.bReadOnly, "readonly", xAttributes, _pImport->XMLNS_LIBRARY_UID );
     200           0 :         getBoolAttr(&aDesc.bPasswordProtected, "passwordprotected", xAttributes, _pImport->XMLNS_LIBRARY_UID );
     201             : 
     202           0 :         mLibDescriptors.push_back( aDesc );
     203           0 :         return new LibraryElement( rLocalName, xAttributes, this, _pImport );
     204             :     }
     205             :     else
     206             :     {
     207           0 :         throw xml::sax::SAXException( "expected styles ot bulletinboard element!", Reference< XInterface >(), Any() );
     208             :     }
     209             : }
     210             : 
     211           0 : void LibrariesElement::endElement()
     212             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     213             : {
     214           0 :     sal_Int32 nLibCount = _pImport->mpLibArray->mnLibCount = (sal_Int32)mLibDescriptors.size();
     215           0 :     _pImport->mpLibArray->mpLibs = new LibDescriptor[ nLibCount ];
     216             : 
     217           0 :     for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
     218             :     {
     219           0 :         const LibDescriptor& rLib = mLibDescriptors[i];
     220           0 :         _pImport->mpLibArray->mpLibs[i] = rLib;
     221             :     }
     222           0 : }
     223             : 
     224             : // library
     225           0 : Reference< xml::input::XElement > LibraryElement::startChildElement(
     226             :     sal_Int32 nUid, OUString const & rLocalName,
     227             :     Reference< xml::input::XAttributes > const & xAttributes )
     228             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     229             : {
     230           0 :     if (_pImport->XMLNS_LIBRARY_UID != nUid)
     231             :     {
     232           0 :         throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     233             :     }
     234             :     // library
     235           0 :     else if ( rLocalName == "element" )
     236             :     {
     237           0 :         OUString aValue( xAttributes->getValueByUidName(_pImport->XMLNS_LIBRARY_UID, "name" ) );
     238           0 :         if (!aValue.isEmpty())
     239           0 :             mElements.push_back( aValue );
     240             : 
     241           0 :         return new LibElementBase( rLocalName, xAttributes, this, _pImport );
     242             :     }
     243             :     else
     244             :     {
     245           0 :         throw xml::sax::SAXException( "expected styles ot bulletinboard element!", Reference< XInterface >(), Any() );
     246             :     }
     247             : }
     248             : 
     249           0 : void LibraryElement::endElement()
     250             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     251             : {
     252           0 :     sal_Int32 nElementCount = mElements.size();
     253           0 :     Sequence< OUString > aElementNames( nElementCount );
     254           0 :     OUString* pElementNames = aElementNames.getArray();
     255           0 :     for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
     256           0 :         pElementNames[i] = mElements[i];
     257             : 
     258           0 :     LibDescriptor* pLib = _pImport->mpLibDesc;
     259           0 :     if( !pLib )
     260           0 :         pLib = &static_cast< LibrariesElement* >( _pParent )->mLibDescriptors.back();
     261           0 :     pLib->aElementNames = aElementNames;
     262           0 : }
     263             : 
     264             : Reference< ::com::sun::star::xml::sax::XDocumentHandler >
     265           0 : SAL_CALL importLibraryContainer( LibDescriptorArray* pLibArray )
     266             :         SAL_THROW( (Exception) )
     267             : {
     268             :     return ::xmlscript::createDocumentHandler(
     269           0 :         static_cast< xml::input::XRoot * >( new LibraryImport( pLibArray ) ) );
     270             : }
     271             : 
     272             : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >
     273           0 : SAL_CALL importLibrary( LibDescriptor& rLib )
     274             :         SAL_THROW( (::com::sun::star::uno::Exception) )
     275             : {
     276             :     return ::xmlscript::createDocumentHandler(
     277           0 :         static_cast< xml::input::XRoot * >( new LibraryImport( &rLib ) ) );
     278             : }
     279             : 
     280           0 : LibDescriptorArray::LibDescriptorArray( sal_Int32 nLibCount )
     281             : {
     282           0 :     mnLibCount = nLibCount;
     283           0 :     mpLibs = new LibDescriptor[ mnLibCount ];
     284           0 : }
     285             : 
     286           0 : LibDescriptorArray::~LibDescriptorArray()
     287             : {
     288           0 :     delete[] mpLibs;
     289           0 : }
     290             : 
     291             : }
     292             : 
     293             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10