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_import.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/XLibraryContainerPassword.hpp>
32cdf0e10cSrcweir #include <com/sun/star/document/XEmbeddedScripts.hpp>
33cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir using namespace ::com::sun::star::lang;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //.........................................................................
41cdf0e10cSrcweir namespace xmlscript
42cdf0e10cSrcweir {
43cdf0e10cSrcweir //.........................................................................
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     // =============================================================================
46cdf0e10cSrcweir     // BasicElementBase
47cdf0e10cSrcweir     // =============================================================================
48cdf0e10cSrcweir 
BasicElementBase(const::rtl::OUString & rLocalName,const Reference<xml::input::XAttributes> & xAttributes,BasicElementBase * pParent,BasicImport * pImport)49cdf0e10cSrcweir     BasicElementBase::BasicElementBase( const ::rtl::OUString& rLocalName,
50cdf0e10cSrcweir             const Reference< xml::input::XAttributes >& xAttributes,
51cdf0e10cSrcweir             BasicElementBase* pParent, BasicImport* pImport )
52cdf0e10cSrcweir         :m_pImport( pImport )
53cdf0e10cSrcweir         ,m_pParent( pParent )
54cdf0e10cSrcweir         ,m_aLocalName( rLocalName )
55cdf0e10cSrcweir         ,m_xAttributes( xAttributes )
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         if ( m_pImport )
58cdf0e10cSrcweir             m_pImport->acquire();
59cdf0e10cSrcweir         if ( m_pParent )
60cdf0e10cSrcweir             m_pParent->acquire();
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     // -----------------------------------------------------------------------------
64cdf0e10cSrcweir 
~BasicElementBase()65cdf0e10cSrcweir     BasicElementBase::~BasicElementBase()
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir         if ( m_pImport )
68cdf0e10cSrcweir             m_pImport->release();
69cdf0e10cSrcweir         if ( m_pParent )
70cdf0e10cSrcweir             m_pParent->release();
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     // -----------------------------------------------------------------------------
74cdf0e10cSrcweir 
getBoolAttr(sal_Bool * pRet,const::rtl::OUString & rAttrName,const::com::sun::star::uno::Reference<::com::sun::star::xml::input::XAttributes> & xAttributes,sal_Int32 nUid)75cdf0e10cSrcweir     bool BasicElementBase::getBoolAttr( sal_Bool* pRet, const ::rtl::OUString& rAttrName,
76cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::xml::input::XAttributes >& xAttributes,
77cdf0e10cSrcweir         sal_Int32 nUid )
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         if ( xAttributes.is() )
80cdf0e10cSrcweir         {
81cdf0e10cSrcweir             ::rtl::OUString aValue( xAttributes->getValueByUidName( nUid, rAttrName ) );
82cdf0e10cSrcweir             if ( aValue.getLength() )
83cdf0e10cSrcweir             {
84cdf0e10cSrcweir                 if ( aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "true" ) ) )
85cdf0e10cSrcweir                 {
86cdf0e10cSrcweir                     *pRet = sal_True;
87cdf0e10cSrcweir                     return true;
88cdf0e10cSrcweir                 }
89cdf0e10cSrcweir                 else if ( aValue.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "false" ) ) )
90cdf0e10cSrcweir                 {
91cdf0e10cSrcweir                     *pRet = sal_False;
92cdf0e10cSrcweir                     return true;
93cdf0e10cSrcweir                 }
94cdf0e10cSrcweir                 else
95cdf0e10cSrcweir                 {
96cdf0e10cSrcweir                     throw xml::sax::SAXException(
97cdf0e10cSrcweir                         rAttrName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": no boolean value (true|false)!" ) ),
98cdf0e10cSrcweir                         Reference< XInterface >(), Any() );
99cdf0e10cSrcweir                 }
100cdf0e10cSrcweir             }
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir         return false;
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     // -----------------------------------------------------------------------------
106cdf0e10cSrcweir     // XElement
107cdf0e10cSrcweir     // -----------------------------------------------------------------------------
108cdf0e10cSrcweir 
getParent()109cdf0e10cSrcweir     Reference< xml::input::XElement > BasicElementBase::getParent()
110cdf0e10cSrcweir         throw (RuntimeException)
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         return static_cast< xml::input::XElement* >( m_pParent );
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     // -----------------------------------------------------------------------------
116cdf0e10cSrcweir 
getLocalName()117cdf0e10cSrcweir     ::rtl::OUString BasicElementBase::getLocalName()
118cdf0e10cSrcweir         throw (RuntimeException)
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         return m_aLocalName;
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // -----------------------------------------------------------------------------
124cdf0e10cSrcweir 
getUid()125cdf0e10cSrcweir     sal_Int32 BasicElementBase::getUid()
126cdf0e10cSrcweir         throw (RuntimeException)
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         sal_Int32 nId = -1;
129cdf0e10cSrcweir         if ( m_pImport )
130cdf0e10cSrcweir             nId = m_pImport->XMLNS_UID;
131cdf0e10cSrcweir         return nId;
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     // -----------------------------------------------------------------------------
135cdf0e10cSrcweir 
getAttributes()136cdf0e10cSrcweir     Reference< xml::input::XAttributes > BasicElementBase::getAttributes()
137cdf0e10cSrcweir         throw (RuntimeException)
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         return m_xAttributes;
140cdf0e10cSrcweir     }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     // -----------------------------------------------------------------------------
143cdf0e10cSrcweir 
startChildElement(sal_Int32,const::rtl::OUString &,const Reference<xml::input::XAttributes> &)144cdf0e10cSrcweir     Reference< xml::input::XElement > BasicElementBase::startChildElement(
145cdf0e10cSrcweir         sal_Int32 /*nUid*/, const ::rtl::OUString& /*rLocalName*/,
146cdf0e10cSrcweir         const Reference< xml::input::XAttributes >& /*xAttributes*/ )
147cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         throw xml::sax::SAXException(
150cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unexpected element!" ) ),
151cdf0e10cSrcweir             Reference< XInterface >(), Any() );
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     // -----------------------------------------------------------------------------
155cdf0e10cSrcweir 
characters(const::rtl::OUString &)156cdf0e10cSrcweir void BasicElementBase::characters( const ::rtl::OUString& /*rChars*/ )
157cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         // not used, all characters ignored
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     // -----------------------------------------------------------------------------
163cdf0e10cSrcweir 
ignorableWhitespace(const::rtl::OUString &)164cdf0e10cSrcweir void BasicElementBase::ignorableWhitespace( const ::rtl::OUString& /*rWhitespaces*/ )
165cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir     }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     // -----------------------------------------------------------------------------
170cdf0e10cSrcweir 
processingInstruction(const::rtl::OUString &,const::rtl::OUString &)171cdf0e10cSrcweir void BasicElementBase::processingInstruction( const ::rtl::OUString& /*rTarget*/, const ::rtl::OUString& /*rData*/ )
172cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     // -----------------------------------------------------------------------------
177cdf0e10cSrcweir 
endElement()178cdf0e10cSrcweir     void BasicElementBase::endElement()
179cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     // =============================================================================
185cdf0e10cSrcweir     // BasicLibrariesElement
186cdf0e10cSrcweir     // =============================================================================
187cdf0e10cSrcweir 
BasicLibrariesElement(const::rtl::OUString & rLocalName,const Reference<xml::input::XAttributes> & xAttributes,BasicElementBase * pParent,BasicImport * pImport,const Reference<script::XLibraryContainer2> & rxLibContainer)188cdf0e10cSrcweir     BasicLibrariesElement::BasicLibrariesElement( const ::rtl::OUString& rLocalName,
189cdf0e10cSrcweir             const Reference< xml::input::XAttributes >& xAttributes,
190cdf0e10cSrcweir             BasicElementBase* pParent, BasicImport* pImport,
191cdf0e10cSrcweir             const Reference< script::XLibraryContainer2 >& rxLibContainer )
192cdf0e10cSrcweir         :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
193cdf0e10cSrcweir         ,m_xLibContainer( rxLibContainer )
194cdf0e10cSrcweir     {
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     // -----------------------------------------------------------------------------
198cdf0e10cSrcweir     // XElement
199cdf0e10cSrcweir     // -----------------------------------------------------------------------------
200cdf0e10cSrcweir 
startChildElement(sal_Int32 nUid,const::rtl::OUString & rLocalName,const Reference<xml::input::XAttributes> & xAttributes)201cdf0e10cSrcweir     Reference< xml::input::XElement > BasicLibrariesElement::startChildElement(
202cdf0e10cSrcweir             sal_Int32 nUid, const ::rtl::OUString& rLocalName,
203cdf0e10cSrcweir             const Reference< xml::input::XAttributes >& xAttributes )
204cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
205cdf0e10cSrcweir     {
206cdf0e10cSrcweir         Reference< xml::input::XElement > xElement;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir         if ( nUid != m_pImport->XMLNS_UID )
209cdf0e10cSrcweir         {
210cdf0e10cSrcweir             throw xml::sax::SAXException(
211cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
212cdf0e10cSrcweir                 Reference< XInterface >(), Any() );
213cdf0e10cSrcweir         }
214cdf0e10cSrcweir         else if ( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "library-linked" ) ) )
215cdf0e10cSrcweir         {
216cdf0e10cSrcweir             if ( xAttributes.is() )
217cdf0e10cSrcweir             {
218cdf0e10cSrcweir                 ::rtl::OUString aName = xAttributes->getValueByUidName(
219cdf0e10cSrcweir                     m_pImport->XMLNS_UID,
220cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir                 ::rtl::OUString aStorageURL = xAttributes->getValueByUidName(
223cdf0e10cSrcweir                     m_pImport->XMLNS_XLINK_UID,
224cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "href" ) ) );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir                 sal_Bool bReadOnly = sal_False;
227cdf0e10cSrcweir                 getBoolAttr( &bReadOnly,
228cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "readonly" ) ),
229cdf0e10cSrcweir                     xAttributes, m_pImport->XMLNS_UID );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir                 if ( m_xLibContainer.is() )
232cdf0e10cSrcweir                 {
233cdf0e10cSrcweir                     try
234cdf0e10cSrcweir                     {
235cdf0e10cSrcweir                         Reference< container::XNameAccess > xLib(
236cdf0e10cSrcweir                             m_xLibContainer->createLibraryLink( aName, aStorageURL, bReadOnly ) );
237cdf0e10cSrcweir                         if ( xLib.is() )
238cdf0e10cSrcweir                             xElement.set( new BasicElementBase( rLocalName, xAttributes, this, m_pImport ) );
239cdf0e10cSrcweir                     }
240cdf0e10cSrcweir                     catch ( container::ElementExistException& e )
241cdf0e10cSrcweir                     {
242cdf0e10cSrcweir                         OSL_TRACE( "BasicLibrariesElement::startChildElement: caught ElementExceptionExist reason %s",
243cdf0e10cSrcweir                             ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
244cdf0e10cSrcweir                     }
245cdf0e10cSrcweir                     catch ( lang::IllegalArgumentException& e )
246cdf0e10cSrcweir                     {
247cdf0e10cSrcweir                         OSL_TRACE( "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason %s",
248cdf0e10cSrcweir                             ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
249cdf0e10cSrcweir                     }
250cdf0e10cSrcweir                 }
251cdf0e10cSrcweir             }
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir         else if ( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "library-embedded" ) ) )
254cdf0e10cSrcweir         {
255cdf0e10cSrcweir             // TODO: create password protected libraries
256cdf0e10cSrcweir 
257cdf0e10cSrcweir             if ( xAttributes.is() )
258cdf0e10cSrcweir             {
259cdf0e10cSrcweir                 ::rtl::OUString aName = xAttributes->getValueByUidName(
260cdf0e10cSrcweir                     m_pImport->XMLNS_UID,
261cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
262cdf0e10cSrcweir 
263cdf0e10cSrcweir                 sal_Bool bReadOnly = sal_False;
264cdf0e10cSrcweir                 getBoolAttr( &bReadOnly,
265cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "readonly" ) ),
266cdf0e10cSrcweir                     xAttributes, m_pImport->XMLNS_UID );
267cdf0e10cSrcweir 
268cdf0e10cSrcweir                 if ( m_xLibContainer.is() )
269cdf0e10cSrcweir                 {
270cdf0e10cSrcweir                     try
271cdf0e10cSrcweir                     {
272cdf0e10cSrcweir                         Reference< container::XNameContainer > xLib;
273cdf0e10cSrcweir                         if ( m_xLibContainer->hasByName( aName ) )
274cdf0e10cSrcweir                         {
275cdf0e10cSrcweir                             // Standard library
276cdf0e10cSrcweir                             m_xLibContainer->getByName( aName ) >>= xLib;
277cdf0e10cSrcweir                         }
278cdf0e10cSrcweir                         else
279cdf0e10cSrcweir                         {
280cdf0e10cSrcweir                             xLib.set( m_xLibContainer->createLibrary( aName ) );
281cdf0e10cSrcweir                         }
282cdf0e10cSrcweir 
283cdf0e10cSrcweir                         if ( xLib.is() )
284cdf0e10cSrcweir                             xElement.set( new BasicEmbeddedLibraryElement( rLocalName, xAttributes, this, m_pImport, m_xLibContainer, aName, bReadOnly ) );
285cdf0e10cSrcweir                     }
286cdf0e10cSrcweir                     catch ( lang::IllegalArgumentException& e )
287cdf0e10cSrcweir                     {
288cdf0e10cSrcweir                         OSL_TRACE( "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason %s",
289cdf0e10cSrcweir                             ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
290cdf0e10cSrcweir                     }
291cdf0e10cSrcweir                 }
292cdf0e10cSrcweir             }
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir         else
295cdf0e10cSrcweir         {
296cdf0e10cSrcweir             throw xml::sax::SAXException(
297cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected library-linked or library-embedded element!" ) ),
298cdf0e10cSrcweir                 Reference< XInterface >(), Any() );
299cdf0e10cSrcweir         }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         return xElement;
302cdf0e10cSrcweir     }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir     // -----------------------------------------------------------------------------
305cdf0e10cSrcweir 
endElement()306cdf0e10cSrcweir     void BasicLibrariesElement::endElement()
307cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir     }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     // =============================================================================
313cdf0e10cSrcweir     // BasicEmbeddedLibraryElement
314cdf0e10cSrcweir     // =============================================================================
315cdf0e10cSrcweir 
BasicEmbeddedLibraryElement(const::rtl::OUString & rLocalName,const Reference<xml::input::XAttributes> & xAttributes,BasicElementBase * pParent,BasicImport * pImport,const Reference<script::XLibraryContainer2> & rxLibContainer,const::rtl::OUString & rLibName,bool bReadOnly)316cdf0e10cSrcweir     BasicEmbeddedLibraryElement::BasicEmbeddedLibraryElement( const ::rtl::OUString& rLocalName,
317cdf0e10cSrcweir             const Reference< xml::input::XAttributes >& xAttributes,
318cdf0e10cSrcweir             BasicElementBase* pParent, BasicImport* pImport,
319cdf0e10cSrcweir             const Reference< script::XLibraryContainer2 >& rxLibContainer,
320cdf0e10cSrcweir             const ::rtl::OUString& rLibName, bool bReadOnly )
321cdf0e10cSrcweir         :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
322cdf0e10cSrcweir         ,m_xLibContainer( rxLibContainer )
323cdf0e10cSrcweir         ,m_aLibName( rLibName )
324cdf0e10cSrcweir         ,m_bReadOnly( bReadOnly )
325cdf0e10cSrcweir     {
326cdf0e10cSrcweir         try
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir             if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_aLibName ) )
329cdf0e10cSrcweir                 m_xLibContainer->getByName( m_aLibName ) >>= m_xLib;
330cdf0e10cSrcweir         }
331cdf0e10cSrcweir         catch ( lang::WrappedTargetException& e )
332cdf0e10cSrcweir         {
333cdf0e10cSrcweir             OSL_TRACE( "BasicEmbeddedLibraryElement CTOR: caught WrappedTargetException reason %s",
334cdf0e10cSrcweir                 ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
335cdf0e10cSrcweir         }
336cdf0e10cSrcweir     }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     // -----------------------------------------------------------------------------
339cdf0e10cSrcweir     // XElement
340cdf0e10cSrcweir     // -----------------------------------------------------------------------------
341cdf0e10cSrcweir 
startChildElement(sal_Int32 nUid,const::rtl::OUString & rLocalName,const Reference<xml::input::XAttributes> & xAttributes)342cdf0e10cSrcweir     Reference< xml::input::XElement > BasicEmbeddedLibraryElement::startChildElement(
343cdf0e10cSrcweir             sal_Int32 nUid, const ::rtl::OUString& rLocalName,
344cdf0e10cSrcweir             const Reference< xml::input::XAttributes >& xAttributes )
345cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
346cdf0e10cSrcweir     {
347cdf0e10cSrcweir         Reference< xml::input::XElement > xElement;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir         if ( nUid != m_pImport->XMLNS_UID )
350cdf0e10cSrcweir         {
351cdf0e10cSrcweir             throw xml::sax::SAXException(
352cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
353cdf0e10cSrcweir                 Reference< XInterface >(), Any() );
354cdf0e10cSrcweir         }
355cdf0e10cSrcweir         else if ( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "module" ) ) )
356cdf0e10cSrcweir         {
357cdf0e10cSrcweir             if ( xAttributes.is() )
358cdf0e10cSrcweir             {
359cdf0e10cSrcweir                 ::rtl::OUString aName = xAttributes->getValueByUidName(
360cdf0e10cSrcweir                     m_pImport->XMLNS_UID,
361cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
362cdf0e10cSrcweir 
363cdf0e10cSrcweir                 if ( m_xLib.is() && aName.getLength() )
364cdf0e10cSrcweir                     xElement.set( new BasicModuleElement( rLocalName, xAttributes, this, m_pImport, m_xLib, aName ) );
365cdf0e10cSrcweir             }
366cdf0e10cSrcweir         }
367cdf0e10cSrcweir         else
368cdf0e10cSrcweir         {
369cdf0e10cSrcweir             throw xml::sax::SAXException(
370cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected module element!" ) ),
371cdf0e10cSrcweir                 Reference< XInterface >(), Any() );
372cdf0e10cSrcweir         }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir         return xElement;
375cdf0e10cSrcweir     }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     // -----------------------------------------------------------------------------
378cdf0e10cSrcweir 
endElement()379cdf0e10cSrcweir     void BasicEmbeddedLibraryElement::endElement()
380cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
381cdf0e10cSrcweir     {
382cdf0e10cSrcweir         if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_aLibName ) && m_bReadOnly )
383cdf0e10cSrcweir             m_xLibContainer->setLibraryReadOnly( m_aLibName, m_bReadOnly );
384cdf0e10cSrcweir     }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 
387cdf0e10cSrcweir     // =============================================================================
388cdf0e10cSrcweir     // BasicModuleElement
389cdf0e10cSrcweir     // =============================================================================
390cdf0e10cSrcweir 
BasicModuleElement(const::rtl::OUString & rLocalName,const Reference<xml::input::XAttributes> & xAttributes,BasicElementBase * pParent,BasicImport * pImport,const Reference<container::XNameContainer> & rxLib,const::rtl::OUString & rName)391cdf0e10cSrcweir     BasicModuleElement::BasicModuleElement( const ::rtl::OUString& rLocalName,
392cdf0e10cSrcweir             const Reference< xml::input::XAttributes >& xAttributes,
393cdf0e10cSrcweir             BasicElementBase* pParent, BasicImport* pImport,
394cdf0e10cSrcweir             const Reference< container::XNameContainer >& rxLib, const ::rtl::OUString& rName )
395cdf0e10cSrcweir         :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
396cdf0e10cSrcweir         ,m_xLib( rxLib )
397cdf0e10cSrcweir         ,m_aName( rName )
398cdf0e10cSrcweir     {
399cdf0e10cSrcweir     }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     // -----------------------------------------------------------------------------
402cdf0e10cSrcweir     // XElement
403cdf0e10cSrcweir     // -----------------------------------------------------------------------------
404cdf0e10cSrcweir 
startChildElement(sal_Int32 nUid,const::rtl::OUString & rLocalName,const Reference<xml::input::XAttributes> & xAttributes)405cdf0e10cSrcweir     Reference< xml::input::XElement > BasicModuleElement::startChildElement(
406cdf0e10cSrcweir             sal_Int32 nUid, const ::rtl::OUString& rLocalName,
407cdf0e10cSrcweir             const Reference< xml::input::XAttributes >& xAttributes )
408cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
409cdf0e10cSrcweir     {
410cdf0e10cSrcweir         // TODO: <byte-code>
411cdf0e10cSrcweir 
412cdf0e10cSrcweir         Reference< xml::input::XElement > xElement;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir         if ( nUid != m_pImport->XMLNS_UID )
415cdf0e10cSrcweir         {
416cdf0e10cSrcweir             throw xml::sax::SAXException(
417cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
418cdf0e10cSrcweir                 Reference< XInterface >(), Any() );
419cdf0e10cSrcweir         }
420cdf0e10cSrcweir         else if ( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "source-code" ) ) )
421cdf0e10cSrcweir         {
422cdf0e10cSrcweir             // TODO: password protected libraries
423cdf0e10cSrcweir 
424cdf0e10cSrcweir             if ( xAttributes.is() )
425cdf0e10cSrcweir             {
426cdf0e10cSrcweir                 if ( m_xLib.is() && m_aName.getLength() )
427cdf0e10cSrcweir                     xElement.set( new BasicSourceCodeElement( rLocalName, xAttributes, this, m_pImport, m_xLib, m_aName ) );
428cdf0e10cSrcweir             }
429cdf0e10cSrcweir         }
430cdf0e10cSrcweir         else
431cdf0e10cSrcweir         {
432cdf0e10cSrcweir             throw xml::sax::SAXException(
433cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected source-code element!" ) ),
434cdf0e10cSrcweir                 Reference< XInterface >(), Any() );
435cdf0e10cSrcweir         }
436cdf0e10cSrcweir 
437cdf0e10cSrcweir         return xElement;
438cdf0e10cSrcweir     }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir     // -----------------------------------------------------------------------------
441cdf0e10cSrcweir 
endElement()442cdf0e10cSrcweir     void BasicModuleElement::endElement()
443cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
444cdf0e10cSrcweir     {
445cdf0e10cSrcweir     }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     // =============================================================================
449cdf0e10cSrcweir     // BasicSourceCodeElement
450cdf0e10cSrcweir     // =============================================================================
451cdf0e10cSrcweir 
BasicSourceCodeElement(const::rtl::OUString & rLocalName,const Reference<xml::input::XAttributes> & xAttributes,BasicElementBase * pParent,BasicImport * pImport,const Reference<container::XNameContainer> & rxLib,const::rtl::OUString & rName)452cdf0e10cSrcweir     BasicSourceCodeElement::BasicSourceCodeElement( const ::rtl::OUString& rLocalName,
453cdf0e10cSrcweir             const Reference< xml::input::XAttributes >& xAttributes,
454cdf0e10cSrcweir             BasicElementBase* pParent, BasicImport* pImport,
455cdf0e10cSrcweir             const Reference< container::XNameContainer >& rxLib, const ::rtl::OUString& rName )
456cdf0e10cSrcweir         :BasicElementBase( rLocalName, xAttributes, pParent, pImport )
457cdf0e10cSrcweir         ,m_xLib( rxLib )
458cdf0e10cSrcweir         ,m_aName( rName )
459cdf0e10cSrcweir     {
460cdf0e10cSrcweir     }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     // -----------------------------------------------------------------------------
463cdf0e10cSrcweir     // XElement
464cdf0e10cSrcweir     // -----------------------------------------------------------------------------
465cdf0e10cSrcweir 
characters(const::rtl::OUString & rChars)466cdf0e10cSrcweir     void BasicSourceCodeElement::characters( const ::rtl::OUString& rChars )
467cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
468cdf0e10cSrcweir     {
469cdf0e10cSrcweir         m_aBuffer.append( rChars );
470cdf0e10cSrcweir     }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir     // -----------------------------------------------------------------------------
473cdf0e10cSrcweir 
endElement()474cdf0e10cSrcweir     void BasicSourceCodeElement::endElement()
475cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
476cdf0e10cSrcweir     {
477cdf0e10cSrcweir         try
478cdf0e10cSrcweir         {
479cdf0e10cSrcweir             if ( m_xLib.is() && m_aName.getLength() )
480cdf0e10cSrcweir             {
481cdf0e10cSrcweir                 Any aElement;
482cdf0e10cSrcweir 		        aElement <<= m_aBuffer.makeStringAndClear();
483cdf0e10cSrcweir 		        m_xLib->insertByName( m_aName, aElement );
484cdf0e10cSrcweir             }
485cdf0e10cSrcweir         }
486cdf0e10cSrcweir         catch ( container::ElementExistException& e )
487cdf0e10cSrcweir         {
488cdf0e10cSrcweir             OSL_TRACE( "BasicSourceCodeElement::endElement: caught ElementExceptionExist reason %s",
489cdf0e10cSrcweir                 ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
490cdf0e10cSrcweir         }
491cdf0e10cSrcweir         catch ( lang::IllegalArgumentException& e )
492cdf0e10cSrcweir         {
493cdf0e10cSrcweir             OSL_TRACE( "BasicSourceCodeElement::endElement: caught IllegalArgumentException reason %s",
494cdf0e10cSrcweir                 ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
495cdf0e10cSrcweir         }
496cdf0e10cSrcweir         catch ( lang::WrappedTargetException& e )
497cdf0e10cSrcweir         {
498cdf0e10cSrcweir             OSL_TRACE( "BasicSourceCodeElement::endElement: caught WrappedTargetException reason %s",
499cdf0e10cSrcweir                 ::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).pData->buffer );
500cdf0e10cSrcweir         }
501cdf0e10cSrcweir     }
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 
504cdf0e10cSrcweir     // =============================================================================
505cdf0e10cSrcweir     // BasicImport
506cdf0e10cSrcweir     // =============================================================================
507cdf0e10cSrcweir 
BasicImport(const Reference<frame::XModel> & rxModel,sal_Bool bOasis)508cdf0e10cSrcweir     BasicImport::BasicImport( const Reference< frame::XModel >& rxModel, sal_Bool bOasis )
509cdf0e10cSrcweir         :m_xModel( rxModel )
510cdf0e10cSrcweir         ,m_bOasis( bOasis )
511cdf0e10cSrcweir     {
512cdf0e10cSrcweir     }
513cdf0e10cSrcweir 
514cdf0e10cSrcweir     // -----------------------------------------------------------------------------
515cdf0e10cSrcweir 
~BasicImport()516cdf0e10cSrcweir     BasicImport::~BasicImport()
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir     }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir     // -----------------------------------------------------------------------------
521cdf0e10cSrcweir     // XRoot
522cdf0e10cSrcweir     // -----------------------------------------------------------------------------
523cdf0e10cSrcweir 
startDocument(const Reference<xml::input::XNamespaceMapping> & xNamespaceMapping)524cdf0e10cSrcweir     void BasicImport::startDocument( const Reference< xml::input::XNamespaceMapping >& xNamespaceMapping )
525cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
526cdf0e10cSrcweir     {
527cdf0e10cSrcweir         if ( xNamespaceMapping.is() )
528cdf0e10cSrcweir         {
529cdf0e10cSrcweir             ::rtl::OUString aURI;
530cdf0e10cSrcweir             if ( m_bOasis )
531cdf0e10cSrcweir                 aURI = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_OOO_URI ) );
532cdf0e10cSrcweir             else
533cdf0e10cSrcweir                 aURI = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_SCRIPT_URI ) );
534cdf0e10cSrcweir             XMLNS_UID = xNamespaceMapping->getUidByUri( aURI );
535cdf0e10cSrcweir             XMLNS_XLINK_UID = xNamespaceMapping->getUidByUri( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_URI ) ) );
536cdf0e10cSrcweir         }
537cdf0e10cSrcweir     }
538cdf0e10cSrcweir 
539cdf0e10cSrcweir     // -----------------------------------------------------------------------------
540cdf0e10cSrcweir 
endDocument()541cdf0e10cSrcweir     void BasicImport::endDocument()
542cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
543cdf0e10cSrcweir     {
544cdf0e10cSrcweir     }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir     // -----------------------------------------------------------------------------
547cdf0e10cSrcweir 
processingInstruction(const::rtl::OUString &,const::rtl::OUString &)548cdf0e10cSrcweir void BasicImport::processingInstruction( const ::rtl::OUString& /*rTarget*/, const ::rtl::OUString& /*rData*/ )
549cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
550cdf0e10cSrcweir     {
551cdf0e10cSrcweir     }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir     // -----------------------------------------------------------------------------
554cdf0e10cSrcweir 
setDocumentLocator(const Reference<xml::sax::XLocator> &)555cdf0e10cSrcweir void BasicImport::setDocumentLocator( const Reference< xml::sax::XLocator >& /*xLocator*/ )
556cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
557cdf0e10cSrcweir     {
558cdf0e10cSrcweir     }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir     // -----------------------------------------------------------------------------
561cdf0e10cSrcweir 
startRootElement(sal_Int32 nUid,const::rtl::OUString & rLocalName,Reference<xml::input::XAttributes> const & xAttributes)562cdf0e10cSrcweir     Reference< xml::input::XElement > BasicImport::startRootElement( sal_Int32 nUid, const ::rtl::OUString& rLocalName,
563cdf0e10cSrcweir             Reference< xml::input::XAttributes > const & xAttributes )
564cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
565cdf0e10cSrcweir     {
566cdf0e10cSrcweir         Reference< xml::input::XElement > xElement;
567cdf0e10cSrcweir 
568cdf0e10cSrcweir         if ( nUid != XMLNS_UID )
569cdf0e10cSrcweir         {
570cdf0e10cSrcweir             throw xml::sax::SAXException(
571cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
572cdf0e10cSrcweir                 Reference< XInterface >(), Any() );
573cdf0e10cSrcweir         }
574cdf0e10cSrcweir         else if ( rLocalName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "libraries" ) ) )
575cdf0e10cSrcweir         {
576cdf0e10cSrcweir             Reference< script::XLibraryContainer2 > xLibContainer;
577cdf0e10cSrcweir 
578cdf0e10cSrcweir             // try the XEmbeddedScripts interface
579cdf0e10cSrcweir             Reference< document::XEmbeddedScripts > xDocumentScripts( m_xModel, UNO_QUERY );
580cdf0e10cSrcweir             if ( xDocumentScripts.is() )
581cdf0e10cSrcweir                 xLibContainer.set( xDocumentScripts->getBasicLibraries().get() );
582cdf0e10cSrcweir 
583cdf0e10cSrcweir             if ( !xLibContainer.is() )
584cdf0e10cSrcweir             {
585cdf0e10cSrcweir                 // try the "BasicLibraries" property (old-style, for compatibility)
586cdf0e10cSrcweir                 Reference< beans::XPropertySet > xPSet( m_xModel, UNO_QUERY );
587cdf0e10cSrcweir                 if ( xPSet.is() )
588cdf0e10cSrcweir 	                xPSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ) >>= xLibContainer;
589cdf0e10cSrcweir             }
590cdf0e10cSrcweir 
591cdf0e10cSrcweir             OSL_ENSURE( xLibContainer.is(), "BasicImport::startRootElement: nowhere to import to!" );
592cdf0e10cSrcweir 
593cdf0e10cSrcweir             if ( xLibContainer.is() )
594cdf0e10cSrcweir             {
595cdf0e10cSrcweir                 xElement.set( new BasicLibrariesElement( rLocalName, xAttributes, 0, this, xLibContainer ) );
596cdf0e10cSrcweir             }
597cdf0e10cSrcweir         }
598cdf0e10cSrcweir         else
599cdf0e10cSrcweir         {
600cdf0e10cSrcweir             throw xml::sax::SAXException(
601cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal root element (expected libraries) given: " ) ) +
602cdf0e10cSrcweir                 rLocalName, Reference< XInterface >(), Any() );
603cdf0e10cSrcweir         }
604cdf0e10cSrcweir 
605cdf0e10cSrcweir         return xElement;
606cdf0e10cSrcweir     }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     // =============================================================================
610cdf0e10cSrcweir     // component operations
611cdf0e10cSrcweir     // =============================================================================
612cdf0e10cSrcweir 
getImplementationName_XMLBasicImporter()613cdf0e10cSrcweir     ::rtl::OUString getImplementationName_XMLBasicImporter()
614cdf0e10cSrcweir     {
615cdf0e10cSrcweir         static ::rtl::OUString* pImplName = 0;
616cdf0e10cSrcweir 	    if ( !pImplName )
617cdf0e10cSrcweir 	    {
618cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
619cdf0e10cSrcweir             if ( !pImplName )
620cdf0e10cSrcweir 		    {
621cdf0e10cSrcweir                 static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLBasicImporter" ) );
622cdf0e10cSrcweir 			    pImplName = &aImplName;
623cdf0e10cSrcweir 		    }
624cdf0e10cSrcweir 	    }
625cdf0e10cSrcweir 	    return *pImplName;
626cdf0e10cSrcweir     }
627cdf0e10cSrcweir 
628cdf0e10cSrcweir     // -----------------------------------------------------------------------------
629cdf0e10cSrcweir 
getSupportedServiceNames_XMLBasicImporter()630cdf0e10cSrcweir     Sequence< ::rtl::OUString > getSupportedServiceNames_XMLBasicImporter()
631cdf0e10cSrcweir     {
632cdf0e10cSrcweir         static Sequence< ::rtl::OUString >* pNames = 0;
633cdf0e10cSrcweir 	    if ( !pNames )
634cdf0e10cSrcweir 	    {
635cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
636cdf0e10cSrcweir 		    if ( !pNames )
637cdf0e10cSrcweir 		    {
638cdf0e10cSrcweir                 static Sequence< ::rtl::OUString > aNames(1);
639cdf0e10cSrcweir                 aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLBasicImporter" ) );
640cdf0e10cSrcweir                 pNames = &aNames;
641cdf0e10cSrcweir 		    }
642cdf0e10cSrcweir 	    }
643cdf0e10cSrcweir 	    return *pNames;
644cdf0e10cSrcweir     }
645cdf0e10cSrcweir 
646cdf0e10cSrcweir     // -----------------------------------------------------------------------------
647cdf0e10cSrcweir 
getImplementationName_XMLOasisBasicImporter()648cdf0e10cSrcweir     ::rtl::OUString getImplementationName_XMLOasisBasicImporter()
649cdf0e10cSrcweir     {
650cdf0e10cSrcweir         static ::rtl::OUString* pImplName = 0;
651cdf0e10cSrcweir 	    if ( !pImplName )
652cdf0e10cSrcweir 	    {
653cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
654cdf0e10cSrcweir             if ( !pImplName )
655cdf0e10cSrcweir 		    {
656cdf0e10cSrcweir                 static ::rtl::OUString aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLOasisBasicImporter" ) );
657cdf0e10cSrcweir 			    pImplName = &aImplName;
658cdf0e10cSrcweir 		    }
659cdf0e10cSrcweir 	    }
660cdf0e10cSrcweir 	    return *pImplName;
661cdf0e10cSrcweir     }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     // -----------------------------------------------------------------------------
664cdf0e10cSrcweir 
getSupportedServiceNames_XMLOasisBasicImporter()665cdf0e10cSrcweir     Sequence< ::rtl::OUString > getSupportedServiceNames_XMLOasisBasicImporter()
666cdf0e10cSrcweir     {
667cdf0e10cSrcweir         static Sequence< ::rtl::OUString >* pNames = 0;
668cdf0e10cSrcweir 	    if ( !pNames )
669cdf0e10cSrcweir 	    {
670cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
671cdf0e10cSrcweir 		    if ( !pNames )
672cdf0e10cSrcweir 		    {
673cdf0e10cSrcweir                 static Sequence< ::rtl::OUString > aNames(1);
674cdf0e10cSrcweir                 aNames.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicImporter" ) );
675cdf0e10cSrcweir                 pNames = &aNames;
676cdf0e10cSrcweir 		    }
677cdf0e10cSrcweir 	    }
678cdf0e10cSrcweir 	    return *pNames;
679cdf0e10cSrcweir     }
680cdf0e10cSrcweir 
681cdf0e10cSrcweir 
682cdf0e10cSrcweir     // =============================================================================
683cdf0e10cSrcweir     // XMLBasicImporterBase
684cdf0e10cSrcweir     // =============================================================================
685cdf0e10cSrcweir 
XMLBasicImporterBase(const Reference<XComponentContext> & rxContext,sal_Bool bOasis)686cdf0e10cSrcweir     XMLBasicImporterBase::XMLBasicImporterBase( const Reference< XComponentContext >& rxContext, sal_Bool bOasis )
687cdf0e10cSrcweir         :m_xContext( rxContext )
688cdf0e10cSrcweir         ,m_bOasis( bOasis )
689cdf0e10cSrcweir     {
690cdf0e10cSrcweir     }
691cdf0e10cSrcweir 
692cdf0e10cSrcweir     // -----------------------------------------------------------------------------
693cdf0e10cSrcweir 
~XMLBasicImporterBase()694cdf0e10cSrcweir     XMLBasicImporterBase::~XMLBasicImporterBase()
695cdf0e10cSrcweir     {
696cdf0e10cSrcweir     }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir     // -----------------------------------------------------------------------------
699cdf0e10cSrcweir     // XServiceInfo
700cdf0e10cSrcweir     // -----------------------------------------------------------------------------
701cdf0e10cSrcweir 
supportsService(const::rtl::OUString & rServiceName)702cdf0e10cSrcweir     sal_Bool XMLBasicImporterBase::supportsService( const ::rtl::OUString& rServiceName ) throw (RuntimeException)
703cdf0e10cSrcweir     {
704cdf0e10cSrcweir 	    Sequence< ::rtl::OUString > aNames( getSupportedServiceNames() );
705cdf0e10cSrcweir 	    const ::rtl::OUString* pNames = aNames.getConstArray();
706cdf0e10cSrcweir 	    const ::rtl::OUString* pEnd = pNames + aNames.getLength();
707cdf0e10cSrcweir 	    for ( ; pNames != pEnd && !pNames->equals( rServiceName ); ++pNames )
708cdf0e10cSrcweir 		    ;
709cdf0e10cSrcweir 
710cdf0e10cSrcweir 	    return pNames != pEnd;
711cdf0e10cSrcweir     }
712cdf0e10cSrcweir 
713cdf0e10cSrcweir     // -----------------------------------------------------------------------------
714cdf0e10cSrcweir     // XImporter
715cdf0e10cSrcweir     // -----------------------------------------------------------------------------
716cdf0e10cSrcweir 
setTargetDocument(const Reference<XComponent> & rxDoc)717cdf0e10cSrcweir     void XMLBasicImporterBase::setTargetDocument( const Reference< XComponent >& rxDoc )
718cdf0e10cSrcweir 	    throw (IllegalArgumentException, RuntimeException)
719cdf0e10cSrcweir     {
720cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
721cdf0e10cSrcweir 
722cdf0e10cSrcweir         m_xModel.set( rxDoc, UNO_QUERY );
723cdf0e10cSrcweir 
724cdf0e10cSrcweir         if ( !m_xModel.is() )
725cdf0e10cSrcweir         {
726cdf0e10cSrcweir             throw IllegalArgumentException(
727cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLBasicExporter::setTargetDocument: no document model!" ) ),
728cdf0e10cSrcweir                 Reference< XInterface >(), 1 );
729cdf0e10cSrcweir         }
730cdf0e10cSrcweir 
731cdf0e10cSrcweir         if ( m_xContext.is() )
732cdf0e10cSrcweir         {
733cdf0e10cSrcweir             Reference< XMultiComponentFactory > xSMgr( m_xContext->getServiceManager() );
734cdf0e10cSrcweir             if ( xSMgr.is() )
735cdf0e10cSrcweir             {
736cdf0e10cSrcweir                 Reference < xml::input::XRoot > xRoot( new BasicImport( m_xModel, m_bOasis ) );
737cdf0e10cSrcweir 	            Sequence < Any > aArgs( 1 );
738cdf0e10cSrcweir 	            aArgs[0] <<= xRoot;
739cdf0e10cSrcweir                 m_xHandler.set( xSMgr->createInstanceWithArgumentsAndContext(
740cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.input.SaxDocumentHandler" ) ),
741cdf0e10cSrcweir                     aArgs, m_xContext ), UNO_QUERY );
742cdf0e10cSrcweir             }
743cdf0e10cSrcweir         }
744cdf0e10cSrcweir     }
745cdf0e10cSrcweir 
746cdf0e10cSrcweir     // -----------------------------------------------------------------------------
747cdf0e10cSrcweir     // XDocumentHandler
748cdf0e10cSrcweir     // -----------------------------------------------------------------------------
749cdf0e10cSrcweir 
startDocument()750cdf0e10cSrcweir     void XMLBasicImporterBase::startDocument()
751cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
752cdf0e10cSrcweir     {
753cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
754cdf0e10cSrcweir 
755cdf0e10cSrcweir         if ( m_xHandler.is() )
756cdf0e10cSrcweir             m_xHandler->startDocument();
757cdf0e10cSrcweir     }
758cdf0e10cSrcweir 
759cdf0e10cSrcweir     // -----------------------------------------------------------------------------
760cdf0e10cSrcweir 
endDocument()761cdf0e10cSrcweir     void XMLBasicImporterBase::endDocument()
762cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
765cdf0e10cSrcweir 
766cdf0e10cSrcweir         if ( m_xHandler.is() )
767cdf0e10cSrcweir             m_xHandler->endDocument();
768cdf0e10cSrcweir     }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir     // -----------------------------------------------------------------------------
771cdf0e10cSrcweir 
startElement(const::rtl::OUString & aName,const Reference<xml::sax::XAttributeList> & xAttribs)772cdf0e10cSrcweir     void XMLBasicImporterBase::startElement( const ::rtl::OUString& aName,
773cdf0e10cSrcweir             const Reference< xml::sax::XAttributeList >& xAttribs )
774cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
775cdf0e10cSrcweir     {
776cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
777cdf0e10cSrcweir 
778cdf0e10cSrcweir         if ( m_xHandler.is() )
779cdf0e10cSrcweir             m_xHandler->startElement( aName, xAttribs );
780cdf0e10cSrcweir     }
781cdf0e10cSrcweir 
782cdf0e10cSrcweir     // -----------------------------------------------------------------------------
783cdf0e10cSrcweir 
endElement(const::rtl::OUString & aName)784cdf0e10cSrcweir     void XMLBasicImporterBase::endElement( const ::rtl::OUString& aName )
785cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
786cdf0e10cSrcweir     {
787cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
788cdf0e10cSrcweir 
789cdf0e10cSrcweir         if ( m_xHandler.is() )
790cdf0e10cSrcweir             m_xHandler->endElement( aName );
791cdf0e10cSrcweir     }
792cdf0e10cSrcweir 
793cdf0e10cSrcweir     // -----------------------------------------------------------------------------
794cdf0e10cSrcweir 
characters(const::rtl::OUString & aChars)795cdf0e10cSrcweir     void XMLBasicImporterBase::characters( const ::rtl::OUString& aChars )
796cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
797cdf0e10cSrcweir     {
798cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
799cdf0e10cSrcweir 
800cdf0e10cSrcweir         if ( m_xHandler.is() )
801cdf0e10cSrcweir             m_xHandler->characters( aChars );
802cdf0e10cSrcweir     }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir     // -----------------------------------------------------------------------------
805cdf0e10cSrcweir 
ignorableWhitespace(const::rtl::OUString & aWhitespaces)806cdf0e10cSrcweir     void XMLBasicImporterBase::ignorableWhitespace( const ::rtl::OUString& aWhitespaces )
807cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
808cdf0e10cSrcweir     {
809cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
810cdf0e10cSrcweir 
811cdf0e10cSrcweir         if ( m_xHandler.is() )
812cdf0e10cSrcweir             m_xHandler->ignorableWhitespace( aWhitespaces );
813cdf0e10cSrcweir     }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir     // -----------------------------------------------------------------------------
816cdf0e10cSrcweir 
processingInstruction(const::rtl::OUString & aTarget,const::rtl::OUString & aData)817cdf0e10cSrcweir     void XMLBasicImporterBase::processingInstruction( const ::rtl::OUString& aTarget,
818cdf0e10cSrcweir             const ::rtl::OUString& aData )
819cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
820cdf0e10cSrcweir     {
821cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
822cdf0e10cSrcweir 
823cdf0e10cSrcweir         if ( m_xHandler.is() )
824cdf0e10cSrcweir             m_xHandler->processingInstruction( aTarget, aData );
825cdf0e10cSrcweir     }
826cdf0e10cSrcweir 
827cdf0e10cSrcweir     // -----------------------------------------------------------------------------
828cdf0e10cSrcweir 
setDocumentLocator(const Reference<xml::sax::XLocator> & xLocator)829cdf0e10cSrcweir     void XMLBasicImporterBase::setDocumentLocator( const Reference< xml::sax::XLocator >& xLocator )
830cdf0e10cSrcweir         throw (xml::sax::SAXException, RuntimeException)
831cdf0e10cSrcweir     {
832cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
833cdf0e10cSrcweir 
834cdf0e10cSrcweir         if ( m_xHandler.is() )
835cdf0e10cSrcweir             m_xHandler->setDocumentLocator( xLocator );
836cdf0e10cSrcweir     }
837cdf0e10cSrcweir 
838cdf0e10cSrcweir 
839cdf0e10cSrcweir     // =============================================================================
840cdf0e10cSrcweir     // XMLBasicImporter
841cdf0e10cSrcweir     // =============================================================================
842cdf0e10cSrcweir 
XMLBasicImporter(const Reference<XComponentContext> & rxContext)843cdf0e10cSrcweir     XMLBasicImporter::XMLBasicImporter( const Reference< XComponentContext >& rxContext )
844cdf0e10cSrcweir         :XMLBasicImporterBase( rxContext, sal_False )
845cdf0e10cSrcweir     {
846cdf0e10cSrcweir     }
847cdf0e10cSrcweir 
848cdf0e10cSrcweir     // -----------------------------------------------------------------------------
849cdf0e10cSrcweir 
~XMLBasicImporter()850cdf0e10cSrcweir     XMLBasicImporter::~XMLBasicImporter()
851cdf0e10cSrcweir     {
852cdf0e10cSrcweir     }
853cdf0e10cSrcweir 
854cdf0e10cSrcweir     // -----------------------------------------------------------------------------
855cdf0e10cSrcweir     // XServiceInfo
856cdf0e10cSrcweir     // -----------------------------------------------------------------------------
857cdf0e10cSrcweir 
getImplementationName()858cdf0e10cSrcweir     ::rtl::OUString XMLBasicImporter::getImplementationName(  ) throw (RuntimeException)
859cdf0e10cSrcweir     {
860cdf0e10cSrcweir         return getImplementationName_XMLBasicImporter();
861cdf0e10cSrcweir     }
862cdf0e10cSrcweir 
863cdf0e10cSrcweir     // -----------------------------------------------------------------------------
864cdf0e10cSrcweir 
getSupportedServiceNames()865cdf0e10cSrcweir     Sequence< ::rtl::OUString > XMLBasicImporter::getSupportedServiceNames(  ) throw (RuntimeException)
866cdf0e10cSrcweir     {
867cdf0e10cSrcweir         return getSupportedServiceNames_XMLBasicImporter();
868cdf0e10cSrcweir     }
869cdf0e10cSrcweir 
870cdf0e10cSrcweir 
871cdf0e10cSrcweir     // =============================================================================
872cdf0e10cSrcweir     // XMLOasisBasicImporter
873cdf0e10cSrcweir     // =============================================================================
874cdf0e10cSrcweir 
XMLOasisBasicImporter(const Reference<XComponentContext> & rxContext)875cdf0e10cSrcweir     XMLOasisBasicImporter::XMLOasisBasicImporter( const Reference< XComponentContext >& rxContext )
876cdf0e10cSrcweir         :XMLBasicImporterBase( rxContext, sal_True )
877cdf0e10cSrcweir     {
878cdf0e10cSrcweir     }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir     // -----------------------------------------------------------------------------
881cdf0e10cSrcweir 
~XMLOasisBasicImporter()882cdf0e10cSrcweir     XMLOasisBasicImporter::~XMLOasisBasicImporter()
883cdf0e10cSrcweir     {
884cdf0e10cSrcweir     }
885cdf0e10cSrcweir 
886cdf0e10cSrcweir     // -----------------------------------------------------------------------------
887cdf0e10cSrcweir     // XServiceInfo
888cdf0e10cSrcweir     // -----------------------------------------------------------------------------
889cdf0e10cSrcweir 
getImplementationName()890cdf0e10cSrcweir     ::rtl::OUString XMLOasisBasicImporter::getImplementationName(  ) throw (RuntimeException)
891cdf0e10cSrcweir     {
892cdf0e10cSrcweir         return getImplementationName_XMLOasisBasicImporter();
893cdf0e10cSrcweir     }
894cdf0e10cSrcweir 
895cdf0e10cSrcweir     // -----------------------------------------------------------------------------
896cdf0e10cSrcweir 
getSupportedServiceNames()897cdf0e10cSrcweir     Sequence< ::rtl::OUString > XMLOasisBasicImporter::getSupportedServiceNames(  ) throw (RuntimeException)
898cdf0e10cSrcweir     {
899cdf0e10cSrcweir         return getSupportedServiceNames_XMLOasisBasicImporter();
900cdf0e10cSrcweir     }
901cdf0e10cSrcweir 
902cdf0e10cSrcweir 
903cdf0e10cSrcweir     // =============================================================================
904cdf0e10cSrcweir     // component operations
905cdf0e10cSrcweir     // =============================================================================
906cdf0e10cSrcweir 
create_XMLBasicImporter(Reference<XComponentContext> const & xContext)907cdf0e10cSrcweir     Reference< XInterface > SAL_CALL create_XMLBasicImporter(
908cdf0e10cSrcweir         Reference< XComponentContext > const & xContext )
909cdf0e10cSrcweir         SAL_THROW( () )
910cdf0e10cSrcweir     {
911cdf0e10cSrcweir         return static_cast< lang::XTypeProvider * >( new XMLBasicImporter( xContext ) );
912cdf0e10cSrcweir     }
913cdf0e10cSrcweir 
914cdf0e10cSrcweir     // -----------------------------------------------------------------------------
915cdf0e10cSrcweir 
create_XMLOasisBasicImporter(Reference<XComponentContext> const & xContext)916cdf0e10cSrcweir     Reference< XInterface > SAL_CALL create_XMLOasisBasicImporter(
917cdf0e10cSrcweir         Reference< XComponentContext > const & xContext )
918cdf0e10cSrcweir         SAL_THROW( () )
919cdf0e10cSrcweir     {
920cdf0e10cSrcweir         return static_cast< lang::XTypeProvider * >( new XMLOasisBasicImporter( xContext ) );
921cdf0e10cSrcweir     }
922cdf0e10cSrcweir 
923cdf0e10cSrcweir     // -----------------------------------------------------------------------------
924cdf0e10cSrcweir 
925cdf0e10cSrcweir //.........................................................................
926cdf0e10cSrcweir }	// namespace xmlscript
927cdf0e10cSrcweir //.........................................................................
928