1 23 24 package org.hammurapi.render.dom; 25 26 import java.util.Iterator ; 27 28 import org.hammurapi.Inspector; 29 import org.hammurapi.InspectorDescriptor; 30 import org.w3c.dom.Document ; 31 import org.w3c.dom.Element ; 32 33 import com.pavelvlasov.config.ConfigurationException; 34 import com.pavelvlasov.render.RenderRequest; 35 import com.pavelvlasov.render.RenderingException; 36 import com.pavelvlasov.render.dom.AbstractRenderer; 37 38 43 public class InspectorDescriptorRenderer extends AbstractRenderer { 44 45 46 public InspectorDescriptorRenderer(RenderRequest request) { 47 super(request); 48 } 49 50 public Element render(Document document) throws RenderingException { 51 Element ret=document.createElement("inspector-descriptor"); 52 InspectorDescriptor descriptor=(InspectorDescriptor) request.getRenderee(); 53 54 if (descriptor.getDescription()!=null) { 55 ret 56 .appendChild(document.createElement("description")) 57 .appendChild(document.createTextNode(descriptor.getDescription())); 58 } 59 60 if (descriptor.getMessage()!=null) { 61 ret 62 .appendChild(document.createElement("message")) 63 .appendChild(document.createTextNode(descriptor.getMessage())); 64 } 65 66 try { 67 if (descriptor.getInspector()!=null) { 68 Element inspectorElement=document.createElement("inspector"); 69 inspectorElement.setAttribute("type", descriptor.getInspector().getClass().getName()); 70 ret.appendChild(inspectorElement); 71 } 72 } catch (ConfigurationException e) { 73 throw new RenderingException(e); 74 } 75 76 if (descriptor.isEnabled()!=null) { 77 ret 78 .appendChild(document.createElement("enabled")) 79 .appendChild(document.createTextNode(Boolean.TRUE.equals(descriptor.isEnabled()) ? "yes" : "no")); 80 } 81 82 if (descriptor.isWaivable()!=null) { 83 ret 84 .appendChild(document.createElement("waivable")) 85 .appendChild(document.createTextNode(Boolean.TRUE.equals(descriptor.isWaivable()) ? "yes" : "no")); 86 } 87 88 if (descriptor.getName()!=null) { 89 ret 90 .appendChild(document.createElement("name")) 91 .appendChild(document.createTextNode(descriptor.getName())); 92 } 93 94 if (descriptor.getSeverity()!=null) { 95 ret 96 .appendChild(document.createElement("severity")) 97 .appendChild(document.createTextNode(descriptor.getSeverity().toString())); 98 } 99 100 if (descriptor.getOrder()!=null) { 101 ret 102 .appendChild(document.createElement("order")) 103 .appendChild(document.createTextNode(descriptor.getOrder().toString())); 104 } 105 106 if (descriptor.getRationale()!=null) { 107 ret 108 .appendChild(document.createElement("rationale")) 109 .appendChild(document.createTextNode(descriptor.getRationale())); 110 } 111 112 if (descriptor.getViolationSample()!=null) { 113 ret 114 .appendChild(document.createElement("violation-sample")) 115 .appendChild(document.createTextNode(descriptor.getViolationSample())); 116 } 117 118 if (descriptor.getFixSample()!=null) { 119 ret 120 .appendChild(document.createElement("fix-sample")) 121 .appendChild(document.createTextNode(descriptor.getFixSample())); 122 } 123 124 if (descriptor.getResources()!=null) { 125 ret 126 .appendChild(document.createElement("resources")) 127 .appendChild(document.createTextNode(descriptor.getResources())); 128 } 129 130 if (descriptor.getCategory()!=null) { 131 ret 132 .appendChild(document.createElement("category")) 133 .appendChild(document.createTextNode(descriptor.getCategory())); 134 } 135 136 145 Iterator it=descriptor.getWaiveCases().iterator(); 146 while (it.hasNext()) { 147 Element e=document.createElement("waive-case"); 148 ret.appendChild(e); 149 e.appendChild(document.createTextNode((String ) it.next())); 150 } 151 152 try { 153 Inspector inspector=descriptor.getInspector(); 154 if (inspector!=null) { 155 String inspectorConfigInfo=inspector.getConfigInfo(); 156 if (inspectorConfigInfo!=null) { 157 ret 158 .appendChild(document.createElement("config-info")) 159 .appendChild(document.createTextNode(inspectorConfigInfo)); 160 } 161 } 162 } catch (ConfigurationException e) { 163 throw new RenderingException("Unable to read inspector configuration info", e); 164 } 165 166 return ret; 167 } 168 } 169 | Popular Tags |