01: /*
02: * Hammurapi
03: * Automated Java code review system.
04: * Copyright (C) 2004 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (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;
28: import org.w3c.dom.Element;
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 render(Document document) throws RenderingException {
49: Element 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 sourceURL = ve.getSource().getSourceURL();
64: if (sourceURL != null) {
65: ret.setAttribute("source-url", sourceURL);
66: }
67:
68: if (ve.getSource() instanceof Signed) {
69: String signature = ((Signed) ve.getSource())
70: .getSignature();
71: if (signature != null) {
72: ret.setAttribute("signature", signature);
73: }
74: }
75: }
76:
77: Element me = document.createElement("message");
78: ret.appendChild(me);
79: me.appendChild(document.createTextNode(ve.getMessage()));
80: if (ve.getDescriptor() != null) {
81: DomRenderer rdr = new InspectorDescriptorRenderer(
82: new RenderRequest(ve.getDescriptor()));
83: ret.appendChild(rdr.render(document));
84: }
85: return ret;
86: }
87:
88: }
|