what is this and why was it sent to me? -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, August 13, 2001 11:07 AM To: [EMAIL PROTECTED] Subject: cvs commit: xml-xerces/c/src/validators/common DFAContentModel.hpp MixedContentModel.hpp SimpleContentModel.hpp
knoaman 01/08/13 08:06:39 Modified: c/src/framework XMLContentModel.hpp c/src/internal XMLScanner.cpp XMLScanner.hpp XMLScanner2.cpp c/src/validators/common DFAContentModel.hpp MixedContentModel.hpp SimpleContentModel.hpp Log: update <any> validation. Revision Changes Path 1.12 +6 -0 xml-xerces/c/src/framework/XMLContentModel.hpp Index: XMLContentModel.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/framework/XMLContentModel.hpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- XMLContentModel.hpp 2001/05/28 20:53:35 1.11 +++ XMLContentModel.hpp 2001/08/13 15:06:38 1.12 @@ -56,6 +56,9 @@ /* * $Log: XMLContentModel.hpp,v $ + * Revision 1.12 2001/08/13 15:06:38 knoaman + * update <any> validation. + * * Revision 1.11 2001/05/28 20:53:35 tng * Schema: move static data gInvalidTrans, gEOCFakeId, gEpsilonFakeId to XMLContentModel for others to access * @@ -171,6 +174,9 @@ virtual ContentLeafNameTypeVector* getContentLeafNameTypeVector() const = 0; + + virtual unsigned int getNextState(const unsigned int currentState, + const unsigned int elementIndex) const = 0; protected : // ----------------------------------------------------------------------- 1.60 +81 -36 xml-xerces/c/src/internal/XMLScanner.cpp Index: XMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.cpp,v retrieving revision 1.59 retrieving revision 1.60 diff -u -r1.59 -r1.60 --- XMLScanner.cpp 2001/08/07 13:47:47 1.59 +++ XMLScanner.cpp 2001/08/13 15:06:39 1.60 @@ -55,7 +55,7 @@ */ /* - * $Id: XMLScanner.cpp,v 1.59 2001/08/07 13:47:47 tng Exp $ + * $Id: XMLScanner.cpp,v 1.60 2001/08/13 15:06:39 knoaman Exp $ */ @@ -153,38 +153,41 @@ // --------------------------------------------------------------------------- XMLScanner::XMLScanner(XMLValidator* const valToAdopt) : - fAttrList(0) - , fDocHandler(0) - , fDocTypeHandler(0) - , fDoNamespaces(false) - , fEntityHandler(0) - , fEntityResolver(0) - , fErrorReporter(0) - , fErrorHandler(0) + fDoNamespaces(false) , fExitOnFirstFatal(true) , fValidationConstraintFatal(false) - , fIDRefList(0) , fInException(false) - , fRawAttrList(0) , fReuseGrammar(false) - , fScannerId(0) - , fSequenceId(0) , fStandalone(false) , fHasNoDTD(true) , fValidate(false) - , fValidator(valToAdopt) - , fDTDValidator(0) - , fSchemaValidator(0) , fValidatorFromUser(false) - , fValScheme(Val_Never) , fDoSchema(false) , fSchemaFullChecking(false) , fSeeXsi(false) + , fErrorCount(0) , fEmptyNamespaceId(0) , fUnknownNamespaceId(0) , fXMLNamespaceId(0) , fXMLNSNamespaceId(0) , fSchemaNamespaceId(0) + , fElemStateSize(16) + , fScannerId(0) + , fSequenceId(0) + , fElemState(0) + , fAttrList(0) + , fDocHandler(0) + , fDocTypeHandler(0) + , fEntityHandler(0) + , fEntityResolver(0) + , fErrorReporter(0) + , fErrorHandler(0) + , fIDRefList(0) + , fRawAttrList(0) + , fValidator(valToAdopt) + , fDTDValidator(0) + , fSchemaValidator(0) + , fValScheme(Val_Never) , fGrammarResolver(0) , fGrammar(0) , fEntityDeclPool(0) @@ -208,38 +211,41 @@ , XMLErrorReporter* const errHandler , XMLValidator* const valToAdopt) : - fAttrList(0) - , fDocHandler(docHandler) - , fDocTypeHandler(docTypeHandler) - , fDoNamespaces(false) - , fEntityHandler(entityHandler) - , fEntityResolver(0) - , fErrorReporter(errHandler) - , fErrorHandler(0) + fDoNamespaces(false) , fExitOnFirstFatal(true) , fValidationConstraintFatal(false) - , fIDRefList(0) , fInException(false) - , fRawAttrList(0) , fReuseGrammar(false) - , fScannerId(0) - , fSequenceId(0) , fStandalone(false) , fHasNoDTD(true) , fValidate(false) - , fValidator(valToAdopt) - , fDTDValidator(0) - , fSchemaValidator(0) , fValidatorFromUser(false) - , fValScheme(Val_Never) , fDoSchema(false) , fSchemaFullChecking(false) , fSeeXsi(false) + , fErrorCount(0) , fEmptyNamespaceId(0) , fUnknownNamespaceId(0) , fXMLNamespaceId(0) , fXMLNSNamespaceId(0) , fSchemaNamespaceId(0) + , fElemStateSize(16) + , fScannerId(0) + , fSequenceId(0) + , fElemState(0) + , fAttrList(0) + , fDocHandler(docHandler) + , fDocTypeHandler(docTypeHandler) + , fEntityHandler(entityHandler) + , fEntityResolver(0) + , fErrorReporter(errHandler) + , fErrorHandler(0) + , fIDRefList(0) + , fRawAttrList(0) + , fValidator(valToAdopt) + , fDTDValidator(0) + , fSchemaValidator(0) + , fValScheme(Val_Never) , fGrammarResolver(0) , fGrammar(0) , fEntityDeclPool(0) @@ -259,6 +265,7 @@ XMLScanner::~XMLScanner() { + delete [] fElemState; delete fAttrList; delete fIDRefList; delete fRawAttrList; @@ -859,6 +866,11 @@ } // + // Create the element state array + // + fElemState = new unsigned int[fElemStateSize]; + + // // Create the attribute list, which is used to store attribute values // during start tag processing. Give it a reasonable initial size that // will serve for most folks, though it will grow as required. @@ -2726,6 +2738,7 @@ // save the contentleafname and currentscope before addlevel, for later use ContentLeafNameTypeVector* cv = 0; + XMLContentModel* cm = 0; int currentScope = Grammar::TOP_LEVEL_SCOPE; if (!isRoot && fGrammar->getGrammarType() == Grammar::SchemaGrammarType) { SchemaElementDecl* tempElement = (SchemaElementDecl*) fElemStack.topElement()->fThisElement; @@ -2734,7 +2747,8 @@ if ((modelType == SchemaElementDecl::Mixed) || (modelType == SchemaElementDecl::Children)) { - cv = tempElement->getContentModel()->getContentLeafNameTypeVector(); + cm = tempElement->getContentModel(); + cv = cm->getContentLeafNameTypeVector(); currentScope = fElemStack.getCurrentScope(); } } @@ -2744,7 +2758,7 @@ // but we don't have the element decl yet, we just tell the element stack // to expand up to get ready. // - fElemStack.addLevel(); + unsigned int elemDepth = fElemStack.addLevel(); fElemStack.setValidationFlag(fValidate); // @@ -2806,7 +2820,9 @@ bool laxThisOne = false; if (cv) { QName element(fPrefixBuf.getRawBuffer(), fNameBuf.getRawBuffer(), uriId); - laxThisOne = laxElementValidation(&element, cv); + // elementDepth will be > 0, as cv is only constructed if element is not + // root. + laxThisOne = laxElementValidation(&element, cv, cm, elemDepth - 1); } // @@ -3015,7 +3031,15 @@ if (typeinfo) currentScope = typeinfo->getScopeDefined(); fElemStack.setCurrentScope(currentScope); + + // Set element next state + if (elemDepth >= fElemStateSize) { + resizeElemState(); + } + + fElemState[elemDepth] = 0; } + fElemStack.setCurrentGrammar(fGrammar); // @@ -3497,3 +3521,24 @@ } +// --------------------------------------------------------------------------- +// XMLScanner: Helper methos +// --------------------------------------------------------------------------- +void XMLScanner::resizeElemState() { + + unsigned int newSize = fElemStateSize * 2; + unsigned int* newElemState = new unsigned int[newSize]; + + // Copy the existing values + unsigned int index = 0; + for (; index < fElemStateSize; index++) + newElemState[index] = fElemState[index]; + + for (; index < newSize; index++) + newElemState[index] = 0; + + // Delete the old array and udpate our members + delete [] fElemState; + fElemState = newElemState; + fElemStateSize = newSize; +} \ No newline at end of file 1.31 +38 -24 xml-xerces/c/src/internal/XMLScanner.hpp Index: XMLScanner.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner.hpp,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- XMLScanner.hpp 2001/08/02 16:54:39 1.30 +++ XMLScanner.hpp 2001/08/13 15:06:39 1.31 @@ -56,6 +56,9 @@ /* * $Log: XMLScanner.hpp,v $ + * Revision 1.31 2001/08/13 15:06:39 knoaman + * update <any> validation. + * * Revision 1.30 2001/08/02 16:54:39 tng * Reset some Scanner flags in scanReset(). * @@ -574,7 +577,9 @@ 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); + bool laxElementValidation(QName* element, ContentLeafNameTypeVector* cv, + const XMLContentModel* const cm, + const unsigned int parentElemDepth); // ----------------------------------------------------------------------- // Private scanning methods @@ -622,8 +627,13 @@ , const XMLCh chEndChar ); + // ----------------------------------------------------------------------- + // Private helper methods + // ----------------------------------------------------------------------- + void resizeElemState(); + // ----------------------------------------------------------------------- // Data members // @@ -791,6 +801,11 @@ // fSchemaNamespaceId // This is the id of the schema namespace URI. // + // fElemState + // fElemStateSize + // Stores an element next state from DFA content model - used for + // wildcard validation + // // fGrammarResolver // Grammar Pool that stores all the Grammar // @@ -808,38 +823,44 @@ // Use only if namespace is turned on. // // ----------------------------------------------------------------------- + bool fDoNamespaces; + bool fExitOnFirstFatal; + bool fValidationConstraintFatal; + bool fInException; + bool fReuseGrammar; + bool fStandalone; + bool fHasNoDTD; + bool fValidate; + bool fValidatorFromUser; + bool fDoSchema; + bool fSchemaFullChecking; + bool fSeeXsi; + int fErrorCount; + unsigned int fEmptyNamespaceId; + unsigned int fUnknownNamespaceId; + unsigned int fXMLNamespaceId; + unsigned int fXMLNSNamespaceId; + unsigned int fSchemaNamespaceId; + unsigned int fElemStateSize; + XMLUInt32 fScannerId; + XMLUInt32 fSequenceId; + unsigned int* fElemState; RefVectorOf<XMLAttr>* fAttrList; XMLBufferMgr fBufMgr; XMLDocumentHandler* fDocHandler; DocTypeHandler* fDocTypeHandler; - bool fDoNamespaces; ElemStack fElemStack; XMLEntityHandler* fEntityHandler; EntityResolver* fEntityResolver; XMLErrorReporter* fErrorReporter; ErrorHandler* fErrorHandler; - bool fExitOnFirstFatal; - bool fValidationConstraintFatal; RefHashTableOf<XMLRefInfo>* fIDRefList; - bool fInException; RefVectorOf<KVStringPair>* fRawAttrList; ReaderMgr fReaderMgr; - bool fReuseGrammar; - XMLUInt32 fScannerId; - XMLUInt32 fSequenceId; - bool fStandalone; - bool fHasNoDTD; - bool fValidate; XMLValidator* fValidator; DTDValidator* fDTDValidator; SchemaValidator* fSchemaValidator; - bool fValidatorFromUser; ValSchemes fValScheme; - int fErrorCount; - bool fDoSchema; - bool fSchemaFullChecking; - bool fSeeXsi; - XMLBuffer fAttNameBuf; XMLBuffer fAttValueBuf; XMLBuffer fCDataBuf; @@ -847,13 +868,6 @@ XMLBuffer fQNameBuf; XMLBuffer fPrefixBuf; XMLBuffer fURIBuf; - - unsigned int fEmptyNamespaceId; - unsigned int fUnknownNamespaceId; - unsigned int fXMLNamespaceId; - unsigned int fXMLNSNamespaceId; - unsigned int fSchemaNamespaceId; - GrammarResolver* fGrammarResolver; Grammar* fGrammar; NameIdPool<DTDEntityDecl>* fEntityDeclPool; 1.52 +62 -33 xml-xerces/c/src/internal/XMLScanner2.cpp Index: XMLScanner2.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/internal/XMLScanner2.cpp,v retrieving revision 1.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- XMLScanner2.cpp 2001/08/02 16:54:39 1.51 +++ XMLScanner2.cpp 2001/08/13 15:06:39 1.52 @@ -55,7 +55,7 @@ */ /* - * $Id: XMLScanner2.cpp,v 1.51 2001/08/02 16:54:39 tng Exp $ + * $Id: XMLScanner2.cpp,v 1.52 2001/08/13 15:06:39 knoaman Exp $ */ @@ -96,6 +96,7 @@ #include <validators/schema/SchemaSymbols.hpp> #include <validators/schema/SchemaGrammar.hpp> #include <validators/schema/TraverseSchema.hpp> +#include <validators/schema/SubstitutionGroupComparator.hpp> @@ -2757,58 +2758,86 @@ // if skip - no validation // if lax - validate only if the element if found -bool XMLScanner::laxElementValidation(QName* element, ContentLeafNameTypeVector* cv) +bool XMLScanner::laxElementValidation(QName* element, ContentLeafNameTypeVector* cv, + const XMLContentModel* const cm, + const unsigned int parentElemDepth) { bool skipThisOne = false; bool laxThisOne = false; unsigned int elementURI = element->getURI(); + unsigned int currState = fElemState[parentElemDepth]; + if (currState == XMLContentModel::gInvalidTrans) { + return laxThisOne; + } + + SubstitutionGroupComparator comparator(fGrammarResolver, fURIStringPool); + if (cv) { - for (unsigned int i=0; i < cv->getLeafCount(); i++) { + unsigned int i = 0; + unsigned int leafCount = cv->getLeafCount(); + + for (; i < leafCount; i++) { + QName* fElemMap = cv->getLeafNameAt(i); unsigned int uri = fElemMap->getURI(); + unsigned int nextState; + bool anyEncountered = false; ContentSpecNode::NodeTypes type = cv->getLeafTypeAt(i); if (type == ContentSpecNode::Leaf) { - if ((uri == elementURI) - && !(XMLString::compareString(fElemMap->getLocalPart(), element->getLocalPart()))) - break; - } else if (type == ContentSpecNode::Any) { - break; - } else if (type == ContentSpecNode::Any_NS) { - if (uri == elementURI) - break; - } else if (type == ContentSpecNode::Any_Other) { - if (uri != elementURI) - break; - } else if (type == ContentSpecNode::Any_Skip) { - skipThisOne = true; - break; - } else if (type == ContentSpecNode::Any_NS_Skip) { - if (uri == elementURI) { - skipThisOne = true; - break; + if (((uri == elementURI) + && !XMLString::compareString(fElemMap->getLocalPart(), element->getLocalPart())) + || comparator.isEquivalentTo(element, fElemMap)) { + + nextState = cm->getNextState(currState, i); + + if (nextState != XMLContentModel::gInvalidTrans) { + fElemState[parentElemDepth] = nextState; + break; + } } - } else if (type == ContentSpecNode::Any_Other_Skip) { + } else if ((type & 0x0f) == ContentSpecNode::Any) { + anyEncountered = true; + } + else if ((type & 0x0f) == ContentSpecNode::Any_Other) { if (uri != elementURI) { - skipThisOne = true; - break; + anyEncountered = true; } - } else if (type == ContentSpecNode::Any_Lax) { - laxThisOne = true; - break; - } else if (type == ContentSpecNode::Any_NS_Lax) { + } + else if ((type & 0x0f) == ContentSpecNode::Any_NS) { if (uri == elementURI) { - laxThisOne = true; - break; + anyEncountered = true; } - } else if (type == ContentSpecNode::Any_Other_Lax) { - if (uri != elementURI) { - laxThisOne = true; + } + + if (anyEncountered) { + + nextState = cm->getNextState(currState, i); + if (nextState != XMLContentModel::gInvalidTrans) { + fElemState[parentElemDepth] = nextState; + + if (type == ContentSpecNode::Any_Skip || + type == ContentSpecNode::Any_NS_Skip || + type == ContentSpecNode::Any_Other_Skip) { + skipThisOne = true; + } + else if (type == ContentSpecNode::Any_Lax || + type == ContentSpecNode::Any_NS_Lax || + type == ContentSpecNode::Any_Other_Lax) { + laxThisOne = true; + } + break; } } } // for + + if (i == leafCount) { // no match + fElemState[parentElemDepth] = XMLContentModel::gInvalidTrans; + return laxThisOne; + } + } // if if (skipThisOne) { 1.10 +23 -0 xml-xerces/c/src/validators/common/DFAContentModel.hpp Index: DFAContentModel.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/validators/common/DFAContentModel.hpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- DFAContentModel.hpp 2001/06/13 20:50:55 1.9 +++ DFAContentModel.hpp 2001/08/13 15:06:39 1.10 @@ -56,6 +56,9 @@ /* * $Log: DFAContentModel.hpp,v $ + * Revision 1.10 2001/08/13 15:06:39 knoaman + * update <any> validation. + * * Revision 1.9 2001/06/13 20:50:55 peiyongz * fIsMixed: to handle mixed Content Model * @@ -107,6 +110,7 @@ #define DFACONTENTMODEL_HPP #include <util/XercesDefs.hpp> +#include <util/ArrayIndexOutOfBoundsException.hpp> #include <framework/XMLContentModel.hpp> #include <validators/common/ContentLeafNameTypeVector.hpp> @@ -165,6 +169,9 @@ virtual ContentLeafNameTypeVector* getContentLeafNameTypeVector() const ; + virtual unsigned int getNextState(const unsigned int currentState, + const unsigned int elementIndex) const; + private : // ----------------------------------------------------------------------- // Unimplemented constructors and operators @@ -283,5 +290,21 @@ bool fIsMixed; ContentLeafNameTypeVector *fLeafNameTypeVector; }; + + +inline unsigned int +DFAContentModel::getNextState(const unsigned int currentState, + const unsigned int elementIndex) const { + + if (currentState == XMLContentModel::gInvalidTrans) { + return XMLContentModel::gInvalidTrans; + } + + if (currentState >= fTransTableSize || elementIndex >= fElemMapSize) { + ThrowXML(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex); + } + + return fTransTable[currentState][elementIndex]; +} #endif 1.9 +13 -0 xml-xerces/c/src/validators/common/MixedContentModel.hpp Index: MixedContentModel.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/validators/common/MixedContentModel.hpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- MixedContentModel.hpp 2001/05/11 13:27:19 1.8 +++ MixedContentModel.hpp 2001/08/13 15:06:39 1.9 @@ -56,6 +56,9 @@ /* * $Log: MixedContentModel.hpp,v $ + * Revision 1.9 2001/08/13 15:06:39 knoaman + * update <any> validation. + * * Revision 1.8 2001/05/11 13:27:19 tng * Copyright update. * @@ -162,6 +165,9 @@ virtual ContentLeafNameTypeVector* getContentLeafNameTypeVector() const ; + virtual unsigned int getNextState(const unsigned int currentState, + const unsigned int elementIndex) const; + private : // ----------------------------------------------------------------------- // Private helper methods @@ -213,6 +219,13 @@ inline ContentLeafNameTypeVector* MixedContentModel::getContentLeafNameTypeVector() const { return 0; +} + +inline unsigned int +MixedContentModel::getNextState(const unsigned int currentState, + const unsigned int elementIndex) const { + + return XMLContentModel::gInvalidTrans; } #endif 1.9 +17 -0 xml-xerces/c/src/validators/common/SimpleContentModel.hpp Index: SimpleContentModel.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/validators/common/SimpleContentModel.hpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SimpleContentModel.hpp 2001/05/11 13:27:20 1.8 +++ SimpleContentModel.hpp 2001/08/13 15:06:39 1.9 @@ -56,6 +56,9 @@ /* * $Log: SimpleContentModel.hpp,v $ + * Revision 1.9 2001/08/13 15:06:39 knoaman + * update <any> validation. + * * Revision 1.8 2001/05/11 13:27:20 tng * Copyright update. * @@ -165,6 +168,9 @@ virtual ContentLeafNameTypeVector *getContentLeafNameTypeVector() const; + virtual unsigned int getNextState(const unsigned int currentState, + const unsigned int elementIndex) const; + private : // ----------------------------------------------------------------------- // Unimplemented constructors and operators @@ -228,6 +234,17 @@ { delete fFirstChild; delete fSecondChild; +} + + +// --------------------------------------------------------------------------- +// SimpleContentModel: Virtual methods +// --------------------------------------------------------------------------- +inline unsigned int +SimpleContentModel::getNextState(const unsigned int currentState, + const unsigned int elementIndex) const { + + return XMLContentModel::gInvalidTrans; } #endif --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]