01: // ========================================================================
02: // $Id: Block.java,v 1.3 2004/05/09 20:31:28 gregwilkins Exp $
03: // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd.
04: // ------------------------------------------------------------------------
05: // Licensed under the Apache License, Version 2.0 (the "License");
06: // you may not use this file except in compliance with the License.
07: // You may obtain a copy of the License at
08: // http://www.apache.org/licenses/LICENSE-2.0
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14: // ========================================================================
15:
16: package org.mortbay.html;
17:
18: import java.io.IOException;
19: import java.io.Writer;
20:
21: /* -------------------------------------------------------------------- */
22: /** HTML Block Composite.
23: * Block of predefined or arbitrary type.
24: * Block types are predefined for PRE, BLOCKQUOTE, CENTER, LISTING,
25: * PLAINTEXT, XMP, DIV (Left and Right) and SPAN.
26: * @see org.mortbay.html.Composite
27: */
28: public class Block extends Composite {
29: /* ----------------------------------------------------------------- */
30: /** Preformatted text */
31: public static final String Pre = "pre";
32: /** Quoted Text */
33: public static final String Quote = "blockquote";
34: /** Center the block */
35: public static final String Center = "center";
36: /** Code listing style */
37: public static final String Listing = "listing";
38: /** Plain text */
39: public static final String Plain = "plaintext";
40: /** Old pre format - preserve line breaks */
41: public static final String Xmp = "xmp";
42: /** Basic Division */
43: public static final String Div = "div";
44: /** Left align */
45: public static final String Left = "divl";
46: /** Right align */
47: public static final String Right = "divr";
48: /** Bold */
49: public static final String Bold = "b";
50: /** Italic */
51: public static final String Italic = "i";
52: /** Span */
53: public static final String Span = "span";
54:
55: /* ----------------------------------------------------------------- */
56: private String tag;
57:
58: /* ----------------------------------------------------------------- */
59: /** Construct a block using the passed string as the tag.
60: * @param tag The tag to use to open and close the block.
61: */
62: public Block(String tag) {
63: this .tag = tag;
64: if (tag == Left) {
65: tag = Div;
66: left();
67: }
68: if (tag == Right) {
69: tag = Div;
70: right();
71: }
72: }
73:
74: /* ----------------------------------------------------------------- */
75: /** Construct a block using the passed string as the tag.
76: * @param tag The tag to use to open and close the block.
77: * @param attributes String of attributes for opening tag.
78: */
79: public Block(String tag, String attributes) {
80: super (attributes);
81: this .tag = tag;
82: }
83:
84: /* ----------------------------------------------------------------- */
85: public void write(Writer out) throws IOException {
86: out.write('<' + tag + attributes() + '>');
87: super .write(out);
88: out.write("</" + tag + "\n>");
89: }
90: }
|