KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > html > Block


1 // ===========================================================================
2
// Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
3
// $Id: Block.java,v 1.3 2004/03/23 13:59:49 laurent Exp $
4
// ---------------------------------------------------------------------------
5

6 // Laurent Martelli <laurent@aopsys.com> - 12 oct. 2002
7
// cosmetic modification in generated HTML ("</"+tag+">" instead of "</"+tag+"\n>")
8

9 package org.objectweb.jac.aspects.gui.web.html;
10
11 import java.io.IOException JavaDoc;
12 import java.io.Writer JavaDoc;
13
14 /* -------------------------------------------------------------------- */
15 /** HTML Block Composite.
16  * Block of predefined or arbitrary type.
17  * Block types are predefined for PRE, BLOCKQUOTE, CENTER, LISTING,
18  * PLAINTEXT, XMP, DIV (Left and Right) and SPAN.
19  * @see org.mortbay.html.Composite
20  */

21 public class Block extends Composite
22 {
23     /* ----------------------------------------------------------------- */
24     /** Preformatted text */
25     public static final String JavaDoc Pre="pre";
26     /** Quoted Text */
27     public static final String JavaDoc Quote="blockquote";
28     /** Center the block */
29     public static final String JavaDoc Center="center";
30     /** Code listing style */
31     public static final String JavaDoc Listing="listing";
32     /** Plain text */
33     public static final String JavaDoc Plain="plaintext";
34     /** Old pre format - preserve line breaks */
35     public static final String JavaDoc Xmp="xmp";
36     /** Basic Division */
37     public static final String JavaDoc Div="div";
38     /** Left align */
39     public static final String JavaDoc Left="divl";
40     /** Right align */
41     public static final String JavaDoc Right="divr";
42     /** Bold */
43     public static final String JavaDoc Bold="b";
44     /** Italic */
45     public static final String JavaDoc Italic="i";
46     /** Span */
47     public static final String JavaDoc Span="span";
48
49     /* ----------------------------------------------------------------- */
50     private String JavaDoc tag;
51
52     /* ----------------------------------------------------------------- */
53     /** Construct a block using the passed string as the tag.
54      * @param tag The tag to use to open and close the block.
55      */

56     public Block(String JavaDoc tag)
57     {
58         this.tag=tag;
59         if (tag.equals(Left))
60         {
61             tag=Div;
62             left();
63         }
64         if (tag.equals(Right))
65         {
66             tag=Div;
67             right();
68         }
69     }
70
71     /* ----------------------------------------------------------------- */
72     /** Construct a block using the passed string as the tag.
73      * @param tag The tag to use to open and close the block.
74      * @param attributes String of attributes for opening tag.
75      */

76     public Block(String JavaDoc tag, String JavaDoc attributes)
77     {
78         super(attributes);
79         this.tag=tag;
80     }
81         
82     /* ----------------------------------------------------------------- */
83     public void write(Writer JavaDoc out)
84          throws IOException JavaDoc
85     {
86         out.write('<'+tag+attributes()+'>');
87         super.write(out);
88         out.write("</"+tag+">");
89     }
90 }
91
Popular Tags