1 16 package org.apache.html.dom; 17 18 import java.util.Locale ; 19 20 import org.apache.xerces.dom.ElementImpl; 21 import org.w3c.dom.Attr ; 22 import org.w3c.dom.Node ; 23 import org.w3c.dom.NodeList ; 24 import org.w3c.dom.html.HTMLElement; 25 import org.w3c.dom.html.HTMLFormElement; 26 27 42 public class HTMLElementImpl 43 extends ElementImpl 44 implements HTMLElement 45 { 46 47 private static final long serialVersionUID = 3833188025499792690L; 48 49 57 HTMLElementImpl( HTMLDocumentImpl owner, String tagName ) 58 { 59 super( owner, tagName.toUpperCase(Locale.ENGLISH) ); 60 } 61 62 63 public String getId() 64 { 65 return getAttribute( "id" ); 66 } 67 68 69 public void setId( String id ) 70 { 71 setAttribute( "id", id ); 72 } 73 74 75 public String getTitle() 76 { 77 return getAttribute( "title" ); 78 } 79 80 81 public void setTitle( String title ) 82 { 83 setAttribute( "title", title ); 84 } 85 86 87 public String getLang() 88 { 89 return getAttribute( "lang" ); 90 } 91 92 93 public void setLang( String lang ) 94 { 95 setAttribute( "lang", lang ); 96 } 97 98 99 public String getDir() 100 { 101 return getAttribute( "dir" ); 102 } 103 104 105 public void setDir( String dir ) 106 { 107 setAttribute( "dir", dir ); 108 } 109 110 111 public String getClassName() 112 { 113 return getAttribute( "class" ); 114 } 115 116 117 public void setClassName( String className ) 118 { 119 setAttribute( "class", className ); 120 } 121 122 123 131 int getInteger( String value ) 132 { 133 try 134 { 135 return Integer.parseInt( value ); 136 } 137 catch ( NumberFormatException except ) 138 { 139 return 0; 140 } 141 } 142 143 144 153 boolean getBinary( String name ) 154 { 155 return ( getAttributeNode( name ) != null ); 156 } 157 158 159 167 void setAttribute( String name, boolean value ) 168 { 169 if ( value ) 170 setAttribute( name, name ); 171 else 172 removeAttribute( name ); 173 } 174 175 176 public Attr getAttributeNode( String attrName ) 177 { 178 return super.getAttributeNode( attrName.toLowerCase(Locale.ENGLISH) ); 179 } 180 181 182 public Attr getAttributeNodeNS( String namespaceURI, 183 String localName ) 184 { 185 if ( namespaceURI != null && namespaceURI.length() > 0 ) 186 return super.getAttributeNodeNS( namespaceURI, localName ); 187 else 188 return super.getAttributeNode( localName.toLowerCase(Locale.ENGLISH) ); 189 } 190 191 192 public String getAttribute( String attrName ) 193 { 194 return super.getAttribute( attrName.toLowerCase(Locale.ENGLISH) ); 195 } 196 197 198 public String getAttributeNS( String namespaceURI, 199 String localName ) 200 { 201 if ( namespaceURI != null && namespaceURI.length() > 0 ) 202 return super.getAttributeNS( namespaceURI, localName ); 203 else 204 return super.getAttribute( localName.toLowerCase(Locale.ENGLISH) ); 205 } 206 207 208 public final NodeList getElementsByTagName( String tagName ) 209 { 210 return super.getElementsByTagName( tagName.toUpperCase(Locale.ENGLISH) ); 211 } 212 213 214 public final NodeList getElementsByTagNameNS( String namespaceURI, 215 String localName ) 216 { 217 if ( namespaceURI != null && namespaceURI.length() > 0 ) 218 return super.getElementsByTagNameNS( namespaceURI, localName.toUpperCase(Locale.ENGLISH) ); 219 else 220 return super.getElementsByTagName( localName.toUpperCase(Locale.ENGLISH) ); 221 } 222 223 224 232 String capitalize( String value ) 233 { 234 char[] chars; 235 int i; 236 237 chars = value.toCharArray(); 240 if ( chars.length > 0 ) 241 { 242 chars[ 0 ] = Character.toUpperCase( chars[ 0 ] ); 243 for ( i = 1 ; i < chars.length ; ++i ) 244 chars[ i ] = Character.toLowerCase( chars[ i ] ); 245 return String.valueOf( chars ); 246 } 247 return value; 248 } 249 250 251 259 String getCapitalized( String name ) 260 { 261 String value; 262 char[] chars; 263 int i; 264 265 value = getAttribute( name ); 266 if ( value != null ) 267 { 268 chars = value.toCharArray(); 271 if ( chars.length > 0 ) 272 { 273 chars[ 0 ] = Character.toUpperCase( chars[ 0 ] ); 274 for ( i = 1 ; i < chars.length ; ++i ) 275 chars[ i ] = Character.toLowerCase( chars[ i ] ); 276 return String.valueOf( chars ); 277 } 278 } 279 return value; 280 } 281 282 283 288 public HTMLFormElement getForm() 289 { 290 Node parent; 291 292 parent = getParentNode(); 293 while ( parent != null ) 294 { 295 if ( parent instanceof HTMLFormElement ) 296 return (HTMLFormElement) parent; 297 parent = parent.getParentNode(); 298 } 299 return null; 300 } 301 302 303 } 304 305 | Popular Tags |