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.util.Iterator;
027:
028: import org.hammurapi.Inspector;
029: import org.hammurapi.InspectorDescriptor;
030: import org.w3c.dom.Document;
031: import org.w3c.dom.Element;
032:
033: import com.pavelvlasov.config.ConfigurationException;
034: import com.pavelvlasov.render.RenderRequest;
035: import com.pavelvlasov.render.RenderingException;
036: import com.pavelvlasov.render.dom.AbstractRenderer;
037:
038: /**
039: *
040: * @author Pavel Vlasov
041: * @version $Revision: 1.4 $
042: */
043: public class InspectorDescriptorRenderer extends AbstractRenderer {
044:
045: /** Creates a new instance of InspectorDescriptorRendrerer */
046: public InspectorDescriptorRenderer(RenderRequest request) {
047: super (request);
048: }
049:
050: public Element render(Document document) throws RenderingException {
051: Element ret = document.createElement("inspector-descriptor");
052: InspectorDescriptor descriptor = (InspectorDescriptor) request
053: .getRenderee();
054:
055: if (descriptor.getDescription() != null) {
056: ret.appendChild(document.createElement("description"))
057: .appendChild(
058: document.createTextNode(descriptor
059: .getDescription()));
060: }
061:
062: if (descriptor.getMessage() != null) {
063: ret.appendChild(document.createElement("message"))
064: .appendChild(
065: document.createTextNode(descriptor
066: .getMessage()));
067: }
068:
069: try {
070: if (descriptor.getInspector() != null) {
071: Element inspectorElement = document
072: .createElement("inspector");
073: inspectorElement.setAttribute("type", descriptor
074: .getInspector().getClass().getName());
075: ret.appendChild(inspectorElement);
076: }
077: } catch (ConfigurationException e) {
078: throw new RenderingException(e);
079: }
080:
081: if (descriptor.isEnabled() != null) {
082: ret
083: .appendChild(document.createElement("enabled"))
084: .appendChild(
085: document
086: .createTextNode(Boolean.TRUE
087: .equals(descriptor
088: .isEnabled()) ? "yes"
089: : "no"));
090: }
091:
092: if (descriptor.isWaivable() != null) {
093: ret
094: .appendChild(document.createElement("waivable"))
095: .appendChild(
096: document
097: .createTextNode(Boolean.TRUE
098: .equals(descriptor
099: .isWaivable()) ? "yes"
100: : "no"));
101: }
102:
103: if (descriptor.getName() != null) {
104: ret.appendChild(document.createElement("name"))
105: .appendChild(
106: document.createTextNode(descriptor
107: .getName()));
108: }
109:
110: if (descriptor.getSeverity() != null) {
111: ret.appendChild(document.createElement("severity"))
112: .appendChild(
113: document.createTextNode(descriptor
114: .getSeverity().toString()));
115: }
116:
117: if (descriptor.getOrder() != null) {
118: ret.appendChild(document.createElement("order"))
119: .appendChild(
120: document.createTextNode(descriptor
121: .getOrder().toString()));
122: }
123:
124: if (descriptor.getRationale() != null) {
125: ret.appendChild(document.createElement("rationale"))
126: .appendChild(
127: document.createTextNode(descriptor
128: .getRationale()));
129: }
130:
131: if (descriptor.getViolationSample() != null) {
132: ret.appendChild(document.createElement("violation-sample"))
133: .appendChild(
134: document.createTextNode(descriptor
135: .getViolationSample()));
136: }
137:
138: if (descriptor.getFixSample() != null) {
139: ret.appendChild(document.createElement("fix-sample"))
140: .appendChild(
141: document.createTextNode(descriptor
142: .getFixSample()));
143: }
144:
145: if (descriptor.getResources() != null) {
146: ret.appendChild(document.createElement("resources"))
147: .appendChild(
148: document.createTextNode(descriptor
149: .getResources()));
150: }
151:
152: if (descriptor.getCategory() != null) {
153: ret.appendChild(document.createElement("category"))
154: .appendChild(
155: document.createTextNode(descriptor
156: .getCategory()));
157: }
158:
159: // Iterator it=descriptor.getParameters().entrySet().iterator();
160: // while (it.hasNext()) {
161: // Map.Entry entry=(Map.Entry) it.next();
162: // Element e=document.createElement("parameter");
163: // ret.appendChild(e);
164: // e.setAttribute("name", (String) entry.getKey());
165: // e.appendChild(document.createTextNode((String) entry.getValue()));
166: // }
167:
168: Iterator it = descriptor.getWaiveCases().iterator();
169: while (it.hasNext()) {
170: Element e = document.createElement("waive-case");
171: ret.appendChild(e);
172: e.appendChild(document.createTextNode((String) it.next()));
173: }
174:
175: try {
176: Inspector inspector = descriptor.getInspector();
177: if (inspector != null) {
178: String inspectorConfigInfo = inspector.getConfigInfo();
179: if (inspectorConfigInfo != null) {
180: ret
181: .appendChild(
182: document
183: .createElement("config-info"))
184: .appendChild(
185: document
186: .createTextNode(inspectorConfigInfo));
187: }
188: }
189: } catch (ConfigurationException e) {
190: throw new RenderingException(
191: "Unable to read inspector configuration info", e);
192: }
193:
194: return ret;
195: }
196: }
|