1 57 package org.enhydra.xml.xhtml.dom.xerces; 58 59 import org.enhydra.apache.xerces.dom.ElementNSImpl; 60 import org.w3c.dom.Attr ; 61 import org.w3c.dom.Node ; 62 import org.w3c.dom.NodeList ; 63 import org.w3c.dom.html.HTMLElement; 64 import org.w3c.dom.html.HTMLFormElement; 65 66 70 71 82 public class XHTMLElementImpl 83 extends ElementNSImpl 84 implements HTMLElement 85 { 86 87 95 XHTMLElementImpl( XHTMLDocumentBase owner, String namespaceURI, String tagName ) 96 { 97 super( owner, namespaceURI, tagName ); 98 } 99 100 101 public String getId() 102 { 103 return getAttribute( "id" ); 104 } 105 106 107 public void setId( String id ) 108 { 109 setAttribute( "id", id ); 110 } 111 112 113 public String getTitle() 114 { 115 return getAttribute( "title" ); 116 } 117 118 119 public void setTitle( String title ) 120 { 121 setAttribute( "title", title ); 122 } 123 124 125 public String getLang() 126 { 127 return getAttribute( "lang" ); 128 } 129 130 131 public void setLang( String lang ) 132 { 133 setAttribute( "lang", lang ); 134 } 135 136 137 public String getDir() 138 { 139 return getAttribute( "dir" ); 140 } 141 142 143 public void setDir( String dir ) 144 { 145 setAttribute( "dir", dir ); 146 } 147 148 149 public String getClassName() 150 { 151 return getAttribute( "class" ); 152 } 153 154 155 public void setClassName( String className ) 156 { 157 setAttribute( "class", className ); 158 } 159 160 public Attr getAttributeNode( String attrName ) 161 { 162 return super.getAttributeNode( attrName.toLowerCase() ); 163 } 164 165 166 public Attr getAttributeNodeNS( String namespaceURI, 167 String localName ) 168 { 169 if ( namespaceURI != null && namespaceURI.length() > 0 ) 170 return super.getAttributeNodeNS( namespaceURI, localName ); 171 else 172 return super.getAttributeNode( localName.toLowerCase() ); 173 } 174 175 176 public String getAttribute( String attrName ) 177 { 178 return super.getAttribute( attrName.toLowerCase() ); 179 } 180 181 182 public String getAttributeNS( String namespaceURI, 183 String localName ) 184 { 185 if ( namespaceURI != null && namespaceURI.length() > 0 ) 186 return super.getAttributeNS( namespaceURI, localName ); 187 else 188 return super.getAttribute( localName.toLowerCase() ); 189 } 190 191 192 public final NodeList getElementsByTagName( String tagName ) 193 { 194 return super.getElementsByTagName( tagName.toUpperCase() ); 195 } 196 197 198 public final NodeList getElementsByTagNameNS( String namespaceURI, 199 String localName ) 200 { 201 if ( namespaceURI != null && namespaceURI.length() > 0 ) 202 return super.getElementsByTagNameNS( namespaceURI, localName.toUpperCase() ); 203 else 204 return super.getElementsByTagName( localName.toUpperCase() ); 205 } 206 207 208 216 String capitalize( String value ) 217 { 218 char[] chars; 219 int i; 220 221 chars = value.toCharArray(); 224 if ( chars.length > 0 ) 225 { 226 chars[ 0 ] = Character.toUpperCase( chars[ 0 ] ); 227 for ( i = 1 ; i < chars.length ; ++i ) 228 chars[ i ] = Character.toLowerCase( chars[ i ] ); 229 return String.valueOf( chars ); 230 } 231 return value; 232 } 233 234 235 243 String getCapitalized( String name ) 244 { 245 String value; 246 char[] chars; 247 int i; 248 249 value = getAttribute( name ); 250 if ( value != null ) 251 { 252 chars = value.toCharArray(); 255 if ( chars.length > 0 ) 256 { 257 chars[ 0 ] = Character.toUpperCase( chars[ 0 ] ); 258 for ( i = 1 ; i < chars.length ; ++i ) 259 chars[ i ] = Character.toLowerCase( chars[ i ] ); 260 return String.valueOf( chars ); 261 } 262 } 263 return value; 264 } 265 266 267 272 public HTMLFormElement getForm() 273 { 274 Node parent; 275 276 parent = getParentNode(); 277 while ( parent != null ) 278 { 279 if ( parent instanceof HTMLFormElement ) 280 return (HTMLFormElement) parent; 281 parent = parent.getParentNode(); 282 } 283 return null; 284 } 285 286 287 290 protected final boolean getBooleanAttribute(String attr, 291 boolean defaultValue) { 292 String attrVal = getAttribute(attr); 293 if (attrVal != null) { 294 return (attrVal.equalsIgnoreCase("y") 295 || attrVal.equalsIgnoreCase("yes") 296 || attrVal.equalsIgnoreCase("true")); 297 } else { 298 return defaultValue; 299 } 300 } 301 302 305 protected final boolean getBooleanAttribute(String attr) { 306 return getBooleanAttribute(attr, false); 307 } 308 309 312 protected final void setAttribute(String attr, 313 boolean value) { 314 if ( value ) 320 setAttribute( attr, attr ); 321 else 322 removeAttribute( attr ); 323 } 324 325 328 protected final int getIntAttribute(String attr, 329 int defaultValue) { 330 String attrVal = getAttribute(attr); 331 if (attrVal != null) { 332 return Integer.parseInt(attrVal); 333 } else { 334 return defaultValue; 335 } 336 } 337 338 341 protected final int getIntAttribute(String attr) { 342 return getIntAttribute(attr, 0); 343 } 344 345 348 protected final void setAttribute(String attr, 349 int value) { 350 setAttribute(attr, Integer.toString(value)); 351 } 352 } 353 354 | Popular Tags |