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 java.io.*; 026 027 import org.apache.log4j.Logger; 028 029 import com.jcoverage.reporting.Format; 030 import com.jcoverage.reporting.FormattingContext; 031 import com.jcoverage.reporting.Page; 032 import com.jcoverage.reporting.ReportingException; 033 import com.jcoverage.reporting.View; 034 import com.jcoverage.reporting.ViewFormattingContext; 035 036 import com.jcoverage.coverage.reporting.collation.PackageSummaryPage; 037 import com.jcoverage.coverage.reporting.collation.ReportSummaryPage; 038 import com.jcoverage.coverage.reporting.collation.JavaFilePage; 039 import com.jcoverage.coverage.reporting.collation.StaticFileCollator; 040 041 /** 042 * This class provides the generation of coverage reports in static 043 * html. Multiple views are defined by this class, and used to 044 * generate each page. Each view corresponds to a different line 045 * ordering, so that lines can be generated in alphabetical order, or 046 * by ascending or descending coverage. 047 */ 048 public class MultiViewStaticHtmlFormat implements Format { 049 050 static Logger logger=Logger.getLogger(MultiViewStaticHtmlFormat.class); 051 052 public final static View ALPHABETICAL_VIEW=new AlphabeticalView("By Name"); 053 public final static View COVERAGE_ASCENDING_VIEW=new CoverageView("By Coverage (Most covered first)",CoverageView.ASCENDING); 054 public final static View COVERAGE_DESCENDING_VIEW=new CoverageView("By Coverage (Least covered first)",CoverageView.DESCENDING); 055 056 public final static View[] ALL_VIEWS=new View[]{ALPHABETICAL_VIEW,COVERAGE_ASCENDING_VIEW,COVERAGE_DESCENDING_VIEW}; 057 058 public void formatPage(ViewFormattingContext ctx,Page page) throws ReportingException { 059 throw new IllegalStateException(getClass().getName()+" must be called with a plain FormattingContext"); 060 } 061 062 /** 063 * Implementation proxy. This implementation delegates to another 064 * formatPage implementation depending on the page. 065 * @throws ReportingException if the page is not recognized. 066 */ 067 public void formatPage(FormattingContext ctx,Page page) throws ReportingException { 068 069 if (page instanceof ReportSummaryPage || page instanceof PackageSummaryPage) { 070 071 Format format=null; 072 073 if (page instanceof ReportSummaryPage) { 074 format=new ReportSummaryFormat(); 075 } else if (page instanceof PackageSummaryPage) { 076 format=new PackageSummaryFormat(); 077 } 078 079 ViewFormattingContext viewContext=new ViewFormattingContext(ctx,ALL_VIEWS,ALPHABETICAL_VIEW); 080 format.formatPage(viewContext,page); 081 viewContext=new ViewFormattingContext(ctx,ALL_VIEWS,COVERAGE_ASCENDING_VIEW); 082 format.formatPage(viewContext,page); 083 viewContext=new ViewFormattingContext(ctx,ALL_VIEWS,COVERAGE_DESCENDING_VIEW); 084 format.formatPage(viewContext,page); 085 086 } else if (page instanceof JavaFilePage) { 087 088 Format format=new JavaFilePageFormat(); 089 format.formatPage(ctx,page); 090 091 } else { 092 throw new ReportingException("Don't know how to format a page of type "+page.getClass()); 093 } 094 095 } 096 097 }