sax: FastSaxSerializer: add well-formedness assertions
In an --enable-dbgutil build, assert on the following XML well-formedness violations: * Element Type Match (-> start/end tag mismatch) * Unique Att Spec (-> duplicate attributes) Change-Id: I1d5c405b4316ba941be1db7df6cacf00b5837261
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#if OSL_DEBUG_LEVEL > 0
|
#if OSL_DEBUG_LEVEL > 0
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <set>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using ::comphelper::SequenceAsVector;
|
using ::comphelper::SequenceAsVector;
|
||||||
@@ -123,6 +124,25 @@ namespace sax_fastparser {
|
|||||||
writeBytes(mxFastTokenHandler->getUTF8Identifier(nElement));
|
writeBytes(mxFastTokenHandler->getUTF8Identifier(nElement));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef DBG_UTIL
|
||||||
|
OString SAL_CALL FastSaxSerializer::getId( ::sal_Int32 nElement )
|
||||||
|
{
|
||||||
|
if (HAS_NAMESPACE(nElement)) {
|
||||||
|
Sequence<sal_Int8> const ns(
|
||||||
|
mxFastTokenHandler->getUTF8Identifier(NAMESPACE(nElement)));
|
||||||
|
Sequence<sal_Int8> const name(
|
||||||
|
mxFastTokenHandler->getUTF8Identifier(TOKEN(nElement)));
|
||||||
|
return OString(reinterpret_cast<sal_Char const*>(ns.getConstArray()), ns.getLength())
|
||||||
|
+ OString(reinterpret_cast<sal_Char const*>(maColon.getConstArray()), maColon.getLength())
|
||||||
|
+ OString(reinterpret_cast<sal_Char const*>(name.getConstArray()), name.getLength());
|
||||||
|
} else {
|
||||||
|
Sequence<sal_Int8> const name(
|
||||||
|
mxFastTokenHandler->getUTF8Identifier(nElement));
|
||||||
|
return OString(reinterpret_cast<sal_Char const*>(name.getConstArray()), name.getLength());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void SAL_CALL FastSaxSerializer::startFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs )
|
void SAL_CALL FastSaxSerializer::startFastElement( ::sal_Int32 Element, const Reference< XFastAttributeList >& Attribs )
|
||||||
throw (SAXException, RuntimeException)
|
throw (SAXException, RuntimeException)
|
||||||
{
|
{
|
||||||
@@ -132,6 +152,10 @@ namespace sax_fastparser {
|
|||||||
if ( !maMarkStack.empty() )
|
if ( !maMarkStack.empty() )
|
||||||
maMarkStack.top()->setCurrentElement( Element );
|
maMarkStack.top()->setCurrentElement( Element );
|
||||||
|
|
||||||
|
#ifdef DBG_UTIL
|
||||||
|
m_DebugStartedElements.push(Element);
|
||||||
|
#endif
|
||||||
|
|
||||||
writeBytes(toUnoSequence(maOpeningBracket));
|
writeBytes(toUnoSequence(maOpeningBracket));
|
||||||
|
|
||||||
writeId(Element);
|
writeId(Element);
|
||||||
@@ -146,6 +170,13 @@ namespace sax_fastparser {
|
|||||||
if (!mxOutputStream.is())
|
if (!mxOutputStream.is())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#ifdef DBG_UTIL
|
||||||
|
assert(!m_DebugStartedElements.empty());
|
||||||
|
// Well-formedness constraint: Element Type Match
|
||||||
|
assert(Element == m_DebugStartedElements.top());
|
||||||
|
m_DebugStartedElements.pop();
|
||||||
|
#endif
|
||||||
|
|
||||||
writeBytes(toUnoSequence(maOpeningBracketAndSlash));
|
writeBytes(toUnoSequence(maOpeningBracketAndSlash));
|
||||||
|
|
||||||
writeId(Element);
|
writeId(Element);
|
||||||
@@ -193,6 +224,9 @@ namespace sax_fastparser {
|
|||||||
}
|
}
|
||||||
void FastSaxSerializer::writeFastAttributeList( const Reference< XFastAttributeList >& Attribs )
|
void FastSaxSerializer::writeFastAttributeList( const Reference< XFastAttributeList >& Attribs )
|
||||||
{
|
{
|
||||||
|
#ifdef DBG_UTIL
|
||||||
|
::std::set<OUString> DebugAttributes;
|
||||||
|
#endif
|
||||||
Sequence< Attribute > aAttrSeq = Attribs->getUnknownAttributes();
|
Sequence< Attribute > aAttrSeq = Attribs->getUnknownAttributes();
|
||||||
const Attribute *pAttr = aAttrSeq.getConstArray();
|
const Attribute *pAttr = aAttrSeq.getConstArray();
|
||||||
sal_Int32 nAttrLength = aAttrSeq.getLength();
|
sal_Int32 nAttrLength = aAttrSeq.getLength();
|
||||||
@@ -200,7 +234,13 @@ namespace sax_fastparser {
|
|||||||
{
|
{
|
||||||
writeBytes(toUnoSequence(maSpace));
|
writeBytes(toUnoSequence(maSpace));
|
||||||
|
|
||||||
write(pAttr[i].Name);
|
OUString const& rAttrName(pAttr[i].Name);
|
||||||
|
#ifdef DBG_UTIL
|
||||||
|
// Well-formedness constraint: Unique Att Spec
|
||||||
|
assert(DebugAttributes.find(rAttrName) == DebugAttributes.end());
|
||||||
|
DebugAttributes.insert(rAttrName);
|
||||||
|
#endif
|
||||||
|
write(rAttrName);
|
||||||
writeBytes(toUnoSequence(maEqualSignAndQuote));
|
writeBytes(toUnoSequence(maEqualSignAndQuote));
|
||||||
write(escapeXml(pAttr[i].Value));
|
write(escapeXml(pAttr[i].Value));
|
||||||
writeBytes(toUnoSequence(maQuote));
|
writeBytes(toUnoSequence(maQuote));
|
||||||
@@ -216,6 +256,14 @@ namespace sax_fastparser {
|
|||||||
sal_Int32 nToken = pFastAttr[j].Token;
|
sal_Int32 nToken = pFastAttr[j].Token;
|
||||||
writeId(nToken);
|
writeId(nToken);
|
||||||
|
|
||||||
|
#ifdef DBG_UTIL
|
||||||
|
// Well-formedness constraint: Unique Att Spec
|
||||||
|
OUString const name(OStringToOUString(getId(nToken),
|
||||||
|
RTL_TEXTENCODING_UTF8));
|
||||||
|
assert(DebugAttributes.find(name) == DebugAttributes.end());
|
||||||
|
DebugAttributes.insert(name);
|
||||||
|
#endif
|
||||||
|
|
||||||
writeBytes(toUnoSequence(maEqualSignAndQuote));
|
writeBytes(toUnoSequence(maEqualSignAndQuote));
|
||||||
|
|
||||||
write(escapeXml(Attribs->getValue(pFastAttr[j].Token)));
|
write(escapeXml(Attribs->getValue(pFastAttr[j].Token)));
|
||||||
|
@@ -111,6 +111,7 @@ public:
|
|||||||
|
|
||||||
// C++ helpers
|
// C++ helpers
|
||||||
void SAL_CALL writeId( ::sal_Int32 Element );
|
void SAL_CALL writeId( ::sal_Int32 Element );
|
||||||
|
OString SAL_CALL getId( ::sal_Int32 Element );
|
||||||
|
|
||||||
static OUString escapeXml( const OUString& s );
|
static OUString escapeXml( const OUString& s );
|
||||||
|
|
||||||
@@ -207,6 +208,10 @@ private:
|
|||||||
::std::stack< boost::shared_ptr< ForMerge > > maMarkStack;
|
::std::stack< boost::shared_ptr< ForMerge > > maMarkStack;
|
||||||
::std::stack< boost::shared_ptr< ForMerge > > maSavedMarkStack;
|
::std::stack< boost::shared_ptr< ForMerge > > maSavedMarkStack;
|
||||||
|
|
||||||
|
#ifdef DBG_UTIL
|
||||||
|
::std::stack<sal_Int32> m_DebugStartedElements;
|
||||||
|
#endif
|
||||||
|
|
||||||
void writeFastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs );
|
void writeFastAttributeList( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& Attribs );
|
||||||
void write( const OUString& s );
|
void write( const OUString& s );
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user