Kaydet (Commit) bf46b46a authored tarafından Mohammed Abdul Azeem's avatar Mohammed Abdul Azeem Kaydeden (comit) Michael Meeks

Moving XSAXDocumentBuilder2 to use XFastDocumentHandler:

This is used in parsing of meta Contexts across different
modules. This also involved moving to XFastParser for
parsing xml filters in sw, sd, starmath.

Change-Id: Ic663aaac6cb20ee8ce5b97cae87c93220f5a2929
Reviewed-on: https://gerrit.libreoffice.org/42989Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 1b61d041
......@@ -55,6 +55,8 @@
#include <xmloff/formlayerimport.hxx>
#include <comphelper/attributelist.hxx>
#include <sax/fastattribs.hxx>
#include <rtl/ustring.hxx>
#include <unordered_map>
#include <com/sun/star/beans/NamedValue.hpp>
......@@ -225,6 +227,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public cppu::WeakImplHelper<
css::uno::Reference< css::xml::sax::XFastDocumentHandler > mxFastDocumentHandler;
static css::uno::Reference< css::xml::sax::XFastTokenHandler > xTokenHandler;
static std::unordered_map< sal_Int32, std::pair< OUString, OUString > > aNamespaceMap;
static std::unordered_map< OUString, OUString, OUStringHash > aNamespaceURIPrefixMap;
static bool bIsNSMapsInitialized;
static void initializeNamespaceMaps();
......@@ -378,6 +381,8 @@ public:
static const OUString getNameFromToken( sal_Int32 nToken );
static const OUString getNamespacePrefixFromToken( sal_Int32 nToken );
static const OUString getNamespaceURIFromToken( sal_Int32 nToken );
static const OUString getNamespacePrefixFromURI( const OUString& rURI );
SvXMLNamespaceMap& GetNamespaceMap() { return *mpNamespaceMap; }
const SvXMLNamespaceMap& GetNamespaceMap() const { return *mpNamespaceMap; }
......
......@@ -40,22 +40,20 @@ private:
css::uno::Reference< css::xml::dom::XSAXDocumentBuilder2> mxDocBuilder;
public:
SvXMLMetaDocumentContext(SvXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName,
const css::uno::Reference< css::document::XDocumentProperties>& xDocProps);
SvXMLMetaDocumentContext(SvXMLImport& rImport,
const css::uno::Reference< css::document::XDocumentProperties>& xDocProps);
virtual ~SvXMLMetaDocumentContext() override;
virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList>& xAttrList ) override;
virtual void SAL_CALL characters( const OUString& aChars ) override;
virtual void SAL_CALL startFastElement( sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
virtual void StartElement( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
virtual void EndElement() override;
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
public:
static void setBuildId(const OUString & rGenerator,
......
......@@ -20,7 +20,7 @@
#ifndef __com_sun_star_xml_dom_XSAXDocumentBuilder2_idl
#define __com_sun_star_xml_dom_XSAXDocumentBuilder2_idl
#include <com/sun/star/xml/sax/XDocumentHandler.idl>
#include <com/sun/star/xml/sax/XFastDocumentHandler.idl>
#include <com/sun/star/xml/dom/XSAXDocumentBuilder.idl>
module com { module sun { module star { module xml { module dom {
......@@ -33,7 +33,7 @@ module com { module sun { module star { module xml { module dom {
interface XSAXDocumentBuilder2
{
interface XSAXDocumentBuilder;
interface com::sun::star::xml::sax::XDocumentHandler;
interface com::sun::star::xml::sax::XFastDocumentHandler;
};
};};};};};
......
......@@ -745,10 +745,6 @@ SvXMLImportContext* ORptFilter::CreateDocumentContext( sal_uInt16 nPrefix,
case XML_TOK_DOC_CONTENT:
pContext = new RptXMLDocumentContentContext(*this, nPrefix, rLocalName);
break;
case XML_TOK_DOC_META:
GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
pContext = CreateMetaContext( rLocalName );
break;
default:
break;
}
......@@ -759,6 +755,23 @@ SvXMLImportContext* ORptFilter::CreateDocumentContext( sal_uInt16 nPrefix,
return pContext;
}
SvXMLImportContext *ORptFilter::CreateFastContext( sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
{
SvXMLImportContext *pContext = nullptr;
switch (nElement)
{
case XML_ELEMENT( OFFICE, XML_DOCUMENT_META ):
GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
pContext = CreateMetaContext( nElement );
break;
default:
pContext = new SvXMLImportContext(*this);
}
return pContext;
}
const SvXMLTokenMap& ORptFilter::GetDocElemTokenMap() const
{
if ( !m_pDocElemTokenMap.get() )
......@@ -1102,14 +1115,14 @@ void ORptFilter::insertFunction(const css::uno::Reference< css::report::XFunctio
m_aFunctions.emplace(_xFunction->getName(),_xFunction);
}
SvXMLImportContext* ORptFilter::CreateMetaContext(const OUString& rLocalName)
SvXMLImportContext* ORptFilter::CreateMetaContext(const sal_Int32 /*nElement*/)
{
SvXMLImportContext* pContext = nullptr;
if ( getImportFlags() & SvXMLImportFlags::META )
{
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(), uno::UNO_QUERY_THROW);
pContext = new SvXMLMetaDocumentContext(*this,XML_NAMESPACE_OFFICE, rLocalName,xDPS->getDocumentProperties());
pContext = new SvXMLMetaDocumentContext(*this, xDPS->getDocumentProperties());
}
return pContext;
}
......
......@@ -99,7 +99,7 @@ public:
using SvXMLImport::SetMasterStyles;
SvXMLImportContext* CreateStylesContext(const OUString& rLocalName,
const Reference< XAttributeList>& xAttrList, bool bIsAutoStyle );
SvXMLImportContext* CreateMetaContext(const OUString& rLocalName);
SvXMLImportContext* CreateMetaContext(const sal_Int32 nElement);
SvXMLImportContext* CreateFontDeclsContext(const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList );
protected:
......@@ -108,6 +108,9 @@ protected:
const OUString& rLocalName,
const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override;
virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
virtual XMLShapeImportHelper* CreateShapeImport() override;
virtual ~ORptFilter() throw() override;
......
......@@ -234,10 +234,6 @@ protected:
ScXMLImport& GetScImport() { return static_cast<ScXMLImport&>(GetImport()); }
public:
ScXMLDocContext_Impl( ScXMLImport& rImport,
sal_uInt16 nPrfx,
const OUString& rLName );
ScXMLDocContext_Impl( ScXMLImport& rImport );
virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
......@@ -256,13 +252,6 @@ public:
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
};
ScXMLDocContext_Impl::ScXMLDocContext_Impl( ScXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName ) :
SvXMLImportContext( rImport, nPrfx, rLName )
{
}
ScXMLDocContext_Impl::ScXMLDocContext_Impl( ScXMLImport& rImport ) :
SvXMLImportContext( rImport )
{
......@@ -273,37 +262,22 @@ class ScXMLFlatDocContext_Impl
: public ScXMLDocContext_Impl, public SvXMLMetaDocumentContext
{
public:
ScXMLFlatDocContext_Impl( ScXMLImport& i_rImport,
sal_uInt16 i_nPrefix, const OUString & i_rLName,
const uno::Reference<document::XDocumentProperties>& i_xDocProps);
ScXMLFlatDocContext_Impl( ScXMLImport& i_rImport,
const uno::Reference<document::XDocumentProperties>& i_xDocProps);
virtual SvXMLImportContextRef CreateChildContext(
sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
const uno::Reference<xml::sax::XAttributeList>& i_xAttrList) override;
virtual void SAL_CALL startFastElement (sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) override;
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override;
virtual void SAL_CALL characters( const OUString& aChars ) override;
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL
createFastChildContext( sal_Int32 nElement,
const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override;
};
ScXMLFlatDocContext_Impl::ScXMLFlatDocContext_Impl( ScXMLImport& i_rImport,
sal_uInt16 i_nPrefix, const OUString & i_rLName,
const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
ScXMLDocContext_Impl(i_rImport, i_nPrefix, i_rLName),
SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
i_xDocProps)
{
}
ScXMLFlatDocContext_Impl::ScXMLFlatDocContext_Impl( ScXMLImport& i_rImport,
const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
SvXMLImportContext(i_rImport),
......@@ -312,29 +286,14 @@ SvXMLMetaDocumentContext(i_rImport, i_xDocProps)
{
}
SvXMLImportContextRef ScXMLFlatDocContext_Impl::CreateChildContext(
sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
{
// behave like meta base class iff we encounter office:meta
const SvXMLTokenMap& rTokenMap = GetScImport().GetDocElemTokenMap();
if ( XML_TOK_DOC_META == rTokenMap.Get( i_nPrefix, i_rLocalName ) ) {
return SvXMLMetaDocumentContext::CreateChildContext(
i_nPrefix, i_rLocalName, i_xAttrList );
} else {
return ScXMLDocContext_Impl::CreateChildContext(
i_nPrefix, i_rLocalName, i_xAttrList );
}
}
uno::Reference< xml::sax::XFastContextHandler > SAL_CALL
ScXMLFlatDocContext_Impl::createFastChildContext( sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList > & xAttrList )
{
if ( nElement != XML_ELEMENT( OFFICE, XML_META ) )
return ScXMLDocContext_Impl::createFastChildContext( nElement, xAttrList );
if ( nElement == XML_ELEMENT( OFFICE, XML_META ) )
return SvXMLMetaDocumentContext::createFastChildContext( nElement, xAttrList );
else
return new SvXMLImportContext( GetImport() );
return ScXMLDocContext_Impl::createFastChildContext( nElement, xAttrList );
}
void SAL_CALL ScXMLFlatDocContext_Impl::startFastElement(sal_Int32 nElement,
......@@ -348,6 +307,11 @@ void SAL_CALL ScXMLFlatDocContext_Impl::endFastElement(sal_Int32 nElement)
SvXMLMetaDocumentContext::endFastElement( nElement );
}
void SAL_CALL ScXMLFlatDocContext_Impl::characters(const OUString& rChars)
{
SvXMLMetaDocumentContext::characters(rChars);
}
class ScXMLBodyContext_Impl : public ScXMLImportContext
{
public:
......@@ -659,29 +623,6 @@ sc::PivotTableSources& ScXMLImport::GetPivotTableSources()
return *mpPivotSources;
}
SvXMLImportContext *ScXMLImport::CreateDocumentContext( sal_uInt16 nPrefix,
const OUString& rLocalName,
const uno::Reference<xml::sax::XAttributeList>& xAttrList )
{
SvXMLImportContext *pContext = nullptr;
if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
( IsXMLToken(rLocalName, XML_DOCUMENT_META)) ) {
pContext = CreateMetaContext(rLocalName);
} else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
( IsXMLToken(rLocalName, XML_DOCUMENT)) ) {
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
GetModel(), uno::UNO_QUERY_THROW);
// flat OpenDocument file format
pContext = new ScXMLFlatDocContext_Impl( *this, nPrefix, rLocalName,
xDPS->getDocumentProperties());
}
else
pContext = SvXMLImport::CreateDocumentContext( nPrefix, rLocalName, xAttrList );
return pContext;
}
SvXMLImportContext *ScXMLImport::CreateFastContext( sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
{
......@@ -695,6 +636,10 @@ SvXMLImportContext *ScXMLImport::CreateFastContext( sal_Int32 nElement,
pContext = new ScXMLDocContext_Impl( *this );
break;
case XML_ELEMENT( OFFICE, XML_DOCUMENT_META ):
pContext = CreateMetaContext(nElement);
break;
case XML_ELEMENT( OFFICE, XML_DOCUMENT ):
{
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
......@@ -847,7 +792,7 @@ SvXMLImportContext *ScXMLImport::CreateBodyContext(const rtl::Reference<sax_fast
}
SvXMLImportContext *ScXMLImport::CreateMetaContext(
const OUString& rLocalName )
const sal_Int32 /*nElement*/ )
{
SvXMLImportContext* pContext = nullptr;
......@@ -857,14 +802,11 @@ SvXMLImportContext *ScXMLImport::CreateMetaContext(
GetModel(), uno::UNO_QUERY_THROW);
uno::Reference<document::XDocumentProperties> const xDocProps(
(IsStylesOnlyMode()) ? nullptr : xDPS->getDocumentProperties());
pContext = new SvXMLMetaDocumentContext(*this,
XML_NAMESPACE_OFFICE, rLocalName,
xDocProps);
pContext = new SvXMLMetaDocumentContext(*this, xDocProps);
}
if( !pContext )
pContext = new SvXMLImportContext( *this,
XML_NAMESPACE_OFFICE, rLocalName );
pContext = new SvXMLImportContext( *this );
return pContext;
}
......
......@@ -299,10 +299,8 @@ class ScXMLImport: public SvXMLImport
protected:
virtual SvXMLImportContext *CreateDocumentContext(sal_uInt16 nPrefix,
const OUString& rLocalName,
const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override;
// This method is called after the namespace map has been updated, but
// before a context for the current element has been pushed.
virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override;
......@@ -322,7 +320,7 @@ public:
// NB: in contrast to other CreateFooContexts, this particular one handles
// the root element (i.e. office:document-meta)
SvXMLImportContext *CreateMetaContext(
const OUString& rLocalName );
const sal_Int32 nElement );
SvXMLImportContext *CreateFontDeclsContext(const sal_uInt16 nPrefix, const OUString& rLocalName,
const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList);
SvXMLImportContext *CreateScriptContext(
......
......@@ -41,6 +41,7 @@
#include <strmname.h>
#include <svx/xmleohlp.hxx>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
#include <com/sun/star/xml/sax/XFastParser.hpp>
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/document/XExporter.hpp>
......@@ -216,11 +217,18 @@ ErrCode ReadThroughComponent(
// connect model and filter
Reference < XImporter > xImporter( xFilter, UNO_QUERY );
xImporter->setTargetDocument( xModelComponent );
uno::Reference< xml::sax::XFastParser > xFastParser = dynamic_cast<
xml::sax::XFastParser* >( xFilter.get() );
// finally, parser the stream
SAL_INFO( "sd.filter", "parsing stream" );
try
{
xParser->parseStream( aParserInput );
if( xFastParser.is() )
xFastParser->parseStream( aParserInput );
else
xParser->parseStream( aParserInput );
}
catch (const xml::sax::SAXParseException& r)
{
......
......@@ -30,6 +30,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sdext_pdfimport,\
sal \
test \
unotest \
xo \
))
$(eval $(call gb_CppunitTest_use_library_objects,sdext_pdfimport,pdfimport))
......
......@@ -30,6 +30,7 @@ $(eval $(call gb_Executable_use_libraries,pdf2xml,\
unotest \
cppuhelper \
sal \
xo \
))
$(eval $(call gb_Executable_use_library_objects,pdf2xml,pdfimport))
......
......@@ -28,6 +28,7 @@ $(eval $(call gb_Executable_use_libraries,pdfunzip,\
cppuhelper \
sal \
vcl \
xo \
))
$(eval $(call gb_Executable_use_library_objects,pdfunzip,pdfimport))
......
......@@ -27,6 +27,7 @@ $(eval $(call gb_Library_use_libraries,pdfimport,\
cppu \
cppuhelper \
sal \
xo \
))
$(eval $(call gb_Library_use_externals,pdfimport,\
......
......@@ -27,6 +27,7 @@
#include <cppuhelper/exc_hlp.hxx>
#include <com/sun/star/xml/sax/SAXException.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
#include <xmloff/xmlimp.hxx>
#if OSL_DEBUG_LEVEL > 0
#include <osl/file.hxx>
......@@ -43,6 +44,8 @@ SaxEmitter::SaxEmitter( const uno::Reference< xml::sax::XDocumentHandler >& xDoc
m_xDocHdl( xDocHdl )
{
OSL_PRECOND(m_xDocHdl.is(), "SaxEmitter(): invalid doc handler");
if (SvXMLImport *pFastHandler = dynamic_cast<SvXMLImport*>(m_xDocHdl.get()))
m_xDocHdl.set( new SvXMLLegacyToFastDocHandler( pFastHandler ) );
try
{
m_xDocHdl->startDocument();
......
......@@ -48,6 +48,7 @@
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/xml/sax/Parser.hpp>
#include <com/sun/star/xml/sax/Writer.hpp>
#include <com/sun/star/xml/sax/XFastParser.hpp>
#include <com/sun/star/xml/dom/DOMException.hpp>
#include <com/sun/star/xml/dom/XDocument.hpp>
#include <com/sun/star/xml/dom/XElement.hpp>
......@@ -1770,8 +1771,13 @@ SfxDocumentMetaData::loadFromStorage(
css::uno::UNO_QUERY_THROW);
xImp->setTargetDocument(css::uno::Reference<css::lang::XComponent>(this));
xParser->setDocumentHandler(xDocHandler);
css::uno::Reference< css::xml::sax::XFastParser > xFastParser = dynamic_cast<
css::xml::sax::XFastParser* >( xDocHandler.get() );
try {
xParser->parseStream(input);
if( xFastParser.is() )
xFastParser->parseStream(input);
else
xParser->parseStream(input);
} catch (const css::xml::sax::SAXException &) {
throw css::io::WrongFormatException(
"SfxDocumentMetaData::loadFromStorage:"
......
......@@ -24,6 +24,7 @@ one go*/
#include <com/sun/star/xml/sax/InputSource.hpp>
#include <com/sun/star/xml/sax/Parser.hpp>
#include <com/sun/star/xml/sax/XFastParser.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/packages/WrongPasswordException.hpp>
......@@ -286,10 +287,16 @@ ErrCode SmXMLImportWrapper::ReadThroughComponent(
Reference < XImporter > xImporter( xFilter, UNO_QUERY );
xImporter->setTargetDocument( xModelComponent );
uno::Reference< xml::sax::XFastParser > xFastParser = dynamic_cast<
xml::sax::XFastParser* >( xFilter.get() );
// finally, parser the stream
try
{
xParser->parseStream( aParserInput );
if( xFastParser.is() )
xFastParser->parseStream( aParserInput );
else
xParser->parseStream( aParserInput );
uno::Reference<lang::XUnoTunnel> xFilterTunnel( xFilter, uno::UNO_QUERY );
SmXMLImport *pFilter = reinterpret_cast< SmXMLImport * >(
......@@ -1935,11 +1942,20 @@ public:
class SmXMLOfficeContext_Impl : public virtual SvXMLImportContext
{
public:
SmXMLOfficeContext_Impl( SmXMLImport &rImport, sal_uInt16 nPrfx,
const OUString& rLName)
: SvXMLImportContext(rImport,nPrfx,rLName) {}
SmXMLOfficeContext_Impl( SmXMLImport &rImport )
: SvXMLImportContext(rImport) {}
virtual void SAL_CALL characters( const OUString& /*aChars*/ ) override {}
virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) override {}
virtual void SAL_CALL endFastElement( sal_Int32 /*nElement*/ ) override {}
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList > &xAttrList) override;
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
};
SvXMLImportContextRef SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPrefix,
......@@ -1965,6 +1981,12 @@ SvXMLImportContextRef SmXMLOfficeContext_Impl::CreateChildContext(sal_uInt16 nPr
return pContext;
}
uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SmXMLOfficeContext_Impl::createFastChildContext(
sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
{
return new SvXMLImportContext( GetImport() );
}
// context for flat file xml format
class SmXMLFlatDocContext_Impl
......@@ -1972,41 +1994,59 @@ class SmXMLFlatDocContext_Impl
{
public:
SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport,
sal_uInt16 i_nPrefix, const OUString & i_rLName,
const uno::Reference<document::XDocumentProperties>& i_xDocProps);
virtual SvXMLImportContextRef CreateChildContext(sal_uInt16 i_nPrefix, const OUString& i_rLocalName, const uno::Reference<xml::sax::XAttributeList>& i_xAttrList) override;
virtual void SAL_CALL characters( const OUString& aChars ) override;
virtual void SAL_CALL startFastElement( sal_Int32 nElement,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
virtual void SAL_CALL endFastElement( sal_Int32 nElement ) override;
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
};
SmXMLFlatDocContext_Impl::SmXMLFlatDocContext_Impl( SmXMLImport& i_rImport,
sal_uInt16 i_nPrefix, const OUString & i_rLName,
const uno::Reference<document::XDocumentProperties>& i_xDocProps) :
SvXMLImportContext(i_rImport, i_nPrefix, i_rLName),
SmXMLOfficeContext_Impl(i_rImport, i_nPrefix, i_rLName),
SvXMLMetaDocumentContext(i_rImport, i_nPrefix, i_rLName,
i_xDocProps)
SvXMLImportContext(i_rImport),
SmXMLOfficeContext_Impl(i_rImport),
SvXMLMetaDocumentContext(i_rImport, i_xDocProps)
{
}
void SAL_CALL SmXMLFlatDocContext_Impl::startFastElement( sal_Int32 nElement,
const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
{
SvXMLMetaDocumentContext::startFastElement(nElement, xAttrList);
}
void SAL_CALL SmXMLFlatDocContext_Impl::endFastElement( sal_Int32 nElement )
{
SvXMLMetaDocumentContext::endFastElement(nElement);
}
SvXMLImportContextRef SmXMLFlatDocContext_Impl::CreateChildContext(
sal_uInt16 i_nPrefix, const OUString& i_rLocalName,
const uno::Reference<xml::sax::XAttributeList>& i_xAttrList)
void SAL_CALL SmXMLFlatDocContext_Impl::characters( const OUString& rChars )
{
SvXMLMetaDocumentContext::characters(rChars);
}
uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SmXMLFlatDocContext_Impl::createFastChildContext(
sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
{
// behave like meta base class iff we encounter office:meta
if ( XML_NAMESPACE_OFFICE == i_nPrefix &&
i_rLocalName == GetXMLToken(XML_META) )
if ( nElement == XML_ELEMENT(OFFICE, XML_META) )
{
return SvXMLMetaDocumentContext::CreateChildContext(
i_nPrefix, i_rLocalName, i_xAttrList );
return SvXMLMetaDocumentContext::createFastChildContext(
nElement, xAttrList );
}
else
{
return SmXMLOfficeContext_Impl::CreateChildContext(
i_nPrefix, i_rLocalName, i_xAttrList );
return SmXMLOfficeContext_Impl::createFastChildContext(
nElement, xAttrList );
}
}
static const SvXMLTokenMapEntry aPresLayoutElemTokenMap[] =
{
{ XML_NAMESPACE_MATH, XML_SEMANTICS, XML_TOK_SEMANTICS },
......@@ -2823,28 +2863,40 @@ SvXMLImportContext *SmXMLImport::CreateDocumentContext(sal_uInt16 nPrefix,
const OUString &rLocalName,
const uno::Reference <xml::sax::XAttributeList> & /*xAttrList*/)
{
if ( XML_NAMESPACE_OFFICE == nPrefix )
SvXMLImportContext *pContext = nullptr;
if ( XML_NAMESPACE_OFFICE != nPrefix )
pContext = new SmXMLDocContext_Impl(*this,nPrefix,rLocalName);
return pContext;
}
SvXMLImportContext *SmXMLImport::CreateFastContext(sal_Int32 nElement,
const uno::Reference <xml::sax::XFastAttributeList> & /*xAttrList*/)
{
SvXMLImportContext *pContext = nullptr;
switch (nElement)
{
if ( IsXMLToken(rLocalName, XML_DOCUMENT) ||
IsXMLToken(rLocalName, XML_DOCUMENT_META) )
case XML_ELEMENT( OFFICE, XML_DOCUMENT ):
case XML_ELEMENT( OFFICE, XML_DOCUMENT_META ):
{
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
GetModel(), uno::UNO_QUERY_THROW);
return IsXMLToken(rLocalName, XML_DOCUMENT_META)
? new SvXMLMetaDocumentContext(*this,
XML_NAMESPACE_OFFICE, rLocalName,
xDPS->getDocumentProperties())
pContext = ( (nElement & TOKEN_MASK) == XML_DOCUMENT_META )
? new SvXMLMetaDocumentContext( *this,
xDPS->getDocumentProperties() )
// flat OpenDocument file format -- this has not been tested...
: new SmXMLFlatDocContext_Impl( *this, nPrefix, rLocalName,
xDPS->getDocumentProperties());
}
else
{
return new SmXMLOfficeContext_Impl( *this,nPrefix,rLocalName);
: new SmXMLFlatDocContext_Impl( *this,
xDPS->getDocumentProperties() );
}
break;
default:
if ((nElement & NMSP_MASK) == NAMESPACE_TOKEN(XML_NAMESPACE_OFFICE))
pContext = new SmXMLOfficeContext_Impl(*this);
else
pContext = new SvXMLImportContext(*this);
}
else
return new SmXMLDocContext_Impl(*this,nPrefix,rLocalName);
return pContext;
}
SvXMLImportContext *SmXMLImport::CreateRowContext(sal_uInt16 nPrefix,
......
......@@ -99,6 +99,9 @@ public:
const OUString &rLocalName,
const css::uno::Reference <
css::xml::sax::XAttributeList> &xAttrList) override;
SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
const css::uno::Reference<
css::xml::sax::XFastAttributeList >& xAttrList ) override;
SvXMLImportContext *CreateRowContext(sal_uInt16 nPrefix,
const OUString &rLocalName);
SvXMLImportContext *CreateEncloseContext(sal_uInt16 nPrefix,
......
......@@ -34,6 +34,7 @@
#include <com/sun/star/packages/zip/ZipIOException.hpp>
#include <com/sun/star/packages/WrongPasswordException.hpp>
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
#include <com/sun/star/xml/sax/XFastParser.hpp>
#include <o3tl/any.hxx>
#include <vcl/errinf.hxx>
#include <sfx2/docfile.hxx>
......@@ -168,11 +169,16 @@ ErrCode ReadThroughComponent(
// connect model and filter
uno::Reference < XImporter > xImporter( xFilter, UNO_QUERY );
xImporter->setTargetDocument( xModelComponent );
uno::Reference< xml::sax::XFastParser > xFastParser = dynamic_cast<
xml::sax::XFastParser* >( xFilter.get() );
// finally, parser the stream
try
{
xParser->parseStream( aParserInput );
if( xFastParser.is() )
xFastParser->parseStream( aParserInput );
else
xParser->parseStream( aParserInput );
}
catch( xml::sax::SAXParseException& r )
{
......
......@@ -196,9 +196,14 @@ public:
SwXMLDocContext_Impl( SwXMLImport& rImport, sal_uInt16 nPrfx,
const OUString& rLName );
SwXMLDocContext_Impl( SwXMLImport& rImport );
virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix,
const OUString& rLocalName,
const Reference< xml::sax::XAttributeList > & xAttrList ) override;
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
};