You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by mr...@apache.org on 2008/11/03 16:56:53 UTC
svn commit: r710088 -
/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java
Author: mrglavas
Date: Mon Nov 3 07:56:52 2008
New Revision: 710088
URL: http://svn.apache.org/viewvc?rev=710088&view=rev
Log:
Fixing a bug. We cannot cache the Location object from the start document event.
To get the correct line and column numbers it needs to be read at the point where
the error occurs. To handle this introduced a wrapper around the XMLStreamReader
which reads the Location from the reader on demand.
Modified:
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java
URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java?rev=710088&r1=710087&r2=710088&view=diff
==============================================================================
--- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java (original)
+++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/StAXValidatorHelper.java Mon Nov 3 07:56:52 2008
@@ -119,6 +119,9 @@
/** XML Locator wrapper for StAX. **/
private final StAXLocationWrapper fStAXLocationWrapper = new StAXLocationWrapper();
+ /** On demand reader of the Location from an XMLStreamReader. **/
+ private final XMLStreamReaderLocation fXMLStreamReaderLocation = new XMLStreamReaderLocation();
+
/** Map for tracking entity declarations. */
private HashMap fEntities = null;
@@ -203,6 +206,7 @@
// Release references to application objects
fCurrentEvent = null;
fStAXLocationWrapper.setLocation(null);
+ fXMLStreamReaderLocation.setXMLStreamReader(null);
if (fStAXValidatorHandler != null) {
fStAXValidatorHandler.setStAXResult(null);
}
@@ -350,7 +354,8 @@
throw new SAXException(JAXPValidationMessageFormatter.formatMessage(Locale.getDefault(),
"StAXIllegalInitialState", null));
}
- setup(reader.getLocation(), result, Boolean.TRUE.equals(reader.getProperty(STRING_INTERNING)));
+ fXMLStreamReaderLocation.setXMLStreamReader(reader);
+ setup(fXMLStreamReaderLocation, result, Boolean.TRUE.equals(reader.getProperty(STRING_INTERNING)));
fSchemaValidator.startDocument(fStAXLocationWrapper, null, fNamespaceContext, null);
do {
switch (eventType) {
@@ -631,5 +636,63 @@
}
}
}
+
+ /**
+ * On demand reader of the Location from an XMLStreamReader.
+ */
+ static final class XMLStreamReaderLocation implements Location {
+
+ private XMLStreamReader reader;
+
+ public XMLStreamReaderLocation() {}
+
+ public int getCharacterOffset() {
+ Location loc = getLocation();
+ if (loc != null) {
+ return loc.getCharacterOffset();
+ }
+ return -1;
+ }
+
+ public int getColumnNumber() {
+ Location loc = getLocation();
+ if (loc != null) {
+ return loc.getColumnNumber();
+ }
+ return -1;
+ }
+
+ public int getLineNumber() {
+ Location loc = getLocation();
+ if (loc != null) {
+ return loc.getLineNumber();
+ }
+ return -1;
+ }
+
+ public String getPublicId() {
+ Location loc = getLocation();
+ if (loc != null) {
+ return loc.getPublicId();
+ }
+ return null;
+ }
+
+ public String getSystemId() {
+ Location loc = getLocation();
+ if (loc != null) {
+ return loc.getSystemId();
+ }
+ return null;
+ }
+
+ public void setXMLStreamReader(XMLStreamReader reader) {
+ this.reader = reader;
+ }
+
+ private Location getLocation() {
+ return reader != null ? reader.getLocation() : null;
+ }
+ }
} // StAXValidatorHelper
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org