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