1 19 20 package org.netbeans.modules.xsl.grammar; 21 22 import org.w3c.dom.*; 23 24 30 public class ResultNode implements Node { 31 32 protected Node peer; 33 34 protected String ignorePrefix; 35 36 protected String onlyUsePrefix; 37 38 50 public ResultNode(Node peer, String ignorePrefix, String onlyUsePrefix) { 51 this.peer = peer; 52 this.ignorePrefix = ignorePrefix; 53 this.onlyUsePrefix = onlyUsePrefix; 54 } 55 56 public Node appendChild(Node newChild) throws DOMException { 57 return createNode(peer.appendChild(newChild)); 58 } 59 60 public Node cloneNode(boolean deep) { 61 return createNode(peer.cloneNode(deep)); 62 } 63 64 public NamedNodeMap getAttributes() { 65 return peer.getAttributes(); 66 } 67 68 public NodeList getChildNodes() { 69 return new ResultNodeList(peer.getChildNodes()); 70 } 71 72 public Node getFirstChild() { 73 NodeList childNodes = getChildNodes(); 74 if (childNodes.getLength() == 0) { 75 return null; 76 } else { 77 return childNodes.item(0); 78 } 79 } 80 81 public Node getLastChild() { 82 NodeList childNodes = new ResultNodeList(peer.getChildNodes()); 83 if (childNodes.getLength() == 0) { 84 return null; 85 } else { 86 return childNodes.item(childNodes.getLength()-1); 87 } 88 } 89 90 public String getLocalName() { 91 return peer.getLocalName(); 92 } 93 94 public String getNamespaceURI() { 95 return peer.getNamespaceURI(); 96 } 97 98 public Node getNextSibling() { 99 Node node = peer.getNextSibling(); 100 while (node != null && node.getNodeName() != null && !hasAllowedPrefix(node.getNodeName())) { 101 node = node.getNextSibling(); 102 } 103 104 if (node == null) { 105 return null; 106 } else { 107 return createNode(node); 108 } 109 } 110 111 public String getNodeName() { 112 return peer.getNodeName(); 113 } 114 115 public short getNodeType() { 116 return peer.getNodeType(); 117 } 118 119 public String getNodeValue() throws DOMException { 120 return peer.getNodeValue(); 121 } 122 123 public Document getOwnerDocument() { 124 return peer.getOwnerDocument(); 125 } 126 127 public Node getParentNode() { 128 Node node = peer.getParentNode(); 129 while (node != null && node.getNodeName() != null && !hasAllowedPrefix(node.getNodeName())) { 130 node = node.getParentNode(); 131 } 132 133 if (node == null) { 134 return null; 135 } else { 136 return createNode(node); 137 } 138 } 139 140 public String getPrefix() { 141 return peer.getPrefix(); 142 } 143 144 public Node getPreviousSibling() { 145 Node node = peer.getPreviousSibling(); 146 while (node != null && node.getNodeName() != null && !hasAllowedPrefix(node.getNodeName())) { 147 node = node.getPreviousSibling(); 148 } 149 150 if (node == null) { 151 return null; 152 } else { 153 return createNode(node); 154 } 155 } 156 157 public boolean hasAttributes() { 158 return peer.hasAttributes(); 159 } 160 161 public boolean hasChildNodes() { 162 return getChildNodes().getLength() > 0; 163 } 164 165 public Node insertBefore(Node newChild, Node refChild) throws DOMException { 166 return createNode(peer.insertBefore(newChild, refChild)); 167 } 168 169 public boolean isSupported(String feature, String version) { 170 return peer.isSupported(feature, version); 171 } 172 173 public void normalize() { 174 peer.normalize(); 175 } 176 177 public Node removeChild(Node oldChild) throws DOMException { 178 return createNode(peer.removeChild(oldChild)); 179 } 180 181 public Node replaceChild(Node newChild, Node oldChild) throws DOMException { 182 return createNode(peer.replaceChild(newChild, oldChild)); 183 } 184 185 public void setNodeValue(String nodeValue) throws DOMException { 186 peer.setNodeValue(nodeValue); 187 } 188 189 public void setPrefix(String prefix) throws DOMException { 190 peer.setPrefix(prefix); 191 } 192 193 196 protected Node createNode(Node orig) { 197 if (orig.getNodeType() == Node.ELEMENT_NODE) { 198 return new ResultElement((Element)orig, ignorePrefix, onlyUsePrefix); 199 } else if (orig.getNodeType() == Node.DOCUMENT_NODE) { 200 return new ResultDocument((Document)orig, ignorePrefix, onlyUsePrefix); 201 } else if (orig.getNodeType() == Node.ATTRIBUTE_NODE) { 202 return new ResultAttr((Attr)orig, ignorePrefix, onlyUsePrefix); 203 } else { 204 return orig; 205 } 206 } 207 208 212 protected boolean hasAllowedPrefix(String name) { 213 if (onlyUsePrefix != null) { 214 return name.startsWith(onlyUsePrefix); 215 } else if (ignorePrefix != null){ 216 return !name.startsWith(ignorePrefix); 217 } else { 218 return name.indexOf(':') == -1; 219 } 220 } 221 222 public class ResultNodeList implements NodeList{ 223 java.util.Vector nodeVector; 224 225 public ResultNodeList(NodeList list) { 226 nodeVector = new java.util.Vector (list.getLength()); 227 for (int ind = 0; ind < list.getLength(); ind++) { 228 Node node = list.item(ind); 229 if (node.getNodeName() != null && hasAllowedPrefix(node.getNodeName())) { 230 nodeVector.add(createNode(node)); 231 } 232 } 233 } 234 235 public int getLength() { 236 return nodeVector.size(); 237 } 238 239 public Node item(int index) { 240 return (Node)nodeVector.elementAt(index); 241 } 242 } 243 244 248 public short compareDocumentPosition (Node a) { 249 throw new UOException(); 250 } 251 252 public String getBaseURI() { 253 throw new UOException(); 254 } 255 public Object getFeature(String a, String b) { 256 throw new UOException(); 257 } 258 public String getTextContent () { 259 throw new UOException(); 260 } 261 public Object getUserData(String a) { 262 throw new UOException(); 263 } 264 public boolean isDefaultNamespace (String a) { 265 throw new UOException(); 266 } 267 public boolean isEqualNode(Node a) { 268 throw new UOException(); 269 } 270 public boolean isSameNode(Node a) { 271 throw new UOException(); 272 } 273 public String lookupNamespaceURI(String a) { 274 throw new UOException(); 275 } 276 public String lookupPrefix(String a) { 277 throw new UOException(); 278 } 279 public void setTextContent(String a) { 280 throw new UOException(); 281 } 282 public Object setUserData(String a, Object b, UserDataHandler c) { 283 throw new UOException(); 284 } 285 286 public TypeInfo getSchemaTypeInfo() { 288 throw new UOException (); 289 } 290 public void setIdAttribute(String a, boolean b) { 291 throw new UOException (); 292 } 293 public void setIdAttributeNS(String a, String b, boolean c) { 294 throw new UOException (); 295 } 296 public void setIdAttributeNode(Attr a, boolean b) { 297 throw new UOException (); 298 } 299 301 public boolean isId () { 302 throw new UOException (); 303 } 304 public Text replaceWholeText (String a) { 306 throw new UOException (); 307 } 308 public String getWholeText() { 309 throw new UOException (); 310 } 311 public boolean isElementContentWhitespace() { 312 throw new UOException (); 313 } 314 315 public Node adoptNode (Node a) { 317 throw new UOException (); 318 } 319 public String getDocumentURI () { 320 throw new UOException (); 321 } 322 public DOMConfiguration getDomConfig() { 323 throw new UOException (); 324 } 325 public String getInputEncoding() { 326 throw new UOException (); 327 } 328 public boolean getStrictErrorChecking() { 329 throw new UOException (); 330 } 331 public String getXmlEncoding () { 332 throw new UOException (); 333 } 334 public boolean getXmlStandalone() { 335 throw new UOException (); 336 } 337 public String getXmlVersion() { 338 throw new UOException (); 339 } 340 public void normalizeDocument() { 341 throw new UOException (); 342 } 343 public Node renameNode(Node a, String nb, String c) { 344 throw new UOException (); 345 } 346 public void setDocumentURI(String a) { 347 throw new UOException (); 348 } 349 public void setStrictErrorChecking(boolean a) { 350 throw new UOException (); 351 } 352 public void setXmlStandalone(boolean a) { 353 throw new UOException (); 354 } 355 public void setXmlVersion(String a) { 356 throw new UOException (); 357 } 358 359 private static final class UOException extends IllegalStateException { 360 361 } 362 } 363 | Popular Tags |