summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2012-10-03 13:30:43 +0200
committerStephan Bergmann <sbergman@redhat.com>2012-10-04 16:29:53 +0200
commita20f9a410fdd3f776f870434bc39219d5fc64b40 (patch)
tree079278e5859c5782fbe9bfcc34302d09bd8dfadd /sw
parentbd6b41bce491ac5a5f562652b7e32045cc22c35c (diff)
fdo#46808, Adapt xml::sax::XParser UNO service to new style
The xml.sax.Parser service already existed, it just did not have a new-style service to create it. Change-Id: I6f145a7504ff9e149c802f723991954a2801cbc9
Diffstat (limited to 'sw')
-rw-r--r--sw/CppunitTest_sw_filters_test.mk1
-rw-r--r--sw/CppunitTest_sw_subsequent_rtfimport.mk1
-rw-r--r--sw/source/core/swg/SwXMLTextBlocks1.cxx154
-rw-r--r--sw/source/filter/xml/swxml.cxx34
4 files changed, 74 insertions, 116 deletions
diff --git a/sw/CppunitTest_sw_filters_test.mk b/sw/CppunitTest_sw_filters_test.mk
index 7b0d48fa14b4..e49b46719135 100644
--- a/sw/CppunitTest_sw_filters_test.mk
+++ b/sw/CppunitTest_sw_filters_test.mk
@@ -80,6 +80,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_filters_test,\
framework/util/fwk \
i18npool/util/i18npool \
package/util/package2 \
+ sax/source/expatwrap/expwrap \
sfx2/util/sfx \
svtools/util/svt \
sw/util/msword \
diff --git a/sw/CppunitTest_sw_subsequent_rtfimport.mk b/sw/CppunitTest_sw_subsequent_rtfimport.mk
index 062ef8dd87f7..2cc2110594eb 100644
--- a/sw/CppunitTest_sw_subsequent_rtfimport.mk
+++ b/sw/CppunitTest_sw_subsequent_rtfimport.mk
@@ -72,6 +72,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_subsequent_rtfimport,\
framework/util/fwk \
i18npool/util/i18npool \
package/util/package2 \
+ sax/source/expatwrap/expwrap \
sw/util/sw \
sw/util/swd \
sfx2/util/sfx \
diff --git a/sw/source/core/swg/SwXMLTextBlocks1.cxx b/sw/source/core/swg/SwXMLTextBlocks1.cxx
index 646439badc93..714de20465f3 100644
--- a/sw/source/core/swg/SwXMLTextBlocks1.cxx
+++ b/sw/source/core/swg/SwXMLTextBlocks1.cxx
@@ -32,10 +32,11 @@
#include <svtools/unoevent.hxx>
#include <sfx2/docfile.hxx>
#include <unotools/streamwrap.hxx>
+#include <comphelper/componentcontext.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/xml/sax/InputSource.hpp>
#include <com/sun/star/io/XActiveDataSource.hpp>
-#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/xml/sax/Parser.hpp>
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <doc.hxx>
#include <docsh.hxx>
@@ -118,23 +119,13 @@ sal_uLong SwXMLTextBlocks::GetDoc( sal_uInt16 nIdx )
aParserInput.aInputStream = xStream->getInputStream();
- // get parser
- uno::Reference< XInterface > xXMLParser = xServiceFactory->createInstance(
- OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser")));
- OSL_ENSURE( xXMLParser.is(),
- "XMLReader::Read: com.sun.star.xml.sax.Parser service missing" );
- if( !xXMLParser.is() )
- {
- // Maybe throw an exception?
- }
-
// get filter
// #110680#
// uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, aCur, sal_True );
uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( xServiceFactory, *this, aCur, sal_True );
// connect parser and filter
- uno::Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY );
+ uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(comphelper::getComponentContext(xServiceFactory));
xParser->setDocumentHandler( xFilter );
// parse
@@ -218,74 +209,67 @@ sal_uLong SwXMLTextBlocks::GetMacroTable( sal_uInt16 nIdx,
// get service factory
uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
comphelper::getProcessServiceFactory();
+ uno::Reference< uno::XComponentContext > xContext =
+ comphelper::getProcessComponentContext();
if ( xServiceFactory.is() )
{
// get parser
- OUString sParserService( RTL_CONSTASCII_USTRINGPARAM(
- "com.sun.star.xml.sax.Parser" ) );
- uno::Reference< xml::sax::XParser > xParser(
- xServiceFactory->createInstance(sParserService),
+ uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
+
+ // create descriptor and reference to it. Either
+ // both or neither must be kept because of the
+ // reference counting!
+ SvMacroTableEventDescriptor* pDescriptor =
+ new SvMacroTableEventDescriptor(aAutotextEvents);
+ uno::Reference<XNameReplace> xReplace = pDescriptor;
+ Sequence<Any> aFilterArguments( 1 );
+ aFilterArguments[0] <<= xReplace;
+
+ // get filter
+ OUString sFilterComponent = bOasis
+ ? OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter"))
+ : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.XMLAutotextEventsImporter"));
+ uno::Reference< xml::sax::XDocumentHandler > xFilter(
+ xServiceFactory->createInstanceWithArguments(
+ sFilterComponent, aFilterArguments),
UNO_QUERY );
- OSL_ENSURE( xParser.is(), "Can't create parser" );
- if( xParser.is() )
+ OSL_ENSURE( xFilter.is(),
+ "can't instantiate atevents filter");
+ if ( xFilter.is() )
{
- // create descriptor and reference to it. Either
- // both or neither must be kept because of the
- // reference counting!
- SvMacroTableEventDescriptor* pDescriptor =
- new SvMacroTableEventDescriptor(aAutotextEvents);
- uno::Reference<XNameReplace> xReplace = pDescriptor;
- Sequence<Any> aFilterArguments( 1 );
- aFilterArguments[0] <<= xReplace;
-
- // get filter
- OUString sFilterComponent = bOasis
- ? OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter"))
- : OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.XMLAutotextEventsImporter"));
- uno::Reference< xml::sax::XDocumentHandler > xFilter(
- xServiceFactory->createInstanceWithArguments(
- sFilterComponent, aFilterArguments),
- UNO_QUERY );
- OSL_ENSURE( xFilter.is(),
- "can't instantiate atevents filter");
- if ( xFilter.is() )
+ // connect parser and filter
+ xParser->setDocumentHandler( xFilter );
+
+ // connect model and filter
+ uno::Reference<document::XImporter> xImporter( xFilter,
+ UNO_QUERY );
+
+ // we don't need a model
+ // xImporter->setTargetDocument( xModelComponent );
+
+ // parse the stream
+ try
+ {
+ xParser->parseStream( aParserInput );
+ }
+ catch( xml::sax::SAXParseException& )
+ {
+ // workaround for #83452#: SetSize doesn't work
+ // nRet = ERR_SWG_READ_ERROR;
+ }
+ catch( xml::sax::SAXException& )
{
- // connect parser and filter
- xParser->setDocumentHandler( xFilter );
-
- // connect model and filter
- uno::Reference<document::XImporter> xImporter( xFilter,
- UNO_QUERY );
-
- // we don't need a model
- // xImporter->setTargetDocument( xModelComponent );
-
- // parse the stream
- try
- {
- xParser->parseStream( aParserInput );
- }
- catch( xml::sax::SAXParseException& )
- {
- // workaround for #83452#: SetSize doesn't work
- // nRet = ERR_SWG_READ_ERROR;
- }
- catch( xml::sax::SAXException& )
- {
- nRet = ERR_SWG_READ_ERROR;
- }
- catch( io::IOException& )
- {
- nRet = ERR_SWG_READ_ERROR;
- }
-
- // and finally, copy macro into table
- if (0 == nRet)
- pDescriptor->copyMacrosIntoTable(rMacroTbl);
+ nRet = ERR_SWG_READ_ERROR;
}
- else
+ catch( io::IOException& )
+ {
nRet = ERR_SWG_READ_ERROR;
+ }
+
+ // and finally, copy macro into table
+ if (0 == nRet)
+ pDescriptor->copyMacrosIntoTable(rMacroTbl);
}
else
nRet = ERR_SWG_READ_ERROR;
@@ -331,6 +315,8 @@ sal_uLong SwXMLTextBlocks::GetBlockText( const String& rShort, String& rText )
uno::Reference < io::XStream > xContents = xRoot->openStreamElement( aStreamName, embed::ElementModes::READ );
uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
comphelper::getProcessServiceFactory();
+ uno::Reference< uno::XComponentContext > xContext =
+ comphelper::getProcessComponentContext();
OSL_ENSURE( xServiceFactory.is(), "XMLReader::Read: got no service manager" );
if( !xServiceFactory.is() )
{
@@ -341,23 +327,13 @@ sal_uLong SwXMLTextBlocks::GetBlockText( const String& rShort, String& rText )
aParserInput.sSystemId = aName;
aParserInput.aInputStream = xContents->getInputStream();
- // get parser
- uno::Reference< XInterface > xXMLParser = xServiceFactory->createInstance(
- OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser")) );
- OSL_ENSURE( xXMLParser.is(),
- "XMLReader::Read: com.sun.star.xml.sax.Parser service missing" );
- if( !xXMLParser.is() )
- {
- // Maybe throw an exception?
- }
-
// get filter
// #110680#
// uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( *this, rText, bTextOnly );
uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLTextBlockImport( xServiceFactory, *this, rText, bTextOnly );
// connect parser and filter
- uno::Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY );
+ uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
xParser->setDocumentHandler( xFilter );
// parse
@@ -483,6 +459,8 @@ void SwXMLTextBlocks::ReadInfo( void )
{
uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
comphelper::getProcessServiceFactory();
+ uno::Reference< uno::XComponentContext > xContext =
+ comphelper::getProcessComponentContext();
OSL_ENSURE( xServiceFactory.is(),
"XMLReader::Read: got no service manager" );
if( !xServiceFactory.is() )
@@ -496,23 +474,13 @@ void SwXMLTextBlocks::ReadInfo( void )
uno::Reference < io::XStream > xDocStream = xBlkRoot->openStreamElement( sDocName, embed::ElementModes::READ );
aParserInput.aInputStream = xDocStream->getInputStream();
- // get parser
- uno::Reference< XInterface > xXMLParser = xServiceFactory->createInstance(
- OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser")));
- OSL_ENSURE( xXMLParser.is(),
- "XMLReader::Read: com.sun.star.xml.sax.Parser service missing" );
- if( !xXMLParser.is() )
- {
- // Maybe throw an exception?
- }
-
// get filter
// #110680#
// uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLBlockListImport( *this );
uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLBlockListImport( xServiceFactory, *this );
// connect parser and filter
- uno::Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY );
+ uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create( xContext );
xParser->setDocumentHandler( xFilter );
// parse
diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index cfda96c4e7a5..c07cedac9075 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -33,7 +33,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/componentcontext.hxx>
#include <com/sun/star/xml/sax/InputSource.hpp>
-#include <com/sun/star/xml/sax/XParser.hpp>
+#include <com/sun/star/xml/sax/Parser.hpp>
#include <com/sun/star/io/XActiveDataControl.hpp>
#include <com/sun/star/text/XTextRange.hpp>
#include <com/sun/star/container/XChild.hpp>
@@ -158,13 +158,7 @@ sal_Int32 ReadThroughComponent(
aParserInput.aInputStream = xInputStream;
// get parser
- uno::Reference< xml::sax::XParser > xParser(
- rFactory->createInstance(
- OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser"))),
- UNO_QUERY );
- OSL_ENSURE( xParser.is(), "Can't create parser" );
- if( !xParser.is() )
- return ERR_SWG_READ_ERROR;
+ uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(comphelper::getComponentContext(rFactory));
RTL_LOGFILE_CONTEXT_TRACE( aLog, "parser created" );
// get filter
@@ -1067,6 +1061,8 @@ size_t XMLReader::GetSectionList( SfxMedium& rMedium,
{
uno::Reference< lang::XMultiServiceFactory > xServiceFactory =
comphelper::getProcessServiceFactory();
+ uno::Reference< uno::XComponentContext > xContext =
+ comphelper::getProcessComponentContext();
OSL_ENSURE( xServiceFactory.is(),
"XMLReader::Read: got no service manager" );
uno::Reference < embed::XStorage > xStg2;
@@ -1082,23 +1078,15 @@ size_t XMLReader::GetSectionList( SfxMedium& rMedium,
uno::Reference < io::XStream > xStm = xStg2->openStreamElement( sDocName, embed::ElementModes::READ );
aParserInput.aInputStream = xStm->getInputStream();
- // get parser
- uno::Reference< XInterface > xXMLParser = xServiceFactory->createInstance(
- OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser")) );
- OSL_ENSURE( xXMLParser.is(),
- "XMLReader::Read: com.sun.star.xml.sax.Parser service missing" );
- if( xXMLParser.is() )
- {
- // get filter
- uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLSectionList( xServiceFactory, rStrings );
+ // get filter
+ uno::Reference< xml::sax::XDocumentHandler > xFilter = new SwXMLSectionList( xServiceFactory, rStrings );
- // connect parser and filter
- uno::Reference< xml::sax::XParser > xParser( xXMLParser, UNO_QUERY );
- xParser->setDocumentHandler( xFilter );
+ // connect parser and filter
+ uno::Reference< xml::sax::XParser > xParser = xml::sax::Parser::create(xContext);
+ xParser->setDocumentHandler( xFilter );
- // parse
- xParser->parseStream( aParserInput );
- }
+ // parse
+ xParser->parseStream( aParserInput );
}
catch( xml::sax::SAXParseException& )
{