001    // ===========================================================================
002    // Copyright (c) 1996 Mort Bay Consulting Pty. Ltd. All rights reserved.
003    // $Id: Block.java,v 1.3 2004/03/23 13:59:49 laurent Exp $
004    // ---------------------------------------------------------------------------
005    
006    // Laurent Martelli <laurent@aopsys.com> - 12 oct. 2002
007    // cosmetic modification in generated HTML ("</"+tag+">" instead of "</"+tag+"\n>")
008    
009    package org.objectweb.jac.aspects.gui.web.html;
010    
011    import java.io.IOException;
012    import java.io.Writer;
013    
014    /* -------------------------------------------------------------------- */
015    /** HTML Block Composite.
016     * Block of predefined or arbitrary type.
017     * Block types are predefined for PRE, BLOCKQUOTE, CENTER, LISTING,
018     * PLAINTEXT, XMP, DIV (Left and Right) and SPAN.
019     * @see  org.mortbay.html.Composite
020     */
021    public class Block extends Composite
022    {
023        /* ----------------------------------------------------------------- */
024        /** Preformatted text */
025        public static final String Pre="pre";
026        /** Quoted Text */
027        public static final String Quote="blockquote";
028        /** Center the block */
029        public static final String Center="center";
030        /** Code listing style */
031        public static final String Listing="listing";
032        /** Plain text */
033        public static final String Plain="plaintext";
034        /** Old pre format - preserve line breaks */
035        public static final String Xmp="xmp";
036        /** Basic Division */
037        public static final String Div="div";
038        /** Left align */
039        public static final String Left="divl";
040        /** Right align */
041        public static final String Right="divr";
042        /** Bold */
043        public static final String Bold="b";
044        /** Italic */
045        public static final String Italic="i";
046        /** Span */
047        public static final String Span="span";
048    
049        /* ----------------------------------------------------------------- */
050        private String tag;
051    
052        /* ----------------------------------------------------------------- */
053        /** Construct a block using the passed string as the tag.
054         * @param tag The tag to use to open and close the block.
055         */
056        public Block(String tag)
057        {
058            this.tag=tag;
059            if (tag.equals(Left))
060            {
061                tag=Div;
062                left();
063            }
064            if (tag.equals(Right))
065            {
066                tag=Div;
067                right();
068            }
069        }
070    
071        /* ----------------------------------------------------------------- */
072        /** Construct a block using the passed string as the tag.
073         * @param tag The tag to use to open and close the block.
074         * @param attributes String of attributes for opening tag.
075         */
076        public Block(String tag, String attributes)
077        {
078            super(attributes);
079            this.tag=tag;
080        }
081            
082        /* ----------------------------------------------------------------- */
083        public void write(Writer out)
084             throws IOException
085        {
086            out.write('<'+tag+attributes()+'>');
087            super.write(out);
088            out.write("</"+tag+">");
089        }
090    }