1 20 21 22 package org.ozoneDB.xml.dom.html; 23 24 25 import org.ozoneDB.xml.dom.ElementImpl; 26 import org.w3c.dom.Node ; 27 import org.w3c.dom.NodeList ; 28 import org.w3c.dom.Text ; 29 import org.w3c.dom.html.HTMLElement; 30 import org.w3c.dom.html.HTMLOptionElement; 31 import org.w3c.dom.html.HTMLSelectElement; 32 33 34 40 public final class HTMLOptionElementImpl extends HTMLElementImpl implements HTMLOptionElement { 41 42 43 public boolean getDefaultSelected() { 44 return getAttribute( "default-selected" ) != null; 46 } 47 48 49 public void setDefaultSelected( boolean defaultSelected ) { 50 setAttribute( "default-selected", defaultSelected ? "" : null ); 52 } 53 54 55 public String getText() { 56 Node child; 57 String text; 58 59 child = getFirstChild(); 62 text = ""; 63 while (child != null) { 64 if (child instanceof Text ) { 65 text = text + ((Text )child).getData(); 66 } 67 child = child.getNextSibling(); 68 } 69 return text; 70 } 71 72 73 public void setText( String text ) { 74 Node child; 75 Node next; 76 77 child = getFirstChild(); 80 while (child != null) { 81 next = child.getNextSibling(); 82 removeChild( child ); 83 child = next; 84 } 85 insertBefore( getOwnerDocument().createTextNode( text ), getFirstChild() ); 86 } 87 88 89 public int getIndex() { 90 Node parent; 91 NodeList options; 92 int i; 93 94 parent = getParentNode(); 98 while (parent != null && !(parent instanceof HTMLSelectElement)) { 99 parent = parent.getParentNode(); 100 } 101 if (parent != null) { 102 options = ((HTMLElement)parent).getElementsByTagName( "OPTION" ); 106 for (i = 0; i < options.getLength(); ++i) { 107 if (options.item( i ) == this) { 108 return i; 109 } 110 } 111 } 112 return -1; 113 } 114 115 116 public void setIndex( int index ) { 117 Node parent; 118 NodeList options; 119 Node item; 120 121 parent = getParentNode(); 125 while (parent != null && !(parent instanceof HTMLSelectElement)) { 126 parent = parent.getParentNode(); 127 } 128 if (parent != null) { 129 options = ((HTMLElement)parent).getElementsByTagName( "OPTION" ); 134 if (options.item( index ) != this) { 135 getParentNode().removeChild( this ); 139 item = options.item( index ); 140 item.getParentNode().insertBefore( this, item ); 141 } 142 } 143 } 144 145 146 public boolean getDisabled() { 147 return getAttribute( "disabled" ) != null; 148 } 149 150 151 public void setDisabled( boolean disabled ) { 152 setAttribute( "disabled", disabled ? "" : null ); 153 } 154 155 156 public String getLabel() { 157 return capitalize( getAttribute( "label" ) ); 158 } 159 160 161 public void setLabel( String label ) { 162 setAttribute( "label", label ); 163 } 164 165 166 public boolean getSelected() { 167 return getAttribute( "selected" ) != null; 168 } 169 170 171 public void setSelected( boolean selected ) { 172 setAttribute( "selected", selected ? "" : null ); 173 } 174 175 176 public String getValue() { 177 return getAttribute( "value" ); 178 } 179 180 181 public void setValue( String value ) { 182 setAttribute( "value", value ); 183 } 184 185 186 191 public HTMLOptionElementImpl( HTMLDocumentImpl owner, String name ) { 192 super( owner, "OPTION" ); 193 } 194 195 196 } 197 | Popular Tags |