LCOV - code coverage report
Current view: top level - xmlscript/source/xmlflat_imexp - xmlbas_import.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 37 292 12.7 %
Date: 2014-04-11 Functions: 9 62 14.5 %
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 "xmlbas_import.hxx"
      21             : #include <xmlscript/xmlns.h>
      22             : #include <xmlscript/xml_helper.hxx>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      25             : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      26             : #include <com/sun/star/document/XEmbeddedScripts.hpp>
      27             : #include <cppuhelper/implementationentry.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : using namespace ::com::sun::star::lang;
      32             : using namespace ::com::sun::star::uno;
      33             : 
      34             : namespace xmlscript
      35             : {
      36             : 
      37             :     // BasicElementBase
      38             : 
      39           0 :     BasicElementBase::BasicElementBase( const OUString& rLocalName,
      40             :             const Reference< xml::input::XAttributes >& xAttributes,
      41             :             BasicElementBase* pParent, BasicImport* pImport )
      42             :         :m_pImport( pImport )
      43             :         ,m_pParent( pParent )
      44             :         ,m_aLocalName( rLocalName )
      45           0 :         ,m_xAttributes( xAttributes )
      46             :     {
      47           0 :         if ( m_pImport )
      48           0 :             m_pImport->acquire();
      49           0 :         if ( m_pParent )
      50           0 :             m_pParent->acquire();
      51           0 :     }
      52             : 
      53           0 :     BasicElementBase::~BasicElementBase()
      54             :     {
      55           0 :         if ( m_pImport )
      56           0 :             m_pImport->release();
      57           0 :         if ( m_pParent )
      58           0 :             m_pParent->release();
      59           0 :     }
      60             : 
      61           0 :     bool BasicElementBase::getBoolAttr( sal_Bool* pRet, const OUString& rAttrName,
      62             :         const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
      63             :         sal_Int32 nUid )
      64             :     {
      65           0 :         if ( xAttributes.is() )
      66             :         {
      67           0 :             OUString aValue( xAttributes->getValueByUidName( nUid, rAttrName ) );
      68           0 :             if ( !aValue.isEmpty() )
      69             :             {
      70           0 :                 if ( aValue == "true" )
      71             :                 {
      72           0 :                     *pRet = sal_True;
      73           0 :                     return true;
      74             :                 }
      75           0 :                 else if ( aValue == "false" )
      76             :                 {
      77           0 :                     *pRet = sal_False;
      78           0 :                     return true;
      79             :                 }
      80             :                 else
      81             :                 {
      82           0 :                     throw xml::sax::SAXException(rAttrName + ": no boolean value (true|false)!", Reference< XInterface >(), Any() );
      83             :                 }
      84           0 :             }
      85             :         }
      86           0 :         return false;
      87             :     }
      88             : 
      89             :     // XElement
      90             : 
      91           0 :     Reference< xml::input::XElement > BasicElementBase::getParent()
      92             :         throw (RuntimeException, std::exception)
      93             :     {
      94           0 :         return static_cast< xml::input::XElement* >( m_pParent );
      95             :     }
      96             : 
      97           0 :     OUString BasicElementBase::getLocalName()
      98             :         throw (RuntimeException, std::exception)
      99             :     {
     100           0 :         return m_aLocalName;
     101             :     }
     102             : 
     103           0 :     sal_Int32 BasicElementBase::getUid()
     104             :         throw (RuntimeException, std::exception)
     105             :     {
     106           0 :         sal_Int32 nId = -1;
     107           0 :         if ( m_pImport )
     108           0 :             nId = m_pImport->XMLNS_UID;
     109           0 :         return nId;
     110             :     }
     111             : 
     112           0 :     Reference< xml::input::XAttributes > BasicElementBase::getAttributes()
     113             :         throw (RuntimeException, std::exception)
     114             :     {
     115           0 :         return m_xAttributes;
     116             :     }
     117             : 
     118           0 :     Reference< xml::input::XElement > BasicElementBase::startChildElement(
     119             :         sal_Int32 /*nUid*/, const OUString& /*rLocalName*/,
     120             :         const Reference< xml::input::XAttributes >& /*xAttributes*/ )
     121             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     122             :     {
     123           0 :         throw xml::sax::SAXException("unexpected element!", Reference< XInterface >(), Any() );
     124             :     }
     125             : 
     126           0 : void BasicElementBase::characters( const OUString& /*rChars*/ )
     127             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     128             :     {
     129             :         // not used, all characters ignored
     130           0 :     }
     131             : 
     132           0 : void BasicElementBase::ignorableWhitespace( const OUString& /*rWhitespaces*/ )
     133             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     134             :     {
     135           0 :     }
     136             : 
     137           0 : void BasicElementBase::processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ )
     138             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     139             :     {
     140           0 :     }
     141             : 
     142           0 :     void BasicElementBase::endElement()
     143             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     144             :     {
     145           0 :     }
     146             : 
     147             :     // BasicLibrariesElement
     148             : 
     149           0 :     BasicLibrariesElement::BasicLibrariesElement( const OUString& rLocalName,
     150             :             const Reference< xml::input::XAttributes >& xAttributes,
     151             :             BasicElementBase* pParent, BasicImport* pImport,
     152             :             const Reference< script::XLibraryContainer2 >& rxLibContainer )
     153             :         :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
     154           0 :         ,m_xLibContainer( rxLibContainer )
     155             :     {
     156           0 :     }
     157             : 
     158             :     // XElement
     159             : 
     160           0 :     Reference< xml::input::XElement > BasicLibrariesElement::startChildElement(
     161             :             sal_Int32 nUid, const OUString& rLocalName,
     162             :             const Reference< xml::input::XAttributes >& xAttributes )
     163             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     164             :     {
     165           0 :         Reference< xml::input::XElement > xElement;
     166             : 
     167           0 :         if ( nUid != m_pImport->XMLNS_UID )
     168             :         {
     169           0 :             throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     170             :         }
     171           0 :         else if ( rLocalName == "library-linked" )
     172             :         {
     173           0 :             if ( xAttributes.is() )
     174             :             {
     175           0 :                 OUString aName = xAttributes->getValueByUidName( m_pImport->XMLNS_UID, "name" );
     176             : 
     177           0 :                 OUString aStorageURL = xAttributes->getValueByUidName(m_pImport->XMLNS_XLINK_UID, "href" );
     178             : 
     179           0 :                 sal_Bool bReadOnly = sal_False;
     180           0 :                 getBoolAttr( &bReadOnly,"readonly", xAttributes, m_pImport->XMLNS_UID );
     181             : 
     182           0 :                 if ( m_xLibContainer.is() )
     183             :                 {
     184             :                     try
     185             :                     {
     186             :                         Reference< container::XNameAccess > xLib(
     187           0 :                             m_xLibContainer->createLibraryLink( aName, aStorageURL, bReadOnly ) );
     188           0 :                         if ( xLib.is() )
     189           0 :                             xElement.set( new BasicElementBase( rLocalName, xAttributes, this, m_pImport ) );
     190             :                     }
     191           0 :                     catch ( const container::ElementExistException& e )
     192             :                     {
     193             :                         SAL_INFO("xmlscript.xmlflat", "BasicLibrariesElement::startChildElement: caught ElementExceptionExist reason " << e.Message );
     194             :                     }
     195           0 :                     catch ( const lang::IllegalArgumentException& e )
     196             :                     {
     197             :                         SAL_INFO("xmlscript.xmlflat", "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason " << e.Message );
     198             :                     }
     199           0 :                 }
     200             :             }
     201             :         }
     202           0 :         else if ( rLocalName == "library-embedded" )
     203             :         {
     204             :             // TODO: create password protected libraries
     205             : 
     206           0 :             if ( xAttributes.is() )
     207             :             {
     208           0 :                 OUString aName = xAttributes->getValueByUidName( m_pImport->XMLNS_UID, "name" );
     209             : 
     210           0 :                 sal_Bool bReadOnly = sal_False;
     211           0 :                 getBoolAttr( &bReadOnly, "readonly", xAttributes, m_pImport->XMLNS_UID );
     212             : 
     213           0 :                 if ( m_xLibContainer.is() )
     214             :                 {
     215             :                     try
     216             :                     {
     217           0 :                         Reference< container::XNameContainer > xLib;
     218           0 :                         if ( m_xLibContainer->hasByName( aName ) )
     219             :                         {
     220             :                             // Standard library
     221           0 :                             m_xLibContainer->getByName( aName ) >>= xLib;
     222             :                         }
     223             :                         else
     224             :                         {
     225           0 :                             xLib.set( m_xLibContainer->createLibrary( aName ) );
     226             :                         }
     227             : 
     228           0 :                         if ( xLib.is() )
     229           0 :                             xElement.set( new BasicEmbeddedLibraryElement( rLocalName, xAttributes, this, m_pImport, m_xLibContainer, aName, bReadOnly ) );
     230             :                     }
     231           0 :                     catch ( const lang::IllegalArgumentException& e )
     232             :                     {
     233             :                         SAL_INFO("xmlscript.xmlflat", "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason " << e.Message );
     234             :                     }
     235           0 :                 }
     236             :             }
     237             :         }
     238             :         else
     239             :         {
     240           0 :             throw xml::sax::SAXException( "expected library-linked or library-embedded element!", Reference< XInterface >(), Any() );
     241             :         }
     242             : 
     243           0 :         return xElement;
     244             :     }
     245             : 
     246           0 :     void BasicLibrariesElement::endElement()
     247             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     248             :     {
     249           0 :     }
     250             : 
     251             :     // BasicEmbeddedLibraryElement
     252             : 
     253           0 :     BasicEmbeddedLibraryElement::BasicEmbeddedLibraryElement( const OUString& rLocalName,
     254             :             const Reference< xml::input::XAttributes >& xAttributes,
     255             :             BasicElementBase* pParent, BasicImport* pImport,
     256             :             const Reference< script::XLibraryContainer2 >& rxLibContainer,
     257             :             const OUString& rLibName, bool bReadOnly )
     258             :         :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
     259             :         ,m_xLibContainer( rxLibContainer )
     260             :         ,m_aLibName( rLibName )
     261           0 :         ,m_bReadOnly( bReadOnly )
     262             :     {
     263             :         try
     264             :         {
     265           0 :             if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_aLibName ) )
     266           0 :                 m_xLibContainer->getByName( m_aLibName ) >>= m_xLib;
     267             :         }
     268           0 :         catch ( const lang::WrappedTargetException& e )
     269             :         {
     270             :             SAL_INFO("xmlscript.xmlflat", "BasicEmbeddedLibraryElement CTOR: caught WrappedTargetException reason " << e.Message );
     271             :         }
     272           0 :     }
     273             : 
     274             :     // XElement
     275             : 
     276           0 :     Reference< xml::input::XElement > BasicEmbeddedLibraryElement::startChildElement(
     277             :             sal_Int32 nUid, const OUString& rLocalName,
     278             :             const Reference< xml::input::XAttributes >& xAttributes )
     279             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     280             :     {
     281           0 :         Reference< xml::input::XElement > xElement;
     282             : 
     283           0 :         if ( nUid != m_pImport->XMLNS_UID )
     284             :         {
     285           0 :             throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     286             :         }
     287           0 :         else if ( rLocalName == "module" )
     288             :         {
     289           0 :             if ( xAttributes.is() )
     290             :             {
     291           0 :                 OUString aName = xAttributes->getValueByUidName(m_pImport->XMLNS_UID, "name" );
     292             : 
     293           0 :                 if ( m_xLib.is() && !aName.isEmpty() )
     294           0 :                     xElement.set( new BasicModuleElement( rLocalName, xAttributes, this, m_pImport, m_xLib, aName ) );
     295             :             }
     296             :         }
     297             :         else
     298             :         {
     299           0 :             throw xml::sax::SAXException( "expected module element!", Reference< XInterface >(), Any() );
     300             :         }
     301             : 
     302           0 :         return xElement;
     303             :     }
     304             : 
     305           0 :     void BasicEmbeddedLibraryElement::endElement()
     306             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     307             :     {
     308           0 :         if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_aLibName ) && m_bReadOnly )
     309           0 :             m_xLibContainer->setLibraryReadOnly( m_aLibName, m_bReadOnly );
     310           0 :     }
     311             : 
     312             :     // BasicModuleElement
     313             : 
     314           0 :     BasicModuleElement::BasicModuleElement( const OUString& rLocalName,
     315             :             const Reference< xml::input::XAttributes >& xAttributes,
     316             :             BasicElementBase* pParent, BasicImport* pImport,
     317             :             const Reference< container::XNameContainer >& rxLib, const OUString& rName )
     318             :         :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
     319             :         ,m_xLib( rxLib )
     320           0 :         ,m_aName( rName )
     321             :     {
     322           0 :     }
     323             : 
     324             :     // XElement
     325             : 
     326           0 :     Reference< xml::input::XElement > BasicModuleElement::startChildElement(
     327             :             sal_Int32 nUid, const OUString& rLocalName,
     328             :             const Reference< xml::input::XAttributes >& xAttributes )
     329             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     330             :     {
     331             :         // TODO: <byte-code>
     332             : 
     333           0 :         Reference< xml::input::XElement > xElement;
     334             : 
     335           0 :         if ( nUid != m_pImport->XMLNS_UID )
     336             :         {
     337           0 :             throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     338             :         }
     339           0 :         else if ( rLocalName == "source-code" )
     340             :         {
     341             :             // TODO: password protected libraries
     342             : 
     343           0 :             if ( xAttributes.is() )
     344             :             {
     345           0 :                 if ( m_xLib.is() && !m_aName.isEmpty() )
     346           0 :                     xElement.set( new BasicSourceCodeElement( rLocalName, xAttributes, this, m_pImport, m_xLib, m_aName ) );
     347             :             }
     348             :         }
     349             :         else
     350             :         {
     351           0 :             throw xml::sax::SAXException( "expected source-code element!", Reference< XInterface >(), Any() );
     352             :         }
     353             : 
     354           0 :         return xElement;
     355             :     }
     356             : 
     357           0 :     void BasicModuleElement::endElement()
     358             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     359             :     {
     360           0 :     }
     361             : 
     362             :     // BasicSourceCodeElement
     363             : 
     364           0 :     BasicSourceCodeElement::BasicSourceCodeElement( const OUString& rLocalName,
     365             :             const Reference< xml::input::XAttributes >& xAttributes,
     366             :             BasicElementBase* pParent, BasicImport* pImport,
     367             :             const Reference< container::XNameContainer >& rxLib, const OUString& rName )
     368             :         :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
     369             :         ,m_xLib( rxLib )
     370           0 :         ,m_aName( rName )
     371             :     {
     372           0 :     }
     373             : 
     374             :     // XElement
     375             : 
     376           0 :     void BasicSourceCodeElement::characters( const OUString& rChars )
     377             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     378             :     {
     379           0 :         m_aBuffer.append( rChars );
     380           0 :     }
     381             : 
     382           0 :     void BasicSourceCodeElement::endElement()
     383             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     384             :     {
     385             :         try
     386             :         {
     387           0 :             if ( m_xLib.is() && !m_aName.isEmpty() )
     388             :             {
     389           0 :                 Any aElement;
     390           0 :                 aElement <<= m_aBuffer.makeStringAndClear();
     391           0 :                 m_xLib->insertByName( m_aName, aElement );
     392             :             }
     393             :         }
     394           0 :         catch ( const container::ElementExistException& e )
     395             :         {
     396             :             SAL_INFO("xmlscript.xmlflat", "BasicSourceCodeElement::endElement: caught ElementExceptionExist reason " << e.Message );
     397             :         }
     398           0 :         catch ( const lang::IllegalArgumentException& e )
     399             :         {
     400             :             SAL_INFO("xmlscript.xmlflat", "BasicSourceCodeElement::endElement: caught IllegalArgumentException reason " << e.Message );
     401             :         }
     402           0 :         catch ( const lang::WrappedTargetException& e )
     403             :         {
     404             :             SAL_INFO("xmlscript.xmlflat", "BasicSourceCodeElement::endElement: caught WrappedTargetException reason " << e.Message );
     405             :         }
     406           0 :     }
     407             : 
     408             :     // BasicImport
     409             : 
     410           0 :     BasicImport::BasicImport( const Reference< frame::XModel >& rxModel, bool bOasis )
     411             :         : XMLNS_UID(0)
     412             :         , XMLNS_XLINK_UID(0)
     413             :         , m_xModel(rxModel)
     414           0 :         , m_bOasis(bOasis)
     415             :     {
     416           0 :     }
     417             : 
     418           0 :     BasicImport::~BasicImport()
     419             :     {
     420           0 :     }
     421             : 
     422             :     // XRoot
     423             : 
     424           0 :     void BasicImport::startDocument( const Reference< xml::input::XNamespaceMapping >& xNamespaceMapping )
     425             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     426             :     {
     427           0 :         if ( xNamespaceMapping.is() )
     428             :         {
     429           0 :             OUString aURI;
     430           0 :             if ( m_bOasis )
     431           0 :                 aURI = XMLNS_OOO_URI;
     432             :             else
     433           0 :                 aURI = XMLNS_SCRIPT_URI;
     434           0 :             XMLNS_UID = xNamespaceMapping->getUidByUri( aURI );
     435           0 :             XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri( XMLNS_XLINK_URI );
     436             :         }
     437           0 :     }
     438             : 
     439           0 :     void BasicImport::endDocument()
     440             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     441             :     {
     442           0 :     }
     443             : 
     444           0 : void BasicImport::processingInstruction( const OUString& /*rTarget*/, const OUString& /*rData*/ )
     445             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     446             :     {
     447           0 :     }
     448             : 
     449           0 : void BasicImport::setDocumentLocator( const Reference< xml::sax::XLocator >& /*xLocator*/ )
     450             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     451             :     {
     452           0 :     }
     453             : 
     454           0 :     Reference< xml::input::XElement > BasicImport::startRootElement( sal_Int32 nUid, const OUString& rLocalName,
     455             :             Reference< xml::input::XAttributes > const & xAttributes )
     456             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     457             :     {
     458           0 :         Reference< xml::input::XElement > xElement;
     459             : 
     460           0 :         if ( nUid != XMLNS_UID )
     461             :         {
     462           0 :             throw xml::sax::SAXException( "illegal namespace!", Reference< XInterface >(), Any() );
     463             :         }
     464           0 :         else if ( rLocalName == "libraries" )
     465             :         {
     466           0 :             Reference< script::XLibraryContainer2 > xLibContainer;
     467             : 
     468             :             // try the XEmbeddedScripts interface
     469           0 :             Reference< document::XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
     470           0 :             if ( xDocumentScripts.is() )
     471           0 :                 xLibContainer.set( xDocumentScripts->getBasicLibraries().get() );
     472             : 
     473           0 :             if ( !xLibContainer.is() )
     474             :             {
     475             :                 // try the "BasicLibraries" property (old-style, for compatibility)
     476           0 :                 Reference< beans::XPropertySet > xPSet( m_xModel, UNO_QUERY );
     477           0 :                 if ( xPSet.is() )
     478           0 :                     xPSet->getPropertyValue("BasicLibraries" ) >>= xLibContainer;
     479             :             }
     480             : 
     481             :             SAL_WARN_IF( !xLibContainer.is(), "xmlscript.xmlflat", "BasicImport::startRootElement: nowhere to import to!" );
     482             : 
     483           0 :             if ( xLibContainer.is() )
     484             :             {
     485           0 :                 xElement.set( new BasicLibrariesElement( rLocalName, xAttributes, 0, this, xLibContainer ) );
     486           0 :             }
     487             :         }
     488             :         else
     489             :         {
     490           0 :             throw xml::sax::SAXException("illegal root element (expected libraries) given: " + rLocalName, Reference< XInterface >(), Any() );
     491             :         }
     492             : 
     493           0 :         return xElement;
     494             :     }
     495             : 
     496             :     // component operations
     497             : 
     498           2 :     OUString getImplementationName_XMLBasicImporter()
     499             :     {
     500             :         static OUString* pImplName = 0;
     501           2 :         if ( !pImplName )
     502             :         {
     503           2 :             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     504           2 :             if ( !pImplName )
     505             :             {
     506           2 :                 static OUString aImplName( "com.sun.star.comp.xmlscript.XMLBasicImporter" );
     507           2 :                 pImplName = &aImplName;
     508           2 :             }
     509             :         }
     510           2 :         return *pImplName;
     511             :     }
     512             : 
     513           0 :     Sequence< OUString > getSupportedServiceNames_XMLBasicImporter()
     514             :     {
     515             :         static Sequence< OUString >* pNames = 0;
     516           0 :         if ( !pNames )
     517             :         {
     518           0 :             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     519           0 :             if ( !pNames )
     520             :             {
     521           0 :                 static Sequence< OUString > aNames(1);
     522           0 :                 aNames.getArray()[0] = "com.sun.star.document.XMLBasicImporter";
     523           0 :                 pNames = &aNames;
     524           0 :             }
     525             :         }
     526           0 :         return *pNames;
     527             :     }
     528             : 
     529           2 :     OUString getImplementationName_XMLOasisBasicImporter()
     530             :     {
     531             :         static OUString* pImplName = 0;
     532           2 :         if ( !pImplName )
     533             :         {
     534           2 :             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     535           2 :             if ( !pImplName )
     536             :             {
     537           2 :                 static OUString aImplName( "com.sun.star.comp.xmlscript.XMLOasisBasicImporter" );
     538           2 :                 pImplName = &aImplName;
     539           2 :             }
     540             :         }
     541           2 :         return *pImplName;
     542             :     }
     543             : 
     544           1 :     Sequence< OUString > getSupportedServiceNames_XMLOasisBasicImporter()
     545             :     {
     546             :         static Sequence< OUString >* pNames = 0;
     547           1 :         if ( !pNames )
     548             :         {
     549           1 :             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
     550           1 :             if ( !pNames )
     551             :             {
     552           1 :                 static Sequence< OUString > aNames(1);
     553           1 :                 aNames.getArray()[0] = "com.sun.star.document.XMLOasisBasicImporter";
     554           1 :                 pNames = &aNames;
     555           1 :             }
     556             :         }
     557           1 :         return *pNames;
     558             :     }
     559             : 
     560             :     // XMLBasicImporterBase
     561             : 
     562           1 :     XMLBasicImporterBase::XMLBasicImporterBase( const Reference< XComponentContext >& rxContext, bool bOasis )
     563             :         :m_xContext( rxContext )
     564           1 :         ,m_bOasis( bOasis )
     565             :     {
     566           1 :     }
     567             : 
     568           1 :     XMLBasicImporterBase::~XMLBasicImporterBase()
     569             :     {
     570           1 :     }
     571             : 
     572             :     // XServiceInfo
     573           0 :     sal_Bool XMLBasicImporterBase::supportsService( const OUString& rServiceName ) throw (RuntimeException, std::exception)
     574             :     {
     575           0 :         return cppu::supportsService(this, rServiceName);
     576             :     }
     577             : 
     578             :     // XImporter
     579           0 :     void XMLBasicImporterBase::setTargetDocument( const Reference< XComponent >& rxDoc )
     580             :         throw (IllegalArgumentException, RuntimeException, std::exception)
     581             :     {
     582           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     583             : 
     584           0 :         m_xModel.set( rxDoc, UNO_QUERY );
     585             : 
     586           0 :         if ( !m_xModel.is() )
     587             :         {
     588           0 :             throw IllegalArgumentException( "XMLBasicExporter::setTargetDocument: no document model!", Reference< XInterface >(), 1 );
     589             :         }
     590             : 
     591           0 :         if ( m_xContext.is() )
     592             :         {
     593           0 :             Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
     594           0 :             if ( xSMgr.is() )
     595             :             {
     596           0 :                 Reference < xml::input::XRoot > xRoot( new BasicImport( m_xModel, m_bOasis ) );
     597           0 :                 Sequence < Any > aArgs( 1 );
     598           0 :                 aArgs[0] <<= xRoot;
     599           0 :                 m_xHandler.set( xSMgr->createInstanceWithArgumentsAndContext("com.sun.star.xml.input.SaxDocumentHandler", aArgs, m_xContext ), UNO_QUERY );
     600           0 :             }
     601           0 :         }
     602           0 :     }
     603             : 
     604             :     // XDocumentHandler
     605             : 
     606           0 :     void XMLBasicImporterBase::startDocument()
     607             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     608             :     {
     609           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     610             : 
     611           0 :         if ( m_xHandler.is() )
     612           0 :             m_xHandler->startDocument();
     613           0 :     }
     614             : 
     615           0 :     void XMLBasicImporterBase::endDocument()
     616             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     617             :     {
     618           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     619             : 
     620           0 :         if ( m_xHandler.is() )
     621           0 :             m_xHandler->endDocument();
     622           0 :     }
     623             : 
     624           0 :     void XMLBasicImporterBase::startElement( const OUString& aName,
     625             :             const Reference< xml::sax::XAttributeList >& xAttribs )
     626             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     627             :     {
     628           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     629             : 
     630           0 :         if ( m_xHandler.is() )
     631           0 :             m_xHandler->startElement( aName, xAttribs );
     632           0 :     }
     633             : 
     634           0 :     void XMLBasicImporterBase::endElement( const OUString& aName )
     635             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     636             :     {
     637           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     638             : 
     639           0 :         if ( m_xHandler.is() )
     640           0 :             m_xHandler->endElement( aName );
     641           0 :     }
     642             : 
     643           0 :     void XMLBasicImporterBase::characters( const OUString& aChars )
     644             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     645             :     {
     646           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     647             : 
     648           0 :         if ( m_xHandler.is() )
     649           0 :             m_xHandler->characters( aChars );
     650           0 :     }
     651             : 
     652           0 :     void XMLBasicImporterBase::ignorableWhitespace( const OUString& aWhitespaces )
     653             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     654             :     {
     655           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     656             : 
     657           0 :         if ( m_xHandler.is() )
     658           0 :             m_xHandler->ignorableWhitespace( aWhitespaces );
     659           0 :     }
     660             : 
     661           0 :     void XMLBasicImporterBase::processingInstruction( const OUString& aTarget,
     662             :             const OUString& aData )
     663             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     664             :     {
     665           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     666             : 
     667           0 :         if ( m_xHandler.is() )
     668           0 :             m_xHandler->processingInstruction( aTarget, aData );
     669           0 :     }
     670             : 
     671           0 :     void XMLBasicImporterBase::setDocumentLocator( const Reference< xml::sax::XLocator >& xLocator )
     672             :         throw (xml::sax::SAXException, RuntimeException, std::exception)
     673             :     {
     674           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     675             : 
     676           0 :         if ( m_xHandler.is() )
     677           0 :             m_xHandler->setDocumentLocator( xLocator );
     678           0 :     }
     679             : 
     680             :     // XMLBasicImporter
     681             : 
     682           0 :     XMLBasicImporter::XMLBasicImporter( const Reference< XComponentContext >& rxContext )
     683           0 :         :XMLBasicImporterBase( rxContext, false )
     684             :     {
     685           0 :     }
     686             : 
     687           0 :     XMLBasicImporter::~XMLBasicImporter()
     688             :     {
     689           0 :     }
     690             : 
     691             :     // XServiceInfo
     692             : 
     693           0 :     OUString XMLBasicImporter::getImplementationName(  ) throw (RuntimeException, std::exception)
     694             :     {
     695           0 :         return getImplementationName_XMLBasicImporter();
     696             :     }
     697             : 
     698           0 :     Sequence< OUString > XMLBasicImporter::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     699             :     {
     700           0 :         return getSupportedServiceNames_XMLBasicImporter();
     701             :     }
     702             : 
     703             :     // XMLOasisBasicImporter
     704             : 
     705           1 :     XMLOasisBasicImporter::XMLOasisBasicImporter( const Reference< XComponentContext >& rxContext )
     706           1 :         :XMLBasicImporterBase( rxContext, true )
     707             :     {
     708           1 :     }
     709             : 
     710           2 :     XMLOasisBasicImporter::~XMLOasisBasicImporter()
     711             :     {
     712           2 :     }
     713             : 
     714             :     // XServiceInfo
     715             : 
     716           0 :     OUString XMLOasisBasicImporter::getImplementationName(  ) throw (RuntimeException, std::exception)
     717             :     {
     718           0 :         return getImplementationName_XMLOasisBasicImporter();
     719             :     }
     720             : 
     721           0 :     Sequence< OUString > XMLOasisBasicImporter::getSupportedServiceNames(  ) throw (RuntimeException, std::exception)
     722             :     {
     723           0 :         return getSupportedServiceNames_XMLOasisBasicImporter();
     724             :     }
     725             : 
     726             :     // component operations
     727             : 
     728           0 :     Reference< XInterface > SAL_CALL create_XMLBasicImporter(
     729             :         Reference< XComponentContext > const & xContext )
     730             :         SAL_THROW(())
     731             :     {
     732           0 :         return static_cast< lang::XTypeProvider * >( new XMLBasicImporter( xContext ) );
     733             :     }
     734             : 
     735           1 :     Reference< XInterface > SAL_CALL create_XMLOasisBasicImporter(
     736             :         Reference< XComponentContext > const & xContext )
     737             :         SAL_THROW(())
     738             :     {
     739           1 :         return static_cast< lang::XTypeProvider * >( new XMLOasisBasicImporter( xContext ) );
     740             :     }
     741             : 
     742             : }   // namespace xmlscript
     743             : 
     744             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10