1 // ======================================================================== 2 // $Id: Block.java,v 1.3 2004/05/09 20:31:28 gregwilkins Exp $ 3 // Copyright 1996-2004 Mort Bay Consulting Pty. Ltd. 4 // ------------------------------------------------------------------------ 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 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 import java.io.IOException; 18 import java.io.Writer; 19 20 /* -------------------------------------------------------------------- */ 21 /** HTML Block Composite. 22 * Block of predefined or arbitrary type. 23 * Block types are predefined for PRE, BLOCKQUOTE, CENTER, LISTING, 24 * PLAINTEXT, XMP, DIV (Left and Right) and SPAN. 25 * @see org.mortbay.html.Composite 26 */ 27 public class Block extends Composite 28 { 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 { 64 this.tag=tag; 65 if (tag==Left) 66 { 67 tag=Div; 68 left(); 69 } 70 if (tag==Right) 71 { 72 tag=Div; 73 right(); 74 } 75 } 76 77 /* ----------------------------------------------------------------- */ 78 /** Construct a block using the passed string as the tag. 79 * @param tag The tag to use to open and close the block. 80 * @param attributes String of attributes for opening tag. 81 */ 82 public Block(String tag, String attributes) 83 { 84 super(attributes); 85 this.tag=tag; 86 } 87 88 /* ----------------------------------------------------------------- */ 89 public void write(Writer out) 90 throws IOException 91 { 92 out.write('<'+tag+attributes()+'>'); 93 super.write(out); 94 out.write("</"+tag+"\n>"); 95 } 96 } 97 98