1 23 package org.enhydra.xml.lazydom.html; 24 25 26 import org.enhydra.xml.lazydom.LazyElement; 27 import org.enhydra.xml.lazydom.LazyElementNoNS; 28 import org.w3c.dom.Attr ; 29 import org.w3c.dom.Node ; 30 import org.w3c.dom.NodeList ; 31 import org.w3c.dom.html.HTMLElement; 32 import org.w3c.dom.html.HTMLFormElement; 33 34 41 42 56 public class LazyHTMLElement 57 extends LazyElementNoNS 58 implements HTMLElement 59 { 60 61 62 72 LazyHTMLElement( LazyHTMLDocument owner, LazyElement template, String tagName ) 73 { 74 super( owner, template, tagName ); 76 } 77 78 79 public String getId() 80 { 81 return getAttribute( "id" ); 82 } 83 84 85 public void setId( String id ) 86 { 87 setAttribute( "id", id ); 88 } 89 90 91 public String getTitle() 92 { 93 return getAttribute( "title" ); 94 } 95 96 97 public void setTitle( String title ) 98 { 99 setAttribute( "title", title ); 100 } 101 102 103 public String getLang() 104 { 105 return getAttribute( "lang" ); 106 } 107 108 109 public void setLang( String lang ) 110 { 111 setAttribute( "lang", lang ); 112 } 113 114 115 public String getDir() 116 { 117 return getAttribute( "dir" ); 118 } 119 120 121 public void setDir( String dir ) 122 { 123 setAttribute( "dir", dir ); 124 } 125 126 127 public String getClassName() 128 { 129 return getAttribute( "class" ); 130 } 131 132 133 public void setClassName( String className ) 134 { 135 setAttribute( "class", className ); 136 } 137 138 139 147 int getInteger( String value ) 148 { 149 try 150 { 151 return Integer.parseInt( value ); 152 } 153 catch ( NumberFormatException except ) 154 { 155 return 0; 156 } 157 } 158 159 160 169 boolean getBinary( String name ) 170 { 171 return ( getAttributeNode( name ) != null ); 172 } 173 174 175 183 void setAttribute( String name, boolean value ) 184 { 185 if ( value ) 186 setAttribute( name, name ); 187 else 188 removeAttribute( name ); 189 } 190 191 192 public Attr getAttributeNode( String attrName ) 193 { 194 return super.getAttributeNode( attrName.toLowerCase() ); 195 } 196 197 198 public Attr getAttributeNodeNS( String namespaceURI, 199 String localName ) 200 { 201 if ( namespaceURI != null && namespaceURI.length() > 0 ) 202 return super.getAttributeNodeNS( namespaceURI, localName ); 203 else 204 return super.getAttributeNode( localName.toLowerCase() ); 205 } 206 207 208 public String getAttribute( String attrName ) 209 { 210 return super.getAttribute( attrName.toLowerCase() ); 211 } 212 213 214 public String getAttributeNS( String namespaceURI, 215 String localName ) 216 { 217 if ( namespaceURI != null && namespaceURI.length() > 0 ) 218 return super.getAttributeNS( namespaceURI, localName ); 219 else 220 return super.getAttribute( localName.toLowerCase() ); 221 } 222 223 224 public final NodeList getElementsByTagName( String tagName ) 225 { 226 return super.getElementsByTagName( tagName.toUpperCase() ); 227 } 228 229 230 public final NodeList getElementsByTagNameNS( String namespaceURI, 231 String localName ) 232 { 233 if ( namespaceURI != null && namespaceURI.length() > 0 ) 234 return super.getElementsByTagNameNS( namespaceURI, localName.toUpperCase() ); 235 else 236 return super.getElementsByTagName( localName.toUpperCase() ); 237 } 238 239 240 248 String capitalize( String value ) 249 { 250 char[] chars; 251 int i; 252 253 chars = value.toCharArray(); 256 if ( chars.length > 0 ) 257 { 258 chars[ 0 ] = Character.toUpperCase( chars[ 0 ] ); 259 for ( i = 1 ; i < chars.length ; ++i ) 260 chars[ i ] = Character.toLowerCase( chars[ i ] ); 261 return String.valueOf( chars ); 262 } 263 return value; 264 } 265 266 267 275 String getCapitalized( String name ) 276 { 277 String value; 278 char[] chars; 279 int i; 280 281 value = getAttribute( name ); 282 if ( value != null ) 283 { 284 chars = value.toCharArray(); 287 if ( chars.length > 0 ) 288 { 289 chars[ 0 ] = Character.toUpperCase( chars[ 0 ] ); 290 for ( i = 1 ; i < chars.length ; ++i ) 291 chars[ i ] = Character.toLowerCase( chars[ i ] ); 292 return String.valueOf( chars ); 293 } 294 } 295 return value; 296 } 297 298 299 304 public HTMLFormElement getForm() 305 { 306 Node parent; 307 308 parent = getParentNode(); 309 while ( parent != null ) 310 { 311 if ( parent instanceof HTMLFormElement ) 312 return (HTMLFormElement) parent; 313 parent = parent.getParentNode(); 314 } 315 return null; 316 } 317 318 319 } 320 321 | Popular Tags |