You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2001/09/24 19:06:44 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2 SchemaSymbols.java SchemaValidator.java XSAttributeChecker.java XSDHandler.java
sandygao 01/09/24 10:06:44
Modified: java/src/org/apache/xerces/impl/msg
XMLSchemaMessages.properties
java/src/org/apache/xerces/impl/v2 SchemaSymbols.java
SchemaValidator.java XSAttributeChecker.java
XSDHandler.java
Log:
1. Updated error messages in XSAttributeChecker;
2. More SchemaValidator code;
3. Fixed a null pointer exception.
Revision Changes Path
1.5 +3 -1 xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties
Index: XMLSchemaMessages.properties
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMLSchemaMessages.properties 2001/09/21 19:56:32 1.4
+++ XMLSchemaMessages.properties 2001/09/24 17:06:44 1.5
@@ -125,6 +125,8 @@
s4s-att-not-allowed = s4s-att-not-allowed: Attribute ''{1}'' cannot appear in element ''{0}''.
s4s-att-must-appear = s4s-att-must-appear: Attribute ''{1}'' must appear in element ''{0}''.
s4s-att-invalid-value = s4s-att-invalid-value: Invalid attribute value for ''{1}'' in element ''{0}'': {2}.
+ s4s-elt-schema-ns = s4s-elt-schema-ns: The namespace of element ''{0}'' must be from the schema namespace.
+ s4s-elt-invalid = s4s-elt-invalid: Element ''{0}'' is not a valid element in schema document.
s4s-elt-must-match = s4s-elt-must-match: The content of ''{0}'' must match {1}.
#schema valid (3.X.3)
@@ -210,7 +212,7 @@
minLength-valid-restriction = minLength-valid-restriction: error.
no-xmlns = no-xmlns: error.
no-xsi = no-xsi: error.
- n-props-correct = n-props-correct: error.
+ n-props-correct.2.1 = n-props-correct.2.1: {min occurs} = ''{1}'' must not be greater than {max occurs} = ''{2}'' for ''{0}''.
p-props-correct = p-props-correct: error.
range-ok = range-ok: error.
rcase-MapAndSum = rcase-MapAndSum: error.
1.14 +19 -19 xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaSymbols.java
Index: SchemaSymbols.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaSymbols.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SchemaSymbols.java 2001/09/24 15:24:54 1.13
+++ SchemaSymbols.java 2001/09/24 17:06:44 1.14
@@ -63,7 +63,7 @@
* Collection of symbols used to parse a Schema Grammar.
*
* @author jeffrey rodriguez
- * @version $Id: SchemaSymbols.java,v 1.13 2001/09/24 15:24:54 sandygao Exp $
+ * @version $Id: SchemaSymbols.java,v 1.14 2001/09/24 17:06:44 sandygao Exp $
*/
public final class SchemaSymbols {
@@ -251,32 +251,32 @@
public static final String ATTVAL_YEARMONTH = "yearMonth";
// block/final values
- public static final int EMPTY_SET = 0;
- public static final int EXTENSION = 1;
- public static final int RESTRICTION = 2;
- public static final int UNION = 4;
- public static final int LIST = 8;
- public static final int ENUMERATION = 16;
- public static final int SUBSTITUTION = 32;
+ public static final short EMPTY_SET = 0;
+ public static final short EXTENSION = 1;
+ public static final short RESTRICTION = 2;
+ public static final short UNION = 4;
+ public static final short LIST = 8;
+ public static final short ENUMERATION = 16;
+ public static final short SUBSTITUTION = 32;
// form qualified/unqualified
- public static final int FORM_UNQUALIFIED = 0;
- public static final int FORM_QUALIFIED = 1;
+ public static final short FORM_UNQUALIFIED = 0;
+ public static final short FORM_QUALIFIED = 1;
// any: processContents
- public static final int ANY_STRICT = 0;
- public static final int ANY_LAX = 1;
- public static final int ANY_SKIP = 2;
+ public static final short ANY_STRICT = 0;
+ public static final short ANY_LAX = 1;
+ public static final short ANY_SKIP = 2;
// attribute use
- public static final int USE_OPTIONAL = 0;
- public static final int USE_REQUIRED = 1;
- public static final int USE_PROHIBITED = 2;
+ public static final short USE_OPTIONAL = 0;
+ public static final short USE_REQUIRED = 1;
+ public static final short USE_PROHIBITED = 2;
// whiteSpace
- public static final int WS_PRESERVE = 0;
- public static final int WS_REPLACE = 1;
- public static final int WS_COLLAPSE = 2;
+ public static final short WS_PRESERVE = 0;
+ public static final short WS_REPLACE = 1;
+ public static final short WS_COLLAPSE = 2;
// maxOccurs = "unbounded"
public static final int OCCURRENCE_UNBOUNDED = -1;
1.10 +119 -59 xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaValidator.java
Index: SchemaValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaValidator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- SchemaValidator.java 2001/09/24 15:24:54 1.9
+++ SchemaValidator.java 2001/09/24 17:06:44 1.10
@@ -107,7 +107,7 @@
* @author Andy Clark, IBM
* @author Jeffrey Rodriguez IBM
*
- * @version $Id: SchemaValidator.java,v 1.9 2001/09/24 15:24:54 sandygao Exp $
+ * @version $Id: SchemaValidator.java,v 1.10 2001/09/24 17:06:44 sandygao Exp $
*/
public class SchemaValidator
implements XMLComponent, XMLDocumentHandler {
@@ -793,6 +793,7 @@
fCurrentType = null;
fCurrentCM = null;
fCurrCMState = null;
+ fBuffer = null;
fSkipValidationDepth = -1;
fElementDepth = -1;
fChildCount = 0;
@@ -994,10 +995,13 @@
getXsiNil(element, xsiNil);
// now validate everything related with the attributes
+ // first, get the attribute group
+ XSAttributeGroupDecl attrGrp = null;
if ((fCurrentType.getXSType() & XSTypeDecl.COMPLEX_TYPE) != 0) {
XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType;
- validateOnAttributes(element, attributes, ctype.fAttrGrp);
+ attrGrp = ctype.fAttrGrp;
}
+ processAttributes(element, attributes, attrGrp);
} // handleStartElement(QName,XMLAttributes,boolean)
@@ -1024,38 +1028,8 @@
return;
}
- if (fDoValidation) {
- // REVISIT: fCurrentElemDecl: fixed/default value; ...
- // REVISIT: fCurrentType: value content, element content
- if (fCurrentType != null) {
- if (fCurrentCM == null && fChildCount != 0) {
- // the parent element doesn't expect any child element
- // REVISIT: report an error
- reportGenericSchemaError("element content doesn't allowed here");
- }
- // validate against simple type
- if ((fCurrentType.getXSType() & XSTypeDecl.SIMPLE_TYPE) != 0) {
- try {
- DatatypeValidator dv = (DatatypeValidator)fCurrentType;
- String content = XSAttributeChecker.normalize(fBuffer.toString(), dv.getWSFacet());
- dv.validate(content, null);
- } catch (InvalidDatatypeValueException e) {
- //REVISIT
- reportGenericSchemaError("datatype error: " + e.getMessage());
- }
- } else {
- // REVISIT: validate against complex type with simple content
- // if the current state is a valid state, check whether
- // it's one of the final states.
- if (fCurrCMState != null && fCurrCMState[0] >= 0 &&
- !fCurrentCM.endContentModel(fCurrCMState)) {
- XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType;
- // REVISIT: report error for not matching content
- reportGenericSchemaError("the content of '"+element.rawname+"' is not complete. it must match ("+ctype.fParticle.toString()+")");
- }
- }
- }
- }
+ // now validate the content of the element
+ processElementContent(element);
// decrease element depth and restore states
fElementDepth--;
@@ -1146,15 +1120,10 @@
void checkXsiNil(String xsiNil) {
// REVISIT: check whether the content is empty
}
-
- void validateOnAttributes(QName element, XMLAttributes attributes, XSAttributeGroupDecl attrGrp) {
- XSAttributeUse attrUses[] = attrGrp.getAttributeUses();
- int useCount = attrUses.length;
- XSWildcardDecl attrWildcard = attrGrp.fAttributeWC;
+ void processAttributes(QName element, XMLAttributes attributes, XSAttributeGroupDecl attrGrp) {
- // REVISIT: do we add default attribute before or after
- // we validate the attribute values?
+ // REVISIT: add default attribute values
//if (fGrammar != null && fGrammarIsSchemaGrammar && elementIndex != -1) {
// fAttrListHandle = addDefaultAttributes(elementIndex, attrList, fAttrListHandle, fValidating, fStandaloneReader != -1);
//}
@@ -1163,6 +1132,29 @@
if (!fDoValidation)
return;
+ // if there is no attribute group, meaning no attribute is associated
+ // with this complexType, so no attributes are allowed, other than those
+ // from xsi namespace
+ if (attrGrp == null) {
+ int attCount = attributes.getLength();
+ for (int index = 0; index < attCount; index++) {
+ attributes.getName(index, fTempQName);
+ if (fTempQName.uri != URI_XSI ||
+ fTempQName.localpart != XSI_SCHEMALOCACTION &&
+ fTempQName.localpart != XSI_NONAMESPACESCHEMALOCACTION &&
+ fTempQName.localpart != XSI_NIL &&
+ fTempQName.localpart != XSI_TYPE) {
+ reportGenericSchemaError("no attribute is allowed other than those from xsi namespace whose name is one of schemaLocation, noNamespaceSchemaLocation, type, or nil");
+ return;
+ }
+ }
+ return;
+ }
+
+ XSAttributeUse attrUses[] = attrGrp.getAttributeUses();
+ int useCount = attrUses.length;
+ XSWildcardDecl attrWildcard = attrGrp.fAttributeWC;
+
// for each present attribute
int attCount = attributes.getLength();
for (int index = 0; index < attCount; index++) {
@@ -1236,28 +1228,96 @@
// if the value is fixed
if (constType == XSAttributeDecl.FIXED_VALUET) {
// REVISIT: get compiled form of value, then compare
- if (attDV.compare(attrValue, (String)defaultValue) != 0) {
+ if (attDV.compare(attrValue, (String)defaultValue) != 0)
reportGenericSchemaError("attribute value not match fixed value");
- } else {
- // if it's one of IDREF type, we should record this value for further checking against ID vlues
- if (attDV instanceof IDREFDatatypeValidator) {
- fTableOfIDRefs.put(fTempQName.localpart, fTempObject);
- }
- }
- } else {
- // otherwise, check the value against the simpleType
- // REVISIT: normalize the attribute value
- //attrValue = normalizeValue(attrValue, attDV.getWSFacet());
- try {
- // REVISIT: use XSSimpleTypeDecl.ValidateContext to replace null
- attDV.validate(attrValue, null);
- } catch (InvalidDatatypeValueException idve) {
- reportGenericSchemaError("datatype validation error: "+idve);
- }
+ }
+
+ // now check the value against the simpleType
+ // REVISIT: or should the normalize() be called withing validate()?
+ attrValue = XSAttributeChecker.normalize(attrValue, attDV.getWSFacet());
+ try {
+ // REVISIT: use XSSimpleTypeDecl.ValidateContext to replace null
+ attDV.validate(attrValue, null);
+ } catch (InvalidDatatypeValueException idve) {
+ reportGenericSchemaError("datatype validation error: "+idve);
}
} // end of if (not xsi and not xmlns)
} // end of for (all attributes)
- } //validateOnAttributes
+ } //processAttributes
+
+ void processElementContent(QName element) {
+ // REVISIT: fCurrentElemDecl: default value; ...
+ if (fCurrentElemDecl != null &&
+ fCurrentElemDecl.getConstraintType() == XSElementDecl.DEFAULT_VALUE) {
+ }
+
+ if (fDoValidation && fCurrentType != null) {
+ // validate against simple type
+ if ((fCurrentType.getXSType() & XSTypeDecl.SIMPLE_TYPE) != 0) {
+ if (fChildCount != 0)
+ reportGenericSchemaError("element content isn't allowed here");
+ try {
+ DatatypeValidator dv = (DatatypeValidator)fCurrentType;
+ if (fCurrentElemDecl != null &&
+ fCurrentElemDecl.getConstraintType() == XSElementDecl.FIXED_VALUET) {
+ // REVISIT: get compiled form of value, then compare
+ if (dv.compare(fBuffer.toString(), (String)fCurrentElemDecl.fDefault) != 0)
+ reportGenericSchemaError("element value not match fixed value");
+ }
+ // REVISIT: or should the normalize() be called withing validate()?
+ String content = XSAttributeChecker.normalize(fBuffer.toString(), dv.getWSFacet());
+ dv.validate(content, null);
+ } catch (InvalidDatatypeValueException e) {
+ //REVISIT
+ reportGenericSchemaError("datatype error: " + e.getMessage());
+ }
+ } else {
+ XSComplexTypeDecl ctype = (XSComplexTypeDecl)fCurrentType;
+ String content = XSAttributeChecker.normalize(fBuffer.toString(), SchemaSymbols.WS_COLLAPSE);
+ if (fCurrentElemDecl != null &&
+ fCurrentElemDecl.getConstraintType() == XSElementDecl.FIXED_VALUET) {
+ // REVISIT: get compiled form of value, then compare
+ if (!content.equals(fBuffer.toString()))
+ reportGenericSchemaError("element value not match fixed value");
+ }
+ boolean hasTextContent = content.length() == 0;
+ // REVISIT: implement nil
+ //if (fNil || ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_EMPTY) {
+ if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_EMPTY) {
+ if (fChildCount != 0 || hasTextContent)
+ reportGenericSchemaError("content must be empty/nil");
+ }
+
+ if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_SIMPLE) {
+ // REVISIT: validate against complex type with simple content
+ if (fChildCount != 0)
+ reportGenericSchemaError("element content isn't allowed here");
+ }
+
+ if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
+ if (hasTextContent)
+ reportGenericSchemaError("text content is not allowed for element '"+element.rawname+"'");
+ }
+
+ if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT ||
+ ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_MIXED) {
+ if (fCurrentCM == null) {
+ // the parent element doesn't expect any child element
+ // REVISIT: report an error
+ if (fChildCount != 0)
+ reportGenericSchemaError("element content isn't allowed here");
+ }
+ // if the current state is a valid state, check whether
+ // it's one of the final states.
+ else if (fCurrCMState != null && fCurrCMState[0] >= 0 &&
+ !fCurrentCM.endContentModel(fCurrCMState)) {
+ // REVISIT: report error for not matching content
+ reportGenericSchemaError("the content of '"+element.rawname+"' is not complete. it must match ("+ctype.fParticle.toString()+")");
+ }
+ }
+ } // else for complexType
+ } // if (fDoValidation && fCurrentType != null)
+ } // processElementContent
// REVISIT: move the following 5 methods to common place
boolean checkTypeDerivationOk(XSTypeDecl derived, XSTypeDecl base, int block) {
1.21 +15 -31 xml-xerces/java/src/org/apache/xerces/impl/v2/XSAttributeChecker.java
Index: XSAttributeChecker.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSAttributeChecker.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- XSAttributeChecker.java 2001/09/24 15:24:54 1.20
+++ XSAttributeChecker.java 2001/09/24 17:06:44 1.21
@@ -89,7 +89,7 @@
* - use symbol table instead of many hashtables
*
* @author Sandy Gao, IBM
- * @version $Id: XSAttributeChecker.java,v 1.20 2001/09/24 15:24:54 sandygao Exp $
+ * @version $Id: XSAttributeChecker.java,v 1.21 2001/09/24 17:06:44 sandygao Exp $
*/
public class XSAttributeChecker {
@@ -985,7 +985,7 @@
String elName = DOMUtil.getLocalName(element);
if (uri == null || !uri.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA)) {
- reportSchemaError("Con3X3ElementSchemaURI", new Object[] {elName});
+ reportSchemaError("s4s-elt-schema-ns", new Object[] {elName});
}
// Get the proper registry:
@@ -1003,8 +1003,7 @@
// get desired attribute list of this element
OneElement oneEle = (OneElement)eleAttrsMap.get(elName);
if (oneEle == null) {
- reportSchemaError ("Con3X3ElementAppearance",
- new Object[] {elName});
+ reportSchemaError ("s4s-elt-invalid", new Object[] {elName});
return null;
}
@@ -1040,8 +1039,7 @@
// and not allowed on "document" and "appInfo"
if (attrURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) ||
!oneEle.allowNonSchemaAttr) {
- reportSchemaError ("Con3X3AttributeAppearance",
- new Object[] {elName, attrName});
+ reportSchemaError ("s4s-att-not-allowed", new Object[] {elName, attrName});
}
else {
// for attributes from other namespace
@@ -1068,7 +1066,7 @@
// check whether this attribute is allowed
OneAttr oneAttr = (OneAttr)attrList.get(attrName);
if (oneAttr == null) {
- reportSchemaError ("Con3X3AttributeAppearance",
+ reportSchemaError ("s4s-att-not-allowed",
new Object[] {elName, attrName});
continue;
}
@@ -1112,7 +1110,7 @@
}
}
catch (InvalidDatatypeValueException ide) {
- reportSchemaError ("Con3X3AttributeInvalidValue",
+ reportSchemaError ("s4s-att-invalid-value",
new Object[] {elName, attrName, ide.getLocalizedMessage()});
if (oneAttr.dfltValue != null)
//attrValues.put(attrName, oneAttr.dfltValue);
@@ -1146,13 +1144,10 @@
int max = ((XInt)attrValues[ATTIDX_MAXOCCURS]).intValue();
if (max != SchemaSymbols.OCCURRENCE_UNBOUNDED) {
if (min > max) {
- reportSchemaError ("p-props-correct:2.1 Value of minOccurs '" + attrValues[ATTIDX_MINOCCURS] + "' must not be greater than value of maxOccurs '" + attrValues[ATTIDX_MAXOCCURS] +"'",
+ reportSchemaError ("p-props-correct:2.1",
new Object[] {elName, attrValues[ATTIDX_MINOCCURS], attrValues[ATTIDX_MAXOCCURS]});
+ attrValues[ATTIDX_MINOCCURS] = attrValues[ATTIDX_MAXOCCURS];
}
- if (((XInt)attrValues[ATTIDX_MAXOCCURS]).intValue() < 1) {
- reportSchemaError("p-props-correct:2.2 Value of maxOccurs " + attrValues[ATTIDX_MAXOCCURS] + " is invalid. It must be greater than or equal to 1",
- new Object[] {elName, attrValues[ATTIDX_MAXOCCURS]});
- }
}
}
@@ -1286,12 +1281,10 @@
retValue = INT_UNBOUNDED;
} else {
try {
- retValue = fXIntPool.getXInt(Integer.parseInt(value.trim()));
+ retValue = validate(attr, value, DT_NONNEGINT, schemaDoc);
} catch (NumberFormatException e) {
throw new InvalidDatatypeValueException("the value '"+value+"' must match (nonNegativeInteger | unbounded)");
}
- if (((XInt)retValue).intValue() < 0)
- throw new InvalidDatatypeValueException("the value '"+value+"' must match (nonNegativeInteger | unbounded)");
}
break;
case DT_MAXOCCURS1:
@@ -1437,24 +1430,15 @@
return retValue;
}
- // report an error. copied from TraverseSchema
private void reportSchemaError(String key, Object args[]) {
- if (fErrorReporter == null) {
- System.out.println("__TraverseSchemaError__ : " + key);
- for (int i=0; i< args.length ; i++) {
- System.out.println((String)args[i]);
- }
- }
- else {
- fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
- key,
- args,
- XMLErrorReporter.SEVERITY_ERROR);
- }
+ fErrorReporter.reportError(XSMessageFormatter.SCHEMA_DOMAIN,
+ key,
+ args,
+ XMLErrorReporter.SEVERITY_ERROR);
}
// validate attriubtes from non-schema namespaces
- public void checkNonSchemaAttributes(XSGrammarResolver grammarResolver) throws Exception {
+ public void checkNonSchemaAttributes(XSGrammarResolver grammarResolver) {
// for all attributes
Enumeration enum = fNonSchemaAttrs.keys();
XSAttributeDecl attrDecl;
@@ -1489,7 +1473,7 @@
// and validate it using the DatatypeValidator
dv.validate(attrVal,null);
} catch(InvalidDatatypeValueException ide) {
- reportSchemaError ("Con3X3AttributeInvalidValue",
+ reportSchemaError ("s4s-att-invalid-value",
new Object[] {elName, attrName, ide.getLocalizedMessage()});
}
}
1.29 +3 -2 xml-xerces/java/src/org/apache/xerces/impl/v2/XSDHandler.java
Index: XSDHandler.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSDHandler.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- XSDHandler.java 2001/09/24 15:24:54 1.28
+++ XSDHandler.java 2001/09/24 17:06:44 1.29
@@ -95,7 +95,7 @@
* schema, other grammars may be constructed as a side-effect.
*
* @author Neil Graham, IBM
- * @version $Id: XSDHandler.java,v 1.28 2001/09/24 15:24:54 sandygao Exp $
+ * @version $Id: XSDHandler.java,v 1.29 2001/09/24 17:06:44 sandygao Exp $
*/
class XSDHandler {
@@ -275,7 +275,8 @@
// resolveKeyRefs();
// sixth phase: handle derivation constraint checking
- // and UPA
+ // and UPA, and validate attribute of non-schema namespaces
+ fAttributeChecker.checkNonSchemaAttributes(fGrammarResolver);
// and return.
return fGrammarResolver.getGrammar(fRoot.fTargetNamespace);
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org