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

Generated by: LCOV version 1.10