KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > html > A


1 /*
2  * ====================================================================
3  *
4  * The Apache Software License, Version 1.1
5  *
6  * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if
22  * any, must include the following acknowlegement:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "The Jakarta Project", "Jakarta Element Construction Set",
29  * "Jakarta ECS" , and "Apache Software Foundation" must not be used
30  * to endorse or promote products derived
31  * from this software without prior written permission. For written
32  * permission, please contact apache@apache.org.
33  *
34  * 5. Products derived from this software may not be called "Apache",
35  * "Jakarta Element Construction Set" nor "Jakarta ECS" nor may "Apache"
36  * appear in their names without prior written permission of the Apache Group.
37  *
38  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
42  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49  * SUCH DAMAGE.
50  * ====================================================================
51  *
52  * This software consists of voluntary contributions made by many
53  * individuals on behalf of the Apache Software Foundation. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  *
57  */

58 package org.apache.ecs.html;
59
60 import org.apache.ecs.*;
61 /**
62     This class creates a &lt;A&gt; tag.
63     <P>
64     Please refer to the TestBed.java file for example code usage.
65
66     @version $Id: A.java,v 1.6 2003/04/27 09:21:59 rdonkin Exp $
67     @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
68     @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
69 */

70 public class A extends MultiPartElement implements Printable, FocusEvents, MouseEvents, KeyEvents
71 {
72     /**
73           Private initialization routine.
74      */

75     {
76         setElementType("a");
77     }
78
79     /**
80         Basic constructor. You need to set the attributes using the
81         set* methods.
82     */

83     public A()
84     {
85     }
86
87     /**
88         This constructor creates a &lt;A&gt; tag.
89
90         @param href the URI that goes between double quotes
91     */

92     public A(String href)
93     {
94         setHref(href);
95     }
96
97     /**
98         This constructor creates a &lt;A&gt; tag.
99         
100         @param href the URI that goes between double quotes
101         @param value what goes between &lt;start_tag&gt; &lt;end_tag&gt;
102     */

103     public A(String href, String value)
104     {
105         setHref(href);
106         addElement(value);
107     }
108
109     /**
110         This constructor creates a &lt;A&gt; tag.
111
112         @param href the URI that goes between double quotes
113         @param value what goes between &lt;start_tag&gt; &lt;end_tag&gt;
114     */

115     public A(String href, Element value)
116     {
117         setHref(href);
118         addElement(value);
119     }
120
121     /**
122         This constructor creates a &lt;A&gt; tag.
123
124         @param href the URI that goes between double quotes
125         @param name the NAME="" attribute
126         @param value what goes between &lt;start_tag&gt; &lt;end_tag&gt;
127     */

128     public A(String href, String name, String value)
129     {
130         setHref(href);
131         setName(name);
132         addElement(value);
133     }
134
135     /**
136         This constructor creates a &lt;A&gt; tag.
137
138         @param href the URI that goes between double quotes
139         @param name the NAME="" attribute
140         @param value what goes between &lt;start_tag&gt; &lt;end_tag&gt;
141     */

142     public A(String href, String name, Element value)
143     {
144         setHref(href);
145         setName(name);
146         addElement(value);
147     }
148
149     /**
150         This constructor creates a &lt;A&gt; tag.
151
152         @param href the URI that goes between double quotes
153         @param name the NAME="" attribute
154         @param target the TARGET="" attribute
155         @param value the value that goes between &lt;start_tag&gt; &lt;end_tag&gt;
156     */

157     public A(String href, String name, String target, Element value)
158     {
159         setHref(href);
160         setName(name);
161         setTarget(target);
162         addElement(value);
163     }
164
165     /**
166         This constructor creates a &lt;A&gt; tag.
167
168         @param href the URI that goes between double quotes
169         @param name the NAME="" attribute
170         @param target the TARGET="" attribute
171         @param value the value that goes between &lt;start_tag&gt; &lt;end_tag&gt;
172     */

173     public A(String href, String name, String target, String value)
174     {
175         setHref(href);
176         setName(name);
177         setTarget(target);
178         addElement(value);
179     }
180
181     /**
182         This constructor creates a &lt;A&gt; tag.
183
184         @param href the URI that goes between double quotes
185         @param name the NAME="" attribute
186         @param target the TARGET="" attribute
187         @param lang the LANG="" attribute
188         @param value the value that goes between &lt;start_tag&gt; &lt;end_tag&gt;
189     */

190     public A(String href, String name, String target, String lang,
191             String value)
192     {
193         setHref(href);
194         setName(name);
195         setTarget(target);
196         setLang(lang);
197         addElement(value);
198     }
199
200     /**
201         This constructor creates a &lt;A&gt; tag.
202
203         @param href the URI that goes between double quotes
204         @param name the NAME="" attribute
205         @param target the TARGET="" attribute
206         @param lang the LANG="" attribute
207         @param value the value that goes between &lt;start_tag&gt; &lt;end_tag&gt;
208     */

209     public A(String href, String name, String target, String lang,
210             Element value)
211     {
212         setHref(href);
213         setName(name);
214         setTarget(target);
215         setLang(lang);
216         addElement(value);
217     }
218
219     /**
220         Sets the FOLDER="" attribute
221         @param folder the FOLDER="" attribute
222     */

223     public A setFolder(String folder)
224     {
225         addAttribute("folder",folder);
226         return this;
227     }
228
229     /**
230         Sets the HREF="" attribute
231         @param href the HREF="" attribute
232     */

233     public A setHref(String href)
234     {
235         addAttribute("href",href);
236         return this;
237     }
238
239     /**
240         Sets the NAME="" attribute
241         @param name the NAME="" attribute
242     */

243     public A setName(String name)
244     {
245         addAttribute("name",name);
246         return this;
247     }
248
249     /**
250         Sets the TARGET="" attribute
251         @param target the TARGET="" attribute
252     */

253     public A setTarget(String target)
254     {
255         addAttribute("target",target);
256         return this;
257     }
258
259     /**
260         Sets the REL="" attribute
261         @param rel the REL="" attribute
262     */

263     public A setRel(String rel)
264     {
265         addAttribute("rel",rel);
266         return this;
267     }
268
269     /**
270         Sets the REV="" attribute
271         @param rev the REV="" attribute
272     */

273     public A setRev(String rev)
274     {
275         addAttribute("rev",rev);
276         return this;
277     }
278
279     /**
280         Adds an Element to the element.
281         @param element Adds an Element to the element.
282      */

283     public A addElement(Element element)
284     {
285         addElementToRegistry(element);
286         return(this);
287     }
288
289     /**
290         Adds an Element to the element.
291         @param element Adds an Element to the element.
292      */

293     public A addElement(String element)
294     {
295         addElementToRegistry(element);
296         return(this);
297     }
298
299     /**
300         Adds an Element to the element.
301         @param hashcode name of element for hash table
302         @param element Adds an Element to the element.
303      */

304     public A addElement(String hashcode,Element element)
305     {
306         addElementToRegistry(hashcode,element);
307         return(this);
308     }
309
310     /**
311         Adds an Element to the element.
312         @param hashcode name of element for hash table
313         @param element Adds an Element to the element.
314      */

315     public A addElement(String hashcode,String element)
316     {
317         addElementToRegistry(hashcode,element);
318         return(this);
319     }
320
321     /**
322         Removes an Element from the element.
323         @param hashcode the name of the element to be removed.
324     */

325     public A removeElement(String hashcode)
326     {
327         removeElementFromRegistry(hashcode);
328         return(this);
329     }
330
331     /**
332         The onfocus event occurs when an element receives focus either by the
333         pointing device or by tabbing navigation. This attribute may be used
334         with the following elements: LABEL, INPUT, SELECT, TEXTAREA, and
335         BUTTON.
336         
337         @param The script
338     */

339     public void setOnFocus(String script)
340     {
341         addAttribute ( "onFocus", script );
342     }
343
344     /**
345         The onblur event occurs when an element loses focus either by the
346         pointing device or by tabbing navigation. It may be used with the same
347         elements as onfocus.
348         
349         @param The script
350     */

351     public void setOnBlur(String script)
352     {
353         addAttribute ( "onBlur", script );
354     }
355
356     /**
357         The onclick event occurs when the pointing device button is clicked
358         over an element. This attribute may be used with most elements.
359         
360         @param The script
361     */

362     public void setOnClick(String script)
363     {
364         addAttribute ( "onClick", script );
365     }
366     /**
367         The ondblclick event occurs when the pointing device button is double
368         clicked over an element. This attribute may be used with most elements.
369
370         @param The script
371     */

372     public void setOnDblClick(String script)
373     {
374         addAttribute ( "onDblClick", script );
375     }
376     /**
377         The onmousedown event occurs when the pointing device button is pressed
378         over an element. This attribute may be used with most elements.
379
380         @param The script
381     */

382     public void setOnMouseDown(String script)
383     {
384         addAttribute ( "onMouseDown", script );
385     }
386     /**
387         The onmouseup event occurs when the pointing device button is released
388         over an element. This attribute may be used with most elements.
389
390         @param The script
391     */

392     public void setOnMouseUp(String script)
393     {
394         addAttribute ( "onMouseUp", script );
395     }
396     /**
397         The onmouseover event occurs when the pointing device is moved onto an
398         element. This attribute may be used with most elements.
399
400         @param The script
401     */

402     public void setOnMouseOver(String script)
403     {
404         addAttribute ( "onMouseOver", script );
405     }
406     /**
407         The onmousemove event occurs when the pointing device is moved while it
408         is over an element. This attribute may be used with most elements.
409
410         @param The script
411     */

412     public void setOnMouseMove(String script)
413     {
414         addAttribute ( "onMouseMove", script );
415     }
416     /**
417         The onmouseout event occurs when the pointing device is moved away from
418         an element. This attribute may be used with most elements.
419
420         @param The script
421     */

422     public void setOnMouseOut(String script)
423     {
424         addAttribute ( "onMouseOut", script );
425     }
426
427     /**
428         The onkeypress event occurs when a key is pressed and released over an
429         element. This attribute may be used with most elements.
430         
431         @param The script
432     */

433     public void setOnKeyPress(String script)
434     {
435         addAttribute ( "onKeyPress", script );
436     }
437
438     /**
439         The onkeydown event occurs when a key is pressed down over an element.
440         This attribute may be used with most elements.
441         
442         @param The script
443     */

444     public void setOnKeyDown(String script)
445     {
446         addAttribute ( "onKeyDown", script );
447     }
448
449     /**
450         The onkeyup event occurs when a key is released over an element. This
451         attribute may be used with most elements.
452         
453         @param The script
454     */

455     public void setOnKeyUp(String script)
456     {
457         addAttribute ( "onKeyUp", script );
458     }
459     
460     /**
461         Determine if this element needs a line break, if pretty printing.
462     */

463     public boolean getNeedLineBreak()
464     {
465         java.util.Enumeration enum = elements();
466         int i=0;
467         int j=0;
468         while(enum.hasMoreElements())
469         {
470             j++;
471             Object obj = enum.nextElement();
472             if( obj instanceof IMG )
473                 i++;
474         }
475         if ( i==j)
476             return false;
477         return true;
478     }
479
480 }
481
Popular Tags