package switchyard.qa.audit.common; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import switchyard.qa.audit.common.AuditChecker.Property; public class AuditDiagram { public AuditDiagram() { } public void generate(List data, File path) { String html = ""; html += body; html += ""; try { new FileOutputStream(path).write(html.getBytes()); } catch (IOException ex) { ex.printStackTrace(); } } private String prettyXmlString(String p) { p = p.replaceAll("(<[^&: ]+:|<)([^&? ]+)([^&?]+)?>","$1$2$3>"); // tooltips String xmlnsregex = " xmlns:?([^=]+)?=\"([^\"]+)\""; Pattern pat = Pattern.compile(xmlnsregex); // xmlns:exam="http://www.jboss.org/bpel/examples" Matcher m = pat.matcher(p); while (m.find()) { String ns = m.group(1); String url = m.group(2); String tagns = "<(" + ns + ":[^&]+)"; // <exam:price>10</exam:price> if (ns == null) { tagns = "<([^&]+)( xmlns)|>"; // <productOrderResp>valid</productOrderResp> } Pattern elm = Pattern.compile(tagns); Matcher m2 = elm.matcher(p); while (m2.find()) { String tag = m2.group(1); if (tag != null) { p = p.replaceAll(tag, "" + tag + ""); } } } p = p.replaceAll(xmlnsregex, ""); // remove namespaces return "
"+p+"
"; } public static String prettyFormat(String input, int indent) { try { Source xmlInput = new StreamSource(new StringReader(input)); StringWriter stringWriter = new StringWriter(); StreamResult xmlOutput = new StreamResult(stringWriter); TransformerFactory transformerFactory = TransformerFactory.newInstance(); transformerFactory.setAttribute("indent-number", indent); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.transform(xmlInput, xmlOutput); return xmlOutput.getWriter().toString(); } catch (Exception e) { e.printStackTrace(); return null; } } private String escape(String p) { if (p.contains("<")) { // isXml String pp = prettyFormat(p, 2); if (pp != null) { p = pp; } } p = p.replaceAll("<", "<"); p = p.replaceAll(">", ">"); p = p.replaceAll("\t", "    "); return p; } }