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.text.SimpleDateFormat;
027: import java.util.Collection;
028: import java.util.Iterator;
029:
030: import org.hammurapi.Waiver;
031: import org.hammurapi.WaiverEntry;
032: import org.hammurapi.results.DetailedResults;
033: import org.w3c.dom.Document;
034: import org.w3c.dom.Element;
035: import org.w3c.dom.Node;
036:
037: import com.pavelvlasov.render.RenderRequest;
038: import com.pavelvlasov.render.RenderingException;
039:
040: /**
041: *
042: * @author Pavel Vlasov
043: * @version $Revision: 1.4 $
044: */
045: public class DetailedResultsRenderer extends NamedResultsRenderer {
046:
047: public DetailedResultsRenderer(RenderRequest request) {
048: super (request);
049: }
050:
051: public DetailedResultsRenderer(RenderRequest request, String profile) {
052: super (request, profile);
053: }
054:
055: public Element render(Document document) throws RenderingException {
056: Element ret = super .render(document);
057: Iterator it = ((DetailedResults) request.getRenderee())
058: .getViolations().iterator();
059: while (it.hasNext()) {
060: ViolationRenderer ver = new ViolationRenderer(
061: new RenderRequest(it.next()));
062: ret.appendChild(ver.render(document));
063: }
064:
065: it = ((DetailedResults) request.getRenderee())
066: .getWaivedViolations().iterator();
067: while (it.hasNext()) {
068: WaiverEntry waiverEntry = (WaiverEntry) it.next();
069: Element waivedViolationElement = document
070: .createElement("waived-violation");
071: ret.appendChild(waivedViolationElement);
072: ViolationRenderer ver = new ViolationRenderer(
073: new RenderRequest(waiverEntry.getViolation()));
074: waivedViolationElement.appendChild(ver.render(document));
075: waivedViolationElement.appendChild(renderWaiver(waiverEntry
076: .getWaiver(), document));
077: }
078:
079: // String[] im=((SimpleDetailedResults) renderee).getIncompleteMessages();
080: // for (int i=0; i<im.length; i++) {
081: // Element ie=document.createElement("incomplete");
082: // ie.appendChild(document.createTextNode(im[i]));
083: // ret.appendChild(ie);
084: // }
085: //
086: return ret;
087: }
088:
089: public static Node renderWaiver(Waiver waiver, Document document) {
090: Element ret = document.createElement("waiver");
091:
092: appendTextElement("inspector-name", waiver.getInspectorName(),
093: ret);
094: Collection signatures = waiver.getSignatures();
095: if (signatures != null) {
096: Iterator it = signatures.iterator();
097: while (it.hasNext()) {
098: appendTextElement("signature", (String) it.next(), ret);
099: }
100: }
101:
102: appendTextElement("reason", waiver.getReason(), ret);
103: if (waiver.getExpirationDate() != null) {
104: SimpleDateFormat sdf = new SimpleDateFormat(
105: Waiver.DATE_FORMAT);
106: appendTextElement("expiration-date", sdf.format(waiver
107: .getExpirationDate()), ret);
108: }
109:
110: return ret;
111: }
112: }
|