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.DOMException; 007 import org.w3c.dom.Element; 008 import org.w3c.dom.Node; 009 import org.w3c.dom.NodeList; 010 import org.w3c.dom.TypeInfo; 011 012 import railo.runtime.exp.PageRuntimeException; 013 import railo.runtime.op.Caster; 014 import railo.runtime.type.Collection; 015 import railo.runtime.type.util.ArrayUtil; 016 017 018 /** 019 * 020 */ 021 public class XMLElementStruct extends XMLNodeStruct implements Element { 022 023 024 private Element element; 025 026 /** 027 * constructor of the class 028 * @param element 029 * @param caseSensitive 030 */ 031 protected XMLElementStruct(Element element, boolean caseSensitive) { 032 super(element instanceof XMLElementStruct?element=((XMLElementStruct)element).getElement():element, caseSensitive); 033 this.element=element; 034 } 035 036 /** 037 * @see org.w3c.dom.Element#getTagName() 038 */ 039 public String getTagName() { 040 return element.getTagName(); 041 } 042 /** 043 * @see org.w3c.dom.Element#removeAttribute(java.lang.String) 044 */ 045 public void removeAttribute(String name) throws DOMException { 046 element.removeAttribute(name); 047 } 048 /** 049 * @see org.w3c.dom.Element#hasAttribute(java.lang.String) 050 */ 051 public boolean hasAttribute(String name) { 052 return element.hasAttribute(name); 053 } 054 /** 055 * @see org.w3c.dom.Element#getAttribute(java.lang.String) 056 */ 057 public String getAttribute(String name) { 058 return element.getAttribute(name); 059 } 060 /** 061 * @see org.w3c.dom.Element#removeAttributeNS(java.lang.String, java.lang.String) 062 */ 063 public void removeAttributeNS(String namespaceURI, String localName) throws DOMException { 064 element.removeAttributeNS(namespaceURI,localName); 065 } 066 /** 067 * @see org.w3c.dom.Element#setAttribute(java.lang.String, java.lang.String) 068 */ 069 public void setAttribute(String name, String value) throws DOMException { 070 element.setAttribute(name,value); 071 } 072 /** 073 * @see org.w3c.dom.Element#hasAttributeNS(java.lang.String, java.lang.String) 074 */ 075 public boolean hasAttributeNS(String namespaceURI, String localName) { 076 return element.hasAttributeNS(namespaceURI,localName); 077 } 078 /** 079 * @see org.w3c.dom.Element#getAttributeNode(java.lang.String) 080 */ 081 public Attr getAttributeNode(String name) { 082 return element.getAttributeNode(name); 083 } 084 /** 085 * @see org.w3c.dom.Element#removeAttributeNode(org.w3c.dom.Attr) 086 */ 087 public Attr removeAttributeNode(Attr oldAttr) throws DOMException { 088 return element.removeAttributeNode(oldAttr); 089 } 090 /** 091 * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr) 092 */ 093 public Attr setAttributeNode(Attr newAttr) throws DOMException { 094 return element.setAttributeNode(newAttr); 095 } 096 /** 097 * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr) 098 */ 099 public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { 100 return element.setAttributeNodeNS(newAttr); 101 } 102 /** 103 * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String) 104 */ 105 public NodeList getElementsByTagName(String name) { 106 return element.getElementsByTagName(name); 107 } 108 /** 109 * @see org.w3c.dom.Element#getAttributeNS(java.lang.String, java.lang.String) 110 */ 111 public String getAttributeNS(String namespaceURI, String localName) { 112 return element.getAttributeNS(namespaceURI,localName); 113 } 114 /** 115 * @see org.w3c.dom.Element#setAttributeNS(java.lang.String, java.lang.String, java.lang.String) 116 */ 117 public void setAttributeNS(String namespaceURI, String qualifiedName,String value) throws DOMException { 118 element.setAttributeNS(namespaceURI,qualifiedName,value); 119 } 120 /** 121 * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String) 122 */ 123 public Attr getAttributeNodeNS(String namespaceURI, String localName) { 124 return element.getAttributeNodeNS(namespaceURI,localName); 125 } 126 /** 127 * @see org.w3c.dom.Element#getElementsByTagNameNS(java.lang.String, java.lang.String) 128 */ 129 public NodeList getElementsByTagNameNS(String namespaceURI, String localName) { 130 return element.getElementsByTagNameNS(namespaceURI,localName); 131 } 132 133 /** 134 * 135 * @see org.w3c.dom.Element#setIdAttribute(java.lang.String, boolean) 136 */ 137 public void setIdAttribute(String name, boolean isId) throws DOMException { 138 // dynamic load to support jre 1.4 and 1.5 139 try { 140 Method m = element.getClass().getMethod("setIdAttribute", new Class[]{name.getClass(),boolean.class}); 141 m.invoke(element, new Object[]{name,Caster.toBoolean(isId)}); 142 } 143 catch (Exception e) { 144 throw new PageRuntimeException(Caster.toPageException(e)); 145 } 146 } 147 148 /** 149 * 150 * @see org.w3c.dom.Element#setIdAttributeNS(java.lang.String, java.lang.String, boolean) 151 */ 152 public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) throws DOMException { 153 // dynamic load to support jre 1.4 and 1.5 154 try { 155 Method m = element.getClass().getMethod("setIdAttributeNS", new Class[]{namespaceURI.getClass(),localName.getClass(),boolean.class}); 156 m.invoke(element, new Object[]{namespaceURI,localName,Caster.toBoolean(isId)}); 157 } 158 catch (Exception e) { 159 throw new PageRuntimeException(Caster.toPageException(e)); 160 } 161 } 162 163 /** 164 * 165 * @see org.w3c.dom.Element#setIdAttributeNode(org.w3c.dom.Attr, boolean) 166 */ 167 public void setIdAttributeNode(Attr idAttr, boolean isId) throws DOMException { 168 // dynamic load to support jre 1.4 and 1.5 169 try { 170 Method m = element.getClass().getMethod("setIdAttributeNode", new Class[]{idAttr.getClass(),boolean.class}); 171 m.invoke(element, new Object[]{idAttr,Caster.toBoolean(isId)}); 172 } 173 catch (Exception e) { 174 element.setAttributeNodeNS(idAttr); 175 } 176 } 177 178 /** 179 * 180 * @see org.w3c.dom.Element#getSchemaTypeInfo() 181 */ 182 public TypeInfo getSchemaTypeInfo() { 183 // dynamic load to support jre 1.4 and 1.5 184 try { 185 Method m = element.getClass().getMethod("getSchemaTypeInfo", new Class[]{}); 186 return (TypeInfo) m.invoke(element, ArrayUtil.OBJECT_EMPTY); 187 } 188 catch (Exception e) { 189 throw new PageRuntimeException(Caster.toPageException(e)); 190 } 191 } 192 /** 193 * @return the element 194 */ 195 public Element getElement() { 196 return element; 197 } 198 199 /** 200 * 201 * @see railo.runtime.type.Collection#duplicate(boolean) 202 */ 203 public Collection duplicate(boolean deepCopy) { 204 return new XMLElementStruct((Element)element.cloneNode(deepCopy),caseSensitive); 205 } 206 207 208 /** 209 * @see org.w3c.dom.Node#cloneNode(boolean) 210 */ 211 public Node cloneNode(boolean deep) { 212 return new XMLElementStruct((Element)element.cloneNode(deep),caseSensitive); 213 } 214 }