From d5666317e966bf7609d112d079ddd089f1ce298c Mon Sep 17 00:00:00 2001 From: nirmal070125 Date: Sat, 13 Aug 2011 06:17:54 +0000 Subject: Adding HTML wrapper and fixing the SVG not totally viewable problem, using SVG view box git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1157335 13f79535-47bb-0310-9956-ffa450edef68 --- .../input/Calculator.xml | 49 ++++++++++++ .../input/MyValueComposite2.xml | 91 +++++++++++++++++++++ .../input/composite_idle.xml | 31 ++++++++ .../input/store.xml | 64 +++++++++++++++ .../input/supplychain.xml | 47 +++++++++++ .../output/Calculator_diagram.html | 22 +++++ .../output/Calculator_diagram.svg | 2 +- .../output/IdleTest_diagram.svg | 1 + .../output/MyValueComposite2_diagram.html | 22 +++++ .../output/MyValueComposite2_diagram.svg | 2 +- .../output/store_diagram.html | 22 +++++ .../output/store_diagram.svg | 2 +- .../output/supplychain_diagram.html | 22 +++++ .../output/supplychain_diagram.svg | 2 +- .../tuscany/sca/impl/diagram/DiagramGenerator.java | 28 ++++++- .../apache/tuscany/sca/impl/html/HTMLWrapper.java | 93 ++++++++++++++++++++++ .../tuscany/sca/impl/layout/CompositeEntity.java | 2 +- .../java/org/apache/tuscany/sca/main/Main.java | 13 ++- 18 files changed, 504 insertions(+), 11 deletions(-) create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/Calculator.xml create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/MyValueComposite2.xml create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_idle.xml create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/store.xml create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/supplychain.xml create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.html create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/IdleTest_diagram.svg create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.html create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.html create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.html create mode 100755 collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/impl/html/HTMLWrapper.java (limited to 'collaboration') diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/Calculator.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/Calculator.xml new file mode 100755 index 0000000000..345b9065a9 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/Calculator.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/MyValueComposite2.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/MyValueComposite2.xml new file mode 100755 index 0000000000..722bdeb0a5 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/MyValueComposite2.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + EURO + + + + + + + + + + + + + + + + + + + + EURO + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_idle.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_idle.xml new file mode 100755 index 0000000000..99517f639f --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/composite_idle.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/store.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/store.xml new file mode 100755 index 0000000000..fc32186344 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/store.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + USD + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/supplychain.xml b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/supplychain.xml new file mode 100755 index 0000000000..1964db7fbb --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/input/supplychain.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.html b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.html new file mode 100755 index 0000000000..9788bbce0a --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.html @@ -0,0 +1,22 @@ + + +

Apache Tuscany - Composite Diagram Generator

+

Calculator

+
+ + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg index c99236805e..7c7622b974 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/Calculator_diagram.svg @@ -1 +1 @@ -CalculatorCalculatorServiceComponentCalculatorServiceaddServicesubtractServicemultiplyServicedivideServiceAddServiceComponentAddServiceSubtractServiceComponentSubtractServiceMultiplyServiceComponentMultiplyServiceDivideServiceComponentDivideServiceStockQuoteMediatorComponentcurrencySQMediatorstockQuoteService \ No newline at end of file +CalculatorCalculatorServiceComponentCalculatorServiceaddServicesubtractServicemultiplyServicedivideServiceAddServiceComponentAddServiceSubtractServiceComponentSubtractServiceMultiplyServiceComponentMultiplyServiceDivideServiceComponentDivideServiceStockQuoteMediatorComponentcurrencySQMediatorstockQuoteService \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/IdleTest_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/IdleTest_diagram.svg new file mode 100755 index 0000000000..a18d9c11a2 --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/IdleTest_diagram.svg @@ -0,0 +1 @@ +IdleTestAddServiceComponentAddService \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.html b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.html new file mode 100755 index 0000000000..ae6b2d49fa --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.html @@ -0,0 +1,22 @@ + + +

Apache Tuscany - Composite Diagram Generator

+

MyValueComposite2

+
+ + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.svg index 8f2772470b..f731eb05aa 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/MyValueComposite2_diagram.svg @@ -1 +1 @@ -MyValueComposite2MyValueServiceComponentcurrencymyValueServicestockQuoteServicecustomerServiceStockQuoteMediatorComponentcurrencySQMediatorstockQuoteServiceSubtractServiceComponentSubtractServiceMultiplyServiceComponentMultiplyServicecurrencyMyValueServiceCustomerServiceStockQuoteServiceIncluded Composites store , Calculator , supplychain , \ No newline at end of file +MyValueComposite2MyValueServiceComponentcurrencymyValueServicestockQuoteServicecustomerServiceStockQuoteMediatorComponentcurrencySQMediatorstockQuoteServiceSubtractServiceComponentSubtractServiceMultiplyServiceComponentMultiplyServicecurrencyMyValueServiceCustomerServiceStockQuoteServiceIncluded Composites store , Calculator , supplychain , \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.html b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.html new file mode 100755 index 0000000000..16b72202ac --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.html @@ -0,0 +1,22 @@ + + +

Apache Tuscany - Composite Diagram Generator

+

store

+
+ + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg index 396cc733b9..2bce7c1173 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/store_diagram.svg @@ -1 +1 @@ -storeStoreWidgetcatalogshoppingCartshoppingTotalCatalogcurrencyCodeCatalogcurrencyConverterShoppingCartCartTotalCurrencyConverterCurrencyConverter \ No newline at end of file +storeStoreWidgetcatalogshoppingCartshoppingTotalCatalogcurrencyCodeCatalogcurrencyConverterShoppingCartCartTotalCurrencyConverterCurrencyConverter \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.html b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.html new file mode 100755 index 0000000000..227ebd720b --- /dev/null +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.html @@ -0,0 +1,22 @@ + + +

Apache Tuscany - Composite Diagram Generator

+

supplychain

+
+ + + + + + + + + \ No newline at end of file diff --git a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg index 11be7dd98d..466028c02e 100755 --- a/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg +++ b/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/output/supplychain_diagram.svg @@ -1 +1 @@ -supplychainCustomerComponentCustomerComponentretailerRetailerComponentRetailerComponentwarehouseWarehouseComponentWarehouseComponentshipperShipperComponentShipperComponentcustomer \ No newline at end of file +supplychainCustomerComponentCustomerComponentretailerRetailerComponentRetailerComponentwarehouseWarehouseComponentWarehouseComponentshipperShipperComponentShipperComponentcustomer \ No newline at end of file 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 refs= new ArrayList(); private ArrayList sers= new ArrayList(); + 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 = "" + + "\n" + + "\n" + + "

Apache Tuscany - Composite Diagram Generator

\n" + + "

"+compositeName+"

\n" + + "
\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + ""; + + 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(); } } -- cgit v1.2.3