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.CDATASection; 21 import com.google.gwt.xml.client.Comment; 22 import com.google.gwt.xml.client.DOMException; 23 import com.google.gwt.xml.client.Document; 24 import com.google.gwt.xml.client.DocumentFragment; 25 import com.google.gwt.xml.client.Element; 26 import com.google.gwt.xml.client.Node; 27 import com.google.gwt.xml.client.NodeList; 28 import com.google.gwt.xml.client.ProcessingInstruction; 29 import com.google.gwt.xml.client.Text; 30 31 34 class DocumentImpl extends NodeImpl implements Document { 35 36 protected DocumentImpl(JavaScriptObject o) { 37 super(o); 38 } 39 40 44 public CDATASection createCDATASection(String data) { 45 try { 46 return (CDATASection) NodeImpl.build(XMLParserImpl.createCDATASection( 47 this.getJsObject(), data)); 48 } catch (JavaScriptException e) { 49 throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this); 50 } 51 } 52 53 57 public Comment createComment(String data) { 58 try { 59 return (Comment) NodeImpl.build(XMLParserImpl.createComment( 60 this.getJsObject(), data)); 61 } catch (JavaScriptException e) { 62 throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this); 63 } 64 } 65 66 70 public DocumentFragment createDocumentFragment() { 71 try { 72 return (DocumentFragment) NodeImpl.build(XMLParserImpl.createDocumentFragment(this.getJsObject())); 73 } catch (JavaScriptException e) { 74 throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this); 75 } 76 } 77 78 82 public Element createElement(String tagName) { 83 try { 84 return (Element) NodeImpl.build(XMLParserImpl.createElement( 85 this.getJsObject(), tagName)); 86 } catch (JavaScriptException e) { 87 throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this); 88 } 89 } 90 91 95 public ProcessingInstruction createProcessingInstruction(String target, 96 String data) { 97 try { 98 return (ProcessingInstruction) NodeImpl.build(XMLParserImpl.createProcessingInstruction( 99 this.getJsObject(), target, data)); 100 } catch (JavaScriptException e) { 101 throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this); 102 } 103 } 104 105 109 public Text createTextNode(String data) { 110 try { 111 return (Text) NodeImpl.build(XMLParserImpl.createTextNode( 112 this.getJsObject(), data)); 113 } catch (JavaScriptException e) { 114 throw new DOMNodeException(DOMException.INVALID_CHARACTER_ERR, e, this); 115 } 116 } 117 118 122 public Element getDocumentElement() { 123 return (Element) NodeImpl.build(XMLParserImpl.getDocumentElement(this.getJsObject())); 124 } 125 126 130 public Element getElementById(String elementId) { 131 return (Element) NodeImpl.build(XMLParserImpl.getElementById( 132 this.getJsObject(), elementId)); 133 } 134 135 139 public NodeList getElementsByTagName(String tagName) { 140 return new NodeListImpl(XMLParserImpl.getElementsByTagName( 141 this.getJsObject(), tagName)); 142 } 143 144 148 public Node importNode(Node importedNode, boolean deep) { 149 try { 150 return NodeImpl.build(XMLParserImpl.importNode(this.getJsObject(), 151 ((DOMItem) importedNode).getJsObject(), deep)); 152 } catch (JavaScriptException e) { 153 throw new DOMNodeException(DOMException.INVALID_STATE_ERR, e, this); 154 } 155 } 156 157 164 public String toString() { 165 StringBuffer b = new StringBuffer (); 166 NodeList children = getChildNodes(); 167 for (int i = 0; i < children.getLength(); i++) { 168 b.append(children.item(i).toString()); 169 } 170 return b.toString(); 171 } 172 } 173 | Popular Tags |