1 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 41 public class ViolationRenderer extends AbstractRenderer { 42 43 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()).getSignature(); 70 if (signature!=null) { 71 ret.setAttribute("signature", signature); 72 } 73 } 74 } 75 76 Element 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 |