1 23 24 package org.hammurapi.render.dom; 25 26 import java.text.SimpleDateFormat ; 27 28 import org.hammurapi.results.AggregatedResults; 29 import org.hammurapi.results.BasicResults; 30 import org.hammurapi.results.CompositeResults; 31 import org.hammurapi.results.DetailedResults; 32 import org.hammurapi.results.NamedResults; 33 import org.w3c.dom.Document ; 34 import org.w3c.dom.Element ; 35 36 import com.pavelvlasov.render.RenderRequest; 37 import com.pavelvlasov.render.RenderingException; 38 import com.pavelvlasov.render.dom.AbstractRenderer; 39 40 45 public class BasicResultsRenderer extends AbstractRenderer { 46 47 public BasicResultsRenderer(RenderRequest request) { 48 super(request); 49 } 50 51 public BasicResultsRenderer(RenderRequest request, String profile) { 52 super(request, profile); 53 } 54 55 public Element render(Document document) throws RenderingException { 56 Element ret=document.createElement("results"); 57 BasicResults br=(BasicResults) request.getRenderee(); 58 59 ret.setAttribute("violation-level", String.valueOf(br.getViolationLevel())); 60 ret.setAttribute("reviews", String.valueOf(br.getReviewsNumber())); 61 ret.setAttribute("code-base", String.valueOf(br.getCodeBase())); 62 ret.setAttribute("violations", String.valueOf(br.getViolationsNumber())); 63 ret.setAttribute("waived-violations", String.valueOf(br.getWaivedViolationsNumber())); 64 ret.setAttribute("dpmo", br.getDPMO()); 65 ret.setAttribute("sigma", br.getSigma()); 66 SimpleDateFormat sdf=new SimpleDateFormat ("yyyy/MM/dd"); 67 ret.setAttribute("date", sdf.format(br.getDate())); 68 if (br.getMaxSeverity()!=null) { 69 ret.setAttribute("max-severity", br.getMaxSeverity().toString()); 70 } 71 72 return ret; 73 } 74 75 85 public static BasicResultsRenderer newRenderer(RenderRequest request) { 86 if (request.getRenderee() instanceof CompositeResults) { 87 return new CompositeResultsRenderer(request); 88 } else if (request.getRenderee() instanceof DetailedResults) { 89 return new DetailedResultsRenderer(request); 90 } else if (request.getRenderee() instanceof NamedResults) { 91 return new NamedResultsRenderer(request); 92 } else if (request.getRenderee() instanceof AggregatedResults) { 93 return new AggregatedResultsRenderer(request); 94 } else { 95 return new BasicResultsRenderer(request); 96 } 97 } 98 } 99 | Popular Tags |