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