summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main
diff options
context:
space:
mode:
authornirmal070125 <nirmal070125@13f79535-47bb-0310-9956-ffa450edef68>2011-08-15 14:55:26 +0000
committernirmal070125 <nirmal070125@13f79535-47bb-0310-9956-ffa450edef68>2011-08-15 14:55:26 +0000
commit6bbfb01ef30081f9c7ec6b9d4b41facef5090578 (patch)
tree7abd6af5e1070801736c13417697896c622d18e8 /collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main
parent4f933606e0fa045116e70764dbf9d99c05484ccb (diff)
HTMLWrapper is modified, and avoided the use of Canvg.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1157868 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java59
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java21
2 files changed, 64 insertions, 16 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{
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
index ce1d6600b9..191d98b6b7 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java
@@ -37,9 +37,26 @@ public class Main {
* @throws Exception
*/
public static void main(String[] args) throws Exception {
+
+// if(args.length == 0){
+//
+// String help = "" +
+// "----------Apache Tuscany Composite Diagram Generator----------\n" +
+// "\n" +
+// "Error: You have not specified an input \"Composite XML\" file.\n" +
+// "\n" +
+// "-----------------------------Help-----------------------------\n" +
+// "You have 3 options:\n" +
+// "---1) Default: Specify \"Composite XML\" file paths separated \n" +
+// "--- by a space, with no arguments.\n" +
+// "--- Eg: java CompositeDiagramGenerator \\a\\aa\\a.composite \\b\\b\\b.composite \n" +
+// "---" +
+// "---2) SVG Only";
+// System.out.println();
+// }
XMLReader reader = new XMLReader();
- Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite2.xml");//composite1.xml composite_with_compositeService.xml");
+ Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite_with_compositeService.xml");//composite1.xml composite_with_compositeService.xml");
EntityBuilder eb = new EntityBuilder(doc);
CompositeEntity comp =eb.buildCompositeEntity();
@@ -52,7 +69,7 @@ public class Main {
writer.fileWriter(svg, svgFile);
File htmlFile = new File(outFileDir + comp.getName()+ comp.getFileNameSuffix()+".html");
- HTMLWrapper html = new HTMLWrapper(comp.getName(), svgFileName, dg.getDiagramHeight(),
+ HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), svgFileName, dg.getDiagramHeight(),
dg.getDiagramWidth(), htmlFile);
html.buildHTML();
}