001 package railo.runtime.text.xml.struct; 002 003 import java.lang.reflect.Method; 004 005 import org.w3c.dom.Attr; 006 import org.w3c.dom.CDATASection; 007 import org.w3c.dom.Comment; 008 import org.w3c.dom.DOMConfiguration; 009 import org.w3c.dom.DOMException; 010 import org.w3c.dom.DOMImplementation; 011 import org.w3c.dom.Document; 012 import org.w3c.dom.DocumentFragment; 013 import org.w3c.dom.DocumentType; 014 import org.w3c.dom.Element; 015 import org.w3c.dom.EntityReference; 016 import org.w3c.dom.Node; 017 import org.w3c.dom.NodeList; 018 import org.w3c.dom.ProcessingInstruction; 019 import org.w3c.dom.Text; 020 021 import railo.runtime.exp.PageRuntimeException; 022 import railo.runtime.op.Caster; 023 import railo.runtime.type.Collection; 024 import railo.runtime.type.util.ArrayUtil; 025 026 027 /** 028 * 029 */ 030 public final class XMLDocumentStruct extends XMLNodeStruct implements Document { 031 032 private Document doc; 033 034 /** 035 * @param doc 036 * @param caseSensitive 037 */ 038 protected XMLDocumentStruct(Document doc, boolean caseSensitive) { 039 super(doc, caseSensitive); 040 this.doc=doc; 041 042 } 043 044 /** 045 * @see org.w3c.dom.Document#getImplementation() 046 */ 047 public DOMImplementation getImplementation() { 048 return doc.getImplementation(); 049 } 050 051 /** 052 * @see org.w3c.dom.Document#createDocumentFragment() 053 */ 054 public DocumentFragment createDocumentFragment() { 055 return doc.createDocumentFragment(); 056 } 057 058 /** 059 * @see org.w3c.dom.Document#getDoctype() 060 */ 061 public DocumentType getDoctype() { 062 return doc.getDoctype(); 063 } 064 065 /** 066 * @see org.w3c.dom.Document#getDocumentElement() 067 */ 068 public Element getDocumentElement() { 069 return doc.getDocumentElement(); 070 } 071 072 /** 073 * @see org.w3c.dom.Document#createAttribute(java.lang.String) 074 */ 075 public Attr createAttribute(String name) throws DOMException { 076 return doc.createAttribute(name); 077 } 078 079 /** 080 * @see org.w3c.dom.Document#createCDATASection(java.lang.String) 081 */ 082 public CDATASection createCDATASection(String data) throws DOMException { 083 return doc.createCDATASection(data); 084 } 085 086 /** 087 * @see org.w3c.dom.Document#createComment(java.lang.String) 088 */ 089 public Comment createComment(String data) { 090 return doc.createComment(data); 091 } 092 093 /** 094 * @see org.w3c.dom.Document#createElement(java.lang.String) 095 */ 096 public Element createElement(String tagName) throws DOMException { 097 return doc.createElement(tagName); 098 } 099 100 /** 101 * @see org.w3c.dom.Document#getElementById(java.lang.String) 102 */ 103 public Element getElementById(String elementId) { 104 return doc.getElementById(elementId); 105 } 106 107 /** 108 * @see org.w3c.dom.Document#createEntityReference(java.lang.String) 109 */ 110 public EntityReference createEntityReference(String name) throws DOMException { 111 return doc.createEntityReference(name); 112 } 113 114 /** 115 * @see org.w3c.dom.Document#importNode(org.w3c.dom.Node, boolean) 116 */ 117 public Node importNode(Node importedNode, boolean deep) throws DOMException { 118 return doc.importNode(importedNode,deep); 119 } 120 121 /** 122 * @see org.w3c.dom.Document#getElementsByTagName(java.lang.String) 123 */ 124 public NodeList getElementsByTagName(String tagname) { 125 return doc.getElementsByTagName(tagname); 126 } 127 128 /** 129 * @see org.w3c.dom.Document#createTextNode(java.lang.String) 130 */ 131 public Text createTextNode(String data) { 132 return doc.createTextNode(data); 133 } 134 135 /** 136 * @see org.w3c.dom.Document#createAttributeNS(java.lang.String, java.lang.String) 137 */ 138 public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException { 139 return doc.createAttributeNS(namespaceURI,qualifiedName); 140 } 141 142 /** 143 * @see org.w3c.dom.Document#createElementNS(java.lang.String, java.lang.String) 144 */ 145 public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException { 146 return doc.createElementNS(namespaceURI,qualifiedName); 147 } 148 149 /** 150 * @see org.w3c.dom.Document#getElementsByTagNameNS(java.lang.String, java.lang.String) 151 */ 152 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { 153 return doc.getElementsByTagNameNS(namespaceURI,localName); 154 } 155 156 /** 157 * @see org.w3c.dom.Document#createProcessingInstruction(java.lang.String, java.lang.String) 158 */ 159 public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException { 160 return doc.createProcessingInstruction(target,data); 161 } 162 163 /** 164 * @see org.w3c.dom.Document#adoptNode(org.w3c.dom.Node) 165 */ 166 public Node adoptNode(Node arg0) throws DOMException { 167 // dynamic load to support jre 1.4 and 1.5 168 try { 169 Method m = doc.getClass().getMethod("adoptNode", new Class[]{arg0.getClass()}); 170 return Caster.toNode(m.invoke(doc, new Object[]{arg0})); 171 } 172 catch (Exception e) { 173 throw new PageRuntimeException(Caster.toPageException(e)); 174 } 175 } 176 177 /** 178 * @see org.w3c.dom.Document#getDocumentURI() 179 */ 180 public String getDocumentURI() { 181 // dynamic load to support jre 1.4 and 1.5 182 try { 183 Method m = doc.getClass().getMethod("getDocumentURI", new Class[]{}); 184 return Caster.toString(m.invoke(doc, ArrayUtil.OBJECT_EMPTY)); 185 } 186 catch (Exception e) { 187 throw new PageRuntimeException(Caster.toPageException(e)); 188 } 189 } 190 191 /** 192 * 193 * @see org.w3c.dom.Document#getDomConfig() 194 */ 195 public DOMConfiguration getDomConfig() { 196 // dynamic load to support jre 1.4 and 1.5 197 try { 198 Method m = doc.getClass().getMethod("getDomConfig", new Class[]{}); 199 return (DOMConfiguration) m.invoke(doc, ArrayUtil.OBJECT_EMPTY); 200 } 201 catch (Exception e) { 202 throw new PageRuntimeException(Caster.toPageException(e)); 203 } 204 } 205 206 /** 207 * 208 * @see org.w3c.dom.Document#getInputEncoding() 209 */ 210 public String getInputEncoding() { 211 // dynamic load to support jre 1.4 and 1.5 212 try { 213 Method m = doc.getClass().getMethod("getInputEncoding", new Class[]{}); 214 return Caster.toString(m.invoke(doc, ArrayUtil.OBJECT_EMPTY)); 215 } 216 catch (Exception e) { 217 throw new PageRuntimeException(Caster.toPageException(e)); 218 } 219 } 220 221 /** 222 * 223 * @see org.w3c.dom.Document#getStrictErrorChecking() 224 */ 225 public boolean getStrictErrorChecking() { 226 // dynamic load to support jre 1.4 and 1.5 227 try { 228 Method m = doc.getClass().getMethod("getStrictErrorChecking", new Class[]{}); 229 return Caster.toBooleanValue(m.invoke(doc, ArrayUtil.OBJECT_EMPTY)); 230 } 231 catch (Exception e) { 232 throw new PageRuntimeException(Caster.toPageException(e)); 233 } 234 } 235 236 /** 237 * 238 * @see org.w3c.dom.Document#getXmlEncoding() 239 */ 240 public String getXmlEncoding() { 241 // dynamic load to support jre 1.4 and 1.5 242 try { 243 Method m = doc.getClass().getMethod("getXmlEncoding", new Class[]{}); 244 return Caster.toString(m.invoke(doc, ArrayUtil.OBJECT_EMPTY)); 245 } 246 catch (Exception e) { 247 throw new PageRuntimeException(Caster.toPageException(e)); 248 } 249 } 250 251 /** 252 * 253 * @see org.w3c.dom.Document#getXmlStandalone() 254 */ 255 public boolean getXmlStandalone() { 256 // dynamic load to support jre 1.4 and 1.5 257 try { 258 Method m = doc.getClass().getMethod("getXmlStandalone", new Class[]{}); 259 return Caster.toBooleanValue(m.invoke(doc, ArrayUtil.OBJECT_EMPTY)); 260 } 261 catch (Exception e) { 262 throw new PageRuntimeException(Caster.toPageException(e)); 263 } 264 } 265 266 /** 267 * 268 * @see org.w3c.dom.Document#getXmlVersion() 269 */ 270 public String getXmlVersion() { 271 // dynamic load to support jre 1.4 and 1.5 272 try { 273 Method m = doc.getClass().getMethod("getXmlVersion", new Class[]{}); 274 return Caster.toString(m.invoke(doc, ArrayUtil.OBJECT_EMPTY)); 275 } 276 catch (Exception e) { 277 throw new PageRuntimeException(Caster.toPageException(e)); 278 } 279 } 280 281 /** 282 * 283 * @see org.w3c.dom.Document#normalizeDocument() 284 */ 285 public void normalizeDocument() { 286 // dynamic load to support jre 1.4 and 1.5 287 try { 288 Method m = doc.getClass().getMethod("normalizeDocument", new Class[]{}); 289 m.invoke(doc, ArrayUtil.OBJECT_EMPTY); 290 } 291 catch (Exception e) { 292 throw new PageRuntimeException(Caster.toPageException(e)); 293 } 294 } 295 296 /** 297 * 298 * @see org.w3c.dom.Document#renameNode(org.w3c.dom.Node, java.lang.String, java.lang.String) 299 */ 300 public Node renameNode(Node arg0, String arg1, String arg2) throws DOMException { 301 // dynamic load to support jre 1.4 and 1.5 302 try { 303 Method m = doc.getClass().getMethod("renameNode", new Class[]{arg0.getClass(),arg1.getClass(),arg2.getClass()}); 304 return Caster.toNode(m.invoke(doc, new Object[]{arg0,arg1,arg2})); 305 } 306 catch (Exception e) { 307 throw new PageRuntimeException(Caster.toPageException(e)); 308 } 309 } 310 311 /** 312 * @see org.w3c.dom.Document#setDocumentURI(java.lang.String) 313 */ 314 public void setDocumentURI(String arg0) { 315 // dynamic load to support jre 1.4 and 1.5 316 try { 317 Method m = doc.getClass().getMethod("setDocumentURI", new Class[]{arg0.getClass()}); 318 m.invoke(doc, new Object[]{arg0}); 319 } 320 catch (Exception e) { 321 throw new PageRuntimeException(Caster.toPageException(e)); 322 } 323 324 } 325 326 /** 327 * @see org.w3c.dom.Document#setStrictErrorChecking(boolean) 328 */ 329 public void setStrictErrorChecking(boolean arg0) { 330 // dynamic load to support jre 1.4 and 1.5 331 try { 332 Method m = doc.getClass().getMethod("setStrictErrorChecking", new Class[]{boolean.class}); 333 m.invoke(doc, new Object[]{Caster.toBoolean(arg0)}); 334 } 335 catch (Exception e) { 336 throw new PageRuntimeException(Caster.toPageException(e)); 337 } 338 339 } 340 341 /** 342 * @see org.w3c.dom.Document#setXmlStandalone(boolean) 343 */ 344 public void setXmlStandalone(boolean arg0) throws DOMException { 345 // dynamic load to support jre 1.4 and 1.5 346 try { 347 Method m = doc.getClass().getMethod("setXmlStandalone", new Class[]{boolean.class}); 348 m.invoke(doc, new Object[]{Caster.toBoolean(arg0)}); 349 } 350 catch (Exception e) { 351 throw new PageRuntimeException(Caster.toPageException(e)); 352 } 353 354 } 355 356 /** 357 * @see org.w3c.dom.Document#setXmlVersion(java.lang.String) 358 */ 359 public void setXmlVersion(String arg0) throws DOMException { 360 // dynamic load to support jre 1.4 and 1.5 361 try { 362 Method m = doc.getClass().getMethod("setXmlVersion", new Class[]{arg0.getClass()}); 363 m.invoke(doc, new Object[]{arg0}); 364 } 365 catch (Exception e) { 366 throw new PageRuntimeException(Caster.toPageException(e)); 367 } 368 } 369 370 /** 371 * 372 * @see railo.runtime.type.Collection#duplicate(boolean) 373 */ 374 public Collection duplicate(boolean deepCopy) { 375 return new XMLDocumentStruct((Document)doc.cloneNode(deepCopy),caseSensitive); 376 } 377 378 379 /** 380 * @see org.w3c.dom.Node#cloneNode(boolean) 381 */ 382 public Node cloneNode(boolean deep) { 383 return new XMLDocumentStruct((Document)doc.cloneNode(deep),caseSensitive); 384 } 385 }