KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xhtml > dom > xerces > XHTMLOptionElementImpl


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Original Code is DigitalSesame
15  * Portions created by DigitalSesame are Copyright (C) 1997-2000 DigitalSesame
16  * All Rights Reserved.
17  *
18  * Contributor(s):
19  * Rex Tsai <chihchun@digitalsesame.com>
20  * David Li <david@digitalsesam.com>
21  *
22  * $Id: XHTMLOptionElementImpl.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
23  */

24
25 package org.enhydra.xml.xhtml.dom.xerces;
26
27 import org.w3c.dom.Node JavaDoc;
28 import org.w3c.dom.NodeList JavaDoc;
29 import org.w3c.dom.Text JavaDoc;
30 import org.w3c.dom.html.HTMLElement;
31 import org.w3c.dom.html.HTMLSelectElement;
32
33 public class XHTMLOptionElementImpl
34     extends XHTMLElementImpl
35     implements org.enhydra.xml.xhtml.dom.XHTMLOptionElement
36 {
37
38     public XHTMLOptionElementImpl (XHTMLDocumentBase owner, String JavaDoc namespaceURI, String JavaDoc tagName) {
39     super( owner, namespaceURI, tagName);
40     }
41
42         public void setId (String JavaDoc newValue) {
43     setAttribute("id", newValue);
44     }
45
46     public String JavaDoc getId () {
47     return getAttribute ("id");
48     }
49     public void setLang (String JavaDoc newValue) {
50     setAttribute("lang", newValue);
51     }
52
53     public String JavaDoc getLang () {
54     return getAttribute ("lang");
55     }
56     public void setDir (String JavaDoc newValue) {
57     setAttribute("dir", newValue);
58     }
59
60     public String JavaDoc getDir () {
61     return getAttribute ("dir");
62     }
63     public void setClassName (String JavaDoc newValue) {
64     setAttribute("class", newValue);
65     }
66
67     public String JavaDoc getClassName () {
68     return getAttribute ("class");
69     }
70     public void setTitle (String JavaDoc newValue) {
71     setAttribute("title", newValue);
72     }
73
74     public String JavaDoc getTitle () {
75     return getAttribute ("title");
76     }
77     public void setValue (String JavaDoc newValue) {
78     setAttribute("value", newValue);
79     }
80
81     public String JavaDoc getValue () {
82     return getAttribute ("value");
83     }
84     public void setDisabled (boolean newValue) {
85     setAttribute("disabled", newValue);
86     }
87
88     public boolean getDisabled () {
89     return getBooleanAttribute("disabled");
90     }
91     public void setLabel (String JavaDoc newValue) {
92     setAttribute("label", newValue);
93     }
94
95     public String JavaDoc getLabel () {
96     return getAttribute ("label");
97     }
98     public void setDefaultSelected (boolean newValue) {
99     setAttribute("defaultselected", newValue);
100     }
101
102     public boolean getDefaultSelected () {
103     return getBooleanAttribute("defaultselected");
104     }
105     public void setSelected (boolean newValue) {
106     setAttribute("selected", newValue);
107     }
108
109     public boolean getSelected () {
110     return getBooleanAttribute("selected");
111     }
112     public void setOnKeyUp (String JavaDoc newValue) {
113     setAttribute("onkeyup", newValue);
114     }
115
116     public String JavaDoc getOnKeyUp () {
117     return getAttribute ("onkeyup");
118     }
119     public void setStyle (String JavaDoc newValue) {
120     setAttribute("style", newValue);
121     }
122
123     public String JavaDoc getStyle () {
124     return getAttribute ("style");
125     }
126     public void setOnMouseDown (String JavaDoc newValue) {
127     setAttribute("onmousedown", newValue);
128     }
129
130     public String JavaDoc getOnMouseDown () {
131     return getAttribute ("onmousedown");
132     }
133     public void setOnKeyPress (String JavaDoc newValue) {
134     setAttribute("onkeypress", newValue);
135     }
136
137     public String JavaDoc getOnKeyPress () {
138     return getAttribute ("onkeypress");
139     }
140     public void setOnDblClick (String JavaDoc newValue) {
141     setAttribute("ondblclick", newValue);
142     }
143
144     public String JavaDoc getOnDblClick () {
145     return getAttribute ("ondblclick");
146     }
147     public void setOnKeyDown (String JavaDoc newValue) {
148     setAttribute("onkeydown", newValue);
149     }
150
151     public String JavaDoc getOnKeyDown () {
152     return getAttribute ("onkeydown");
153     }
154     public void setOnMouseMove (String JavaDoc newValue) {
155     setAttribute("onmousemove", newValue);
156     }
157
158     public String JavaDoc getOnMouseMove () {
159     return getAttribute ("onmousemove");
160     }
161     public void setOnMouseUp (String JavaDoc newValue) {
162     setAttribute("onmouseup", newValue);
163     }
164
165     public String JavaDoc getOnMouseUp () {
166     return getAttribute ("onmouseup");
167     }
168     public void setXmlLang (String JavaDoc newValue) {
169     setAttribute("xml:lang", newValue);
170     }
171
172     public String JavaDoc getXmlLang () {
173     return getAttribute ("xml:lang");
174     }
175     public void setOnMouseOut (String JavaDoc newValue) {
176     setAttribute("onmouseout", newValue);
177     }
178
179     public String JavaDoc getOnMouseOut () {
180     return getAttribute ("onmouseout");
181     }
182     public void setOnClick (String JavaDoc newValue) {
183     setAttribute("onclick", newValue);
184     }
185
186     public String JavaDoc getOnClick () {
187     return getAttribute ("onclick");
188     }
189     public void setOnMouseOver (String JavaDoc newValue) {
190     setAttribute("onmouseover", newValue);
191     }
192
193     public String JavaDoc getOnMouseOver () {
194     return getAttribute ("onmouseover");
195     }
196 ;
197
198     
199     public String JavaDoc getText() {
200         Node JavaDoc child;
201         String JavaDoc text;
202         
203         // Find the Text nodes contained within this element and return their
204
// concatenated value. Required to go around comments, entities, etc.
205
child = getFirstChild();
206         text = "";
207         while ( child != null )
208         {
209             if ( child instanceof Text JavaDoc )
210                 text = text + ( (Text JavaDoc) child ).getData();
211             child = child.getNextSibling();
212         }
213         return text;
214     }
215     
216     
217     public void setText( String JavaDoc text ) {
218         Node JavaDoc child;
219         Node JavaDoc next;
220         
221         // Delete all the nodes and replace them with a single Text node.
222
// This is the only approach that can handle comments and other nodes.
223
child = getFirstChild();
224         while ( child != null )
225         {
226             next = child.getNextSibling();
227             removeChild( child );
228             child = next;
229         }
230         insertBefore( getOwnerDocument().createTextNode( text ), getFirstChild() );
231     }
232     
233     
234     public int getIndex() {
235         Node JavaDoc parent;
236         NodeList JavaDoc options;
237         int i;
238         
239         // Locate the parent SELECT. Note that this OPTION might be inside a
240
// OPTGROUP inside the SELECT. Or it might not have a parent SELECT.
241
// Everything is possible. If no parent is found, return -1.
242
parent = getParentNode();
243         while ( parent != null && ! ( parent instanceof HTMLSelectElement ) )
244             parent = parent.getParentNode();
245         if ( parent != null )
246         {
247             // Use getElementsByTagName() which creates a snapshot of all the
248
// OPTION elements under the SELECT. Access to the returned NodeList
249
// is very fast and the snapshot solves many synchronization problems.
250
options = ( (HTMLElement) parent ).getElementsByTagName( "option" );
251             for ( i = 0 ; i < options.getLength() ; ++i )
252                 if ( options.item( i ) == this )
253                     return i;
254         }
255         return -1;
256     }
257     
258     
259     public void setIndex( int index ) {
260         Node JavaDoc parent;
261         NodeList JavaDoc options;
262         Node JavaDoc item;
263         
264         // Locate the parent SELECT. Note that this OPTION might be inside a
265
// OPTGROUP inside the SELECT. Or it might not have a parent SELECT.
266
// Everything is possible. If no parent is found, just return.
267
parent = getParentNode();
268         while ( parent != null && ! ( parent instanceof HTMLSelectElement ) )
269             parent = parent.getParentNode();
270         if ( parent != null ) {
271             // Use getElementsByTagName() which creates a snapshot of all the
272
// OPTION elements under the SELECT. Access to the returned NodeList
273
// is very fast and the snapshot solves many synchronization problems.
274
// Make sure this OPTION is not replacing itself.
275
options = ( (HTMLElement) parent ).getElementsByTagName( "option" );
276             if ( options.item( index ) != this ) {
277                 // Remove this OPTION from its parent. Place this OPTION right
278
// before indexed OPTION underneath it's direct parent (might
279
// be an OPTGROUP).
280
getParentNode().removeChild( this );
281                 item = options.item( index );
282                 item.getParentNode().insertBefore( this, item );
283             }
284         }
285     }
286
287
288 ;
289 }
290
291
292
Popular Tags