Lines 30-37
Link Here
|
30 |
import org.w3c.dom.NamedNodeMap; |
30 |
import org.w3c.dom.NamedNodeMap; |
31 |
import org.w3c.dom.Node; |
31 |
import org.w3c.dom.Node; |
32 |
import org.w3c.dom.NodeList; |
32 |
import org.w3c.dom.NodeList; |
|
|
33 |
import org.w3c.dom.UserDataHandler; |
34 |
import org.w3c.dom.events.Event; |
33 |
|
35 |
|
34 |
import java.util.HashMap; |
36 |
import java.util.HashMap; |
|
|
37 |
import java.util.Hashtable; |
35 |
|
38 |
|
36 |
/** |
39 |
/** |
37 |
* NodeImpl implements the foundation of the Xindice compressed DOM. |
40 |
* NodeImpl implements the foundation of the Xindice compressed DOM. |
Lines 295-300
Link Here
|
295 |
: null; |
298 |
: null; |
296 |
} |
299 |
} |
297 |
|
300 |
|
|
|
301 |
|
302 |
public boolean dispatchEvent(Event event) { |
303 |
return false; |
304 |
} |
305 |
|
298 |
/** |
306 |
/** |
299 |
* Inserts the node <code>newChild</code> before the existing child node |
307 |
* Inserts the node <code>newChild</code> before the existing child node |
300 |
* <code>refChild</code>. If <code>refChild</code> is <code>null</code>, |
308 |
* <code>refChild</code>. If <code>refChild</code> is <code>null</code>, |
Lines 920-923
Link Here
|
920 |
public String toString() { |
928 |
public String toString() { |
921 |
return TextWriter.toString(this); |
929 |
return TextWriter.toString(this); |
922 |
} |
930 |
} |
|
|
931 |
|
932 |
public short compareDocumentPosition(Node node) throws DOMException { |
933 |
if(this == node) |
934 |
return 0; |
935 |
else if(node instanceof NodeImpl){ |
936 |
|
937 |
return (short) Math.signum(this.key.hashCode() - ((NodeImpl) node).key.hashCode()); |
938 |
}else |
939 |
return (short) Math.signum(this.hashCode() - node.hashCode()); |
940 |
|
941 |
} |
942 |
|
943 |
|
944 |
public Object getFeature(String s, String s1) { |
945 |
return null; |
946 |
} |
947 |
|
948 |
public String getTextContent() throws DOMException { |
949 |
return getNodeValue(); |
950 |
} |
951 |
|
952 |
|
953 |
public Object setUserData(String s, Object obj, UserDataHandler userdatahandler) { |
954 |
if(obj == null){ |
955 |
if(userData != null){ |
956 |
Hashtable hTable = (Hashtable) userData.get(this); |
957 |
return hTable.get(s); |
958 |
} |
959 |
return null; |
960 |
}else{ |
961 |
|
962 |
Hashtable t; |
963 |
if(userData == null){ |
964 |
userData = new HashMap(); |
965 |
t = new Hashtable(); |
966 |
userData.put(this, t); |
967 |
}else { |
968 |
t = (Hashtable) userData.get(this); |
969 |
if(t== null){ |
970 |
t = new Hashtable(); |
971 |
userData.put(this, t); |
972 |
} |
973 |
} |
974 |
|
975 |
return t.put(s, new UserDataObject(obj,userdatahandler)); |
976 |
|
977 |
} |
978 |
} |
979 |
|
980 |
public String getBaseURI() { |
981 |
return null; |
982 |
} |
983 |
|
984 |
public boolean isEqualNode(Node arg) { |
985 |
if (arg == this) { |
986 |
return true; |
987 |
} |
988 |
if (arg.getNodeType() != getNodeType()) { |
989 |
return false; |
990 |
} |
991 |
// in theory nodeName can't be null but better be careful |
992 |
// who knows what other implementations may be doing?... |
993 |
if (getNodeName() == null) { |
994 |
if (arg.getNodeName() != null) { |
995 |
return false; |
996 |
} |
997 |
} |
998 |
else if (!getNodeName().equals(arg.getNodeName())) { |
999 |
return false; |
1000 |
} |
1001 |
|
1002 |
if (getLocalName() == null) { |
1003 |
if (arg.getLocalName() != null) { |
1004 |
return false; |
1005 |
} |
1006 |
} |
1007 |
else if (!getLocalName().equals(arg.getLocalName())) { |
1008 |
return false; |
1009 |
} |
1010 |
|
1011 |
if (getNamespaceURI() == null) { |
1012 |
if (arg.getNamespaceURI() != null) { |
1013 |
return false; |
1014 |
} |
1015 |
} |
1016 |
else if (!getNamespaceURI().equals(arg.getNamespaceURI())) { |
1017 |
return false; |
1018 |
} |
1019 |
|
1020 |
if (getPrefix() == null) { |
1021 |
if (arg.getPrefix() != null) { |
1022 |
return false; |
1023 |
} |
1024 |
} |
1025 |
else if (!getPrefix().equals(arg.getPrefix())) { |
1026 |
return false; |
1027 |
} |
1028 |
|
1029 |
if (getNodeValue() == null) { |
1030 |
if (arg.getNodeValue() != null) { |
1031 |
return false; |
1032 |
} |
1033 |
} |
1034 |
else if (!getNodeValue().equals(arg.getNodeValue())) { |
1035 |
return false; |
1036 |
} |
1037 |
|
1038 |
|
1039 |
return true; |
1040 |
} |
1041 |
|
1042 |
public void setTextContent(String textContent) |
1043 |
throws DOMException { |
1044 |
setNodeValue(textContent); |
1045 |
} |
1046 |
|
1047 |
public String lookupPrefix(String namespaceURI){ |
1048 |
|
1049 |
// REVISIT: When Namespaces 1.1 comes out this may not be true |
1050 |
// Prefix can't be bound to null namespace |
1051 |
if (namespaceURI == null) { |
1052 |
return null; |
1053 |
} |
1054 |
|
1055 |
short type = this.getNodeType(); |
1056 |
|
1057 |
switch (type) { |
1058 |
case Node.ELEMENT_NODE: { |
1059 |
this.getNamespaceURI(); // to flip out children |
1060 |
return lookupNamespacePrefix(namespaceURI); |
1061 |
} |
1062 |
case Node.DOCUMENT_NODE:{ |
1063 |
return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); |
1064 |
} |
1065 |
|
1066 |
case Node.ENTITY_NODE : |
1067 |
case Node.NOTATION_NODE: |
1068 |
case Node.DOCUMENT_FRAGMENT_NODE: |
1069 |
case Node.DOCUMENT_TYPE_NODE: |
1070 |
// type is unknown |
1071 |
return null; |
1072 |
case Node.ATTRIBUTE_NODE:{ |
1073 |
if (getOwnerDocument()!= null && getOwnerDocument().getNodeType() == Node.ELEMENT_NODE) { |
1074 |
return getOwnerDocument().lookupPrefix(namespaceURI); |
1075 |
|
1076 |
} |
1077 |
return null; |
1078 |
} |
1079 |
default:{ |
1080 |
NodeImpl ancestor = (NodeImpl)getParentNode(); |
1081 |
if (ancestor != null) { |
1082 |
return ancestor.lookupPrefix(namespaceURI); |
1083 |
} |
1084 |
return null; |
1085 |
} |
1086 |
|
1087 |
} |
1088 |
} |
1089 |
|
1090 |
public boolean isDefaultNamespace(String namespaceURI){ |
1091 |
// REVISIT: remove casts when DOM L3 becomes REC. |
1092 |
short type = this.getNodeType(); |
1093 |
switch (type) { |
1094 |
case Node.ELEMENT_NODE: { |
1095 |
String namespace = this.getNamespaceURI(); |
1096 |
String prefix = this.getPrefix(); |
1097 |
|
1098 |
// REVISIT: is it possible that prefix is empty string? |
1099 |
if (prefix == null || prefix.length() == 0) { |
1100 |
if (namespaceURI == null) { |
1101 |
return (namespace == namespaceURI); |
1102 |
} |
1103 |
return namespaceURI.equals(namespace); |
1104 |
} |
1105 |
if (this.hasAttributes()) { |
1106 |
ElementImpl elem = (ElementImpl)this; |
1107 |
NodeImpl attr = (NodeImpl)elem.getAttributeNodeNS("http://www.w3.org/2000/xmlns/", "xmlns"); |
1108 |
if (attr != null) { |
1109 |
String value = attr.getNodeValue(); |
1110 |
if (namespaceURI == null) { |
1111 |
return (namespace == value); |
1112 |
} |
1113 |
return namespaceURI.equals(value); |
1114 |
} |
1115 |
} |
1116 |
|
1117 |
NodeImpl ancestor = (NodeImpl)getParentNode(); |
1118 |
if (ancestor != null) { |
1119 |
return ancestor.isDefaultNamespace(namespaceURI); |
1120 |
} |
1121 |
return false; |
1122 |
} |
1123 |
case Node.DOCUMENT_NODE:{ |
1124 |
return((NodeImpl)((Document)this).getDocumentElement()).isDefaultNamespace(namespaceURI); |
1125 |
} |
1126 |
|
1127 |
case Node.ENTITY_NODE : |
1128 |
case Node.NOTATION_NODE: |
1129 |
case Node.DOCUMENT_FRAGMENT_NODE: |
1130 |
case Node.DOCUMENT_TYPE_NODE: |
1131 |
// type is unknown |
1132 |
return false; |
1133 |
case Node.ATTRIBUTE_NODE:{ |
1134 |
if (getOwnerDocument()!=null && getOwnerDocument().getNodeType() == Node.ELEMENT_NODE) { |
1135 |
return getOwnerDocument().isDefaultNamespace(namespaceURI); |
1136 |
|
1137 |
} |
1138 |
return false; |
1139 |
} |
1140 |
default:{ |
1141 |
NodeImpl ancestor = (NodeImpl)getParentNode(); |
1142 |
if (ancestor != null) { |
1143 |
return ancestor.isDefaultNamespace(namespaceURI); |
1144 |
} |
1145 |
return false; |
1146 |
} |
1147 |
|
1148 |
} |
1149 |
|
1150 |
|
1151 |
} |
1152 |
|
1153 |
class UserDataObject{ |
1154 |
|
1155 |
UserDataHandler handler; |
1156 |
Object node; |
1157 |
|
1158 |
UserDataObject(Object node, UserDataHandler handler){ |
1159 |
this.node = node; |
1160 |
this.handler = handler; |
1161 |
|
1162 |
} |
1163 |
|
1164 |
} |
1165 |
|
1166 |
|
923 |
} |
1167 |
} |