diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-30 08:37:51 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-30 09:43:10 +0200 |
commit | e4da8ae4bef37f5450dcf34d9f06b68e3b901c01 (patch) | |
tree | 5ce67402f1bc237745046e43caf096896f3a92d2 /xmloff/source | |
parent | 315d56582f8a56d8f2d3ea6cda63ea4832249608 (diff) |
Revert "Convert TokenContext to fastparser APIs"
This reverts commit b7bfe6ae08f5b214f2d03d70a40b66c894c0b659.
Reason for revert: I missed some call-sites which means this is not going to work properly, which also means we don't have any tests for this functionality :-(
Change-Id: Ie340a5e2331609258e79176c3dd12249ad46ba7b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93134
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff/source')
20 files changed, 454 insertions, 228 deletions
diff --git a/xmloff/source/core/DomBuilderContext.cxx b/xmloff/source/core/DomBuilderContext.cxx index d6f01954f14b..9f893d710ae0 100644 --- a/xmloff/source/core/DomBuilderContext.cxx +++ b/xmloff/source/core/DomBuilderContext.cxx @@ -55,13 +55,17 @@ using com::sun::star::xml::dom::NodeType_ELEMENT_NODE; // helper functions; implemented below static Reference<XNode> lcl_createDomInstance(); static Reference<XNode> lcl_createElement( SvXMLImport& rImport, - sal_Int32 nElement, + sal_uInt16 nPrefix, + const OUString& rLocalName, const Reference<XNode>& xParent); -DomBuilderContext::DomBuilderContext( SvXMLImport& rImport, sal_Int32 nElement ) : - SvXMLImportContext( rImport ), - mxNode( lcl_createElement( rImport, nElement, lcl_createDomInstance() ) ) +DomBuilderContext::DomBuilderContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName ) : + SvXMLImportContext( rImport, nPrefix, rLocalName ), + mxNode( lcl_createElement( rImport, nPrefix, rLocalName, + lcl_createDomInstance() ) ) { SAL_WARN_IF( !mxNode.is(), "xmloff", "empty XNode not allowed" ); SAL_WARN_IF( !Reference<XElement>( mxNode, UNO_QUERY ).is(), "xmloff", "need element" ); @@ -69,10 +73,11 @@ DomBuilderContext::DomBuilderContext( SvXMLImport& rImport, sal_Int32 nElement ) } DomBuilderContext::DomBuilderContext( SvXMLImport& rImport, - sal_Int32 nElement, + sal_uInt16 nPrefix, + const OUString& rLocalName, Reference<XNode> const & xParent ) : - SvXMLImportContext( rImport ), - mxNode( lcl_createElement( rImport, nElement, xParent ) ) + SvXMLImportContext( rImport, nPrefix, rLocalName ), + mxNode( lcl_createElement( rImport, nPrefix, rLocalName, xParent ) ) { SAL_WARN_IF( !mxNode.is(), "xmloff", "empty XNode not allowed" ); SAL_WARN_IF( !Reference<XElement>( mxNode, UNO_QUERY ).is(), "xmloff", "need element" ); @@ -89,39 +94,43 @@ Reference<XDocument> DomBuilderContext::getTree() return mxNode->getOwnerDocument(); } -css::uno::Reference< css::xml::sax::XFastContextHandler > DomBuilderContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) +SvXMLImportContextRef DomBuilderContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& ) { // create DomBuilder for subtree - return new DomBuilderContext( GetImport(), nElement, mxNode ); + return new DomBuilderContext( GetImport(), nPrefix, rLocalName, mxNode ); } -void DomBuilderContext::startFastElement( - sal_Int32 /*nElement*/, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +void DomBuilderContext::StartElement( + const Reference<XAttributeList>& xAttrList ) { SAL_WARN_IF( !mxNode.is(), "xmloff", "empty XNode not allowed" ); SAL_WARN_IF( !mxNode->getOwnerDocument().is(), "xmloff", "XNode must have XDocument" ); // add attribute nodes to new node - for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) + sal_Int16 nAttributeCount = xAttrList->getLength(); + for( sal_Int16 i = 0; i < nAttributeCount; i++ ) { // get name & value for attribute - OUString aName = SvXMLImport::getNameFromToken(aIter.getToken()); - OUString aValue = aIter.toString(); + const OUString& rName = xAttrList->getNameByIndex( i ); + const OUString& rValue = xAttrList->getValueByIndex( i ); // namespace handling: determine namespace & namespace key - sal_Int32 nNamespacePrefix = (( aIter.getToken() & NMSP_MASK ) >> NMSP_SHIFT) - 1; + OUString sNamespace; + sal_uInt16 nNamespaceKey = + GetImport().GetNamespaceMap().GetKeyByAttrName( + rName, nullptr, nullptr, &sNamespace); // create attribute node and set value Reference<XElement> xElement( mxNode, UNO_QUERY_THROW ); - switch( nNamespacePrefix ) + switch( nNamespaceKey ) { case XML_NAMESPACE_NONE: // no namespace: create a non-namespaced attribute - xElement->setAttribute( aName, aValue ); + xElement->setAttribute( rName, rValue ); break; case XML_NAMESPACE_XMLNS: // namespace declaration: ignore, since the DOM tree handles these @@ -131,20 +140,25 @@ void DomBuilderContext::startFastElement( // unknown namespace: illegal input. Raise Warning. { Sequence<OUString> aSeq(2); - aSeq[0] = aName; - aSeq[1] = aValue; + aSeq[0] = rName; + aSeq[1] = rValue; GetImport().SetError( XMLERROR_FLAG_WARNING | XMLERROR_NAMESPACE_TROUBLE, aSeq ); } break; default: // a real and proper namespace: create namespaced attribute - xElement->setAttributeNS( SvXMLImport::getNamespaceURIFromToken(aIter.getToken()), aName, aValue ); + xElement->setAttributeNS( sNamespace, rName, rValue ); break; } } } +void DomBuilderContext::EndElement() +{ + // nothing to be done! +} + void DomBuilderContext::Characters( const OUString& rCharacters ) { SAL_WARN_IF( !mxNode.is(), "xmloff", "empty XNode not allowed" ); @@ -175,7 +189,8 @@ static Reference<XNode> lcl_createDomInstance() } static Reference<XNode> lcl_createElement( SvXMLImport& rImport, - sal_Int32 nElement, + sal_uInt16 nPrefix, + const OUString& rLocalName, const Reference<XNode>& xParent) { SAL_WARN_IF( !xParent.is(), "xmloff", "need parent node" ); @@ -188,20 +203,18 @@ static Reference<XNode> lcl_createElement( SvXMLImport& rImport, // multiple prefixes for the same namespace. Fortunately, those are rare. Reference<XElement> xElement; - sal_Int32 nNamespacePrefix = (( nElement & NMSP_MASK ) >> NMSP_SHIFT) - 1; - OUString aLocalName = SvXMLImport::getNameFromToken(nElement); - switch( nNamespacePrefix ) + switch( nPrefix ) { case XML_NAMESPACE_NONE: // no namespace: use local name - xElement = xDocument->createElement( aLocalName ); + xElement = xDocument->createElement( rLocalName ); break; case XML_NAMESPACE_XMLNS: case XML_NAMESPACE_UNKNOWN: // both cases are illegal; raise warning (and use only local name) - xElement = xDocument->createElement( aLocalName ); + xElement = xDocument->createElement( rLocalName ); { - Sequence<OUString> aSeq { aLocalName }; + Sequence<OUString> aSeq { rLocalName }; rImport.SetError( XMLERROR_FLAG_WARNING | XMLERROR_NAMESPACE_TROUBLE, aSeq ); } @@ -212,8 +225,8 @@ static Reference<XNode> lcl_createElement( SvXMLImport& rImport, // this is a bug, since this will fail for multiple prefixes used for // the same namespace. xElement = xDocument->createElementNS( - rImport.GetNamespaceMap().GetNameByKey( nNamespacePrefix ), - rImport.GetNamespaceMap().GetQNameByKey( nNamespacePrefix, aLocalName ) ); + rImport.GetNamespaceMap().GetNameByKey( nPrefix ), + rImport.GetNamespaceMap().GetQNameByKey( nPrefix, rLocalName ) ); break; } SAL_WARN_IF( !xElement.is(), "xmloff", "can't create element" ); diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 99be12818ea8..cc515c645a23 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -2254,7 +2254,6 @@ void SAL_CALL SvXMLLegacyToFastDocHandler::startElement( const OUString& rName, const OUString& rAttrValue = xAttrList->getValueByIndex( i ); sal_uInt16 const nAttrPrefix(mrImport->mpNamespaceMap->GetKeyByAttrName( rAttrName, nullptr, &aLocalAttrName, &aNamespace)); - SAL_WARN("xmloff", "nAttrPrefix=" << nAttrPrefix); if( XML_NAMESPACE_XMLNS != nAttrPrefix ) { Sequence< sal_Int8 > aAttrSeq( reinterpret_cast<sal_Int8 const *>( diff --git a/xmloff/source/forms/layerimport.cxx b/xmloff/source/forms/layerimport.cxx index 8bb17c32b14c..0263989f07d1 100644 --- a/xmloff/source/forms/layerimport.cxx +++ b/xmloff/source/forms/layerimport.cxx @@ -458,7 +458,7 @@ SvXMLImportContext* OFormLayerXMLImport_Impl::createContext(const sal_uInt16 _nP else if ( _nPrefix == XML_NAMESPACE_XFORMS && xmloff::token::IsXMLToken( _rLocalName, xmloff::token::XML_MODEL ) ) { - pContext = createXFormsModelContext( m_rImporter ); + pContext = createXFormsModelContext( m_rImporter, _nPrefix, _rLocalName ); } return pContext; diff --git a/xmloff/source/xforms/SchemaContext.cxx b/xmloff/source/xforms/SchemaContext.cxx index 36346bc9393f..6c19cbfa019a 100644 --- a/xmloff/source/xforms/SchemaContext.cxx +++ b/xmloff/source/xforms/SchemaContext.cxx @@ -25,7 +25,6 @@ #include <xmloff/xmltoken.hxx> #include <xmloff/xmlnmspe.hxx> #include <xmloff/xmltkmap.hxx> -#include <xmloff/xmlimp.hxx> #include <com/sun/star/xforms/XDataTypeRepository.hpp> @@ -35,27 +34,42 @@ using com::sun::star::xforms::XDataTypeRepository; using namespace xmloff::token; +static const SvXMLTokenMapEntry aAttributes[] = +{ + XML_TOKEN_MAP_END +}; + +static const SvXMLTokenMapEntry aChildren[] = +{ + TOKEN_MAP_ENTRY( XSD, SIMPLETYPE ), + XML_TOKEN_MAP_END +}; + SchemaContext::SchemaContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, const Reference<XDataTypeRepository>& rRepository ) : - TokenContext( rImport ), + TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ), mxRepository( rRepository ) { } -bool SchemaContext::HandleAttribute( - sal_Int32 , +void SchemaContext::HandleAttribute( + sal_uInt16, const OUString& ) { - return false; } SvXMLImportContext* SchemaContext::HandleChild( - sal_Int32 nElement, - const Reference<css::xml::sax::XFastAttributeList>& ) + sal_uInt16 nToken, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& ) { - if ( nElement == XML_ELEMENT(XSD, XML_SIMPLETYPE)) - return new SchemaSimpleTypeContext( GetImport(), mxRepository ); + if ( nToken == XML_SIMPLETYPE ) + return new SchemaSimpleTypeContext( GetImport(), nPrefix, rLocalName, + mxRepository ); return nullptr; } diff --git a/xmloff/source/xforms/SchemaContext.hxx b/xmloff/source/xforms/SchemaContext.hxx index eca66406bdd3..1e65995eb2a2 100644 --- a/xmloff/source/xforms/SchemaContext.hxx +++ b/xmloff/source/xforms/SchemaContext.hxx @@ -39,18 +39,22 @@ class SchemaContext : public TokenContext public: SchemaContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, const css::uno::Reference<css::xforms::XDataTypeRepository>& rRepository ); // implement TokenContext methods: protected: - virtual bool HandleAttribute( - sal_Int32 nElement, + virtual void HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) override; virtual SvXMLImportContext* HandleChild( - sal_Int32 nElement, - const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override; + sal_uInt16 nToken, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; }; #endif diff --git a/xmloff/source/xforms/SchemaRestrictionContext.cxx b/xmloff/source/xforms/SchemaRestrictionContext.cxx index e4db981de1ab..cafaab50b16c 100644 --- a/xmloff/source/xforms/SchemaRestrictionContext.cxx +++ b/xmloff/source/xforms/SchemaRestrictionContext.cxx @@ -53,11 +53,37 @@ using com::sun::star::xforms::XDataTypeRepository; using namespace xmloff::token; +static const SvXMLTokenMapEntry aAttributes[] = +{ + TOKEN_MAP_ENTRY( NONE, BASE ), + XML_TOKEN_MAP_END +}; + +static const SvXMLTokenMapEntry aChildren[] = +{ + TOKEN_MAP_ENTRY( XSD, LENGTH ), + TOKEN_MAP_ENTRY( XSD, MINLENGTH ), + TOKEN_MAP_ENTRY( XSD, MAXLENGTH ), + TOKEN_MAP_ENTRY( XSD, MININCLUSIVE ), + TOKEN_MAP_ENTRY( XSD, MINEXCLUSIVE ), + TOKEN_MAP_ENTRY( XSD, MAXINCLUSIVE ), + TOKEN_MAP_ENTRY( XSD, MAXEXCLUSIVE ), + TOKEN_MAP_ENTRY( XSD, PATTERN ), + // ??? XML_ENUMERATION + TOKEN_MAP_ENTRY( XSD, WHITESPACE ), + TOKEN_MAP_ENTRY( XSD, TOTALDIGITS ), + TOKEN_MAP_ENTRY( XSD, FRACTIONDIGITS ), + XML_TOKEN_MAP_END +}; + + SchemaRestrictionContext::SchemaRestrictionContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, Reference<css::xforms::XDataTypeRepository> const & rRepository, const OUString& sTypeName ) : - TokenContext( rImport ), + TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ), mxRepository( rRepository ), msTypeName( sTypeName ), msBaseName() @@ -90,16 +116,14 @@ void SchemaRestrictionContext::CreateDataType() SAL_WARN_IF( !mxDataType.is(), "xmloff", "can't create type" ); } -bool SchemaRestrictionContext::HandleAttribute( - sal_Int32 nElement, +void SchemaRestrictionContext::HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) { - if( nElement == XML_ELEMENT(NONE, XML_BASE) ) + if( nToken == XML_BASE ) { msBaseName = rValue; - return true; } - return false; } typedef Any (*convert_t)( const OUString& ); @@ -186,55 +210,59 @@ static Any xforms_time( const OUString& rValue ) return aAny; } + SvXMLImportContext* SchemaRestrictionContext::HandleChild( - sal_Int32 nElement, - const Reference<css::xml::sax::XFastAttributeList>& xAttrList ) + sal_uInt16 nToken, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& xAttrList ) { // find value OUString sValue; - for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) + sal_Int16 nLength = xAttrList->getLength(); + for( sal_Int16 n = 0; n < nLength; n++ ) { - if( (aIter.getToken() & TOKEN_MASK) == XML_VALUE ) - sValue = aIter.toString(); + if( IsXMLToken( xAttrList->getNameByIndex( n ), XML_VALUE ) ) + sValue = xAttrList->getValueByIndex( n ); } // determine property name + suitable converter OUString sPropertyName; convert_t pConvert = nullptr; - switch( nElement ) + switch( nToken ) { - case XML_ELEMENT(XSD, XML_LENGTH): + case XML_LENGTH: sPropertyName = "Length"; pConvert = &xforms_int32; break; - case XML_ELEMENT(XSD, XML_MINLENGTH): + case XML_MINLENGTH: sPropertyName = "MinLength"; pConvert = &xforms_int32; break; - case XML_ELEMENT(XSD, XML_MAXLENGTH): + case XML_MAXLENGTH: sPropertyName = "MaxLength"; pConvert = &xforms_int32; break; - case XML_ELEMENT(XSD, XML_TOTALDIGITS): + case XML_TOTALDIGITS: sPropertyName = "TotalDigits"; pConvert = &xforms_int32; break; - case XML_ELEMENT(XSD, XML_FRACTIONDIGITS): + case XML_FRACTIONDIGITS: sPropertyName = "FractionDigits"; pConvert = &xforms_int32; break; - case XML_ELEMENT(XSD, XML_PATTERN): + case XML_PATTERN: sPropertyName = "Pattern"; pConvert = &xforms_string; break; - case XML_ELEMENT(XSD, XML_WHITESPACE): + case XML_WHITESPACE: sPropertyName = "WhiteSpace"; pConvert = &xforms_whitespace; break; - case XML_ELEMENT(XSD, XML_MININCLUSIVE): - case XML_ELEMENT(XSD, XML_MINEXCLUSIVE): - case XML_ELEMENT(XSD, XML_MAXINCLUSIVE): - case XML_ELEMENT(XSD, XML_MAXEXCLUSIVE): + case XML_MININCLUSIVE: + case XML_MINEXCLUSIVE: + case XML_MAXINCLUSIVE: + case XML_MAXEXCLUSIVE: { // these attributes are mapped to different properties. // To determine the property name, we use an attribute @@ -242,18 +270,18 @@ SvXMLImportContext* SchemaRestrictionContext::HandleChild( // converter is only type dependent. // first, attribute-dependent prefix - switch( nElement ) + switch( nToken ) { - case XML_ELEMENT(XSD, XML_MININCLUSIVE): + case XML_MININCLUSIVE: sPropertyName = "MinInclusive"; break; - case XML_ELEMENT(XSD, XML_MINEXCLUSIVE): + case XML_MINEXCLUSIVE: sPropertyName = "MinExclusive"; break; - case XML_ELEMENT(XSD, XML_MAXINCLUSIVE): + case XML_MAXINCLUSIVE: sPropertyName = "MaxInclusive"; break; - case XML_ELEMENT(XSD, XML_MAXEXCLUSIVE): + case XML_MAXEXCLUSIVE: sPropertyName = "MaxExclusive"; break; } @@ -308,7 +336,7 @@ SvXMLImportContext* SchemaRestrictionContext::HandleChild( break; default: - SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); + OSL_FAIL( "unknown facet" ); } // finally, set the property @@ -328,7 +356,7 @@ SvXMLImportContext* SchemaRestrictionContext::HandleChild( } } - return new SvXMLImportContext( GetImport() ); + return new SvXMLImportContext( GetImport(), nPrefix, rLocalName ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/xforms/SchemaRestrictionContext.hxx b/xmloff/source/xforms/SchemaRestrictionContext.hxx index 1c3e84f1c4d6..29a36247a335 100644 --- a/xmloff/source/xforms/SchemaRestrictionContext.hxx +++ b/xmloff/source/xforms/SchemaRestrictionContext.hxx @@ -42,6 +42,8 @@ class SchemaRestrictionContext : public TokenContext public: SchemaRestrictionContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, css::uno::Reference<css::xforms::XDataTypeRepository> const & rRepository, const OUString& sTypeName ); @@ -51,13 +53,15 @@ private: // implement TokenContext methods: - virtual bool HandleAttribute( - sal_Int32 nElement, + virtual void HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) override; virtual SvXMLImportContext* HandleChild( - sal_Int32 nElement, - const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override; + sal_uInt16 nToken, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; }; #endif diff --git a/xmloff/source/xforms/SchemaSimpleTypeContext.cxx b/xmloff/source/xforms/SchemaSimpleTypeContext.cxx index 47f770325ee3..0c01874efbf5 100644 --- a/xmloff/source/xforms/SchemaSimpleTypeContext.cxx +++ b/xmloff/source/xforms/SchemaSimpleTypeContext.cxx @@ -25,7 +25,6 @@ #include <xmloff/nmspmap.hxx> #include <xmloff/xmlnmspe.hxx> #include <xmloff/xmltkmap.hxx> -#include <xmloff/xmlimp.hxx> #include <osl/diagnose.h> @@ -35,34 +34,49 @@ using com::sun::star::xforms::XDataTypeRepository; using namespace xmloff::token; +static const SvXMLTokenMapEntry aAttributes[] = +{ + TOKEN_MAP_ENTRY( NONE, NAME ), + XML_TOKEN_MAP_END +}; + +static const SvXMLTokenMapEntry aChildren[] = +{ + TOKEN_MAP_ENTRY( XSD, RESTRICTION ), + XML_TOKEN_MAP_END +}; + SchemaSimpleTypeContext::SchemaSimpleTypeContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, const Reference<XDataTypeRepository>& rRepository ) : - TokenContext( rImport ), + TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ), mxRepository( rRepository ) { } -bool SchemaSimpleTypeContext::HandleAttribute( - sal_Int32 nElement, +void SchemaSimpleTypeContext::HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) { - if( nElement == XML_ELEMENT(NONE, XML_NAME) ) + if( nToken == XML_NAME ) { msTypeName = rValue; - return true; } - return false; } SvXMLImportContext* SchemaSimpleTypeContext::HandleChild( - sal_Int32 nElement, - const Reference<css::xml::sax::XFastAttributeList>& ) + sal_uInt16 nToken, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& ) { - switch( nElement ) + switch( nToken ) { - case XML_ELEMENT(XSD, XML_RESTRICTION): + case XML_RESTRICTION: return new SchemaRestrictionContext( GetImport(), + nPrefix, rLocalName, mxRepository, msTypeName ); break; } diff --git a/xmloff/source/xforms/SchemaSimpleTypeContext.hxx b/xmloff/source/xforms/SchemaSimpleTypeContext.hxx index 72341b0b3a5d..0280b0870f3c 100644 --- a/xmloff/source/xforms/SchemaSimpleTypeContext.hxx +++ b/xmloff/source/xforms/SchemaSimpleTypeContext.hxx @@ -40,18 +40,22 @@ class SchemaSimpleTypeContext : public TokenContext public: SchemaSimpleTypeContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, const css::uno::Reference<css::xforms::XDataTypeRepository>& rRepository ); // implement TokenContext methods: protected: - virtual bool HandleAttribute( - sal_Int32 nElement, + virtual void HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) override; virtual SvXMLImportContext* HandleChild( - sal_Int32 nElement, - const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override; + sal_uInt16 nToken, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; }; #endif diff --git a/xmloff/source/xforms/TokenContext.cxx b/xmloff/source/xforms/TokenContext.cxx index d5b410ab94be..71215c4395d7 100644 --- a/xmloff/source/xforms/TokenContext.cxx +++ b/xmloff/source/xforms/TokenContext.cxx @@ -29,51 +29,84 @@ #include <algorithm> using com::sun::star::uno::Reference; +using com::sun::star::xml::sax::XAttributeList; -TokenContext::TokenContext( SvXMLImport& rImport ) - : SvXMLImportContext( rImport ) +const SvXMLTokenMapEntry aEmptyMap[1] = +{ + XML_TOKEN_MAP_END +}; + +TokenContext::TokenContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const SvXMLTokenMapEntry* pAttributes, + const SvXMLTokenMapEntry* pChildren ) + : SvXMLImportContext( rImport, nPrefix, rLocalName ), + mpAttributes( pAttributes ), + mpChildren( pChildren ) { } -void TokenContext::startFastElement( - sal_Int32 /*nElement*/, - const Reference<css::xml::sax::XFastAttributeList>& xAttributeList ) +void TokenContext::StartElement( + const Reference<XAttributeList>& xAttributeList ) { // iterate over attributes // - if in map: call HandleAttribute // - xmlns:... : ignore // - other: warning + SAL_WARN_IF( mpAttributes == nullptr, "xmloff", "no token map for attributes" ); + SvXMLTokenMap aMap( mpAttributes ); - for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttributeList )) + sal_Int16 nCount = xAttributeList->getLength(); + for( sal_Int16 i = 0; i < nCount; i++ ) { + // get key/local-name pair from namespace map + OUString sLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap(). + GetKeyByAttrName( xAttributeList->getNameByIndex(i), &sLocalName ); + + // get token from token map + sal_uInt16 nToken = aMap.Get( nPrefix, sLocalName ); + // and the value... - OUString aValue = aIter.toString(); + const OUString& rValue = xAttributeList->getValueByIndex(i); - if (HandleAttribute( aIter.getToken(), aValue )) - ; //fine - else if ( IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_XMLNS) ) - ; // ignore - else + if( nToken != XML_TOK_UNKNOWN ) + { + HandleAttribute( nToken, rValue ); + } + else if( nPrefix != XML_NAMESPACE_XMLNS ) { // error handling, for all attribute that are not // namespace declarations GetImport().SetError( XMLERROR_UNKNOWN_ATTRIBUTE, - SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()), aValue); + sLocalName, rValue); } } } -css::uno::Reference< css::xml::sax::XFastContextHandler > TokenContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +SvXMLImportContextRef TokenContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& xAttrList ) { - // call handle child, and pass down arguments - SvXMLImportContext* pContext = HandleChild( nElement, xAttrList ); + // call HandleChild for elements in token map. Ignore other content. + + SvXMLImportContext* pContext = nullptr; + + SAL_WARN_IF( mpChildren == nullptr, "xmloff", "no token map for child elements" ); + SvXMLTokenMap aMap( mpChildren ); + sal_uInt16 nToken = aMap.Get( nPrefix, rLocalName ); + if( nToken != XML_TOK_UNKNOWN ) + { + // call handle child, and pass down arguments + pContext = HandleChild( nToken, nPrefix, rLocalName, xAttrList ); + } // error handling: create default context and generate warning if( pContext == nullptr ) { - GetImport().SetError( XMLERROR_UNKNOWN_ELEMENT, SvXMLImport::getPrefixAndNameFromToken(nElement) ); + GetImport().SetError( XMLERROR_UNKNOWN_ELEMENT, rLocalName ); } return pContext; } diff --git a/xmloff/source/xforms/TokenContext.hxx b/xmloff/source/xforms/TokenContext.hxx index a8cd89bdf1e7..97b595232726 100644 --- a/xmloff/source/xforms/TokenContext.hxx +++ b/xmloff/source/xforms/TokenContext.hxx @@ -24,33 +24,46 @@ #include <xmloff/xmltkmap.hxx> namespace com { namespace sun { namespace star { - namespace xml { namespace sax { class XFastAttributeList; } } + namespace xml { namespace sax { class XAttributeList; } } namespace uno { template<typename T> class Reference; } } } } class SvXMLImport; +#define TOKEN_MAP_ENTRY(NAMESPACE,TOKEN) { XML_NAMESPACE_##NAMESPACE, xmloff::token::XML_##TOKEN, xmloff::token::XML_##TOKEN } + +extern const SvXMLTokenMapEntry aEmptyMap[1]; + /** handle attributes through an SvXMLTokenMap */ class TokenContext : public SvXMLImportContext { +protected: + const SvXMLTokenMapEntry* mpAttributes; /// static token map + const SvXMLTokenMapEntry* mpChildren; /// static token map + public: - TokenContext( SvXMLImport& rImport ); + TokenContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const SvXMLTokenMapEntry* pAttributes, + const SvXMLTokenMapEntry* pChildren ); // implement SvXMLImportContext methods: /** call HandleAttribute for each attribute in the token map; * create a warning for all others. Classes that wish to override * StartElement need to call the parent method. */ - 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; /** call HandleChild for each child element in the token map; * create a warning for all others. Classes that wish to override * CreateChildContext may want to call the parent method for * handling of defaults. */ - virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + virtual SvXMLImportContextRef CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; /** Create a warning for all non-namespace character * content. Classes that wish to deal with character content have @@ -59,15 +72,20 @@ public: virtual void Characters( const OUString& rChars ) override; protected: - /** will be called for each attribute. return true for success. */ - virtual bool HandleAttribute( - sal_Int32 nElement, + /** will be called for each attribute */ + virtual void HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) = 0; /** will be called for each child element */ virtual SvXMLImportContext* HandleChild( - sal_Int32 nElement, - const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) = 0; + sal_uInt16 nToken, + + // the following attributes are mainly to be used for child + // context creation + sal_uInt16 nPrefix, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) = 0; }; #endif diff --git a/xmloff/source/xforms/XFormsBindContext.cxx b/xmloff/source/xforms/XFormsBindContext.cxx index cd848f9e1275..c975e8b65b5c 100644 --- a/xmloff/source/xforms/XFormsBindContext.cxx +++ b/xmloff/source/xforms/XFormsBindContext.cxx @@ -44,14 +44,29 @@ using com::sun::star::xforms::XModel2; using namespace xmloff::token; +static const struct SvXMLTokenMapEntry aAttributeMap[] = +{ + TOKEN_MAP_ENTRY( NONE, NODESET ), + TOKEN_MAP_ENTRY( NONE, ID ), + TOKEN_MAP_ENTRY( NONE, READONLY ), + TOKEN_MAP_ENTRY( NONE, RELEVANT ), + TOKEN_MAP_ENTRY( NONE, REQUIRED ), + TOKEN_MAP_ENTRY( NONE, CONSTRAINT ), + TOKEN_MAP_ENTRY( NONE, CALCULATE ), + TOKEN_MAP_ENTRY( NONE, TYPE ), + XML_TOKEN_MAP_END +}; + // helper function; see below static void lcl_fillNamespaceContainer( const SvXMLNamespaceMap&, Reference<XNameContainer> const & ); XFormsBindContext::XFormsBindContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, const Reference<XModel2>& xModel ) : - TokenContext( rImport ), + TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ), mxModel( xModel ) { // attach binding to model @@ -60,47 +75,46 @@ XFormsBindContext::XFormsBindContext( mxModel->getBindings()->insert( makeAny( mxBinding ) ); } -bool XFormsBindContext::HandleAttribute( sal_Int32 nElement, +void XFormsBindContext::HandleAttribute( sal_uInt16 nToken, const OUString& rValue ) { - switch( nElement ) + switch( nToken ) { - case XML_ELEMENT(NONE, XML_NODESET): + case XML_NODESET: xforms_setValue( mxBinding, "BindingExpression", rValue ); break; - case XML_ELEMENT(NONE, XML_ID): + case XML_ID: xforms_setValue( mxBinding, "BindingID", rValue ); break; - case XML_ELEMENT(NONE, XML_READONLY): + case XML_READONLY: xforms_setValue( mxBinding, "ReadonlyExpression", rValue ); break; - case XML_ELEMENT(NONE, XML_RELEVANT): + case XML_RELEVANT: xforms_setValue( mxBinding, "RelevantExpression", rValue ); break; - case XML_ELEMENT(NONE, XML_REQUIRED): + case XML_REQUIRED: xforms_setValue( mxBinding, "RequiredExpression", rValue ); break; - case XML_ELEMENT(NONE, XML_CONSTRAINT): + case XML_CONSTRAINT: xforms_setValue( mxBinding, "ConstraintExpression", rValue ); break; - case XML_ELEMENT(NONE, XML_CALCULATE): + case XML_CALCULATE: xforms_setValue( mxBinding, "CalculateExpression", rValue ); break; - case XML_ELEMENT(NONE, XML_TYPE): + case XML_TYPE: xforms_setValue( mxBinding, "Type", makeAny( xforms_getTypeName( mxModel->getDataTypeRepository(), GetImport().GetNamespaceMap(), rValue ) ) ); break; default: - return false; + OSL_FAIL( "should not happen" ); + break; } - return true; } -void XFormsBindContext::startFastElement( - sal_Int32 nElement, - const Reference<css::xml::sax::XFastAttributeList>& xAttributeList ) +void XFormsBindContext::StartElement( + const Reference<XAttributeList>& xAttributeList ) { // we need to register the namespaces Reference<XNameContainer> xContainer( @@ -112,13 +126,15 @@ void XFormsBindContext::startFastElement( lcl_fillNamespaceContainer( GetImport().GetNamespaceMap(), xContainer); // call super-class for attribute handling - TokenContext::startFastElement( nElement, xAttributeList ); + TokenContext::StartElement( xAttributeList ); } /** will be called for each child element */ SvXMLImportContext* XFormsBindContext::HandleChild( - sal_Int32, - const Reference<css::xml::sax::XFastAttributeList>& ) + sal_uInt16, + sal_uInt16, + const OUString&, + const Reference<XAttributeList>& ) { OSL_FAIL( "no children supported" ); return nullptr; diff --git a/xmloff/source/xforms/XFormsBindContext.hxx b/xmloff/source/xforms/XFormsBindContext.hxx index a4c7a47a48fd..26424b8c406f 100644 --- a/xmloff/source/xforms/XFormsBindContext.hxx +++ b/xmloff/source/xforms/XFormsBindContext.hxx @@ -40,21 +40,24 @@ class XFormsBindContext : public TokenContext public: XFormsBindContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, const css::uno::Reference<css::xforms::XModel2>& xModel ); // implement SvXMLImportContext & TokenContext methods: - 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; protected: - virtual bool HandleAttribute( sal_Int32 nElement, + virtual void HandleAttribute( sal_uInt16 nToken, const OUString& rValue ) override; virtual SvXMLImportContext* HandleChild( - sal_Int32 nElement, - const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override; + sal_uInt16 nToken, + sal_uInt16 nNamespace, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; }; diff --git a/xmloff/source/xforms/XFormsInstanceContext.cxx b/xmloff/source/xforms/XFormsInstanceContext.cxx index 05beebbb2e11..e1a81a3f6c37 100644 --- a/xmloff/source/xforms/XFormsInstanceContext.cxx +++ b/xmloff/source/xforms/XFormsInstanceContext.cxx @@ -46,18 +46,28 @@ using com::sun::star::xml::sax::XAttributeList; using xmloff::token::XML_SRC; using xmloff::token::XML_ID; +static const SvXMLTokenMapEntry aAttributes[] = +{ + TOKEN_MAP_ENTRY( NONE, SRC ), + TOKEN_MAP_ENTRY( NONE, ID ), + XML_TOKEN_MAP_END +}; + XFormsInstanceContext::XFormsInstanceContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, const Reference<XModel2> & xModel ) : - TokenContext( rImport ), + TokenContext( rImport, nPrefix, rLocalName, aAttributes, aEmptyMap ), mxModel( xModel ) { SAL_WARN_IF( !mxModel.is(), "xmloff", "need model" ); } -css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext::createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) +SvXMLImportContextRef XFormsInstanceContext::CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& ) { SvXMLImportContext* pContext = nullptr; @@ -66,12 +76,13 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext // ignored. if( mxInstance.is() ) { - GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, SvXMLImport::getPrefixAndNameFromToken(nElement) ); + GetImport().SetError( XMLERROR_XFORMS_ONLY_ONE_INSTANCE_ELEMENT, rLocalName ); } else { // create new DomBuilderContext. Save reference to tree in Model. - DomBuilderContext* pInstance = new DomBuilderContext( GetImport(), nElement ); + DomBuilderContext* pInstance = + new DomBuilderContext( GetImport(), nPrefix, rLocalName ); mxInstance = pInstance->getTree(); pContext = pInstance; } @@ -81,7 +92,7 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > XFormsInstanceContext } -void XFormsInstanceContext::endFastElement(sal_Int32 ) +void XFormsInstanceContext::EndElement() { Sequence<PropertyValue> aSequence( 3 ); PropertyValue* pSequence = aSequence.getArray(); @@ -96,28 +107,29 @@ void XFormsInstanceContext::endFastElement(sal_Int32 ) } -bool XFormsInstanceContext::HandleAttribute( - sal_Int32 nElement, +void XFormsInstanceContext::HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) { - switch( nElement ) + switch( nToken ) { - case XML_ELEMENT(NONE, XML_SRC): + case XML_SRC: msURL = rValue; break; - case XML_ELEMENT(NONE, XML_ID): + case XML_ID: msId = rValue; break; default: - return false; + OSL_FAIL( "should not happen" ); break; } - return true; } SvXMLImportContext* XFormsInstanceContext::HandleChild( - sal_Int32, - const Reference<css::xml::sax::XFastAttributeList>& ) + sal_uInt16, + sal_uInt16, + const OUString&, + const Reference<XAttributeList>& ) { OSL_FAIL( "to be handled by CreateChildContext" ); return nullptr; diff --git a/xmloff/source/xforms/XFormsInstanceContext.hxx b/xmloff/source/xforms/XFormsInstanceContext.hxx index 92734dcadc89..df77d00a7e18 100644 --- a/xmloff/source/xforms/XFormsInstanceContext.hxx +++ b/xmloff/source/xforms/XFormsInstanceContext.hxx @@ -43,6 +43,8 @@ class XFormsInstanceContext : public TokenContext public: XFormsInstanceContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName, const css::uno::Reference<css::xforms::XModel2> & xModel ); // implement SvXMLImportContext & TokenContext methods: @@ -50,20 +52,23 @@ public: // arbitrary DOM elements. For the attributes, we use the // TokenContext mechanism. - virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( - sal_Int32 nElement, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override; + virtual SvXMLImportContextRef CreateChildContext( + sal_uInt16 nPrefix, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList >& xAttrList ) override; - virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; + virtual void EndElement() override; protected: - virtual bool HandleAttribute( - sal_Int32 nElement, + virtual void HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) override; virtual SvXMLImportContext* HandleChild( - sal_Int32 nElement, - const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override; + sal_uInt16 nToken, + sal_uInt16 nNamespace, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; }; #endif diff --git a/xmloff/source/xforms/XFormsModelContext.cxx b/xmloff/source/xforms/XFormsModelContext.cxx index 9217ab30c14d..e846e54b5866 100644 --- a/xmloff/source/xforms/XFormsModelContext.cxx +++ b/xmloff/source/xforms/XFormsModelContext.cxx @@ -44,52 +44,77 @@ using namespace com::sun::star::uno; using namespace xmloff::token; -XFormsModelContext::XFormsModelContext( SvXMLImport& rImport ) : - TokenContext( rImport ), +static const SvXMLTokenMapEntry aAttributes[] = +{ + TOKEN_MAP_ENTRY( NONE, ID ), + TOKEN_MAP_ENTRY( NONE, SCHEMA ), + XML_TOKEN_MAP_END +}; + +static const SvXMLTokenMapEntry aChildren[] = +{ + TOKEN_MAP_ENTRY( XFORMS, INSTANCE ), + TOKEN_MAP_ENTRY( XFORMS, BIND ), + TOKEN_MAP_ENTRY( XFORMS, SUBMISSION ), + TOKEN_MAP_ENTRY( XSD, SCHEMA ), + XML_TOKEN_MAP_END +}; + + +XFormsModelContext::XFormsModelContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName ) : + TokenContext( rImport, nPrefix, rLocalName, aAttributes, aChildren ), mxModel( xforms_createXFormsModel() ) { } -bool XFormsModelContext::HandleAttribute( - sal_Int32 nElement, +void XFormsModelContext::HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) { - switch( nElement ) + switch( nToken ) { - case XML_ELEMENT(NONE, XML_ID): + case XML_ID: mxModel->setPropertyValue( "ID", makeAny( rValue ) ); break; - case XML_ELEMENT(NONE, XML_SCHEMA): + case XML_SCHEMA: GetImport().SetError( XMLERROR_XFORMS_NO_SCHEMA_SUPPORT ); break; default: - return false; + OSL_FAIL( "this should not happen" ); break; } - return true; } SvXMLImportContext* XFormsModelContext::HandleChild( - sal_Int32 nElement, - const Reference<css::xml::sax::XFastAttributeList>& ) + sal_uInt16 nToken, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const Reference<XAttributeList>& ) { SvXMLImportContext* pContext = nullptr; - switch( nElement ) + switch( nToken ) { - case XML_ELEMENT(XFORMS, XML_INSTANCE): - pContext = new XFormsInstanceContext( GetImport(), mxModel ); + case XML_INSTANCE: + pContext = new XFormsInstanceContext( GetImport(), nPrefix, rLocalName, + mxModel ); break; - case XML_ELEMENT(XFORMS, XML_BIND): - pContext = new XFormsBindContext( GetImport(), mxModel ); + case XML_BIND: + pContext = new XFormsBindContext( GetImport(), nPrefix, rLocalName, + mxModel ); break; - case XML_ELEMENT(XFORMS, XML_SUBMISSION): - pContext = new XFormsSubmissionContext( GetImport(), mxModel ); + case XML_SUBMISSION: + pContext = new XFormsSubmissionContext( GetImport(), nPrefix, + rLocalName, mxModel ); break; - case XML_ELEMENT(XSD, XML_SCHEMA): - pContext = new SchemaContext( GetImport(), mxModel->getDataTypeRepository() ); + case XML_SCHEMA: + pContext = new SchemaContext( + GetImport(), nPrefix, rLocalName, mxModel->getDataTypeRepository() ); break; default: + OSL_FAIL( "Boooo!" ); break; } diff --git a/xmloff/source/xforms/XFormsModelContext.hxx b/xmloff/source/xforms/XFormsModelContext.hxx index 1e44951ad26d..d80b33088a7d 100644 --- a/xmloff/source/xforms/XFormsModelContext.hxx +++ b/xmloff/source/xforms/XFormsModelContext.hxx @@ -38,20 +38,24 @@ class XFormsModelContext : public TokenContext css::uno::Reference<css::xforms::XModel2> mxModel; public: - XFormsModelContext( SvXMLImport& rImport ); + XFormsModelContext( SvXMLImport& rImport, + sal_uInt16 nPrfx, + const OUString& rLName ); // implement SvXMLImportContext & TokenContext methods: virtual void EndElement() override; protected: - virtual bool HandleAttribute( - sal_Int32 nElement, + virtual void HandleAttribute( + sal_uInt16 nToken, const OUString& rValue ) override; virtual SvXMLImportContext* HandleChild( - sal_Int32 nElement, - const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override; + sal_uInt16 nToken, + sal_uInt16 nPrefix, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; }; #endif diff --git a/xmloff/source/xforms/XFormsSubmissionContext.cxx b/xmloff/source/xforms/XFormsSubmissionContext.cxx index 695b70808a87..254c7b97b11d 100644 --- a/xmloff/source/xforms/XFormsSubmissionContext.cxx +++ b/xmloff/source/xforms/XFormsSubmissionContext.cxx @@ -41,10 +41,32 @@ using namespace com::sun::star::uno; using namespace xmloff::token; +static const struct SvXMLTokenMapEntry aAttributeMap[] = +{ + TOKEN_MAP_ENTRY( NONE, ID ), + TOKEN_MAP_ENTRY( NONE, BIND ), + TOKEN_MAP_ENTRY( NONE, REF ), + TOKEN_MAP_ENTRY( NONE, ACTION ), + TOKEN_MAP_ENTRY( NONE, METHOD ), + TOKEN_MAP_ENTRY( NONE, VERSION ), + TOKEN_MAP_ENTRY( NONE, INDENT ), + TOKEN_MAP_ENTRY( NONE, MEDIATYPE ), + TOKEN_MAP_ENTRY( NONE, ENCODING ), + TOKEN_MAP_ENTRY( NONE, OMIT_XML_DECLARATION ), + TOKEN_MAP_ENTRY( NONE, STANDALONE ), + TOKEN_MAP_ENTRY( NONE, CDATA_SECTION_ELEMENTS ), + TOKEN_MAP_ENTRY( NONE, REPLACE ), + TOKEN_MAP_ENTRY( NONE, SEPARATOR ), + TOKEN_MAP_ENTRY( NONE, INCLUDENAMESPACEPREFIXES ), + XML_TOKEN_MAP_END +}; + XFormsSubmissionContext::XFormsSubmissionContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, const Reference<XModel2>& xModel ) : - TokenContext( rImport ), + TokenContext( rImport, nPrefix, rLocalName, aAttributeMap, aEmptyMap ), mxSubmission() { // register submission with model @@ -69,68 +91,69 @@ Any toBool( const OUString& rValue ) } // namespace -bool XFormsSubmissionContext::HandleAttribute( sal_Int32 nElement, +void XFormsSubmissionContext::HandleAttribute( sal_uInt16 nToken, const OUString& rValue ) { - switch( nElement ) + switch( nToken ) { - case XML_ELEMENT(NONE, XML_ID): + case XML_ID: xforms_setValue( mxSubmission, "ID", rValue ); break; - case XML_ELEMENT(NONE, XML_BIND): + case XML_BIND: xforms_setValue( mxSubmission, "Bind", rValue ); break; - case XML_ELEMENT(NONE, XML_REF): + case XML_REF: xforms_setValue( mxSubmission, "Ref", rValue ); break; - case XML_ELEMENT(NONE, XML_ACTION): + case XML_ACTION: xforms_setValue( mxSubmission, "Action", rValue ); break; - case XML_ELEMENT(NONE, XML_METHOD): + case XML_METHOD: xforms_setValue( mxSubmission, "Method", rValue ); break; - case XML_ELEMENT(NONE, XML_VERSION): + case XML_VERSION: xforms_setValue( mxSubmission, "Version", rValue ); break; - case XML_ELEMENT(NONE, XML_INDENT): + case XML_INDENT: xforms_setValue( mxSubmission, "Indent", toBool( rValue ) ); break; - case XML_ELEMENT(NONE, XML_MEDIATYPE): + case XML_MEDIATYPE: xforms_setValue( mxSubmission, "MediaType", rValue ); break; - case XML_ELEMENT(NONE, XML_ENCODING): + case XML_ENCODING: xforms_setValue( mxSubmission, "Encoding", rValue ); break; - case XML_ELEMENT(NONE, XML_OMIT_XML_DECLARATION): + case XML_OMIT_XML_DECLARATION: xforms_setValue( mxSubmission, "OmitXmlDeclaration", toBool( rValue ) ); break; - case XML_ELEMENT(NONE, XML_STANDALONE): + case XML_STANDALONE: xforms_setValue( mxSubmission, "Standalone", toBool( rValue ) ); break; - case XML_ELEMENT(NONE, XML_CDATA_SECTION_ELEMENTS): + case XML_CDATA_SECTION_ELEMENTS: xforms_setValue( mxSubmission, "CDataSectionElement", rValue ); break; - case XML_ELEMENT(NONE, XML_REPLACE): + case XML_REPLACE: xforms_setValue( mxSubmission, "Replace", rValue ); break; - case XML_ELEMENT(NONE, XML_SEPARATOR): + case XML_SEPARATOR: xforms_setValue( mxSubmission, "Separator", rValue ); break; - case XML_ELEMENT(NONE, XML_INCLUDENAMESPACEPREFIXES): + case XML_INCLUDENAMESPACEPREFIXES: xforms_setValue( mxSubmission, "IncludeNamespacePrefixes", rValue ); break; default: - return false; + OSL_FAIL( "unknown attribute" ); break; } - return true; } /** will be called for each child element */ SvXMLImportContext* XFormsSubmissionContext::HandleChild( - sal_Int32, - const Reference<css::xml::sax::XFastAttributeList>& ) + sal_uInt16, + sal_uInt16, + const OUString&, + const Reference<XAttributeList>& ) { OSL_FAIL( "no children supported" ); return nullptr; diff --git a/xmloff/source/xforms/XFormsSubmissionContext.hxx b/xmloff/source/xforms/XFormsSubmissionContext.hxx index 5fe7d4d379ef..33ac54542bd8 100644 --- a/xmloff/source/xforms/XFormsSubmissionContext.hxx +++ b/xmloff/source/xforms/XFormsSubmissionContext.hxx @@ -39,17 +39,21 @@ class XFormsSubmissionContext : public TokenContext public: XFormsSubmissionContext( SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName, const css::uno::Reference<css::xforms::XModel2>& xModel ); // implement TokenContext methods: protected: - virtual bool HandleAttribute( sal_Int32 nElement, + virtual void HandleAttribute( sal_uInt16 nToken, const OUString& rValue ) override; virtual SvXMLImportContext* HandleChild( - sal_Int32 nElement, - const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList ) override; + sal_uInt16 nToken, + sal_uInt16 nNamespace, + const OUString& rLocalName, + const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList ) override; }; diff --git a/xmloff/source/xforms/xformsimport.cxx b/xmloff/source/xforms/xformsimport.cxx index 2579d2cf0d93..4d07507a6e68 100644 --- a/xmloff/source/xforms/xformsimport.cxx +++ b/xmloff/source/xforms/xformsimport.cxx @@ -54,9 +54,12 @@ using com::sun::star::form::binding::XListEntrySink; using com::sun::star::form::submission::XSubmission; using com::sun::star::form::submission::XSubmissionSupplier; -SvXMLImportContext* createXFormsModelContext( SvXMLImport& rImport ) +SvXMLImportContext* createXFormsModelContext( + SvXMLImport& rImport, + sal_uInt16 nPrefix, + const OUString& rLocalName ) { - return new XFormsModelContext( rImport ); + return new XFormsModelContext( rImport, nPrefix, rLocalName ); } void bindXFormsValueBinding(Reference<XModel> const& xModel, |