summaryrefslogtreecommitdiffstats
path: root/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main')
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java28
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java93
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java2
-rwxr-xr-xcollaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/main/Main.java13
4 files changed, 129 insertions, 7 deletions
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
index 544ce37a2f..df366581de 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/diagram/DiagramGenerator.java
@@ -52,6 +52,7 @@ public class DiagramGenerator {
private Element svgRoot;
private ArrayList<ReferenceArtifact> refs= new ArrayList<ReferenceArtifact>();
private ArrayList<ServiceArtifact> sers= new ArrayList<ServiceArtifact>();
+ private int diagramHeight, diagramWidth;
private int lastUsedChangingFactor = 0;
enum changingFactor{a(20), b(25), c(30), d(35), e(40), f(15);
@@ -92,6 +93,11 @@ public class DiagramGenerator {
// Get the root element (the 'svg' element).
svgRoot = doc.getDocumentElement();
+
+ setDiagramHeight(comp.getHeight()+200);
+ setDiagramWidth(comp.getWidth()+400);
+
+ svgRoot.setAttributeNS(null, "viewBox", "0 0 "+getDiagramWidth()+" "+getDiagramHeight());
addLayer();
addComposite();
@@ -118,9 +124,9 @@ public class DiagramGenerator {
}
private void addLayer() {
-
+
Layer outerLayer = new Layer();
- Element layerElt = outerLayer.addElement(doc, svgNS, 0, 0, comp.getHeight()+200, comp.getWidth()+400);
+ Element layerElt = outerLayer.addElement(doc, svgNS, 0, 0, getDiagramHeight(), getDiagramWidth() );
svgRoot.appendChild(layerElt);
}
@@ -187,7 +193,7 @@ public class DiagramGenerator {
for(String includedComposite : comp.getIncludedComposites()){
Link link = new Link();
- Element aLink = link.addElement(doc, svgNS, includedComposite+comp.getFileNameSuffix(), includedComposite);
+ Element aLink = link.addElement(doc, svgNS, includedComposite+comp.getFileNameSuffix()+".svg", includedComposite);
text.appendChild(aLink);
}
@@ -562,6 +568,22 @@ public class DiagramGenerator {
}
+ public void setDiagramHeight(int diagramHeight) {
+ this.diagramHeight = diagramHeight;
+ }
+
+ public int getDiagramHeight() {
+ return diagramHeight;
+ }
+
+ public void setDiagramWidth(int diagramWidth) {
+ this.diagramWidth = diagramWidth;
+ }
+
+ public int getDiagramWidth() {
+ return diagramWidth;
+ }
+
}
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
new file mode 100755
index 0000000000..f286f050b8
--- /dev/null
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.impl.html;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+
+
+public class HTMLWrapper {
+
+ private File htmlFilePath;
+ private String compositeName;
+ private String svgFileName;
+ private int compositeHeight, compositeWidth;
+ 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";
+
+ /**
+ *
+ * @param compositeName
+ * @param svgFileName
+ * @param compositeHeight
+ * @param compositeWidth
+ * @param htmlFilePath
+ */
+ public HTMLWrapper(String compositeName, String svgFileName,
+ int compositeHeight, int compositeWidth, File htmlFilePath) {
+
+ this.compositeName = compositeName;
+ this.svgFileName = svgFileName;
+ this.compositeHeight = compositeHeight;
+ this.compositeWidth = compositeWidth;
+ this.htmlFilePath = htmlFilePath;
+ }
+
+ public void buildHTML() throws Exception{
+ String content = "" +
+ "<html>\n" +
+ "<head>\n" +
+ "<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" +
+ "</head>\n" +
+ "<body>\n" +
+ "<canvas id=\"canvas\" width=\""+compositeWidth+"px\" height=\""+compositeHeight+"px\">\n" +
+ "</canvas>\n" +
+ "</body>\n" +
+ "</html>";
+
+ fileWriter(content);
+
+ }
+
+
+ private void fileWriter(String content) throws Exception{
+
+ FileWriter fileWriter = new FileWriter(htmlFilePath);
+ BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
+ bufferedWriter.append(content);
+ bufferedWriter.close();
+
+ }
+}
diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java
index c7f1142964..aa98c3db65 100755
--- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java
+++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/layout/CompositeEntity.java
@@ -44,7 +44,7 @@ public class CompositeEntity extends Entity{
// public static final int defaultNoOfRefs= Component.DEFAULT_HEIGHT / (Reference.MAXIMUM_HEIGHT+Reference.SPACING); //same value for defaultNoOfSers
// public static final int defaultNoOfProps= Component.DEFAULT_WIDTH / (Property.MAXIMUM_HEIGHT+Property.SPACING);
- private final String fileNameSuffix = "_diagram.svg";
+ private final String fileNameSuffix = "_diagram";
private int maxInternalLevel=0;
private int maxInternalLane=0;
private ComponentEntity[] componentList;
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 f56c88aed4..ce1d6600b9 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
@@ -22,6 +22,7 @@ package org.apache.tuscany.sca.main;
import java.io.File;
import org.apache.tuscany.sca.impl.diagram.DiagramGenerator;
+import org.apache.tuscany.sca.impl.html.HTMLWrapper;
import org.apache.tuscany.sca.impl.io.XMLReader;
import org.apache.tuscany.sca.impl.io.XMLWriter;
import org.apache.tuscany.sca.impl.layout.CompositeEntity;
@@ -38,16 +39,22 @@ public class Main {
public static void main(String[] args) throws Exception {
XMLReader reader = new XMLReader();
- Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite_with_compositeService.xml");//composite1.xml composite_with_compositeService.xml");
+ Document doc =reader.parseXMLFile(System.getProperty("user.dir")+"/input/composite2.xml");//composite1.xml composite_with_compositeService.xml");
EntityBuilder eb = new EntityBuilder(doc);
CompositeEntity comp =eb.buildCompositeEntity();
DiagramGenerator dg = new DiagramGenerator(comp);
Document svg =dg.buildSVGDocument();
- File outFile = new File(outFileDir + comp.getName()+ comp.getFileNameSuffix());
+ String svgFileName = comp.getName()+ comp.getFileNameSuffix()+".svg";
+ File svgFile = new File(outFileDir + svgFileName);
XMLWriter writer = new XMLWriter();
- writer.fileWriter(svg, outFile);
+ writer.fileWriter(svg, svgFile);
+
+ File htmlFile = new File(outFileDir + comp.getName()+ comp.getFileNameSuffix()+".html");
+ HTMLWrapper html = new HTMLWrapper(comp.getName(), svgFileName, dg.getDiagramHeight(),
+ dg.getDiagramWidth(), htmlFile);
+ html.buildHTML();
}
}