001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.org
021: * e-Mail: support@hammurapi.biz
022: */
023:
024: package org.hammurapi.render.dom;
025:
026: import java.text.SimpleDateFormat;
027:
028: import org.hammurapi.results.AggregatedResults;
029: import org.hammurapi.results.BasicResults;
030: import org.hammurapi.results.CompositeResults;
031: import org.hammurapi.results.DetailedResults;
032: import org.hammurapi.results.NamedResults;
033: import org.w3c.dom.Document;
034: import org.w3c.dom.Element;
035:
036: import com.pavelvlasov.render.RenderRequest;
037: import com.pavelvlasov.render.RenderingException;
038: import com.pavelvlasov.render.dom.AbstractRenderer;
039:
040: /**
041: *
042: * @author Pavel Vlasov
043: * @version $Revision: 1.2 $
044: */
045: public class BasicResultsRenderer extends AbstractRenderer {
046:
047: public BasicResultsRenderer(RenderRequest request) {
048: super (request);
049: }
050:
051: public BasicResultsRenderer(RenderRequest request, String profile) {
052: super (request, profile);
053: }
054:
055: public Element render(Document document) throws RenderingException {
056: Element ret = document.createElement("results");
057: BasicResults br = (BasicResults) request.getRenderee();
058:
059: ret.setAttribute("violation-level", String.valueOf(br
060: .getViolationLevel()));
061: ret.setAttribute("reviews", String.valueOf(br
062: .getReviewsNumber()));
063: ret.setAttribute("code-base", String.valueOf(br.getCodeBase()));
064: ret.setAttribute("violations", String.valueOf(br
065: .getViolationsNumber()));
066: ret.setAttribute("waived-violations", String.valueOf(br
067: .getWaivedViolationsNumber()));
068: ret.setAttribute("dpmo", br.getDPMO());
069: ret.setAttribute("sigma", br.getSigma());
070: SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
071: ret.setAttribute("date", sdf.format(br.getDate()));
072: if (br.getMaxSeverity() != null) {
073: ret.setAttribute("max-severity", br.getMaxSeverity()
074: .toString());
075: }
076:
077: return ret;
078: }
079:
080: // public static String format(double d) {
081: // String ret=String.valueOf(d);
082: // int idx=ret.lastIndexOf('.');
083: // if (idx==-1) {
084: // return ret+".00";
085: // } else {
086: // return (ret+"000").substring(0, idx+3);
087: // }
088: // }
089:
090: public static BasicResultsRenderer newRenderer(RenderRequest request) {
091: if (request.getRenderee() instanceof CompositeResults) {
092: return new CompositeResultsRenderer(request);
093: } else if (request.getRenderee() instanceof DetailedResults) {
094: return new DetailedResultsRenderer(request);
095: } else if (request.getRenderee() instanceof NamedResults) {
096: return new NamedResultsRenderer(request);
097: } else if (request.getRenderee() instanceof AggregatedResults) {
098: return new AggregatedResultsRenderer(request);
099: } else {
100: return new BasicResultsRenderer(request);
101: }
102: }
103: }
|