You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by er...@locus.apache.org on 2000/12/14 18:51:32 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/msg SchemaMessages.java

ericye      00/12/14 09:51:29

  Modified:    java/src/org/apache/xerces/validators/schema
                        TraverseSchema.java SchemaMessageProvider.java
               java/src/org/apache/xerces/validators/common
                        XMLValidator.java XMLAttributeDecl.java
               java/src/org/apache/xerces/msg SchemaMessages.java
  Log:
  Schema attribute validation patch from Neil Graham, neilg@ca.ibm.com
  
  Revision  Changes    Path
  1.67      +50 -25    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.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- TraverseSchema.java	2000/12/08 18:20:28	1.66
  +++ TraverseSchema.java	2000/12/14 17:50:59	1.67
  @@ -375,7 +375,7 @@
    *  
    * @see                  org.apache.xerces.validators.common.Grammar
    *
  - * @version $Id: TraverseSchema.java,v 1.66 2000/12/08 18:20:28 ericye Exp $
  + * @version $Id: TraverseSchema.java,v 1.67 2000/12/14 17:50:59 ericye Exp $
    */
   
   public class TraverseSchema implements 
  @@ -2719,11 +2719,20 @@
   
           String ref       = attrDecl.getAttribute(SchemaSymbols.ATT_REF); 
           String datatype  = attrDecl.getAttribute(SchemaSymbols.ATT_TYPE);
  +		// various tests if 'ref' is present:
  +		if(!ref.equals("")) {
  +			if(!attNameStr.equals(""))
  +				// REVISIT:  localize 
  +   	    	    reportGenericSchemaError ( "Attribute " + attNameStr + " cannot refer to another attribute, but it refers to " + ref);
  +			if(!datatype.equals(""))
  +				// REVISIT:  localize 
  +       	        reportGenericSchemaError ( "Attribute with reference " + ref + " cannot also contain a type");
  +		}
  +		Element simpleTypeChild = findAttributeSimpleType(attrDecl);
  +
           String localpart = null;
   
  -        if (!ref.equals("")) {
  -            if (XUtil.getFirstChildElement(attrDecl) != null)
  -                reportSchemaError(SchemaMessageProvider.NoContentForRef, null);
  +		if (!ref.equals("")) {
               String prefix = "";
               localpart = ref;
               int colonptr = ref.indexOf(":");
  @@ -2757,16 +2766,9 @@
   
   
           if (datatype.equals("")) {
  -            Element child = XUtil.getFirstChildElement(attrDecl);
  -
  -            while (child != null && 
  -                             !child.getLocalName().equals(SchemaSymbols.ELT_SIMPLETYPE))
  -                child = XUtil.getNextSiblingElement(child);
  -
  -
  -            if (child != null && child.getLocalName().equals(SchemaSymbols.ELT_SIMPLETYPE)) {
  +            if (simpleTypeChild != null) { 
                   attType        = XMLAttributeDecl.TYPE_SIMPLE;
  -                dataTypeSymbol = traverseSimpleTypeDecl(child);
  +                dataTypeSymbol = traverseSimpleTypeDecl(simpleTypeChild);
                   localpart = fStringPool.toString(dataTypeSymbol);
               } 
               else {
  @@ -2779,6 +2781,8 @@
               dv = fDatatypeRegistry.getDatatypeValidator(localpart);
   
           } else {
  +			if(simpleTypeChild != null)
  +            	reportGenericSchemaError("Attribute declarations may not contain both a type and a simpleType declaration");
   
               String prefix = "";
               localpart = datatype;
  @@ -2829,7 +2833,7 @@
                           }
                       }
                   }
  -            } else {
  +            } else { //isn't of the schema for schemas namespace...
   
                   // check if the type is from the same Schema
   
  @@ -2856,19 +2860,22 @@
           int attDefaultValue = -1;
   
           String  use      = attrDecl.getAttribute(SchemaSymbols.ATT_USE);
  -        boolean required = use.equals(SchemaSymbols.ATTVAL_REQUIRED);
   
  -
  +        boolean prohibited = use.equals(SchemaSymbols.ATTVAL_PROHIBITED);
  +        boolean required = use.equals(SchemaSymbols.ATTVAL_REQUIRED);
           if (dv == null) {
               // REVISIT: Localize
               reportGenericSchemaError("could not resolve the type or get a null validator for datatype : " 
                                        + fStringPool.toString(dataTypeSymbol));
           }
   
  -        if (required) {
  +        if (prohibited) 
  +            attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_PROHIBITED; 
  +        else if (required) {
               attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_REQUIRED;
           } else {
  -            if (use.equals(SchemaSymbols.ATTVAL_FIXED)) {
  +			// perhaps a controversial change:  no "use" in lcoal scope means "fixed"!
  +            if (use.equals(SchemaSymbols.ATTVAL_FIXED) || (!isTopLevel(attrDecl) && !use.equals(SchemaSymbols.ATTVAL_DEFAULT))) {
                   String fixed = attrDecl.getAttribute(SchemaSymbols.ATT_VALUE);
                   if (!fixed.equals("")) {
                       attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_FIXED;
  @@ -2883,12 +2890,6 @@
                       attDefaultValue = fStringPool.addString(defaultValue);
                   } 
               }
  -            else if (use.equals(SchemaSymbols.ATTVAL_PROHIBITED)) {
  -                
  -                //REVISIT, TO DO. !!!
  -                attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_IMPLIED;
  -                //attDefaultValue = fStringPool.addString("");
  -            }
               else {
                   attDefaultType = XMLAttributeDecl.DEFAULT_TYPE_IMPLIED;
               }       // check default value is valid for the datatype.
  @@ -3120,6 +3121,27 @@
           return -1;
       } // end of method traverseAttributeGroupFromAnotherSchema
       
  +	// This simple method takes an attribute declaration as a parameter and
  +	// returns null if there is no simpleType defined or the simpleType
  +	// declaration if one exists.  It also throws an error if more than one
  +	// <annotation> or <simpleType> group is present.
  +	private Element findAttributeSimpleType(Element attrDecl) throws Exception {
  +		Element child = XUtil.getFirstChildElement(attrDecl);
  +	    	if (child == null)
  +	   		return null;
  +		if (child.getLocalName().equals(SchemaSymbols.ELT_SIMPLETYPE))
  +			return child;
  +		if (child.getLocalName().equals(SchemaSymbols.ELT_ANNOTATION))
  +			child = XUtil.getNextSiblingElement(child);
  +	    	if (child == null)
  +	   		return null;
  +		if (child.getLocalName().equals(SchemaSymbols.ELT_SIMPLETYPE) &&
  +				XUtil.getNextSiblingElement(child) == null) 
  +			return child;
  +		//REVISIT: localize
  +		reportGenericSchemaError ( "An attribute declaration must contain at most one annotation preceding at most one simpleType");
  +		return null;
  +	} // end findAttributeSimpleType
   
       /**
        * Traverse element declaration:
  @@ -3746,10 +3768,13 @@
               return true;
           }
           /****/
  +	/* why not make this more efficient by simply returning the conditional's value?  NG
           if (component.getParentNode().getLocalName().endsWith(SchemaSymbols.ELT_SCHEMA) ) {
               return true;
           }
  -        return false;
  +        return false; 
  +	*****/
  +        return (component.getParentNode().getLocalName().endsWith(SchemaSymbols.ELT_SCHEMA) ); 
       }
       
       DatatypeValidator getTypeValidatorFromNS(String newSchemaURI, String localpart) throws Exception {
  
  
  
  1.5       +3 -1      xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaMessageProvider.java
  
  Index: SchemaMessageProvider.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/schema/SchemaMessageProvider.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SchemaMessageProvider.java	2000/12/08 18:20:28	1.4
  +++ SchemaMessageProvider.java	2000/12/14 17:51:06	1.5
  @@ -161,6 +161,7 @@
           ContentError = 25,
           AnnotationError = 26,
           ListUnionRestrictionError = 27,
  +        ProhibitedAttributePresent = 28,
           // ...
           MSG_MAX_CODE = 31;
       //
  @@ -197,6 +198,7 @@
   		"UnclassifiedError",			//	24,	"Unclassified error."
           "ContentError",                 //  25, "Content (annotation?,..) is incorrect for type {0}"
           "AnnotationError",                //  26, "Annotation can only appear once: type {0}"
  -        "ListUnionRestrictionError"       //  27, "List | Union | Restriction content is invalid for type {0}"
  +        "ListUnionRestrictionError",       //  27, "List | Union | Restriction content is invalid for type {0}"
  +        "ProhibitedAttributePresent",	    		// 	28,	attribue dcld prohibited is present
       };
   }
  
  
  
  1.105     +18 -5     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.104
  retrieving revision 1.105
  diff -u -r1.104 -r1.105
  --- XMLValidator.java	2000/12/09 01:48:59	1.104
  +++ XMLValidator.java	2000/12/14 17:51:14	1.105
  @@ -111,7 +111,7 @@
   /**
    * This class is the super all-in-one validator used by the parser.
    *
  - * @version $Id: XMLValidator.java,v 1.104 2000/12/09 01:48:59 lehors Exp $
  + * @version $Id: XMLValidator.java,v 1.105 2000/12/14 17:51:14 ericye Exp $
    */
   public final class XMLValidator
   implements DefaultEntityHandler.EventHandler,
  @@ -814,7 +814,8 @@
         //
         // Check after all specified attrs are scanned
         // (1) report error for REQUIRED attrs that are missing (V_TAGc)
  -      // (2) add default attrs (FIXED and NOT_FIXED)
  +      // (2) report error for PROHIBITED attrs that are present (V_TAGc)
  +      // (3) add default attrs (FIXED and NOT_FIXED)
         //
   
         if (!fSeenRootElement) {
  @@ -1596,8 +1597,9 @@
         //
         // Check after all specified attrs are scanned
         // (1) report error for REQUIRED attrs that are missing (V_TAGc)
  -      // (2) check that FIXED attrs have matching value (V_TAGd)
  -      // (3) add default attrs (FIXED and NOT_FIXED)
  +      // (2) report error for PROHIBITED attrs that are present (V_TAGc)
  +      // (3) check that FIXED attrs have matching value (V_TAGd)
  +      // (4) add default attrs (FIXED and NOT_FIXED)
         //
         fGrammar.getElementDecl(elementIndex,fTempElementDecl);
   
  @@ -1620,10 +1622,11 @@
   
            boolean specified = false;
            boolean required = attDefType == XMLAttributeDecl.DEFAULT_TYPE_REQUIRED;
  +         boolean prohibited = attDefType == XMLAttributeDecl.DEFAULT_TYPE_PROHIBITED;
   
            if (firstCheck != -1) {
               boolean cdata = attType == fCDATASymbol;
  -            if (!cdata || required || attValue != -1) {
  +            if (!cdata || required || prohibited || attValue != -1) {
                  int i = attrList.getFirstAttr(firstCheck);
                  while (i != -1 && (lastCheck == -1 || i <= lastCheck)) {
   
  @@ -1631,6 +1634,16 @@
                          (  fStringPool.equalNames(attrList.getAttrLocalpart(i), attName)
                             && fStringPool.equalNames(attrList.getAttrURI(i), fTempAttDecl.name.uri) ) ) {
   
  +            		if (prohibited && validationEnabled) {
  +                  		Object[] args = { fStringPool.toString(elementNameIndex),
  +                     		fStringPool.toString(attName)};
  +						fErrorReporter.reportError(fErrorReporter.getLocator(),
  +								SchemaMessageProvider.SCHEMA_DOMAIN,
  +								SchemaMessageProvider.ProhibitedAttributePresent,
  +								SchemaMessageProvider.MSG_NONE,
  +								args,
  +								XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR);
  +               		}
                        if (validationEnabled && attDefType == XMLAttributeDecl.DEFAULT_TYPE_FIXED) {
                           int alistValue = attrList.getAttValue(i);
                           if (alistValue != attValue &&
  
  
  
  1.4       +2 -1      xml-xerces/java/src/org/apache/xerces/validators/common/XMLAttributeDecl.java
  
  Index: XMLAttributeDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/XMLAttributeDecl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLAttributeDecl.java	2000/07/21 03:42:44	1.3
  +++ XMLAttributeDecl.java	2000/12/14 17:51:17	1.4
  @@ -61,7 +61,7 @@
   import org.apache.xerces.validators.datatype.DatatypeValidator;
   
   /**
  - * @version $Id: XMLAttributeDecl.java,v 1.3 2000/07/21 03:42:44 ericye Exp $
  + * @version $Id: XMLAttributeDecl.java,v 1.4 2000/12/14 17:51:17 ericye Exp $
    */
   public class XMLAttributeDecl {
   
  @@ -94,6 +94,7 @@
       public static final int DEFAULT_TYPE_FIXED = 1;
       public static final int DEFAULT_TYPE_REQUIRED = 2;
       public static final int DEFAULT_TYPE_DEFAULT = 3;
  +    public static final int DEFAULT_TYPE_PROHIBITED = 7;
   
       // schema: attribte wildcard processContents property, share the defaultType field
       public static final int PROCESSCONTENTS_STRICT = 4;
  
  
  
  1.5       +3 -2      xml-xerces/java/src/org/apache/xerces/msg/SchemaMessages.java
  
  Index: SchemaMessages.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/msg/SchemaMessages.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SchemaMessages.java	2000/12/08 18:20:26	1.4
  +++ SchemaMessages.java	2000/12/14 17:51:25	1.5
  @@ -63,7 +63,7 @@
    * This file contains error and warning messages for the Schema validator
    * The messages are arranged in key and value tuples in a ListResourceBundle.
    *
  - * @version $Id: SchemaMessages.java,v 1.4 2000/12/08 18:20:26 ericye Exp $
  + * @version $Id: SchemaMessages.java,v 1.5 2000/12/14 17:51:25 ericye Exp $
    */
   public class SchemaMessages extends ListResourceBundle {
       /** The list resource bundle contents. */
  @@ -95,7 +95,8 @@
   		{ "UnexpectedError", "UnexpectedError" },
                   {"ContentError", "Content (annotation?,..) is incorrect for type {0}"},
                   {"AnnotationError", "Annotation can only appear once: type {0}"},
  -                {"ListUnionRestrictionError","List | Union | Restriction content is invalid for type {0}"}
  +                {"ListUnionRestrictionError","List | Union | Restriction content is invalid for type {0}"},
  +		{ "ProhibitedAttributePresent", "An attribute declared \"prohibited\" is present in this element definition." },
                   
      };