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

Fixes for migrating SvXMLImport to use FastParser:

These are necessary for implementing fast interfaces
for the contexts.

Change-Id: I37655c85c76b42782a49eeea3140490213047341
Reviewed-on: https://gerrit.libreoffice.org/28641Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst 4e933ea8
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
#include <o3tl/typed_flags_set.hxx> #include <o3tl/typed_flags_set.hxx>
#include <memory> #include <memory>
#define NAMESPACE_TOKEN( prefixToken ) ( ( prefixToken + 1 ) << NMSP_SHIFT ) #define NAMESPACE_TOKEN( prefixToken ) ( ( sal_Int32( prefixToken + 1 ) ) << NMSP_SHIFT )
const size_t NMSP_SHIFT = 16; const size_t NMSP_SHIFT = 16;
const sal_Int32 TOKEN_MASK = 0xffff; const sal_Int32 TOKEN_MASK = 0xffff;
...@@ -191,6 +191,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8< ...@@ -191,6 +191,7 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8<
SvXMLImportFlags mnImportFlags; SvXMLImportFlags mnImportFlags;
SvXMLErrorFlags mnErrorFlags; SvXMLErrorFlags mnErrorFlags;
std::set< OUString > embeddedFontUrlsKnown; std::set< OUString > embeddedFontUrlsKnown;
bool isFastContext;
css::uno::Reference< css::xml::sax::XFastParser > mxParser; css::uno::Reference< css::xml::sax::XFastParser > mxParser;
rtl::Reference< SvXMLImportFastNamespaceHandler > maNamespaceHandler; rtl::Reference< SvXMLImportFastNamespaceHandler > maNamespaceHandler;
css::uno::Reference< css::xml::sax::XFastTokenHandler > mxTokenHandler; css::uno::Reference< css::xml::sax::XFastTokenHandler > mxTokenHandler;
...@@ -199,6 +200,9 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8< ...@@ -199,6 +200,9 @@ class XMLOFF_DLLPUBLIC SvXMLImport : public ::cppu::WeakImplHelper8<
const OUString getNamespacePrefixFromToken( sal_Int32 nToken ); const OUString getNamespacePrefixFromToken( sal_Int32 nToken );
void registerNamespaces(); void registerNamespaces();
void registerNSHelper(sal_Int32 nToken, sal_Int32 nPrefix, sal_Int32 nNamespace ); void registerNSHelper(sal_Int32 nToken, sal_Int32 nPrefix, sal_Int32 nNamespace );
void processNSAttributes( const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList,
SvXMLNamespaceMap *pRewindMap );
void Characters(const OUString& aChars);
protected: protected:
......
...@@ -44,7 +44,7 @@ struct SvXMLTokenMapEntry ...@@ -44,7 +44,7 @@ struct SvXMLTokenMapEntry
nPrefixKey( nPrefix ), nPrefixKey( nPrefix ),
eLocalName( eName ), eLocalName( eName ),
nToken( nTok ), nToken( nTok ),
nFastToken( sal_uInt32( nPrefixKey + 1 ) << 16 | eLocalName ) nFastToken( ( sal_Int32( nPrefixKey + 1 ) ) << 16 | eLocalName )
{ {
if ( nFastTok ) // alternative value for duplicate/dummy tokens if ( nFastTok ) // alternative value for duplicate/dummy tokens
nFastToken = nFastTok; nFastToken = nFastTok;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <com/sun/star/xml/sax/XLocator.hpp> #include <com/sun/star/xml/sax/XLocator.hpp>
#include <xmloff/xmlimp.hxx> #include <xmloff/xmlimp.hxx>
#include <xmloff/xmlictxt.hxx> #include <xmloff/xmlictxt.hxx>
#include <sax/fastattribs.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -69,6 +70,7 @@ void SvXMLImportContext::Characters( const OUString& ) ...@@ -69,6 +70,7 @@ void SvXMLImportContext::Characters( const OUString& )
void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & Attribs) void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
throw (uno::RuntimeException, xml::sax::SAXException, std::exception) throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
{ {
mrImport.isFastContext = false;
startUnknownElement( mrImport.getNamespacePrefixFromToken( nElement ), startUnknownElement( mrImport.getNamespacePrefixFromToken( nElement ),
mrImport.getNameFromToken( nElement ), Attribs ); mrImport.getNameFromToken( nElement ), Attribs );
} }
...@@ -85,38 +87,47 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & rPrefix, ...@@ -85,38 +87,47 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & rPrefix,
else else
elementName = rLocalName; elementName = rLocalName;
uno::Sequence< xml::FastAttribute > fastAttribs = Attribs->getFastAttributes(); if ( Attribs.is() )
sal_uInt16 len = fastAttribs.getLength();
for (sal_uInt16 i = 0; i < len; i++)
{ {
OUString& rAttrValue = fastAttribs[i].Value; sax_fastparser::FastAttributeList *pAttribList;
sal_Int32 nToken = fastAttribs[i].Token; assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != nullptr );
const OUString& rAttrNamespacePrefix = mrImport.getNamespacePrefixFromToken( nToken ); pAttribList = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() );
OUString sAttrName = mrImport.getNameFromToken( nToken );
if ( !rAttrNamespacePrefix.isEmpty() ) const std::vector< sal_Int32 >& rAttrTokenList = pAttribList->getFastAttributeTokens();
sAttrName = rAttrNamespacePrefix + ":" + sAttrName; for ( size_t i = 0; i < rAttrTokenList.size(); i++ )
{
rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue ); const OUString& rAttrValue = OUString(pAttribList->getFastAttributeValue(i),
pAttribList->AttributeValueLength(i), RTL_TEXTENCODING_UTF8);
sal_Int32 nToken = rAttrTokenList[ i ];
const OUString& rAttrNamespacePrefix = mrImport.getNamespacePrefixFromToken( nToken );
OUString sAttrName = mrImport.getNameFromToken( nToken );
if ( !rAttrNamespacePrefix.isEmpty() )
sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
}
uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes();
sal_Int32 len = unknownAttribs.getLength();
for ( sal_Int32 i = 0; i < len; i++ )
{
const OUString& rAttrValue = unknownAttribs[i].Value;
OUString sAttrName = unknownAttribs[i].Name;
const OUString& rAttrNamespacePrefix = unknownAttribs[i].NamespaceURL;
if ( !rAttrNamespacePrefix.isEmpty() )
sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
}
} }
uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes();
len = unknownAttribs.getLength();
for ( sal_uInt16 i = 0; i < len; i++ )
{
OUString& rAttrValue = unknownAttribs[i].Value;
OUString sAttrName = unknownAttribs[i].Name;
OUString& rAttrNamespacePrefix = unknownAttribs[i].NamespaceURL;
if ( !rAttrNamespacePrefix.isEmpty() )
sAttrName = rAttrNamespacePrefix + ":" + sAttrName;
rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue );
}
mrImport.startElement( elementName, rAttrList.get() ); mrImport.startElement( elementName, rAttrList.get() );
} }
void SAL_CALL SvXMLImportContext::endFastElement(sal_Int32 nElement) void SAL_CALL SvXMLImportContext::endFastElement(sal_Int32 nElement)
throw (uno::RuntimeException, xml::sax::SAXException, std::exception) throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
{ {
mrImport.isFastContext = false;
endUnknownElement( mrImport.getNamespacePrefixFromToken( nElement ), endUnknownElement( mrImport.getNamespacePrefixFromToken( nElement ),
mrImport.getNameFromToken( nElement ) ); mrImport.getNameFromToken( nElement ) );
} }
...@@ -146,9 +157,10 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::cre ...@@ -146,9 +157,10 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::cre
return this; return this;
} }
void SAL_CALL SvXMLImportContext::characters(const OUString &) void SAL_CALL SvXMLImportContext::characters(const OUString &rChars)
throw (uno::RuntimeException, xml::sax::SAXException, std::exception) throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
{ {
mrImport.Characters( rChars );
} }
void SvXMLImportContext::onDemandRescueUsefulDataFromTemporary( const SvXMLImportContext& ) void SvXMLImportContext::onDemandRescueUsefulDataFromTemporary( const SvXMLImportContext& )
......
...@@ -435,6 +435,7 @@ SvXMLImport::SvXMLImport( ...@@ -435,6 +435,7 @@ SvXMLImport::SvXMLImport(
mpXMLErrors( nullptr ), mpXMLErrors( nullptr ),
mnImportFlags( nImportFlags ), mnImportFlags( nImportFlags ),
mnErrorFlags(SvXMLErrorFlags::NO), mnErrorFlags(SvXMLErrorFlags::NO),
isFastContext( false ),
maNamespaceHandler( new SvXMLImportFastNamespaceHandler() ), maNamespaceHandler( new SvXMLImportFastNamespaceHandler() ),
mxTokenHandler( new FastTokenHandler() ), mxTokenHandler( new FastTokenHandler() ),
mbIsFormsSupported( true ), mbIsFormsSupported( true ),
...@@ -691,14 +692,9 @@ void SAL_CALL SvXMLImport::endDocument() ...@@ -691,14 +692,9 @@ void SAL_CALL SvXMLImport::endDocument()
} }
} }
void SAL_CALL SvXMLImport::startElement( const OUString& rName, void SvXMLImport::processNSAttributes( const uno::Reference< xml::sax::XAttributeList >& xAttrList,
const uno::Reference< xml::sax::XAttributeList >& xAttrList ) SvXMLNamespaceMap *pRewindMap )
throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
{ {
SvXMLNamespaceMap *pRewindMap = nullptr;
// SAL_INFO("svg", "startElement " << rName);
// Process namespace attributes. This must happen before creating the
// context, because namespace decaration apply to the element name itself.
sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
for( sal_Int16 i=0; i < nAttrCount; i++ ) for( sal_Int16 i=0; i < nAttrCount; i++ )
{ {
...@@ -746,6 +742,17 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName, ...@@ -746,6 +742,17 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
} }
} }
}
void SAL_CALL SvXMLImport::startElement( const OUString& rName,
const uno::Reference< xml::sax::XAttributeList >& xAttrList )
throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
{
SvXMLNamespaceMap *pRewindMap = nullptr;
// SAL_INFO("svg", "startElement " << rName);
// Process namespace attributes. This must happen before creating the
// context, because namespace decaration apply to the element name itself.
processNSAttributes( xAttrList, pRewindMap );
// Get element's namespace and local name. // Get element's namespace and local name.
OUString aLocalName; OUString aLocalName;
...@@ -852,6 +859,14 @@ void SAL_CALL SvXMLImport::characters( const OUString& rChars ) ...@@ -852,6 +859,14 @@ void SAL_CALL SvXMLImport::characters( const OUString& rChars )
} }
} }
void SvXMLImport::Characters( const OUString& rChars )
{
if( !mpContexts->empty() )
{
mpContexts->back()->Characters( rChars );
}
}
void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& ) void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& )
throw(xml::sax::SAXException, uno::RuntimeException, std::exception) throw(xml::sax::SAXException, uno::RuntimeException, std::exception)
{ {
...@@ -888,9 +903,23 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element, ...@@ -888,9 +903,23 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element,
if ( !xContext.is() ) if ( !xContext.is() )
xContext.set( new SvXMLImportContext( *this ) ); xContext.set( new SvXMLImportContext( *this ) );
isFastContext = true;
// Call a startElement at the new context. // Call a startElement at the new context.
xContext->startFastElement( Element, Attribs ); xContext->startFastElement( Element, Attribs );
if ( isFastContext )
{
rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList;
maNamespaceHandler->addNSDeclAttributes( rAttrList );
SvXMLNamespaceMap *pRewindMap = nullptr;
processNSAttributes( rAttrList.get(), pRewindMap );
SvXMLImportContext *pContext = dynamic_cast<SvXMLImportContext*>( xContext.get() );
if( pContext && pRewindMap )
pContext->PutRewindMap( pRewindMap );
mpContexts->push_back( pContext );
}
// Push context on stack. // Push context on stack.
mpFastContexts->push_back( xContext ); mpFastContexts->push_back( xContext );
} }
...@@ -924,7 +953,11 @@ void SAL_CALL SvXMLImport::endFastElement (sal_Int32 Element) ...@@ -924,7 +953,11 @@ void SAL_CALL SvXMLImport::endFastElement (sal_Int32 Element)
{ {
uno::Reference< XFastContextHandler > xContext = mpFastContexts->back(); uno::Reference< XFastContextHandler > xContext = mpFastContexts->back();
mpFastContexts->pop_back(); mpFastContexts->pop_back();
isFastContext = true;
xContext->endFastElement( Element ); xContext->endFastElement( Element );
if ( isFastContext )
mpContexts->pop_back();
xContext = nullptr; xContext = nullptr;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment