mrglavas 2004/04/22 13:39:04
Modified: java/src/org/apache/xerces/dom DOMNormalizer.java
java/src/org/apache/xml/serialize DOMSerializerImpl.java
Log:
Fixing Jira Bug #948:
http://nagoya.apache.org/jira/browse/XERCESJ-948
In DOMNormailzer and DOMSerializerImpl DOMLocator.relatedNode
and DOMError.relatedData were not being reported correctly in
many instances. Patched thanks to Naela Nissar.
Also fixed a bug in DOMSerializerImpl where the well-formedness
of an element name was checked over and over again instead of
checking the well-formedness of the names of its attributes.
Revision Changes Path
1.54 +30 -28 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.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- DOMNormalizer.java 30 Mar 2004 02:50:28 -0000 1.53
+++ DOMNormalizer.java 22 Apr 2004 20:39:03 -0000 1.54
@@ -246,7 +246,8 @@
int type = node.getNodeType();
boolean wellformed;
-
+ fLocator.fRelatedNode=node;
+
switch (type) {
case Node.DOCUMENT_TYPE_NODE: {
if (DEBUG_ND) {
@@ -276,7 +277,7 @@
DOMMessageFormatter.DOM_DOMAIN,
"wf-invalid-character-in-node-name",
new Object[]{"Element",
node.getNodeName()});
- reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR, node,
+ reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR,
"wf-invalid-character-in-node-name");
}
}
@@ -312,7 +313,7 @@
"wf-invalid-character-in-node-name",
new
Object[]{"Attr",node.getNodeName()});
reportDOMError(fErrorHandler, fError, fLocator, msg, DOMError.SEVERITY_ERROR,
- node,
"wf-invalid-character-in-node-name");
+
"wf-invalid-character-in-node-name");
}
}
}
@@ -479,12 +480,13 @@
parent.insertBefore(newChild, node.getNextSibling());
node = newChild;
// issue warning
+ fLocator.fRelatedNode = firstSplitNode;
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"cdata-sections-splitted",
null);
reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_WARNING,
- firstSplitNode, "cdata-sections-splitted");
+ "cdata-sections-splitted");
}
}
@@ -572,7 +574,7 @@
DOMMessageFormatter.DOM_DOMAIN,
"wf-invalid-character-in-node-name",
new Object[]{"Element", node.getNodeName()});
- reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR, null,
+ reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR,
"wf-invalid-character-in-node-name");
}
@@ -643,8 +645,9 @@
if (value.equals(NamespaceContext.XMLNS_URI)) {
//A null value for locale is passed to formatMessage,
//which means that the default locale will be used
+ fLocator.fRelatedNode = attr;
String msg =
DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,"CantBindXMLNS",null
);
- reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR, attr, "CantBindXMLNS");
+ reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR, "CantBindXMLNS");
} else {
// XML 1.0 Attribute value normalization
// value = normalizeAttributeValue(value, attr);
@@ -717,13 +720,13 @@
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName",
new Object[]{element.getNodeName()});
- reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_FATAL_ERROR, element,
+ reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_FATAL_ERROR,
"NullLocalElementName");
} else {
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN, "NullLocalElementName",
new Object[]{element.getNodeName()});
- reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR, element,
+ reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR,
"NullLocalElementName");
}
} else { // uri=null and no colon (DOM L2 node)
@@ -748,6 +751,7 @@
attributes.cloneMap(fAttributeList);
for (int i = 0; i < fAttributeList.size(); i++) {
Attr attr = (Attr) fAttributeList.elementAt(i);
+ fLocator.fRelatedNode = attr;
if (DEBUG) {
System.out.println("==>[ns-fixup] process attribute:
"+attr.getNodeName());
@@ -789,7 +793,7 @@
DOMMessageFormatter.DOM_DOMAIN,
"wf-invalid-character-in-node-name",
new Object[]{"Attribute",
attr.getNodeName()});
- reportDOMError(fErrorHandler, fError,
fLocator, msg, DOMError.SEVERITY_ERROR, attr,
+ reportDOMError(fErrorHandler, fError,
fLocator, msg, DOMError.SEVERITY_ERROR,
"wf-invalid-character-in-node-name");
}
}
@@ -871,13 +875,13 @@
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NullLocalAttrName", new
Object[]{attr.getNodeName()});
- reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_FATAL_ERROR, attr,
+ reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_FATAL_ERROR,
"NullLocalAttrName");
} else {
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NullLocalAttrName", new
Object[]{attr.getNodeName()});
- reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR, attr,
+ reportDOMError(fErrorHandler, fError, fLocator, msg,
DOMError.SEVERITY_ERROR,
"NullLocalAttrName");
}
} else {
@@ -958,7 +962,6 @@
locator,
msg,
DOMError.SEVERITY_ERROR,
- null,
"wf-invalid-character");
}
else if (c==']'){
@@ -971,7 +974,7 @@
//CDEndInContent
String msg =
DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
"CDEndInContent", null);
- reportDOMError(errorHandler,
error, locator,msg, DOMError.SEVERITY_ERROR, null, "wf-invalid-character");
+ reportDOMError(errorHandler,
error, locator,msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
}
@@ -989,7 +992,7 @@
//"wf-invalid-character" is used. Also per DOM it is error
but
//as per XML spec. it is fatal error
String msg =
DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
"InvalidCharInCDSect", new Object[]{Integer.toString(c, 16)});
- reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, null,
+ reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR,
"wf-invalid-character");
}
else if (c==']'){
@@ -1000,7 +1003,7 @@
}
if (count <datalength && dataarray[count]=='>'){
String msg =
DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,"CDEndInContent",
null);
- reportDOMError(errorHandler,
error, locator, msg, DOMError.SEVERITY_ERROR, null, "wf-invalid-character");
+ reportDOMError(errorHandler,
error, locator, msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
}
@@ -1024,27 +1027,27 @@
//version of the document is XML 1.1
if(isXML11Version){
- //we need to check all chracters as per production rules of XML11
+ //we need to check all characters as per production rules of XML11
int i = 0 ;
while(i < datalength){
if(XML11Char.isXML11Invalid(dataarray[i++])){
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN, "InvalidXMLCharInDOM",
new Object[]{Integer.toString(dataarray[i-1], 16)});
- reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, null,
+ reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR,
"wf-invalid-character");
};
}
}//version of the document is XML 1.0
else{
- //we need to check all chracters as per production rules of XML 1.0
+ //we need to check all characters as per production rules of XML 1.0
int i = 0 ;
while(i < datalength){
if( XMLChar.isInvalid(dataarray[i++]) ){
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN, "InvalidXMLCharInDOM",
new Object[]{Integer.toString(dataarray[i-1], 16)});
- reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, null,
+ reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR,
"wf-invalid-character");
};
}
@@ -1076,13 +1079,13 @@
String msg =
DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
"InvalidCharInComment",
new Object []
{Integer.toString(dataarray[i-1], 16)});
- reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, null, "wf-invalid-character");
+ reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
else if (c == '-' && i<datalength && dataarray[i]=='-'){
String msg =
DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
"DashDashInComment", null);
// invalid: '--' in comment
- reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, null, "wf-invalid-character");
+ reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
}
}//version of the document is XML 1.0
@@ -1094,13 +1097,13 @@
if( XMLChar.isInvalid(c) ){
String msg =
DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
"InvalidCharInComment", new Object []
{Integer.toString(dataarray[i-1], 16)});
- reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, null, "wf-invalid-character");
+ reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
else if (c == '-' && i<datalength && dataarray[i]=='-'){
String msg =
DOMMessageFormatter.formatMessage(DOMMessageFormatter.XML_DOMAIN,
"DashDashInComment", null);
// invalid: '--' in comment
- reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, null, "wf-invalid-character");
+ reportDOMError(errorHandler, error, locator,
msg, DOMError.SEVERITY_ERROR, "wf-invalid-character");
}
}
@@ -1143,7 +1146,7 @@
DOMMessageFormatter.DOM_DOMAIN,
"UndeclaredEntRefInAttrValue",
new Object[]{a.getNodeName()});
reportDOMError(errorHandler, error, locator, msg,
DOMError.SEVERITY_ERROR,
- null, "UndeclaredEntRefInAttrValue");
+ "UndeclaredEntRefInAttrValue");
}
}
else {
@@ -1162,15 +1165,14 @@
* If the error is fatal, the processing will be always aborted.
*/
public static final void reportDOMError(DOMErrorHandler errorHandler,
DOMErrorImpl error, DOMLocatorImpl locator,
- String message, short severity, Node node, String type ){
+ String message, short severity, String type ) {
if( errorHandler!=null ) {
error.reset();
error.fMessage = message;
error.fSeverity = severity;
error.fLocator = locator;
error.fType = type;
- error.fRelatedData = node;
- locator.fRelatedNode = node;
+ error.fRelatedData = locator.fRelatedNode;
if(!errorHandler.handleError(error))
throw abort;
1.21 +6 -5
xml-xerces/java/src/org/apache/xml/serialize/DOMSerializerImpl.java
Index: DOMSerializerImpl.java
===================================================================
RCS file:
/home/cvs/xml-xerces/java/src/org/apache/xml/serialize/DOMSerializerImpl.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- DOMSerializerImpl.java 29 Mar 2004 20:02:07 -0000 1.20
+++ DOMSerializerImpl.java 22 Apr 2004 20:39:04 -0000 1.21
@@ -1005,6 +1005,7 @@
private void verify (Node node, boolean verifyNames, boolean xml11Version){
int type = node.getNodeType();
+ fLocator.fRelatedNode = node;
boolean wellformed;
switch (type) {
case Node.DOCUMENT_NODE:{
@@ -1028,7 +1029,7 @@
DOMMessageFormatter.DOM_DOMAIN,
"wf-invalid-character-in-node-name",
new Object[]{"Element",
node.getNodeName()});
- DOMNormalizer.reportDOMError(fErrorHandler,
fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR, null,
+ DOMNormalizer.reportDOMError(fErrorHandler,
fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR,
"wf-invalid-character-in-node-name");
}
@@ -1040,17 +1041,18 @@
if (attributes != null) {
for (int i = 0; i < attributes.getLength(); ++i) {
Attr attr = (Attr) attributes.item(i);
+ fLocator.fRelatedNode = attr;
DOMNormalizer.isAttrValueWF( fErrorHandler, fError,
fLocator,
attributes,(AttrImpl) attr, attr.getValue(),
xml11Version);
if (verifyNames) {
- wellformed = CoreDocumentImpl.isXMLName(
node.getNodeName(), xml11Version);
+ wellformed = CoreDocumentImpl.isXMLName(
attr.getNodeName(), xml11Version);
if (!wellformed) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"wf-invalid-character-in-node-name",
new Object[] { "Attr",
node.getNodeName()});
- DOMNormalizer.reportDOMError( fErrorHandler,
fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR, null,
+ DOMNormalizer.reportDOMError( fErrorHandler,
fError, fLocator, msg, DOMError.SEVERITY_FATAL_ERROR,
"wf-invalid-character-in-node-name");
}
}
@@ -1107,7 +1109,6 @@
fLocator,
msg,
DOMError.SEVERITY_FATAL_ERROR,
- null,
"wf-invalid-character-in-node-name");
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]