KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ecs > FrameSetDocument


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;
59
60 import java.io.OutputStream JavaDoc;
61 import java.io.PrintWriter JavaDoc;
62 import java.io.Serializable JavaDoc;
63 import org.apache.ecs.html.Html;
64 import org.apache.ecs.html.Body;
65 import org.apache.ecs.html.Title;
66 import org.apache.ecs.html.Head;
67 import org.apache.ecs.html.FrameSet;
68 import org.apache.ecs.html.NoFrames;
69
70 /**
71     This class creates a FrameSetDocument container, for convience.
72
73     @version $Id: FrameSetDocument.java,v 1.4 2003/04/27 09:43:57 rdonkin Exp $
74     @author <a HREF="mailto:snagy@servletapi.com">Stephan Nagy</a>
75     @author <a HREF="mailto:jon@clearink.com">Jon S. Stevens</a>
76 */

77 public class FrameSetDocument implements Serializable JavaDoc,Cloneable JavaDoc
78 {
79     /** @serial html html */
80     private Html html; // this is the actual container for head and body
81
/** @serial head head */
82     private Head head;
83     /** @serial body body */
84     private Body body;
85     /** @serial title title */
86     private Title title;
87     /** @serial frameset frameset */
88     private FrameSet frameset;
89     /** @serial noframes frameset */
90     private NoFrames noframes;
91     /** @serial doctype doctype */
92     private Doctype doctype = null;
93
94     /** @serial codeset codeset */
95     private String JavaDoc codeset = null;
96     
97     {
98         html = new Html();
99         head = new Head();
100         title = new Title();
101         frameset = new FrameSet();
102         noframes = new NoFrames();
103         body = new Body();
104         
105         head.addElement("title",title);
106         html.addElement("head",head);
107         html.addElement("frameset",frameset);
108         html.addElement("noframes",noframes);
109         noframes.addElement("body",body);
110     }
111     
112     /**
113         Basic constructor.
114     */

115     public FrameSetDocument()
116     {
117     }
118
119     /**
120         Basic constructor. Sets the codeset for the page output.
121     */

122     public FrameSetDocument(String JavaDoc codeset)
123     {
124         setCodeset(codeset);
125     }
126
127     /**
128         Get the doctype element for this document container.
129     */

130     public Doctype getDoctype()
131     {
132         return(doctype);
133     }
134     
135     /**
136         Set the doctype element for this document container.
137     */

138     public FrameSetDocument setDoctype(Doctype set_doctype)
139     {
140         this.doctype = set_doctype;
141         return(this);
142     }
143
144     /**
145         Get the html element for this document container.
146     */

147     public Html getHtml()
148     {
149         return(html);
150     }
151     
152     /**
153         Set the html element for this FrameSetDocument container.
154     */

155     public FrameSetDocument setHtml(Html set_html)
156     {
157         this.html = set_html;
158         return(this);
159     }
160     
161     /**
162         Get the head element for this FrameSetDocument container.
163     */

164     public Head getHead()
165     {
166         return(head);
167     }
168
169     /**
170         Set the head element for this FrameSetDocument container.
171     */

172     public FrameSetDocument setHead(Head set_head)
173     {
174         html.addElement("head",set_head);
175         this.head = set_head;
176         return(this);
177     }
178
179     /**
180         Append to the head element for this FrameSetDocument container.
181         @param value adds to the value between the head tags
182     */

183     public FrameSetDocument appendHead(Element value)
184     {
185         head.addElement(value);
186         return(this);
187     }
188
189     /**
190         Append to the head element for this FrameSetDocument container.
191         @param value adds to the value between the head tags
192     */

193     public FrameSetDocument appendHead(String JavaDoc value)
194     {
195         head.addElement(value);
196         return(this);
197     }
198
199     /**
200         Get the FrameSet element for this FrameSetDocument container.
201     */

202     public FrameSet getFrameSet()
203     {
204         return(frameset);
205     }
206
207     /**
208         Set the FrameSet element for this FrameSetDocument container.
209     */

210     public FrameSetDocument setFrameSet(FrameSet set_frameset)
211     {
212         html.addElement("frameset",set_frameset);
213         this.frameset = set_frameset;
214         return(this);
215     }
216
217     /**
218         Append to the head element for this FrameSetDocument container.
219         @param value adds to the value between the head tags
220     */

221     public FrameSetDocument appendFrameSet(Element value)
222     {
223         frameset.addElement(value);
224         return(this);
225     }
226
227     /**
228         Append to the head element for this FrameSetDocument container.
229         @param value adds to the value between the head tags
230     */

231     public FrameSetDocument appendFrameSet(String JavaDoc value)
232     {
233         frameset.addElement(value);
234         return(this);
235     }
236     /**
237         Get the body element for this FrameSetDocument container.
238     */

239     public Body getBody()
240     {
241         return(body);
242     }
243
244     /**
245         Set the Body element for this FrameSetDocument container.
246     */

247     public FrameSetDocument setBody(Body set_body)
248     {
249         noframes.addElement("body",set_body);
250         this.body = set_body;
251         return(this);
252     }
253     
254     /**
255         Append to the body element for this FrameSetDocument container.
256         @param value adds to the value between the body tags
257     */

258     public FrameSetDocument appendBody(Element value)
259     {
260         body.addElement(value);
261         return(this);
262     }
263
264     /**
265         Append to the body element for this FrameSetDocument container.
266         @param value adds to the value between the body tags
267     */

268     public FrameSetDocument appendBody(String JavaDoc value)
269     {
270         body.addElement(value);
271         return(this);
272     }
273
274     /**
275         Get the title element for this FrameSetDocument container.
276     */

277     public Title getTitle()
278     {
279         return(title);
280     }
281
282     /**
283         Set the Title element for this FrameSetDocument container.
284     */

285     public FrameSetDocument setTitle(Title set_title)
286     {
287         head.addElement("title",set_title);
288         this.title = set_title;
289         return(this);
290     }
291     
292     /**
293         Append to the title element for this FrameSetDocument container.
294         @param value adds to the value between the title tags
295     */

296     public FrameSetDocument appendTitle(Element value)
297     {
298         title.addElement(value);
299         return(this);
300     }
301
302     /**
303         Append to the title element for this FrameSetDocument container.
304         @param value adds to the value between the title tags
305     */

306     public FrameSetDocument appendTitle(String JavaDoc value)
307     {
308         title.addElement(value);
309         return(this);
310     }
311
312     /**
313      * Sets the codeset for this FrameSetDocument
314      */

315     public void setCodeset ( String JavaDoc codeset )
316     {
317         this.codeset = codeset;
318     }
319
320     /**
321      * Gets the codeset for this FrameSetDocument
322      *
323      * @return the codeset
324      */

325     public String JavaDoc getCodeset()
326     {
327         return this.codeset;
328     }
329     
330     /**
331         Write the container to the OutputStream
332     */

333     public void output(OutputStream JavaDoc out)
334     {
335         if (doctype != null)
336         {
337             doctype.output(out);
338             try
339             {
340                 out.write('\n');
341             }
342             catch ( Exception JavaDoc e)
343             {}
344         }
345         // FrameSetDocument is just a convient wrapper for Html call Html.output
346
html.output(out);
347     }
348
349     /**
350         Write the container to the PrintWriter
351     */

352     public void output(PrintWriter JavaDoc out)
353     {
354         if (doctype != null)
355         {
356             doctype.output(out);
357             try
358             {
359                 out.write('\n');
360             }
361             catch ( Exception JavaDoc e)
362             {}
363         }
364         // FrameSetDocument is just a convient wrapper for Html call Html.output
365
html.output(out);
366     }
367
368     /**
369         Override the toString() method so that it prints something meaningful.
370     */

371     public final String JavaDoc toString()
372     {
373         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
374         if ( getCodeset() != null )
375         {
376             if (doctype != null)
377                 sb.append (doctype.toString(getCodeset()));
378             sb.append (html.toString(getCodeset()));
379             return (sb.toString());
380         }
381         else
382         {
383             if (doctype != null)
384                 sb.append (doctype.toString());
385             sb.append (html.toString());
386             return(sb.toString());
387         }
388     }
389
390     /**
391         Override the toString() method so that it prints something meaningful.
392     */

393     public final String JavaDoc toString(String JavaDoc codeset)
394     {
395         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
396         if (doctype != null)
397             sb.append (doctype.toString(getCodeset()));
398         sb.append (html.toString(getCodeset()));
399         return(sb.toString());
400     }
401    
402     /**
403         Allows the FrameSetDocument to be cloned. Doesn't return an instanceof FrameSetDocument returns instance of Html.
404
405     */

406
407     public Object JavaDoc clone()
408     {
409         return(html.clone());
410     }
411 }
412
Popular Tags