1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_xmlscript.hxx" 30*cdf0e10cSrcweir #include "xmlbas_export.hxx" 31*cdf0e10cSrcweir #include "xmlscript/xmlns.h" 32*cdf0e10cSrcweir #include "xmlscript/xml_helper.hxx" 33*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer2.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainerPassword.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp> 38*cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using namespace ::com::sun::star; 41*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir //......................................................................... 46*cdf0e10cSrcweir namespace xmlscript 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir //......................................................................... 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir // ============================================================================= 51*cdf0e10cSrcweir // component operations 52*cdf0e10cSrcweir // ============================================================================= 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir ::rtl::OUString getImplementationName_XMLBasicExporter() 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir static ::rtl::OUString* pImplName = 0; 57*cdf0e10cSrcweir if ( !pImplName ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 60*cdf0e10cSrcweir if ( !pImplName ) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLBasicExporter" ) ); 63*cdf0e10cSrcweir pImplName = &aImplName; 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir return *pImplName; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir Sequence< ::rtl::OUString > getSupportedServiceNames_XMLBasicExporter() 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir static Sequence< ::rtl::OUString >* pNames = 0; 74*cdf0e10cSrcweir if ( !pNames ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 77*cdf0e10cSrcweir if ( !pNames ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir static Sequence< ::rtl::OUString > aNames(1); 80*cdf0e10cSrcweir aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLBasicExporter" ) ); 81*cdf0e10cSrcweir pNames = &aNames; 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir return *pNames; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir ::rtl::OUString getImplementationName_XMLOasisBasicExporter() 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir static ::rtl::OUString* pImplName = 0; 92*cdf0e10cSrcweir if ( !pImplName ) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 95*cdf0e10cSrcweir if ( !pImplName ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLOasisBasicExporter" ) ); 98*cdf0e10cSrcweir pImplName = &aImplName; 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir return *pImplName; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir Sequence< ::rtl::OUString > getSupportedServiceNames_XMLOasisBasicExporter() 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir static Sequence< ::rtl::OUString >* pNames = 0; 109*cdf0e10cSrcweir if ( !pNames ) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 112*cdf0e10cSrcweir if ( !pNames ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir static Sequence< ::rtl::OUString > aNames(1); 115*cdf0e10cSrcweir aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicExporter" ) ); 116*cdf0e10cSrcweir pNames = &aNames; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir return *pNames; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // ============================================================================= 124*cdf0e10cSrcweir // XMLBasicExporterBase 125*cdf0e10cSrcweir // ============================================================================= 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir XMLBasicExporterBase::XMLBasicExporterBase( const Reference< XComponentContext >& rxContext, sal_Bool bOasis ) 128*cdf0e10cSrcweir :m_xContext( rxContext ) 129*cdf0e10cSrcweir ,m_bOasis( bOasis ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir XMLBasicExporterBase::~XMLBasicExporterBase() 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 140*cdf0e10cSrcweir // XServiceInfo 141*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir sal_Bool XMLBasicExporterBase::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() ); 146*cdf0e10cSrcweir const ::rtl::OUString* pNames = aNames.getConstArray(); 147*cdf0e10cSrcweir const ::rtl::OUString* pEnd = pNames + aNames.getLength(); 148*cdf0e10cSrcweir for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames ) 149*cdf0e10cSrcweir ; 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir return pNames != pEnd; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 155*cdf0e10cSrcweir // XInitialization 156*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir void XMLBasicExporterBase::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir if ( aArguments.getLength() == 1 ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir aArguments[0] >>= m_xHandler; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir if ( !m_xHandler.is() ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir throw RuntimeException( 169*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLBasicExporterBase::initialize: invalid argument format!" ) ), 170*cdf0e10cSrcweir Reference< XInterface >() ); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir else 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir throw RuntimeException( 176*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLBasicExporterBase::initialize: invalid number of arguments!" ) ), 177*cdf0e10cSrcweir Reference< XInterface >() ); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 182*cdf0e10cSrcweir // XExporter 183*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir void XMLBasicExporterBase::setSourceDocument( const Reference< XComponent >& rxDoc ) 186*cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir m_xModel.set( rxDoc, UNO_QUERY ); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if ( !m_xModel.is() ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir throw IllegalArgumentException( 195*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLBasicExporter::setSourceDocument: no document model!" ) ), 196*cdf0e10cSrcweir Reference< XInterface >(), 1 ); 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 201*cdf0e10cSrcweir // XFilter 202*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir sal_Bool XMLBasicExporterBase::filter( const Sequence< beans::PropertyValue >& /*aDescriptor*/ ) 205*cdf0e10cSrcweir throw (RuntimeException) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir sal_Bool bReturn = sal_True; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir try 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir if ( m_xHandler.is() ) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir m_xHandler->startDocument(); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir // ooo/script prefix and URI 218*cdf0e10cSrcweir ::rtl::OUString aPrefix; 219*cdf0e10cSrcweir ::rtl::OUString aURI; 220*cdf0e10cSrcweir if ( m_bOasis ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir aPrefix = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_OOO_PREFIX ) ); 223*cdf0e10cSrcweir aURI = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_OOO_URI ) ); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir else 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir aPrefix = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_SCRIPT_PREFIX ) ); 228*cdf0e10cSrcweir aURI = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_SCRIPT_URI ) ); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir // ooo/script:libraries element 232*cdf0e10cSrcweir ::rtl::OUString aLibContElementName( aPrefix ); 233*cdf0e10cSrcweir aLibContElementName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":libraries" ) ); 234*cdf0e10cSrcweir XMLElement* pLibContElement = new XMLElement( aLibContElementName ); 235*cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xLibContAttribs( pLibContElement ); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir // ooo/script namespace attribute 238*cdf0e10cSrcweir pLibContElement->addAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "xmlns:" ) ) + aPrefix, 239*cdf0e10cSrcweir aURI ); 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir // xlink namespace attribute 242*cdf0e10cSrcweir pLibContElement->addAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "xmlns:" XMLNS_XLINK_PREFIX ) ), 243*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_URI ) ) ); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir // <ooo/script:libraries... 246*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 247*cdf0e10cSrcweir m_xHandler->startElement( aLibContElementName, xLibContAttribs ); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir Reference< script::XLibraryContainer2 > xLibContainer; 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir // try the XEmbeddedScripts interface 252*cdf0e10cSrcweir Reference< document::XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY ); 253*cdf0e10cSrcweir if ( xDocumentScripts.is() ) 254*cdf0e10cSrcweir xLibContainer.set( xDocumentScripts->getBasicLibraries().get() ); 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir if ( !xLibContainer.is() ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir // try the "BasicLibraries" property (old-style, for compatibility) 259*cdf0e10cSrcweir Reference< beans::XPropertySet > xPSet( m_xModel, UNO_QUERY ); 260*cdf0e10cSrcweir if ( xPSet.is() ) 261*cdf0e10cSrcweir xPSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ) >>= xLibContainer; 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir OSL_ENSURE( xLibContainer.is(), "XMLBasicExporterBase::filter: nowhere to export to!" ); 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir if ( xLibContainer.is() ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir Sequence< ::rtl::OUString > aLibNames = xLibContainer->getElementNames(); 269*cdf0e10cSrcweir sal_Int32 nLibCount = aLibNames.getLength(); 270*cdf0e10cSrcweir const ::rtl::OUString* pLibNames = aLibNames.getConstArray(); 271*cdf0e10cSrcweir for ( sal_Int32 i = 0 ; i < nLibCount ; ++i ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir ::rtl::OUString aLibName( pLibNames[i] ); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir if ( xLibContainer->hasByName( aLibName ) ) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir ::rtl::OUString aTrueStr( RTL_CONSTASCII_USTRINGPARAM( "true" ) ); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir if ( xLibContainer->isLibraryLink( aLibName ) ) 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir // ooo/script:library-linked element 282*cdf0e10cSrcweir ::rtl::OUString aLibElementName( aPrefix ); 283*cdf0e10cSrcweir aLibElementName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":library-linked" ) ); 284*cdf0e10cSrcweir XMLElement* pLibElement = new XMLElement( aLibElementName ); 285*cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xLibAttribs; 286*cdf0e10cSrcweir xLibAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement ); 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir // ooo/script:name attribute 289*cdf0e10cSrcweir pLibElement->addAttribute( aPrefix + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":name" ) ), 290*cdf0e10cSrcweir aLibName ); 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir ::rtl::OUString aLinkURL( xLibContainer->getLibraryLinkURL( aLibName ) ); 293*cdf0e10cSrcweir if ( aLinkURL.getLength() ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir // xlink:href attribute 296*cdf0e10cSrcweir pLibElement->addAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX ":href" ) ), 297*cdf0e10cSrcweir aLinkURL ); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir // xlink:type attribute 300*cdf0e10cSrcweir pLibElement->addAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX ":type" ) ), 301*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "simple" ) ) ); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir if ( xLibContainer->isLibraryReadOnly( aLibName ) ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir // ooo/script:readonly attribute 307*cdf0e10cSrcweir pLibElement->addAttribute( aPrefix + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":readonly" ) ), 308*cdf0e10cSrcweir aTrueStr ); 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir // <ooo/script:library-linked... 312*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 313*cdf0e10cSrcweir m_xHandler->startElement( aLibElementName, xLibAttribs ); 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir // ...ooo/script:library-linked> 316*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 317*cdf0e10cSrcweir m_xHandler->endElement( aLibElementName ); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir else 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir // ooo/script:library-embedded element 322*cdf0e10cSrcweir ::rtl::OUString aLibElementName( aPrefix ); 323*cdf0e10cSrcweir aLibElementName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":library-embedded" ) ); 324*cdf0e10cSrcweir XMLElement* pLibElement = new XMLElement( aLibElementName ); 325*cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xLibAttribs; 326*cdf0e10cSrcweir xLibAttribs = static_cast< xml::sax::XAttributeList* >( pLibElement ); 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir // ooo/script:name attribute 329*cdf0e10cSrcweir pLibElement->addAttribute( aPrefix + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":name" ) ), 330*cdf0e10cSrcweir aLibName ); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir if ( xLibContainer->isLibraryReadOnly( aLibName ) ) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir // ooo/script:readonly attribute 335*cdf0e10cSrcweir pLibElement->addAttribute( aPrefix + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":readonly" ) ), 336*cdf0e10cSrcweir aTrueStr ); 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir // TODO: password protected libraries 340*cdf0e10cSrcweir Reference< script::XLibraryContainerPassword > xPasswd( xLibContainer, UNO_QUERY ); 341*cdf0e10cSrcweir if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) ) 342*cdf0e10cSrcweir continue; 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir // <ooo/script:library-embedded... 345*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 346*cdf0e10cSrcweir m_xHandler->startElement( aLibElementName, xLibAttribs ); 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir if ( !xLibContainer->isLibraryLoaded( aLibName ) ) 349*cdf0e10cSrcweir xLibContainer->loadLibrary( aLibName ); 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir Reference< container::XNameContainer > xLib; 352*cdf0e10cSrcweir xLibContainer->getByName( aLibName ) >>= xLib; 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir if ( xLib.is() ) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir Sequence< ::rtl::OUString > aModNames = xLib->getElementNames(); 357*cdf0e10cSrcweir sal_Int32 nModCount = aModNames.getLength(); 358*cdf0e10cSrcweir const ::rtl::OUString* pModNames = aModNames.getConstArray(); 359*cdf0e10cSrcweir for ( sal_Int32 j = 0 ; j < nModCount ; ++j ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir ::rtl::OUString aModName( pModNames[j] ); 362*cdf0e10cSrcweir if ( xLib->hasByName( aModName ) ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir // ooo/script:module element 365*cdf0e10cSrcweir ::rtl::OUString aModElementName( aPrefix ); 366*cdf0e10cSrcweir aModElementName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":module" ) ); 367*cdf0e10cSrcweir XMLElement* pModElement = new XMLElement( aModElementName ); 368*cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xModAttribs; 369*cdf0e10cSrcweir xModAttribs = static_cast< xml::sax::XAttributeList* >( pModElement ); 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir // ooo/script:name attribute 372*cdf0e10cSrcweir pModElement->addAttribute( aPrefix + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":name" ) ), 373*cdf0e10cSrcweir aModName ); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir // <ooo/script:module... 376*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 377*cdf0e10cSrcweir m_xHandler->startElement( aModElementName, xModAttribs ); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir // ooo/script:source-code element 380*cdf0e10cSrcweir ::rtl::OUString aSourceElementName( aPrefix ); 381*cdf0e10cSrcweir aSourceElementName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ":source-code" ) ); 382*cdf0e10cSrcweir XMLElement* pSourceElement = new XMLElement( aSourceElementName ); 383*cdf0e10cSrcweir Reference< xml::sax::XAttributeList > xSourceAttribs; 384*cdf0e10cSrcweir xSourceAttribs = static_cast< xml::sax::XAttributeList* >( pSourceElement ); 385*cdf0e10cSrcweir 386*cdf0e10cSrcweir // <ooo/script:source-code... 387*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 388*cdf0e10cSrcweir m_xHandler->startElement( aSourceElementName, xSourceAttribs ); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir // module data 391*cdf0e10cSrcweir // TODO: write encrypted data for password protected libraries 392*cdf0e10cSrcweir ::rtl::OUString aSource; 393*cdf0e10cSrcweir xLib->getByName( aModName ) >>= aSource; 394*cdf0e10cSrcweir m_xHandler->characters( aSource ); 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir // TODO: <ooo/script:byte-code> 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir // ...ooo/script:source-code> 399*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 400*cdf0e10cSrcweir m_xHandler->endElement( aSourceElementName ); 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir // ...ooo/script:module> 403*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 404*cdf0e10cSrcweir m_xHandler->endElement( aModElementName ); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir // ...ooo/script:library-embedded> 410*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 411*cdf0e10cSrcweir m_xHandler->endElement( aLibElementName ); 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir // ...ooo/script:libraries> 418*cdf0e10cSrcweir m_xHandler->ignorableWhitespace( ::rtl::OUString() ); 419*cdf0e10cSrcweir m_xHandler->endElement( aLibContElementName ); 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir m_xHandler->endDocument(); 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir catch ( container::NoSuchElementException& e ) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir OSL_TRACE( "XMLBasicExporterBase::filter: caught NoSuchElementException reason %s", 427*cdf0e10cSrcweir ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 428*cdf0e10cSrcweir bReturn = sal_False; 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir catch ( lang::IllegalArgumentException& e ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir OSL_TRACE( "XMLBasicExporterBase::filter: caught IllegalArgumentException reason %s", 433*cdf0e10cSrcweir ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 434*cdf0e10cSrcweir bReturn = sal_False; 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir catch ( lang::WrappedTargetException& e ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir OSL_TRACE( "XMLBasicExporterBase::filter: caught WrappedTargetException reason %s", 439*cdf0e10cSrcweir ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 440*cdf0e10cSrcweir bReturn = sal_False; 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir catch ( xml::sax::SAXException& e ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir OSL_TRACE( "XMLBasicExporterBase::filter: caught SAXException reason %s", 445*cdf0e10cSrcweir ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer ); 446*cdf0e10cSrcweir bReturn = sal_False; 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir return bReturn; 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir void XMLBasicExporterBase::cancel() 455*cdf0e10cSrcweir throw (RuntimeException) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir // cancel export 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir // ============================================================================= 464*cdf0e10cSrcweir // XMLBasicExporter 465*cdf0e10cSrcweir // ============================================================================= 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir XMLBasicExporter::XMLBasicExporter( const Reference< XComponentContext >& rxContext ) 468*cdf0e10cSrcweir :XMLBasicExporterBase( rxContext, sal_False ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir XMLBasicExporter::~XMLBasicExporter() 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 479*cdf0e10cSrcweir // XServiceInfo 480*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir ::rtl::OUString XMLBasicExporter::getImplementationName( ) throw (RuntimeException) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir return getImplementationName_XMLBasicExporter(); 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir Sequence< ::rtl::OUString > XMLBasicExporter::getSupportedServiceNames( ) throw (RuntimeException) 490*cdf0e10cSrcweir { 491*cdf0e10cSrcweir return getSupportedServiceNames_XMLBasicExporter(); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir // ============================================================================= 496*cdf0e10cSrcweir // XMLOasisBasicExporter 497*cdf0e10cSrcweir // ============================================================================= 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir XMLOasisBasicExporter::XMLOasisBasicExporter( const Reference< XComponentContext >& rxContext ) 500*cdf0e10cSrcweir :XMLBasicExporterBase( rxContext, sal_True ) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir } 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir XMLOasisBasicExporter::~XMLOasisBasicExporter() 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 511*cdf0e10cSrcweir // XServiceInfo 512*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir ::rtl::OUString XMLOasisBasicExporter::getImplementationName( ) throw (RuntimeException) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir return getImplementationName_XMLOasisBasicExporter(); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir Sequence< ::rtl::OUString > XMLOasisBasicExporter::getSupportedServiceNames( ) throw (RuntimeException) 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir return getSupportedServiceNames_XMLOasisBasicExporter(); 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir // ============================================================================= 528*cdf0e10cSrcweir // component operations 529*cdf0e10cSrcweir // ============================================================================= 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir Reference< XInterface > SAL_CALL create_XMLBasicExporter( 532*cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 533*cdf0e10cSrcweir SAL_THROW( () ) 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir return static_cast< lang::XTypeProvider * >( new XMLBasicExporter( xContext ) ); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir Reference< XInterface > SAL_CALL create_XMLOasisBasicExporter( 541*cdf0e10cSrcweir Reference< XComponentContext > const & xContext ) 542*cdf0e10cSrcweir SAL_THROW( () ) 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir return static_cast< lang::XTypeProvider * >( new XMLOasisBasicExporter( xContext ) ); 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir //......................................................................... 550*cdf0e10cSrcweir } // namespace xmlscript 551*cdf0e10cSrcweir //......................................................................... 552