From 25af31622377e8a6c63cff4ce051f66aa4638207 Mon Sep 17 00:00:00 2001 From: Khaled Noaman <knoaman@apache.org> Date: Thu, 3 May 2001 19:09:38 +0000 Subject: [PATCH] Support Warning/Error/FatalError messaging. Validity constraints errors are treated as errors, with the ability by user to set validity constraints as fatal errors. git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@172609 13f79535-47bb-0310-9956-ffa450edef68 --- src/framework/XMLErrorReporter.hpp | 7 +- src/framework/XMLValidator.cpp | 14 +- src/internal/XMLScanner.cpp | 238 +++++++++++++++++++---------- src/internal/XMLScanner.hpp | 49 ++++-- src/parsers/DOMParser.cpp | 10 ++ src/parsers/DOMParser.hpp | 30 ++++ src/parsers/SAXParser.cpp | 32 +++- src/parsers/SAXParser.hpp | 34 +++++ tools/NLS/Xlat/Xlat.cpp | 38 ++--- tools/NLS/Xlat/Xlat.hpp | 7 +- 10 files changed, 337 insertions(+), 122 deletions(-) diff --git a/src/framework/XMLErrorReporter.hpp b/src/framework/XMLErrorReporter.hpp index 1fba35e2f..d0700ec35 100644 --- a/src/framework/XMLErrorReporter.hpp +++ b/src/framework/XMLErrorReporter.hpp @@ -56,6 +56,11 @@ /* * $Log$ + * Revision 1.10 2001/05/03 19:08:56 knoaman + * Support Warning/Error/FatalError messaging. + * Validity constraints errors are treated as errors, with the ability by user to set + * validity constraints as fatal errors. + * * Revision 1.9 2000/12/14 18:49:57 tng * Fix API document generation warning: "Warning: end of member group without matching begin" * @@ -119,7 +124,7 @@ public: enum ErrTypes { ErrType_Warning - , ErrType_Invalid + , ErrType_Error , ErrType_Fatal , ErrTypes_Unknown diff --git a/src/framework/XMLValidator.cpp b/src/framework/XMLValidator.cpp index ee89af7a2..1f55cd93e 100644 --- a/src/framework/XMLValidator.cpp +++ b/src/framework/XMLValidator.cpp @@ -56,6 +56,11 @@ /** * $Log$ + * Revision 1.8 2001/05/03 19:08:58 knoaman + * Support Warning/Error/FatalError messaging. + * Validity constraints errors are treated as errors, with the ability by user to set + * validity constraints as fatal errors. + * * Revision 1.7 2001/03/21 21:56:02 tng * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar. * @@ -193,7 +198,8 @@ void XMLValidator::emitError(const XMLValid::Codes toEmit) } // Bail out if its fatal an we are to give up on the first fatal error - if ((XMLValid::isValid(toEmit) || XMLValid::isFatal(toEmit)) + if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal()) + || XMLValid::isFatal(toEmit)) && fScanner->getExitOnFirstFatal() && !fScanner->getInException()) { @@ -248,7 +254,8 @@ void XMLValidator::emitError(const XMLValid::Codes toEmit } // Bail out if its fatal an we are to give up on the first fatal error - if ((XMLValid::isValid(toEmit) || XMLValid::isFatal(toEmit)) + if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal()) + || XMLValid::isFatal(toEmit)) && fScanner->getExitOnFirstFatal() && !fScanner->getInException()) { @@ -303,7 +310,8 @@ void XMLValidator::emitError(const XMLValid::Codes toEmit } // Bail out if its fatal an we are to give up on the first fatal error - if ((XMLValid::isValid(toEmit) || XMLValid::isFatal(toEmit)) + if (((XMLValid::isError(toEmit) && fScanner->getValidationConstraintFatal()) + || XMLValid::isFatal(toEmit)) && fScanner->getExitOnFirstFatal() && !fScanner->getInException()) { diff --git a/src/internal/XMLScanner.cpp b/src/internal/XMLScanner.cpp index 053685960..df0346cc8 100644 --- a/src/internal/XMLScanner.cpp +++ b/src/internal/XMLScanner.cpp @@ -157,8 +157,11 @@ XMLScanner::XMLScanner(XMLValidator* const valToAdopt) : , fDocTypeHandler(0) , fDoNamespaces(false) , fEntityHandler(0) + , fEntityResolver(0) , fErrorReporter(0) + , fErrorHandler(0) , fExitOnFirstFatal(true) + , fValidationConstraintFatal(false) , fIDRefList(0) , fInException(false) , fRawAttrList(0) @@ -199,8 +202,11 @@ XMLScanner::XMLScanner( XMLDocumentHandler* const docHandler , fDocTypeHandler(docTypeHandler) , fDoNamespaces(false) , fEntityHandler(entityHandler) + , fEntityResolver(0) , fErrorReporter(errHandler) + , fErrorHandler(0) , fExitOnFirstFatal(true) + , fValidationConstraintFatal(false) , fIDRefList(0) , fInException(false) , fRawAttrList(0) @@ -889,7 +895,7 @@ void XMLScanner::resetEntityDeclPool() { fEntityDeclPool->put(new DTDEntityDecl(gApos, chSingleQuote, true, true)); } -void XMLScanner::resetURIPool() { +void XMLScanner::resetURIStringPool() { fURIStringPool->flushAll(); fEmptyNamespaceId = fURIStringPool->addOrFind(XMLUni::fgZeroLenString); @@ -1535,11 +1541,10 @@ void XMLScanner::scanEndTag(bool& gotData) return; } - unsigned int elemId; - unsigned int uriId = 0; + unsigned int uriId = fEmptyNamespaceId; + XMLBufBid bbName(&fBufMgr); if (fDoNamespaces) { - XMLBufBid bbName(&fBufMgr); XMLBufBid bbPrefix(&fBufMgr); uriId = resolveQName ( @@ -1548,25 +1553,6 @@ void XMLScanner::scanEndTag(bool& gotData) , bbPrefix.getBuffer() , ElemStack::Mode_Element ); - - // - // Ask the grammar for the element id for the {uri}name we got. He owns - // the element decl pool. - // - // It should be found in the current grammar, no need to switch grammar. - // If not found, it is an error (unbalanced element) - - elemId = fGrammar->getElemId - ( - uriId - , bbName.getBuffer().getRawBuffer() - , qnameBuf.getRawBuffer() - , 0 - ); - } - else - { - elemId = fGrammar->getElemId(fEmptyNamespaceId, 0, qnameBuf.getRawBuffer(), 0); } // @@ -1579,23 +1565,38 @@ void XMLScanner::scanEndTag(bool& gotData) // const ElemStack::StackElem* topElem = fElemStack.popTop(); + // See if it was the root element, to avoid multiple calls below + const bool isRoot = fElemStack.isEmpty(); + // Make sure that its the end of the element that we expect - if (topElem->fThisElement->getId() != elemId) - { - emitError - ( - XMLErrs::ExpectedEndOfTagX - , topElem->fThisElement->getFullName() - ); + XMLElementDecl* tempElement = topElem->fThisElement; + if (fDoNamespaces) { + if ((tempElement->getURI() != uriId) || + (XMLString::compareString(tempElement->getBaseName(), bbName.getRawBuffer()))) + { + emitError + ( + XMLErrs::ExpectedEndOfTagX + , topElem->fThisElement->getFullName() + ); + } + } + else { + if (XMLString::compareString(tempElement->getFullName(), qnameBuf.getRawBuffer())) + { + emitError + ( + XMLErrs::ExpectedEndOfTagX + , topElem->fThisElement->getFullName() + ); + } } + // Make sure we are back on the same reader as where we started if (topElem->fReaderNum != fReaderMgr.getCurrentReaderNum()) emitError(XMLErrs::PartialTagMarkupError); - // See if it was the root element, to avoid multiple calls below - const bool isRoot = fElemStack.isEmpty(); - // Skip optional whitespace fReaderMgr.skipPastSpaces(); @@ -1628,7 +1629,7 @@ void XMLScanner::scanEndTag(bool& gotData) { int res = fValidator->checkContent ( - topElem->fThisElement->getId() + topElem->fThisElement , topElem->fChildren , topElem->fChildCount ); @@ -1660,19 +1661,10 @@ void XMLScanner::scanEndTag(bool& gotData) } else { - // Find the element decl for the evil spawn - XMLElementDecl* decl = fGrammar->getElemDecl - ( - topElem->fChildren[res]->getURI() - , topElem->fChildren[res]->getLocalPart() - , topElem->fChildren[res]->getRawName() - , 0 - ); - fValidator->emitError ( XMLValid::ElementNotValidForContent - , decl->getFullName() + , topElem->fChildren[res]->getRawName() , topElem->fThisElement->getFormattedContentModel() ); } @@ -1682,17 +1674,22 @@ void XMLScanner::scanEndTag(bool& gotData) // If this was the root, then done with content gotData = !isRoot; - if (gotData && fDoNamespaces) { - // Restore the grammar - const ElemStack::StackElem* topElem2 = fElemStack.topElement(); - XMLBuffer bufURI; - getURIText(topElem2->fThisElement->getURI(), bufURI); - if (!switchGrammar(bufURI.getRawBuffer()) && fValidate) - fValidator->emitError - ( - XMLValid::GrammarNotFound - , bufURI.getRawBuffer() - ); + if (gotData) { + if (fDoNamespaces) { + // Restore the grammar + const ElemStack::StackElem* topElem2 = fElemStack.topElement(); + XMLBuffer bufURI; + getURIText(topElem2->fThisElement->getURI(), bufURI); + if (!switchGrammar(bufURI.getRawBuffer()) && fValidate) + fValidator->emitError + ( + XMLValid::GrammarNotFound + , bufURI.getRawBuffer() + ); + } + + // Restore the validation flag + fValidate = fElemStack.getValidationFlag(); } } @@ -2067,14 +2064,14 @@ bool XMLScanner::scanStartTag(bool& gotData) // // We tell him to fault in a decl if he does not find one. // - bool wasAdded; + bool wasAdded = false; XMLElementDecl* elemDecl = fGrammar->findOrAddElemDecl ( fEmptyNamespaceId , 0 , 0 , fQNameBuf.getRawBuffer() - , 0 + , Grammar::TOP_LEVEL_SCOPE , wasAdded ); @@ -2124,6 +2121,7 @@ bool XMLScanner::scanStartTag(bool& gotData) // Expand the element stack and add the new element fElemStack.addLevel(elemDecl, fReaderMgr.getCurrentReaderNum()); + fElemStack.setValidationFlag(fValidate); // // If this is the first element and we are validating, check the root @@ -2258,6 +2256,7 @@ bool XMLScanner::scanStartTag(bool& gotData) // not validating of course it will not be at first, but we will // fault it into the pool (to avoid lots of redundant errors.) // + wasAdded = false; XMLAttDef* attDef = elemDecl->findAttr ( fAttNameBuf.getRawBuffer() @@ -2386,7 +2385,7 @@ bool XMLScanner::scanStartTag(bool& gotData) { fValidator->validateAttrValue ( - *attDef + attDef , fAttValueBuf.getRawBuffer() ); } @@ -2568,7 +2567,7 @@ bool XMLScanner::scanStartTag(bool& gotData) // If validating, then insure that its legal to have no content if (fValidate) { - const int res = fValidator->checkContent(elemDecl->getId(), 0, 0); + const int res = fValidator->checkContent(elemDecl, 0, 0); if (res >= 0) { fValidator->emitError @@ -2681,12 +2680,28 @@ bool XMLScanner::scanStartTagNS(bool& gotData) ); const bool gotAttrs = (attCount != 0); + // save the contentleafname and currentscope before addlevel, for later use + ContentLeafNameTypeVector* cv = 0; + int currentScope = Grammar::TOP_LEVEL_SCOPE; + if (!isRoot && fGrammar->getGrammarType() == Grammar::SchemaGrammarType) { + SchemaElementDecl* tempElement = (SchemaElementDecl*) fElemStack.topElement()->fThisElement; + SchemaElementDecl::ModelTypes modelType = tempElement->getModelType(); + + if ((modelType == SchemaElementDecl::Mixed) + || (modelType == SchemaElementDecl::Children)) + { + cv = tempElement->getContentModel()->getContentLeafNameTypeVector(); + currentScope = fElemStack.getCurrentScope(); + } + } + // // Now, since we might have to update the namespace map for this element, // but we don't have the element decl yet, we just tell the element stack // to expand up to get ready. // fElemStack.addLevel(); + fElemStack.setValidationFlag(fValidate); // // Make an initial pass through the list and find any xmlns attributes or @@ -2703,9 +2718,9 @@ bool XMLScanner::scanStartTagNS(bool& gotData) XMLElementDecl* elemDecl = fGrammar->getElemDecl ( fEmptyNamespaceId - , fNameBuf.getRawBuffer() - , fQNameBuf.getRawBuffer() , 0 + , fQNameBuf.getRawBuffer() + , Grammar::TOP_LEVEL_SCOPE ); if (elemDecl) { if (elemDecl->hasAttDefs()) { @@ -2743,6 +2758,13 @@ bool XMLScanner::scanStartTagNS(bool& gotData) , ElemStack::Mode_Element ); + //if schema, check if we should lax or skip the validation of this element + bool laxThisOne = false; + if (cv) { + QName element(fPrefixBuf.getRawBuffer(), fNameBuf.getRawBuffer(), uriId); + laxThisOne = laxElementValidation(&element, cv); + } + // // Look up the element now in the grammar. This will get us back a // generic element decl object. We tell him to fault one in if he does @@ -2754,7 +2776,7 @@ bool XMLScanner::scanStartTagNS(bool& gotData) if (uriId != fEmptyNamespaceId) { XMLBuffer bufURI; getURIText(uriId, bufURI); - if (!switchGrammar(bufURI.getRawBuffer()) && fValidate) + if (!switchGrammar(bufURI.getRawBuffer()) && fValidate && !laxThisOne) { fValidator->emitError ( @@ -2762,15 +2784,25 @@ bool XMLScanner::scanStartTagNS(bool& gotData) , bufURI.getRawBuffer() ); } - elemDecl = fGrammar->findOrAddElemDecl - ( - uriId - , fNameBuf.getRawBuffer() - , fPrefixBuf.getRawBuffer() - , fQNameBuf.getRawBuffer() - , 0 - , wasAdded - ); + elemDecl = fGrammar->getElemDecl + ( + uriId + , fNameBuf.getRawBuffer() + , fQNameBuf.getRawBuffer() + , currentScope + ); + if (!elemDecl) { + // if not found, then it may be a reference, try TOP_LEVEL_SCOPE + elemDecl = fGrammar->findOrAddElemDecl + ( + uriId + , fNameBuf.getRawBuffer() + , fPrefixBuf.getRawBuffer() + , fQNameBuf.getRawBuffer() + , Grammar::TOP_LEVEL_SCOPE + , wasAdded + ); + } } else { @@ -2782,12 +2814,23 @@ bool XMLScanner::scanStartTagNS(bool& gotData) uriId , fNameBuf.getRawBuffer() , fQNameBuf.getRawBuffer() - , 0 + , currentScope ); + if (!elemDecl) { + // if not found, then it may be a reference, try TOP_LEVEL_SCOPE + elemDecl = fGrammar->getElemDecl + ( + uriId + , fNameBuf.getRawBuffer() + , fQNameBuf.getRawBuffer() + , Grammar::TOP_LEVEL_SCOPE + ); + } + if (!elemDecl) { - if (!switchGrammar(XMLUni::fgZeroLenString) && fValidate) + if (!switchGrammar(XMLUni::fgZeroLenString) && fValidate && !laxThisOne) { fValidator->emitError ( @@ -2795,15 +2838,27 @@ bool XMLScanner::scanStartTagNS(bool& gotData) , XMLUni::fgZeroLenString ); } - elemDecl = fGrammar->findOrAddElemDecl - ( - uriId - , fNameBuf.getRawBuffer() - , fPrefixBuf.getRawBuffer() - , fQNameBuf.getRawBuffer() - , 0 - , wasAdded - ); + + elemDecl = fGrammar->getElemDecl + ( + uriId + , fNameBuf.getRawBuffer() + , fQNameBuf.getRawBuffer() + , currentScope + ); + + if (!elemDecl) { + // if not found, then it may be a reference, try TOP_LEVEL_SCOPE + elemDecl = fGrammar->findOrAddElemDecl + ( + uriId + , fNameBuf.getRawBuffer() + , fPrefixBuf.getRawBuffer() + , fQNameBuf.getRawBuffer() + , Grammar::TOP_LEVEL_SCOPE + , wasAdded + ); + } } } @@ -2813,11 +2868,16 @@ bool XMLScanner::scanStartTagNS(bool& gotData) // if (wasAdded) { + if (laxThisOne) { + fValidate = false; + fElemStack.setValidationFlag(fValidate); + } + // If validating then emit an error if (fValidate) { // This is to tell the reuse Validator that this element was - // faulted-in, was not an element in the validator pool originally + // faulted-in, was not an element in the grammar pool originally elemDecl->setCreateReason(XMLElementDecl::JustFaultIn); fValidator->emitError @@ -2848,12 +2908,22 @@ bool XMLScanner::scanStartTagNS(bool& gotData) } } + // Validate the element + if (fValidate) + fValidator->validateElement(elemDecl); + // // Now we can update the element stack to set the current element // decl. We expanded the stack above, but couldn't store the element // decl because we didn't know it yet. // fElemStack.setElement(elemDecl, fReaderMgr.getCurrentReaderNum()); + if (fGrammar->getGrammarType() == Grammar::SchemaGrammarType) { + ComplexTypeInfo* typeinfo = ((SchemaElementDecl*)elemDecl)->getComplexTypeInfo(); + if (typeinfo) + currentScope = typeinfo->getScopeDefined(); + fElemStack.setCurrentScope(currentScope); + } // // If this is the first element and we are validating, check the root @@ -2903,7 +2973,7 @@ bool XMLScanner::scanStartTagNS(bool& gotData) // If validating, then insure that its legal to have no content if (fValidate) { - const int res = fValidator->checkContent(elemDecl->getId(), 0, 0); + const int res = fValidator->checkContent(elemDecl, 0, 0); if (res >= 0) { fValidator->emitError diff --git a/src/internal/XMLScanner.hpp b/src/internal/XMLScanner.hpp index ead9cc7db..3fa02e055 100644 --- a/src/internal/XMLScanner.hpp +++ b/src/internal/XMLScanner.hpp @@ -56,6 +56,11 @@ /* * $Log$ + * Revision 1.15 2001/05/03 19:09:09 knoaman + * Support Warning/Error/FatalError messaging. + * Validity constraints errors are treated as errors, with the ability by user to set + * validity constraints as fatal errors. + * * Revision 1.14 2001/04/19 18:16:59 tng * Schema: SchemaValidator update, and use QName in Content Model * @@ -266,6 +271,7 @@ public : const XMLErrorReporter* getErrorReporter() const; XMLErrorReporter* getErrorReporter(); bool getExitOnFirstFatal() const; + bool getValidationConstraintFatal() const; RefHashTableOf<XMLRefInfo>& getIDRefList(); bool getInException() const; const RefHashTableOf<XMLRefInfo>& getIDRefList() const; @@ -293,6 +299,8 @@ public : const XMLCh* const entName ); NameIdPoolEnumerator<DTDEntityDecl> getEntityEnumerator() const; + const XMLStringPool* getURIStringPool() const; + XMLStringPool* getURIStringPool(); // ----------------------------------------------------------------------- // Getter methods @@ -374,6 +382,7 @@ public : void setErrorReporter(XMLErrorReporter* const errHandler); void setErrorHandler(ErrorHandler* const handler); void setExitOnFirstFatal(const bool newValue); + void setValidationConstraintFatal(const bool newValue); void setValidationScheme(const ValSchemes newScheme); void setValidator(XMLValidator* const valToAdopt); void setDoSchema(const bool doSchema); @@ -457,7 +466,7 @@ private : void commonInit(); void initValidator(); void resetEntityDeclPool(); - void resetURIPool(); + void resetURIStringPool(); // ----------------------------------------------------------------------- @@ -509,20 +518,12 @@ private : const XMLCh* const attrName , const XMLCh* const attrValue ); - void validateAttrValue - ( - const XMLCh* const valueText - , const XMLAttDef::AttTypes type - , const XMLAttDef::DefAttTypes defType - , const XMLCh* const defText - , const XMLCh* const fullName - , const XMLCh* const enumList - ); void scanRawAttrListforNameSpaces(const RefVectorOf<KVStringPair>* theRawAttrList, int attCount); void parseSchemaLocation(const XMLCh* const schemaLocationStr); void resolveSchemaGrammar(const XMLCh* const loc, const XMLCh* const uri); bool switchGrammar(int newGrammarNameSpaceIndex); bool switchGrammar(const XMLCh* const newGrammarNameSpace); + bool laxElementValidation(QName* element, ContentLeafNameTypeVector* cv); // ----------------------------------------------------------------------- // Private scanning methods @@ -626,6 +627,10 @@ private : // or not. It defaults to true, which is the strict XML way, but it // can be changed. // + // fValidationConstraintFatal + // This indicates whether we treat validation constraint errors as + // fatal errors or not. It defaults to false, but it can be changed. + // // fIDRefList // This is a list of XMLRefInfo objects. This member lets us do all // needed ID-IDREF balancing checks. @@ -739,6 +744,7 @@ private : XMLErrorReporter* fErrorReporter; ErrorHandler* fErrorHandler; bool fExitOnFirstFatal; + bool fValidationConstraintFatal; RefHashTableOf<XMLRefInfo>* fIDRefList; bool fInException; RefVectorOf<KVStringPair>* fRawAttrList; @@ -827,6 +833,11 @@ inline bool XMLScanner::getExitOnFirstFatal() const return fExitOnFirstFatal; } +inline bool XMLScanner::getValidationConstraintFatal() const +{ + return fValidationConstraintFatal; +} + inline RefHashTableOf<XMLRefInfo>& XMLScanner::getIDRefList() { return *fIDRefList; @@ -917,6 +928,17 @@ inline DTDEntityDecl* XMLScanner::getEntityDecl(const XMLCh* const entName) { return fEntityDeclPool->getByKey(entName); } + +inline const XMLStringPool* XMLScanner::getURIStringPool() const +{ + return fURIStringPool; +} + +inline XMLStringPool* XMLScanner::getURIStringPool() +{ + return fURIStringPool; +} + // --------------------------------------------------------------------------- // XMLScanner: Setter methods // --------------------------------------------------------------------------- @@ -936,7 +958,7 @@ inline void XMLScanner::setDoNamespaces(const bool doNamespaces) if (fDoNamespaces) { if (!fURIStringPool) { fURIStringPool = new XMLStringPool(); - resetURIPool(); + resetURIStringPool(); } } } @@ -967,6 +989,11 @@ inline void XMLScanner::setExitOnFirstFatal(const bool newValue) fExitOnFirstFatal = newValue; } +inline void XMLScanner::setValidationConstraintFatal(const bool newValue) +{ + fValidationConstraintFatal = newValue; +} + inline void XMLScanner::setValidationScheme(const ValSchemes newScheme) { fValScheme = newScheme; diff --git a/src/parsers/DOMParser.cpp b/src/parsers/DOMParser.cpp index fe1462546..476722509 100644 --- a/src/parsers/DOMParser.cpp +++ b/src/parsers/DOMParser.cpp @@ -164,6 +164,11 @@ bool DOMParser::getExitOnFirstFatalError() const return fScanner->getExitOnFirstFatal(); } +bool DOMParser::getValidationConstraintFatal() const +{ + return fScanner->getValidationConstraintFatal(); +} + DOMParser::ValSchemes DOMParser::getValidationScheme() const { const XMLScanner::ValSchemes scheme = fScanner->getValidationScheme(); @@ -221,6 +226,11 @@ void DOMParser::setExitOnFirstFatalError(const bool newState) fScanner->setExitOnFirstFatal(newState); } +void DOMParser::setValidationConstraintFatal(const bool newState) +{ + fScanner->setValidationConstraintFatal(newState); +} + void DOMParser::setValidationScheme(const ValSchemes newScheme) { if (newScheme == Val_Never) diff --git a/src/parsers/DOMParser.hpp b/src/parsers/DOMParser.hpp index d9bd79781..6f7c9b9da 100644 --- a/src/parsers/DOMParser.hpp +++ b/src/parsers/DOMParser.hpp @@ -260,6 +260,19 @@ public : */ bool getExitOnFirstFatalError() const; + /** + * This method returns the state of the parser's + * validation-constraint-fatal flag. + * + * @return true, if the parser is currently configured to + * set validation constraint errors as fatal, false + * otherwise. + * + * @see #setValidationContraintFatal + */ + bool getValidationConstraintFatal() const; + //@} + /** Get the 'expand entity references' flag. * DEPRECATED Use getCreateEntityReferenceNodes() instead. * @@ -396,6 +409,23 @@ public : */ void setExitOnFirstFatalError(const bool newState); + /** + * This method allows users to set the parser's behaviour when it + * encounters a validtion constraint error. If set to true, and the + * the parser is set to exit when it encounter the first fatal error, + * the parser will exit at the first encounter. If false, then it will + * report the error and continue processing. + * + * <p>The default value is 'false'.</p> + * + * @param newState The value specifying whether the parser should + * continue or exit when it encounters a validation + * constraint error. + * + * @see #getValidationConstraintFatal + */ + void setValidationConstraintFatal(const bool newState); + /** Set the 'expand entity references' flag * * DEPRECATED. USE setCreateEntityReferenceNodes instead. diff --git a/src/parsers/SAXParser.cpp b/src/parsers/SAXParser.cpp index b50f52228..be189c43f 100644 --- a/src/parsers/SAXParser.cpp +++ b/src/parsers/SAXParser.cpp @@ -56,6 +56,11 @@ /* * $Log$ + * Revision 1.18 2001/05/03 19:09:23 knoaman + * Support Warning/Error/FatalError messaging. + * Validity constraints errors are treated as errors, with the ability by user to set + * validity constraints as fatal errors. + * * Revision 1.17 2001/03/30 16:46:57 tng * Schema: Use setDoSchema instead of setSchemaValidation which makes more sense. * @@ -285,6 +290,11 @@ bool SAXParser::getExitOnFirstFatalError() const return fScanner->getExitOnFirstFatal(); } +bool SAXParser::getValidationConstraintFatal() const +{ + return fScanner->getValidationConstraintFatal(); +} + SAXParser::ValSchemes SAXParser::getValidationScheme() const { @@ -319,6 +329,12 @@ void SAXParser::setExitOnFirstFatalError(const bool newState) } +void SAXParser::setValidationConstraintFatal(const bool newState) +{ + fScanner->setValidationConstraintFatal(newState); +} + + void SAXParser::setValidationScheme(const ValSchemes newScheme) { if (newScheme == Val_Never) @@ -439,20 +455,28 @@ void SAXParser::setErrorHandler(ErrorHandler* const handler) // error reporter on the scanner. // fErrorHandler = handler; - if (fErrorHandler) + if (fErrorHandler) { fScanner->setErrorReporter(this); - else + fScanner->setErrorHandler(fErrorHandler); + } + else { fScanner->setErrorReporter(0); + fScanner->setErrorHandler(0); + } } void SAXParser::setEntityResolver(EntityResolver* const resolver) { fEntityResolver = resolver; - if (fEntityResolver) + if (fEntityResolver) { fScanner->setEntityHandler(this); - else + fScanner->setEntityResolver(fEntityResolver); + } + else { fScanner->setEntityHandler(0); + fScanner->setEntityResolver(0); + } } diff --git a/src/parsers/SAXParser.hpp b/src/parsers/SAXParser.hpp index 66f7b20fe..09f05f5e5 100644 --- a/src/parsers/SAXParser.hpp +++ b/src/parsers/SAXParser.hpp @@ -56,6 +56,11 @@ /* * $Log$ + * Revision 1.14 2001/05/03 19:09:25 knoaman + * Support Warning/Error/FatalError messaging. + * Validity constraints errors are treated as errors, with the ability by user to set + * validity constraints as fatal errors. + * * Revision 1.13 2001/03/30 16:46:57 tng * Schema: Use setDoSchema instead of setSchemaValidation which makes more sense. * @@ -284,6 +289,18 @@ public : * @see #setExitOnFirstFatalError */ bool getExitOnFirstFatalError() const; + + /** + * This method returns the state of the parser's + * validation-constraint-fatal flag. + * + * @return true, if the parser is currently configured to + * set validation constraint errors as fatal, false + * otherwise. + * + * @see #setValidationContraintFatal + */ + bool getValidationConstraintFatal() const; //@} @@ -362,6 +379,23 @@ public : * @see #getExitOnFirstFatalError */ void setExitOnFirstFatalError(const bool newState); + + /** + * This method allows users to set the parser's behaviour when it + * encounters a validtion constraint error. If set to true, and the + * the parser is set to exit when it encounter the first fatal error, + * the parser will exit at the first encounter. If false, then it will + * report the error and continue processing. + * + * <p>The default value is 'false'.</p> + * + * @param newState The value specifying whether the parser should + * continue or exit when it encounters a validation + * constraint error. + * + * @see #getValidationConstraintFatal + */ + void setValidationConstraintFatal(const bool newState); //@} diff --git a/tools/NLS/Xlat/Xlat.cpp b/tools/NLS/Xlat/Xlat.cpp index 1a20cf113..cd29ad3e2 100644 --- a/tools/NLS/Xlat/Xlat.cpp +++ b/tools/NLS/Xlat/Xlat.cpp @@ -57,6 +57,11 @@ /* * $Log$ + * Revision 1.8 2001/05/03 19:09:36 knoaman + * Support Warning/Error/FatalError messaging. + * Validity constraints errors are treated as errors, with the ability by user to set + * validity constraints as fatal errors. + * * Revision 1.7 2000/03/18 00:00:58 roddey * Improved error reporting * @@ -129,7 +134,7 @@ const XMLCh* typePrefixes[MsgTypes_Count] = { L"W_" , L"E_" - , L"V_" + , L"F_" }; @@ -598,20 +603,17 @@ extern "C" int wmain(int argC, XMLCh** argV) } else if (typeName.equals(L"Error")) { - if (!XMLString::compareString(domainStr.rawBuffer(), XMLUni::fgValidityDomain)) - { - type = MsgType_Validity; - typeGotten[2] = true; - } - else - { - type = MsgType_Error; - typeGotten[1] = true; - } + type = MsgType_Error; + typeGotten[1] = true; + } + else if (typeName.equals(L"FatalError")) + { + type = MsgType_FatalError; + typeGotten[2] = true; } else { - wprintf(L"Expected a Warning or Errornode\n\n"); + wprintf(L"Expected a Warning, Error, or FatalError node\n\n"); throw ErrReturn_SrcFmtError; } @@ -680,7 +682,7 @@ extern "C" int wmain(int argC, XMLCh** argV) outHeader , L" static bool isFatal(const %s::Codes toCheck)\n" L" {\n" - L" return ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds));\n" + L" return ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds));\n" L" }\n\n" , errNameSpace ); @@ -698,9 +700,9 @@ extern "C" int wmain(int argC, XMLCh** argV) fwprintf ( outHeader - , L" static bool isValid(const %s::Codes toCheck)\n" + , L" static bool isError(const %s::Codes toCheck)\n" L" {\n" - L" return ((toCheck >= V_LowBounds) && (toCheck <= V_HighBounds));\n" + L" return ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds));\n" L" }\n\n" , errNameSpace ); @@ -712,10 +714,10 @@ extern "C" int wmain(int argC, XMLCh** argV) L" {\n" L" if ((toCheck >= W_LowBounds) && (toCheck <= W_HighBounds))\n" L" return XMLErrorReporter::ErrType_Warning;\n" - L" else if ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds))\n" + L" else if ((toCheck >= F_LowBounds) && (toCheck <= F_HighBounds))\n" L" return XMLErrorReporter::ErrType_Fatal;\n" - L" else if ((toCheck >= V_LowBounds) && (toCheck <= V_HighBounds))\n" - L" return XMLErrorReporter::ErrType_Invalid;\n" + L" else if ((toCheck >= E_LowBounds) && (toCheck <= E_HighBounds))\n" + L" return XMLErrorReporter::ErrType_Error;\n" L" return XMLErrorReporter::ErrTypes_Unknown;\n" L" }\n" , errNameSpace diff --git a/tools/NLS/Xlat/Xlat.hpp b/tools/NLS/Xlat/Xlat.hpp index d8bfc626a..dafd44876 100644 --- a/tools/NLS/Xlat/Xlat.hpp +++ b/tools/NLS/Xlat/Xlat.hpp @@ -56,6 +56,11 @@ /* * $Log$ + * Revision 1.4 2001/05/03 19:09:38 knoaman + * Support Warning/Error/FatalError messaging. + * Validity constraints errors are treated as errors, with the ability by user to set + * validity constraints as fatal errors. + * * Revision 1.3 2000/03/02 19:55:53 roddey * This checkin includes many changes done while waiting for the * 1.1.0 code to be finished. I can't list them all here, but a list is @@ -80,7 +85,7 @@ enum MsgTypes { MsgType_Warning , MsgType_Error - , MsgType_Validity + , MsgType_FatalError , MsgTypes_Count }; -- GitLab