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.coverage.reporting.html;
024    
025    import com.jcoverage.reporting.MultiViewCollator;
026    import com.jcoverage.reporting.Page;
027    import com.jcoverage.reporting.View;
028    import com.jcoverage.reporting.ViewFormattingContext;
029    import com.jcoverage.reporting.html.AbstractHtmlFormat;
030    import com.jcoverage.reporting.html.H2;
031    import com.jcoverage.reporting.html.Html;
032    import com.jcoverage.reporting.html.Style;
033    
034    import com.jcoverage.coverage.Version;
035    
036    import org.apache.log4j.Logger;
037    
038    /**
039     *
040     */
041    public abstract class CommonFormat extends AbstractHtmlFormat {
042      
043      static Logger logger=Logger.getLogger(CommonFormat.class);
044      
045      protected void buildHeader(Html html) {
046        html.getHead().add(new Style(getClass().getResourceAsStream("style.css")));
047        html.add("<img src=\"http://jcoverage.com/images/shim"+Version.VERSION_STRING+".gif\" width=\"1\" height=\"1\">");
048      }
049      
050      protected void buildFooter(Html html) {
051        html.getBody().add("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"top\"><td>");
052        html.getBody().add("<p class=\"legalleft\">");
053        html.getBody().add("this report was generated by version "+Version.VERSION_STRING+" of jcoverage.<br>");
054        html.getBody().add("visit <a href=\"http://www.jcoverage.com\">www.jcoverage.com</a> for updates.<br>");
055        html.getBody().add("</td><td>");
056        html.getBody().add("<p class=\"legalright\">");
057        html.getBody().add("copyright © 2003, jcoverage ltd. all rights reserved.<br>");
058        html.getBody().add("Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.<br>");
059        html.getBody().add("</td></tr></table>");
060      }
061      
062      protected void addViews(ViewFormattingContext ctx,Page page,Html html) {
063        MultiViewCollator collator=(MultiViewCollator)ctx.getCollator();
064        View[] views=ctx.getViews();
065        html.add(new H2("Set view:"));
066        html.add("<p class=\"view\">");
067        for (int i=0;i<views.length;i++) {
068          if (ctx.getCurrentView().equals(views[i])) {
069            html.getBody().add("<b>"+views[i].getLabel()+"</b>");
070          } else {
071            String href=collator.getPathToPage(ctx,page,page,views[i]);
072            html.getBody().add("<a href=\""+href+"\">"+views[i].getLabel()+"</a>");
073          }
074          html.add("<br>");
075        }
076      }
077    }