diff options
Diffstat (limited to 'collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java')
-rwxr-xr-x | collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java | 59 |
1 files changed, 45 insertions, 14 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java index f286f050b8..076e28fd70 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java @@ -22,6 +22,15 @@ package org.apache.tuscany.sca.impl.html; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; +import java.io.StringWriter; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Document; public class HTMLWrapper { @@ -30,6 +39,7 @@ public class HTMLWrapper { private String compositeName; private String svgFileName; private int compositeHeight, compositeWidth; + private Document svg; private static final String CANVG_LIB_DIR = System.getProperty("user.dir")+"/resources/"; private static final String CANVG_FILE = "canvg-1.0.js"; private static final String RGB_FILE = "rgbcolor.js"; @@ -42,9 +52,10 @@ public class HTMLWrapper { * @param compositeWidth * @param htmlFilePath */ - public HTMLWrapper(String compositeName, String svgFileName, + public HTMLWrapper(Document svg, String compositeName, String svgFileName, int compositeHeight, int compositeWidth, File htmlFilePath) { + this.svg = svg; this.compositeName = compositeName; this.svgFileName = svgFileName; this.compositeHeight = compositeHeight; @@ -59,27 +70,47 @@ public class HTMLWrapper { "<h1 align='center'>Apache Tuscany - Composite Diagram Generator</h1>\n" + "<h2 align='center'>"+compositeName+"</h2>\n" + "</br>\n" + - "<script type=\"text/javascript\" src=\""+CANVG_LIB_DIR+RGB_FILE+"\"></script>\n" + - "<script type=\"text/javascript\" src=\""+CANVG_LIB_DIR+CANVG_FILE+"\"></script>\n" + - "<script type=\"text/javascript\">\n" + - "window.onload = function() {\n" + - "//load '../path/to/your.svg' in the canvas with id = 'canvas'\n" + - "canvg('canvas', '"+svgFileName+"')\n" + - "//load a svg snippet in the canvas with id = 'drawingArea'\n" + - "canvg(document.getElementById('drawingArea'), '<svg>...</svg>')\n" + - "canvg('canvas', '"+svgFileName+"', {})\n" + - "}\n" + - "</script>\n" + +// "<script type=\"text/javascript\" src=\""+CANVG_LIB_DIR+RGB_FILE+"\"></script>\n" + +// "<script type=\"text/javascript\" src=\""+CANVG_LIB_DIR+CANVG_FILE+"\"></script>\n" + +// "<script type=\"text/javascript\">\n" + +// "window.onload = function() {\n" + +// "//load '../path/to/your.svg' in the canvas with id = 'canvas'\n" + +// "canvg('canvas', '"+svgFileName+"')\n" + +// "//load a svg snippet in the canvas with id = 'drawingArea'\n" + +// "canvg(document.getElementById('drawingArea'), '<svg>...</svg>')\n" + +// "canvg('canvas', '"+svgFileName+"', {})\n" + +// "}\n" + +// "</script>\n" + "</head>\n" + "<body>\n" + - "<canvas id=\"canvas\" width=\""+compositeWidth+"px\" height=\""+compositeHeight+"px\">\n" + - "</canvas>\n" + + extractSvg()+"\n"+ +// "<canvas id=\"canvas\" width=\""+compositeWidth+"px\" height=\""+compositeHeight+"px\">\n" + +// "</canvas>\n" + "</body>\n" + "</html>"; fileWriter(content); } + + public String extractSvg() throws Exception{ + + // Set up the output transformer + TransformerFactory transfac = TransformerFactory.newInstance(); + Transformer trans = transfac.newTransformer(); + + // Print the DOM node + + StringWriter sw = new StringWriter(); + StreamResult result = new StreamResult(sw); + DOMSource source = new DOMSource(svg); + trans.transform(source, result); + String svgString = sw.toString(); + + System.out.println(svgString); + + return svgString; + } private void fileWriter(String content) throws Exception{ |