KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
63     This class creates a &lt;U&gt; tag.
64
65     @version $Id: Script.java,v 1.6 2003/05/02 09:54:59 rdonkin Exp $
66     @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
67     @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
68 */

69 public class Script extends MultiPartElement implements Printable
70 {
71     /**
72         Private initialization routine.
73     */

74     {
75         setElementType("script");
76         setLanguage("JavaScript");
77     }
78     /**
79         Basic constructor.
80     */

81     public Script()
82     {
83     }
84
85     /**
86         Basic constructor.
87         @param element Adds an Element to the element.
88     */

89     public Script(Element element)
90     {
91         addElement(element);
92     }
93
94     /**
95         Basic constructor.
96         @param element Adds an Element to the element.
97         @param src sets the SRC="" attribute
98     */

99     public Script(Element element, String JavaDoc src)
100     {
101         addElement(element);
102         setSrc(src);
103     }
104
105     /**
106         Basic constructor.
107         @param element Adds an Element to the element.
108         @param src sets the SRC="" attribute
109         @param type sets the TYPE="" attribute
110     */

111     public Script(Element element, String JavaDoc src, String JavaDoc type)
112     {
113         addElement(element);
114         setSrc(src);
115         setType(type);
116     }
117
118     /**
119         Basic constructor.
120         @param element Adds an Element to the element.
121         @param src sets the SRC="" attribute
122         @param type sets the TYPE="" attribute
123         @param lang sets the LANGUAGE="" attribute
124     */

125     public Script(Element element, String JavaDoc src, String JavaDoc type, String JavaDoc lang)
126     {
127         addElement(element);
128         setSrc(src);
129         setType(type);
130         setLanguage(lang);
131     }
132
133     /**
134         Basic constructor.
135         @param element Adds an Element to the element.
136     */

137     public Script(String JavaDoc element)
138     {
139         addElement(element);
140     }
141
142     /**
143         Basic constructor.
144         @param element Adds an Element to the element.
145         @param src sets the SRC="" attribute
146     */

147     public Script(String JavaDoc element, String JavaDoc src)
148     {
149         addElement(element);
150         setSrc(src);
151     }
152
153     /**
154         Basic constructor.
155         @param element Adds an Element to the element.
156         @param src sets the SRC="" attribute
157         @param type sets the TYPE="" attribute
158     */

159     public Script(String JavaDoc element, String JavaDoc src, String JavaDoc type)
160     {
161         addElement(element);
162         setSrc(src);
163         setType(type);
164     }
165
166     /**
167         Basic constructor.
168         @param element Adds an Element to the element.
169         @param src sets the SRC="" attribute
170         @param type sets the TYPE="" attribute
171         @param lang sets the LANGUAGE="" attribute
172     */

173     public Script(String JavaDoc element, String JavaDoc src, String JavaDoc type, String JavaDoc lang)
174     {
175         addElement(element);
176         setSrc(src);
177         setType(type);
178         setLanguage(lang);
179     }
180
181     /**
182         Sets the SRC="" attribute
183         @param src the SRC="" attribute
184     */

185     public Script setSrc(String JavaDoc src)
186     {
187         addAttribute("src",src);
188         return this;
189     }
190
191     /**
192         Sets the TYPE="" attribute
193         @param type the TYPE="" attribute
194     */

195     public Script setType(String JavaDoc type)
196     {
197         addAttribute("type", type);
198         return this;
199     }
200
201     /**
202         Sets the LANGUAGE="" attribute
203         @param language the LANGUAGE="" attribute
204     */

205     public Script setLanguage(String JavaDoc language)
206     {
207         addAttribute("language", language);
208         return this;
209     }
210
211     /**
212         Adds an Element to the element.
213         @param hashcode name of element for hash table
214         @param element Adds an Element to the element.
215      */

216     public Script addElement(String JavaDoc hashcode,Element element)
217     {
218         addElementToRegistry(hashcode,element);
219         return(this);
220     }
221
222     /**
223         Adds an Element to the element.
224         @param hashcode name of element for hash table
225         @param element Adds an Element to the element.
226      */

227     public Script addElement(String JavaDoc hashcode,String JavaDoc element)
228     {
229         addElementToRegistry(hashcode,element);
230         return(this);
231     }
232
233     /**
234         Adds an Element to the element.
235         @param element Adds an Element to the element.
236      */

237     public Script addElement(Element element)
238     {
239         addElementToRegistry(element);
240         return(this);
241     }
242
243     /**
244         Adds an Element to the element.
245         @param element Adds an Element to the element.
246      */

247     public Script addElement(String JavaDoc element)
248     {
249         addElementToRegistry(element);
250         return(this);
251     }
252     /**
253         Removes an Element from the element.
254         @param hashcode the name of the element to be removed.
255     */

256     public Script removeElement(String JavaDoc hashcode)
257     {
258         removeElementFromRegistry(hashcode);
259         return(this);
260     }
261     
262     /**
263         We override this method here in order to create the Html
264         comment code by default that protects scripts from older
265         browsers. We put in hard returns here because we want to make
266         sure that this code works even with PrettyPrint false.
267     */

268     public String JavaDoc createStartTag()
269     {
270         StringBuffer JavaDoc out = new StringBuffer JavaDoc();
271         out.append(super.createStartTag());
272         if (!(hasAttribute("src"))) {
273             out.append("\n");
274             out.append("<!--");
275             out.append("\n");
276         }
277         return(out.toString());
278     }
279     /**
280         We override this method here in order to create the Html
281         comment code by default that protects scripts from older
282         browsers. We put in hard returns here because we want to make
283         sure that this code works even with PrettyPrint false.
284     */

285     public String JavaDoc createEndTag()
286     {
287         StringBuffer JavaDoc out = new StringBuffer JavaDoc();
288         if (!(hasAttribute("src"))) {
289             out.append("\n");
290             out.append("// -->");
291             out.append("\n");
292         }
293         out.append(super.createEndTag());
294         return(out.toString());
295     }
296 }
297
Popular Tags