KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > www > WDoc


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.www;
15
16 import java.io.*;
17 import org.apache.ecs.xhtml.*;
18
19 /**
20  * XHTML Document
21  *
22  * @author Jorg Janke
23  * @version $Id: WDoc.java,v 1.1.1.1 2002/10/12 01:06:54 jjanke Exp $
24  */

25 public class WDoc
26 {
27     /**
28      * Create Document
29      * @param plain if true adds stylesheet and standard js
30      * @return Document
31      */

32     public static WDoc create (boolean plain)
33     {
34         WDoc doc = new WDoc();
35         doc.setUp (plain);
36         return doc;
37     } // create
38

39     /**
40      * Create Document with Title
41      * @param title title
42      * @return Document
43      */

44     public static WDoc create (String JavaDoc title)
45     {
46         WDoc doc = WDoc.create(false);
47         doc.setTitle (title);
48         return doc;
49     } // create
50

51     /*************************************************************************/
52
53     /**
54      * Create new XHTML Document structure
55      */

56     private WDoc ()
57     {
58     } // WDoc
59

60     private html m_html = new html();
61     private head m_head = new head();
62     private body m_body = new body();
63
64     /**
65      * Set up Document
66      * @param plain if true adds stylesheet and standard js
67      */

68     protected void setUp (boolean plain)
69     {
70         m_html.addElement(m_head);
71         m_html.addElement(m_body);
72         if (!plain)
73         {
74             m_head.addElement(new link().setRel("stylesheet").setHref(WEnv.getStylesheetURL()));
75             script std = new script("", WEnv.getBaseDirectory("standard.js"));
76             m_head.addElement(std);
77             m_body.addElement(WEnv.getLogo());
78         }
79     } // setUp
80

81     /**
82      * Create new XHTML Document with Title & Logo
83      * @param title title
84      */

85     protected void setTitle (String JavaDoc title)
86     {
87         if (title == null)
88             return;
89
90         m_head.addElement(new title(title));
91         m_body.addElement(new h1(title));
92     } // setTitle
93

94     /**
95      * Get Body
96      * @return Body
97      */

98     public body getBody()
99     {
100         return m_body;
101     } // getBody
102

103     /**
104      * Get Head
105      * @return Header
106      */

107     public head getHead()
108     {
109         return m_head;
110     } // getHead
111

112     /**
113      * String representation
114      * @return String
115      */

116     public String JavaDoc toString()
117     {
118         return m_html.toString();
119     } // toString
120

121     /**
122      * Output Document
123      * @param out out
124      */

125     public void output (OutputStream out)
126     {
127         m_html.output(out);
128     } // output
129

130     /**
131      * Output Document
132      * @param out out
133      */

134     public void output (PrintWriter out)
135     {
136         m_html.output(out);
137     } // output
138

139     /*************************************************************************/
140
141     /**
142      * Test Class
143      * @param args args
144      */

145     public static void main (String JavaDoc[] args)
146     {
147         WDoc doc = WDoc.create("Test");
148         System.out.println(doc.toString());
149         System.out.println("---------");
150         doc.output(System.out);
151
152     } // main
153
} // WDoc
154
Popular Tags