Author: mrglavas Date: Tue Sep 4 04:43:34 2012 New Revision: 1380445 URL: http://svn.apache.org/viewvc?rev=1380445&view=rev Log: JIRA Issue #1581: https://issues.apache.org/jira/browse/XERCESJ-1581. Report multiple IDREF errors during DTD and XML Schema validation.
Modified: xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java xerces/java/trunk/src/org/apache/xerces/impl/validation/ConfigurableValidationState.java xerces/java/trunk/src/org/apache/xerces/impl/validation/ValidationState.java xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Modified: xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java?rev=1380445&r1=1380444&r2=1380445&view=diff ============================================================================== --- xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java (original) +++ xerces/java/trunk/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java Tue Sep 4 04:43:34 2012 @@ -17,6 +17,8 @@ package org.apache.xerces.impl.dtd; +import java.util.Iterator; + import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.RevalidationHandler; import org.apache.xerces.impl.XMLEntityManager; @@ -2066,12 +2068,14 @@ public class XMLDTDValidator // IDREF and IDREFS attr (V_IDREF0) // if (fPerformValidation) { - String value = fValidationState.checkIDRefID(); - if (value != null) { - fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, - "MSG_ELEMENT_WITH_ID_REQUIRED", - new Object[]{value}, - XMLErrorReporter.SEVERITY_ERROR ); + Iterator invIdRefs = fValidationState.checkIDRefID(); + if (invIdRefs != null) { + while (invIdRefs.hasNext()) { + fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, + "MSG_ELEMENT_WITH_ID_REQUIRED", + new Object[]{invIdRefs.next()}, + XMLErrorReporter.SEVERITY_ERROR ); + } } } return; Modified: xerces/java/trunk/src/org/apache/xerces/impl/validation/ConfigurableValidationState.java URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/validation/ConfigurableValidationState.java?rev=1380445&r1=1380444&r2=1380445&view=diff ============================================================================== --- xerces/java/trunk/src/org/apache/xerces/impl/validation/ConfigurableValidationState.java (original) +++ xerces/java/trunk/src/org/apache/xerces/impl/validation/ConfigurableValidationState.java Tue Sep 4 04:43:34 2012 @@ -17,6 +17,8 @@ package org.apache.xerces.impl.validation; +import java.util.Iterator; + /** * <p>An extension of ValidationState which can be configured to turn * off checking for ID/IDREF errors and unparsed entity errors.</p> @@ -72,7 +74,7 @@ public final class ConfigurableValidatio * @return null, if ID/IDREF checking is turned off * otherwise, returns the value of the super implementation */ - public String checkIDRefID() { + public Iterator checkIDRefID() { return (fIdIdrefChecking) ? super.checkIDRefID() : null; } Modified: xerces/java/trunk/src/org/apache/xerces/impl/validation/ValidationState.java URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/validation/ValidationState.java?rev=1380445&r1=1380444&r2=1380445&view=diff ============================================================================== --- xerces/java/trunk/src/org/apache/xerces/impl/validation/ValidationState.java (original) +++ xerces/java/trunk/src/org/apache/xerces/impl/validation/ValidationState.java Tue Sep 4 04:43:34 2012 @@ -18,6 +18,7 @@ package org.apache.xerces.impl.validation; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Locale; @@ -87,18 +88,23 @@ public class ValidationState implements /** * return null if all IDREF values have a corresponding ID value; - * otherwise return the first IDREF value without a matching ID value. + * otherwise return an iterator for all the IDREF values without + * a matching ID value. */ - public String checkIDRefID () { + public Iterator checkIDRefID() { + HashSet missingIDs = null; Iterator iter = fIdRefTable.keySet().iterator(); String key; while (iter.hasNext()) { key = (String) iter.next(); if (!fIdTable.containsKey(key)) { - return key; + if (missingIDs == null) { + missingIDs = new HashSet(); + } + missingIDs.add(key); } } - return null; + return (missingIDs != null) ? missingIDs.iterator() : null; } public void reset () { Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java URL: http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?rev=1380445&r1=1380444&r2=1380445&view=diff ============================================================================== --- xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java (original) +++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Tue Sep 4 04:43:34 2012 @@ -2460,10 +2460,12 @@ public class XMLSchemaValidator // have we reached the end tag of the validation root? if (fElementDepth == 0) { // 7 If the element information item is the validation root, it must be valid per Validation Root Valid (ID/IDREF) (3.3.4). - String invIdRef = fValidationState.checkIDRefID(); + Iterator invIdRefs = fValidationState.checkIDRefID(); fValidationState.resetIDTables(); - if (invIdRef != null) { - reportSchemaError("cvc-id.1", new Object[] { invIdRef }); + if (invIdRefs != null) { + while (invIdRefs.hasNext()) { + reportSchemaError("cvc-id.1", new Object[] { invIdRefs.next() }); + } } // check extra schema constraints if (fFullChecking && !fUseGrammarPoolOnly) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@xerces.apache.org For additional commands, e-mail: commits-h...@xerces.apache.org