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/06/20 17:09:32 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema GeneralAttrCheck.java SubstitutionGroupComparator.java
sandygao 01/06/20 08:09:31
Modified: java/src/org/apache/xerces/validators/common
ElementWildcard.java XMLValidator.java
java/src/org/apache/xerces/validators/datatype
AbstractStringValidator.java
DatatypeValidatorFactoryImpl.java
ENTITYDatatypeValidator.java
IDDatatypeValidator.java
IDREFDatatypeValidator.java
QNameDatatypeValidator.java
java/src/org/apache/xerces/validators/schema
GeneralAttrCheck.java
SubstitutionGroupComparator.java
Log:
1. new parser for name/ncname/nmtoken to improve performance (replacing the old regex)
2. remove static member from ElementWildcard;
3. add support for attributes from non-schema namespace.
Revision Changes Path
1.6 +20 -23 xml-xerces/java/src/org/apache/xerces/validators/common/ElementWildcard.java
Index: ElementWildcard.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/ElementWildcard.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ElementWildcard.java 2001/06/14 20:35:13 1.5
+++ ElementWildcard.java 2001/06/20 15:08:44 1.6
@@ -70,13 +70,6 @@
public class ElementWildcard {
private ElementWildcard(){}
- private static StringPool fStringPool;
- private static XMLErrorReporter fErrorReporter;
- public static void setErrReporter (StringPool stringPool, XMLErrorReporter errorReporter) {
- fStringPool = stringPool;
- fErrorReporter = errorReporter;
- }
-
private static boolean uriInWildcard(QName qname, int wildcard, int wtype,
SubstitutionGroupComparator comparator) {
int type = wtype & 0x0f;
@@ -108,7 +101,7 @@
// error occurs in comparator, do nothing here.
}
} else {
- //if (wildcard != uri && uri != fStringPool.EMPTY_STRING) // ???
+ //if (wildcard != uri && uri != StringPool.EMPTY_STRING) // ???
if (wildcard != qname.uri)
return true;
}
@@ -196,39 +189,43 @@
boolean ret = conflic(type1, local1, uri1, type2, local2, uri2, comparator);
try {
- if (ret && fStringPool != null && fErrorReporter != null) {
- String elements = getString (type1, local1, uri1, type2, local2, uri2);
- fErrorReporter.reportError(fErrorReporter.getLocator(),
- SchemaMessageProvider.SCHEMA_DOMAIN,
- SchemaMessageProvider.GenericError,
- SchemaMessageProvider.MSG_NONE,
- new Object[]{elements},
- XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
+ if (ret && comparator != null) {
+ String elements = getString (type1, local1, uri1,
+ type2, local2, uri2,
+ comparator.getStringPool());
+ XMLErrorReporter err = comparator.getErrorReporter();
+ err.reportError(err.getLocator(),
+ SchemaMessageProvider.SCHEMA_DOMAIN,
+ SchemaMessageProvider.GenericError,
+ SchemaMessageProvider.MSG_NONE,
+ new Object[]{elements},
+ XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
}
} catch (Exception e) {
}
return ret;
}
- private static String eleString(int type, int local, int uri) {
+ private static String eleString(int type, int local, int uri, StringPool stringPool) {
switch (type & 0x0f) {
case XMLContentSpec.CONTENTSPECNODE_LEAF:
- return fStringPool.toString(uri) + ":" + fStringPool.toString(local);
+ return stringPool.toString(uri) + ":" + stringPool.toString(local);
case XMLContentSpec.CONTENTSPECNODE_ANY:
return "##any:*";
case XMLContentSpec.CONTENTSPECNODE_ANY_NS:
- return fStringPool.toString(uri) + ":*";
+ return stringPool.toString(uri) + ":*";
case XMLContentSpec.CONTENTSPECNODE_ANY_OTHER:
- return "##other(" + fStringPool.toString(uri) + "):*";
+ return "##other(" + stringPool.toString(uri) + "):*";
}
return "";
}
private static String getString(int type1, int local1, int uri1,
- int type2, int local2, int uri2) {
- return "cos-nonambig: (" + eleString(type1, local1, uri1) +
- ") and (" + eleString(type2, local2, uri2) +
+ int type2, int local2, int uri2,
+ StringPool stringPool) {
+ return "cos-nonambig: (" + eleString(type1, local1, uri1, stringPool) +
+ ") and (" + eleString(type2, local2, uri2, stringPool) +
") violate the \"Unique Particle Attribution\" rule";
}
} // class ElementWildcard
1.166 +21 -10 xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java
Index: XMLValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java,v
retrieving revision 1.165
retrieving revision 1.166
diff -u -r1.165 -r1.166
--- XMLValidator.java 2001/06/18 19:25:44 1.165
+++ XMLValidator.java 2001/06/20 15:08:46 1.166
@@ -125,7 +125,7 @@
/**
* This class is the super all-in-one validator used by the parser.
*
- * @version $Id: XMLValidator.java,v 1.165 2001/06/18 19:25:44 sandygao Exp $
+ * @version $Id: XMLValidator.java,v 1.166 2001/06/20 15:08:46 sandygao Exp $
*/
public final class XMLValidator
implements DefaultEntityHandler.EventHandler,
@@ -189,7 +189,19 @@
}
};
- private Object[] fEntityValParam = null;
+ private StateMessageDatatype fValidateEntity = new StateMessageDatatype() {
+ private Object fData;
+ public Object getDatatypeObject(){
+ return fData;
+ }
+ public int getDatatypeState(){
+ return ENTITYDatatypeValidator.ENTITY_VALIDATE;
+ }
+ public void setDatatypeObject( Object data ){
+ fData = data;
+ }
+ };
+
//
// Data
//
@@ -398,7 +410,7 @@
fEntityHandler = entityHandler;
fDocumentScanner = documentScanner;
- fEntityValParam = new Object[]{entityHandler, stringPool};
+ fValidateEntity.setDatatypeObject(new Object[]{entityHandler, stringPool});
fValidateIDRef.setDatatypeObject(fIdREFDefs);
fCheckIDRef.setDatatypeObject(new Object[]{fIdDefs, fIdREFDefs});
@@ -1884,7 +1896,7 @@
private void resetCommon(StringPool stringPool) throws Exception {
fStringPool = stringPool;
- fEntityValParam[1] = stringPool;
+ fValidateEntity.setDatatypeObject(new Object[]{fEntityHandler, stringPool});
fValidating = fValidationEnabled;
fValidationEnabledByDynamic = false;
fDynamicDisabledByValidation = false;
@@ -2269,7 +2281,6 @@
/** Queries the content model for the specified element index. */
private XMLContentModel getElementContentModel(int elementIndex) throws CMException {
- ElementWildcard.setErrReporter(fStringPool, fErrorReporter);
XMLContentModel contentModel = null;
if ( elementIndex > -1) {
if ( fGrammar.getElementDecl(elementIndex,fTempElementDecl) ) {
@@ -2710,8 +2721,9 @@
//At this point we should expand the registry table.
// 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()
- GeneralAttrCheck generalAttrCheck = new GeneralAttrCheck(fErrorReporter);
+ GeneralAttrCheck generalAttrCheck = new GeneralAttrCheck(fErrorReporter, fDataTypeReg);
tst = new TraverseSchema( root, fStringPool, (SchemaGrammar)grammar, fGrammarResolver, fErrorReporter, source.getSystemId(), currentER, getSchemaFullCheckingEnabled(), generalAttrCheck);
+ generalAttrCheck.checkNonSchemaAttributes(fGrammarResolver);
//allowing xsi:schemaLocation to appear on any element
String targetNS = root.getAttribute("targetNamespace");
@@ -2724,7 +2736,6 @@
// by constructing all content models
if (fSchemaValidationFullChecking) {
try {
- ElementWildcard.setErrReporter(fStringPool, fErrorReporter);
// get all grammar URIs
Enumeration grammarURIs = fGrammarResolver.nameSpaceKeys();
String grammarURI;
@@ -3745,9 +3756,9 @@
try {
if ( isAlistAttribute ) {
- fValENTITIES.validate( value, fEntityValParam );
+ fValENTITIES.validate( value, fValidateEntity );
} else {
- fValENTITY.validate( value, fEntityValParam );
+ fValENTITY.validate( value, fValidateEntity );
}
} catch ( InvalidDatatypeValueException ex ) {
if ( ex.getMajorCode() != 1 && ex.getMinorCode() != -1 ) {
@@ -4329,7 +4340,7 @@
} else if (dv instanceof IDREFDatatypeValidator) {
dv.validate( content, fValidateIDRef );
} else if (dv instanceof ENTITYDatatypeValidator) {
- dv.validate( content, fEntityValParam);
+ dv.validate( content, fValidateEntity);
} else if (!onlyVal3Types) {
if (dv instanceof NOTATIONDatatypeValidator && content != null) {
content = bindNotationURI(content);
1.3 +193 -11 xml-xerces/java/src/org/apache/xerces/validators/datatype/AbstractStringValidator.java
Index: AbstractStringValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/AbstractStringValidator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractStringValidator.java 2001/05/31 21:13:06 1.2
+++ AbstractStringValidator.java 2001/06/20 15:08:57 1.3
@@ -68,9 +68,9 @@
/**
* AbstractStringValidator is a base class for anyURI, string,
* hexBinary, base64Binary, QName and Notation datatypes.
- *
+ *
* @author Elena Litani
- * @version $Id: AbstractStringValidator.java,v 1.2 2001/05/31 21:13:06 neilg Exp $
+ * @version $Id: AbstractStringValidator.java,v 1.3 2001/06/20 15:08:57 sandygao Exp $
*/
public abstract class AbstractStringValidator extends AbstractDatatypeValidator {
@@ -79,6 +79,20 @@
protected int fMinLength = 0;
protected Vector fEnumeration = null;
+ // _dummy_ facet for which special token parser to use
+ public static final String FACET_SPECIAL_TOKEN = "specialToken";
+ public static final String SPECIAL_TOKEN_NONE = "NONE";
+ public static final String SPECIAL_TOKEN_NMTOKEN = "NMTOKEN";
+ public static final String SPECIAL_TOKEN_NAME = "Name";
+ public static final String SPECIAL_TOKEN_IDNAME = "ID";
+ public static final String SPECIAL_TOKEN_IDREFNAME = "IDREF";
+ public static final String SPECIAL_TOKEN_NCNAME = "NCName";
+ public static final String SPECIAL_TOKEN_IDNCNAME = "ID";
+ public static final String SPECIAL_TOKEN_IDREFNCNAME = "IDREF";
+ public static final String SPECIAL_TOKEN_ENTITY = "ENTITY";
+
+ protected String fTokenType = SPECIAL_TOKEN_NONE; //flags special token parser
+
public AbstractStringValidator () throws InvalidDatatypeFacetException{
this( null, null, false ); // Native, No Facets defined, Restriction
@@ -151,6 +165,9 @@
else if ( key.equals(DatatypeValidator.FACET_FIXED) ) {// fixed flags
fFlags = ((Short)facets.get(key)).shortValue();
}
+ else if ( key == FACET_SPECIAL_TOKEN ) {// special token parser
+ setTokenType((String)facets.get(key));
+ }
else {
assignAdditionalFacets(key, facets);
}
@@ -159,7 +176,7 @@
if ( base != null ) {
// check 4.3.5.c0 must: enumeration values from the value space of base
//REVISIT: we should try either to delay it till validate() or
- // store enumeration values in _value_space
+ // store enumeration values in _value_space
// otherwise we end up creating and throwing objects
if ( (fFacetsDefined & DatatypeValidator.FACET_ENUMERATION) != 0 &&
(fEnumeration != null) ) {
@@ -236,7 +253,7 @@
else if ( (strBase.fFacetsDefined & DatatypeValidator.FACET_MINLENGTH) != 0 ) {
if ( (strBase.fFlags & DatatypeValidator.FACET_MINLENGTH) != 0 &&
fMinLength != strBase.fMinLength ) {
- throw new InvalidDatatypeFacetException( "minLength value = '" + fMinLength +
+ throw new InvalidDatatypeFacetException( "minLength value = '" + fMinLength +
"' must be equal to base.minLength value = '" +
strBase.fMinLength + "' with attribute {fixed} = true" );
}
@@ -262,7 +279,7 @@
if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
if ( (strBase.fFlags & DatatypeValidator.FACET_MAXLENGTH) != 0 &&
fMaxLength != strBase.fMaxLength ) {
- throw new InvalidDatatypeFacetException( "maxLength value = '" + fMaxLength +
+ throw new InvalidDatatypeFacetException( "maxLength value = '" + fMaxLength +
"' must be equal to base.maxLength value = '" +
strBase.fMaxLength + "' with attribute {fixed} = true" );
}
@@ -306,7 +323,7 @@
fEnumeration = strBase.fEnumeration;
}
inheritAdditionalFacets();
-
+
//inherit fixed values
fFlags |= strBase.fFlags;
}
@@ -317,7 +334,7 @@
// string has whiteSpace facet
// all other datatypes will throw InvalidDatatypeFacetException
//
- abstract protected void assignAdditionalFacets(String key, Hashtable facets)
+ abstract protected void assignAdditionalFacets(String key, Hashtable facets)
throws InvalidDatatypeFacetException;
//
@@ -367,6 +384,10 @@
"' does not match regular expression facet '" + fPattern + "'." );
}
+ // validate special kinds of token, in place of old pattern matching
+ if (fTokenType != SPECIAL_TOKEN_NONE)
+ validateToken (fTokenType, content);
+
// if this is a base validator, we only need to check pattern facet
// all other facet were inherited by the derived type
if ( asBase )
@@ -374,7 +395,7 @@
checkValueSpace (content);
int length = getLength(content);
-
+
if ( (fFacetsDefined & DatatypeValidator.FACET_MAXLENGTH) != 0 ) {
if ( length > fMaxLength ) {
throw new InvalidDatatypeValueException("Value '"+content+
@@ -412,13 +433,174 @@
/**
* Returns a copy of this object.
- *
- * @return
+ *
+ * @return
* @exception CloneNotSupportedException
*/
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("clone() is not supported in "+this.getClass().getName());
}
-}
+ public void setTokenType (String tokenType) {
+ fTokenType = tokenType;
+ }
+ protected static void validateToken(String tokenType, String content) throws InvalidDatatypeValueException {
+ int len;
+ if (content == null || (len = content.length()) == 0) {
+ throw new InvalidDatatypeValueException("The length of the content must be greater than 0");
+ }
+ boolean seenErr = false;
+ if (tokenType == SPECIAL_TOKEN_NMTOKEN) {
+ // PATTERN "\\c+"
+ for (int i = 0; i < len; i++) {
+ if (!isNameChar(content.charAt(i))) {
+ seenErr = true;
+ break;
+ }
+ }
+ } else if (tokenType == SPECIAL_TOKEN_NAME ||
+ tokenType == SPECIAL_TOKEN_IDNAME ||
+ tokenType == SPECIAL_TOKEN_IDREFNAME) {
+ // PATTERN "\\i\\c*"
+ if (isInitNameChar(content.charAt(0))) {
+ for (int i = 1; i < len; i++) {
+ if (!isNameChar(content.charAt(i))) {
+ seenErr = true;
+ break;
+ }
+ }
+ } else {
+ seenErr = true;
+ }
+ } else if (tokenType == SPECIAL_TOKEN_NCNAME ||
+ tokenType == SPECIAL_TOKEN_IDNCNAME ||
+ tokenType == SPECIAL_TOKEN_IDREFNCNAME ||
+ tokenType == SPECIAL_TOKEN_ENTITY) {
+ // PATTERN "[\\i-[:]][\\c-[:]]*"
+ if (isNCInitNameChar(content.charAt(0))) {
+ for (int i = 1; i < len; i++) {
+ if (!isNCNameChar(content.charAt(i))) {
+ seenErr = true;
+ break;
+ }
+ }
+ } else {
+ seenErr = true;
+ }
+ }
+ if (seenErr) {
+ throw new InvalidDatatypeValueException("Value '"+content+"' is not a valid " + tokenType);
+ }
+ }
+
+ private static boolean isNameChar(char ch) {
+ return inRange (ch, NAMECHARS);
+ }
+
+ private static boolean isInitNameChar(char ch) {
+ return ch == '_' || ch == ':' || inRange (ch, LETTERS);
+ }
+
+ private static boolean isNCNameChar(char ch) {
+ return ch != ':' && inRange (ch, NAMECHARS);
+ }
+
+ private static boolean isNCInitNameChar(char ch) {
+ return ch == '_' || inRange (ch, LETTERS);
+ }
+
+ private static boolean inRange (char ch, char[] range) {
+ int first = 0, last = range.length-1;
+ if (ch < range[0] || ch > range[last])
+ return false;
+
+ int middle;
+ while (last - first >= 2) {
+ middle = (first+last)/2;
+ if (ch == range[middle])
+ return true;
+ if (ch > range[middle])
+ first = middle;
+ else
+ last = middle;
+ }
+
+ return ((first/2)*2)==first;
+ }
+
+ private static final char[] NAMECHARS = {
+ '\u002d', '\u002e', '\u0030', '\u003a', '\u0041', '\u005a', '\u005f', '\u005f', '\u0061', '\u007a', '\u00b7', '\u00b7', '\u00c0', '\u00d6',
+ '\u00d8', '\u00f6', '\u00f8', '\u0131', '\u0134', '\u013e', '\u0141', '\u0148', '\u014a', '\u017e', '\u0180', '\u01c3', '\u01cd', '\u01f0',
+ '\u01f4', '\u01f5', '\u01fa', '\u0217', '\u0250', '\u02a8', '\u02bb', '\u02c1', '\u02d0', '\u02d1', '\u0300', '\u0345', '\u0360', '\u0361',
+ '\u0386', '\u038a', '\u038c', '\u038c', '\u038e', '\u03a1', '\u03a3', '\u03ce', '\u03d0', '\u03d6', '\u03da', '\u03da', '\u03dc', '\u03dc',
+ '\u03de', '\u03de', '\u03e0', '\u03e0', '\u03e2', '\u03f3', '\u0401', '\u040c', '\u040e', '\u044f', '\u0451', '\u045c', '\u045e', '\u0481',
+ '\u0483', '\u0486', '\u0490', '\u04c4', '\u04c7', '\u04c8', '\u04cb', '\u04cc', '\u04d0', '\u04eb', '\u04ee', '\u04f5', '\u04f8', '\u04f9',
+ '\u0531', '\u0556', '\u0559', '\u0559', '\u0561', '\u0586', '\u0591', '\u05a1', '\u05a3', '\u05b9', '\u05bb', '\u05bd', '\u05bf', '\u05bf',
+ '\u05c1', '\u05c2', '\u05c4', '\u05c4', '\u05d0', '\u05ea', '\u05f0', '\u05f2', '\u0621', '\u063a', '\u0640', '\u0652', '\u0660', '\u0669',
+ '\u0670', '\u06b7', '\u06ba', '\u06be', '\u06c0', '\u06ce', '\u06d0', '\u06d3', '\u06d5', '\u06e8', '\u06ea', '\u06ed', '\u06f0', '\u06f9',
+ '\u0901', '\u0903', '\u0905', '\u0939', '\u093c', '\u094d', '\u0951', '\u0954', '\u0958', '\u0963', '\u0966', '\u096f', '\u0981', '\u0983',
+ '\u0985', '\u098c', '\u098f', '\u0990', '\u0993', '\u09a8', '\u09aa', '\u09b0', '\u09b2', '\u09b2', '\u09b6', '\u09b9', '\u09bc', '\u09bc',
+ '\u09be', '\u09c4', '\u09c7', '\u09c8', '\u09cb', '\u09cd', '\u09d7', '\u09d7', '\u09dc', '\u09dd', '\u09df', '\u09e3', '\u09e6', '\u09f1',
+ '\u0a02', '\u0a02', '\u0a05', '\u0a0a', '\u0a0f', '\u0a10', '\u0a13', '\u0a28', '\u0a2a', '\u0a30', '\u0a32', '\u0a33', '\u0a35', '\u0a36',
+ '\u0a38', '\u0a39', '\u0a3c', '\u0a3c', '\u0a3e', '\u0a42', '\u0a47', '\u0a48', '\u0a4b', '\u0a4d', '\u0a59', '\u0a5c', '\u0a5e', '\u0a5e',
+ '\u0a66', '\u0a74', '\u0a81', '\u0a83', '\u0a85', '\u0a8b', '\u0a8d', '\u0a8d', '\u0a8f', '\u0a91', '\u0a93', '\u0aa8', '\u0aaa', '\u0ab0',
+ '\u0ab2', '\u0ab3', '\u0ab5', '\u0ab9', '\u0abc', '\u0ac5', '\u0ac7', '\u0ac9', '\u0acb', '\u0acd', '\u0ae0', '\u0ae0', '\u0ae6', '\u0aef',
+ '\u0b01', '\u0b03', '\u0b05', '\u0b0c', '\u0b0f', '\u0b10', '\u0b13', '\u0b28', '\u0b2a', '\u0b30', '\u0b32', '\u0b33', '\u0b36', '\u0b39',
+ '\u0b3c', '\u0b43', '\u0b47', '\u0b48', '\u0b4b', '\u0b4d', '\u0b56', '\u0b57', '\u0b5c', '\u0b5d', '\u0b5f', '\u0b61', '\u0b66', '\u0b6f',
+ '\u0b82', '\u0b83', '\u0b85', '\u0b8a', '\u0b8e', '\u0b90', '\u0b92', '\u0b95', '\u0b99', '\u0b9a', '\u0b9c', '\u0b9c', '\u0b9e', '\u0b9f',
+ '\u0ba3', '\u0ba4', '\u0ba8', '\u0baa', '\u0bae', '\u0bb5', '\u0bb7', '\u0bb9', '\u0bbe', '\u0bc2', '\u0bc6', '\u0bc8', '\u0bca', '\u0bcd',
+ '\u0bd7', '\u0bd7', '\u0be7', '\u0bef', '\u0c01', '\u0c03', '\u0c05', '\u0c0c', '\u0c0e', '\u0c10', '\u0c12', '\u0c28', '\u0c2a', '\u0c33',
+ '\u0c35', '\u0c39', '\u0c3e', '\u0c44', '\u0c46', '\u0c48', '\u0c4a', '\u0c4d', '\u0c55', '\u0c56', '\u0c60', '\u0c61', '\u0c66', '\u0c6f',
+ '\u0c82', '\u0c83', '\u0c85', '\u0c8c', '\u0c8e', '\u0c90', '\u0c92', '\u0ca8', '\u0caa', '\u0cb3', '\u0cb5', '\u0cb9', '\u0cbe', '\u0cc4',
+ '\u0cc6', '\u0cc8', '\u0cca', '\u0ccd', '\u0cd5', '\u0cd6', '\u0cde', '\u0cde', '\u0ce0', '\u0ce1', '\u0ce6', '\u0cef', '\u0d02', '\u0d03',
+ '\u0d05', '\u0d0c', '\u0d0e', '\u0d10', '\u0d12', '\u0d28', '\u0d2a', '\u0d39', '\u0d3e', '\u0d43', '\u0d46', '\u0d48', '\u0d4a', '\u0d4d',
+ '\u0d57', '\u0d57', '\u0d60', '\u0d61', '\u0d66', '\u0d6f', '\u0e01', '\u0e2e', '\u0e30', '\u0e3a', '\u0e40', '\u0e4e', '\u0e50', '\u0e59',
+ '\u0e81', '\u0e82', '\u0e84', '\u0e84', '\u0e87', '\u0e88', '\u0e8a', '\u0e8a', '\u0e8d', '\u0e8d', '\u0e94', '\u0e97', '\u0e99', '\u0e9f',
+ '\u0ea1', '\u0ea3', '\u0ea5', '\u0ea5', '\u0ea7', '\u0ea7', '\u0eaa', '\u0eab', '\u0ead', '\u0eae', '\u0eb0', '\u0eb9', '\u0ebb', '\u0ebd',
+ '\u0ec0', '\u0ec4', '\u0ec6', '\u0ec6', '\u0ec8', '\u0ecd', '\u0ed0', '\u0ed9', '\u0f18', '\u0f19', '\u0f20', '\u0f29', '\u0f35', '\u0f35',
+ '\u0f37', '\u0f37', '\u0f39', '\u0f39', '\u0f3e', '\u0f47', '\u0f49', '\u0f69', '\u0f71', '\u0f84', '\u0f86', '\u0f8b', '\u0f90', '\u0f95',
+ '\u0f97', '\u0f97', '\u0f99', '\u0fad', '\u0fb1', '\u0fb7', '\u0fb9', '\u0fb9', '\u10a0', '\u10c5', '\u10d0', '\u10f6', '\u1100', '\u1100',
+ '\u1102', '\u1103', '\u1105', '\u1107', '\u1109', '\u1109', '\u110b', '\u110c', '\u110e', '\u1112', '\u113c', '\u113c', '\u113e', '\u113e',
+ '\u1140', '\u1140', '\u114c', '\u114c', '\u114e', '\u114e', '\u1150', '\u1150', '\u1154', '\u1155', '\u1159', '\u1159', '\u115f', '\u1161',
+ '\u1163', '\u1163', '\u1165', '\u1165', '\u1167', '\u1167', '\u1169', '\u1169', '\u116d', '\u116e', '\u1172', '\u1173', '\u1175', '\u1175',
+ '\u119e', '\u119e', '\u11a8', '\u11a8', '\u11ab', '\u11ab', '\u11ae', '\u11af', '\u11b7', '\u11b8', '\u11ba', '\u11ba', '\u11bc', '\u11c2',
+ '\u11eb', '\u11eb', '\u11f0', '\u11f0', '\u11f9', '\u11f9', '\u1e00', '\u1e9b', '\u1ea0', '\u1ef9', '\u1f00', '\u1f15', '\u1f18', '\u1f1d',
+ '\u1f20', '\u1f45', '\u1f48', '\u1f4d', '\u1f50', '\u1f57', '\u1f59', '\u1f59', '\u1f5b', '\u1f5b', '\u1f5d', '\u1f5d', '\u1f5f', '\u1f7d',
+ '\u1f80', '\u1fb4', '\u1fb6', '\u1fbc', '\u1fbe', '\u1fbe', '\u1fc2', '\u1fc4', '\u1fc6', '\u1fcc', '\u1fd0', '\u1fd3', '\u1fd6', '\u1fdb',
+ '\u1fe0', '\u1fec', '\u1ff2', '\u1ff4', '\u1ff6', '\u1ffc', '\u20d0', '\u20dc', '\u20e1', '\u20e1', '\u2126', '\u2126', '\u212a', '\u212b',
+ '\u212e', '\u212e', '\u2180', '\u2182', '\u3005', '\u3005', '\u3007', '\u3007', '\u3021', '\u302f', '\u3031', '\u3035', '\u3041', '\u3094',
+ '\u3099', '\u309a', '\u309d', '\u309e', '\u30a1', '\u30fa', '\u30fc', '\u30fe', '\u3105', '\u312c', '\u4e00', '\u9fa5', '\uac00', '\ud7a3'};
+
+ private static final char[] LETTERS = {
+ '\u0041', '\u005a', '\u0061', '\u007a', '\u00c0', '\u00d6', '\u00d8', '\u00f6', '\u00f8', '\u0131', '\u0134', '\u013e', '\u0141', '\u0148',
+ '\u014a', '\u017e', '\u0180', '\u01c3', '\u01cd', '\u01f0', '\u01f4', '\u01f5', '\u01fa', '\u0217', '\u0250', '\u02a8', '\u02bb', '\u02c1',
+ '\u0386', '\u0386', '\u0388', '\u038a', '\u038c', '\u038c', '\u038e', '\u03a1', '\u03a3', '\u03ce', '\u03d0', '\u03d6', '\u03da', '\u03da',
+ '\u03dc', '\u03dc', '\u03de', '\u03de', '\u03e0', '\u03e0', '\u03e2', '\u03f3', '\u0401', '\u040c', '\u040e', '\u044f', '\u0451', '\u045c',
+ '\u045e', '\u0481', '\u0490', '\u04c4', '\u04c7', '\u04c8', '\u04cb', '\u04cc', '\u04d0', '\u04eb', '\u04ee', '\u04f5', '\u04f8', '\u04f9',
+ '\u0531', '\u0556', '\u0559', '\u0559', '\u0561', '\u0586', '\u05d0', '\u05ea', '\u05f0', '\u05f2', '\u0621', '\u063a', '\u0641', '\u064a',
+ '\u0671', '\u06b7', '\u06ba', '\u06be', '\u06c0', '\u06ce', '\u06d0', '\u06d3', '\u06d5', '\u06d5', '\u06e5', '\u06e6', '\u0905', '\u0939',
+ '\u093d', '\u093d', '\u0958', '\u0961', '\u0985', '\u098c', '\u098f', '\u0990', '\u0993', '\u09a8', '\u09aa', '\u09b0', '\u09b2', '\u09b2',
+ '\u09b6', '\u09b9', '\u09dc', '\u09dd', '\u09df', '\u09e1', '\u09f0', '\u09f1', '\u0a05', '\u0a0a', '\u0a0f', '\u0a10', '\u0a13', '\u0a28',
+ '\u0a2a', '\u0a30', '\u0a32', '\u0a33', '\u0a35', '\u0a36', '\u0a38', '\u0a39', '\u0a59', '\u0a5c', '\u0a5e', '\u0a5e', '\u0a72', '\u0a74',
+ '\u0a85', '\u0a8b', '\u0a8d', '\u0a8d', '\u0a8f', '\u0a91', '\u0a93', '\u0aa8', '\u0aaa', '\u0ab0', '\u0ab2', '\u0ab3', '\u0ab5', '\u0ab9',
+ '\u0abd', '\u0abd', '\u0ae0', '\u0ae0', '\u0b05', '\u0b0c', '\u0b0f', '\u0b10', '\u0b13', '\u0b28', '\u0b2a', '\u0b30', '\u0b32', '\u0b33',
+ '\u0b36', '\u0b39', '\u0b3d', '\u0b3d', '\u0b5c', '\u0b5d', '\u0b5f', '\u0b61', '\u0b85', '\u0b8a', '\u0b8e', '\u0b90', '\u0b92', '\u0b95',
+ '\u0b99', '\u0b9a', '\u0b9c', '\u0b9c', '\u0b9e', '\u0b9f', '\u0ba3', '\u0ba4', '\u0ba8', '\u0baa', '\u0bae', '\u0bb5', '\u0bb7', '\u0bb9',
+ '\u0c05', '\u0c0c', '\u0c0e', '\u0c10', '\u0c12', '\u0c28', '\u0c2a', '\u0c33', '\u0c35', '\u0c39', '\u0c60', '\u0c61', '\u0c85', '\u0c8c',
+ '\u0c8e', '\u0c90', '\u0c92', '\u0ca8', '\u0caa', '\u0cb3', '\u0cb5', '\u0cb9', '\u0cde', '\u0cde', '\u0ce0', '\u0ce1', '\u0d05', '\u0d0c',
+ '\u0d0e', '\u0d10', '\u0d12', '\u0d28', '\u0d2a', '\u0d39', '\u0d60', '\u0d61', '\u0e01', '\u0e2e', '\u0e30', '\u0e30', '\u0e32', '\u0e33',
+ '\u0e40', '\u0e45', '\u0e81', '\u0e82', '\u0e84', '\u0e84', '\u0e87', '\u0e88', '\u0e8a', '\u0e8a', '\u0e8d', '\u0e8d', '\u0e94', '\u0e97',
+ '\u0e99', '\u0e9f', '\u0ea1', '\u0ea3', '\u0ea5', '\u0ea5', '\u0ea7', '\u0ea7', '\u0eaa', '\u0eab', '\u0ead', '\u0eae', '\u0eb0', '\u0eb0',
+ '\u0eb2', '\u0eb3', '\u0ebd', '\u0ebd', '\u0ec0', '\u0ec4', '\u0f40', '\u0f47', '\u0f49', '\u0f69', '\u10a0', '\u10c5', '\u10d0', '\u10f6',
+ '\u1100', '\u1100', '\u1102', '\u1103', '\u1105', '\u1107', '\u1109', '\u1109', '\u110b', '\u110c', '\u110e', '\u1112', '\u113c', '\u113c',
+ '\u113e', '\u113e', '\u1140', '\u1140', '\u114c', '\u114c', '\u114e', '\u114e', '\u1150', '\u1150', '\u1154', '\u1155', '\u1159', '\u1159',
+ '\u115f', '\u1161', '\u1163', '\u1163', '\u1165', '\u1165', '\u1167', '\u1167', '\u1169', '\u1169', '\u116d', '\u116e', '\u1172', '\u1173',
+ '\u1175', '\u1175', '\u119e', '\u119e', '\u11a8', '\u11a8', '\u11ab', '\u11ab', '\u11ae', '\u11af', '\u11b7', '\u11b8', '\u11ba', '\u11ba',
+ '\u11bc', '\u11c2', '\u11eb', '\u11eb', '\u11f0', '\u11f0', '\u11f9', '\u11f9', '\u1e00', '\u1e9b', '\u1ea0', '\u1ef9', '\u1f00', '\u1f15',
+ '\u1f18', '\u1f1d', '\u1f20', '\u1f45', '\u1f48', '\u1f4d', '\u1f50', '\u1f57', '\u1f59', '\u1f59', '\u1f5b', '\u1f5b', '\u1f5d', '\u1f5d',
+ '\u1f5f', '\u1f7d', '\u1f80', '\u1fb4', '\u1fb6', '\u1fbc', '\u1fbe', '\u1fbe', '\u1fc2', '\u1fc4', '\u1fc6', '\u1fcc', '\u1fd0', '\u1fd3',
+ '\u1fd6', '\u1fdb', '\u1fe0', '\u1fec', '\u1ff2', '\u1ff4', '\u1ff6', '\u1ffc', '\u2126', '\u2126', '\u212a', '\u212b', '\u212e', '\u212e',
+ '\u2180', '\u2182', '\u3007', '\u3007', '\u3021', '\u3029', '\u3041', '\u3094', '\u30a1', '\u30fa', '\u3105', '\u312c', '\u4e00', '\u9fa5',
+ '\uac00', '\ud7a3'};
+}
1.30 +20 -9 xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactoryImpl.java
Index: DatatypeValidatorFactoryImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/DatatypeValidatorFactoryImpl.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- DatatypeValidatorFactoryImpl.java 2001/06/06 22:42:16 1.29
+++ DatatypeValidatorFactoryImpl.java 2001/06/20 15:08:59 1.30
@@ -91,7 +91,7 @@
* @author Elena Litani
* @author Jeffrey Rodriguez
* @author Mark Swinkles - List Validation refactoring
- * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.29 2001/06/06 22:42:16 sandygao Exp $
+ * @version $Id: DatatypeValidatorFactoryImpl.java,v 1.30 2001/06/20 15:08:59 sandygao Exp $
*/
public class DatatypeValidatorFactoryImpl implements DatatypeValidatorFactory {
@@ -140,7 +140,8 @@
createDTDDatatypeValidator( "ENTITIES", new ENTITYDatatypeValidator(), null, true );
Hashtable facets = new Hashtable(2);
- facets.put(SchemaSymbols.ELT_PATTERN , "\\c+" );
+ facets.put(AbstractStringValidator.FACET_SPECIAL_TOKEN,
+ AbstractStringValidator.SPECIAL_TOKEN_NMTOKEN);
facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
createDTDDatatypeValidator("NMTOKEN", new StringDatatypeValidator(), facets, false );
@@ -191,24 +192,29 @@
}
Hashtable facets = new Hashtable (2);
facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_REPLACE);
- createSchemaDatatypeValidator("normalizedString", new StringDatatypeValidator(), facets, false);
+ createSchemaDatatypeValidator("normalizedString", getDatatypeValidator("string"), facets, false);
facets.clear();
facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
- createSchemaDatatypeValidator("token", getDatatypeValidator("normalizedString"), facets, false);
+ createSchemaDatatypeValidator("token", getDatatypeValidator("string"), facets, false);
facets.clear();
+ facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
facets.put(SchemaSymbols.ELT_PATTERN , "([a-zA-Z]{2}|[iI]-[a-zA-Z]+|[xX]-[a-zA-Z]+)(-[a-zA-Z]+)*" );
- createSchemaDatatypeValidator("language", getDatatypeValidator("token") , facets, false );
+ createSchemaDatatypeValidator("language", getDatatypeValidator("string") , facets, false );
facets.clear();
- facets.put(SchemaSymbols.ELT_PATTERN , "\\i\\c*" );
- createSchemaDatatypeValidator("Name", getDatatypeValidator("token"), facets, false );
+ facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
+ facets.put(AbstractStringValidator.FACET_SPECIAL_TOKEN,
+ AbstractStringValidator.SPECIAL_TOKEN_NAME);
+ createSchemaDatatypeValidator("Name", getDatatypeValidator("string"), facets, false );
facets.clear();
- facets.put(SchemaSymbols.ELT_PATTERN , "[\\i-[:]][\\c-[:]]*" );
- createSchemaDatatypeValidator("NCName", getDatatypeValidator("token"), facets, false );
+ facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
+ facets.put(AbstractStringValidator.FACET_SPECIAL_TOKEN,
+ AbstractStringValidator.SPECIAL_TOKEN_NCNAME);
+ createSchemaDatatypeValidator("NCName", getDatatypeValidator("string"), facets, false );
facets.clear();
facets.put(SchemaSymbols.ELT_FRACTIONDIGITS, "0");
@@ -280,6 +286,11 @@
createSchemaDatatypeValidator("positiveInteger",
getDatatypeValidator( "nonNegativeInteger"), facets, false );
+ // in the case of schema, ID/IDREF are of type NCNAME
+ ((IDDatatypeValidator)getDatatypeValidator("ID")).setTokenType(AbstractStringValidator.SPECIAL_TOKEN_IDNCNAME);
+ ((IDREFDatatypeValidator)getDatatypeValidator("IDREF")).setTokenType(AbstractStringValidator.SPECIAL_TOKEN_IDREFNCNAME);
+ // set the NCName validator into QName validator
+ QNameDatatypeValidator.setNCNameValidator(getDatatypeValidator("NCName"));
fRegistryExpanded = 2;
}
1.14 +7 -42 xml-xerces/java/src/org/apache/xerces/validators/datatype/ENTITYDatatypeValidator.java
Index: ENTITYDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/ENTITYDatatypeValidator.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ENTITYDatatypeValidator.java 2001/06/07 12:17:04 1.13
+++ ENTITYDatatypeValidator.java 2001/06/20 15:09:01 1.14
@@ -104,29 +104,15 @@
*
* @author Jeffrey Rodriguez-
* @author Mark Swinkles - List Validation refactoring
- * @version $Id: ENTITYDatatypeValidator.java,v 1.13 2001/06/07 12:17:04 elena Exp $
+ * @version $Id: ENTITYDatatypeValidator.java,v 1.14 2001/06/20 15:09:01 sandygao Exp $
* @see org.apache.xerces.validators.datatype.DatatypeValidator
* @see org.apache.xerces.validators.datatype.DatatypeValidatorFactoryImpl
* @see org.apache.xerces.validators.datatype.DatatypeValidatorFactory
* @see org.apache.xerces.validators.common.XMLValidator
*/
public class ENTITYDatatypeValidator extends StringDatatypeValidator {
- private static StringDatatypeValidator fgStrValidator = null;
- static {
- // make a string validator for NCName
- if ( fgStrValidator == null) {
- Hashtable strFacets = new Hashtable();
- strFacets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
- strFacets.put(SchemaSymbols.ELT_PATTERN , "[\\i-[:]][\\c-[:]]*" );
- try{
-
- fgStrValidator = new StringDatatypeValidator (null, strFacets, false);
- }
- catch (Exception e){
- }
- }
- }
+ public static final int ENTITY_VALIDATE = 0;
public ENTITYDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
@@ -142,26 +128,14 @@
if ( derivedByList )
return;
- Vector enum = null;
- if (facets != null)
- enum = (Vector)facets.get(SchemaSymbols.ELT_ENUMERATION);
- if (enum != null) {
- int i = 0;
- try {
- for ( ; i < enum.size(); i++)
- fgStrValidator.validate((String)enum.elementAt(i), null);
- } catch ( Exception idve ){
- throw new InvalidDatatypeFacetException( "Value of enumeration = '" + enum.elementAt(i) +
- "' must be from the value space of base.");
- }
- }
+ setTokenType(SPECIAL_TOKEN_ENTITY);
}
/**
* return value of whiteSpace facet
*/
public short getWSFacet(){
- return fgStrValidator.getWSFacet();
+ return COLLAPSE;
}
/**
@@ -183,19 +157,10 @@
public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
// use StringDatatypeValidator to validate content against facets
super.validate(content, state);
-
- // check if content is a valid NCName
- try {
- fgStrValidator.validate(content, null);
- } catch (InvalidDatatypeValueException idve) {
- InvalidDatatypeValueException error = new InvalidDatatypeValueException( "ID is not valid: " + content );
- error.setMinorCode(XMLMessages.MSG_ENTITY_INVALID);
- error.setMajorCode(XMLMessages.VC_ENTITY_NAME);
- throw error;
- }
- if (state != null) {
- Object[] params = (Object[]) state;
+ StateMessageDatatype message = (StateMessageDatatype) state;
+ if (message != null && message.getDatatypeState() == ENTITY_VALIDATE) {
+ Object[] params = (Object[])message.getDatatypeObject();
DefaultEntityHandler entityHandler = (DefaultEntityHandler)params[0];
StringPool stringPool = (StringPool)params[1];
1.23 +7 -42 xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java
Index: IDDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/IDDatatypeValidator.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- IDDatatypeValidator.java 2001/06/07 12:17:06 1.22
+++ IDDatatypeValidator.java 2001/06/20 15:09:03 1.23
@@ -70,26 +70,11 @@
* standalone code as well as plugins to the validator architecture.
* @author Jeffrey Rodriguez
* @author Mark Swinkles - List Validation refactoring
- * @version $Id: IDDatatypeValidator.java,v 1.22 2001/06/07 12:17:06 elena Exp $
+ * @version $Id: IDDatatypeValidator.java,v 1.23 2001/06/20 15:09:03 sandygao Exp $
*/
public class IDDatatypeValidator extends StringDatatypeValidator {
- private static StringDatatypeValidator fgStrValidator = null;
private static Object fNullValue = new Object();
- static {
- // make a string validator for NCName
- if ( fgStrValidator == null ) {
- Hashtable strFacets = new Hashtable();
- strFacets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
- strFacets.put(SchemaSymbols.ELT_PATTERN , "[\\i-[:]][\\c-[:]]*" );
- try{
- fgStrValidator = new StringDatatypeValidator (null, strFacets, false);
- }
- catch (Exception e){
- }
- }
- }
-
public IDDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
@@ -104,27 +89,18 @@
if ( derivedByList )
return;
- Vector enum = null;
- if ( facets != null )
- enum = (Vector)facets.get(SchemaSymbols.ELT_ENUMERATION);
- if ( enum != null ) {
- int i = 0;
- try {
- for ( ; i < enum.size(); i++ )
- fgStrValidator.validate((String)enum.elementAt(i), null);
- }
- catch ( Exception idve ) {
- throw new InvalidDatatypeFacetException( "Value of enumeration = '" + enum.elementAt(i) +
- "' must be from the value space of base.");
- }
- }
+ // the type is NAME by default
+ if (base != null)
+ setTokenType(((IDDatatypeValidator)base).fTokenType);
+ else
+ setTokenType(SPECIAL_TOKEN_IDNAME);
}
/**
* return value of whiteSpace facet
*/
public short getWSFacet() {
- return fgStrValidator.getWSFacet();
+ return COLLAPSE;
}
/**
@@ -144,17 +120,6 @@
public Object validate(String content, Object state ) throws InvalidDatatypeValueException{
// use StringDatatypeValidator to validate content against facets
super.validate(content, state);
-
- // check if content is a valid NCName
- try {
- fgStrValidator.validate(content, null);
- }
- catch ( InvalidDatatypeValueException idve ) {
- InvalidDatatypeValueException error = new InvalidDatatypeValueException( "ID is not valid: " + content );
- error.setMinorCode(XMLMessages.MSG_ID_INVALID);
- error.setMajorCode(XMLMessages.VC_ID);
- throw error;
- }
if (state != null) {
if ( !addId( content, (Hashtable)state) ) {
1.23 +7 -41 xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java
Index: IDREFDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/IDREFDatatypeValidator.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- IDREFDatatypeValidator.java 2001/06/07 12:17:07 1.22
+++ IDREFDatatypeValidator.java 2001/06/20 15:09:07 1.23
@@ -71,29 +71,14 @@
*
* @author Jeffrey Rodriguez-
* @author Mark Swinkles - List Validation refactoring
- * @version $Id: IDREFDatatypeValidator.java,v 1.22 2001/06/07 12:17:07 elena Exp $
+ * @version $Id: IDREFDatatypeValidator.java,v 1.23 2001/06/20 15:09:07 sandygao Exp $
*/
public class IDREFDatatypeValidator extends StringDatatypeValidator {
- private static StringDatatypeValidator fgStrValidator = null;
private static Object fNullValue = new Object();
public static final int IDREF_VALIDATE = 0;
public static final int IDREF_CHECKID = 1;
- static {
- // make a string validator for NCName
- if ( fgStrValidator == null ) {
- Hashtable strFacets = new Hashtable();
- strFacets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
- strFacets.put(SchemaSymbols.ELT_PATTERN , "[\\i-[:]][\\c-[:]]*" );
- try{
- fgStrValidator = new StringDatatypeValidator (null, strFacets, false);
- }
- catch (Exception e){
- }
- }
- }
-
public IDREFDatatypeValidator () throws InvalidDatatypeFacetException {
this( null, null, false ); // Native, No Facets defined, Restriction
}
@@ -108,27 +93,18 @@
if ( derivedByList )
return;
- Vector enum = null;
- if ( facets != null )
- enum = (Vector)facets.get(SchemaSymbols.ELT_ENUMERATION);
- if ( enum != null ) {
- int i = 0;
- try {
- for ( ; i < enum.size(); i++ )
- fgStrValidator.validate((String)enum.elementAt(i), null);
- }
- catch ( Exception idve ) {
- throw new InvalidDatatypeFacetException( "Value of enumeration = '" + enum.elementAt(i) +
- "' must be from the value space of base.");
- }
- }
+ // the type is NAME by default
+ if (base != null)
+ setTokenType(((IDREFDatatypeValidator)base).fTokenType);
+ else
+ setTokenType(SPECIAL_TOKEN_IDREFNAME);
}
/**
* return value of whiteSpace facet
*/
public short getWSFacet() {
- return fgStrValidator.getWSFacet();
+ return COLLAPSE;
}
/**
@@ -156,16 +132,6 @@
else {
// use StringDatatypeValidator to validate content against facets
super.validate(content, state);
- // check if content is a valid NCName
- try {
- fgStrValidator.validate(content, null);
- }
- catch ( InvalidDatatypeValueException idve ) {
- InvalidDatatypeValueException error = new InvalidDatatypeValueException( "IDREF is not valid: " + content );
- error.setMinorCode(XMLMessages.MSG_IDREF_INVALID);
- error.setMajorCode(XMLMessages.VC_IDREF);
- throw error;
- }
if ( message != null && message.getDatatypeState() == IDREF_VALIDATE )
addIdRef( content, (Hashtable)message.getDatatypeObject());
1.13 +11 -13 xml-xerces/java/src/org/apache/xerces/validators/datatype/QNameDatatypeValidator.java
Index: QNameDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/QNameDatatypeValidator.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- QNameDatatypeValidator.java 2001/05/09 18:29:17 1.12
+++ QNameDatatypeValidator.java 2001/06/20 15:09:08 1.13
@@ -74,14 +74,14 @@
*
* @author Jeffrey Rodriguez
* @author Mark Swinkles - List Validation refactoring
- * @version $Id: QNameDatatypeValidator.java,v 1.12 2001/05/09 18:29:17 elena Exp $
+ * @version $Id: QNameDatatypeValidator.java,v 1.13 2001/06/20 15:09:08 sandygao Exp $
*/
public class QNameDatatypeValidator extends AbstractStringValidator {
-
+
// for the NCName validator
// REVISIT: synch issues?
- private static StringDatatypeValidator fgStrValidator = null;
+ private static DatatypeValidator fgStrValidator = null;
public QNameDatatypeValidator () throws InvalidDatatypeFacetException {
this ( null, null, false ); // Native, No Facets defined, Restriction
@@ -90,15 +90,7 @@
public QNameDatatypeValidator ( DatatypeValidator base, Hashtable facets,
boolean derivedByList ) throws InvalidDatatypeFacetException {
-
super (base, facets, derivedByList);
- // make a string validator for NCName
- if ( fgStrValidator == null) {
- Hashtable strFacets = new Hashtable();
- strFacets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
- strFacets.put(SchemaSymbols.ELT_PATTERN , "[\\i-[:]][\\c-[:]]*" );
- fgStrValidator = new StringDatatypeValidator (null, strFacets, false);
- }
}
protected void assignAdditionalFacets(String key, Hashtable facets) throws InvalidDatatypeFacetException{
@@ -108,7 +100,7 @@
protected void checkValueSpace (String content) throws InvalidDatatypeValueException {
-
+
// check 3.2.18.c0 must: "NCName:NCName"
try {
int posColon = content.indexOf(':');
@@ -124,6 +116,12 @@
Locale loc = Locale.getDefault();
Collator collator = Collator.getInstance( loc );
return collator.compare( content, facetValue );
+ }
+
+ protected static void setNCNameValidator (DatatypeValidator dv) {
+ // make a string validator for NCName
+ if ( fgStrValidator == null) {
+ fgStrValidator = dv;
+ }
}
-
}
1.11 +178 -75 xml-xerces/java/src/org/apache/xerces/validators/schema/GeneralAttrCheck.java
Index: GeneralAttrCheck.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/GeneralAttrCheck.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- GeneralAttrCheck.java 2001/06/15 19:23:41 1.10
+++ GeneralAttrCheck.java 2001/06/20 15:09:22 1.11
@@ -63,6 +63,8 @@
import org.apache.xerces.validators.datatype.*;
import org.apache.xerces.framework.XMLErrorReporter;
import org.apache.xerces.validators.common.XMLAttributeDecl;
+import org.apache.xerces.validators.common.GrammarResolver;
+import org.apache.xerces.validators.common.Grammar;
/**
* Title:
@@ -699,7 +701,7 @@
attrList = new Hashtable();
// source = anyURI
attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]);
- oneEle = new OneElement (attrList);
+ oneEle = new OneElement (attrList, false);
fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_APPINFO, oneEle);
// for element "documentation" - local name
@@ -707,7 +709,7 @@
// source = anyURI
attrList.put(SchemaSymbols.ATT_SOURCE, allAttrs[ATT_SOURCE_N]);
// xml:lang = language ???
- oneEle = new OneElement (attrList);
+ oneEle = new OneElement (attrList, false);
fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_DOCUMENTATION, oneEle);
// for element "simpleType" - global
@@ -857,67 +859,6 @@
fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_MININCLUSIVE, oneEle);
// for element "minExclusive" - local name
fEleAttrsMap.put(PRE_LOC_NAME+SchemaSymbols.ELT_MINEXCLUSIVE, oneEle);
-
-
- // step 5: register all datatype validators for new types
- Hashtable facets;
- DatatypeValidator extraDV;
- try {
- // anyURI
- extraDV = new AnyURIDatatypeValidator();
- fExtraDVs[DT_ANYURI] = extraDV;
-
- // boolean
- extraDV = new BooleanDatatypeValidator();
- fExtraDVs[DT_BOOLEAN] = extraDV;
-
- // ID
- extraDV = new IDDatatypeValidator();
- fExtraDVs[DT_ID] = extraDV;
-
- // nonNegtiveInteger
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_FRACTIONDIGITS, "0");
- facets.put(SchemaSymbols.ELT_MININCLUSIVE, "0" );
- extraDV = new DecimalDatatypeValidator(null, facets, false);
- fExtraDVs[DT_NONNEGINT] = extraDV;
-
- // QName
- extraDV = new QNameDatatypeValidator();
- fExtraDVs[DT_QNAME] = extraDV;
-
- // string
- extraDV = new StringDatatypeValidator();
- fExtraDVs[DT_STRING] = extraDV;
-
- // token
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_WHITESPACE, SchemaSymbols.ATT_COLLAPSE);
- extraDV = new StringDatatypeValidator(null, facets, false);
- fExtraDVs[DT_TOKEN] = extraDV;
-
- // NCName
- facets = new Hashtable();
- facets.put(SchemaSymbols.ELT_PATTERN, "[\\i-[:]][\\c-[:]]*");
- extraDV = new StringDatatypeValidator(fExtraDVs[DT_TOKEN], facets, false);
- fExtraDVs[DT_NCNAME] = extraDV;
-
- // xpath = a subset of XPath expression
- // facets = new Hashtable();
- // facets.put(SchemaSymbols.ELT_PATTERN, "(\\.//)?(((child::)?((\\i\\c*:)?(\\i\\c*|\\*)))|\\.)(/(((child::)?((\\i\\c*:)?(\\i\\c*|\\*)))|\\.))*(\\|(\\.//)?(((child::)?((\\i\\c*:)?(\\i\\c*|\\*)))|\\.)(/(((child::)?((\\i\\c*:)?(\\i\\c*|\\*)))|\\.))*)*");
- // extraDV = new StringDatatypeValidator(fExtraDVs[DT_TOKEN], facets, false);
- // fExtraDVs[DT_XPATH] = extraDV;
- fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING];
-
- // xpath = a subset of XPath expression
- // facets = new Hashtable();
- // facets.put(SchemaSymbols.ELT_PATTERN, "(\\.//)?((((child::)?((\\i\\c*:)?(\\i\\c*|\\*)))|\\.)/)*((((child::)?((\\i\\c*:)?(\\i\\c*|\\*)))|\\.)|((attribute::|@)((\\i\\c*:)?(\\i\\c*|\\*))))(\\|(\\.//)?((((child::)?((\\i\\c*:)?(\\i\\c*|\\*)))|\\.)/)*((((child::)?((\\i\\c*:)?(\\i\\c*|\\*)))|\\.)|((attribute::|@)((\\i\\c*:)?(\\i\\c*|\\*)))))*");
- // extraDV = new StringDatatypeValidator(fExtraDVs[DT_TOKEN], facets, false);
- // fExtraDVs[DT_XPATH1] = extraDV;
- fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING];
- } catch (InvalidDatatypeFacetException ide) {
- // shouldn't be any problem
- }
}
private Hashtable fIdDefs = new Hashtable();
@@ -925,13 +866,46 @@
// used to store utility reference: error reproter. set via constructor.
protected XMLErrorReporter fErrorReporter = null;
+ // used to store the list of simple type validators
+ protected DatatypeValidatorFactoryImpl fDatatypeRegistry;
+
// used to store the mapping from processed element to attributes
- protected Hashtable fProcessedElements = null;
+ protected Hashtable fProcessedElements = new Hashtable();
+ // used to store the mapping from processed element to attributes
+ protected Hashtable fNonSchemaAttrs = new Hashtable();
+
// constructor. Sets fDVRegistry and fErrorReproter
- public GeneralAttrCheck(XMLErrorReporter er) {
+ private GeneralAttrCheck() {}
+ public GeneralAttrCheck (XMLErrorReporter er, DatatypeValidatorFactoryImpl datatypeRegistry) {
fErrorReporter = er;
- fProcessedElements = new Hashtable();
+ fDatatypeRegistry = fDatatypeRegistry;
+ synchronized (getClass()) {
+ if (fExtraDVs[DT_ANYURI] == null) {
+ // step 5: register all datatype validators for new types
+ datatypeRegistry.expandRegistryToFullSchemaSet();
+ // anyURI
+ fExtraDVs[DT_ANYURI] = datatypeRegistry.getDatatypeValidator("anyURI");
+ // boolean
+ fExtraDVs[DT_BOOLEAN] = datatypeRegistry.getDatatypeValidator("boolean");
+ // ID
+ fExtraDVs[DT_ID] = datatypeRegistry.getDatatypeValidator("ID");
+ // nonNegtiveInteger
+ fExtraDVs[DT_NONNEGINT] = datatypeRegistry.getDatatypeValidator("nonNegativeInteger");
+ // QName
+ fExtraDVs[DT_QNAME] = datatypeRegistry.getDatatypeValidator("QName");
+ // string
+ fExtraDVs[DT_STRING] = datatypeRegistry.getDatatypeValidator("string");
+ // token
+ fExtraDVs[DT_TOKEN] = datatypeRegistry.getDatatypeValidator("token");
+ // NCName
+ fExtraDVs[DT_NCNAME] = datatypeRegistry.getDatatypeValidator("NCName");
+ // xpath = a subset of XPath expression
+ fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING];
+ // xpath = a subset of XPath expression
+ fExtraDVs[DT_XPATH] = fExtraDVs[DT_STRING];
+ }
+ }
}
// check whether the specified element conforms to the attributes restriction
@@ -952,12 +926,12 @@
// LR_ for local + ref;
String elName = element.getLocalName(), name;
if (eleContext == ELE_CONTEXT_GLOBAL) {
- name = PRE_GLOBAL + element.getLocalName();
+ name = PRE_GLOBAL + elName;
} else {
if (element.getAttributeNode(SchemaSymbols.ATT_REF) == null)
- name = PRE_LOC_NAME + element.getLocalName();
+ name = PRE_LOC_NAME + elName;
else
- name = PRE_LOC_REF + element.getLocalName();
+ name = PRE_LOC_REF + elName;
}
// get desired attribute list of this element
@@ -976,15 +950,46 @@
Attr sattr = null;
int i = 0;
while ((sattr = (Attr)attrs.item(i++)) != null) {
+ // get the attribute name/value
+ String attrName = sattr.getName();
+ String attrVal = sattr.getValue();
+
// skip anything starts with x/X m/M l/L ???
// simply put their values in the return hashtable
- if (sattr.getName().toLowerCase().startsWith("xml")) {
- attrValues.put(sattr.getName(), new Object[] {sattr.getValue(), Boolean.FALSE});
+ if (attrName.toLowerCase().startsWith("xml")) {
+ attrValues.put(attrName, new Object[] {sattr.getValue(), Boolean.FALSE});
continue;
}
+ // for attributes with namespace prefix
+ String attrURI = sattr.getNamespaceURI();
+ if (attrURI != null && attrURI.length() != 0) {
+ // attributes with schema namespace are not allowed
+ // and not allowed on "document" and "appInfo"
+ if (attrURI.equals(SchemaSymbols.URI_SCHEMAFORSCHEMA) ||
+ !oneEle.allowNonSchemaAttr) {
+ reportSchemaError (SchemaMessageProvider.GenericError,
+ new Object[] {"Attribute '"+attrName+"' cannot appear in '"+elName+"'"});
+ } else {
+ // for attributes from other namespace
+ // store them in a list, and TRY to validate them after
+ // schema traversal (because it's "lax")
+ attrValues.put(attrName,
+ new Object[] {attrVal, Boolean.FALSE});
+ String attrRName = attrURI + "," + sattr.getLocalName();
+ Vector values = (Vector)fNonSchemaAttrs.get(attrRName);
+ if (values == null) {
+ values = new Vector();
+ values.addElement(attrVal);
+ fNonSchemaAttrs.put(attrRName, values);
+ } else {
+ values.addElement(attrVal);
+ }
+ }
+ continue;
+ }
+
// check whether this attribute is allowed
- String attrName = sattr.getLocalName();
OneAttr oneAttr = (OneAttr)attrList.get(attrName);
if (oneAttr == null) {
reportSchemaError (SchemaMessageProvider.GenericError,
@@ -992,9 +997,7 @@
continue;
}
- // get the attribute valud, and check it against the datatype
- String attrVal = sattr.getValue();
-
+ // check the value against the datatype
try {
// no checking on string needs to be done here.
// no checking on xpath needs to be done here.
@@ -1221,6 +1224,98 @@
XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
}
}
+
+ // validate attriubtes from non-schema namespaces
+ public void checkNonSchemaAttributes(GrammarResolver grammarResolver) throws Exception {
+ // for all attributes
+ Enumeration enum = fNonSchemaAttrs.keys();
+ while (enum.hasMoreElements()) {
+ // get name, uri, localpart
+ String attrRName = (String)enum.nextElement();
+ String attrURI = attrRName.substring(0,attrRName.indexOf(','));
+ String attrLocal = attrRName.substring(attrRName.indexOf(',')+1);
+ // find associated grammar
+ Grammar grammar = grammarResolver.getGrammar(attrURI);
+ if (grammar == null || !(grammar instanceof SchemaGrammar))
+ continue;
+ SchemaGrammar sGrammar = (SchemaGrammar)grammar;
+ // then get all top-level attributes from that grammar
+ Hashtable attrRegistry = sGrammar.getAttributeDeclRegistry();
+ if (attrRegistry == null)
+ continue;
+ // and get the datatype validator, if there is one
+ XMLAttributeDecl tempAttrDecl = (XMLAttributeDecl)attrRegistry.get(attrLocal);
+ if (tempAttrDecl == null)
+ continue;
+ DatatypeValidator dv = tempAttrDecl.datatypeValidator;
+ if (dv == null)
+ continue;
+
+ // get all values appeared with this attribute name
+ Vector values = (Vector)fNonSchemaAttrs.get(attrRName);
+ String attrVal;
+ String attrName = (String)values.get(0);
+ // for each of the values
+ int count = values.size();
+ for (int i = 1; i < count; i++) {
+ // normalize it according to the whiteSpace facet
+ attrVal = normalize((String)values.get(i), dv.getWSFacet());
+ try {
+ // and validate it using the DatatypeValidator
+ dv.validate(attrVal,null);
+ } catch(InvalidDatatypeValueException ide) {
+ reportSchemaError (SchemaMessageProvider.GenericError,
+ new Object[] {"Invalid attribute value '"+attrVal+"' for '"+
+ attrName + "': " + ide.getLocalizedMessage()});
+ }
+ }
+ }
+ }
+
+ // normalize the string according to the whiteSpace facet
+ private String normalize(String content, short ws) {
+ int len = content == null ? 0 : content.length();
+ if (len == 0 || ws == DatatypeValidator.PRESERVE)
+ return content;
+
+ StringBuffer sb = new StringBuffer();
+ if (ws == DatatypeValidator.REPLACE) {
+ char ch;
+ // when it's replace, just replace #x9, #xa, #xd by #x20
+ for (int i = 0; i < len; i++) {
+ ch = content.charAt(i);
+ if (ch != 0x9 && ch != 0xa && ch != 0xd)
+ sb.append(ch);
+ else
+ sb.append((char)0x20);
+ }
+ } else {
+ char ch;
+ int i;
+ boolean isLeading = true;
+ // when it's collapse
+ for (i = 0; i < len; i++) {
+ ch = content.charAt(i);
+ // append real characters, so we passed leading ws
+ if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20) {
+ sb.append(ch);
+ isLeading = false;
+ } else {
+ // for whitespaces, we skip all following ws
+ for (; i < len-1; i++) {
+ ch = content.charAt(i+1);
+ if (ch != 0x9 && ch != 0xa && ch != 0xd && ch != 0x20)
+ break;
+ }
+ // if it's not a leading or tailing ws, then append a space
+ if (i < len - 1 && !isLeading)
+ sb.append((char)0x20);
+ }
+ }
+ }
+
+ return sb.toString();
+ }
}
class OneAttr {
@@ -1246,8 +1341,14 @@
public Hashtable attrList;
// the array of attributes that can appear in one element
public Object[] attrArray;
+ // does this element allow attributes from non-schema namespace
+ public boolean allowNonSchemaAttr;
public OneElement (Hashtable attrList) {
+ this(attrList, true);
+ }
+
+ public OneElement (Hashtable attrList, boolean allowNonSchemaAttr) {
this.attrList = attrList;
int count = attrList.size();
@@ -1255,5 +1356,7 @@
Enumeration enum = attrList.elements();
for (int i = 0; i < count; i++)
this.attrArray[i] = enum.nextElement();
+
+ this.allowNonSchemaAttr = allowNonSchemaAttr;
}
}
1.5 +8 -0 xml-xerces/java/src/org/apache/xerces/validators/schema/SubstitutionGroupComparator.java
Index: SubstitutionGroupComparator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SubstitutionGroupComparator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SubstitutionGroupComparator.java 2001/06/14 20:46:15 1.4
+++ SubstitutionGroupComparator.java 2001/06/20 15:09:24 1.5
@@ -103,6 +103,14 @@
fErrorReporter = errorReporter;
}
+ public StringPool getStringPool() {
+ return fStringPool;
+ }
+
+ public XMLErrorReporter getErrorReporter () {
+ return fErrorReporter;
+ }
+
//public methods
public boolean isEquivalentTo(QName anElement, QName exemplar) throws Exception{
if (anElement.localpart==exemplar.localpart && anElement.uri==exemplar.uri ) {
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org