sw/source/core/swg/SwXMLTextBlocks1.cxx | 156 ++++++++++++++------------------ 1 file changed, 73 insertions(+), 83 deletions(-)
New commits: commit 9c0065dd4127b852281a175e523b176730dea417 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Thu Jan 9 10:49:11 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Jan 9 14:02:52 2020 +0100 flatten SwXMLTextBlocks::GetMacroTable Change-Id: Ie3fcb4bb350796b10d0e10aadc58d57b71d480a3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86475 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/core/swg/SwXMLTextBlocks1.cxx b/sw/source/core/swg/SwXMLTextBlocks1.cxx index 782284c0d1f4..36a69ffb033c 100644 --- a/sw/source/core/swg/SwXMLTextBlocks1.cxx +++ b/sw/source/core/swg/SwXMLTextBlocks1.cxx @@ -168,100 +168,90 @@ ErrCode SwXMLTextBlocks::GetMacroTable( sal_uInt16 nIdx, m_aLong = m_aNames[nIdx]->aLong; aPackageName = m_aNames[nIdx]->aPackageName; - ErrCode nRet = ERRCODE_NONE; - // open stream in proper sub-storage CloseFile(); - nRet = OpenFile(); - if ( ERRCODE_NONE == nRet ) + if ( OpenFile() != ERRCODE_NONE ) + return ERR_SWG_READ_ERROR; + + try { + xRoot = xBlkRoot->openStorageElement( aPackageName, embed::ElementModes::READ ); + bool bOasis = SotStorage::GetVersion( xRoot ) > SOFFICE_FILEFORMAT_60; + + uno::Reference < io::XStream > xDocStream = xRoot->openStreamElement( + "atevent.xml", embed::ElementModes::READ ); + OSL_ENSURE(xDocStream.is(), "Can't create stream"); + if ( !xDocStream.is() ) + return ERR_SWG_READ_ERROR; + + uno::Reference<io::XInputStream> xInputStream = xDocStream->getInputStream(); + + // prepare ParserInputSrouce + xml::sax::InputSource aParserInput; + aParserInput.sSystemId = m_aName; + aParserInput.aInputStream = xInputStream; + + // get service factory + uno::Reference< uno::XComponentContext > xContext = + comphelper::getProcessComponentContext(); + + // get parser + 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("com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter") + : OUString("com.sun.star.comp.Writer.XMLAutotextEventsImporter"); + uno::Reference< xml::sax::XDocumentHandler > xFilter( + xContext->getServiceManager()->createInstanceWithArgumentsAndContext( + sFilterComponent, aFilterArguments, xContext), + UNO_QUERY ); + OSL_ENSURE( xFilter.is(), "can't instantiate autotext-events filter"); + if ( !xFilter.is() ) + return ERR_SWG_READ_ERROR; + + // connect parser and filter + xParser->setDocumentHandler( xFilter ); + + // parse the stream try { - xRoot = xBlkRoot->openStorageElement( aPackageName, embed::ElementModes::READ ); - bool bOasis = SotStorage::GetVersion( xRoot ) > SOFFICE_FILEFORMAT_60; - - uno::Reference < io::XStream > xDocStream = xRoot->openStreamElement( - "atevent.xml", embed::ElementModes::READ ); - OSL_ENSURE(xDocStream.is(), "Can't create stream"); - if ( xDocStream.is() ) - { - uno::Reference<io::XInputStream> xInputStream = xDocStream->getInputStream(); - - // prepare ParserInputSrouce - xml::sax::InputSource aParserInput; - aParserInput.sSystemId = m_aName; - aParserInput.aInputStream = xInputStream; - - // get service factory - uno::Reference< uno::XComponentContext > xContext = - comphelper::getProcessComponentContext(); - - // get parser - 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("com.sun.star.comp.Writer.XMLOasisAutotextEventsImporter") - : OUString("com.sun.star.comp.Writer.XMLAutotextEventsImporter"); - uno::Reference< xml::sax::XDocumentHandler > xFilter( - xContext->getServiceManager()->createInstanceWithArgumentsAndContext( - sFilterComponent, aFilterArguments, xContext), - UNO_QUERY ); - OSL_ENSURE( xFilter.is(), - "can't instantiate atevent filter"); - if ( xFilter.is() ) - { - // connect parser and filter - xParser->setDocumentHandler( xFilter ); - - // 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 (ERRCODE_NONE == nRet) - pDescriptor->copyMacrosIntoTable(rMacroTable); - } - else - nRet = ERR_SWG_READ_ERROR; - } - else - nRet = ERR_SWG_READ_ERROR; + xParser->parseStream( aParserInput ); } - catch( uno::Exception& ) + 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; + return ERR_SWG_READ_ERROR; } + catch( io::IOException& ) + { + return ERR_SWG_READ_ERROR; + } + + // and finally, copy macro into table + pDescriptor->copyMacrosIntoTable(rMacroTable); + } + catch( uno::Exception& ) + { + TOOLS_WARN_EXCEPTION("sw", ""); + return ERR_SWG_READ_ERROR; } - else - nRet = ERR_SWG_READ_ERROR; // success! - return nRet; + return ERRCODE_NONE; } ErrCode SwXMLTextBlocks::GetBlockText( const OUString& rShort, OUString& rText ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits