KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.Collection JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 import org.hammurapi.Waiver;
31 import org.hammurapi.WaiverEntry;
32 import org.hammurapi.results.DetailedResults;
33 import org.w3c.dom.Document JavaDoc;
34 import org.w3c.dom.Element JavaDoc;
35 import org.w3c.dom.Node JavaDoc;
36
37 import com.pavelvlasov.render.RenderRequest;
38 import com.pavelvlasov.render.RenderingException;
39
40 /**
41  *
42  * @author Pavel Vlasov
43  * @version $Revision: 1.4 $
44  */

45 public class DetailedResultsRenderer extends NamedResultsRenderer {
46     
47     public DetailedResultsRenderer(RenderRequest request) {
48         super(request);
49     }
50     
51     public DetailedResultsRenderer(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=super.render(document);
57         Iterator JavaDoc it=((DetailedResults) request.getRenderee()).getViolations().iterator();
58         while (it.hasNext()) {
59             ViolationRenderer ver=new ViolationRenderer(new RenderRequest(it.next()));
60             ret.appendChild(ver.render(document));
61         }
62         
63         it=((DetailedResults) request.getRenderee()).getWaivedViolations().iterator();
64         while (it.hasNext()) {
65             WaiverEntry waiverEntry=(WaiverEntry) it.next();
66             Element JavaDoc waivedViolationElement=document.createElement("waived-violation");
67             ret.appendChild(waivedViolationElement);
68             ViolationRenderer ver=new ViolationRenderer(new RenderRequest(waiverEntry.getViolation()));
69             waivedViolationElement.appendChild(ver.render(document));
70             waivedViolationElement.appendChild(renderWaiver(waiverEntry.getWaiver(), document));
71         }
72         
73 // String[] im=((SimpleDetailedResults) renderee).getIncompleteMessages();
74
// for (int i=0; i<im.length; i++) {
75
// Element ie=document.createElement("incomplete");
76
// ie.appendChild(document.createTextNode(im[i]));
77
// ret.appendChild(ie);
78
// }
79
//
80
return ret;
81     }
82
83     public static Node JavaDoc renderWaiver(Waiver waiver, Document JavaDoc document) {
84         Element JavaDoc ret=document.createElement("waiver");
85         
86         appendTextElement("inspector-name", waiver.getInspectorName(), ret);
87         Collection JavaDoc signatures = waiver.getSignatures();
88         if (signatures!=null) {
89             Iterator JavaDoc it=signatures.iterator();
90             while (it.hasNext()) {
91                 appendTextElement("signature", (String JavaDoc) it.next(), ret);
92             }
93         }
94         
95         appendTextElement("reason", waiver.getReason(), ret);
96         if (waiver.getExpirationDate()!=null) {
97             SimpleDateFormat JavaDoc sdf=new SimpleDateFormat JavaDoc(Waiver.DATE_FORMAT);
98             appendTextElement("expiration-date", sdf.format(waiver.getExpirationDate()), ret);
99         }
100         
101         return ret;
102     }
103 }
104
Popular Tags