From fb741b5e1e6aeaee74cf14af4f1cc152f0ab0952 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 10 Oct 2012 10:13:18 +0200 Subject: fdo#46808, Adapt xml::sax::XWriter UNO service to new style Create a merged XWriter interface for the service. The xml.sax.Writer service already existed, it just did not have an IDL file. Change-Id: I4e6d3f3c68f9282a55fc7aa19778f97632fd8ad5 --- comphelper/inc/comphelper/ofopxmlhelper.hxx | 4 +- comphelper/source/xml/ofopxmlhelper.cxx | 59 +++++++++++++---------------- 2 files changed, 28 insertions(+), 35 deletions(-) (limited to 'comphelper') diff --git a/comphelper/inc/comphelper/ofopxmlhelper.hxx b/comphelper/inc/comphelper/ofopxmlhelper.hxx index e18d08f727ef..c263022166cd 100644 --- a/comphelper/inc/comphelper/ofopxmlhelper.hxx +++ b/comphelper/inc/comphelper/ofopxmlhelper.hxx @@ -96,7 +96,7 @@ public: void SAL_CALL WriteRelationsInfoSequence( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aSequence, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory ) + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext ) throw( ::com::sun::star::uno::Exception ); // writes two entries of type sequence @@ -109,7 +109,7 @@ public: const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aDefaultsSequence, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aOverridesSequence, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory ) + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext ) throw( ::com::sun::star::uno::Exception ); // XDocumentHandler diff --git a/comphelper/source/xml/ofopxmlhelper.cxx b/comphelper/source/xml/ofopxmlhelper.cxx index 739b27d1512d..41f5a5ca620c 100644 --- a/comphelper/source/xml/ofopxmlhelper.cxx +++ b/comphelper/source/xml/ofopxmlhelper.cxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -54,19 +55,15 @@ uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OFOPXMLHelper::Read } // ----------------------------------- -void SAL_CALL OFOPXMLHelper::WriteRelationsInfoSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< uno::Sequence< beans::StringPair > >& aSequence, const uno::Reference< lang::XMultiServiceFactory > xFactory ) +void SAL_CALL OFOPXMLHelper::WriteRelationsInfoSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< uno::Sequence< beans::StringPair > >& aSequence, const uno::Reference< uno::XComponentContext > xContext ) throw( uno::Exception ) { if ( !xOutStream.is() ) throw uno::RuntimeException(); - uno::Reference< io::XActiveDataSource > xWriterSource( - xFactory->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ), - uno::UNO_QUERY_THROW ); - uno::Reference< xml::sax::XDocumentHandler > xWriterHandler( xWriterSource, uno::UNO_QUERY_THROW ); + uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext); - xWriterSource->setOutputStream( xOutStream ); + xWriter->setOutputStream( xOutStream ); ::rtl::OUString aRelListElement( RTL_CONSTASCII_USTRINGPARAM( "Relationships" ) ); ::rtl::OUString aRelElement( RTL_CONSTASCII_USTRINGPARAM( "Relationship" ) ); @@ -85,8 +82,8 @@ void SAL_CALL OFOPXMLHelper::WriteRelationsInfoSequence( const uno::Reference< i aCDATAString, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "http://schemas.openxmlformats.org/package/2006/relationships" ) ) ); - xWriterHandler->startDocument(); - xWriterHandler->startElement( aRelListElement, xRootAttrList ); + xWriter->startDocument(); + xWriter->startElement( aRelListElement, xRootAttrList ); for ( sal_Int32 nInd = 0; nInd < aSequence.getLength(); nInd++ ) { @@ -108,30 +105,26 @@ void SAL_CALL OFOPXMLHelper::WriteRelationsInfoSequence( const uno::Reference< i } } - xWriterHandler->startElement( aRelElement, xAttrList ); - xWriterHandler->ignorableWhitespace( aWhiteSpace ); - xWriterHandler->endElement( aRelElement ); + xWriter->startElement( aRelElement, xAttrList ); + xWriter->ignorableWhitespace( aWhiteSpace ); + xWriter->endElement( aRelElement ); } - xWriterHandler->ignorableWhitespace( aWhiteSpace ); - xWriterHandler->endElement( aRelListElement ); - xWriterHandler->endDocument(); + xWriter->ignorableWhitespace( aWhiteSpace ); + xWriter->endElement( aRelListElement ); + xWriter->endDocument(); } // ----------------------------------- -void SAL_CALL OFOPXMLHelper::WriteContentSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< beans::StringPair >& aDefaultsSequence, const uno::Sequence< beans::StringPair >& aOverridesSequence, const uno::Reference< lang::XMultiServiceFactory > xFactory ) +void SAL_CALL OFOPXMLHelper::WriteContentSequence( const uno::Reference< io::XOutputStream >& xOutStream, const uno::Sequence< beans::StringPair >& aDefaultsSequence, const uno::Sequence< beans::StringPair >& aOverridesSequence, const uno::Reference< uno::XComponentContext > xContext ) throw( uno::Exception ) { if ( !xOutStream.is() ) throw uno::RuntimeException(); - uno::Reference< io::XActiveDataSource > xWriterSource( - xFactory->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.xml.sax.Writer" ) ) ), - uno::UNO_QUERY_THROW ); - uno::Reference< xml::sax::XDocumentHandler > xWriterHandler( xWriterSource, uno::UNO_QUERY_THROW ); + uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create(xContext); - xWriterSource->setOutputStream( xOutStream ); + xWriter->setOutputStream( xOutStream ); ::rtl::OUString aTypesElement( RTL_CONSTASCII_USTRINGPARAM( "Types" ) ); ::rtl::OUString aDefaultElement( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ); @@ -150,8 +143,8 @@ void SAL_CALL OFOPXMLHelper::WriteContentSequence( const uno::Reference< io::XOu aCDATAString, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "http://schemas.openxmlformats.org/package/2006/content-types" ) ) ); - xWriterHandler->startDocument(); - xWriterHandler->startElement( aTypesElement, xRootAttrList ); + xWriter->startDocument(); + xWriter->startElement( aTypesElement, xRootAttrList ); for ( sal_Int32 nInd = 0; nInd < aDefaultsSequence.getLength(); nInd++ ) { @@ -160,9 +153,9 @@ void SAL_CALL OFOPXMLHelper::WriteContentSequence( const uno::Reference< io::XOu pAttrList->AddAttribute( aExtensionAttr, aCDATAString, aDefaultsSequence[nInd].First ); pAttrList->AddAttribute( aContentTypeAttr, aCDATAString, aDefaultsSequence[nInd].Second ); - xWriterHandler->startElement( aDefaultElement, xAttrList ); - xWriterHandler->ignorableWhitespace( aWhiteSpace ); - xWriterHandler->endElement( aDefaultElement ); + xWriter->startElement( aDefaultElement, xAttrList ); + xWriter->ignorableWhitespace( aWhiteSpace ); + xWriter->endElement( aDefaultElement ); } for ( sal_Int32 nInd = 0; nInd < aOverridesSequence.getLength(); nInd++ ) @@ -172,14 +165,14 @@ void SAL_CALL OFOPXMLHelper::WriteContentSequence( const uno::Reference< io::XOu pAttrList->AddAttribute( aPartNameAttr, aCDATAString, aOverridesSequence[nInd].First ); pAttrList->AddAttribute( aContentTypeAttr, aCDATAString, aOverridesSequence[nInd].Second ); - xWriterHandler->startElement( aOverrideElement, xAttrList ); - xWriterHandler->ignorableWhitespace( aWhiteSpace ); - xWriterHandler->endElement( aOverrideElement ); + xWriter->startElement( aOverrideElement, xAttrList ); + xWriter->ignorableWhitespace( aWhiteSpace ); + xWriter->endElement( aOverrideElement ); } - xWriterHandler->ignorableWhitespace( aWhiteSpace ); - xWriterHandler->endElement( aTypesElement ); - xWriterHandler->endDocument(); + xWriter->ignorableWhitespace( aWhiteSpace ); + xWriter->endElement( aTypesElement ); + xWriter->endDocument(); } -- cgit