/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
namespace
{ // a class that inherits from AttributeList, builds the internal data and then will be sliced off // during conversion to the base class class AttributeListBuilder
: public XmlStream::AttributeList
{ public: explicit AttributeListBuilder( const uno::Reference< xml::sax::XFastAttributeList >& a );
};
XmlStream::XmlStream()
: pos( 0 )
{ // make sure our extra bit does not conflict with values used by oox
assert( TAG_OPENING > ( 1024 << NMSP_SHIFT ));
}
XmlStream::Tag XmlStream::checkTag( int token, bool optional )
{ // either it's the following tag, or find it int savedPos = pos; if( optional )
{ // avoid printing debug messages about skipping tags if the optional one // will not be found and the position will be reset back if( currentToken() != token && !findTagInternal( token, true ))
{
pos = savedPos; return Tag();
}
} if( currentToken() == token || findTag( token ))
{
Tag ret = currentTag();
moveToNextTag(); return ret; // ok
} if( optional )
{ // not a problem, just rewind
pos = savedPos; return Tag();
}
SAL_WARN( "oox.xmlstream", "Expected tag " << tokenToString( token ) << " not found." ); return Tag();
}
bool XmlStream::findTagInternal( int token, bool silent )
{ int depth = 0; for(;
!atEnd();
moveToNextTag())
{ if( depth > 0 ) // we're inside a nested element, skip those
{ if( currentToken() == OPENING( currentToken()))
{ if( !silent )
SAL_INFO( "oox.xmlstream", "Skipping tag " << tokenToString( currentToken()));
++depth;
} elseif( currentToken() == CLOSING( currentToken()))
{ if( !silent )
SAL_INFO( "oox.xmlstream", "Skipping tag " << tokenToString( currentToken()));
--depth;
} else
{ if( !silent )
SAL_WARN( "oox.xmlstream", "Malformed token " << currentToken() << " ("
<< tokenToString( currentToken()) << ")" );
abort();
} continue;
} if( currentToken() == token ) returntrue; // ok, found if( currentToken() == CLOSING( currentToken())) returnfalse; // that would be leaving current element, so not found if( currentToken() == OPENING( currentToken()))
{ if( !silent )
SAL_INFO( "oox.xmlstream", "Skipping tag " << tokenToString( currentToken()));
++depth;
} else
abort();
} if( !silent )
SAL_WARN( "oox.xmlstream", "Unexpected end of stream reached." ); returnfalse;
}
void XmlStream::skipElementInternal( int token, bool silent )
{ int closing = ( token & ~TAG_OPENING ) | TAG_CLOSING; // make it a closing tag
assert( currentToken() == OPENING( token )); if( !silent )
SAL_INFO( "oox.xmlstream", "Skipping unexpected element " << tokenToString( currentToken()));
moveToNextTag(); // and just find the matching closing tag if( findTag( closing ))
{ if( !silent )
SAL_INFO( "oox.xmlstream", "Skipped unexpected element " << tokenToString( token ));
moveToNextTag(); // and skip it too return;
} // this one is an unexpected problem, do not silent it
SAL_WARN( "oox.xmlstream", "Expected end of element " << tokenToString( token ) << " not found." );
}
void XmlStream::handleUnexpectedTag()
{ if( atEnd()) return; if( currentToken() == CLOSING( currentToken()))
{
SAL_INFO( "oox.xmlstream", "Skipping unexpected tag " << tokenToString( currentToken()));
moveToNextTag(); // just skip it return;
}
skipElementInternal( currentToken(), false ); // otherwise skip the entire element
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.