1 57 package org.enhydra.xml.lazydom.html; 58 import org.enhydra.xml.lazydom.LazyElement; 59 import org.enhydra.xml.lazydom.LazyElementNoNS; 60 import org.w3c.dom.Node ; 61 import org.w3c.dom.NodeList ; 62 import org.w3c.dom.Text ; 63 import org.w3c.dom.html.HTMLElement; 64 import org.w3c.dom.html.HTMLOptionElement; 65 import org.w3c.dom.html.HTMLSelectElement; 66 67 68 74 public class HTMLOptionElementImpl 75 extends LazyHTMLElement 76 implements HTMLOptionElement 77 { 78 79 80 81 public boolean getDefaultSelected() 82 { 83 return getBinary( "default-selected" ); 85 } 86 87 88 public void setDefaultSelected( boolean defaultSelected ) 89 { 90 setAttribute( "default-selected", defaultSelected ); 92 } 93 94 95 public String getText() 96 { 97 Node child; 98 String text; 99 100 child = getFirstChild(); 103 text = ""; 104 while ( child != null ) 105 { 106 if ( child instanceof Text ) 107 text = text + ( (Text ) child ).getData(); 108 child = child.getNextSibling(); 109 } 110 return text; 111 } 112 113 114 public void setText( String text ) 115 { 116 Node child; 117 Node next; 118 119 child = getFirstChild(); 122 while ( child != null ) 123 { 124 next = child.getNextSibling(); 125 removeChild( child ); 126 child = next; 127 } 128 insertBefore( getOwnerDocument().createTextNode( text ), getFirstChild() ); 129 } 130 131 132 public int getIndex() 133 { 134 Node parent; 135 NodeList options; 136 int i; 137 138 parent = getParentNode(); 142 while ( parent != null && ! ( parent instanceof HTMLSelectElement ) ) 143 parent = parent.getParentNode(); 144 if ( parent != null ) 145 { 146 options = ( (HTMLElement) parent ).getElementsByTagName( "OPTION" ); 150 for ( i = 0 ; i < options.getLength() ; ++i ) 151 if ( options.item( i ) == this ) 152 return i; 153 } 154 return -1; 155 } 156 157 158 public void setIndex( int index ) 159 { 160 Node parent; 161 NodeList options; 162 Node item; 163 164 parent = getParentNode(); 168 while ( parent != null && ! ( parent instanceof HTMLSelectElement ) ) 169 parent = parent.getParentNode(); 170 if ( parent != null ) 171 { 172 options = ( (HTMLElement) parent ).getElementsByTagName( "OPTION" ); 177 if ( options.item( index ) != this ) 178 { 179 getParentNode().removeChild( this ); 183 item = options.item( index ); 184 item.getParentNode().insertBefore( this, item ); 185 } 186 } 187 } 188 189 190 public boolean getDisabled() 191 { 192 return getBinary( "disabled" ); 193 } 194 195 196 public void setDisabled( boolean disabled ) 197 { 198 setAttribute( "disabled", disabled ); 199 } 200 201 202 public String getLabel() 203 { 204 return capitalize( getAttribute( "label" ) ); 205 } 206 207 208 public void setLabel( String label ) 209 { 210 setAttribute( "label", label ); 211 } 212 213 214 public boolean getSelected() 215 { 216 return getBinary( "selected" ); 217 } 218 219 220 public void setSelected( boolean selected ) 221 { 222 setAttribute( "selected", selected ); 223 } 224 225 226 public String getValue() 227 { 228 return getAttribute( "value" ); 229 } 230 231 232 public void setValue( String value ) 233 { 234 setAttribute( "value", value ); 235 } 236 237 238 243 public HTMLOptionElementImpl( LazyHTMLDocument owner, LazyElement template, String name ) 244 { 245 super( owner, template, name ); 246 } 247 248 249 } 250 251 | Popular Tags |