1 57 package org.enhydra.apache.html.dom; 58 59 60 import org.enhydra.apache.xerces.dom.ElementImpl; 61 import org.w3c.dom.Node ; 62 import org.w3c.dom.NodeList ; 63 import org.w3c.dom.Text ; 64 import org.w3c.dom.html.HTMLElement; 65 import org.w3c.dom.html.HTMLOptionElement; 66 import org.w3c.dom.html.HTMLSelectElement; 67 68 69 75 public class HTMLOptionElementImpl 76 extends HTMLElementImpl 77 implements HTMLOptionElement 78 { 79 public boolean getDefaultSelected() 80 { 81 return getBinary( "selected" ); 82 } 83 84 85 public void setDefaultSelected( boolean defaultSelected ) 86 { 87 setAttribute( "selected", defaultSelected ); 88 } 89 90 91 public String getText() 92 { 93 Node child; 94 String text; 95 96 child = getFirstChild(); 99 text = ""; 100 while ( child != null ) 101 { 102 if ( child instanceof Text ) 103 text = text + ( (Text ) child ).getData(); 104 child = child.getNextSibling(); 105 } 106 return text; 107 } 108 109 110 public void setText( String text ) 111 { 112 Node child; 113 Node next; 114 115 child = getFirstChild(); 118 while ( child != null ) 119 { 120 next = child.getNextSibling(); 121 removeChild( child ); 122 child = next; 123 } 124 insertBefore( getOwnerDocument().createTextNode( text ), getFirstChild() ); 125 } 126 127 128 public int getIndex() 129 { 130 Node parent; 131 NodeList options; 132 int i; 133 134 parent = getParentNode(); 138 while ( parent != null && ! ( parent instanceof HTMLSelectElement ) ) 139 parent = parent.getParentNode(); 140 if ( parent != null ) 141 { 142 options = ( (HTMLElement) parent ).getElementsByTagName( "OPTION" ); 146 for ( i = 0 ; i < options.getLength() ; ++i ) 147 if ( options.item( i ) == this ) 148 return i; 149 } 150 return -1; 151 } 152 153 154 public void setIndex( int index ) 155 { 156 Node parent; 157 NodeList options; 158 Node item; 159 160 parent = getParentNode(); 164 while ( parent != null && ! ( parent instanceof HTMLSelectElement ) ) 165 parent = parent.getParentNode(); 166 if ( parent != null ) 167 { 168 options = ( (HTMLElement) parent ).getElementsByTagName( "OPTION" ); 173 if ( options.item( index ) != this ) 174 { 175 getParentNode().removeChild( this ); 179 item = options.item( index ); 180 item.getParentNode().insertBefore( this, item ); 181 } 182 } 183 } 184 185 186 public boolean getDisabled() 187 { 188 return getBinary( "disabled" ); 189 } 190 191 192 public void setDisabled( boolean disabled ) 193 { 194 setAttribute( "disabled", disabled ); 195 } 196 197 198 public String getLabel() 199 { 200 return capitalize( getAttribute( "label" ) ); 201 } 202 203 204 public void setLabel( String label ) 205 { 206 setAttribute( "label", label ); 207 } 208 209 210 public boolean getSelected() 211 { 212 return getBinary( "selected" ); 213 } 214 215 216 public void setSelected( boolean selected ) 217 { 218 setAttribute( "selected", selected ); 219 } 220 221 222 public String getValue() 223 { 224 return getAttribute( "value" ); 225 } 226 227 228 public void setValue( String value ) 229 { 230 setAttribute( "value", value ); 231 } 232 233 234 239 public HTMLOptionElementImpl( HTMLDocumentImpl owner, String name ) 240 { 241 super( owner, name ); 242 } 243 244 245 } 246 247 | Popular Tags |