KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > 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.xhtml;
59
60 import org.apache.ecs.*;
61 /**
62     This class creates an &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.2 2003/04/27 09:41:09 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     @author <a HREF="mailto:bojan@binarix.com">Bojan Smojver</a>
70 */

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

76     {
77         setElementType("a");
78         setCase(LOWERCASE); // XHTML specific
79
setAttributeQuote(true); // XHTML specific
80
}
81
82     /**
83         Basic constructor. You need to set the attributes using the
84         set* methods.
85     */

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

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

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

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

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

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

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

176     public a(String href, String name, String target, String value)
177     {
178         setHref(href);
179         setName(name);
180         setTarget(target);
181         addElement(value);
182     }
183
184     /**
185         This constructor creates an &lt;a&gt; tag.
186
187         @param href the URI that goes between double quotes
188         @param name the name="" attribute
189         @param target the target="" attribute
190         @param lang the lang="" and xml:lang="" attributes
191         @param value the value that goes between &lt;start_tag&gt; &lt;end_tag&gt;
192     */

193     public a(String href, String name, String target, String lang,
194             String value)
195     {
196         setHref(href);
197         setName(name);
198         setTarget(target);
199         setLang(lang);
200         addElement(value);
201     }
202
203     /**
204         This constructor creates an &lt;a&gt; tag.
205
206         @param href the URI that goes between double quotes
207         @param name the name="" attribute
208         @param target the target="" attribute
209         @param lang the lang="" and xml:lang="" attributes
210         @param value the value that goes between &lt;start_tag&gt; &lt;end_tag&gt;
211     */

212     public a(String href, String name, String target, String lang,
213             Element value)
214     {
215         setHref(href);
216         setName(name);
217         setTarget(target);
218         setLang(lang);
219         addElement(value);
220     }
221
222     /**
223         Sets the HREF="" attribute
224         @param href the HREF="" attribute
225     */

226     public a setHref(String href)
227     {
228         addAttribute("href",href);
229         return this;
230     }
231
232     /**
233         Sets the name="" attribute
234         @param name the name="" attribute
235     */

236     public a setName(String name)
237     {
238         addAttribute("name",name);
239         return this;
240     }
241
242     /**
243         Sets the target="" attribute
244         @param target the target="" attribute
245     */

246     public a setTarget(String target)
247     {
248         addAttribute("target",target);
249         return this;
250     }
251
252     /**
253         Sets the rel="" attribute
254         @param rel the rel="" attribute
255     */

256     public a setRel(String rel)
257     {
258         addAttribute("rel",rel);
259         return this;
260     }
261
262     /**
263         Sets the rev="" attribute
264         @param rev the rev="" attribute
265     */

266     public a setRev(String rev)
267     {
268         addAttribute("rev",rev);
269         return this;
270     }
271
272     /**
273         Sets the lang="" and xml:lang="" attributes
274         @param lang the lang="" and xml:lang="" attributes
275     */

276     public Element setLang(String lang)
277     {
278         addAttribute("lang",lang);
279         addAttribute("xml:lang",lang);
280         return this;
281     }
282
283     /**
284         Adds an Element to the element.
285         @param element Adds an Element to the element.
286      */

287     public a addElement(Element element)
288     {
289         addElementToRegistry(element);
290         return(this);
291     }
292
293     /**
294         Adds an Element to the element.
295         @param element Adds an Element to the element.
296      */

297     public a addElement(String element)
298     {
299         addElementToRegistry(element);
300         return(this);
301     }
302
303     /**
304         Adds an Element to the element.
305         @param hashcode name of element for hash table
306         @param element Adds an Element to the element.
307      */

308     public a addElement(String hashcode,Element element)
309     {
310         addElementToRegistry(hashcode,element);
311         return(this);
312     }
313
314     /**
315         Adds an Element to the element.
316         @param hashcode name of element for hash table
317         @param element Adds an Element to the element.
318      */

319     public a addElement(String hashcode,String element)
320     {
321         addElementToRegistry(hashcode,element);
322         return(this);
323     }
324
325     /**
326         Removes an Element from the element.
327         @param hashcode the name of the element to be removed.
328     */

329     public a removeElement(String hashcode)
330     {
331         removeElementFromRegistry(hashcode);
332         return(this);
333     }
334
335     /**
336         The onfocus event occurs when an element receives focus either by the
337         pointing device or by tabbing navigation. This attribute may be used
338         with the following elements: label, input, select, textarea, and
339         button.
340         
341         @param The script
342     */

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

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

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

377     public void setOnDblClick(String script)
378     {
379         addAttribute ( "ondblclick", script );
380     }
381
382     /**
383         The onmousedown event occurs when the pointing device button is pressed
384         over an element. This attribute may be used with most elements.
385
386         @param The script
387     */

388     public void setOnMouseDown(String script)
389     {
390         addAttribute ( "onmousedown", script );
391     }
392
393     /**
394         The onmouseup event occurs when the pointing device button is released
395         over an element. This attribute may be used with most elements.
396
397         @param The script
398     */

399     public void setOnMouseUp(String script)
400     {
401         addAttribute ( "onnlouseup", script );
402     }
403
404     /**
405         The onmouseover event occurs when the pointing device is moved onto an
406         element. This attribute may be used with most elements.
407
408         @param The script
409     */

410     public void setOnMouseOver(String script)
411     {
412         addAttribute ( "onmouseover", script );
413     }
414
415     /**
416         The onmousemove event occurs when the pointing device is moved while it
417         is over an element. This attribute may be used with most elements.
418
419         @param The script
420     */

421     public void setOnMouseMove(String script)
422     {
423         addAttribute ( "onmousemove", script );
424     }
425
426     /**
427         The onmouseout event occurs when the pointing device is moved away from
428         an element. This attribute may be used with most elements.
429
430         @param The script
431     */

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

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

454     public void setOnKeyDown(String script)
455     {
456         addAttribute ( "onkeydown", script );
457     }
458
459     /**
460         The onkeyup event occurs when a key is released over an element. This
461         attribute may be used with most elements.
462         
463         @param The script
464     */

465     public void setOnKeyUp(String script)
466     {
467         addAttribute ( "onkeyup", script );
468     }
469     
470     /**
471         Determine if this element needs a line break, if pretty printing.
472     */

473     public boolean getNeedLineBreak()
474     {
475         java.util.Enumeration enum = elements();
476         int i=0;
477         int j=0;
478         while(enum.hasMoreElements())
479         {
480             j++;
481             Object obj = enum.nextElement();
482             if( obj instanceof img )
483                 i++;
484         }
485         if ( i==j)
486             return false;
487         return true;
488     }
489 }
490
Popular Tags