1 57 package org.enhydra.apache.html.dom; 58 59 60 import org.enhydra.apache.xerces.dom.ElementImpl; 61 import org.w3c.dom.Attr ; 62 import org.w3c.dom.Node ; 63 import org.w3c.dom.NodeList ; 64 import org.w3c.dom.html.HTMLElement; 65 import org.w3c.dom.html.HTMLFormElement; 66 67 68 82 public class HTMLElementImpl 83 extends ElementImpl 84 implements HTMLElement 85 { 86 87 88 96 public HTMLElementImpl( HTMLDocumentImpl owner, String tagName ) 97 { 98 super( owner, tagName.toUpperCase() ); 99 } 100 101 102 public String getId() 103 { 104 return getAttribute( "id" ); 105 } 106 107 108 public void setId( String id ) 109 { 110 setAttribute( "id", id ); 111 } 112 113 114 public String getTitle() 115 { 116 return getAttribute( "title" ); 117 } 118 119 120 public void setTitle( String title ) 121 { 122 setAttribute( "title", title ); 123 } 124 125 126 public String getLang() 127 { 128 return getAttribute( "lang" ); 129 } 130 131 132 public void setLang( String lang ) 133 { 134 setAttribute( "lang", lang ); 135 } 136 137 138 public String getDir() 139 { 140 return getAttribute( "dir" ); 141 } 142 143 144 public void setDir( String dir ) 145 { 146 setAttribute( "dir", dir ); 147 } 148 149 150 public String getClassName() 151 { 152 return getAttribute( "class" ); 153 } 154 155 156 public void setClassName( String className ) 157 { 158 setAttribute( "class", className ); 159 } 160 161 162 170 int getInteger( String value ) 171 { 172 try 173 { 174 return Integer.parseInt( value ); 175 } 176 catch ( NumberFormatException except ) 177 { 178 return 0; 179 } 180 } 181 182 183 192 boolean getBinary( String name ) 193 { 194 return ( getAttributeNode( name ) != null ); 195 } 196 197 198 206 void setAttribute( String name, boolean value ) 207 { 208 if ( value ) 209 setAttribute( name, name ); 210 else 211 removeAttribute( name ); 212 } 213 214 215 public Attr getAttributeNode( String attrName ) 216 { 217 return super.getAttributeNode( attrName.toLowerCase() ); 218 } 219 220 221 public Attr getAttributeNodeNS( String namespaceURI, 222 String localName ) 223 { 224 if ( namespaceURI != null && namespaceURI.length() > 0 ) 225 return super.getAttributeNodeNS( namespaceURI, localName ); 226 else 227 return super.getAttributeNode( localName.toLowerCase() ); 228 } 229 230 231 public String getAttribute( String attrName ) 232 { 233 return super.getAttribute( attrName.toLowerCase() ); 234 } 235 236 237 public String getAttributeNS( String namespaceURI, 238 String localName ) 239 { 240 if ( namespaceURI != null && namespaceURI.length() > 0 ) 241 return super.getAttributeNS( namespaceURI, localName ); 242 else 243 return super.getAttribute( localName.toLowerCase() ); 244 } 245 246 247 public final NodeList getElementsByTagName( String tagName ) 248 { 249 return super.getElementsByTagName( tagName.toUpperCase() ); 250 } 251 252 253 public final NodeList getElementsByTagNameNS( String namespaceURI, 254 String localName ) 255 { 256 if ( namespaceURI != null && namespaceURI.length() > 0 ) 257 return super.getElementsByTagNameNS( namespaceURI, localName.toUpperCase() ); 258 else 259 return super.getElementsByTagName( localName.toUpperCase() ); 260 } 261 262 263 271 String capitalize( String value ) 272 { 273 char[] chars; 274 int i; 275 276 chars = value.toCharArray(); 279 if ( chars.length > 0 ) 280 { 281 chars[ 0 ] = Character.toUpperCase( chars[ 0 ] ); 282 for ( i = 1 ; i < chars.length ; ++i ) 283 chars[ i ] = Character.toLowerCase( chars[ i ] ); 284 return String.valueOf( chars ); 285 } 286 return value; 287 } 288 289 290 298 String getCapitalized( String name ) 299 { 300 String value; 301 char[] chars; 302 int i; 303 304 value = getAttribute( name ); 305 if ( value != null ) 306 { 307 chars = value.toCharArray(); 310 if ( chars.length > 0 ) 311 { 312 chars[ 0 ] = Character.toUpperCase( chars[ 0 ] ); 313 for ( i = 1 ; i < chars.length ; ++i ) 314 chars[ i ] = Character.toLowerCase( chars[ i ] ); 315 return String.valueOf( chars ); 316 } 317 } 318 return value; 319 } 320 321 322 327 public HTMLFormElement getForm() 328 { 329 Node parent; 330 331 parent = getParentNode(); 332 while ( parent != null ) 333 { 334 if ( parent instanceof HTMLFormElement ) 335 return (HTMLFormElement) parent; 336 parent = parent.getParentNode(); 337 } 338 return null; 339 } 340 341 342 } 343 344 | Popular Tags |