elena 2002/08/11 13:27:19
Modified: java/src/org/apache/xerces/dom DOMErrorImpl.java
DOMLocatorImpl.java DOMNormalizer.java
Log:
Set current node on the DOM error handler wrapper, so that applications
that register DOM error handler before calling normalizeDocument,
have access to the current node if any validation error occurs.
Make some modifications to DOMError and DOMLocator to make those objects reusable.
Revision Changes Path
1.7 +8 -31 xml-xerces/java/src/org/apache/xerces/dom/DOMErrorImpl.java
Index: DOMErrorImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMErrorImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- DOMErrorImpl.java 9 Aug 2002 15:18:14 -0000 1.6
+++ DOMErrorImpl.java 11 Aug 2002 20:27:18 -0000 1.7
@@ -88,10 +88,10 @@
// Data
//
- short fSeverity = DOMError.SEVERITY_WARNING;
- String fMessage = null;
- DOMLocator fLocation = null;
- Exception fException = null;
+ public short fSeverity = DOMError.SEVERITY_WARNING;
+ public String fMessage = null;
+ public DOMLocatorImpl fLocator = new DOMLocatorImpl();
+ public Exception fException = null;
//
@@ -106,8 +106,7 @@
public DOMErrorImpl (short severity, XMLParseException exception) {
fSeverity = severity;
fException = exception;
- fMessage = exception.getMessage();
- fLocation = createDOMLocator (exception);
+ fLocator = createDOMLocator (exception);
}
/**
@@ -132,11 +131,11 @@
*/
public DOMLocator getLocation() {
- return fLocation;
+ return fLocator;
}
// method to get the DOMLocator Object
- private DOMLocator createDOMLocator(XMLParseException exception) {
+ private DOMLocatorImpl createDOMLocator(XMLParseException exception) {
// assuming DOMLocator wants the *expanded*, not the literal, URI of the
doc... - neilg
return new DOMLocatorImpl(exception.getLineNumber(),
exception.getColumnNumber(),
@@ -144,26 +143,6 @@
);
} // createDOMLocator()
- //
- // non-DOM methods
- // The setter methods allow to reuse DOMError object
- //
-
- public void setSeverity(short error){
- fSeverity = error;
- }
-
- public void setMessage(String msg){
- fMessage = msg;
- }
-
- public void setLocator(DOMLocator locator){
- fLocation = locator;
- }
-
- public void setException(Exception ex){
- fException = ex;
- }
/**
* The related platform dependent exception if any.exception is a reserved
@@ -176,8 +155,6 @@
public void reset(){
fSeverity = DOMError.SEVERITY_WARNING;
- fMessage = null;
- fLocation = null;
fException = null;
}
1.5 +11 -8 xml-xerces/java/src/org/apache/xerces/dom/DOMLocatorImpl.java
Index: DOMLocatorImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMLocatorImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DOMLocatorImpl.java 9 Aug 2002 15:18:14 -0000 1.4
+++ DOMLocatorImpl.java 11 Aug 2002 20:27:18 -0000 1.5
@@ -80,19 +80,19 @@
* The column number where the error occured,
* or -1 if there is no column number available.
*/
- int fColumnNumber = -1;
+ public int fColumnNumber = -1;
/**
* The DOM Node where the error occured, or
* null if there is no Node available.
*/
- Node fErrorNode = null;
+ public Node fErrorNode = null;
/**
* The line number where the error occured,
* or -1 if there is no line number available.
*/
- int fLineNumber = -1;
+ public int fLineNumber = -1;
/**
* The byte or character offset into the input source,
@@ -100,31 +100,34 @@
* will be the byte offset into that stream, but if a character media
* is parsed then the offset will be the character offset
*/
- int fOffset = -1;
+ public int fOffset = -1;
/**
* The URI where the error occured,
* or null if there is no URI available.
*/
- String fUri = null;
+ public String fUri = null;
//
// Constructors
//
+ public DOMLocatorImpl(){
+ }
+
public DOMLocatorImpl (int lineNumber, int columnNumber, String uri ){
fLineNumber = lineNumber ;
fColumnNumber = columnNumber ;
fUri = uri;
} // DOMLocatorImpl (int lineNumber, int columnNumber, String uri )
- public DOMLocatorImpl (int lineNumber, int columnNumber, int offset, Node
errorNode, String uri ){
+ public DOMLocatorImpl (int lineNumber, int columnNumber, int offset, Node
errorNode, String uri ){
fLineNumber = lineNumber ;
fColumnNumber = columnNumber ;
fOffset = offset ;
fErrorNode = errorNode ;
fUri = uri;
- } // DOMLocatorImpl (int lineNumber, int columnNumber, int offset, Node
errorNode, String uri )
+ } // DOMLocatorImpl (int lineNumber, int columnNumber, int offset, Node
errorNode, String uri )
/**
* The line number where the error occured, or -1 if there is no line
1.8 +29 -6 xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java
Index: DOMNormalizer.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DOMNormalizer.java 8 Aug 2002 22:35:52 -0000 1.7
+++ DOMNormalizer.java 11 Aug 2002 20:27:18 -0000 1.8
@@ -178,6 +178,9 @@
/** DOM Error object */
protected final DOMErrorImpl fDOMError = new DOMErrorImpl();
+ /** DOM Locator - for namespace fixup algorithm */
+ protected final DOMLocatorImpl fLocator = new DOMLocatorImpl();
+
//
@@ -324,6 +327,11 @@
// or rely on the PSVI information.
fAttrProxy.setAttributes(attributes, fDocument, elem);
updateQName(elem, fQName); // updates global qname
+ //
+ // set error node in the dom error wrapper
+ // so if error occurs we can report an error node
+ fDocument.fErrorHandlerWrapper.fCurrentNode = node;
+ // call re-validation handler
fValidationHandler.startElement(fQName, fAttrProxy, null);
}
@@ -349,6 +357,11 @@
if (fValidationHandler != null) {
updateQName(elem, fQName); // updates global qname
+ //
+ // set error node in the dom error wrapper
+ // so if error occurs we can report an error node
+ fDocument.fErrorHandlerWrapper.fCurrentNode = node;
+
fValidationHandler.endElement(fQName, null);
int count = fNamespaceBinder.getDeclaredPrefixCount();
for (int i = count - 1; i >= 0; i--) {
@@ -430,6 +443,12 @@
}
// send characters call for CDATA
if (fValidationHandler != null) {
+
+ //
+ // set error node in the dom error wrapper
+ // so if error occurs we can report an error node
+ fDocument.fErrorHandlerWrapper.fCurrentNode = node;
+
fValidationHandler.startCDATA(null);
fValidationHandler.characterData(node.getNodeValue(), null);
fValidationHandler.endCDATA(null);
@@ -486,6 +505,11 @@
nextType == Node.COMMENT_NODE) ||
((fDocument.features & CoreDocumentImpl.CDATA) == 0)
&&
nextType == Node.CDATA_SECTION_NODE)) {
+
+ //
+ // set error node in the dom error wrapper
+ // so if error occurs we can report an error node
+ fDocument.fErrorHandlerWrapper.fCurrentNode = node;
fValidationHandler.characterData(node.getNodeValue(),
null);
if (DEBUG_ND) {
System.out.println("=====>characterData(),"+nextType);
@@ -851,12 +875,11 @@
protected final DOMError modifyDOMError(String message, short severity, Node
node){
fDOMError.reset();
- fDOMError.setMessage(message);
- fDOMError.setSeverity(severity);
- // REVISIT: do we need to create a new locator for each error??
- fDOMError.setLocator(new DOMLocatorImpl(-1, -1, -1, node, null));
+ fDOMError.fMessage = message;
+ fDOMError.fSeverity = severity;
+ fDOMError.fLocator = fLocator;
+ fLocator.fErrorNode = node;
return fDOMError;
-
}
protected final void updateQName (Node node, QName qname){
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]