001: // ========================================================================
002: // $Id: TestHtml.java,v 1.4 2004/05/09 20:33:27 gregwilkins Exp $
003: // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
004: // ------------------------------------------------------------------------
005: // Licensed under the Apache License, Version 2.0 (the "License");
006: // you may not use this file except in compliance with the License.
007: // You may obtain a copy of the License at
008: // http://www.apache.org/licenses/LICENSE-2.0
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014: // ========================================================================
015:
016: package org.mortbay.html;
017:
018: import java.io.IOException;
019:
020: import junit.framework.TestCase;
021:
022: // ====================================================================
023: public class HtmlTest extends TestCase {
024: public HtmlTest(String arg0) {
025: super (arg0);
026: }
027:
028: public static void main(String[] args) {
029: junit.textui.TestRunner.run(HtmlTest.class);
030: }
031:
032: public void testGenerate() {
033: try {
034:
035: int loops = 1;
036:
037: for (int i = 0; i < loops; i++) {
038:
039: Page page = new Page("Test Page");
040: page.addHeader(new StyleLink("/File/jetty.css"));
041: page.setBackGroundColor("A0A0A0");
042:
043: Break rule = new Break(Break.Rule);
044: page.add(rule);
045:
046: page.add(new Heading(1, "Testing Testing 123"));
047:
048: Composite composite1 = new Composite();
049: Composite composite2 = new Composite();
050: Composite text1 = new Composite();
051: Composite text2 = new Composite();
052: Composite text3 = new Composite();
053:
054: text1.add("How now");
055: text1.add("Brown cow");
056:
057: text2
058: .add("The Quick Brown Fox Jumped Over The Lazy Dog");
059:
060: text3
061: .add("Now is the time for all good men to come to");
062: text3.add("the aid of the party.");
063:
064: composite1.add(text1);
065: composite2.add(text2);
066: composite2.add(text3);
067: composite1.add(composite2);
068: composite1.add("Plain Texted Added1");
069:
070: page.add(composite1);
071: page.add("Plain Texted Added2");
072:
073: page.add(rule);
074:
075: Block right = new Block(Block.Right);
076: right.add(text3);
077: page.add(right);
078: page.add(rule);
079:
080: page.add(new Heading(3, "Test List"));
081: List list = new List(List.Ordered);
082: list.add(text1);
083: list.add(text2);
084: list.add(composite1);
085: page.add(list);
086:
087: DefList dList = new DefList();
088: page.add(dList);
089: Composite word1 = new Composite();
090: Composite word2 = new Composite();
091: Composite word3 = new Composite();
092: word1.add("Blah");
093: word2.add("Foo");
094: word3.add("Bah");
095: dList.add(word1, text1);
096: dList.add(word2, text2);
097: dList.add(word3, text3);
098:
099: page.flush(System.out);
100:
101: page.add(rule);
102: Composite c = new Composite();
103: c.add("Test Link");
104: page.add(new Link("test.html", c));
105:
106: page.add(rule);
107: Table table = new Table(2);
108: table.newRow();
109: table.addHeading("Heading1");
110: table.addHeading("Heading2");
111: table.addHeading("Heading3");
112: table.newRow();
113: table.addCell("String1");
114: table.addCell(text2);
115: table.addCell(text3);
116: page.add(table);
117:
118: page.add(rule);
119: table = new Table(2);
120: table.defaultRow().cssID("I1");
121: table.defaultHead().cssID("I2");
122: table.defaultCell().cssID("I3");
123: table.defaultCell().add("<b>");
124: table.newRow();
125: table.addHeading("Heading1");
126: table.addHeading("Heading2");
127: table.addHeading("Heading3");
128: table.newRow();
129: table.addCell("String1");
130: table.addCell(text2);
131: table.addCell(text3);
132: page.add(table);
133:
134: page.add(rule);
135:
136: Form form = new Form("/CGI/test-cgi");
137: page.add(form);
138: form.add(new Input(Input.Text, "N1", "Value"));
139: form.add(new Input(Input.Password, "N2", "Value"));
140: form.add(new Input(Input.Checkbox, "N3", "Value"));
141: form.add(new Input(Input.Checkbox, "N4", "Value"));
142: form.add(new Input(Input.Radio, "N5", "Value"));
143: form.add(new Input(Input.Radio, "N5", "Value"));
144: form.add(new Input(Input.Submit, "N6"));
145: form.add(new Input(Input.Reset, "N7"));
146: form.add(new Input(Input.Hidden, "N8", "Value"));
147: form.add(new TextArea("N9", "Value"));
148:
149: Select select = new Select("Select", false);
150: form.add(select);
151: select.add("Tom");
152: select.add("Dick");
153: select.add("Harry");
154: select.add("Thomas");
155: select.add("Richard");
156: select.add("Harold");
157:
158: select = new Select("Select", true);
159: select.setSize(3);
160: form.add(select);
161: select.add("Tom");
162: select.add("Dick");
163: select.add("Harry");
164: select.add("Thomas");
165: select.add("Richard");
166: select.add("Harold");
167:
168: page.add(Break.rule);
169:
170: TableForm tf = new TableForm("ScriptName");
171: page.add(tf);
172: tf
173: .addText(
174: "Text",
175: "Plain Text Information. Which is not included in any data sent when the form is submitted.");
176: tf.addTextField("F1", "Text Field", 0, null);
177: tf.addTextField("F2", "Text Field", 10, "value");
178: tf
179: .addTextArea("F3", "Text Area", 0, 4,
180: "Value of the text area.\nWhich can be over many lines.");
181: tf.addInfoField("F4", "Info Field", "value");
182: tf.addHiddenField("F5", "hidden value");
183: tf.addPassword("F6", "Password", 10);
184: tf.addButtonArea();
185: tf.addButton("F11a", "Button1a");
186: tf.addButton("F11b", "Button1b");
187: tf.addButtonRow();
188: tf.addButton("F11c", "Button1c");
189: tf.addButton("F11d", "Button1d");
190: tf.addCheckbox("F7", "Checkbox", false);
191: tf.addCheckbox("F8", "Checkbox", true);
192: tf.buttonsAtBottom();
193: tf.addButton("F11", "Button2");
194: tf.addReset("Reset");
195: tf.addTextField("F12", "Extended", 10, "value");
196: tf.extendRow();
197: tf.addCheckbox("F13", null, false);
198:
199: tf.addSelect("F9", "Select", false, 0).add("A")
200: .add("B").add("C").add("D");
201: tf.addSelect("F0", "Select", true, 3).add("A").add("B")
202: .add("C").add("D");
203:
204: page.add(Break.rule);
205:
206: page.add(new Style().comment().add(
207: "dt { background: yellow; color: black }"));
208:
209: page.write(System.out);
210: }
211: } catch (IOException e) {
212: e.printStackTrace();
213: }
214: }
215: }
|