001    /**
002     * www.jcoverage.com
003     * Copyright (C)2003 jcoverage ltd.
004     *
005     * This file is part of jcoverage.
006     *
007     * jcoverage is free software; you can redistribute it and/or modify
008     * it under the terms of the GNU General Public License as published
009     * by the Free Software Foundation; either version 2 of the License,
010     * or (at your option) any later version.
011     *
012     * jcoverage is distributed in the hope that it will be useful, but
013     * WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015     * General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * along with jcoverage; if not, write to the Free Software
019     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
020     * USA
021     *
022     */
023    package com.jcoverage.reporting.html;
024    
025    import java.io.*;
026    import java.util.*;
027    
028    import org.apache.log4j.Logger;
029    
030    /**
031     *
032     */
033    public abstract class HtmlBlockElement extends HtmlElement {
034      
035      static Logger logger=Logger.getLogger(HtmlBlockElement.class);
036      
037      List writables;
038    
039      protected HtmlBlockElement(String tag) {
040        super(tag);
041      }
042    
043      public void add(Writable writable) {
044        if (writables==null) {
045          writables=new ArrayList();
046        }
047        writables.add(writable);
048      }
049      
050      protected List getWritables() {
051        return writables;
052      }
053    
054      protected void openBlock(PrintWriter writer) {
055        openElement(writer);
056        writer.println();
057      }
058    
059      protected void closeBlock(PrintWriter writer) {
060        writer.println();
061        closeElement(writer);
062        writer.println();
063      }
064    
065      public void writeTo(PrintWriter writer) {
066        openBlock(writer);
067        writeWritables(writer);
068        closeBlock(writer);
069      }
070    
071      protected void writeWritables(PrintWriter writer) {
072        for(Iterator it=getWritables().iterator();it.hasNext();) {
073          ((Writable)it.next()).writeTo(writer);
074        }
075      }
076    
077    }