You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/05/03 22:34:51 UTC
cvs commit: xml-xerces/c/src/validators/schema ComplexTypeInfo.cpp Makefile.in SchemaElementDecl.cpp SchemaElementDecl.hpp SchemaGrammar.hpp SchemaSymbols.hpp SchemaValidator.cpp SchemaValidator.hpp
tng 01/05/03 13:34:50
Modified: c/src/framework XMLElementDecl.hpp XMLErrorCodes.hpp
XMLValidator.hpp XMLValidityCodes.hpp
c/src/internal ElemStack.cpp ElemStack.hpp XMLScanner.cpp
XMLScanner.hpp XMLScanner2.cpp
c/src/parsers SAX2XMLReaderImpl.cpp
c/src/util XMLString.hpp
c/src/validators/DTD DTDScanner.cpp DTDValidator.cpp
DTDValidator.hpp
c/src/validators/common ContentSpecNode.hpp Grammar.hpp
c/src/validators/schema ComplexTypeInfo.cpp Makefile.in
SchemaElementDecl.cpp SchemaElementDecl.hpp
SchemaGrammar.hpp SchemaSymbols.hpp
SchemaValidator.cpp SchemaValidator.hpp
Log:
Schema: SchemaValidator update
Revision Changes Path
1.14 +6 -3 xml-xerces/c/src/framework/XMLElementDecl.hpp
Index: XMLElementDecl.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/framework/XMLElementDecl.hpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- XMLElementDecl.hpp 2001/04/19 18:16:52 1.13
+++ XMLElementDecl.hpp 2001/05/03 20:34:22 1.14
@@ -56,6 +56,9 @@
/*
* $Log: XMLElementDecl.hpp,v $
+ * Revision 1.14 2001/05/03 20:34:22 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.13 2001/04/19 18:16:52 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -336,7 +339,7 @@
*
* @return The URI Id of the element decl, or the emptyNamespaceId if not applicable.
*/
- const int getURI() const;
+ const unsigned int getURI() const;
/** Get the QName of this element type.
*
@@ -366,7 +369,7 @@
* internally but still allow the outside world to do simple stuff with
* them.
*
- * @return A const pointer to the element's content model, via the basic
+ * @return A pointer to the element's content model, via the basic
* abstract content model type.
*/
XMLContentModel* getContentModel();
@@ -604,7 +607,7 @@
return fElementName->getLocalPart();
}
-inline const int XMLElementDecl::getURI() const
+inline const unsigned int XMLElementDecl::getURI() const
{
return fElementName->getURI();
}
1.7 +172 -173 xml-xerces/c/src/framework/XMLErrorCodes.hpp
Index: XMLErrorCodes.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/framework/XMLErrorCodes.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- XMLErrorCodes.hpp 2001/05/03 19:31:18 1.6
+++ XMLErrorCodes.hpp 2001/05/03 20:34:22 1.7
@@ -52,179 +52,178 @@
, InvalidChildInComplexType = 39
, BaseTypeNotFound = 40
, NoAttributeInSchema = 41
- , GenericError = 42
- , DatatypeValidatorCreationError = 43
- , InvalidComplexTypeName = 44
- , InvalidChildFollowingSimpleContent = 45
- , InvalidChildFollowingConplexContent = 46
- , InvalidComplexTypeBlockValue = 47
- , InvalidComplexTypeFinalValue = 48
- , AttributeDefaultFixedValue = 49
- , NotOptionalDefaultAttValue = 50
- , AttributeWithNameRef = 51
- , DuplicateAttribute = 52
- , AttributeWithTypeAndSimpleType = 53
- , AttributeSimpleTypeNotFound = 54
- , ElementWithFixedAndDefault = 55
- , ElementWithNameRef = 56
- , BadAttWithRef = 57
- , InvalidElementName = 58
- , GlobalElementWithRef = 59
- , ElementWithTypeAndAnonType = 60
- , DatatypeValidationFailure = 61
- , NotSimpleOrMixedElement = 62
- , DisallowedSimpleTypeExtension = 63
- , InvalidSimpleContentBase = 64
- , InvalidComplexTypeBase = 65
- , InvalidChildInSimpleContent = 66
- , InvalidChildInComplexContent = 67
- , AnnotationError = 68
- , DisallowedBaseDerivation = 69
- , SubstitutionRepeated = 70
- , UnionRepeated = 71
- , ExtensionRepeated = 72
- , ListRepeated = 73
- , RestrictionRepeated = 74
- , InvalidBlockValue = 75
- , InvalidFinalValue = 76
- , InvalidSubstitutionGroupElement = 77
- , SubstitutionGroupTypeMismatch = 78
- , DuplicateElementDeclaration = 79
- , InvalidElementBlockValue = 80
- , InvalidElementFinalValue = 81
- , AttributeRefContentError = 82
- , DuplicateRefAttribute = 83
- , ForbiddenDerivationByRestriction = 84
- , ForbiddenDerivationByExtension = 85
- , BaseNotComplexType = 86
- , DisplayErrorMessage = 87
- , E_HighBounds = 88
- , F_LowBounds = 89
- , ExpectedCommentOrCDATA = 90
- , ExpectedAttrName = 91
- , ExpectedNotationName = 92
- , NoRepInMixed = 93
- , BadDefAttrDecl = 94
- , ExpectedDefAttrDecl = 95
- , AttListSyntaxError = 96
- , ExpectedEqSign = 97
- , DupAttrName = 98
- , BadIdForXMLLangAttr = 99
- , ExpectedElementName = 100
- , MustStartWithXMLDecl = 101
- , CommentsMustStartWith = 102
- , InvalidDocumentStructure = 103
- , ExpectedDeclString = 104
- , BadXMLVersion = 105
- , UnsupportedXMLVersion = 106
- , UnterminatedXMLDecl = 107
- , BadXMLEncoding = 108
- , BadStandalone = 109
- , UnterminatedComment = 110
- , PINameExpected = 111
- , UnterminatedPI = 112
- , InvalidCharacter = 113
- , UnexpectedTextBeforeRoot = 114
- , UnterminatedStartTag = 115
- , ExpectedAttrValue = 116
- , UnterminatedEndTag = 117
- , ExpectedAttributeType = 118
- , ExpectedEndOfTagX = 119
- , ExpectedMarkup = 120
- , NotValidAfterContent = 121
- , ExpectedComment = 122
- , ExpectedCommentOrPI = 123
- , ExpectedWhitespace = 124
- , NoRootElemInDOCTYPE = 125
- , ExpectedQuotedString = 126
- , ExpectedPublicId = 127
- , InvalidPublicIdChar = 128
- , UnterminatedDOCTYPE = 129
- , InvalidCharacterInIntSubset = 130
- , ExpectedCDATA = 131
- , InvalidInitialNameChar = 132
- , InvalidNameChar = 133
- , UnexpectedWhitespace = 134
- , InvalidCharacterInAttrValue = 135
- , ExpectedMarkupDecl = 136
- , TextDeclNotLegalHere = 137
- , ConditionalSectInIntSubset = 138
- , ExpectedPEName = 139
- , UnterminatedEntityDecl = 140
- , InvalidCharacterRef = 141
- , UnterminatedCharRef = 142
- , ExpectedEntityRefName = 143
- , EntityNotFound = 144
- , NoUnparsedEntityRefs = 145
- , UnterminatedEntityRef = 146
- , RecursiveEntity = 147
- , PartialMarkupInEntity = 148
- , UnterminatedElementDecl = 149
- , ExpectedContentSpecExpr = 150
- , ExpectedAsterisk = 151
- , UnterminatedContentModel = 152
- , ExpectedSystemId = 153
- , ExpectedSystemOrPublicId = 154
- , UnterminatedNotationDecl = 155
- , ExpectedSeqChoiceLeaf = 156
- , ExpectedChoiceOrCloseParen = 157
- , ExpectedSeqOrCloseParen = 158
- , ExpectedEnumValue = 159
- , ExpectedEnumSepOrParen = 160
- , UnterminatedEntityLiteral = 161
- , MoreEndThanStartTags = 162
- , IllegalRefInStandalone = 163
- , ExpectedOpenParen = 164
- , AttrAlreadyUsedInSTag = 165
- , BracketInAttrValue = 166
- , Expected2ndSurrogateChar = 167
- , ExpectedEndOfConditional = 168
- , ExpectedIncOrIgn = 169
- , ExpectedINCLUDEBracket = 170
- , ExpectedTextDecl = 171
- , ExpectedXMLDecl = 172
- , UnexpectedEOE = 173
- , PEPropogated = 174
- , ExtraCloseSquare = 175
- , PERefInMarkupInIntSubset = 176
- , EntityPropogated = 177
- , ExpectedNumericalCharRef = 178
- , ExpectedOpenSquareBracket = 179
- , BadSequenceInCharData = 180
- , IllegalSequenceInComment = 181
- , UnterminatedCDATASection = 182
- , ExpectedNDATA = 183
- , NDATANotValidForPE = 184
- , HexRadixMustBeLowerCase = 185
- , DeclStringRep = 186
- , DeclStringsInWrongOrder = 187
- , NoExtRefsInAttValue = 188
- , XMLDeclMustBeLowerCase = 189
- , ExpectedEntityValue = 190
- , BadDigitForRadix = 191
- , EndedWithTagsOnStack = 192
- , AmbiguousContentModel = 193
- , NestedCDATA = 194
- , UnknownPrefix = 195
- , PartialTagMarkupError = 196
- , EmptyMainEntity = 197
- , CDATAOutsideOfContent = 198
- , OnlyCharRefsAllowedHere = 199
- , Unexpected2ndSurrogateChar = 200
- , NoPIStartsWithXML = 201
- , XMLDeclMustBeFirst = 202
- , XMLVersionRequired = 203
- , StandaloneNotLegal = 204
- , TooManyColonsInName = 205
- , InvalidColonPos = 206
- , ColonNotLegalWithNS = 207
- , SysException = 208
- , XMLException = 209
- , UnexpectedEOF = 210
- , UnexpectedError = 211
- , BadSchemaLocation = 212
- , NoGrammarResolver = 213
- , F_HighBounds = 214
+ , DatatypeValidatorCreationError = 42
+ , InvalidComplexTypeName = 43
+ , InvalidChildFollowingSimpleContent = 44
+ , InvalidChildFollowingConplexContent = 45
+ , InvalidComplexTypeBlockValue = 46
+ , InvalidComplexTypeFinalValue = 47
+ , AttributeDefaultFixedValue = 48
+ , NotOptionalDefaultAttValue = 49
+ , AttributeWithNameRef = 50
+ , DuplicateAttribute = 51
+ , AttributeWithTypeAndSimpleType = 52
+ , AttributeSimpleTypeNotFound = 53
+ , ElementWithFixedAndDefault = 54
+ , ElementWithNameRef = 55
+ , BadAttWithRef = 56
+ , InvalidElementName = 57
+ , GlobalElementWithRef = 58
+ , ElementWithTypeAndAnonType = 59
+ , DatatypeValidationFailure = 60
+ , NotSimpleOrMixedElement = 61
+ , DisallowedSimpleTypeExtension = 62
+ , InvalidSimpleContentBase = 63
+ , InvalidComplexTypeBase = 64
+ , InvalidChildInSimpleContent = 65
+ , InvalidChildInComplexContent = 66
+ , AnnotationError = 67
+ , DisallowedBaseDerivation = 68
+ , SubstitutionRepeated = 69
+ , UnionRepeated = 70
+ , ExtensionRepeated = 71
+ , ListRepeated = 72
+ , RestrictionRepeated = 73
+ , InvalidBlockValue = 74
+ , InvalidFinalValue = 75
+ , InvalidSubstitutionGroupElement = 76
+ , SubstitutionGroupTypeMismatch = 77
+ , DuplicateElementDeclaration = 78
+ , InvalidElementBlockValue = 79
+ , InvalidElementFinalValue = 80
+ , AttributeRefContentError = 81
+ , DuplicateRefAttribute = 82
+ , ForbiddenDerivationByRestriction = 83
+ , ForbiddenDerivationByExtension = 84
+ , BaseNotComplexType = 85
+ , DisplayErrorMessage = 86
+ , E_HighBounds = 87
+ , F_LowBounds = 88
+ , ExpectedCommentOrCDATA = 89
+ , ExpectedAttrName = 90
+ , ExpectedNotationName = 91
+ , NoRepInMixed = 92
+ , BadDefAttrDecl = 93
+ , ExpectedDefAttrDecl = 94
+ , AttListSyntaxError = 95
+ , ExpectedEqSign = 96
+ , DupAttrName = 97
+ , BadIdForXMLLangAttr = 98
+ , ExpectedElementName = 99
+ , MustStartWithXMLDecl = 100
+ , CommentsMustStartWith = 101
+ , InvalidDocumentStructure = 102
+ , ExpectedDeclString = 103
+ , BadXMLVersion = 104
+ , UnsupportedXMLVersion = 105
+ , UnterminatedXMLDecl = 106
+ , BadXMLEncoding = 107
+ , BadStandalone = 108
+ , UnterminatedComment = 109
+ , PINameExpected = 110
+ , UnterminatedPI = 111
+ , InvalidCharacter = 112
+ , UnexpectedTextBeforeRoot = 113
+ , UnterminatedStartTag = 114
+ , ExpectedAttrValue = 115
+ , UnterminatedEndTag = 116
+ , ExpectedAttributeType = 117
+ , ExpectedEndOfTagX = 118
+ , ExpectedMarkup = 119
+ , NotValidAfterContent = 120
+ , ExpectedComment = 121
+ , ExpectedCommentOrPI = 122
+ , ExpectedWhitespace = 123
+ , NoRootElemInDOCTYPE = 124
+ , ExpectedQuotedString = 125
+ , ExpectedPublicId = 126
+ , InvalidPublicIdChar = 127
+ , UnterminatedDOCTYPE = 128
+ , InvalidCharacterInIntSubset = 129
+ , ExpectedCDATA = 130
+ , InvalidInitialNameChar = 131
+ , InvalidNameChar = 132
+ , UnexpectedWhitespace = 133
+ , InvalidCharacterInAttrValue = 134
+ , ExpectedMarkupDecl = 135
+ , TextDeclNotLegalHere = 136
+ , ConditionalSectInIntSubset = 137
+ , ExpectedPEName = 138
+ , UnterminatedEntityDecl = 139
+ , InvalidCharacterRef = 140
+ , UnterminatedCharRef = 141
+ , ExpectedEntityRefName = 142
+ , EntityNotFound = 143
+ , NoUnparsedEntityRefs = 144
+ , UnterminatedEntityRef = 145
+ , RecursiveEntity = 146
+ , PartialMarkupInEntity = 147
+ , UnterminatedElementDecl = 148
+ , ExpectedContentSpecExpr = 149
+ , ExpectedAsterisk = 150
+ , UnterminatedContentModel = 151
+ , ExpectedSystemId = 152
+ , ExpectedSystemOrPublicId = 153
+ , UnterminatedNotationDecl = 154
+ , ExpectedSeqChoiceLeaf = 155
+ , ExpectedChoiceOrCloseParen = 156
+ , ExpectedSeqOrCloseParen = 157
+ , ExpectedEnumValue = 158
+ , ExpectedEnumSepOrParen = 159
+ , UnterminatedEntityLiteral = 160
+ , MoreEndThanStartTags = 161
+ , IllegalRefInStandalone = 162
+ , ExpectedOpenParen = 163
+ , AttrAlreadyUsedInSTag = 164
+ , BracketInAttrValue = 165
+ , Expected2ndSurrogateChar = 166
+ , ExpectedEndOfConditional = 167
+ , ExpectedIncOrIgn = 168
+ , ExpectedINCLUDEBracket = 169
+ , ExpectedTextDecl = 170
+ , ExpectedXMLDecl = 171
+ , UnexpectedEOE = 172
+ , PEPropogated = 173
+ , ExtraCloseSquare = 174
+ , PERefInMarkupInIntSubset = 175
+ , EntityPropogated = 176
+ , ExpectedNumericalCharRef = 177
+ , ExpectedOpenSquareBracket = 178
+ , BadSequenceInCharData = 179
+ , IllegalSequenceInComment = 180
+ , UnterminatedCDATASection = 181
+ , ExpectedNDATA = 182
+ , NDATANotValidForPE = 183
+ , HexRadixMustBeLowerCase = 184
+ , DeclStringRep = 185
+ , DeclStringsInWrongOrder = 186
+ , NoExtRefsInAttValue = 187
+ , XMLDeclMustBeLowerCase = 188
+ , ExpectedEntityValue = 189
+ , BadDigitForRadix = 190
+ , EndedWithTagsOnStack = 191
+ , AmbiguousContentModel = 192
+ , NestedCDATA = 193
+ , UnknownPrefix = 194
+ , PartialTagMarkupError = 195
+ , EmptyMainEntity = 196
+ , CDATAOutsideOfContent = 197
+ , OnlyCharRefsAllowedHere = 198
+ , Unexpected2ndSurrogateChar = 199
+ , NoPIStartsWithXML = 200
+ , XMLDeclMustBeFirst = 201
+ , XMLVersionRequired = 202
+ , StandaloneNotLegal = 203
+ , TooManyColonsInName = 204
+ , InvalidColonPos = 205
+ , ColonNotLegalWithNS = 206
+ , SysException = 207
+ , XMLException = 208
+ , UnexpectedEOF = 209
+ , UnexpectedError = 210
+ , BadSchemaLocation = 211
+ , NoGrammarResolver = 212
+ , F_HighBounds = 213
};
static bool isFatal(const XMLErrs::Codes toCheck)
1.12 +18 -2 xml-xerces/c/src/framework/XMLValidator.hpp
Index: XMLValidator.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/framework/XMLValidator.hpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- XMLValidator.hpp 2001/04/19 18:16:53 1.11
+++ XMLValidator.hpp 2001/05/03 20:34:22 1.12
@@ -56,6 +56,9 @@
/*
* $Log: XMLValidator.hpp,v $
+ * Revision 1.12 2001/05/03 20:34:22 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.11 2001/04/19 18:16:53 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -110,6 +113,7 @@
class ReaderMgr;
class XMLBuffer;
class XMLBufferMgr;
+class XMLElementDecl;
class XMLEntityHandler;
class XMLErrorReporter;
class XMLMsgLoader;
@@ -181,7 +185,7 @@
*/
virtual int checkContent
(
- const unsigned int elemId
+ XMLElementDecl* const elemDecl
, QName** const children
, const unsigned int childCount
) = 0;
@@ -251,8 +255,20 @@
*/
virtual void validateAttrValue
(
- const XMLAttDef& attDef
+ const XMLAttDef* attDef
, const XMLCh* const attrValue
+ ) = 0;
+
+ /**
+ * The derived class should apply any rules to the passed element decl
+ * that are above and beyond those defined by XML 1.0.
+ *
+ * If the value breaks any rules as defined by the derived class, it
+ * should just issue errors as usual.
+ */
+ virtual void validateElement
+ (
+ const XMLElementDecl* elemDef
) = 0;
/**
1.8 +6 -5 xml-xerces/c/src/framework/XMLValidityCodes.hpp
Index: XMLValidityCodes.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/framework/XMLValidityCodes.hpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XMLValidityCodes.hpp 2001/05/03 19:31:19 1.7
+++ XMLValidityCodes.hpp 2001/05/03 20:34:23 1.8
@@ -89,11 +89,12 @@
, NilAttrNotEmpty = 76
, FixedDifferentFromActual = 77
, NoDatatypeValidatorForAttribute = 78
- , E_HighBounds = 79
- , W_LowBounds = 80
- , W_HighBounds = 81
- , F_LowBounds = 82
- , F_HighBounds = 83
+ , GenericError = 79
+ , E_HighBounds = 80
+ , W_LowBounds = 81
+ , W_HighBounds = 82
+ , F_LowBounds = 83
+ , F_HighBounds = 84
};
static bool isFatal(const XMLValid::Codes toCheck)
1.10 +8 -0 xml-xerces/c/src/internal/ElemStack.cpp
Index: ElemStack.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/ElemStack.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ElemStack.cpp 2001/04/19 18:16:57 1.9
+++ ElemStack.cpp 2001/05/03 20:34:28 1.10
@@ -56,6 +56,9 @@
/*
* $Log: ElemStack.cpp,v $
+ * Revision 1.10 2001/05/03 20:34:28 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.9 2001/04/19 18:16:57 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -100,6 +103,7 @@
#include <util/NoSuchElementException.hpp>
#include <framework/XMLElementDecl.hpp>
#include <internal/ElemStack.hpp>
+#include <validators/common/Grammar.hpp>
// ---------------------------------------------------------------------------
@@ -170,6 +174,8 @@
fStack[fStackTop]->fReaderNum = 0xFFFFFFFF;
fStack[fStackTop]->fChildCount = 0;
fStack[fStackTop]->fMapCount = 0;
+ fStack[fStackTop]->fValidationFlag = false;
+ fStack[fStackTop]->fCurrentScope = Grammar::TOP_LEVEL_SCOPE;
// Bump the top of stack
fStackTop++;
@@ -200,6 +206,8 @@
fStack[fStackTop]->fReaderNum = 0xFFFFFFFF;
fStack[fStackTop]->fChildCount = 0;
fStack[fStackTop]->fMapCount = 0;
+ fStack[fStackTop]->fValidationFlag = false;
+ fStack[fStackTop]->fCurrentScope = Grammar::TOP_LEVEL_SCOPE;
// And store the new stuff
fStack[fStackTop]->fThisElement = toSet;
1.7 +33 -0 xml-xerces/c/src/internal/ElemStack.hpp
Index: ElemStack.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/internal/ElemStack.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ElemStack.hpp 2001/04/19 18:16:58 1.6
+++ ElemStack.hpp 2001/05/03 20:34:28 1.7
@@ -56,6 +56,9 @@
/*
* $Log: ElemStack.hpp,v $
+ * Revision 1.7 2001/05/03 20:34:28 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.6 2001/04/19 18:16:58 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -166,6 +169,9 @@
PrefMapElem* fMap;
unsigned int fMapCapacity;
unsigned int fMapCount;
+
+ bool fValidationFlag;
+ int fCurrentScope;
};
enum MapModes
@@ -199,6 +205,11 @@
const StackElem* topElement() const;
void setElement(XMLElementDecl* const toSet, const unsigned int readerNum);
+ void setValidationFlag(bool validationFlag);
+ bool getValidationFlag();
+
+ void setCurrentScope(int currentScope);
+ int getCurrentScope();
// -----------------------------------------------------------------------
// Prefix map methods
@@ -303,6 +314,28 @@
inline bool ElemStack::isEmpty() const
{
return (fStackTop == 0);
+}
+
+inline bool ElemStack::getValidationFlag()
+{
+ return fStack[fStackTop-1]->fValidationFlag;
+}
+
+inline void ElemStack::setValidationFlag(bool validationFlag)
+{
+ fStack[fStackTop-1]->fValidationFlag = validationFlag;
+ return;
+}
+
+inline int ElemStack::getCurrentScope()
+{
+ return fStack[fStackTop-1]->fCurrentScope;
+}
+
+inline void ElemStack::setCurrentScope(int currentScope)
+{
+ fStack[fStackTop-1]->fCurrentScope = currentScope;
+ return;
}
#endif
1.37 +70 -1 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.36
retrieving revision 1.37
diff -u -r1.36 -r1.37
--- XMLScanner.cpp 2001/05/03 19:09:06 1.36
+++ XMLScanner.cpp 2001/05/03 20:34:29 1.37
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLScanner.cpp,v 1.36 2001/05/03 19:09:06 knoaman Exp $
+ * $Id: XMLScanner.cpp,v 1.37 2001/05/03 20:34:29 tng Exp $
*/
@@ -3258,3 +3258,72 @@
uriBufToFill.set(value);
return true;
}
+
+unsigned int
+XMLScanner::resolveQName( const XMLCh* const qName
+ , XMLBuffer& nameBuf
+ , XMLBuffer& prefixBuf
+ , const ElemStack::MapModes mode)
+{
+ // Reset both target buffers in case we don't get anything for either
+ nameBuf.reset();
+ prefixBuf.reset();
+
+ //
+ // Lets split out the qName into a URI and name buffer first. The URI
+ // can be empty.
+ //
+ const int colonPos = XMLString::indexOf(qName, chColon);
+ unsigned int uriId = 0;
+ if (colonPos == -1)
+ {
+ //
+ // Its all name with no prefix, so put the whole thing into the name
+ // buffer. Then map the empty string to a URI, since the empty string
+ // represents the default namespace. This will either return some
+ // explicit URI which the default namespace is mapped to, or the
+ // the default global namespace.
+ //
+ nameBuf.append(qName);
+ bool unknown;
+ uriId = fElemStack.mapPrefixToURI(prefixBuf.getRawBuffer(), mode, unknown);
+
+ #if defined(XERCES_DEBUG)
+ if (unknown)
+ {
+ // <TBD> This one should never be unknown
+ }
+ #endif
+ }
+ else
+ {
+ //
+ // Copy the chars up to but not including the colon into the prefix
+ // buffer.
+ //
+ prefixBuf.append(qName, colonPos);
+
+ // And copy over the rest of the chars to the name buffer
+ nameBuf.append(&qName[colonPos+1]);
+
+ //
+ // Watch for the special namespace prefixes. We always map these to
+ // special URIs. 'xml' gets mapped to the official URI that its defined
+ // to map to by the NS spec. xmlns gets mapped to a special place holder
+ // URI that we define (so that it maps to something checkable.)
+ //
+ if (!XMLString::compareString(prefixBuf.getRawBuffer(), XMLUni::fgXMLNSString))
+ uriId = fXMLNSNamespaceId;
+ else if (!XMLString::compareString(prefixBuf.getRawBuffer(), XMLUni::fgXMLString))
+ uriId = fXMLNamespaceId;
+ else
+ {
+ bool unknown;
+ uriId = fElemStack.mapPrefixToURI(prefixBuf.getRawBuffer(), mode, unknown);
+ if (unknown)
+ emitError(XMLErrs::UnknownPrefix, prefixBuf.getRawBuffer());
+ }
+ }
+ return uriId;
+}
+
1.16 +20 -7 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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- XMLScanner.hpp 2001/05/03 19:09:09 1.15
+++ XMLScanner.hpp 2001/05/03 20:34:29 1.16
@@ -56,6 +56,9 @@
/*
* $Log: XMLScanner.hpp,v $
+ * Revision 1.16 2001/05/03 20:34:29 tng
+ * Schema: SchemaValidator update
+ *
* 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
@@ -367,6 +370,21 @@
const XMLCh* getURIText(const unsigned int uriId) const;
+ /**
+ * This method separate the passed QName into prefix
+ * and local part, and then return the URI id by resolving
+ * the prefix.
+ *
+ * mode: Indicate if this QName comes from an Element or Attribute
+ */
+ unsigned int resolveQName
+ (
+ const XMLCh* const qName
+ , XMLBuffer& nameBufToFill
+ , XMLBuffer& prefixBufToFill
+ , const ElemStack::MapModes mode
+ );
+
/* tell if the validator comes from user */
bool isValidatorFromUser();
@@ -492,13 +510,6 @@
, XMLBuffer& toFill
);
- unsigned int resolveQName
- (
- const XMLCh* const qName
- , XMLBuffer& nameBufToFill
- , XMLBuffer& prefixBufToFill
- , const ElemStack::MapModes mode
- );
unsigned int resolvePrefix
(
const XMLCh* const prefix
1.27 +206 -105 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.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- XMLScanner2.cpp 2001/04/19 18:17:00 1.26
+++ XMLScanner2.cpp 2001/05/03 20:34:30 1.27
@@ -55,7 +55,7 @@
*/
/*
- * $Id: XMLScanner2.cpp,v 1.26 2001/04/19 18:17:00 tng Exp $
+ * $Id: XMLScanner2.cpp,v 1.27 2001/05/03 20:34:30 tng Exp $
*/
@@ -75,7 +75,10 @@
#include <util/UnexpectedEOFException.hpp>
#include <util/XMLUniDefs.hpp>
#include <util/XMLUni.hpp>
+#include <util/XMLURL.hpp>
#include <sax/InputSource.hpp>
+#include <framework/LocalFileInputSource.hpp>
+#include <framework/URLInputSource.hpp>
#include <framework/XMLErrorReporter.hpp>
#include <framework/XMLDocumentHandler.hpp>
#include <framework/XMLEntityHandler.hpp>
@@ -87,9 +90,11 @@
#include <parsers/DOMParser.hpp>
#include <dom/DOM_DOMException.hpp>
#include <sax/EntityResolver.hpp>
+#include <validators/common/ContentLeafNameTypeVector.hpp>
#include <validators/datatype/DatatypeValidator.hpp>
#include <validators/schema/SchemaSymbols.hpp>
#include <validators/schema/SchemaGrammar.hpp>
+#include <validators/schema/TraverseSchema.hpp>
@@ -202,7 +207,8 @@
//
const bool isNSAttr = (uriId == fXMLNSNamespaceId)
|| (uriId == fXMLNamespaceId)
- || !XMLString::compareString(suffPtr, XMLUni::fgXMLNSString);
+ || !XMLString::compareString(suffPtr, XMLUni::fgXMLNSString)
+ || !XMLString::compareString(getURIText(uriId), SchemaSymbols::fgURI_XSI);
//
@@ -217,7 +223,7 @@
// the uriID/name and the raw QName buffer, since we don't know
// how the derived validator and its elements store attributes.
//
- bool wasAdded;
+ bool wasAdded = false;
XMLAttDef* attDef = elemDecl.findAttr
(
curPair->getKey()
@@ -313,13 +319,15 @@
if (fGrammar->getGrammarType() == Grammar::SchemaGrammarType)
{
// normalize the attribute according to schema whitespace facet
+ XMLBuffer toFill;
DatatypeValidator* tempDV = ((SchemaAttDef*) attDef)->getDatatypeValidator();
- ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, normBuf.getRawBuffer(), normBuf);
+ ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, normBuf.getRawBuffer(), toFill);
+ normBuf.set(toFill.getRawBuffer());
}
fValidator->validateAttrValue
(
- *attDef
+ attDef
, normBuf.getRawBuffer()
);
}
@@ -407,9 +415,7 @@
//
// Check after all specified attrs are scanned
// (1) report error for REQUIRED attrs that are missing (V_TAGc)
- // (2) check that FIXED attrs have matching value (V_TAGd)
- // (3) add default attrs (FIXED and NOT_FIXED)
- // (4) (schema) report error for PROHIBITED attrs that are present (V_TAGc)
+ // (2) add default attrs if missing (FIXED and NOT_FIXED)
//
XMLAttDefList& attDefList = elemDecl.getAttDefList();
while (attDefList.hasMoreElements())
@@ -420,6 +426,7 @@
if (!curDef.getProvided())
{
+ //the attributes is not provided
if (fValidate)
{
// If we are validating and its required, then an error
@@ -461,26 +468,40 @@
fValidator->faultInAttr(*curAtt, curDef);
fAttrList->addElement(curAtt);
}
- else
+ else
{
curAtt = fAttrList->elementAt(retCount);
fValidator->faultInAttr(*curAtt, curDef);
}
- //
- // Map the new attribute's prefix to a URI id and store
- // that in the attribute object.
- //
- curAtt->setURIId
- (
- resolvePrefix(curAtt->getPrefix(), ElemStack::Mode_Attribute)
- );
+ if (fGrammar->getGrammarType() == Grammar::DTDGrammarType)
+ {
+ //
+ // Map the new attribute's prefix to a URI id and store
+ // that in the attribute object.
+ //
+ curAtt->setURIId
+ (
+ resolvePrefix(curAtt->getPrefix(), ElemStack::Mode_Attribute)
+ );
+ }
// Indicate it was not explicitly specified and bump count
curAtt->setSpecified(false);
retCount++;
}
}
+ else
+ {
+ //attribute is provided
+ // (schema) report error for PROHIBITED attrs that are present (V_TAGc)
+ if (defType == XMLAttDef::Prohibited)
+ fValidator->emitError
+ (
+ XMLValid::ProhibitedAttributePresent
+ , curDef.getFullName()
+ );
+ }
}
}
return retCount;
@@ -695,74 +716,6 @@
}
-unsigned int
-XMLScanner::resolveQName( const XMLCh* const qName
- , XMLBuffer& nameBuf
- , XMLBuffer& prefixBuf
- , const ElemStack::MapModes mode)
-{
- // Reset both target buffers in case we don't get anything for either
- nameBuf.reset();
- prefixBuf.reset();
-
- //
- // Lets split out the qName into a URI and name buffer first. The URI
- // can be empty.
- //
- const int colonPos = XMLString::indexOf(qName, chColon);
- unsigned int uriId = 0;
- if (colonPos == -1)
- {
- //
- // Its all name with no prefix, so put the whole thing into the name
- // buffer. Then map the empty string to a URI, since the empty string
- // represents the default namespace. This will either return some
- // explicit URI which the default namespace is mapped to, or the
- // the default global namespace.
- //
- nameBuf.append(qName);
- bool unknown;
- uriId = fElemStack.mapPrefixToURI(prefixBuf.getRawBuffer(), mode, unknown);
-
- #if defined(XERCES_DEBUG)
- if (unknown)
- {
- // <TBD> This one should never be unknown
- }
- #endif
- }
- else
- {
- //
- // Copy the chars up to but not including the colon into the prefix
- // buffer.
- //
- prefixBuf.append(qName, colonPos);
-
- // And copy over the rest of the chars to the name buffer
- nameBuf.append(&qName[colonPos+1]);
-
- //
- // Watch for the special namespace prefixes. We always map these to
- // special URIs. 'xml' gets mapped to the official URI that its defined
- // to map to by the NS spec. xmlns gets mapped to a special place holder
- // URI that we define (so that it maps to something checkable.)
- //
- if (!XMLString::compareString(prefixBuf.getRawBuffer(), XMLUni::fgXMLNSString))
- uriId = fXMLNSNamespaceId;
- else if (!XMLString::compareString(prefixBuf.getRawBuffer(), XMLUni::fgXMLString))
- uriId = fXMLNamespaceId;
- else
- {
- bool unknown;
- uriId = fElemStack.mapPrefixToURI(prefixBuf.getRawBuffer(), mode, unknown);
- if (unknown)
- emitError(XMLErrs::UnknownPrefix, prefixBuf.getRawBuffer());
- }
- }
- return uriId;
-}
-
//
// This method will reset the scanner data structures, and related plugged
// in stuff, for a new scan session. We get the input source for the primary
@@ -785,7 +738,7 @@
resetEntityDeclPool();
if (fDoNamespaces)
- resetURIPool();
+ resetURIStringPool();
// create a default validator
if (fValidate) {
@@ -900,6 +853,7 @@
// Get the raw data we need for the callback
const XMLCh* rawBuf = toSend.getRawBuffer();
const unsigned int len = toSend.getLen();
+ XMLBuffer toFill;
//
// We do different things according to whether we are validating or
@@ -950,8 +904,8 @@
{
// normalize the character according to schema whitespace facet
DatatypeValidator* tempDV = ((SchemaElementDecl*) topElem->fThisElement)->getDatatypeValidator();
- ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, rawBuf, toSend);
- rawBuf = toSend.getRawBuffer();
+ ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, rawBuf, toFill);
+ rawBuf = toFill.getRawBuffer();
}
if (fDocHandler)
@@ -1122,10 +1076,10 @@
bool seeXsi = false;
// Schema prefix xxx (e.g. xmlns:xxx="http://www.w3.org/2000/10/XMLSchema-instance")
- const XMLCh* fXsiPrefix;
+ XMLBuffer fXsiPrefix;
- // Schema type
- const XMLCh* fXsiType;
+ // Schema Xsi Type yyyy (e.g. xsi:type="yyyyy")
+ XMLBuffer fXsiType;
//
// Make an initial pass through the list and find any xmlns attributes or
@@ -1156,7 +1110,7 @@
// if the schema URI is seen in the the valuePtr, set the boolean seeXsi
if (!XMLString::compareString(valuePtr, SchemaSymbols::fgURI_XSI)) {
- fXsiPrefix = suffPtr;
+ fXsiPrefix.set(suffPtr);
seeXsi = true;
}
}
@@ -1178,19 +1132,32 @@
// if schema URI has been seen, scan for the schema location and uri
// and resolve the schema grammar; or scan for schema type
- if (!XMLString::compareString(prefPtr, fXsiPrefix)) {
+ if (!XMLString::compareString(prefPtr, fXsiPrefix.getRawBuffer())) {
if (!XMLString::compareString(suffPtr, SchemaSymbols::fgXSI_SCHEMALOCACTION))
parseSchemaLocation(valuePtr);
else if (!XMLString::compareString(suffPtr, SchemaSymbols::fgXSI_NONAMESPACESCHEMALOCACTION))
resolveSchemaGrammar(valuePtr, XMLUni::fgZeroLenString);
else if (!XMLString::compareString(suffPtr, SchemaSymbols::fgXSI_TYPE))
- fXsiType = valuePtr;
+ fXsiType.set(valuePtr);
+ else if (!XMLString::compareString(suffPtr, SchemaSymbols::fgATT_NILLABLE)) {
+ if (fValidator) {
+ if (!XMLString::compareString(valuePtr, SchemaSymbols::fgATTVAL_TRUE))
+ ((SchemaValidator*)fValidator)->setNillable(true);
+ }
+ }
}
}
if (fValidator) {
- if (fXsiType)
- ((SchemaValidator*)fValidator)->setXsiTypeAttValue(fXsiType);
+ if (!fXsiType.isEmpty()) {
+ unsigned int uriId = resolveQName (
+ fXsiType.getRawBuffer()
+ , fNameBuf
+ , fPrefixBuf
+ , ElemStack::Mode_Element
+ );
+ ((SchemaValidator*)fValidator)->setXsiType(fPrefixBuf.getRawBuffer(), fNameBuf.getRawBuffer(), uriId);
+ }
}
}
}
@@ -1247,8 +1214,73 @@
parser.setErrorHandler(fErrorHandler);
parser.setEntityResolver(fEntityResolver);
+ // Create a buffer for expanding the system id
+ XMLBuffer expSysId;
+
+ //
+ // Allow the entity handler to expand the system id if they choose
+ // to do so.
+ //
+ if (fEntityHandler)
+ {
+ if (!fEntityHandler->expandSystemId(loc, expSysId))
+ expSysId.set(loc);
+ }
+ else
+ {
+ expSysId.set(loc);
+ }
+
+ // Call the entity resolver interface to get an input source
+ InputSource* srcToFill = 0;
+ if (fEntityResolver)
+ {
+ srcToFill = fEntityResolver->resolveEntity
+ (
+ XMLUni::fgZeroLenString
+ , expSysId.getRawBuffer()
+ );
+ }
+
+ //
+ // If they didn't create a source via the entity resolver, then we
+ // have to create one on our own.
+ //
+ if (!srcToFill)
+ {
+ ReaderMgr::LastExtEntityInfo lastInfo;
+ fReaderMgr.getLastExtEntityInfo(lastInfo);
+
+ try
+ {
+ XMLURL urlTmp(lastInfo.systemId, expSysId.getRawBuffer());
+ if (urlTmp.isRelative())
+ {
+ ThrowXML
+ (
+ MalformedURLException
+ , XMLExcepts::URL_NoProtocolPresent
+ );
+ }
+ srcToFill = new URLInputSource(urlTmp);
+ }
+
+ catch(const MalformedURLException&)
+ {
+ // Its not a URL, so lets assume its a local file name.
+ srcToFill = new LocalFileInputSource
+ (
+ lastInfo.systemId
+ , expSysId.getRawBuffer()
+ );
+ }
+ }
+
+ // Put a janitor on the input source
+ Janitor<InputSource> janSrc(srcToFill);
+
try {
- parser.parse( loc );
+ parser.parse( *srcToFill) ;
}
catch (const XMLException& e)
{
@@ -1267,7 +1299,7 @@
DOM_Document document = parser.getDocument(); //Our Grammar
DOM_Element root = document.getDocumentElement();// This is what we pass to TraverserSchema
- if (root.getNodeName().equals(SchemaSymbols::fgELT_SCHEMA)) {
+ if (fValidate && root.isNull()) {
fValidator->emitError(XMLValid::SchemaRootError, loc);
}
else
@@ -1276,13 +1308,7 @@
fValidator->emitError(XMLValid::WrongTargetNamespace, loc, uri);
grammar = new SchemaGrammar();
- grammar->setTargetNamespace(root.getAttribute(SchemaSymbols::fgATT_TARGETNAMESPACE).rawBuffer());
-
- // pass parser's entity resolver (local Resolver), which also has reference to user's
- // entity resolver, and also can fall-back to entityhandler's expandSystemId()
-// TraverseSchema traverseSchema;
-// traverseSchema.TraverseSchema(root, grammar, source.getSystemId());
- fGrammarResolver->putGrammar(grammar->getTargetNamespace(), grammar);
+ TraverseSchema traverseSchema(root, fURIStringPool, grammar, fGrammarResolver, this, fValidator, uri, fEntityResolver);
}
}
fGrammar = grammar;
@@ -2536,6 +2562,8 @@
return false;
else {
fGrammar = tempGrammar;
+ if (fValidator)
+ fValidator->setGrammar(fGrammar);
return true;
}
}
@@ -2551,6 +2579,79 @@
return false;
else {
fGrammar = tempGrammar;
+ if (fValidator)
+ fValidator->setGrammar(fGrammar);
return true;
}
+}
+
+// check if we should skip or lax the validation of the element
+// if skip - no validation
+// if lax - validate only if the element if found
+
+bool XMLScanner::laxElementValidation(QName* element, ContentLeafNameTypeVector* cv)
+{
+ bool skipThisOne = false;
+ bool laxThisOne = false;
+ unsigned int elementURI = element->getURI();
+
+ if (cv) {
+ for (unsigned int i=0; i < cv->getLeafCount(); i++) {
+ QName* fElemMap = cv->getLeafNameAt(i);
+ unsigned int uri = fElemMap->getURI();
+ 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) {
+ if (uri == fEmptyNamespaceId || uri == elementURI)
+ break;
+ } else if (type == ContentSpecNode::Any_Local) {
+ if (elementURI == fEmptyNamespaceId)
+ break;
+ } else if (type == ContentSpecNode::Any_Other) {
+ if (uri != elementURI)
+ break;
+ } else if (type == ContentSpecNode::Any_Skip) {
+ if (uri == fEmptyNamespaceId || uri == elementURI) {
+ skipThisOne = true;
+ break;
+ }
+ } else if (type == ContentSpecNode::Any_Local_Skip) {
+ if (elementURI == fEmptyNamespaceId) {
+ skipThisOne = true;
+ break;
+ }
+ } else if (type == ContentSpecNode::Any_Other_Skip) {
+ if (uri != elementURI) {
+ skipThisOne = true;
+ break;
+ }
+ } else if (type == ContentSpecNode::Any_Lax) {
+ if (uri == fEmptyNamespaceId || uri == elementURI) {
+ laxThisOne = true;
+ break;
+ }
+ } else if (type == ContentSpecNode::Any_Local_Lax) {
+ if (elementURI == fEmptyNamespaceId) {
+ laxThisOne = true;
+ break;
+ }
+ } else if (type == ContentSpecNode::Any_Other_Lax) {
+ if (uri != elementURI) {
+ laxThisOne = true;
+ break;
+ }
+ }
+ } // for
+ } // if
+
+ if (skipThisOne) {
+ fValidate = false;
+ fElemStack.setValidationFlag(fValidate);
+ }
+
+ return laxThisOne;
}
1.11 +15 -4 xml-xerces/c/src/parsers/SAX2XMLReaderImpl.cpp
Index: SAX2XMLReaderImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/parsers/SAX2XMLReaderImpl.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SAX2XMLReaderImpl.cpp 2001/03/30 16:46:57 1.10
+++ SAX2XMLReaderImpl.cpp 2001/05/03 20:34:33 1.11
@@ -56,6 +56,9 @@
/*
* $Log: SAX2XMLReaderImpl.cpp,v $
+ * Revision 1.11 2001/05/03 20:34:33 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.10 2001/03/30 16:46:57 tng
* Schema: Use setDoSchema instead of setSchemaValidation which makes more sense.
*
@@ -379,10 +382,14 @@
// 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);
+ }
}
@@ -395,10 +402,14 @@
void SAX2XMLReaderImpl::setEntityResolver(EntityResolver* const resolver)
{
fEntityResolver = resolver;
- if (fEntityResolver)
+ if (fEntityResolver) {
fScanner->setEntityHandler(this);
- else
+ fScanner->setEntityResolver(fEntityResolver);
+ }
+ else {
fScanner->setEntityHandler(0);
+ fScanner->setEntityResolver(0);
+ }
}
void SAX2XMLReaderImpl::parse (const InputSource& source)
1.19 +11 -1 xml-xerces/c/src/util/XMLString.hpp
Index: XMLString.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/util/XMLString.hpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- XMLString.hpp 2001/05/03 19:17:35 1.18
+++ XMLString.hpp 2001/05/03 20:34:35 1.19
@@ -56,6 +56,9 @@
/*
* $Log: XMLString.hpp,v $
+ * Revision 1.19 2001/05/03 20:34:35 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.18 2001/05/03 19:17:35 knoaman
* TraverseSchema Part II.
*
@@ -1092,6 +1095,13 @@
*/
static RefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc);
+ /** Find is the string appears in the enum list
+ * @param toFind the string to be found
+ * @param enumList the list
+ * return true if found
+ */
+ static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
+
//@}
/** @name Formatting functions */
@@ -1228,7 +1238,7 @@
unsigned int suffixLen = XMLString::stringLen(suffix);
- return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
+ return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
suffix, 0, suffixLen);
}
1.5 +9 -6 xml-xerces/c/src/validators/DTD/DTDScanner.cpp
Index: DTDScanner.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/DTD/DTDScanner.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DTDScanner.cpp 2001/04/23 18:54:35 1.4
+++ DTDScanner.cpp 2001/05/03 20:34:36 1.5
@@ -56,6 +56,9 @@
/*
* $Log: DTDScanner.cpp,v $
+ * Revision 1.5 2001/05/03 20:34:36 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.4 2001/04/23 18:54:35 tng
* Reuse grammar should allow users to use any stored element decl as root. Fixed by Erik Rydgren.
*
@@ -597,7 +600,7 @@
// Find this element's declaration. If it has not been declared yet,
// we will force one into the list, but not mark it as declared.
//
- DTDElementDecl* elemDecl = (DTDElementDecl*) fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bbName.getRawBuffer(), 0);
+ DTDElementDecl* elemDecl = (DTDElementDecl*) fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bbName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
if (!elemDecl)
{
//
@@ -1049,7 +1052,7 @@
// this element, then use it. Else, we have to fault in an element
// decl, marked as created because of being in a content model.
//
- XMLElementDecl* decl = fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bufToUse.getRawBuffer(), 0);
+ XMLElementDecl* decl = fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bufToUse.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
if (!decl)
{
decl = new DTDElementDecl(bufToUse.getRawBuffer(), fEmptyNamespaceId);
@@ -1218,7 +1221,7 @@
// fault in an element decl, marked as created because
// of being in a content model.
//
- XMLElementDecl* decl = fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bufToUse.getRawBuffer(), 0);
+ XMLElementDecl* decl = fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bufToUse.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
if (!decl)
{
decl = new DTDElementDecl(bufToUse.getRawBuffer(), fEmptyNamespaceId);
@@ -1554,7 +1557,7 @@
DTDElementDecl* rootDecl;
if (reuseGrammar)
{
- rootDecl = (DTDElementDecl*) fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bbRootName.getRawBuffer(), 0);
+ rootDecl = (DTDElementDecl*) fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bbRootName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
if (fScanner->getDoValidation())
{
if (!rootDecl)
@@ -1810,7 +1813,7 @@
}
// Look this guy up in the element decl pool
- DTDElementDecl* decl = (DTDElementDecl*) fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bbName.getRawBuffer(), 0);
+ DTDElementDecl* decl = (DTDElementDecl*) fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, bbName.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
//
// If it does not exist, then we need to create it. If it does and
@@ -3317,7 +3320,7 @@
// this element, then use it. Else, we have to fault in an element
// decl, marked as created because of being in a content model.
//
- XMLElementDecl* decl = fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, nameBuf.getRawBuffer(), 0);
+ XMLElementDecl* decl = fDTDGrammar->getElemDecl(fEmptyNamespaceId, 0, nameBuf.getRawBuffer(), Grammar::TOP_LEVEL_SCOPE);
if (!decl)
{
decl = new DTDElementDecl(nameBuf.getRawBuffer(), fEmptyNamespaceId);
1.17 +13 -89 xml-xerces/c/src/validators/DTD/DTDValidator.cpp
Index: DTDValidator.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/DTD/DTDValidator.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- DTDValidator.cpp 2001/04/19 18:17:22 1.16
+++ DTDValidator.cpp 2001/05/03 20:34:37 1.17
@@ -55,7 +55,7 @@
*/
/*
- * $Id: DTDValidator.cpp,v 1.16 2001/04/19 18:17:22 tng Exp $
+ * $Id: DTDValidator.cpp,v 1.17 2001/05/03 20:34:37 tng Exp $
*/
@@ -69,81 +69,6 @@
#include <internal/XMLScanner.hpp>
#include <validators/DTD/DTDValidator.hpp>
-
-// ---------------------------------------------------------------------------
-// Local const data
-//
-// These are the text for the require char refs that must always be present.
-// We init these into the entity pool upon construction.
-// ---------------------------------------------------------------------------
-static const XMLCh gAmp[] = { chLatin_a, chLatin_m, chLatin_p, chNull };
-static const XMLCh gLT[] = { chLatin_l, chLatin_t, chNull };
-static const XMLCh gGT[] = { chLatin_g, chLatin_t, chNull };
-static const XMLCh gQuot[] = { chLatin_q, chLatin_u, chLatin_o, chLatin_t, chNull };
-static const XMLCh gApos[] = { chLatin_a, chLatin_p, chLatin_o, chLatin_s, chNull };
-
-
-
-// ---------------------------------------------------------------------------
-// Local methods
-// ---------------------------------------------------------------------------
-
-//
-// This method is called when we get a notation or enumeration type attribute
-// to validate. We have to confirm that the passed value to find is one of
-// the values in the passed list. The list is a space separated string of
-// values to match against.
-//
-static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList)
-{
- //
- // We loop through the values in the list via this outer loop. We end
- // when we hit the end of the enum list or get a match.
- //
- const XMLCh* listPtr = enumList;
- const unsigned int findLen = XMLString::stringLen(toFind);
- while (*listPtr)
- {
- unsigned int testInd;
- for (testInd = 0; testInd < findLen; testInd++)
- {
- //
- // If they don't match, then reset and try again. Note that
- // hitting the end of the current item will cause a mismatch
- // because there can be no spaces in the toFind string.
- //
- if (listPtr[testInd] != toFind[testInd])
- break;
- }
-
- //
- // If we went the distance, see if we matched. If we did, the current
- // list character has to be null or space.
- //
- if (testInd == findLen)
- {
- if ((listPtr[testInd] == chSpace) || !listPtr[testInd])
- return true;
- }
-
- // Run the list pointer up to the next substring
- while ((*listPtr != chSpace) && *listPtr)
- listPtr++;
-
- // If we hit the end, then we failed
- if (!*listPtr)
- return false;
-
- // Else move past the space and try again
- listPtr++;
- }
-
- // We never found it
- return false;
-}
-
-
-
// ---------------------------------------------------------------------------
// DTDValidator: Constructors and Destructor
// ---------------------------------------------------------------------------
@@ -163,15 +88,14 @@
// ---------------------------------------------------------------------------
// DTDValidator: Implementation of the XMLValidator interface
// ---------------------------------------------------------------------------
-int DTDValidator::checkContent( const unsigned int elemId
- , QName** const children
- , const unsigned int childCount)
+int DTDValidator::checkContent(XMLElementDecl* const elemDecl
+ , QName** const children
+ , const unsigned int childCount)
{
//
// Look up the element id in our element decl pool. This will get us
// the element decl in our own way of looking at them.
//
- DTDElementDecl* elemDecl = (DTDElementDecl*) fDTDGrammar->getElemDecl(elemId);
if (!elemDecl)
ThrowXML(RuntimeException, XMLExcepts::Val_InvalidElemId);
@@ -179,7 +103,7 @@
// Get the content spec type of this element. This will tell us what
// to do to validate it.
//
- const DTDElementDecl::ModelTypes modelType = elemDecl->getModelType();
+ const DTDElementDecl::ModelTypes modelType = ((DTDElementDecl*) elemDecl)->getModelType();
if (modelType == DTDElementDecl::Empty)
{
@@ -289,7 +213,7 @@
void
-DTDValidator::validateAttrValue(const XMLAttDef& attDef
+DTDValidator::validateAttrValue(const XMLAttDef* attDef
, const XMLCh* const attrValue)
{
//
@@ -297,11 +221,11 @@
// order to simplify the code below, which will reference them very
// often.
//
- const XMLAttDef::AttTypes type = attDef.getType();
- const XMLAttDef::DefAttTypes defType = attDef.getDefaultType();
- const XMLCh* const valueText = attDef.getValue();
- const XMLCh* const fullName = attDef.getFullName();
- const XMLCh* const enumList = attDef.getEnumeration();
+ const XMLAttDef::AttTypes type = attDef->getType();
+ const XMLAttDef::DefAttTypes defType = attDef->getDefaultType();
+ const XMLCh* const valueText = attDef->getValue();
+ const XMLCh* const fullName = attDef->getFullName();
+ const XMLCh* const enumList = attDef->getEnumeration();
//
// If the default type is fixed, then make sure the passed value maps
@@ -501,7 +425,7 @@
// the notation pool (after the DTD is parsed), then obviously
// this value will be legal since it matches one of them.
//
- if (!isInList(pszTmpVal, enumList))
+ if (!XMLString::isInList(pszTmpVal, enumList))
emitError(XMLValid::DoesNotMatchEnumList, fullName);
}
@@ -662,7 +586,7 @@
{
validateAttrValue
(
- curAttDef
+ &curAttDef
, curAttDef.getValue()
);
}
1.10 +13 -2 xml-xerces/c/src/validators/DTD/DTDValidator.hpp
Index: DTDValidator.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/DTD/DTDValidator.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DTDValidator.hpp 2001/04/19 18:17:23 1.9
+++ DTDValidator.hpp 2001/05/03 20:34:37 1.10
@@ -56,6 +56,9 @@
/*
* $Log: DTDValidator.hpp,v $
+ * Revision 1.10 2001/05/03 20:34:37 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.9 2001/04/19 18:17:23 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -127,7 +130,7 @@
// -----------------------------------------------------------------------
virtual int checkContent
(
- const unsigned int elemId
+ XMLElementDecl* const elemDecl
, QName** const children
, const unsigned int childCount
);
@@ -153,9 +156,13 @@
virtual void validateAttrValue
(
- const XMLAttDef& attDef
+ const XMLAttDef* attDef
, const XMLCh* const attrValue
);
+ virtual void validateElement
+ (
+ const XMLElementDecl* elemDef
+ );
virtual Grammar* getGrammar();
virtual void setGrammar(Grammar* aGrammar);
@@ -190,6 +197,10 @@
inline void DTDValidator::setGrammar(Grammar* aGrammar) {
fDTDGrammar = (DTDGrammar*) aGrammar;
+}
+
+inline void DTDValidator::validateElement (const XMLElementDecl* elemDef) {
+ // no special DTD Element validation
}
// ---------------------------------------------------------------------------
1.5 +76 -73 xml-xerces/c/src/validators/common/ContentSpecNode.hpp
Index: ContentSpecNode.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/common/ContentSpecNode.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ContentSpecNode.hpp 2001/04/19 18:17:29 1.4
+++ ContentSpecNode.hpp 2001/05/03 20:34:39 1.5
@@ -56,6 +56,9 @@
/*
* $Log: ContentSpecNode.hpp,v $
+ * Revision 1.5 2001/05/03 20:34:39 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.4 2001/04/19 18:17:29 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -205,79 +208,6 @@
NodeTypes fType;
};
-
-// ---------------------------------------------------------------------------
-// ContentSpecNode: Constructors and Destructor
-// ---------------------------------------------------------------------------
-inline ContentSpecNode::ContentSpecNode() :
-
- fElement(0)
- , fFirst(0)
- , fSecond(0)
- , fType(ContentSpecNode::Leaf)
-{
- fElement = new QName (XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId);
-}
-
-inline
-ContentSpecNode::ContentSpecNode(QName* const element) :
-
- fElement(0)
- , fFirst(0)
- , fSecond(0)
- , fType(ContentSpecNode::Leaf)
-{
- if (!element)
- fElement = new QName (XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId);
- else
- fElement = new QName(element);
-}
-
-inline
-ContentSpecNode::ContentSpecNode(const NodeTypes type
- , ContentSpecNode* const firstAdopt
- , ContentSpecNode* const secondAdopt) :
-
- fElement(0)
- , fFirst(firstAdopt)
- , fSecond(secondAdopt)
- , fType(type)
-{
- fElement = new QName (XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId);
-}
-
-inline
-ContentSpecNode::ContentSpecNode(const ContentSpecNode& toCopy)
-{
- const QName* tempElement = toCopy.getElement();
- if (tempElement)
- fElement = new QName(*tempElement);
- else
- fElement = new QName (XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId);
-
- const ContentSpecNode *tmp = toCopy.getFirst();
- if (!tmp)
- fFirst = new ContentSpecNode(*tmp);
- else
- fFirst = 0;
-
- tmp = toCopy.getSecond();
- if (!tmp)
- fSecond = new ContentSpecNode(*tmp);
- else
- fSecond = 0;
-
- fType = toCopy.getType();
-}
-
-inline ContentSpecNode::~ContentSpecNode()
-{
- // Delete our children, which cause recursive cleanup
- delete fFirst;
- delete fSecond;
- delete fElement;
-}
-
// ---------------------------------------------------------------------------
// ContentSpecNode: Getter methods
// ---------------------------------------------------------------------------
@@ -354,6 +284,79 @@
inline void ContentSpecNode::setType(const NodeTypes type)
{
fType = type;
+}
+
+
+// ---------------------------------------------------------------------------
+// ContentSpecNode: Constructors and Destructor
+// ---------------------------------------------------------------------------
+inline ContentSpecNode::ContentSpecNode() :
+
+ fElement(0)
+ , fFirst(0)
+ , fSecond(0)
+ , fType(ContentSpecNode::Leaf)
+{
+ fElement = new QName (XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId);
+}
+
+inline
+ContentSpecNode::ContentSpecNode(QName* const element) :
+
+ fElement(0)
+ , fFirst(0)
+ , fSecond(0)
+ , fType(ContentSpecNode::Leaf)
+{
+ if (!element)
+ fElement = new QName (XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId);
+ else
+ fElement = new QName(element);
+}
+
+inline
+ContentSpecNode::ContentSpecNode(const NodeTypes type
+ , ContentSpecNode* const firstAdopt
+ , ContentSpecNode* const secondAdopt) :
+
+ fElement(0)
+ , fFirst(firstAdopt)
+ , fSecond(secondAdopt)
+ , fType(type)
+{
+ fElement = new QName (XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId);
+}
+
+inline
+ContentSpecNode::ContentSpecNode(const ContentSpecNode& toCopy)
+{
+ const QName* tempElement = toCopy.getElement();
+ if (tempElement)
+ fElement = new QName(*tempElement);
+ else
+ fElement = new QName (XMLUni::fgZeroLenString, XMLUni::fgZeroLenString, XMLElementDecl::fgInvalidElemId);
+
+ const ContentSpecNode *tmp = toCopy.getFirst();
+ if (!tmp)
+ fFirst = new ContentSpecNode(*tmp);
+ else
+ fFirst = 0;
+
+ tmp = toCopy.getSecond();
+ if (!tmp)
+ fSecond = new ContentSpecNode(*tmp);
+ else
+ fSecond = 0;
+
+ fType = toCopy.getType();
+}
+
+inline ContentSpecNode::~ContentSpecNode()
+{
+ // Delete our children, which cause recursive cleanup
+ delete fFirst;
+ delete fSecond;
+ delete fElement;
}
#endif
1.3 +23 -0 xml-xerces/c/src/validators/common/Grammar.hpp
Index: Grammar.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/common/Grammar.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Grammar.hpp 2001/04/19 18:17:31 1.2
+++ Grammar.hpp 2001/05/03 20:34:40 1.3
@@ -56,6 +56,9 @@
/*
* $Log: Grammar.hpp,v $
+ * Revision 1.3 2001/05/03 20:34:40 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.2 2001/04/19 18:17:31 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -80,9 +83,29 @@
class VALIDATORS_EXPORT Grammar
{
public:
+
+ // -----------------------------------------------------------------------
+ // Class Specific Types
+ //
+ // DTDGrammarType - Indicate this Grammar is built from a DTD.
+ // SchemaGrammarType - Indicate this Grammar is built from a Schema.
+ //
+ // TOP_LEVEL_SCOPE - outermost scope level (i.e. global) of a declaration.
+ // For DTD, all element decls and attribute decls always
+ // have TOP_LEVEL_SCOPE. For schema, it may varies if
+ // it is inside a complex type.
+ //
+ // UNKNOWN_SCOPE - unknown scope level. None of the decls should have this.
+ //
+ // -----------------------------------------------------------------------
enum GrammarType {
DTDGrammarType
, SchemaGrammarType
+ };
+
+ enum {
+ UNKNOWN_SCOPE = -2
+ , TOP_LEVEL_SCOPE = -1
};
// -----------------------------------------------------------------------
1.2 +7 -4 xml-xerces/c/src/validators/schema/ComplexTypeInfo.cpp
Index: ComplexTypeInfo.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/ComplexTypeInfo.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ComplexTypeInfo.cpp 2001/04/19 17:43:14 1.1
+++ ComplexTypeInfo.cpp 2001/05/03 20:34:41 1.2
@@ -56,6 +56,9 @@
/*
* $Log: ComplexTypeInfo.cpp,v $
+ * Revision 1.2 2001/05/03 20:34:41 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.1 2001/04/19 17:43:14 knoaman
* More schema implementation classes.
*
@@ -76,7 +79,7 @@
, fDerivedBy(0)
, fBlockSet(0)
, fFinalSet(0)
- , fScopeDefined(-1)
+ , fScopeDefined(Grammar::TOP_LEVEL_SCOPE)
, fElementId(XMLElementDecl::fgInvalidElemId)
, fTypeName(0)
, fBaseDatatypeValidator(0)
@@ -110,7 +113,7 @@
// Tell this guy the element id of its parent (us)
toAdd->setElemId(getElementId());
- fAttDefs->put((void*)(toAdd->getAttName()->getLocalPart()),
+ fAttDefs->put((void*)(toAdd->getAttName()->getLocalPart()),
toAdd->getAttName()->getURI(), toAdd);
}
@@ -148,7 +151,7 @@
void ComplexTypeInfo::faultInAttDefList() const
{
// Use a hash modulus of 29 and tell it owns its elements
- ((ComplexTypeInfo*)this)->fAttDefs =
+ ((ComplexTypeInfo*)this)->fAttDefs =
new RefHash2KeysTableOf<SchemaAttDef>(29, true);
}
1.8 +9 -0 xml-xerces/c/src/validators/schema/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/Makefile.in,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Makefile.in 2001/05/03 19:17:57 1.7
+++ Makefile.in 2001/05/03 20:34:42 1.8
@@ -55,8 +55,17 @@
#
#
# $Log: Makefile.in,v $
+# Revision 1.8 2001/05/03 20:34:42 tng
+# Schema: SchemaValidator update
+#
# Revision 1.7 2001/05/03 19:17:57 knoaman
# TraverseSchema Part II.
+#
+# Revision 1.6 2001/04/19 17:43:14 knoaman
+# More schema implementation classes.
+#
+# Revision 1.5 2001/04/04 18:02:04 tng
+# Schema: include failure on Unix for XUtil.cpp. Fixed by Pei Yong Zhang.
#
# Revision 1.4 2001/03/30 16:06:00 tng
# Schema: XUtil, added by Pei Yong Zhang
1.7 +39 -2 xml-xerces/c/src/validators/schema/SchemaElementDecl.cpp
Index: SchemaElementDecl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaElementDecl.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- SchemaElementDecl.cpp 2001/05/03 19:17:59 1.6
+++ SchemaElementDecl.cpp 2001/05/03 20:34:42 1.7
@@ -56,6 +56,9 @@
/*
* $Log: SchemaElementDecl.cpp,v $
+ * Revision 1.7 2001/05/03 20:34:42 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.6 2001/05/03 19:17:59 knoaman
* TraverseSchema Part II.
*
@@ -103,8 +106,9 @@
, fMiscFlags(0)
, fDefaultValue(0)
, fSubstitutionGroupName(0)
- , fTypeFromAnotherSchemaURI(0)
+ , fTypeFromAnotherSchemaURI(0)
, fComplexTypeInfo(0)
+ , fAttDefs(0)
{
}
@@ -124,6 +128,7 @@
, fSubstitutionGroupName(0)
, fTypeFromAnotherSchemaURI(0)
, fComplexTypeInfo(0)
+ , fAttDefs(0)
{
setElementName(prefix, localPart, uriId);
}
@@ -142,6 +147,7 @@
, fSubstitutionGroupName(0)
, fTypeFromAnotherSchemaURI(0)
, fComplexTypeInfo(0)
+ , fAttDefs(0)
{
setElementName(elementName);
}
@@ -150,6 +156,7 @@
{
delete [] fDefaultValue;
delete [] fSubstitutionGroupName;
+ delete fAttDefs;
}
@@ -164,7 +171,37 @@
, bool& wasAdded) const
{
if (fComplexTypeInfo == 0) {
- return 0;
+ if (options == XMLElementDecl::AddIfNotFound) {
+ SchemaAttDef* retVal = 0;
+
+ // If no att list exist yet, then create one
+ if (!fAttDefs) {
+ // Use a hash modulus of 29 and tell it owns its elements
+ ((SchemaElementDecl*)this)->fAttDefs = new RefHash2KeysTableOf<SchemaAttDef>(29, true);
+ }
+
+ retVal = fAttDefs->get(baseName, uriId);
+
+ // Fault it in if not found and ask to add it
+ if (!retVal)
+ {
+ // And add a default attribute for this name
+ retVal = new SchemaAttDef(prefix, baseName, uriId);
+ retVal->setElemId(getId());
+ fAttDefs->put((void*)baseName, uriId, retVal);
+
+ wasAdded = true;
+ }
+ else
+ {
+ wasAdded = false;
+ }
+ return retVal;
+ }
+ else {
+ wasAdded = false;
+ return 0;
+ }
}
return fComplexTypeInfo->findAttr(qName, uriId, baseName, prefix, options, wasAdded);
1.6 +11 -0 xml-xerces/c/src/validators/schema/SchemaElementDecl.hpp
Index: SchemaElementDecl.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaElementDecl.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SchemaElementDecl.hpp 2001/05/03 19:18:01 1.5
+++ SchemaElementDecl.hpp 2001/05/03 20:34:43 1.6
@@ -56,6 +56,9 @@
/*
* $Log: SchemaElementDecl.hpp,v $
+ * Revision 1.6 2001/05/03 20:34:43 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.5 2001/05/03 19:18:01 knoaman
* TraverseSchema Part II.
*
@@ -243,6 +246,13 @@
// fComplexTypeInfo
// Stores complex type information
// (no need to delete - handled by schema grammar)
+ //
+ // fAttDefs
+ // The list of attributes that are faulted in for this element
+ // when ComplexTypeInfo does not exist. We want to keep track
+ // of these faulted in attributes to avoid duplicate redundant
+ // error.
+
// -----------------------------------------------------------------------
ModelTypes fModelType;
DatatypeValidator* fDatatypeValidator;
@@ -255,6 +265,7 @@
XMLCh* fSubstitutionGroupName;
XMLCh* fTypeFromAnotherSchemaURI;
ComplexTypeInfo* fComplexTypeInfo;
+ RefHash2KeysTableOf<SchemaAttDef>* fAttDefs;
};
// ---------------------------------------------------------------------------
1.3 +13 -3 xml-xerces/c/src/validators/schema/SchemaGrammar.hpp
Index: SchemaGrammar.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaGrammar.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SchemaGrammar.hpp 2001/04/19 17:43:19 1.2
+++ SchemaGrammar.hpp 2001/05/03 20:34:43 1.3
@@ -56,6 +56,9 @@
/*
* $Log: SchemaGrammar.hpp,v $
+ * Revision 1.3 2001/05/03 20:34:43 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.2 2001/04/19 17:43:19 knoaman
* More schema implementation classes.
*
@@ -177,6 +180,7 @@
// -----------------------------------------------------------------------
// Getter methods
// -----------------------------------------------------------------------
+ RefHash3KeysIdPoolEnumerator<SchemaElementDecl> getElemEnumerator() const;
const XMLCh* getTargetNamespace() const;
XMLCh* getTargetNamespace() ;
RefHashTableOf<XMLAttDef>* getAttributeDeclRegistry() const;
@@ -236,6 +240,12 @@
// ---------------------------------------------------------------------------
// SchemaGrammar: Getter methods
// ---------------------------------------------------------------------------
+inline RefHash3KeysIdPoolEnumerator<SchemaElementDecl>
+SchemaGrammar::getElemEnumerator() const
+{
+ return RefHash3KeysIdPoolEnumerator<SchemaElementDecl>(fElemDeclPool);
+}
+
inline XMLCh* SchemaGrammar::getTargetNamespace() {
return fTargetNamespace;
}
@@ -249,7 +259,7 @@
return fAttributeDeclRegistry;
}
-inline RefHashTableOf<ComplexTypeInfo>*
+inline RefHashTableOf<ComplexTypeInfo>*
SchemaGrammar::getComplexTypeRegistry() const {
return fComplexTypeRegistry;
@@ -272,7 +282,7 @@
fTargetNamespace = XMLString::replicate(targetNamespace);
}
-inline void
+inline void
SchemaGrammar::setAttributeDeclRegistry(RefHashTableOf<XMLAttDef>* const attReg) {
fAttributeDeclRegistry = attReg;
@@ -284,7 +294,7 @@
fComplexTypeRegistry = other;
}
-inline void
+inline void
SchemaGrammar::setDatatypeRegistry(DatatypeValidatorFactory* const dvRegistry) {
fDatatypeRegistry = dvRegistry;
1.3 +17 -16 xml-xerces/c/src/validators/schema/SchemaSymbols.hpp
Index: SchemaSymbols.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaSymbols.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SchemaSymbols.hpp 2001/05/03 19:18:04 1.2
+++ SchemaSymbols.hpp 2001/05/03 20:34:44 1.3
@@ -1,37 +1,37 @@
/*
* The Apache Software License, Version 1.1
- *
+ *
* Copyright (c) 1999-2000 The Apache Software Foundation. All rights
* reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
+ * notice, this list of conditions and the following disclaimer.
+ *
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
- *
+ *
* 3. The end-user documentation included with the redistribution,
- * if any, must include the following acknowledgment:
+ * if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
- *
+ *
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
- * software without prior written permission. For written
+ * software without prior written permission. For written
* permission, please contact apache\@apache.org.
- *
+ *
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
- *
+ *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -45,7 +45,7 @@
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
- *
+ *
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation, and was
* originally based on software copyright (c) 1999, International
@@ -55,7 +55,7 @@
*/
/*
- * $Id: SchemaSymbols.hpp,v 1.2 2001/05/03 19:18:04 knoaman Exp $
+ * $Id: SchemaSymbols.hpp,v 1.3 2001/05/03 20:34:44 tng Exp $
*/
#if !defined(SCHEMASYMBOLS_HPP)
@@ -63,7 +63,7 @@
#include <util/XercesDefs.hpp>
-/*
+/*
* Collection of symbols used to parse a Schema Grammar
*/
@@ -215,7 +215,7 @@
static const XMLCh fgDT_USHORT[];
static const XMLCh fgDT_UBYTE[];
static const XMLCh fgDT_POSITIVEINTEGER[];
- static const XMLCh fgDT_RECURRINGDURATION[];
+ static const XMLCh fgDT_RECURRINGDURATION[];
static const XMLCh fgDT_TIMEINSTANT[];
static const XMLCh fgDT_TIMEPERIOD[];
static const XMLCh fgDT_DATE[];
@@ -250,7 +250,8 @@
enum {
INFINITY = -1,
NILLABLE = 1,
- ABSTRACT = 2
+ ABSTRACT = 2,
+ FIXED = 4
};
};
1.4 +572 -39 xml-xerces/c/src/validators/schema/SchemaValidator.cpp
Index: SchemaValidator.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaValidator.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SchemaValidator.cpp 2001/04/19 18:17:39 1.3
+++ SchemaValidator.cpp 2001/05/03 20:34:44 1.4
@@ -56,6 +56,9 @@
/*
* $Log: SchemaValidator.cpp,v $
+ * Revision 1.4 2001/05/03 20:34:44 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.3 2001/04/19 18:17:39 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -70,11 +73,15 @@
// ---------------------------------------------------------------------------
// Includes
// ---------------------------------------------------------------------------
+#include <util/Janitor.hpp>
#include <util/KVStringPair.hpp>
+#include <framework/XMLDocumentHandler.hpp>
#include <internal/XMLReader.hpp>
#include <internal/XMLScanner.hpp>
#include <validators/datatype/InvalidDatatypeValueException.hpp>
+#include <validators/schema/SchemaSymbols.hpp>
#include <validators/schema/SchemaValidator.hpp>
+#include <validators/schema/SubstitutionGroupComparator.hpp>
// ---------------------------------------------------------------------------
// SchemaValidator: Constructors and Destructor
@@ -85,17 +92,20 @@
, fGrammarResolver(0)
, fTrailing(false)
, fBufferDatatype(0)
+ , fXsiType(0)
+ , fNil(0)
{
}
SchemaValidator::~SchemaValidator()
{
+ delete fXsiType;
}
// ---------------------------------------------------------------------------
// SchemaValidator: Implementation of the XMLValidator interface
// ---------------------------------------------------------------------------
-int SchemaValidator::checkContent (const unsigned int elemId
+int SchemaValidator::checkContent (XMLElementDecl* const elemDecl
, QName** const children
, const unsigned int childCount)
{
@@ -103,7 +113,6 @@
// Look up the element id in our element decl pool. This will get us
// the element decl in our own way of looking at them.
//
- SchemaElementDecl* elemDecl = (SchemaElementDecl*) fSchemaGrammar->getElemDecl(elemId);
if (!elemDecl)
ThrowXML(RuntimeException, XMLExcepts::Val_InvalidElemId);
@@ -111,7 +120,7 @@
// Get the content spec type of this element. This will tell us what
// to do to validate it.
//
- const SchemaElementDecl::ModelTypes modelType = elemDecl->getModelType();
+ const SchemaElementDecl::ModelTypes modelType = ((SchemaElementDecl*) elemDecl)->getModelType();
if (modelType == SchemaElementDecl::Empty)
{
@@ -122,54 +131,87 @@
if (childCount)
return 0;
}
- else if (modelType == SchemaElementDecl::Any)
+ else if (modelType == SchemaElementDecl::Any)
{
// We pass no judgement on this one, anything goes
}
- else if ((modelType == SchemaElementDecl::Mixed)
- || (modelType == SchemaElementDecl::Children))
+ else if ((modelType == SchemaElementDecl::Mixed)
+ || (modelType == SchemaElementDecl::Children))
{
// Get the element's content model or fault it in
- const XMLContentModel* elemCM = elemDecl->getContentModel();
+ XMLContentModel* elemCM = elemDecl->getContentModel();
// Ask it to validate and return its return
int result = elemCM->validateContent(children, childCount, getScanner()->getEmptyNamespaceId());
if (result != -1) {
-// SubstitutionGroupComparator comparator(fGrammarResolver, fStringPool);
-// elemCM->setSubstitutionGroupComparator(comparator);
- result = elemCM->validateContentSpecial(children, childCount, getScanner()->getEmptyNamespaceId());
+ result = elemCM->validateContentSpecial(children
+ , childCount
+ , getScanner()->getEmptyNamespaceId()
+ , fGrammarResolver
+ , getScanner()->getURIStringPool());
}
return result;
}
- else if (modelType == SchemaElementDecl::Simple)
+ else if (modelType == SchemaElementDecl::Simple)
{
- if (childCount > 0) {
- emitError(XMLValid::SimpleTypeHasChild, elemDecl->getFullName());
- } else {
- try {
- if (!fCurrentDV) {
- //no character data
- fCurrentDV = elemDecl->getDatatypeValidator();
- }
-
- // If there is xsi:type validator, substitute it.
+ if (childCount > 0) {
+ emitError(XMLValid::SimpleTypeHasChild, elemDecl->getFullName());
+ } else {
+ try {
+ DatatypeValidator* fCurrentDV = ((SchemaElementDecl*)elemDecl)->getDatatypeValidator();
+ // If there is xsi:type validator, substitute it.
if (!fXsiTypeValidator) {
- fCurrentDV = fXsiTypeValidator;
- fXsiTypeValidator = 0;
+ fCurrentDV = fXsiTypeValidator;
+ fXsiTypeValidator = 0;
}
if (!fCurrentDV) {
emitError(XMLValid::NoDatatypeValidatorForSimpleType, elemDecl->getFullName());
} else {
- XMLCh* value =fDatatypeBuffer.getRawBuffer();
- fCurrentDV->validate(value);
+ XMLCh* value = fDatatypeBuffer.getRawBuffer();
+ XMLCh* elemDefaultValue = ((SchemaElementDecl*) elemDecl)->getDefaultValue();
+
+ if (elemDefaultValue) {
+ // a default value was specified
+ if (!XMLString::compareString(value, XMLUni::fgZeroLenString)) {
+ // if this element didn't specified any value
+ // use default value
+ getScanner()->getDocHandler()->docCharacters(elemDefaultValue, XMLString::stringLen(elemDefaultValue), false);
+ }
+ else {
+ // this element has specified some value
+ // if the flag is FIXED, then this value must be same as default value
+ if ((((SchemaElementDecl*)elemDecl)->getMiscFlags() == SchemaSymbols::FIXED) != 0) {
+ if (fCurrentDV->compare(value, elemDefaultValue) != 0 )
+ emitError(XMLValid::FixedDifferentFromActual, elemDecl->getFullName());
+ }
+
+ // if nillable, it's an error to have value
+ if (fNil)
+ emitError(XMLValid::NilAttrNotEmpty, elemDecl->getFullName());
+ else
+ fCurrentDV->validate(value);
+ }
+ }
+ else {
+ // no default value, then check nillable
+ if (fNil) {
+ if (XMLString::compareString(value, XMLUni::fgZeroLenString))
+ emitError(XMLValid::NilAttrNotEmpty, elemDecl->getFullName());
+ }
+ else
+ fCurrentDV->validate(value);
+ }
}
} catch (InvalidDatatypeValueException idve) {
emitError (XMLValid::DatatypeError, idve.getType(), idve.getMessage());
+ }
+ catch (...) {
+ emitError(XMLValid::GenericError);
}
- fCurrentDV = 0;
+ fNil = false;
fBufferDatatype=false;
fDatatypeBuffer.reset();
- }
+ }
}
else
{
@@ -184,33 +226,526 @@
bool SchemaValidator::checkRootElement (const unsigned int elemId)
{
- return false;
+ // we have nothing to check for root in schema
+ // always return true
+ return true;
}
void SchemaValidator::faultInAttr (XMLAttr& toFill, const XMLAttDef& attDef) const
{
+ //
+ // At this level, we cannot set the URI id. So we just set it to zero
+ // and leave it at that. The scanner, who called us, will look at the
+ // prefix we stored (if any), resolve it, and store the URL id if any.
+ //
+ SchemaAttDef* schemaAttDef = (SchemaAttDef*) &attDef;
+ QName* attName = schemaAttDef->getAttName();
+
+ toFill.set
+ (
+ attName->getURI()
+ , attName->getLocalPart()
+ , attName->getPrefix()
+ , schemaAttDef->getValue()
+ , schemaAttDef->getType()
+ );
}
-void SchemaValidator::preContentValidation(bool reuseGrammar)
+void SchemaValidator::reset()
{
}
-void SchemaValidator::postParseValidation()
+bool SchemaValidator::requiresNamespaces() const
{
+ return true;
}
-void SchemaValidator::reset()
+void SchemaValidator::validateAttrValue (const XMLAttDef* attDef
+ , const XMLCh* const attrValue)
+{
+ //
+ // Get quick refs to lot of the stuff in the passed objects in
+ // order to simplify the code below, which will reference them very
+ // often.
+ //
+ XMLAttDef::AttTypes type = attDef->getType();
+ const XMLAttDef::DefAttTypes defType = attDef->getDefaultType();
+ const XMLCh* const valueText = attDef->getValue();
+ const XMLCh* const fullName = attDef->getFullName();
+ XMLBuffer enumList;
+ enumList.set(attDef->getEnumeration());
+
+ //
+ // If the default type is fixed, then make sure the passed value maps
+ // to the fixed value.
+ //
+ if (defType == XMLAttDef::Fixed)
+ {
+ if (XMLString::compareString(attrValue, valueText))
+ emitError(XMLValid::NotSameAsFixedValue, fullName, attrValue, valueText);
+ }
+
+ // An empty string cannot be valid for non_CDATA any of the other types
+ if (!attrValue[0] && type != XMLAttDef::Simple)
+ {
+ emitError(XMLValid::InvalidEmptyAttValue, fullName);
+ return;
+ }
+
+ if (type == XMLAttDef::Simple) {
+ DatatypeValidator* attDefDV = ((SchemaAttDef*) attDef)->getDatatypeValidator();
+ if (!attDefDV) {
+ emitError(XMLValid::NoDatatypeValidatorForAttribute, fullName);
+ }
+ else {
+ try {
+ attDefDV->validate(attrValue);
+ } catch (InvalidDatatypeValueException idve) {
+ emitError (XMLValid::DatatypeError, idve.getType(), idve.getMessage());
+ }
+ catch (...) {
+ emitError(XMLValid::GenericError);
+ }
+ }
+ }
+ else {
+ // Check the Any Type and Simple Type using datatype validator
+ if (type == XMLAttDef::Any_Any
+ || type == XMLAttDef::Any_List
+ || type == XMLAttDef::Any_Local
+ || type == XMLAttDef::Any_Other) {
+
+ if (defType == XMLAttDef::ProcessContents_Skip) {
+ // attribute should just be bypassed,
+ }
+ else if (defType == XMLAttDef::ProcessContents_Strict
+ || defType == XMLAttDef::ProcessContents_Lax) {
+
+ bool reportError = false;
+ bool processContentStrict = (defType == XMLAttDef::ProcessContents_Strict);
+ QName* const attName = ((SchemaAttDef*)attDef)->getAttName();
+
+ if (attName->getURI() == getScanner()->getEmptyNamespaceId()) {
+ if (processContentStrict)
+ reportError = true;
+ } else {
+ SchemaGrammar* sGrammar = (SchemaGrammar*) fGrammarResolver->getGrammar(getScanner()->getURIText(attName->getURI()));
+ if (!sGrammar) {
+ if (processContentStrict)
+ reportError = true;
+ } else {
+ RefHashTableOf<XMLAttDef>* attRegistry = sGrammar->getAttributeDeclRegistry();
+ if (!attRegistry) {
+ if (processContentStrict)
+ reportError = true;
+ } else {
+ SchemaAttDef* attDecl = (SchemaAttDef*) attRegistry->get(attName->getLocalPart());
+ if (!attDecl) {
+ if (processContentStrict)
+ reportError = true;
+ } else {
+ DatatypeValidator* attDeclDV = attDecl->getDatatypeValidator();
+ if (!attDeclDV) {
+ if (processContentStrict)
+ reportError = true;
+ }
+ else {
+ try {
+ DatatypeValidator::ValidatorType attDeclDVType = attDeclDV->getType();
+ type = attDecl->getType();
+ enumList.set(attDecl->getEnumeration());
+ if (type == XMLAttDef::Simple)
+ attDeclDV->validate(attrValue);
+ } catch (InvalidDatatypeValueException idve) {
+ emitError (XMLValid::DatatypeError, idve.getType(), idve.getMessage());
+ }
+ catch (...) {
+ emitError(XMLValid::GenericError);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (reportError) {
+ emitError(XMLValid::AttNotDefinedForElement, fullName, XMLUni::fgZeroLenString);
+ }
+ }
+ }
+ // check the ID, IDREF, IDREFS, NMTOKEN, NMTOKENS, ENTITY, ENTITIES, NOTATION using the old methods
+
+ // See whether we are doing multiple values or not
+ const bool multipleValues =
+ (
+ (type == XMLAttDef::IDRefs)
+ || (type == XMLAttDef::Entities)
+ || (type == XMLAttDef::NmTokens)
+ || (type == XMLAttDef::Notation)
+ );
+
+ // And whether we must check for a first name char
+ const bool firstNameChar =
+ (
+ (type == XMLAttDef::ID)
+ || (type == XMLAttDef::IDRef)
+ || (type == XMLAttDef::IDRefs)
+ || (type == XMLAttDef::Entity)
+ || (type == XMLAttDef::Entities)
+ || (type == XMLAttDef::Notation)
+ );
+
+ // Some trigger flags to avoid issuing redundant errors and whatnot
+ bool sawOneValue;
+ bool alreadyCapped = false;
+
+ //
+ // Make a copy of the text that we can mangle and get a pointer we can
+ // move through the value
+ //
+
+ // Use a stack-based buffer, when possible...
+ XMLCh tempBuffer[100];
+
+ XMLCh* pszTmpVal = 0;
+
+ ArrayJanitor<XMLCh> janTmpVal(0);
+
+ if (XMLString::stringLen(attrValue) < sizeof(tempBuffer) / sizeof(tempBuffer[0]))
+ {
+ XMLString::copyString(tempBuffer, attrValue);
+ pszTmpVal = tempBuffer;
+ }
+ else
+ {
+ janTmpVal.reset(XMLString::replicate(attrValue));
+ pszTmpVal = janTmpVal.get();
+ }
+
+ XMLCh* valPtr = pszTmpVal;
+
+ while (true)
+ {
+ // Reset the trigger flags
+ sawOneValue = false;
+
+ //
+ // Make sure the first character is a valid first name char, i.e.
+ // if its a Name value. For NmToken values we don't treat the first
+ // char any differently.
+ //
+ if (firstNameChar)
+ {
+ // If its not, emit and error but try to keep going
+ if (!XMLReader::isFirstNameChar(*valPtr))
+ emitError(XMLValid::AttrValNotName, fullName);
+ valPtr++;
+ }
+
+ // Make sure all the remaining chars are valid name chars
+ while (*valPtr)
+ {
+ //
+ // If we hit a whitespace, its either a break between two
+ // or more values, or an error if we have a single value.
+ //
+ if (XMLReader::isWhitespace(*valPtr))
+ {
+ if (!multipleValues)
+ {
+ emitError(XMLValid::NoMultipleValues, fullName);
+ return;
+ }
+ break;
+ }
+
+ if (!XMLReader::isNameChar(*valPtr))
+ {
+ emitError(XMLValid::AttrValNotName, fullName);
+ return;
+ }
+ valPtr++;
+ }
+
+ //
+ // Cap it off at the current non-name char. If already capped,
+ // then remember this.
+ //
+ if (!(*valPtr))
+ alreadyCapped = true;
+ *valPtr = 0;
+
+ //
+ // If this type of attribute requires that we track reference
+ // stuff, then handle that.
+ //
+ if ((type == XMLAttDef::ID)
+ || (type == XMLAttDef::IDRef)
+ || (type == XMLAttDef::IDRefs))
+ {
+ XMLRefInfo* find = getScanner()->getIDRefList().get(pszTmpVal);
+ if (find)
+ {
+ if (find->getDeclared() && (type == XMLAttDef::ID))
+ emitError(XMLValid::ReusedIDValue, pszTmpVal);
+ }
+ else
+ {
+ find = new XMLRefInfo(pszTmpVal);
+ getScanner()->getIDRefList().put((void*)find->getRefName(), find);
+ }
+
+ //
+ // Mark it declared or used, which might be redundant in some cases
+ // but not worth checking
+ //
+ if (type == XMLAttDef::ID)
+ find->setDeclared(true);
+ else
+ find->setUsed(true);
+ }
+ else if ((type == XMLAttDef::Entity) || (type == XMLAttDef::Entities))
+ {
+ //
+ // If its refering to a entity, then look up the name in the
+ // general entity pool. If not there, then its an error. If its
+ // not an external unparsed entity, then its an error.
+ //
+ const XMLEntityDecl* decl = getScanner()->getEntityDecl(pszTmpVal);
+ if (decl)
+ {
+ if (!decl->isUnparsed())
+ emitError(XMLValid::BadEntityRefAttr, fullName);
+ }
+ else
+ {
+ emitError
+ (
+ XMLValid::UnknownEntityRefAttr
+ , fullName
+ , pszTmpVal
+ );
+ }
+ }
+ else if (type == XMLAttDef::Notation)
+ {
+ //
+ // Make sure that this value maps to one of the
+ // notation values in the enumList parameter. We don't have to
+ // look it up in the notation pool (if a notation) because we
+ // will look up the enumerated values themselves. If they are in
+ // the notation pool (after the Grammar is parsed), then obviously
+ // this value will be legal since it matches one of them.
+ //
+ XMLBuffer nameBuf;
+ XMLBuffer prefixBuf;
+ XMLBuffer notationBuf;
+ unsigned int uriId = getScanner()->resolveQName(pszTmpVal, nameBuf, prefixBuf, ElemStack::Mode_Attribute);
+ notationBuf.set(getScanner()->getURIText(uriId));
+ notationBuf.append(chColon);
+ notationBuf.append(nameBuf.getRawBuffer());
+
+ if (!XMLString::isInList(notationBuf.getRawBuffer(), enumList.getRawBuffer()))
+ emitError(XMLValid::DoesNotMatchEnumList, fullName);
+ }
+
+ // If not doing multiple values, then we are done
+ if (!multipleValues)
+ break;
+
+ //
+ // If we are at the end, then break out now, else move up to the
+ // next char and update the base pointer.
+ //
+ if (alreadyCapped)
+ break;
+
+ valPtr++;
+ pszTmpVal = valPtr;
+ }
+ }
+}
+
+void SchemaValidator::validateElement(const XMLElementDecl* elemDef)
{
+ if (!fXsiType) {
+ //
+ // xsi:type was not specified...
+ // If the corresponding type is abstract, detect an error
+ //
+ ComplexTypeInfo* typeInfo = ((SchemaElementDecl*)elemDef)->getComplexTypeInfo();
+
+ if (typeInfo) {
+ if (typeInfo->getAbstract()) {
+ emitError(XMLValid::XsiTypeAbstract, elemDef->getFullName());
+ }
+ }
+ }
+
+ //
+ // Check whether this element is abstract. If so, an error
+ //
+ int miscFlags = ((SchemaElementDecl*)elemDef)->getMiscFlags();
+ if ((miscFlags & SchemaSymbols::ABSTRACT) != 0) {
+ emitError(XMLValid::SchemaAbstractError, elemDef->getFullName());
+ }
+ if (fNil && (miscFlags & SchemaSymbols::NILLABLE) == 0 ) {
+ fNil = false;
+ emitError(XMLValid::NillNotAllowed, elemDef->getFullName());
+ }
}
-bool SchemaValidator::requiresNamespaces() const
+void SchemaValidator::preContentValidation(bool reuseGrammar)
{
- return true;
+ //
+ // Lets enumerate all of the elements in the element decl pool
+ // and put out an error for any that did not get declared.
+ // We also check all of the attributes as well.
+ //
+ RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = fSchemaGrammar->getElemEnumerator();
+ while (elemEnum.hasMoreElements())
+ {
+ const SchemaElementDecl& curElem = elemEnum.nextElement();
+ const SchemaElementDecl::CreateReasons reason = curElem.getCreateReason();
+
+ //
+ // See if this element decl was ever marked as declared. If
+ // not, then put out an error. In some cases its just
+ // a warning, such as being referenced in a content model.
+ //
+ if (reason != XMLElementDecl::Declared)
+ {
+ if (reason == XMLElementDecl::AttList)
+ {
+ getScanner()->emitError
+ (
+ XMLErrs::UndeclaredElemInAttList
+ , curElem.getFullName()
+ );
+ }
+ else if (reason == XMLElementDecl::AsRootElem)
+ {
+ emitError
+ (
+ XMLValid::UndeclaredElemInDocType
+ , curElem.getFullName()
+ );
+ }
+ else if (reason == XMLElementDecl::InContentModel)
+ {
+ getScanner()->emitError
+ (
+ XMLErrs::UndeclaredElemInCM
+ , curElem.getFullName()
+ );
+ }
+ else
+ {
+ }
+ }
+
+ //
+ // Check all of the attributes of the current element.
+ // We check for:
+ //
+ // 1) Multiple ID attributes
+ // 2) That all of the default values of attributes are
+ // valid for their type.
+ // 3) That for any notation types, that their lists
+ // of possible values refer to declared notations.
+ //
+ if (curElem.hasAttDefs()) {
+ XMLAttDefList& attDefList = curElem.getAttDefList();
+ bool seenId = false;
+ while (attDefList.hasMoreElements())
+ {
+ const XMLAttDef& curAttDef = attDefList.nextElement();
+
+ if (curAttDef.getType() == XMLAttDef::ID)
+ {
+ if (seenId)
+ {
+ emitError
+ (
+ XMLValid::MultipleIdAttrs
+ , curElem.getFullName()
+ );
+ break;
+ }
+
+ seenId = true;
+ }
+ else if (curAttDef.getType() == XMLAttDef::Notation)
+ {
+ //
+ // We need to verify that all of its possible values
+ // (in the enum list) refer to valid notations.
+ //
+ XMLCh* list = XMLString::replicate(curAttDef.getEnumeration());
+ ArrayJanitor<XMLCh> janList(list);
+
+ //
+ // Search forward for a space or a null. If a null,
+ // we are done. If a space, cap it and look it up.
+ //
+ bool breakFlag = false;
+ XMLCh* listPtr = list;
+ XMLCh* lastPtr = listPtr;
+ while (true)
+ {
+ while (*listPtr && (*listPtr != chSpace))
+ listPtr++;
+
+ //
+ // If at the end, indicate we need to break after
+ // this one. Else, cap it off here.
+ //
+ if (!*listPtr)
+ breakFlag = true;
+ else
+ *listPtr = chNull;
+
+ if (!fSchemaGrammar->getNotationDecl(lastPtr))
+ {
+ emitError
+ (
+ XMLValid::UnknownNotRefAttr
+ , curAttDef.getFullName()
+ , lastPtr
+ );
+ }
+
+ // Break out if we hit the end last time
+ if (breakFlag)
+ break;
+
+ // Else move upwards and try again
+ listPtr++;
+ lastPtr = listPtr;
+ }
+ }
+
+ // If it has a default/fixed value, then validate it
+ if (curAttDef.getValue())
+ {
+ validateAttrValue
+ (
+ &curAttDef
+ , curAttDef.getValue()
+ );
+ }
+ }
+ }
+ }
}
-void SchemaValidator::validateAttrValue (const XMLAttDef& attDef
- , const XMLCh* const attrValue)
+void SchemaValidator::postParseValidation()
{
+ //
+ // At this time, there is nothing to do here. The scanner itself handles
+ // ID/IDREF validation, since that is the same no matter what kind of
+ // validator.
+ //
}
// ---------------------------------------------------------------------------
@@ -226,10 +761,9 @@
//
void SchemaValidator::normalizeWhiteSpace(DatatypeValidator* dV, const XMLCh* const value, XMLBuffer& toFill)
{
- fCurrentDV = dV;
short fWhiteSpace = DatatypeValidator::PRESERVE;
- if (fCurrentDV)
- fWhiteSpace = fCurrentDV->getWSFacet();
+ if (dV)
+ fWhiteSpace = dV->getWSFacet();
enum States
{
@@ -258,7 +792,6 @@
if (fWhiteSpace == DatatypeValidator::PRESERVE)
{
// do nothing
- break;
}
else if (fWhiteSpace == DatatypeValidator::REPLACE)
{
1.4 +34 -15 xml-xerces/c/src/validators/schema/SchemaValidator.hpp
Index: SchemaValidator.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/validators/schema/SchemaValidator.hpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SchemaValidator.hpp 2001/04/19 18:17:40 1.3
+++ SchemaValidator.hpp 2001/05/03 20:34:45 1.4
@@ -56,6 +56,9 @@
/*
* $Log: SchemaValidator.hpp,v $
+ * Revision 1.4 2001/05/03 20:34:45 tng
+ * Schema: SchemaValidator update
+ *
* Revision 1.3 2001/04/19 18:17:40 tng
* Schema: SchemaValidator update, and use QName in Content Model
*
@@ -98,15 +101,20 @@
// -----------------------------------------------------------------------
// Setter methods
// -----------------------------------------------------------------------
- void setXsiTypeAttValue(const XMLCh* const xsiTypeAttValue);
void setGrammarResolver(GrammarResolver* grammarResolver);
+ void setXsiType(const XMLCh* const prefix
+ , const XMLCh* const localPart
+ , const unsigned int uriId);
+
+ void setNillable(bool isNil);
+
// -----------------------------------------------------------------------
// Implementation of the XMLValidator interface
// -----------------------------------------------------------------------
virtual int checkContent
(
- const unsigned int elemId
+ XMLElementDecl* const elemDecl
, QName** const children
, const unsigned int childCount
);
@@ -132,10 +140,15 @@
virtual void validateAttrValue
(
- const XMLAttDef& attDef
+ const XMLAttDef* attDef
, const XMLCh* const attrValue
);
+ virtual void validateElement
+ (
+ const XMLElementDecl* elemDef
+ );
+
virtual Grammar* getGrammar();
virtual void setGrammar(Grammar* aGrammar);
@@ -159,25 +172,24 @@
// Private data members
//
// -----------------------------------------------------------------------
- // The following comes from the Scanner
+ // The following comes from or set by the Scanner
// fSchemaGrammar
// The current schema grammar used by the validator
//
// fGrammarResolver
// All the schema grammar stored
//
- // fXsiTypeAttValue
+ // fXsiType
// Store the Schema Type Attribute Value if schema type is specified
//
+ // fNil
+ // Indicates if Nillable has been set
// -----------------------------------------------------------------------
// The following used internally in the validator
//
// fXsiTypeValidator
// The validator used for xsi type validation
//
- // fCurrentDV
- // Current DataTypeValidator used by the validator
- //
// fDatatypeBuffer
// Buffer for simple type element string content
//
@@ -190,14 +202,13 @@
// -----------------------------------------------------------------------
SchemaGrammar* fSchemaGrammar;
GrammarResolver* fGrammarResolver;
- const XMLCh* fXsiTypeAttValue;
+ QName* fXsiType;
+ bool fNil;
DatatypeValidator* fXsiTypeValidator;
- DatatypeValidator* fCurrentDV;
bool fBufferDatatype;
XMLBuffer fDatatypeBuffer;
- bool fFirstChunk;
bool fTrailing;
};
@@ -205,12 +216,20 @@
// ---------------------------------------------------------------------------
// SchemaValidator: Setter methods
// ---------------------------------------------------------------------------
-inline void SchemaValidator::setXsiTypeAttValue(const XMLCh* const xsiTypeAttValue) {
- fXsiTypeAttValue = xsiTypeAttValue;
-}
-
inline void SchemaValidator::setGrammarResolver(GrammarResolver* grammarResolver) {
fGrammarResolver = grammarResolver;
+}
+
+inline void SchemaValidator::setXsiType(const XMLCh* const prefix
+ , const XMLCh* const localPart
+ , const unsigned int uriId)
+{
+ delete fXsiType;
+ fXsiType = new QName(prefix, localPart, uriId);
+}
+
+inline void SchemaValidator::setNillable(bool isNil) {
+ fNil = isNil;
}
// ---------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org