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

Generated by: LCOV version 1.10