You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by le...@apache.org on 2001/01/26 20:20:30 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/dom AttrImpl.java AttrNSImpl.java DocumentImpl.java ElementImpl.java ElementNSImpl.java ParentNode.java
lehors 01/01/26 11:20:30
Modified: java/src/org/apache/xerces/dom AttrImpl.java AttrNSImpl.java
DocumentImpl.java ElementImpl.java
ElementNSImpl.java ParentNode.java
Log:
cleaned up error checking code
Revision Changes Path
1.29 +10 -14 xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java
Index: AttrImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- AttrImpl.java 2001/01/25 02:05:23 1.28
+++ AttrImpl.java 2001/01/26 19:20:14 1.29
@@ -881,21 +881,17 @@
Node internalRemoveChild(Node oldChild,int mutationMask)
throws DOMException {
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
- }
-
DocumentImpl ownerDocument = ownerDocument();
- if (ownerDocument.errorChecking &&
- oldChild != null && oldChild.getParentNode() != this) {
- System.err.println("oldChild: " + oldChild +
- " parentNode: " + oldChild.getParentNode() +
- " this: " + this +
- " value: " + value);
- throw new DOMException(DOMException.NOT_FOUND_ERR,
- "DOM008 Not found");
+ if (ownerDocument.errorChecking) {
+ if (isReadOnly()) {
+ throw new DOMException(
+ DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
+ }
+ if (oldChild != null && oldChild.getParentNode() != this) {
+ throw new DOMException(DOMException.NOT_FOUND_ERR,
+ "DOM008 Not found");
+ }
}
// notify document
1.19 +59 -34 xml-xerces/java/src/org/apache/xerces/dom/AttrNSImpl.java
Index: AttrNSImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrNSImpl.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- AttrNSImpl.java 2001/01/12 00:10:19 1.18
+++ AttrNSImpl.java 2001/01/26 19:20:16 1.19
@@ -1,4 +1,4 @@
-/* $Id: AttrNSImpl.java,v 1.18 2001/01/12 00:10:19 lehors Exp $ */
+/* $Id: AttrNSImpl.java,v 1.19 2001/01/26 19:20:16 lehors Exp $ */
/*
* The Apache Software License, Version 1.1
*
@@ -81,6 +81,8 @@
/** Serialization version. */
static final long serialVersionUID = -781906615369795414L;
+ static final String xmlnsURI = "http://www.w3.org/2000/xmlns/";
+ static final String xmlURI = "http://www.w3.org/XML/1998/namespace";
//
// Data
@@ -99,36 +101,47 @@
String qualifiedName) {
super(ownerDocument, qualifiedName);
- if (!DocumentImpl.isXMLName(qualifiedName)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
- }
int index = qualifiedName.indexOf(':');
String prefix;
if (index < 0) {
prefix = null;
localName = qualifiedName;
- }
+
+ if (ownerDocument.errorChecking &&
+ qualifiedName.equals("xmlns") &&
+ (namespaceURI == null || !namespaceURI.equals(xmlnsURI))) {
+
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ }
else {
prefix = qualifiedName.substring(0, index);
localName = qualifiedName.substring(index+1);
- }
- if ((prefix != null &&
- (namespaceURI == null || namespaceURI.equals("") ||
- (prefix.equals("xml") &&
- !namespaceURI.equals("http://www.w3.org/XML/1998/namespace"))
- ||
- (prefix.equals("xmlns") &&
- !namespaceURI.equals("http://www.w3.org/2000/xmlns/"))))
- || (qualifiedName.equals("xmlns") &&
- (namespaceURI == null ||
- !namespaceURI.equals("http://www.w3.org/2000/xmlns/")))) {
-
- throw new DOMException(DOMException.NAMESPACE_ERR,
- "DOM003 Namespace error");
- }
+ if (ownerDocument.errorChecking) {
+ if (namespaceURI == null
+ || (localName.length() == 0)
+ || (localName.indexOf(':') >= 0)) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ } else if (prefix.equals("xml")) {
+ if (!namespaceURI.equals(xmlURI)) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ } else if (prefix.equals("xmlns")) {
+ if (!namespaceURI.equals(xmlnsURI)) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ } else if (index == 0) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ }
+ }
this.namespaceURI = namespaceURI;
}
@@ -203,20 +216,32 @@
if (needsSyncData()) {
synchronizeData();
}
- if (namespaceURI == null ||
- (prefix != null &&
- ((prefix.equals("xmlns") &&
- !namespaceURI.equals("http://www.w3.org/2000/xmlns/"))
- ||
- (prefix.equals("xml") &&
- !namespaceURI.equals("http://www.w3.org/XML/1998/namespace")))))
- {
- throw new DOMException(DOMException.NAMESPACE_ERR,
- "DOM003 Namespace error");
- }
- if (ownerDocument().errorChecking && !DocumentImpl.isXMLName(prefix)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ if (ownerDocument().errorChecking) {
+ if (isReadOnly()) {
+ throw new DOMException(
+ DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
+ }
+ if (!DocumentImpl.isXMLName(prefix)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
+ }
+ if (namespaceURI == null) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ } else if (prefix != null) {
+ if (prefix.equals("xmlns")) {
+ if (!namespaceURI.equals(xmlnsURI)){
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ } else if (prefix.equals("xml")) {
+ if (!namespaceURI.equals(xmlURI)) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ }
+ }
}
// update node name with new qualifiedName
name = prefix + ":" + localName;
1.45 +21 -20 xml-xerces/java/src/org/apache/xerces/dom/DocumentImpl.java
Index: DocumentImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DocumentImpl.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- DocumentImpl.java 2001/01/16 21:33:18 1.44
+++ DocumentImpl.java 2001/01/26 19:20:18 1.45
@@ -488,10 +488,9 @@
throws DOMException {
if (errorChecking && !isXMLName(tagName)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ "DOM002 Illegal character");
}
-
return new ElementImpl(this, tagName);
} // createElement(String):Element
@@ -510,10 +509,9 @@
throws DOMException {
if (errorChecking && !isXMLName(name)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ "DOM002 Illegal character");
}
-
return new EntityReferenceImpl(this, name);
} // createEntityReference(String):EntityReference
@@ -538,7 +536,6 @@
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
}
-
return new ProcessingInstructionImpl(this, target, data);
} // createProcessingInstruction(String,String):ProcessingInstruction
@@ -580,7 +577,7 @@
if (needsSyncChildren()) {
synchronizeChildren();
}
- return docElement;
+ return docElement;
}
/**
@@ -593,7 +590,7 @@
* @see DeepNodeListImpl
*/
public NodeList getElementsByTagName(String tagname) {
- return new DeepNodeListImpl(this,tagname);
+ return new DeepNodeListImpl(this,tagname);
}
/**
@@ -677,8 +674,8 @@
throws DOMException {
if (errorChecking && !isXMLName(qualifiedName)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ "DOM002 Illegal character");
}
return new DocumentTypeImpl(this, qualifiedName, publicID, systemID);
@@ -1155,6 +1152,10 @@
public Element createElementNS(String namespaceURI, String qualifiedName)
throws DOMException
{
+ if (errorChecking && !isXMLName(qualifiedName)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ "DOM002 Illegal character");
+ }
return new ElementNSImpl( this, namespaceURI, qualifiedName);
}
@@ -1179,6 +1180,10 @@
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
throws DOMException
{
+ if (errorChecking && !isXMLName(qualifiedName)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ "DOM002 Illegal character");
+ }
return new AttrNSImpl( this, namespaceURI, qualifiedName);
}
@@ -1199,7 +1204,7 @@
*/
public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
{
- return new DeepNodeListImpl(this, namespaceURI, localName);
+ return new DeepNodeListImpl(this, namespaceURI, localName);
}
//
@@ -1286,17 +1291,13 @@
NodeFilter filter,
boolean entityReferenceExpansion)
{
- if( root==null) {
- throw new DOMException(
+ if (root==null) {
+ throw new DOMException(
DOMException.NOT_SUPPORTED_ERR,
"DOM007 Not supported");
}
-
- TreeWalker treeWalker = new TreeWalkerImpl(root,
- whatToShow,
- filter,
- entityReferenceExpansion);
- return treeWalker;
+ return new TreeWalkerImpl(root, whatToShow, filter,
+ entityReferenceExpansion);
}
//
1.32 +36 -42 xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java
Index: ElementImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- ElementImpl.java 2001/01/23 17:54:40 1.31
+++ ElementImpl.java 2001/01/26 19:20:19 1.32
@@ -363,10 +363,9 @@
*/
public void removeAttribute(String name) {
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
+ if (ownerDocument.errorChecking && isReadOnly()) {
+ throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
}
if (needsSyncData()) {
@@ -399,13 +398,11 @@
* readonly.
*/
public Attr removeAttributeNode(Attr oldAttr)
- throws DOMException
- {
+ throws DOMException {
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
+ if (ownerDocument.errorChecking && isReadOnly()) {
+ throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
}
if (needsSyncData()) {
@@ -442,10 +439,9 @@
*/
public void setAttribute(String name, String value) {
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
+ if (ownerDocument.errorChecking && isReadOnly()) {
+ throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
}
if (needsSyncData()) {
@@ -486,20 +482,21 @@
throws DOMException
{
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
- }
-
if (needsSyncData()) {
synchronizeData();
}
- if (ownerDocument.errorChecking
- && newAttr.getOwnerDocument() != ownerDocument) {
+ if (ownerDocument.errorChecking) {
+ if (isReadOnly()) {
+ throw new DOMException(
+ DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
+ }
+
+ if (newAttr.getOwnerDocument() != ownerDocument) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
- "DOM005 Wrong document");
+ "DOM005 Wrong document");
+ }
}
if (attributes == null) {
@@ -585,10 +582,9 @@
*/
public void setAttributeNS(String namespaceURI, String localName, String value) {
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
+ if (ownerDocument.errorChecking && isReadOnly()) {
+ throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
}
if (needsSyncData()) {
@@ -629,10 +625,9 @@
*/
public void removeAttributeNS(String namespaceURI, String localName) {
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
+ if (ownerDocument.errorChecking && isReadOnly()) {
+ throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
}
if (needsSyncData()) {
@@ -700,20 +695,19 @@
throws DOMException
{
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
- }
-
if (needsSyncData()) {
synchronizeData();
}
-
- if (ownerDocument.errorChecking
- && newAttr.getOwnerDocument() != ownerDocument) {
- throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
- "DOM005 Wrong document");
+ if (ownerDocument.errorChecking) {
+ if (isReadOnly()) {
+ throw new DOMException(
+ DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
+ }
+ if (newAttr.getOwnerDocument() != ownerDocument) {
+ throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
+ "DOM005 Wrong document");
+ }
}
if (attributes == null) {
1.14 +40 -22 xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java
Index: ElementNSImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementNSImpl.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ElementNSImpl.java 2000/10/02 21:58:19 1.13
+++ ElementNSImpl.java 2001/01/26 19:20:20 1.14
@@ -1,4 +1,4 @@
-/* $Id: ElementNSImpl.java,v 1.13 2000/10/02 21:58:19 lehors Exp $ */
+/* $Id: ElementNSImpl.java,v 1.14 2001/01/26 19:20:20 lehors Exp $ */
/*
* The Apache Software License, Version 1.1
*
@@ -76,6 +76,7 @@
/** Serialization version. */
static final long serialVersionUID = -9142310625494392642L;
+ static final String xmlURI = "http://www.w3.org/XML/1998/namespace";
//
// Data
@@ -97,10 +98,6 @@
throws DOMException
{
super(ownerDocument, qualifiedName);
- if (!DocumentImpl.isXMLName(qualifiedName)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
- "DOM002 Illegal character");
- }
int index = qualifiedName.indexOf(':');
String prefix;
@@ -111,16 +108,25 @@
else {
prefix = qualifiedName.substring(0, index);
localName = qualifiedName.substring(index+1);
- }
- if (prefix != null &&
- (namespaceURI == null || namespaceURI.equals("") ||
- (prefix.equals("xml") &&
- !namespaceURI.equals("http://www.w3.org/XML/1998/namespace")))) {
-
- throw new DOMException(DOMException.NAMESPACE_ERR,
- "DOM003 Namespace error");
- }
+ if (ownerDocument.errorChecking) {
+ if (namespaceURI == null
+ || (localName.length() == 0)
+ || (localName.indexOf(':') >= 0)) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ else if (prefix.equals("xml")) {
+ if (!namespaceURI.equals(xmlURI)) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ } else if (index == 0) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ }
+ }
this.namespaceURI = namespaceURI;
}
@@ -196,16 +202,28 @@
{
if (needsSyncData()) {
synchronizeData();
- }
- if (namespaceURI == null ||
- (prefix != null && prefix.equals("xml") &&
- !namespaceURI.equals("http://www.w3.org/XML/1998/namespace"))) {
- throw new DOMException(DOMException.NAMESPACE_ERR,
- "DOM003 Namespace error");
}
- if (ownerDocument.errorChecking && !DocumentImpl.isXMLName(prefix)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
+ if (ownerDocument().errorChecking) {
+ if (isReadOnly()) {
+ throw new DOMException(
+ DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
+ }
+ if (!DocumentImpl.isXMLName(prefix)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"DOM002 Illegal character");
+ }
+ if (namespaceURI == null) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ } else if (prefix != null) {
+ if (prefix.equals("xml")) {
+ if (!namespaceURI.equals(xmlURI)) {
+ throw new DOMException(DOMException.NAMESPACE_ERR,
+ "DOM003 Namespace error");
+ }
+ }
+ }
}
// update node name with new qualifiedName
name = prefix + ":" + localName;
1.23 +11 -10 xml-xerces/java/src/org/apache/xerces/dom/ParentNode.java
Index: ParentNode.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ParentNode.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- ParentNode.java 2001/01/25 02:05:23 1.22
+++ ParentNode.java 2001/01/26 19:20:21 1.23
@@ -1,4 +1,4 @@
-/* $Id: ParentNode.java,v 1.22 2001/01/25 02:05:23 lehors Exp $ */
+/* $Id: ParentNode.java,v 1.23 2001/01/26 19:20:21 lehors Exp $ */
/*
* The Apache Software License, Version 1.1
*
@@ -584,16 +584,17 @@
Node internalRemoveChild(Node oldChild,int mutationMask)
throws DOMException {
- if (isReadOnly()) {
- throw new DOMException(
- DOMException.NO_MODIFICATION_ALLOWED_ERR,
- "DOM001 Modification not allowed");
- }
-
- if (ownerDocument.errorChecking &&
- oldChild != null && oldChild.getParentNode() != this) {
- throw new DOMException(DOMException.NOT_FOUND_ERR,
+ DocumentImpl ownerDocument = ownerDocument();
+ if (ownerDocument.errorChecking) {
+ if (isReadOnly()) {
+ throw new DOMException(
+ DOMException.NO_MODIFICATION_ALLOWED_ERR,
+ "DOM001 Modification not allowed");
+ }
+ if (oldChild != null && oldChild.getParentNode() != this) {
+ throw new DOMException(DOMException.NOT_FOUND_ERR,
"DOM008 Not found");
+ }
}
// notify document