1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlbas_import.cxx,v $
10 * $Revision: 1.6.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmlscript.hxx"
33 #include "xmlbas_import.hxx"
34 #include "xmlscript/xmlns.h"
35 #include "xmlscript/xml_helper.hxx"
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
38 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
39 #include <com/sun/star/document/XEmbeddedScripts.hpp>
40 #include <cppuhelper/implementationentry.hxx>
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::uno
;
47 //.........................................................................
50 //.........................................................................
52 // =============================================================================
54 // =============================================================================
56 BasicElementBase::BasicElementBase( const ::rtl::OUString
& rLocalName
,
57 const Reference
< xml::input::XAttributes
>& xAttributes
,
58 BasicElementBase
* pParent
, BasicImport
* pImport
)
61 ,m_aLocalName( rLocalName
)
62 ,m_xAttributes( xAttributes
)
70 // -----------------------------------------------------------------------------
72 BasicElementBase::~BasicElementBase()
80 // -----------------------------------------------------------------------------
82 bool BasicElementBase::getBoolAttr( sal_Bool
* pRet
, const ::rtl::OUString
& rAttrName
,
83 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::input::XAttributes
>& xAttributes
,
86 if ( xAttributes
.is() )
88 ::rtl::OUString
aValue( xAttributes
->getValueByUidName( nUid
, rAttrName
) );
89 if ( aValue
.getLength() )
91 if ( aValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "true" ) ) )
96 else if ( aValue
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "false" ) ) )
103 throw xml::sax::SAXException(
104 rAttrName
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": no boolean value (true|false)!" ) ),
105 Reference
< XInterface
>(), Any() );
112 // -----------------------------------------------------------------------------
114 // -----------------------------------------------------------------------------
116 Reference
< xml::input::XElement
> BasicElementBase::getParent()
117 throw (RuntimeException
)
119 return static_cast< xml::input::XElement
* >( m_pParent
);
122 // -----------------------------------------------------------------------------
124 ::rtl::OUString
BasicElementBase::getLocalName()
125 throw (RuntimeException
)
130 // -----------------------------------------------------------------------------
132 sal_Int32
BasicElementBase::getUid()
133 throw (RuntimeException
)
137 nId
= m_pImport
->XMLNS_UID
;
141 // -----------------------------------------------------------------------------
143 Reference
< xml::input::XAttributes
> BasicElementBase::getAttributes()
144 throw (RuntimeException
)
146 return m_xAttributes
;
149 // -----------------------------------------------------------------------------
151 Reference
< xml::input::XElement
> BasicElementBase::startChildElement(
152 sal_Int32
/*nUid*/, const ::rtl::OUString
& /*rLocalName*/,
153 const Reference
< xml::input::XAttributes
>& /*xAttributes*/ )
154 throw (xml::sax::SAXException
, RuntimeException
)
156 throw xml::sax::SAXException(
157 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unexpected element!" ) ),
158 Reference
< XInterface
>(), Any() );
161 // -----------------------------------------------------------------------------
163 void BasicElementBase::characters( const ::rtl::OUString
& /*rChars*/ )
164 throw (xml::sax::SAXException
, RuntimeException
)
166 // not used, all characters ignored
169 // -----------------------------------------------------------------------------
171 void BasicElementBase::ignorableWhitespace( const ::rtl::OUString
& /*rWhitespaces*/ )
172 throw (xml::sax::SAXException
, RuntimeException
)
176 // -----------------------------------------------------------------------------
178 void BasicElementBase::processingInstruction( const ::rtl::OUString
& /*rTarget*/, const ::rtl::OUString
& /*rData*/ )
179 throw (xml::sax::SAXException
, RuntimeException
)
183 // -----------------------------------------------------------------------------
185 void BasicElementBase::endElement()
186 throw (xml::sax::SAXException
, RuntimeException
)
191 // =============================================================================
192 // BasicLibrariesElement
193 // =============================================================================
195 BasicLibrariesElement::BasicLibrariesElement( const ::rtl::OUString
& rLocalName
,
196 const Reference
< xml::input::XAttributes
>& xAttributes
,
197 BasicElementBase
* pParent
, BasicImport
* pImport
,
198 const Reference
< script::XLibraryContainer2
>& rxLibContainer
)
199 :BasicElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
200 ,m_xLibContainer( rxLibContainer
)
204 // -----------------------------------------------------------------------------
206 // -----------------------------------------------------------------------------
208 Reference
< xml::input::XElement
> BasicLibrariesElement::startChildElement(
209 sal_Int32 nUid
, const ::rtl::OUString
& rLocalName
,
210 const Reference
< xml::input::XAttributes
>& xAttributes
)
211 throw (xml::sax::SAXException
, RuntimeException
)
213 Reference
< xml::input::XElement
> xElement
;
215 if ( nUid
!= m_pImport
->XMLNS_UID
)
217 throw xml::sax::SAXException(
218 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
219 Reference
< XInterface
>(), Any() );
221 else if ( rLocalName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "library-linked" ) ) )
223 if ( xAttributes
.is() )
225 ::rtl::OUString aName
= xAttributes
->getValueByUidName(
226 m_pImport
->XMLNS_UID
,
227 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
229 ::rtl::OUString aStorageURL
= xAttributes
->getValueByUidName(
230 m_pImport
->XMLNS_XLINK_UID
,
231 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "href" ) ) );
233 sal_Bool bReadOnly
= sal_False
;
234 getBoolAttr( &bReadOnly
,
235 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "readonly" ) ),
236 xAttributes
, m_pImport
->XMLNS_UID
);
238 if ( m_xLibContainer
.is() )
242 Reference
< container::XNameAccess
> xLib(
243 m_xLibContainer
->createLibraryLink( aName
, aStorageURL
, bReadOnly
) );
245 xElement
.set( new BasicElementBase( rLocalName
, xAttributes
, this, m_pImport
) );
247 catch ( container::ElementExistException
& e
)
249 OSL_TRACE( "BasicLibrariesElement::startChildElement: caught ElementExceptionExist reason %s",
250 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
252 catch ( lang::IllegalArgumentException
& e
)
254 OSL_TRACE( "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason %s",
255 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
260 else if ( rLocalName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "library-embedded" ) ) )
262 // TODO: create password protected libraries
264 if ( xAttributes
.is() )
266 ::rtl::OUString aName
= xAttributes
->getValueByUidName(
267 m_pImport
->XMLNS_UID
,
268 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
270 sal_Bool bReadOnly
= sal_False
;
271 getBoolAttr( &bReadOnly
,
272 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "readonly" ) ),
273 xAttributes
, m_pImport
->XMLNS_UID
);
275 if ( m_xLibContainer
.is() )
279 Reference
< container::XNameContainer
> xLib
;
280 if ( m_xLibContainer
->hasByName( aName
) )
283 m_xLibContainer
->getByName( aName
) >>= xLib
;
287 xLib
.set( m_xLibContainer
->createLibrary( aName
) );
291 xElement
.set( new BasicEmbeddedLibraryElement( rLocalName
, xAttributes
, this, m_pImport
, m_xLibContainer
, aName
, bReadOnly
) );
293 catch ( lang::IllegalArgumentException
& e
)
295 OSL_TRACE( "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason %s",
296 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
303 throw xml::sax::SAXException(
304 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected library-linked or library-embedded element!" ) ),
305 Reference
< XInterface
>(), Any() );
311 // -----------------------------------------------------------------------------
313 void BasicLibrariesElement::endElement()
314 throw (xml::sax::SAXException
, RuntimeException
)
319 // =============================================================================
320 // BasicEmbeddedLibraryElement
321 // =============================================================================
323 BasicEmbeddedLibraryElement::BasicEmbeddedLibraryElement( const ::rtl::OUString
& rLocalName
,
324 const Reference
< xml::input::XAttributes
>& xAttributes
,
325 BasicElementBase
* pParent
, BasicImport
* pImport
,
326 const Reference
< script::XLibraryContainer2
>& rxLibContainer
,
327 const ::rtl::OUString
& rLibName
, bool bReadOnly
)
328 :BasicElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
329 ,m_xLibContainer( rxLibContainer
)
330 ,m_aLibName( rLibName
)
331 ,m_bReadOnly( bReadOnly
)
335 if ( m_xLibContainer
.is() && m_xLibContainer
->hasByName( m_aLibName
) )
336 m_xLibContainer
->getByName( m_aLibName
) >>= m_xLib
;
338 catch ( lang::WrappedTargetException
& e
)
340 OSL_TRACE( "BasicEmbeddedLibraryElement CTOR: caught WrappedTargetException reason %s",
341 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
345 // -----------------------------------------------------------------------------
347 // -----------------------------------------------------------------------------
349 Reference
< xml::input::XElement
> BasicEmbeddedLibraryElement::startChildElement(
350 sal_Int32 nUid
, const ::rtl::OUString
& rLocalName
,
351 const Reference
< xml::input::XAttributes
>& xAttributes
)
352 throw (xml::sax::SAXException
, RuntimeException
)
354 Reference
< xml::input::XElement
> xElement
;
356 if ( nUid
!= m_pImport
->XMLNS_UID
)
358 throw xml::sax::SAXException(
359 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
360 Reference
< XInterface
>(), Any() );
362 else if ( rLocalName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "module" ) ) )
364 if ( xAttributes
.is() )
366 ::rtl::OUString aName
= xAttributes
->getValueByUidName(
367 m_pImport
->XMLNS_UID
,
368 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
370 if ( m_xLib
.is() && aName
.getLength() )
371 xElement
.set( new BasicModuleElement( rLocalName
, xAttributes
, this, m_pImport
, m_xLib
, aName
) );
376 throw xml::sax::SAXException(
377 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected module element!" ) ),
378 Reference
< XInterface
>(), Any() );
384 // -----------------------------------------------------------------------------
386 void BasicEmbeddedLibraryElement::endElement()
387 throw (xml::sax::SAXException
, RuntimeException
)
389 if ( m_xLibContainer
.is() && m_xLibContainer
->hasByName( m_aLibName
) && m_bReadOnly
)
390 m_xLibContainer
->setLibraryReadOnly( m_aLibName
, m_bReadOnly
);
394 // =============================================================================
395 // BasicModuleElement
396 // =============================================================================
398 BasicModuleElement::BasicModuleElement( const ::rtl::OUString
& rLocalName
,
399 const Reference
< xml::input::XAttributes
>& xAttributes
,
400 BasicElementBase
* pParent
, BasicImport
* pImport
,
401 const Reference
< container::XNameContainer
>& rxLib
, const ::rtl::OUString
& rName
)
402 :BasicElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
408 // -----------------------------------------------------------------------------
410 // -----------------------------------------------------------------------------
412 Reference
< xml::input::XElement
> BasicModuleElement::startChildElement(
413 sal_Int32 nUid
, const ::rtl::OUString
& rLocalName
,
414 const Reference
< xml::input::XAttributes
>& xAttributes
)
415 throw (xml::sax::SAXException
, RuntimeException
)
419 Reference
< xml::input::XElement
> xElement
;
421 if ( nUid
!= m_pImport
->XMLNS_UID
)
423 throw xml::sax::SAXException(
424 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
425 Reference
< XInterface
>(), Any() );
427 else if ( rLocalName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "source-code" ) ) )
429 // TODO: password protected libraries
431 if ( xAttributes
.is() )
433 if ( m_xLib
.is() && m_aName
.getLength() )
434 xElement
.set( new BasicSourceCodeElement( rLocalName
, xAttributes
, this, m_pImport
, m_xLib
, m_aName
) );
439 throw xml::sax::SAXException(
440 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected source-code element!" ) ),
441 Reference
< XInterface
>(), Any() );
447 // -----------------------------------------------------------------------------
449 void BasicModuleElement::endElement()
450 throw (xml::sax::SAXException
, RuntimeException
)
455 // =============================================================================
456 // BasicSourceCodeElement
457 // =============================================================================
459 BasicSourceCodeElement::BasicSourceCodeElement( const ::rtl::OUString
& rLocalName
,
460 const Reference
< xml::input::XAttributes
>& xAttributes
,
461 BasicElementBase
* pParent
, BasicImport
* pImport
,
462 const Reference
< container::XNameContainer
>& rxLib
, const ::rtl::OUString
& rName
)
463 :BasicElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
469 // -----------------------------------------------------------------------------
471 // -----------------------------------------------------------------------------
473 void BasicSourceCodeElement::characters( const ::rtl::OUString
& rChars
)
474 throw (xml::sax::SAXException
, RuntimeException
)
476 m_aBuffer
.append( rChars
);
479 // -----------------------------------------------------------------------------
481 void BasicSourceCodeElement::endElement()
482 throw (xml::sax::SAXException
, RuntimeException
)
486 if ( m_xLib
.is() && m_aName
.getLength() )
489 aElement
<<= m_aBuffer
.makeStringAndClear();
490 m_xLib
->insertByName( m_aName
, aElement
);
493 catch ( container::ElementExistException
& e
)
495 OSL_TRACE( "BasicSourceCodeElement::endElement: caught ElementExceptionExist reason %s",
496 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
498 catch ( lang::IllegalArgumentException
& e
)
500 OSL_TRACE( "BasicSourceCodeElement::endElement: caught IllegalArgumentException reason %s",
501 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
503 catch ( lang::WrappedTargetException
& e
)
505 OSL_TRACE( "BasicSourceCodeElement::endElement: caught WrappedTargetException reason %s",
506 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
511 // =============================================================================
513 // =============================================================================
515 BasicImport::BasicImport( const Reference
< frame::XModel
>& rxModel
, sal_Bool bOasis
)
521 // -----------------------------------------------------------------------------
523 BasicImport::~BasicImport()
527 // -----------------------------------------------------------------------------
529 // -----------------------------------------------------------------------------
531 void BasicImport::startDocument( const Reference
< xml::input::XNamespaceMapping
>& xNamespaceMapping
)
532 throw (xml::sax::SAXException
, RuntimeException
)
534 if ( xNamespaceMapping
.is() )
536 ::rtl::OUString aURI
;
538 aURI
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_OOO_URI
) );
540 aURI
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_SCRIPT_URI
) );
541 XMLNS_UID
= xNamespaceMapping
->getUidByUri( aURI
);
542 XMLNS_XLINK_UID
= xNamespaceMapping
->getUidByUri( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_URI
) ) );
546 // -----------------------------------------------------------------------------
548 void BasicImport::endDocument()
549 throw (xml::sax::SAXException
, RuntimeException
)
553 // -----------------------------------------------------------------------------
555 void BasicImport::processingInstruction( const ::rtl::OUString
& /*rTarget*/, const ::rtl::OUString
& /*rData*/ )
556 throw (xml::sax::SAXException
, RuntimeException
)
560 // -----------------------------------------------------------------------------
562 void BasicImport::setDocumentLocator( const Reference
< xml::sax::XLocator
>& /*xLocator*/ )
563 throw (xml::sax::SAXException
, RuntimeException
)
567 // -----------------------------------------------------------------------------
569 Reference
< xml::input::XElement
> BasicImport::startRootElement( sal_Int32 nUid
, const ::rtl::OUString
& rLocalName
,
570 Reference
< xml::input::XAttributes
> const & xAttributes
)
571 throw (xml::sax::SAXException
, RuntimeException
)
573 Reference
< xml::input::XElement
> xElement
;
575 if ( nUid
!= XMLNS_UID
)
577 throw xml::sax::SAXException(
578 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
579 Reference
< XInterface
>(), Any() );
581 else if ( rLocalName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "libraries" ) ) )
583 Reference
< script::XLibraryContainer2
> xLibContainer
;
585 // try the XEmbeddedScripts interface
586 Reference
< document::XEmbeddedScripts
> xDocumentScripts( m_xModel
, UNO_QUERY
);
587 if ( xDocumentScripts
.is() )
588 xLibContainer
.set( xDocumentScripts
->getBasicLibraries().get() );
590 if ( !xLibContainer
.is() )
592 // try the "BasicLibraries" property (old-style, for compatibility)
593 Reference
< beans::XPropertySet
> xPSet( m_xModel
, UNO_QUERY
);
595 xPSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ) >>= xLibContainer
;
598 OSL_ENSURE( xLibContainer
.is(), "BasicImport::startRootElement: nowhere to import to!" );
600 if ( xLibContainer
.is() )
602 xElement
.set( new BasicLibrariesElement( rLocalName
, xAttributes
, 0, this, xLibContainer
) );
607 throw xml::sax::SAXException(
608 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal root element (expected libraries) given: " ) ) +
609 rLocalName
, Reference
< XInterface
>(), Any() );
616 // =============================================================================
617 // component operations
618 // =============================================================================
620 ::rtl::OUString
getImplementationName_XMLBasicImporter()
622 static ::rtl::OUString
* pImplName
= 0;
625 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
628 static ::rtl::OUString
aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLBasicImporter" ) );
629 pImplName
= &aImplName
;
635 // -----------------------------------------------------------------------------
637 Sequence
< ::rtl::OUString
> getSupportedServiceNames_XMLBasicImporter()
639 static Sequence
< ::rtl::OUString
>* pNames
= 0;
642 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
645 static Sequence
< ::rtl::OUString
> aNames(1);
646 aNames
.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLBasicImporter" ) );
653 // -----------------------------------------------------------------------------
655 ::rtl::OUString
getImplementationName_XMLOasisBasicImporter()
657 static ::rtl::OUString
* pImplName
= 0;
660 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
663 static ::rtl::OUString
aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLOasisBasicImporter" ) );
664 pImplName
= &aImplName
;
670 // -----------------------------------------------------------------------------
672 Sequence
< ::rtl::OUString
> getSupportedServiceNames_XMLOasisBasicImporter()
674 static Sequence
< ::rtl::OUString
>* pNames
= 0;
677 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
680 static Sequence
< ::rtl::OUString
> aNames(1);
681 aNames
.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicImporter" ) );
689 // =============================================================================
690 // XMLBasicImporterBase
691 // =============================================================================
693 XMLBasicImporterBase::XMLBasicImporterBase( const Reference
< XComponentContext
>& rxContext
, sal_Bool bOasis
)
694 :m_xContext( rxContext
)
699 // -----------------------------------------------------------------------------
701 XMLBasicImporterBase::~XMLBasicImporterBase()
705 // -----------------------------------------------------------------------------
707 // -----------------------------------------------------------------------------
709 sal_Bool
XMLBasicImporterBase::supportsService( const ::rtl::OUString
& rServiceName
) throw (RuntimeException
)
711 Sequence
< ::rtl::OUString
> aNames( getSupportedServiceNames() );
712 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
713 const ::rtl::OUString
* pEnd
= pNames
+ aNames
.getLength();
714 for ( ; pNames
!= pEnd
&& !pNames
->equals( rServiceName
); ++pNames
)
717 return pNames
!= pEnd
;
720 // -----------------------------------------------------------------------------
722 // -----------------------------------------------------------------------------
724 void XMLBasicImporterBase::setTargetDocument( const Reference
< XComponent
>& rxDoc
)
725 throw (IllegalArgumentException
, RuntimeException
)
727 ::osl::MutexGuard
aGuard( m_aMutex
);
729 m_xModel
.set( rxDoc
, UNO_QUERY
);
731 if ( !m_xModel
.is() )
733 throw IllegalArgumentException(
734 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLBasicExporter::setTargetDocument: no document model!" ) ),
735 Reference
< XInterface
>(), 1 );
738 if ( m_xContext
.is() )
740 Reference
< XMultiComponentFactory
> xSMgr( m_xContext
->getServiceManager() );
743 Reference
< xml::input::XRoot
> xRoot( new BasicImport( m_xModel
, m_bOasis
) );
744 Sequence
< Any
> aArgs( 1 );
746 m_xHandler
.set( xSMgr
->createInstanceWithArgumentsAndContext(
747 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.input.SaxDocumentHandler" ) ),
748 aArgs
, m_xContext
), UNO_QUERY
);
753 // -----------------------------------------------------------------------------
755 // -----------------------------------------------------------------------------
757 void XMLBasicImporterBase::startDocument()
758 throw (xml::sax::SAXException
, RuntimeException
)
760 ::osl::MutexGuard
aGuard( m_aMutex
);
762 if ( m_xHandler
.is() )
763 m_xHandler
->startDocument();
766 // -----------------------------------------------------------------------------
768 void XMLBasicImporterBase::endDocument()
769 throw (xml::sax::SAXException
, RuntimeException
)
771 ::osl::MutexGuard
aGuard( m_aMutex
);
773 if ( m_xHandler
.is() )
774 m_xHandler
->endDocument();
777 // -----------------------------------------------------------------------------
779 void XMLBasicImporterBase::startElement( const ::rtl::OUString
& aName
,
780 const Reference
< xml::sax::XAttributeList
>& xAttribs
)
781 throw (xml::sax::SAXException
, RuntimeException
)
783 ::osl::MutexGuard
aGuard( m_aMutex
);
785 if ( m_xHandler
.is() )
786 m_xHandler
->startElement( aName
, xAttribs
);
789 // -----------------------------------------------------------------------------
791 void XMLBasicImporterBase::endElement( const ::rtl::OUString
& aName
)
792 throw (xml::sax::SAXException
, RuntimeException
)
794 ::osl::MutexGuard
aGuard( m_aMutex
);
796 if ( m_xHandler
.is() )
797 m_xHandler
->endElement( aName
);
800 // -----------------------------------------------------------------------------
802 void XMLBasicImporterBase::characters( const ::rtl::OUString
& aChars
)
803 throw (xml::sax::SAXException
, RuntimeException
)
805 ::osl::MutexGuard
aGuard( m_aMutex
);
807 if ( m_xHandler
.is() )
808 m_xHandler
->characters( aChars
);
811 // -----------------------------------------------------------------------------
813 void XMLBasicImporterBase::ignorableWhitespace( const ::rtl::OUString
& aWhitespaces
)
814 throw (xml::sax::SAXException
, RuntimeException
)
816 ::osl::MutexGuard
aGuard( m_aMutex
);
818 if ( m_xHandler
.is() )
819 m_xHandler
->ignorableWhitespace( aWhitespaces
);
822 // -----------------------------------------------------------------------------
824 void XMLBasicImporterBase::processingInstruction( const ::rtl::OUString
& aTarget
,
825 const ::rtl::OUString
& aData
)
826 throw (xml::sax::SAXException
, RuntimeException
)
828 ::osl::MutexGuard
aGuard( m_aMutex
);
830 if ( m_xHandler
.is() )
831 m_xHandler
->processingInstruction( aTarget
, aData
);
834 // -----------------------------------------------------------------------------
836 void XMLBasicImporterBase::setDocumentLocator( const Reference
< xml::sax::XLocator
>& xLocator
)
837 throw (xml::sax::SAXException
, RuntimeException
)
839 ::osl::MutexGuard
aGuard( m_aMutex
);
841 if ( m_xHandler
.is() )
842 m_xHandler
->setDocumentLocator( xLocator
);
846 // =============================================================================
848 // =============================================================================
850 XMLBasicImporter::XMLBasicImporter( const Reference
< XComponentContext
>& rxContext
)
851 :XMLBasicImporterBase( rxContext
, sal_False
)
855 // -----------------------------------------------------------------------------
857 XMLBasicImporter::~XMLBasicImporter()
861 // -----------------------------------------------------------------------------
863 // -----------------------------------------------------------------------------
865 ::rtl::OUString
XMLBasicImporter::getImplementationName( ) throw (RuntimeException
)
867 return getImplementationName_XMLBasicImporter();
870 // -----------------------------------------------------------------------------
872 Sequence
< ::rtl::OUString
> XMLBasicImporter::getSupportedServiceNames( ) throw (RuntimeException
)
874 return getSupportedServiceNames_XMLBasicImporter();
878 // =============================================================================
879 // XMLOasisBasicImporter
880 // =============================================================================
882 XMLOasisBasicImporter::XMLOasisBasicImporter( const Reference
< XComponentContext
>& rxContext
)
883 :XMLBasicImporterBase( rxContext
, sal_True
)
887 // -----------------------------------------------------------------------------
889 XMLOasisBasicImporter::~XMLOasisBasicImporter()
893 // -----------------------------------------------------------------------------
895 // -----------------------------------------------------------------------------
897 ::rtl::OUString
XMLOasisBasicImporter::getImplementationName( ) throw (RuntimeException
)
899 return getImplementationName_XMLOasisBasicImporter();
902 // -----------------------------------------------------------------------------
904 Sequence
< ::rtl::OUString
> XMLOasisBasicImporter::getSupportedServiceNames( ) throw (RuntimeException
)
906 return getSupportedServiceNames_XMLOasisBasicImporter();
910 // =============================================================================
911 // component operations
912 // =============================================================================
914 Reference
< XInterface
> SAL_CALL
create_XMLBasicImporter(
915 Reference
< XComponentContext
> const & xContext
)
918 return static_cast< lang::XTypeProvider
* >( new XMLBasicImporter( xContext
) );
921 // -----------------------------------------------------------------------------
923 Reference
< XInterface
> SAL_CALL
create_XMLOasisBasicImporter(
924 Reference
< XComponentContext
> const & xContext
)
927 return static_cast< lang::XTypeProvider
* >( new XMLOasisBasicImporter( xContext
) );
930 // -----------------------------------------------------------------------------
932 //.........................................................................
933 } // namespace xmlscript
934 //.........................................................................