1 16 package com.google.gwt.xml.client.impl; 17 18 import com.google.gwt.core.client.JavaScriptException; 19 import com.google.gwt.core.client.JavaScriptObject; 20 import com.google.gwt.xml.client.Attr; 21 import com.google.gwt.xml.client.DOMException; 22 import com.google.gwt.xml.client.Element; 23 import com.google.gwt.xml.client.NodeList; 24 25 28 class ElementImpl extends NodeImpl implements Element { 29 30 protected ElementImpl(JavaScriptObject o) { 31 super(o); 32 } 33 34 38 public String getAttribute(String tagName) { 39 return XMLParserImpl.getAttribute(this.getJsObject(), tagName); 40 } 41 42 46 public Attr getAttributeNode(String tagName) { 47 return (Attr) NodeImpl.build(XMLParserImpl.getAttributeNode(this 48 .getJsObject(), tagName)); 49 } 50 51 55 public NodeList getElementsByTagName(String tagName) { 56 return new NodeListImpl(XMLParserImpl.getElementsByTagName(this 57 .getJsObject(), tagName)); 58 } 59 60 64 public String getTagName() { 65 return XMLParserImpl.getTagName(this.getJsObject()); 66 } 67 68 72 public boolean hasAttribute(String tagName) { 73 return getAttribute(tagName) != null; 74 } 75 76 80 public void removeAttribute(String name) throws DOMNodeException { 81 try { 82 XMLParserImpl.removeAttribute(this.getJsObject(), name); 83 } catch (JavaScriptException e) { 84 throw new DOMNodeException(DOMException.INVALID_MODIFICATION_ERR, e, this); 85 } 86 } 87 88 92 public void setAttribute(String name, String value) throws DOMNodeException { 93 try { 94 XMLParserImpl.setAttribute(this.getJsObject(), name, value); 95 } catch (JavaScriptException e) { 96 throw new DOMNodeException(DOMException.INVALID_MODIFICATION_ERR, e, this); 97 } 98 } 99 100 107 public String toString() { 108 final StringBuffer b = new StringBuffer ("<"); 109 b.append(getTagName()); 110 if (hasAttributes()) { 111 b.append(getAttributes().toString()); 112 } 113 if (hasChildNodes()) { 114 b.append(">"); 115 b.append(getChildNodes().toString()); 116 b.append("</"); 117 b.append(getTagName()); 118 b.append(">"); 119 } else { 120 b.append("/>"); 121 } 122 return b.toString(); 123 } 124 } 125 | Popular Tags |