2
* The Apache Software License, Version 1.1
5
* Copyright (c) 1999,2000 The Apache Software Foundation. All rights
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
15
* 2. Redistributions in binary form must reproduce the above copyright
16
* notice, this list of conditions and the following disclaimer in
17
* the documentation and/or other materials provided with the
20
* 3. The end-user documentation included with the redistribution,
21
* if any, must include the following acknowledgment:
22
* "This product includes software developed by the
23
* Apache Software Foundation (http://www.apache.org/)."
24
* Alternately, this acknowledgment may appear in the software itself,
25
* if and wherever such third-party acknowledgments normally appear.
27
* 4. The names "Xerces" and "Apache Software Foundation" must
28
* not be used to endorse or promote products derived from this
29
* software without prior written permission. For written
30
* permission, please contact apache@apache.org.
32
* 5. Products derived from this software may not be called "Apache",
33
* nor may "Apache" appear in their name, without prior written
34
* permission of the Apache Software Foundation.
36
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48
* ====================================================================
50
* This software consists of voluntary contributions made by many
51
* individuals on behalf of the Apache Software Foundation and was
52
* originally based on software copyright (c) 1999, International
53
* Business Machines, Inc., http://www.apache.org. For more
54
* information on the Apache Software Foundation, please see
55
* <http://www.apache.org/>.
57
package org.apache.html.dom;
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;
69
* @version $Revision: 1.6 $ $Date: 2003/05/08 20:13:09 $
70
* @author <a href="mailto:arkin@openxml.org">Assaf Arkin</a>
71
* @see org.w3c.dom.html.HTMLOptionElement
72
* @see org.apache.xerces.dom.ElementImpl
74
public class HTMLOptionElementImpl
75
extends HTMLElementImpl
76
implements HTMLOptionElement
81
public boolean getDefaultSelected()
83
// ! NOT FULLY IMPLEMENTED !
84
return getBinary( "default-selected" );
88
public void setDefaultSelected( boolean defaultSelected )
90
// ! NOT FULLY IMPLEMENTED !
91
setAttribute( "default-selected", defaultSelected );
95
public String getText()
100
// Find the Text nodes contained within this element and return their
101
// concatenated value. Required to go around comments, entities, etc.
102
child = getFirstChild();
104
while ( child != null )
106
if ( child instanceof Text )
107
text = text + ( (Text) child ).getData();
108
child = child.getNextSibling();
114
public void setText( String text )
119
// Delete all the nodes and replace them with a single Text node.
120
// This is the only approach that can handle comments and other nodes.
121
child = getFirstChild();
122
while ( child != null )
124
next = child.getNextSibling();
125
removeChild( child );
128
insertBefore( getOwnerDocument().createTextNode( text ), getFirstChild() );
132
public int getIndex()
138
// Locate the parent SELECT. Note that this OPTION might be inside a
139
// OPTGROUP inside the SELECT. Or it might not have a parent SELECT.
140
// Everything is possible. If no parent is found, return -1.
141
parent = getParentNode();
142
while ( parent != null && ! ( parent instanceof HTMLSelectElement ) )
143
parent = parent.getParentNode();
144
if ( parent != null )
146
// Use getElementsByTagName() which creates a snapshot of all the
147
// OPTION elements under the SELECT. Access to the returned NodeList
148
// is very fast and the snapshot solves many synchronization problems.
149
options = ( (HTMLElement) parent ).getElementsByTagName( "OPTION" );
150
for ( i = 0 ; i < options.getLength() ; ++i )
151
if ( options.item( i ) == this )
158
public void setIndex( int index )
164
// Locate the parent SELECT. Note that this OPTION might be inside a
165
// OPTGROUP inside the SELECT. Or it might not have a parent SELECT.
166
// Everything is possible. If no parent is found, just return.
167
parent = getParentNode();
168
while ( parent != null && ! ( parent instanceof HTMLSelectElement ) )
169
parent = parent.getParentNode();
170
if ( parent != null )
172
// Use getElementsByTagName() which creates a snapshot of all the
173
// OPTION elements under the SELECT. Access to the returned NodeList
174
// is very fast and the snapshot solves many synchronization problems.
175
// Make sure this OPTION is not replacing itself.
176
options = ( (HTMLElement) parent ).getElementsByTagName( "OPTION" );
177
if ( options.item( index ) != this )
179
// Remove this OPTION from its parent. Place this OPTION right
180
// before indexed OPTION underneath it's direct parent (might
182
getParentNode().removeChild( this );
183
item = options.item( index );
184
item.getParentNode().insertBefore( this, item );
190
public boolean getDisabled()
192
return getBinary( "disabled" );
196
public void setDisabled( boolean disabled )
198
setAttribute( "disabled", disabled );
202
public String getLabel()
204
return capitalize( getAttribute( "label" ) );
208
public void setLabel( String label )
210
setAttribute( "label", label );
214
public boolean getSelected()
216
return getBinary( "selected" );
220
public void setSelected( boolean selected )
222
setAttribute( "selected", selected );
226
public String getValue()
228
return getAttribute( "value" );
232
public void setValue( String value )
234
setAttribute( "value", value );
239
* Constructor requires owner document.
241
* @param owner The owner HTML document
243
public HTMLOptionElementImpl( HTMLDocumentImpl owner, String name )
245
super( owner, name );