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