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 2002/01/29 14:52:16 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/msg XMLMessages.properties

neeraj      02/01/29 05:52:15

  Modified:    java/src/org/apache/xerces/impl/dtd DTDGrammar.java
                        XMLDTDValidator.java
               java/src/org/apache/xerces/impl/msg XMLMessages.properties
  Log:
  1.Added support for warn on duplicate attribute definition feature
  http://apache.org/xml/features/validation/warn-on-duplicate-attdef
  its default value is 'false' when set to 'true' warnings will be issued
  to the application through error handler.
  
  2.Fixed the bug in which duplicate attribute definitions were not ignored
  for ID datatype and Notation.As per XML 1.0 spec when more thean one
  definition is provided for the same attribute of a given element type,
  the first declaration is binding and later declarations are ignored.
  
  Revision  Changes    Path
  1.10      +4 -2      xml-xerces/java/src/org/apache/xerces/impl/dtd/DTDGrammar.java
  
  Index: DTDGrammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/DTDGrammar.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DTDGrammar.java	28 Jan 2002 19:33:35 -0000	1.9
  +++ DTDGrammar.java	29 Jan 2002 13:52:15 -0000	1.10
  @@ -95,7 +95,7 @@
    * @author Jeffrey Rodriguez, IBM
    * @author Andy Clark, IBM
    *
  - * @version $Id: DTDGrammar.java,v 1.9 2002/01/28 19:33:35 lehors Exp $
  + * @version $Id: DTDGrammar.java,v 1.10 2002/01/29 13:52:15 neeraj Exp $
    */
   public class DTDGrammar
       extends AbstractDTDGrammar
  @@ -523,8 +523,10 @@
   
           //Get Grammar index to grammar array
           int elementIndex       = getElementDeclIndex( elementName, -1 );
  +        
  +	//return, when more than one definition is provided for the same attribute of given element type
  +	//only the first declaration is binding and later declarations are ignored
           if (getAttributeDeclIndex(elementIndex, attributeName) != -1) {
  -            // REVISIT: BUG - need warn-on-duplicate-attdef feature support
               return;
           }
   
  
  
  
  1.16      +65 -5     xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java
  
  Index: XMLDTDValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- XMLDTDValidator.java	29 Jan 2002 01:15:10 -0000	1.15
  +++ XMLDTDValidator.java	29 Jan 2002 13:52:15 -0000	1.16
  @@ -123,7 +123,7 @@
    * @author Andy Clark, IBM
    * @author Jeffrey Rodriguez IBM
    *
  - * @version $Id: XMLDTDValidator.java,v 1.15 2002/01/29 01:15:10 lehors Exp $
  + * @version $Id: XMLDTDValidator.java,v 1.16 2002/01/29 13:52:15 neeraj Exp $
    */
   public class XMLDTDValidator
   implements XMLComponent, 
  @@ -154,6 +154,12 @@
       protected static final String SCHEMA_VALIDATION = 
       Constants.XERCES_FEATURE_PREFIX +Constants.SCHEMA_VALIDATION_FEATURE;
   
  +    /** Feature identifier: warn on duplicate attdef */
  +    protected static final String WARN_ON_DUPLICATE_ATTDEF = 
  +    Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 
  +
  +
  +
       // property identifiers
   
       /** Property identifier: symbol table. */
  @@ -226,6 +232,9 @@
        */
       protected boolean fDynamicValidation;
   
  +	/** warn on duplicate attribute definition, this feature works only when validation is true */
  +	protected boolean fWarnDuplicateAttdef;
  +	
       // properties
   
       /** Symbol table. */
  @@ -562,6 +571,14 @@
           catch (XMLConfigurationException e) {
               fDynamicValidation = false;
           }
  +        
  +        try {
  +            fWarnDuplicateAttdef = componentManager.getFeature(WARN_ON_DUPLICATE_ATTDEF);
  +        }
  +        catch (XMLConfigurationException e) {
  +            fWarnDuplicateAttdef = false;
  +        }
  +
   
           fValidationManager= (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER);
           fValidationManager.reset();
  @@ -1371,6 +1388,25 @@
           }
   
           if (fValidation) {
  +        
  +        	boolean	duplicateAttributeDef = false ;
  +                                        
  +        	//Get Grammar index to grammar array
  +        	int elementIndex       = fDTDGrammar.getElementDeclIndex( elementName, -1 );        	
  +        	if (fDTDGrammar.getAttributeDeclIndex(elementIndex, attributeName) != -1) {        
  +        		//more than one attribute definition is provided for the same attribute of a given element type.
  +        		duplicateAttributeDef = true ;
  +                		
  +        		//this feature works only when valiation is true.
  +        		if(fWarnDuplicateAttdef){
  +				fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
  +							 "MSG_DUPLICATE_ATTRIBUTE_DEFINITION", 
  +							 new Object[]{ elementName, attributeName },
  +							 XMLErrorReporter.SEVERITY_WARNING );
  +			}        		
  +        	}
  +                
  +        	
               //
               // a) VC: One ID per Element Type, If duplicate ID attribute
               // b) VC: ID attribute Default. if there is a declareared attribute
  @@ -1391,11 +1427,25 @@
                       fTableOfIDAttributeNames.put(elementName, attributeName);
                   }
                   else {
  -                    String previousIDAttributeName = (String)fTableOfIDAttributeNames.get( elementName );//rule a)
  -                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
  +                	//we should not report an error, when there is duplicate attribute definition for given element type
  +                	//according to XML 1.0 spec, When more than one definition is provided for the same attribute of a given
  +                	//element type, the first declaration is binding and later declaration are *ignored*. So processor should 
  +                	//ignore the second declarations, however an application would be warned of the duplicate attribute defintion 
  +                	// if http://apache.org/xml/features/validation/warn-on-duplicate-attdef feature is set to true,
  +                	// one typical case where this could be a  problem, when any XML file  
  +                	// provide the ID type information through internal subset so that it is available to the parser which read 
  +                	//only internal subset. Now that attribute declaration(ID Type) can again be part of external parsed entity 
  +                	//referenced. At that time if parser doesn't make this distinction it will throw an error for VC One ID per 
  +                	//Element Type, which (second defintion) actually should be ignored. Application behavior may differ on the
  +                	//basis of error or warning thrown. - nb.
  +
  +                	if(!duplicateAttributeDef){
  +                    		String previousIDAttributeName = (String)fTableOfIDAttributeNames.get( elementName );//rule a)
  +                    		fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                                  "MSG_MORE_THAN_ONE_ID_ATTRIBUTE",
                                                  new Object[]{ elementName, previousIDAttributeName, attributeName},
                                                  XMLErrorReporter.SEVERITY_ERROR);
  +                	}
                   }
               }
   
  @@ -1414,11 +1464,21 @@
                       fTableOfNOTATIONAttributeNames.put( elementName, attributeName);
                   }
                   else {
  -                    String previousNOTATIONAttributeName = (String) fTableOfNOTATIONAttributeNames.get( elementName );
  -                    fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
  +                	//we should not report an error, when there is duplicate attribute definition for given element type
  +                	//according to XML 1.0 spec, When more than one definition is provided for the same attribute of a given
  +                	//element type, the first declaration is binding and later declaration are *ignored*. So processor should 
  +                	//ignore the second declarations, however an application would be warned of the duplicate attribute defintion 
  +                	// if http://apache.org/xml/features/validation/warn-on-duplicate-attdef feature is set to true, Application behavior may differ on the basis of error or 
  +                	//warning thrown. - nb.
  +
  +                	if(!duplicateAttributeDef){
  +                
  +                    		String previousNOTATIONAttributeName = (String) fTableOfNOTATIONAttributeNames.get( elementName );
  +                    		fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                                                  "MSG_MORE_THAN_ONE_NOTATION_ATTRIBUTE",
                                                  new Object[]{ elementName, previousNOTATIONAttributeName, attributeName},
                                                  XMLErrorReporter.SEVERITY_ERROR);
  +                         }
                   }
               }
   
  
  
  
  1.6       +1 -0      xml-xerces/java/src/org/apache/xerces/impl/msg/XMLMessages.properties
  
  Index: XMLMessages.properties
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/msg/XMLMessages.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XMLMessages.properties	4 Jan 2002 23:27:49 -0000	1.5
  +++ XMLMessages.properties	29 Jan 2002 13:52:15 -0000	1.6
  @@ -158,6 +158,7 @@
           MSG_SPACE_REQUIRED_BEFORE_ATTTYPE_IN_ATTDEF = White space is required before the attribute type in the declaration of attribute \"{1}\" for element \"{0}\".
           AttTypeRequiredInAttDef = The attribute type is required in the declaration of attribute \"{1}\" for element \"{0}\".
           MSG_SPACE_REQUIRED_BEFORE_DEFAULTDECL_IN_ATTDEF = White space is required before the attribute default in the declaration of attribute \"{1}\" for element \"{0}\".
  +        MSG_DUPLICATE_ATTRIBUTE_DEFINITION = More than one attribute definition is provided for the same attribute \"{1}\" of a given element \"{0}\".
   # 3.3.1 Attribute Types
           MSG_SPACE_REQUIRED_AFTER_NOTATION_IN_NOTATIONTYPE = White space must appear after \"NOTATION\" in the \"{1}\" attribute declaration.
           MSG_OPEN_PAREN_REQUIRED_IN_NOTATIONTYPE = The ''('' character must follow \"NOTATION\" in the \"{1}\" attribute declaration.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org