LCOV - code coverage report
Current view: top level - xmlscript/source/xmllib_imexp - xmllib_import.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 85 107 79.4 %
Date: 2014-04-11 Functions: 19 27 70.4 %
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       17194 : void LibElementBase::characters( OUString const & /*rChars*/ )
      57             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
      58             : {
      59             :     // not used, all characters ignored
      60       17194 : }
      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        6428 : void LibElementBase::endElement()
      69             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
      70             : {
      71        6428 : }
      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        9312 : 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        9312 :     , _xAttributes( xAttributes )
      89             : {
      90        9312 :     _pImport->acquire();
      91             : 
      92        9312 :     if (_pParent)
      93             :     {
      94        7768 :         _pParent->acquire();
      95             :     }
      96        9312 : }
      97             : 
      98       25052 : LibElementBase::~LibElementBase()
      99             :     SAL_THROW(())
     100             : {
     101        9312 :     _pImport->release();
     102             : 
     103        9312 :     if (_pParent)
     104             :     {
     105        7768 :         _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       15740 : }
     113             : 
     114             : // XRoot
     115             : 
     116        1544 : void LibraryImport::startDocument(
     117             :     Reference< xml::input::XNamespaceMapping > const & xNamespaceMapping )
     118             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     119             : {
     120        1544 :     XMLNS_LIBRARY_UID = xNamespaceMapping->getUidByUri( XMLNS_LIBRARY_URI );
     121        1544 :     XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri( XMLNS_XLINK_URI );
     122        1544 : }
     123             : 
     124        1544 : void LibraryImport::endDocument()
     125             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     126             : {
     127        1544 : }
     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        1544 : void LibraryImport::setDocumentLocator(
     136             :     Reference< xml::sax::XLocator > const & /*xLocator*/ )
     137             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     138             : {
     139        1544 : }
     140             : 
     141        1544 : 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        1544 :     if (XMLNS_LIBRARY_UID != nUid)
     147             :     {
     148           0 :         throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     149             :     }
     150        1544 :     else if ( mpLibArray && rLocalName == "libraries" )
     151             :     {
     152         204 :         return new LibrariesElement( rLocalName, xAttributes, 0, this );
     153             :     }
     154        1340 :     else if ( mpLibDesc && rLocalName == "library" )
     155             :     {
     156        1340 :         LibDescriptor& aDesc = *mpLibDesc;
     157        1340 :         aDesc.bLink = aDesc.bReadOnly = aDesc.bPasswordProtected = aDesc.bPreload = false;
     158             : 
     159        1340 :         aDesc.aName = xAttributes->getValueByUidName(XMLNS_LIBRARY_UID, "name" );
     160        1340 :         getBoolAttr( &aDesc.bReadOnly, "readonly", xAttributes, XMLNS_LIBRARY_UID );
     161        1340 :         getBoolAttr( &aDesc.bPasswordProtected, "passwordprotected", xAttributes, XMLNS_LIBRARY_UID );
     162        1340 :         getBoolAttr( &aDesc.bPreload, "preload", xAttributes, XMLNS_LIBRARY_UID );
     163             : 
     164        1340 :         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        3088 : LibraryImport::~LibraryImport()
     173             :     SAL_THROW(())
     174             : {
     175             : #if OSL_DEBUG_LEVEL > 1
     176             :     SAL_INFO("xmlscript.xmllib", "LibraryImport::~LibraryImport()." );
     177             : #endif
     178        3088 : }
     179             : 
     180             : // libraries
     181        1340 : 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        1340 :     if (_pImport->XMLNS_LIBRARY_UID != nUid)
     187             :     {
     188           0 :         throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     189             :     }
     190             :     // library
     191        1340 :     else if ( rLocalName == "library" )
     192             :     {
     193        1340 :         LibDescriptor aDesc;
     194        1340 :         aDesc.bLink = aDesc.bReadOnly = aDesc.bPasswordProtected = aDesc.bPreload = false;
     195             : 
     196        1340 :         aDesc.aName = xAttributes->getValueByUidName(_pImport->XMLNS_LIBRARY_UID, "name" );
     197        1340 :         aDesc.aStorageURL = xAttributes->getValueByUidName( _pImport->XMLNS_XLINK_UID, "href" );
     198        1340 :         getBoolAttr(&aDesc.bLink, "link", xAttributes, _pImport->XMLNS_LIBRARY_UID );
     199        1340 :         getBoolAttr(&aDesc.bReadOnly, "readonly", xAttributes, _pImport->XMLNS_LIBRARY_UID );
     200        1340 :         getBoolAttr(&aDesc.bPasswordProtected, "passwordprotected", xAttributes, _pImport->XMLNS_LIBRARY_UID );
     201             : 
     202        1340 :         mLibDescriptors.push_back( aDesc );
     203        2680 :         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         204 : void LibrariesElement::endElement()
     212             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     213             : {
     214         204 :     sal_Int32 nLibCount = _pImport->mpLibArray->mnLibCount = (sal_Int32)mLibDescriptors.size();
     215         204 :     _pImport->mpLibArray->mpLibs = new LibDescriptor[ nLibCount ];
     216             : 
     217        1544 :     for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
     218             :     {
     219        1340 :         const LibDescriptor& rLib = mLibDescriptors[i];
     220        1340 :         _pImport->mpLibArray->mpLibs[i] = rLib;
     221             :     }
     222         204 : }
     223             : 
     224             : // library
     225        6428 : 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        6428 :     if (_pImport->XMLNS_LIBRARY_UID != nUid)
     231             :     {
     232           0 :         throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     233             :     }
     234             :     // library
     235        6428 :     else if ( rLocalName == "element" )
     236             :     {
     237        6428 :         OUString aValue( xAttributes->getValueByUidName(_pImport->XMLNS_LIBRARY_UID, "name" ) );
     238        6428 :         if (!aValue.isEmpty())
     239        6428 :             mElements.push_back( aValue );
     240             : 
     241       12856 :         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        2680 : void LibraryElement::endElement()
     250             :     throw (xml::sax::SAXException, RuntimeException, std::exception)
     251             : {
     252        2680 :     sal_Int32 nElementCount = mElements.size();
     253        2680 :     Sequence< OUString > aElementNames( nElementCount );
     254        2680 :     OUString* pElementNames = aElementNames.getArray();
     255        9108 :     for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
     256        6428 :         pElementNames[i] = mElements[i];
     257             : 
     258        2680 :     LibDescriptor* pLib = _pImport->mpLibDesc;
     259        2680 :     if( !pLib )
     260        1340 :         pLib = &static_cast< LibrariesElement* >( _pParent )->mLibDescriptors.back();
     261        2680 :     pLib->aElementNames = aElementNames;
     262        2680 : }
     263             : 
     264             : Reference< ::com::sun::star::xml::sax::XDocumentHandler >
     265         204 : SAL_CALL importLibraryContainer( LibDescriptorArray* pLibArray )
     266             :         SAL_THROW( (Exception) )
     267             : {
     268             :     return ::xmlscript::createDocumentHandler(
     269         204 :         static_cast< xml::input::XRoot * >( new LibraryImport( pLibArray ) ) );
     270             : }
     271             : 
     272             : ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >
     273        1340 : SAL_CALL importLibrary( LibDescriptor& rLib )
     274             :         SAL_THROW( (::com::sun::star::uno::Exception) )
     275             : {
     276             :     return ::xmlscript::createDocumentHandler(
     277        1340 :         static_cast< xml::input::XRoot * >( new LibraryImport( &rLib ) ) );
     278             : }
     279             : 
     280        1264 : LibDescriptorArray::LibDescriptorArray( sal_Int32 nLibCount )
     281             : {
     282        1264 :     mnLibCount = nLibCount;
     283        1264 :     mpLibs = new LibDescriptor[ mnLibCount ];
     284        1264 : }
     285             : 
     286        1468 : LibDescriptorArray::~LibDescriptorArray()
     287             : {
     288        1468 :     delete[] mpLibs;
     289        1468 : }
     290             : 
     291             : }
     292             : 
     293             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10