You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2001/05/30 00:19:21 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/validators/schema GeneralAttrCheck.java SchemaGrammar.java TraverseSchema.java
neilg 01/05/29 15:19:20
Modified: java/src/org/apache/xerces/utils Base64.java HexBin.java
java/src/org/apache/xerces/validators/datatype
Base64BinaryDatatypeValidator.java
HexBinaryDatatypeValidator.java
java/src/org/apache/xerces/validators/common
ElementWildcard.java XMLValidator.java
java/src/org/apache/xerces/validators/schema
GeneralAttrCheck.java SchemaGrammar.java
TraverseSchema.java
Log:
various bugfixes from Sandy Gao.
Revision Changes Path
1.8 +20 -9 xml-xerces/java/src/org/apache/xerces/utils/Base64.java
Index: Base64.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/utils/Base64.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Base64.java 2001/05/17 16:29:43 1.7
+++ Base64.java 2001/05/29 22:19:01 1.8
@@ -74,7 +74,7 @@
*
* @author Jeffrey Rodriguez
* @author Sandy Gao
- * @version $Id: Base64.java,v 1.7 2001/05/17 16:29:43 neilg Exp $
+ * @version $Id: Base64.java,v 1.8 2001/05/29 22:19:01 neilg Exp $
*/
public final class Base64 {
static private final int BASELENGTH = 255;
@@ -136,6 +136,8 @@
}
public static boolean isBase64( String isValidString ) {
+ if (isValidString == null)
+ return false;
return( isArrayByteBase64( isValidString.getBytes()));
}
@@ -156,22 +158,25 @@
* @return
*/
public static synchronized byte[] removeWhiteSpace( byte[] data ) {
+ if (data == null)
+ return null;
+
int newSize = 0;
int len = data.length;
int i =0;
- for (; i<data.length; i++) {
+ for (; i<len; i++) {
if (!isWhiteSpace( data[i] ))
newSize++;
}
- if (newSize == 0)
+ if (newSize == len)
return data;//return input array since no whiteSpace
byte[] arrayWithoutSpaces = new byte[newSize];//Allocate new array without whiteSpace
- i=0;
- for (int j =0;i<data.length;i++) {
+ int j = 0;
+ for (i=0;i<len;i++) {
if (isWhiteSpace( data[i] ))
continue;
else
@@ -182,7 +187,7 @@
}
public static synchronized boolean isArrayByteBase64( byte[] arrayOctect ) {
- return(getDecodedDataLength(arrayOctect) > 0);
+ return(getDecodedDataLength(arrayOctect) >= 0);
}
/**
@@ -192,6 +197,9 @@
* @return Encoded Base64 array
*/
public static synchronized byte[] encode( byte[] binaryData ) {
+ if (binaryData == null)
+ return null;
+
int lengthDataBits = binaryData.length*EIGHTBIT;
int fewerThan24bits = lengthDataBits%TWENTYFOURBITGROUP;
int numberTriplets = lengthDataBits/TWENTYFOURBITGROUP;
@@ -296,7 +304,7 @@
int numberQuadruple = (normalizedBase64Data.length/FOURBYTE );
if (numberQuadruple == 0)
- return null;
+ return new byte[0];
byte decodedData[] = null;
byte b1=0,b2=0,b3=0, b4=0, marker0=0, marker1=0;
@@ -382,18 +390,21 @@
* valid.
*
* @param base64Data
- * @return a 0 would be return if not
+ * @return a -1 would be return if not
*/
static public synchronized int getDecodedDataLength( byte[] base64Data ) {
if (base64Data == null)
+ return -1;
+
+ if (base64Data.length == 0)
return 0;
//byte[] normalizedBase64Data = removeWhiteSpace( base64Data );//Remove any whiteSpace
byte[] decodedData = null;
if ((decodedData = decode( base64Data ) ) == null)//decode could return a null byte array
- return 0;
+ return -1;
return decodedData.length;
}
1.7 +9 -3 xml-xerces/java/src/org/apache/xerces/utils/HexBin.java
Index: HexBin.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/utils/HexBin.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HexBin.java 2001/05/17 16:29:47 1.6
+++ HexBin.java 2001/05/29 22:19:02 1.7
@@ -65,7 +65,7 @@
*
* This class encodes/decodes hexadecimal data
* @author Jeffrey Rodriguez
- * @version $Id: HexBin.java,v 1.6 2001/05/17 16:29:47 neilg Exp $
+ * @version $Id: HexBin.java,v 1.7 2001/05/29 22:19:02 neilg Exp $
*/
public final class HexBin {
@@ -117,7 +117,7 @@
if (arrayOctect == null)
return false;
int length = arrayOctect.length;
- if( length == 0 || length % 2 != 0)
+ if (length % 2 != 0)
return false;
for( int i=0; i < length; i++ ){
if( HexBin.isHex( arrayOctect[i] ) == false)
@@ -127,6 +127,8 @@
}
public static boolean isHex( String isValidString ){
+ if (isValidString == null)
+ return false;
return( isArrayByteHex( isValidString.getBytes()));
}
@@ -137,6 +139,8 @@
* @return return encode binary array
*/
static public byte[] encode( byte[] binaryData ) {
+ if (binaryData == null)
+ return null;
int lengthData = binaryData.length;
int lengthEncode = lengthData * 2;
byte[] encodedData = new byte[lengthEncode];
@@ -148,8 +152,10 @@
}
static public byte[] decode ( byte[] binaryData ) {
+ if (binaryData == null)
+ return null;
int lengthData = binaryData.length;
- if( lengthData == 0 || lengthData % 2 != 0)
+ if (lengthData % 2 != 0)
return null;
int lengthDecode = lengthData / 2;
1.6 +2 -2 xml-xerces/java/src/org/apache/xerces/validators/datatype/Base64BinaryDatatypeValidator.java
Index: Base64BinaryDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/Base64BinaryDatatypeValidator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Base64BinaryDatatypeValidator.java 2001/05/17 16:30:11 1.5
+++ Base64BinaryDatatypeValidator.java 2001/05/29 22:19:05 1.6
@@ -70,7 +70,7 @@
* @author Kito D. Mann, Virtua Communications Corp.
* @author Jeffrey Rodriguez
* @author Mark Swinkles - List Validation refactoring
- * @version $Id: Base64BinaryDatatypeValidator.java,v 1.5 2001/05/17 16:30:11 neilg Exp $
+ * @version $Id: Base64BinaryDatatypeValidator.java,v 1.6 2001/05/29 22:19:05 neilg Exp $
*/
public class Base64BinaryDatatypeValidator extends AbstractStringValidator{
@@ -94,7 +94,7 @@
protected void checkValueSpace (String content) throws InvalidDatatypeValueException {
- if (getLength( content) <= 0) {
+ if (getLength( content) < 0) {
throw new InvalidDatatypeValueException( "Value '"+content+"' is not encoded in Base64" );
}
}
1.6 +2 -2 xml-xerces/java/src/org/apache/xerces/validators/datatype/HexBinaryDatatypeValidator.java
Index: HexBinaryDatatypeValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/datatype/HexBinaryDatatypeValidator.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HexBinaryDatatypeValidator.java 2001/05/17 16:30:09 1.5
+++ HexBinaryDatatypeValidator.java 2001/05/29 22:19:06 1.6
@@ -70,7 +70,7 @@
* @author Kito D. Mann, Virtua Communications Corp.
* @author Jeffrey Rodriguez
* @author Mark Swinkles - List Validation refactoring
- * @version $Id: HexBinaryDatatypeValidator.java,v 1.5 2001/05/17 16:30:09 neilg Exp $
+ * @version $Id: HexBinaryDatatypeValidator.java,v 1.6 2001/05/29 22:19:06 neilg Exp $
*/
public class HexBinaryDatatypeValidator extends AbstractStringValidator{
@@ -93,7 +93,7 @@
protected void checkValueSpace (String content) throws InvalidDatatypeValueException {
- if (getLength(content) <= 0) {
+ if (getLength(content) < 0) {
throw new InvalidDatatypeValueException( "Value '"+content+"' is not encoded in Hex" );
}
}
1.2 +2 -0 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ElementWildcard.java 2001/05/18 20:56:31 1.1
+++ ElementWildcard.java 2001/05/29 22:19:09 1.2
@@ -73,7 +73,9 @@
private static StringPool fStringPool;
private static XMLErrorReporter fErrorReporter;
public static void setErrReporter (StringPool stringPool, XMLErrorReporter errorReporter) {
+ if (fStringPool == null)
fStringPool = stringPool;
+ if (fErrorReporter == null)
fErrorReporter = errorReporter;
}
1.153 +8 -3 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.152
retrieving revision 1.153
diff -u -r1.152 -r1.153
--- XMLValidator.java 2001/05/18 20:31:14 1.152
+++ XMLValidator.java 2001/05/29 22:19:10 1.153
@@ -124,7 +124,7 @@
/**
* This class is the super all-in-one validator used by the parser.
*
- * @version $Id: XMLValidator.java,v 1.152 2001/05/18 20:31:14 neilg Exp $
+ * @version $Id: XMLValidator.java,v 1.153 2001/05/29 22:19:10 neilg Exp $
*/
public final class XMLValidator
implements DefaultEntityHandler.EventHandler,
@@ -2764,6 +2764,8 @@
// 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()
tst = new TraverseSchema( root, fStringPool, (SchemaGrammar)grammar, fGrammarResolver, fErrorReporter, source.getSystemId(), currentER, getSchemaFullCheckingEnabled());
+ fValID.validate( null, fResetID );//Reset ID for values appeared in the schema
+
//allowing xsi:schemaLocation to appear on any element
String targetNS = root.getAttribute("targetNamespace");
fGrammarNameSpaceIndex = fStringPool.addSymbol(targetNS);
@@ -3279,7 +3281,7 @@
TraverseSchema.ComplexTypeInfo tempType = typeInfo;
TraverseSchema.ComplexTypeInfo destType = ((SchemaGrammar)fGrammar).getElementComplexTypeInfo(elementIndex);
- for(; tempType != null; tempType = tempType.baseComplexTypeInfo) {
+ for(; tempType != null && destType != null; tempType = tempType.baseComplexTypeInfo) {
if(tempType.typeName.equals(destType.typeName))
break;
}
@@ -3288,7 +3290,10 @@
XMLMessages.SCHEMA_GENERIC_ERROR,
"Type : "+uri+","+localpart
+" does not derive from the type " + destType.typeName);
- } else { // now check whether the element or typeInfo's baseType blocks us.
+ } else if (destType == null) {
+ // TO BE DONE:
+ // if the original type is a simple type, check derivation ok.
+ } else if (typeInfo != destType) { // now check whether the element or typeInfo's baseType blocks us.
int derivationMethod = typeInfo.derivedBy;
if((((SchemaGrammar)fGrammar).getElementDeclBlockSet(elementIndex) & derivationMethod) != 0) {
XMLElementDecl tempElementDecl = new XMLElementDecl();
1.5 +21 -12 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- GeneralAttrCheck.java 2001/05/09 17:38:32 1.4
+++ GeneralAttrCheck.java 2001/05/29 22:19:15 1.5
@@ -920,9 +920,13 @@
// used to store utility reference: error reproter. set via constructor.
protected XMLErrorReporter fErrorReporter = null;
+ // used to store the mapping from processed element to attributes
+ protected Hashtable fProcessedElements = null;
+
// constructor. Sets fDVRegistry and fErrorReproter
public GeneralAttrCheck(XMLErrorReporter er) {
fErrorReporter = er;
+ fProcessedElements = new Hashtable();
}
// check whether the specified element conforms to the attributes restriction
@@ -933,6 +937,10 @@
if (element == null)
return null;
+ Hashtable attrValues = (Hashtable)fProcessedElements.get(element);
+ if (attrValues != null)
+ return attrValues;
+
// Get the proper name:
// G_ for global;
// LN_ for local + name;
@@ -955,7 +963,7 @@
return null;
}
- Hashtable attrValues = new Hashtable();
+ attrValues = new Hashtable();
Hashtable attrList = oneEle.attrList;
// traverse all attributes
@@ -966,7 +974,7 @@
// 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(), sattr.getValue());
+ attrValues.put(sattr.getName(), new Object[] {sattr.getValue(), Boolean.FALSE});
continue;
}
@@ -983,26 +991,25 @@
String attrVal = sattr.getValue();
try {
- // values of ID type might be validated more than once,
- // which would fail the validation.
- // disable this temprorily. Enable it after modify TraverseSchema. //???
- // and URI doesn't validate relative URIs, so disable it too. //???
+ // URI doesn't validate relative URIs, so disable it too. //???
// no checking on string needs to be done here.
// no checking on xpath needs to be done here.
// xpath values are validated in xpath parser
if (oneAttr.dvIndex >= 0) {
- if (oneAttr.dvIndex != DT_ID && oneAttr.dvIndex != DT_ANYURI &&
+ if (oneAttr.dvIndex != DT_ANYURI &&
oneAttr.dvIndex != DT_STRING &&
- oneAttr.dvIndex != DT_XPATH && oneAttr.dvIndex != DT_XPATH1)
+ oneAttr.dvIndex != DT_XPATH &&
+ oneAttr.dvIndex != DT_XPATH1)
fExtraDVs[oneAttr.dvIndex].validate(attrVal, null);
- attrValues.put(attrName, attrVal);
+ attrValues.put(attrName, new Object[] {attrVal, Boolean.FALSE});
} else {
attrVal = validate(attrName, attrVal, oneAttr.dvIndex);
- attrValues.put(attrName, attrVal);
+ attrValues.put(attrName, new Object[] {attrVal, Boolean.FALSE});
}
} catch(InvalidDatatypeValueException ide) {
reportSchemaError (SchemaMessageProvider.GenericError,
- new Object[] {"Invalid attribute value '"+attrVal+"' for '"+attrName+"' in '"+ elName +"'"});
+ new Object[] {"Invalid attribute value '"+attrVal+"' for '"+
+ attrName+"' in '"+ elName +"': " + ide.getLocalizedMessage()});
}
}
@@ -1022,9 +1029,11 @@
}
// if the attribute is optional with default value, apply it
else if (oneAttr.optdflt == ATT_OPT_DFLT) {
- attrValues.put(oneAttr.name, oneAttr.dfltValue);
+ attrValues.put(oneAttr.name, new Object[] {oneAttr.dfltValue, Boolean.TRUE});
}
}
+
+ fProcessedElements.put(element, attrValues);
return attrValues;
}
1.26 +1 -2 xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaGrammar.java
Index: SchemaGrammar.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaGrammar.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SchemaGrammar.java 2001/05/22 13:47:17 1.25
+++ SchemaGrammar.java 2001/05/29 22:19:16 1.26
@@ -60,7 +60,7 @@
* @author Eric Ye
*
* @see
- * @version $Id: SchemaGrammar.java,v 1.25 2001/05/22 13:47:17 lmartin Exp $
+ * @version $Id: SchemaGrammar.java,v 1.26 2001/05/29 22:19:16 neilg Exp $
*/
package org.apache.xerces.validators.schema;
@@ -75,7 +75,6 @@
import org.apache.xerces.validators.common.XMLContentModel;
import org.apache.xerces.validators.common.XMLElementDecl;
import org.apache.xerces.validators.common.Grammar;
-import org.apache.xerces.validators.common.DFAContentModel;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
1.179 +10 -3 xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java
Index: TraverseSchema.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/TraverseSchema.java,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -r1.178 -r1.179
--- TraverseSchema.java 2001/05/29 17:54:48 1.178
+++ TraverseSchema.java 2001/05/29 22:19:16 1.179
@@ -128,7 +128,7 @@
*
* @see org.apache.xerces.validators.common.Grammar
*
- * @version $Id: TraverseSchema.java,v 1.178 2001/05/29 17:54:48 lmartin Exp $
+ * @version $Id: TraverseSchema.java,v 1.179 2001/05/29 22:19:16 neilg Exp $
*/
public class TraverseSchema implements
NamespacesScope.NamespacesHandler{
@@ -2377,6 +2377,10 @@
// report error - must not have any children!
if (baseTypeQNameProperty.length() != 0) {
content = checkContent(simpleTypeDecl, content, true);
+ if (content!=null) {
+ reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
+ new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
+ }
}
else {
reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
@@ -2391,7 +2395,6 @@
if (content!=null) {
reportSchemaError(SchemaMessageProvider.ListUnionRestrictionError,
new Object [] { simpleTypeDecl.getAttribute( SchemaSymbols.ATT_NAME )});
-
}
}
else {
@@ -5814,6 +5817,10 @@
if(!attGrpNameStr.equals(""))
// REVISIT: localize
reportGenericSchemaError ( "attributeGroup " + attGrpNameStr + " cannot refer to another attributeGroup, but it refers to " + ref);
+ if (XUtil.getFirstChildElement(attrGrpDecl) != null ||
+ attrGrpDecl.getNodeValue() != null)
+ // REVISIT: localize
+ reportGenericSchemaError ( "An attributeGroup with \"ref\" present must be empty");
String prefix = "";
String localpart = ref;
@@ -5867,7 +5874,7 @@
traverseAttributeDecl(child, typeInfo, false);
}
else if ( child.getLocalName().equals(SchemaSymbols.ELT_ATTRIBUTEGROUP) ) {
- if(typeInfo != null)
+// if(typeInfo != null)
// only do this if we're traversing because we were ref'd here; when we come
// upon this decl by itself we're just validating.
traverseAttributeGroupDecl(child, typeInfo,anyAttDecls);
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org