KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > render > dom > BasicResultsRenderer


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.org
21  * e-Mail: support@hammurapi.biz
22  */

23
24 package org.hammurapi.render.dom;
25
26 import java.text.SimpleDateFormat JavaDoc;
27
28 import org.hammurapi.results.AggregatedResults;
29 import org.hammurapi.results.BasicResults;
30 import org.hammurapi.results.CompositeResults;
31 import org.hammurapi.results.DetailedResults;
32 import org.hammurapi.results.NamedResults;
33 import org.w3c.dom.Document JavaDoc;
34 import org.w3c.dom.Element JavaDoc;
35
36 import com.pavelvlasov.render.RenderRequest;
37 import com.pavelvlasov.render.RenderingException;
38 import com.pavelvlasov.render.dom.AbstractRenderer;
39
40 /**
41  *
42  * @author Pavel Vlasov
43  * @version $Revision: 1.2 $
44  */

45 public class BasicResultsRenderer extends AbstractRenderer {
46     
47     public BasicResultsRenderer(RenderRequest request) {
48         super(request);
49     }
50     
51     public BasicResultsRenderer(RenderRequest request, String JavaDoc profile) {
52         super(request, profile);
53     }
54     
55     public Element JavaDoc render(Document JavaDoc document) throws RenderingException {
56         Element JavaDoc ret=document.createElement("results");
57         BasicResults br=(BasicResults) request.getRenderee();
58
59         ret.setAttribute("violation-level", String.valueOf(br.getViolationLevel()));
60         ret.setAttribute("reviews", String.valueOf(br.getReviewsNumber()));
61         ret.setAttribute("code-base", String.valueOf(br.getCodeBase()));
62         ret.setAttribute("violations", String.valueOf(br.getViolationsNumber()));
63         ret.setAttribute("waived-violations", String.valueOf(br.getWaivedViolationsNumber()));
64         ret.setAttribute("dpmo", br.getDPMO());
65         ret.setAttribute("sigma", br.getSigma());
66         SimpleDateFormat JavaDoc sdf=new SimpleDateFormat JavaDoc("yyyy/MM/dd");
67         ret.setAttribute("date", sdf.format(br.getDate()));
68         if (br.getMaxSeverity()!=null) {
69             ret.setAttribute("max-severity", br.getMaxSeverity().toString());
70         }
71         
72         return ret;
73     }
74     
75 // public static String format(double d) {
76
// String ret=String.valueOf(d);
77
// int idx=ret.lastIndexOf('.');
78
// if (idx==-1) {
79
// return ret+".00";
80
// } else {
81
// return (ret+"000").substring(0, idx+3);
82
// }
83
// }
84

85     public static BasicResultsRenderer newRenderer(RenderRequest request) {
86         if (request.getRenderee() instanceof CompositeResults) {
87             return new CompositeResultsRenderer(request);
88         } else if (request.getRenderee() instanceof DetailedResults) {
89             return new DetailedResultsRenderer(request);
90         } else if (request.getRenderee() instanceof NamedResults) {
91             return new NamedResultsRenderer(request);
92         } else if (request.getRenderee() instanceof AggregatedResults) {
93             return new AggregatedResultsRenderer(request);
94         } else {
95             return new BasicResultsRenderer(request);
96         }
97     }
98 }
99
Popular Tags