From a15cf65c44d5c224169c32ef5495b68c758134b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 18 May 2014 16:08:14 +0200 Subject: Imported Upstream version 3.3.0.2 --- libxsd-frontend/xsd-frontend/schema-dom-parser.cxx | 196 +++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 libxsd-frontend/xsd-frontend/schema-dom-parser.cxx (limited to 'libxsd-frontend/xsd-frontend/schema-dom-parser.cxx') diff --git a/libxsd-frontend/xsd-frontend/schema-dom-parser.cxx b/libxsd-frontend/xsd-frontend/schema-dom-parser.cxx new file mode 100644 index 0000000..452980c --- /dev/null +++ b/libxsd-frontend/xsd-frontend/schema-dom-parser.cxx @@ -0,0 +1,196 @@ +// file : xsd-frontend/schema-dom-parser.cxx +// author : Boris Kolpackov +// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC +// license : GNU GPL v2 + exceptions; see accompanying LICENSE file + +#include + +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include + +namespace XSDFrontend +{ + namespace XML + { + using namespace Xerces; + + const XMLCh line_key[2] = {chLatin_l, chNull}; + const XMLCh column_key[2] = {chLatin_c, chNull}; + + SchemaDOMParser:: + SchemaDOMParser (MemoryManager* mgr) + : XercesDOMParser(0, mgr, 0), + depth_ (-1), + ann_depth_ (-1), + inner_ann_depth_ (-1) + { + error_reporter_.setErrorReporter (this); + setValidationScheme (XercesDOMParser::Val_Never); + setDoNamespaces (true); + } + + void SchemaDOMParser:: + startElement (const XMLElementDecl& decl, + const unsigned int url_id, + const XMLCh* const prefix, + const RefVectorOf& attributes, +#if _XERCES_VERSION >= 30000 + const XMLSize_t attr_count, +#else + const unsigned int attr_count, +#endif + const bool empty, + const bool root) + { + depth_++; + + if (ann_depth_ == -1) + { + if (XMLString::equals(decl.getBaseName(), + SchemaSymbols::fgELT_ANNOTATION) && + XMLString::equals(getURIText(url_id), + SchemaSymbols::fgURI_SCHEMAFORSCHEMA)) + { + ann_depth_ = depth_; + } + } + else if (depth_ == ann_depth_ + 1) + { + inner_ann_depth_ = depth_; + } + + XercesDOMParser::startElement ( + decl, url_id, prefix, attributes, attr_count, false, root); + + // Set the line/column info. + // + ReaderMgr::LastExtEntityInfo info; + ((ReaderMgr*) fScanner->getLocator())->getLastExtEntityInfo(info); + +#if _XERCES_VERSION >= 30000 + unsigned long l (static_cast (info.lineNumber)); + unsigned long c (static_cast (info.colNumber)); +#else + unsigned long l (info.lineNumber == -1 + ? 0UL + : static_cast (info.lineNumber)); + + unsigned long c (info.colNumber == -1 + ? 0UL + : static_cast (info.colNumber)); +#endif + + fCurrentNode->setUserData (line_key, reinterpret_cast (l), 0); + fCurrentNode->setUserData (column_key, reinterpret_cast (c), 0); + + // If an empty element, call the endElement() now. + // + if (empty) + endElement (decl, url_id, root, prefix); + } + + void SchemaDOMParser:: + endElement (const XMLElementDecl& decl, + const unsigned int url_id, + const bool root, + const XMLCh* const prefix) + { + if(ann_depth_ > -1) + { + if (inner_ann_depth_ == depth_) + { + inner_ann_depth_ = -1; + } + else if (ann_depth_ == depth_) + { + ann_depth_ = -1; + } + } + + depth_--; + + XercesDOMParser::endElement (decl, url_id, root, prefix); + } + + void SchemaDOMParser:: + docCharacters (const XMLCh* const s, +#if _XERCES_VERSION >= 30000 + const XMLSize_t length, +#else + const unsigned int length, +#endif + const bool cdata) + { + // Ignore chars outside of content. + // + if (!fWithinElement) + return; + + if (inner_ann_depth_ == -1) + { + if (!((ReaderMgr*) fScanner->getReaderMgr())->getCurrentReader()-> + isAllSpaces(s, length)) + { + ReaderMgr::LastExtEntityInfo lastInfo; + fScanner->getReaderMgr()->getLastExtEntityInfo(lastInfo); + locator_.setValues(lastInfo.systemId, lastInfo.publicId, + lastInfo.lineNumber, lastInfo.colNumber); + error_reporter_.emitError(XMLValid::NonWSContent, + XMLUni::fgValidityDomain, + &locator_); + } + } + else + { + // When it's within either of the 2 annotation sub-elements, + // characters are allowed and we need to store them. + // + XercesDOMParser::docCharacters (s, length, cdata); + } + } + + void SchemaDOMParser:: + docComment (const XMLCh* const) + { + // We don't want any comments. + } + + void SchemaDOMParser:: + startEntityReference (const XMLEntityDecl&) + { + } + + void SchemaDOMParser:: + endEntityReference (const XMLEntityDecl&) + { + } + + void SchemaDOMParser:: + ignorableWhitespace (const XMLCh* const s, +#if _XERCES_VERSION >= 30000 + const XMLSize_t length, +#else + const unsigned int length, +#endif + const bool cdata) + { + // Ignore chars before the root element. + // + if (!fWithinElement || !fIncludeIgnorableWhitespace) + return; + + if (ann_depth_ > -1) + XercesDOMParser::ignorableWhitespace (s, length, cdata); + } + } +} -- cgit v1.2.3