KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.hammurapi.Violation;
27 import org.w3c.dom.Document JavaDoc;
28 import org.w3c.dom.Element JavaDoc;
29
30 import com.pavelvlasov.render.RenderRequest;
31 import com.pavelvlasov.render.RenderingException;
32 import com.pavelvlasov.render.dom.AbstractRenderer;
33 import com.pavelvlasov.render.dom.DomRenderer;
34 import com.pavelvlasov.review.Signed;
35
36 /**
37  *
38  * @author Pavel Vlasov
39  * @version $Revision: 1.4 $
40  */

41 public class ViolationRenderer extends AbstractRenderer {
42     
43     /** Creates a new instance of ViolationEntryRenderer */
44     public ViolationRenderer(RenderRequest request) {
45         super(request);
46     }
47     
48     public Element JavaDoc render(Document JavaDoc document) throws RenderingException {
49         Element JavaDoc ret=document.createElement("violation");
50         Violation ve=(Violation) request.getRenderee();
51         
52         if (ve.getSource()!=null) {
53             int line = ve.getSource().getLine();
54             if (line!=0) {
55                 ret.setAttribute("line", String.valueOf(line));
56             }
57                     
58             int column = ve.getSource().getColumn();
59             if (column!=0) {
60                 ret.setAttribute("col", String.valueOf(column));
61             }
62             
63             String JavaDoc sourceURL = ve.getSource().getSourceURL();
64             if (sourceURL!=null) {
65                 ret.setAttribute("source-url", sourceURL);
66             }
67             
68             if (ve.getSource() instanceof Signed) {
69                 String JavaDoc signature = ((Signed) ve.getSource()).getSignature();
70                 if (signature!=null) {
71                     ret.setAttribute("signature", signature);
72                 }
73             }
74         }
75         
76         Element JavaDoc me=document.createElement("message");
77         ret.appendChild(me);
78         me.appendChild(document.createTextNode(ve.getMessage()));
79         if (ve.getDescriptor()!=null) {
80             DomRenderer rdr=new InspectorDescriptorRenderer(new RenderRequest(ve.getDescriptor()));
81             ret.appendChild(rdr.render(document));
82         }
83         return ret;
84     }
85     
86 }
Popular Tags