1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "xmlbas_import.hxx"
30 #include "xmlscript/xmlns.h"
31 #include "xmlscript/xml_helper.hxx"
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
34 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
35 #include <com/sun/star/document/XEmbeddedScripts.hpp>
36 #include <cppuhelper/implementationentry.hxx>
38 using namespace ::com::sun::star
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::uno
;
43 //.........................................................................
46 //.........................................................................
48 // =============================================================================
50 // =============================================================================
52 BasicElementBase::BasicElementBase( const ::rtl::OUString
& rLocalName
,
53 const Reference
< xml::input::XAttributes
>& xAttributes
,
54 BasicElementBase
* pParent
, BasicImport
* pImport
)
57 ,m_aLocalName( rLocalName
)
58 ,m_xAttributes( xAttributes
)
66 // -----------------------------------------------------------------------------
68 BasicElementBase::~BasicElementBase()
76 // -----------------------------------------------------------------------------
78 bool BasicElementBase::getBoolAttr( sal_Bool
* pRet
, const ::rtl::OUString
& rAttrName
,
79 const ::com::sun::star::uno::Reference
< ::com::sun::star::xml::input::XAttributes
>& xAttributes
,
82 if ( xAttributes
.is() )
84 ::rtl::OUString
aValue( xAttributes
->getValueByUidName( nUid
, rAttrName
) );
85 if ( !aValue
.isEmpty() )
87 if ( aValue
== "true" )
92 else if ( aValue
== "false" )
99 throw xml::sax::SAXException(
100 rAttrName
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": no boolean value (true|false)!" ) ),
101 Reference
< XInterface
>(), Any() );
108 // -----------------------------------------------------------------------------
110 // -----------------------------------------------------------------------------
112 Reference
< xml::input::XElement
> BasicElementBase::getParent()
113 throw (RuntimeException
)
115 return static_cast< xml::input::XElement
* >( m_pParent
);
118 // -----------------------------------------------------------------------------
120 ::rtl::OUString
BasicElementBase::getLocalName()
121 throw (RuntimeException
)
126 // -----------------------------------------------------------------------------
128 sal_Int32
BasicElementBase::getUid()
129 throw (RuntimeException
)
133 nId
= m_pImport
->XMLNS_UID
;
137 // -----------------------------------------------------------------------------
139 Reference
< xml::input::XAttributes
> BasicElementBase::getAttributes()
140 throw (RuntimeException
)
142 return m_xAttributes
;
145 // -----------------------------------------------------------------------------
147 Reference
< xml::input::XElement
> BasicElementBase::startChildElement(
148 sal_Int32
/*nUid*/, const ::rtl::OUString
& /*rLocalName*/,
149 const Reference
< xml::input::XAttributes
>& /*xAttributes*/ )
150 throw (xml::sax::SAXException
, RuntimeException
)
152 throw xml::sax::SAXException(
153 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unexpected element!" ) ),
154 Reference
< XInterface
>(), Any() );
157 // -----------------------------------------------------------------------------
159 void BasicElementBase::characters( const ::rtl::OUString
& /*rChars*/ )
160 throw (xml::sax::SAXException
, RuntimeException
)
162 // not used, all characters ignored
165 // -----------------------------------------------------------------------------
167 void BasicElementBase::ignorableWhitespace( const ::rtl::OUString
& /*rWhitespaces*/ )
168 throw (xml::sax::SAXException
, RuntimeException
)
172 // -----------------------------------------------------------------------------
174 void BasicElementBase::processingInstruction( const ::rtl::OUString
& /*rTarget*/, const ::rtl::OUString
& /*rData*/ )
175 throw (xml::sax::SAXException
, RuntimeException
)
179 // -----------------------------------------------------------------------------
181 void BasicElementBase::endElement()
182 throw (xml::sax::SAXException
, RuntimeException
)
187 // =============================================================================
188 // BasicLibrariesElement
189 // =============================================================================
191 BasicLibrariesElement::BasicLibrariesElement( const ::rtl::OUString
& rLocalName
,
192 const Reference
< xml::input::XAttributes
>& xAttributes
,
193 BasicElementBase
* pParent
, BasicImport
* pImport
,
194 const Reference
< script::XLibraryContainer2
>& rxLibContainer
)
195 :BasicElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
196 ,m_xLibContainer( rxLibContainer
)
200 // -----------------------------------------------------------------------------
202 // -----------------------------------------------------------------------------
204 Reference
< xml::input::XElement
> BasicLibrariesElement::startChildElement(
205 sal_Int32 nUid
, const ::rtl::OUString
& rLocalName
,
206 const Reference
< xml::input::XAttributes
>& xAttributes
)
207 throw (xml::sax::SAXException
, RuntimeException
)
209 Reference
< xml::input::XElement
> xElement
;
211 if ( nUid
!= m_pImport
->XMLNS_UID
)
213 throw xml::sax::SAXException(
214 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
215 Reference
< XInterface
>(), Any() );
217 else if ( rLocalName
== "library-linked" )
219 if ( xAttributes
.is() )
221 ::rtl::OUString aName
= xAttributes
->getValueByUidName(
222 m_pImport
->XMLNS_UID
,
223 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
225 ::rtl::OUString aStorageURL
= xAttributes
->getValueByUidName(
226 m_pImport
->XMLNS_XLINK_UID
,
227 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "href" ) ) );
229 sal_Bool bReadOnly
= sal_False
;
230 getBoolAttr( &bReadOnly
,
231 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "readonly" ) ),
232 xAttributes
, m_pImport
->XMLNS_UID
);
234 if ( m_xLibContainer
.is() )
238 Reference
< container::XNameAccess
> xLib(
239 m_xLibContainer
->createLibraryLink( aName
, aStorageURL
, bReadOnly
) );
241 xElement
.set( new BasicElementBase( rLocalName
, xAttributes
, this, m_pImport
) );
243 catch ( const container::ElementExistException
& e
)
245 OSL_TRACE( "BasicLibrariesElement::startChildElement: caught ElementExceptionExist reason %s",
246 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
248 catch ( const lang::IllegalArgumentException
& e
)
250 OSL_TRACE( "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason %s",
251 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
256 else if ( rLocalName
== "library-embedded" )
258 // TODO: create password protected libraries
260 if ( xAttributes
.is() )
262 ::rtl::OUString aName
= xAttributes
->getValueByUidName(
263 m_pImport
->XMLNS_UID
,
264 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
266 sal_Bool bReadOnly
= sal_False
;
267 getBoolAttr( &bReadOnly
,
268 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "readonly" ) ),
269 xAttributes
, m_pImport
->XMLNS_UID
);
271 if ( m_xLibContainer
.is() )
275 Reference
< container::XNameContainer
> xLib
;
276 if ( m_xLibContainer
->hasByName( aName
) )
279 m_xLibContainer
->getByName( aName
) >>= xLib
;
283 xLib
.set( m_xLibContainer
->createLibrary( aName
) );
287 xElement
.set( new BasicEmbeddedLibraryElement( rLocalName
, xAttributes
, this, m_pImport
, m_xLibContainer
, aName
, bReadOnly
) );
289 catch ( const lang::IllegalArgumentException
& e
)
291 OSL_TRACE( "BasicLibrariesElement::startChildElement: caught IllegalArgumentException reason %s",
292 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
299 throw xml::sax::SAXException(
300 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected library-linked or library-embedded element!" ) ),
301 Reference
< XInterface
>(), Any() );
307 // -----------------------------------------------------------------------------
309 void BasicLibrariesElement::endElement()
310 throw (xml::sax::SAXException
, RuntimeException
)
315 // =============================================================================
316 // BasicEmbeddedLibraryElement
317 // =============================================================================
319 BasicEmbeddedLibraryElement::BasicEmbeddedLibraryElement( const ::rtl::OUString
& rLocalName
,
320 const Reference
< xml::input::XAttributes
>& xAttributes
,
321 BasicElementBase
* pParent
, BasicImport
* pImport
,
322 const Reference
< script::XLibraryContainer2
>& rxLibContainer
,
323 const ::rtl::OUString
& rLibName
, bool bReadOnly
)
324 :BasicElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
325 ,m_xLibContainer( rxLibContainer
)
326 ,m_aLibName( rLibName
)
327 ,m_bReadOnly( bReadOnly
)
331 if ( m_xLibContainer
.is() && m_xLibContainer
->hasByName( m_aLibName
) )
332 m_xLibContainer
->getByName( m_aLibName
) >>= m_xLib
;
334 catch ( const lang::WrappedTargetException
& e
)
336 OSL_TRACE( "BasicEmbeddedLibraryElement CTOR: caught WrappedTargetException reason %s",
337 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
341 // -----------------------------------------------------------------------------
343 // -----------------------------------------------------------------------------
345 Reference
< xml::input::XElement
> BasicEmbeddedLibraryElement::startChildElement(
346 sal_Int32 nUid
, const ::rtl::OUString
& rLocalName
,
347 const Reference
< xml::input::XAttributes
>& xAttributes
)
348 throw (xml::sax::SAXException
, RuntimeException
)
350 Reference
< xml::input::XElement
> xElement
;
352 if ( nUid
!= m_pImport
->XMLNS_UID
)
354 throw xml::sax::SAXException(
355 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
356 Reference
< XInterface
>(), Any() );
358 else if ( rLocalName
== "module" )
360 if ( xAttributes
.is() )
362 ::rtl::OUString aName
= xAttributes
->getValueByUidName(
363 m_pImport
->XMLNS_UID
,
364 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "name" ) ) );
366 if ( m_xLib
.is() && !aName
.isEmpty() )
367 xElement
.set( new BasicModuleElement( rLocalName
, xAttributes
, this, m_pImport
, m_xLib
, aName
) );
372 throw xml::sax::SAXException(
373 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected module element!" ) ),
374 Reference
< XInterface
>(), Any() );
380 // -----------------------------------------------------------------------------
382 void BasicEmbeddedLibraryElement::endElement()
383 throw (xml::sax::SAXException
, RuntimeException
)
385 if ( m_xLibContainer
.is() && m_xLibContainer
->hasByName( m_aLibName
) && m_bReadOnly
)
386 m_xLibContainer
->setLibraryReadOnly( m_aLibName
, m_bReadOnly
);
390 // =============================================================================
391 // BasicModuleElement
392 // =============================================================================
394 BasicModuleElement::BasicModuleElement( const ::rtl::OUString
& rLocalName
,
395 const Reference
< xml::input::XAttributes
>& xAttributes
,
396 BasicElementBase
* pParent
, BasicImport
* pImport
,
397 const Reference
< container::XNameContainer
>& rxLib
, const ::rtl::OUString
& rName
)
398 :BasicElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
404 // -----------------------------------------------------------------------------
406 // -----------------------------------------------------------------------------
408 Reference
< xml::input::XElement
> BasicModuleElement::startChildElement(
409 sal_Int32 nUid
, const ::rtl::OUString
& rLocalName
,
410 const Reference
< xml::input::XAttributes
>& xAttributes
)
411 throw (xml::sax::SAXException
, RuntimeException
)
415 Reference
< xml::input::XElement
> xElement
;
417 if ( nUid
!= m_pImport
->XMLNS_UID
)
419 throw xml::sax::SAXException(
420 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
421 Reference
< XInterface
>(), Any() );
423 else if ( rLocalName
== "source-code" )
425 // TODO: password protected libraries
427 if ( xAttributes
.is() )
429 if ( m_xLib
.is() && !m_aName
.isEmpty() )
430 xElement
.set( new BasicSourceCodeElement( rLocalName
, xAttributes
, this, m_pImport
, m_xLib
, m_aName
) );
435 throw xml::sax::SAXException(
436 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "expected source-code element!" ) ),
437 Reference
< XInterface
>(), Any() );
443 // -----------------------------------------------------------------------------
445 void BasicModuleElement::endElement()
446 throw (xml::sax::SAXException
, RuntimeException
)
451 // =============================================================================
452 // BasicSourceCodeElement
453 // =============================================================================
455 BasicSourceCodeElement::BasicSourceCodeElement( const ::rtl::OUString
& rLocalName
,
456 const Reference
< xml::input::XAttributes
>& xAttributes
,
457 BasicElementBase
* pParent
, BasicImport
* pImport
,
458 const Reference
< container::XNameContainer
>& rxLib
, const ::rtl::OUString
& rName
)
459 :BasicElementBase( rLocalName
, xAttributes
, pParent
, pImport
)
465 // -----------------------------------------------------------------------------
467 // -----------------------------------------------------------------------------
469 void BasicSourceCodeElement::characters( const ::rtl::OUString
& rChars
)
470 throw (xml::sax::SAXException
, RuntimeException
)
472 m_aBuffer
.append( rChars
);
475 // -----------------------------------------------------------------------------
477 void BasicSourceCodeElement::endElement()
478 throw (xml::sax::SAXException
, RuntimeException
)
482 if ( m_xLib
.is() && !m_aName
.isEmpty() )
485 aElement
<<= m_aBuffer
.makeStringAndClear();
486 m_xLib
->insertByName( m_aName
, aElement
);
489 catch ( const container::ElementExistException
& e
)
491 OSL_TRACE( "BasicSourceCodeElement::endElement: caught ElementExceptionExist reason %s",
492 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
494 catch ( const lang::IllegalArgumentException
& e
)
496 OSL_TRACE( "BasicSourceCodeElement::endElement: caught IllegalArgumentException reason %s",
497 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
499 catch ( const lang::WrappedTargetException
& e
)
501 OSL_TRACE( "BasicSourceCodeElement::endElement: caught WrappedTargetException reason %s",
502 ::rtl::OUStringToOString( e
.Message
, RTL_TEXTENCODING_ASCII_US
).pData
->buffer
);
507 // =============================================================================
509 // =============================================================================
511 BasicImport::BasicImport( const Reference
< frame::XModel
>& rxModel
, sal_Bool bOasis
)
517 // -----------------------------------------------------------------------------
519 BasicImport::~BasicImport()
523 // -----------------------------------------------------------------------------
525 // -----------------------------------------------------------------------------
527 void BasicImport::startDocument( const Reference
< xml::input::XNamespaceMapping
>& xNamespaceMapping
)
528 throw (xml::sax::SAXException
, RuntimeException
)
530 if ( xNamespaceMapping
.is() )
532 ::rtl::OUString aURI
;
534 aURI
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_OOO_URI
) );
536 aURI
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_SCRIPT_URI
) );
537 XMLNS_UID
= xNamespaceMapping
->getUidByUri( aURI
);
538 XMLNS_XLINK_UID
= xNamespaceMapping
->getUidByUri( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_URI
) ) );
542 // -----------------------------------------------------------------------------
544 void BasicImport::endDocument()
545 throw (xml::sax::SAXException
, RuntimeException
)
549 // -----------------------------------------------------------------------------
551 void BasicImport::processingInstruction( const ::rtl::OUString
& /*rTarget*/, const ::rtl::OUString
& /*rData*/ )
552 throw (xml::sax::SAXException
, RuntimeException
)
556 // -----------------------------------------------------------------------------
558 void BasicImport::setDocumentLocator( const Reference
< xml::sax::XLocator
>& /*xLocator*/ )
559 throw (xml::sax::SAXException
, RuntimeException
)
563 // -----------------------------------------------------------------------------
565 Reference
< xml::input::XElement
> BasicImport::startRootElement( sal_Int32 nUid
, const ::rtl::OUString
& rLocalName
,
566 Reference
< xml::input::XAttributes
> const & xAttributes
)
567 throw (xml::sax::SAXException
, RuntimeException
)
569 Reference
< xml::input::XElement
> xElement
;
571 if ( nUid
!= XMLNS_UID
)
573 throw xml::sax::SAXException(
574 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal namespace!" ) ),
575 Reference
< XInterface
>(), Any() );
577 else if ( rLocalName
== "libraries" )
579 Reference
< script::XLibraryContainer2
> xLibContainer
;
581 // try the XEmbeddedScripts interface
582 Reference
< document::XEmbeddedScripts
> xDocumentScripts( m_xModel
, UNO_QUERY
);
583 if ( xDocumentScripts
.is() )
584 xLibContainer
.set( xDocumentScripts
->getBasicLibraries().get() );
586 if ( !xLibContainer
.is() )
588 // try the "BasicLibraries" property (old-style, for compatibility)
589 Reference
< beans::XPropertySet
> xPSet( m_xModel
, UNO_QUERY
);
591 xPSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ) >>= xLibContainer
;
594 OSL_ENSURE( xLibContainer
.is(), "BasicImport::startRootElement: nowhere to import to!" );
596 if ( xLibContainer
.is() )
598 xElement
.set( new BasicLibrariesElement( rLocalName
, xAttributes
, 0, this, xLibContainer
) );
603 throw xml::sax::SAXException(
604 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "illegal root element (expected libraries) given: " ) ) +
605 rLocalName
, Reference
< XInterface
>(), Any() );
612 // =============================================================================
613 // component operations
614 // =============================================================================
616 ::rtl::OUString
getImplementationName_XMLBasicImporter()
618 static ::rtl::OUString
* pImplName
= 0;
621 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
624 static ::rtl::OUString
aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLBasicImporter" ) );
625 pImplName
= &aImplName
;
631 // -----------------------------------------------------------------------------
633 Sequence
< ::rtl::OUString
> getSupportedServiceNames_XMLBasicImporter()
635 static Sequence
< ::rtl::OUString
>* pNames
= 0;
638 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
641 static Sequence
< ::rtl::OUString
> aNames(1);
642 aNames
.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLBasicImporter" ) );
649 // -----------------------------------------------------------------------------
651 ::rtl::OUString
getImplementationName_XMLOasisBasicImporter()
653 static ::rtl::OUString
* pImplName
= 0;
656 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
659 static ::rtl::OUString
aImplName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.xmlscript.XMLOasisBasicImporter" ) );
660 pImplName
= &aImplName
;
666 // -----------------------------------------------------------------------------
668 Sequence
< ::rtl::OUString
> getSupportedServiceNames_XMLOasisBasicImporter()
670 static Sequence
< ::rtl::OUString
>* pNames
= 0;
673 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
676 static Sequence
< ::rtl::OUString
> aNames(1);
677 aNames
.getArray()[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.XMLOasisBasicImporter" ) );
685 // =============================================================================
686 // XMLBasicImporterBase
687 // =============================================================================
689 XMLBasicImporterBase::XMLBasicImporterBase( const Reference
< XComponentContext
>& rxContext
, sal_Bool bOasis
)
690 :m_xContext( rxContext
)
695 // -----------------------------------------------------------------------------
697 XMLBasicImporterBase::~XMLBasicImporterBase()
701 // -----------------------------------------------------------------------------
703 // -----------------------------------------------------------------------------
705 sal_Bool
XMLBasicImporterBase::supportsService( const ::rtl::OUString
& rServiceName
) throw (RuntimeException
)
707 Sequence
< ::rtl::OUString
> aNames( getSupportedServiceNames() );
708 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
709 const ::rtl::OUString
* pEnd
= pNames
+ aNames
.getLength();
710 for ( ; pNames
!= pEnd
&& !pNames
->equals( rServiceName
); ++pNames
)
713 return pNames
!= pEnd
;
716 // -----------------------------------------------------------------------------
718 // -----------------------------------------------------------------------------
720 void XMLBasicImporterBase::setTargetDocument( const Reference
< XComponent
>& rxDoc
)
721 throw (IllegalArgumentException
, RuntimeException
)
723 ::osl::MutexGuard
aGuard( m_aMutex
);
725 m_xModel
.set( rxDoc
, UNO_QUERY
);
727 if ( !m_xModel
.is() )
729 throw IllegalArgumentException(
730 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XMLBasicExporter::setTargetDocument: no document model!" ) ),
731 Reference
< XInterface
>(), 1 );
734 if ( m_xContext
.is() )
736 Reference
< XMultiComponentFactory
> xSMgr( m_xContext
->getServiceManager() );
739 Reference
< xml::input::XRoot
> xRoot( new BasicImport( m_xModel
, m_bOasis
) );
740 Sequence
< Any
> aArgs( 1 );
742 m_xHandler
.set( xSMgr
->createInstanceWithArgumentsAndContext(
743 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.input.SaxDocumentHandler" ) ),
744 aArgs
, m_xContext
), UNO_QUERY
);
749 // -----------------------------------------------------------------------------
751 // -----------------------------------------------------------------------------
753 void XMLBasicImporterBase::startDocument()
754 throw (xml::sax::SAXException
, RuntimeException
)
756 ::osl::MutexGuard
aGuard( m_aMutex
);
758 if ( m_xHandler
.is() )
759 m_xHandler
->startDocument();
762 // -----------------------------------------------------------------------------
764 void XMLBasicImporterBase::endDocument()
765 throw (xml::sax::SAXException
, RuntimeException
)
767 ::osl::MutexGuard
aGuard( m_aMutex
);
769 if ( m_xHandler
.is() )
770 m_xHandler
->endDocument();
773 // -----------------------------------------------------------------------------
775 void XMLBasicImporterBase::startElement( const ::rtl::OUString
& aName
,
776 const Reference
< xml::sax::XAttributeList
>& xAttribs
)
777 throw (xml::sax::SAXException
, RuntimeException
)
779 ::osl::MutexGuard
aGuard( m_aMutex
);
781 if ( m_xHandler
.is() )
782 m_xHandler
->startElement( aName
, xAttribs
);
785 // -----------------------------------------------------------------------------
787 void XMLBasicImporterBase::endElement( const ::rtl::OUString
& aName
)
788 throw (xml::sax::SAXException
, RuntimeException
)
790 ::osl::MutexGuard
aGuard( m_aMutex
);
792 if ( m_xHandler
.is() )
793 m_xHandler
->endElement( aName
);
796 // -----------------------------------------------------------------------------
798 void XMLBasicImporterBase::characters( const ::rtl::OUString
& aChars
)
799 throw (xml::sax::SAXException
, RuntimeException
)
801 ::osl::MutexGuard
aGuard( m_aMutex
);
803 if ( m_xHandler
.is() )
804 m_xHandler
->characters( aChars
);
807 // -----------------------------------------------------------------------------
809 void XMLBasicImporterBase::ignorableWhitespace( const ::rtl::OUString
& aWhitespaces
)
810 throw (xml::sax::SAXException
, RuntimeException
)
812 ::osl::MutexGuard
aGuard( m_aMutex
);
814 if ( m_xHandler
.is() )
815 m_xHandler
->ignorableWhitespace( aWhitespaces
);
818 // -----------------------------------------------------------------------------
820 void XMLBasicImporterBase::processingInstruction( const ::rtl::OUString
& aTarget
,
821 const ::rtl::OUString
& aData
)
822 throw (xml::sax::SAXException
, RuntimeException
)
824 ::osl::MutexGuard
aGuard( m_aMutex
);
826 if ( m_xHandler
.is() )
827 m_xHandler
->processingInstruction( aTarget
, aData
);
830 // -----------------------------------------------------------------------------
832 void XMLBasicImporterBase::setDocumentLocator( const Reference
< xml::sax::XLocator
>& xLocator
)
833 throw (xml::sax::SAXException
, RuntimeException
)
835 ::osl::MutexGuard
aGuard( m_aMutex
);
837 if ( m_xHandler
.is() )
838 m_xHandler
->setDocumentLocator( xLocator
);
842 // =============================================================================
844 // =============================================================================
846 XMLBasicImporter::XMLBasicImporter( const Reference
< XComponentContext
>& rxContext
)
847 :XMLBasicImporterBase( rxContext
, sal_False
)
851 // -----------------------------------------------------------------------------
853 XMLBasicImporter::~XMLBasicImporter()
857 // -----------------------------------------------------------------------------
859 // -----------------------------------------------------------------------------
861 ::rtl::OUString
XMLBasicImporter::getImplementationName( ) throw (RuntimeException
)
863 return getImplementationName_XMLBasicImporter();
866 // -----------------------------------------------------------------------------
868 Sequence
< ::rtl::OUString
> XMLBasicImporter::getSupportedServiceNames( ) throw (RuntimeException
)
870 return getSupportedServiceNames_XMLBasicImporter();
874 // =============================================================================
875 // XMLOasisBasicImporter
876 // =============================================================================
878 XMLOasisBasicImporter::XMLOasisBasicImporter( const Reference
< XComponentContext
>& rxContext
)
879 :XMLBasicImporterBase( rxContext
, sal_True
)
883 // -----------------------------------------------------------------------------
885 XMLOasisBasicImporter::~XMLOasisBasicImporter()
889 // -----------------------------------------------------------------------------
891 // -----------------------------------------------------------------------------
893 ::rtl::OUString
XMLOasisBasicImporter::getImplementationName( ) throw (RuntimeException
)
895 return getImplementationName_XMLOasisBasicImporter();
898 // -----------------------------------------------------------------------------
900 Sequence
< ::rtl::OUString
> XMLOasisBasicImporter::getSupportedServiceNames( ) throw (RuntimeException
)
902 return getSupportedServiceNames_XMLOasisBasicImporter();
906 // =============================================================================
907 // component operations
908 // =============================================================================
910 Reference
< XInterface
> SAL_CALL
create_XMLBasicImporter(
911 Reference
< XComponentContext
> const & xContext
)
914 return static_cast< lang::XTypeProvider
* >( new XMLBasicImporter( xContext
) );
917 // -----------------------------------------------------------------------------
919 Reference
< XInterface
> SAL_CALL
create_XMLOasisBasicImporter(
920 Reference
< XComponentContext
> const & xContext
)
923 return static_cast< lang::XTypeProvider
* >( new XMLOasisBasicImporter( xContext
) );
926 // -----------------------------------------------------------------------------
928 //.........................................................................
929 } // namespace xmlscript
930 //.........................................................................
932 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */