1 20 21 22 package org.ozoneDB.xml.dom.html; 23 24 25 import org.ozoneDB.xml.dom.DOMExceptionImpl; 26 import org.ozoneDB.xml.dom.ElementImpl; 27 import org.ozoneDB.xml.dom.NodeImpl; 28 import org.w3c.dom.*; 29 import org.w3c.dom.html.HTMLElement; 30 import org.w3c.dom.html.HTMLFormElement; 31 32 33 52 public class HTMLElementImpl extends ElementImpl implements HTMLElement { 53 54 55 public String getId() { 56 return getAttribute( "id" ); 57 } 58 59 60 public void setId( String id ) { 61 setAttribute( "id", id ); 62 } 63 64 65 public String getTitle() { 66 return getAttribute( "title" ); 67 } 68 69 70 public void setTitle( String title ) { 71 setAttribute( "title", title ); 72 } 73 74 75 public String getLang() { 76 return getAttribute( "lang" ); 77 } 78 79 80 public void setLang( String lang ) { 81 setAttribute( "lang", lang ); 82 } 83 84 85 public String getDir() { 86 return getAttribute( "dir" ); 87 } 88 89 90 public void setDir( String dir ) { 91 setAttribute( "dir", dir ); 92 } 93 94 95 public String getClassName() { 96 return getAttribute( "class" ); 97 } 98 99 100 public void setClassName( String className ) { 101 setAttribute( "class", className ); 102 } 103 104 105 113 int toInteger( String value ) { 114 try { 115 return Integer.parseInt( value ); 116 } catch (NumberFormatException except) { 117 return 0; 118 } 119 } 120 121 122 131 boolean toBoolean( String name ) { 132 return getAttribute( name ) != null; 133 } 134 135 136 144 void setAttribute( String name, boolean value ) { 145 if (value) { 146 setAttribute( name, "" ); 147 } else { 148 removeAttribute( name ); 149 } 150 } 151 152 153 161 String capitalize( String value ) { 162 char[] chars; 163 int i; 164 165 chars = value.toCharArray(); 168 if (chars.length > 0) { 169 chars[0] = Character.toUpperCase( chars[0] ); 170 for (i = 1; i < chars.length; ++i) { 171 chars[i] = Character.toLowerCase( chars[i] ); 172 } 173 return String.valueOf( chars ); 174 } 175 return value; 176 } 177 178 179 187 String getCapitalized( String name ) { 188 String value; 189 char[] chars; 190 int i; 191 192 value = getAttribute( name ); 193 if (value != null) { 194 chars = value.toCharArray(); 197 if (chars.length > 0) { 198 chars[0] = Character.toUpperCase( chars[0] ); 199 for (i = 1; i < chars.length; ++i) { 200 chars[i] = Character.toLowerCase( chars[i] ); 201 } 202 return String.valueOf( chars ); 203 } 204 } 205 return value; 206 } 207 208 209 214 public HTMLFormElement getForm() { 215 Node parent; 216 217 parent = getParentNode(); 218 while (parent != null) { 219 if (parent instanceof HTMLFormElement) { 220 return (HTMLFormElement)parent; 221 } 222 parent = parent.getParentNode(); 223 } 224 return null; 225 } 226 227 228 protected Node castNewChild( Node newChild ) throws DOMException { 229 231 if (newChild == null) { 232 throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR, "Child reference is null." ); 233 } 234 if (!(newChild instanceof NodeImpl)) { 235 throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR, 236 "Child is not a compatible type for this node." ); 237 } 238 239 if (!(newChild instanceof ElementImpl || newChild instanceof Comment || newChild instanceof Text 243 || newChild instanceof DocumentFragment || newChild instanceof ProcessingInstruction)) { 244 throw new DOMExceptionImpl( DOMException.HIERARCHY_REQUEST_ERR, 245 "Child is not a compatible type for this node." ); 246 } 247 return (NodeImpl)newChild; 248 } 249 250 251 259 HTMLElementImpl( HTMLDocumentImpl owner, String tagName ) { 260 super( owner, tagName.toUpperCase() ); 261 } 262 263 264 } 265 | Popular Tags |