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 2004/04/23 06:40:39 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/util XMLErrorCode.java DOMErrorHandlerWrapper.java
mrglavas 2004/04/22 21:40:39
Modified: java/src/org/apache/xerces/util DOMErrorHandlerWrapper.java
Added: java/src/org/apache/xerces/util XMLErrorCode.java
Log:
Fixing Jira Bug #949:
http://nagoya.apache.org/jira/browse/XERCESJ-949
DOM Level 3 defines error types for well-formedness errors
such as 'wf-invalid-character-in-node-name'. The parser was
reporting it's own internal error code instead of what the API
expects.
Applying patch from Naela Nissar with some modifications.
This introduces a new class which represents the parser's
internal error codes. These internal codes are mapped
to DOM error types. This structure might be useful in the
future if SAX ever standardizes exception identifiers.
Revision Changes Path
1.12 +24 -6 xml-xerces/java/src/org/apache/xerces/util/DOMErrorHandlerWrapper.java
Index: DOMErrorHandlerWrapper.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/DOMErrorHandlerWrapper.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- DOMErrorHandlerWrapper.java 19 Mar 2004 19:46:54 -0000 1.11
+++ DOMErrorHandlerWrapper.java 23 Apr 2004 04:40:38 -0000 1.12
@@ -1,5 +1,5 @@
/*
- * Copyright 2001, 2002,2004 The Apache Software Foundation.
+ * Copyright 2001, 2002, 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,8 +26,10 @@
import org.apache.xerces.dom3.DOMErrorHandler;
import org.apache.xerces.dom.DOMErrorImpl;
import org.apache.xerces.dom.DOMLocatorImpl;
+import org.apache.xerces.impl.msg.XMLMessageFormatter;
import java.io.PrintWriter;
+import java.util.Hashtable;
/**
* This class handles DOM errors .
@@ -46,9 +48,11 @@
// I think we can avoid this indirection if we modify XMLErrorReporter. --el
public class DOMErrorHandlerWrapper
-implements XMLErrorHandler, DOMErrorHandler {
-
+ implements XMLErrorHandler, DOMErrorHandler {
+ /** Map for converting internal error codes to DOM error types. **/
+ private static Hashtable fgDOMErrorTypeTable;
+
// It keeps the reference of DOMErrorHandler of application
protected DOMErrorHandler fDomErrorHandler;
@@ -62,8 +66,20 @@
// @see DOMNormalizer.
public Node fCurrentNode;
+ /** Error code for comparisons. **/
+ protected final XMLErrorCode fErrorCode = new XMLErrorCode(null, null);
+
protected final DOMErrorImpl fDOMError = new DOMErrorImpl();
-
+
+ static {
+ // initialize error type table: internal error codes (represented by domain and key) need to be mapped to a DOM error type.
+ fgDOMErrorTypeTable = new Hashtable();
+ fgDOMErrorTypeTable.put(new XMLErrorCode(XMLMessageFormatter.XML_DOMAIN, "DoctypeNotAllowed"), "doctype-not-allowed");
+ fgDOMErrorTypeTable.put(new XMLErrorCode(XMLMessageFormatter.XML_DOMAIN, "ElementUnterminated"), "wf-invalid-character-in-node-name");
+ fgDOMErrorTypeTable.put(new XMLErrorCode(XMLMessageFormatter.XML_DOMAIN, "EncodingDeclInvalid"), "unsupported-encoding");
+ fgDOMErrorTypeTable.put(new XMLErrorCode(XMLMessageFormatter.XML_DOMAIN, "EqRequiredInAttribute"), "wf-invalid-character-in-node-name");
+ fgDOMErrorTypeTable.put(new XMLErrorCode(XMLMessageFormatter.XML_DOMAIN, "LessthanInAttValue"), "wf-invalid-character");
+ }
//
// Constructors
@@ -196,7 +212,9 @@
XMLParseException exception) throws XNIException {
fDOMError.fSeverity = DOMError.SEVERITY_FATAL_ERROR;
fDOMError.fException = exception;
- fDOMError.fType = key;
+ fErrorCode.setValues(domain, key);
+ String domErrorType = (String) fgDOMErrorTypeTable.get(fErrorCode);
+ fDOMError.fType = (domErrorType != null) ? domErrorType : key;
fDOMError.fRelatedData = fDOMError.fMessage = exception.getMessage();
DOMLocatorImpl locator = fDOMError.fLocator;
if (locator != null) {
1.1 xml-xerces/java/src/org/apache/xerces/util/XMLErrorCode.java
Index: XMLErrorCode.java
===================================================================
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.xerces.util;
/**
* <p>A structure that represents an error code, characterized by
* a domain and a message key.</p>
*
* @author Naela Nissar, IBM
*
* @version $Id: XMLErrorCode.java,v 1.1 2004/04/23 04:40:39 mrglavas Exp $
*/
public class XMLErrorCode {
//
// Data
//
/** error domain **/
private String fDomain;
/** message key **/
private String fKey;
/**
* <p>Constructs an XMLErrorCode with the given domain and key.</p>
*
* @param domain The error domain.
* @param key The key of the error message.
*/
public XMLErrorCode(String domain, String key) {
fDomain = domain;
fKey = key;
}
/**
* <p>Convenience method to set the values of an XMLErrorCode.</p>
*
* @param domain The error domain.
* @param key The key of the error message.
*/
public void setValues(String domain, String key) {
fDomain = domain;
fKey = key;
}
/**
* <p>Indicates whether some other object is equal to this XMLErrorCode.</p>
*
* @param obj the object with which to compare.
*/
public boolean equals(Object obj) {
if (!(obj instanceof XMLErrorCode))
return false;
XMLErrorCode err = (XMLErrorCode) obj;
return (fDomain.equals(err.fDomain) && fKey.equals(err.fKey));
}
/**
* <p>Returns a hash code value for this XMLErrorCode.</p>
*
* @return a hash code value for this XMLErrorCode.
*/
public int hashCode() {
return fDomain.hashCode() + fKey.hashCode();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org