tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1171339 - in /tuscany/sca-java-2.x/trunk: maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/ modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/ modules/composite-diagram/s...
Date Fri, 16 Sep 2011 00:19:28 GMT
Author: rfeng
Date: Fri Sep 16 00:19:27 2011
New Revision: 1171339

URL: http://svn.apache.org/viewvc?rev=1171339&view=rev
Log:
Add the ablity to generate links for the component/service/reference/property

Modified:
    tuscany/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java
    tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
    tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
    tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java

Modified: tuscany/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java?rev=1171339&r1=1171338&r2=1171339&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java
(original)
+++ tuscany/sca-java-2.x/trunk/maven/tuscany-diagram-plugin/src/main/java/org/apache/tuscany/sca/diagram/maven/plugin/TuscanyDiagramMojo.java
Fri Sep 16 00:19:27 2011
@@ -70,6 +70,11 @@ public class TuscanyDiagramMojo extends 
     private File outputDirectory;
 
     /**
+     * @parameter The base URL for the clickable blocks
+     */
+    private String baseURL;
+
+    /**
      * @parameter
      */
     private boolean generateSVG = true;
@@ -97,6 +102,7 @@ public class TuscanyDiagramMojo extends 
             try {
                 getLog().info("Generating diagram for " + f);
                 org.apache.tuscany.sca.diagram.main.Main.generate(outputDirectory,
+                                                                  baseURL,
                                                                   generateSVG,
                                                                   generateHTML,
                                                                   generateJPG,

Modified: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java?rev=1171339&r1=1171338&r2=1171339&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/generator/DiagramGenerator.java
Fri Sep 16 00:19:27 2011
@@ -45,6 +45,7 @@ import org.w3c.dom.Element;
 
 public class DiagramGenerator {
 
+    private static final String XLINK_NS = "http://www.w3.org/1999/xlink";
     private CompositeEntity comp;
     private Document doc;
     private String svgNS;
@@ -54,6 +55,7 @@ public class DiagramGenerator {
     private int diagramHeight, diagramWidth;
 
     private boolean isHtml;
+    private final String baseURL;
 
     private int lastUsedChangingFactor = 0;
 
@@ -82,10 +84,11 @@ public class DiagramGenerator {
      * Constructor to generate a SVG diagram for a given CompositeEntity
      * Object.
      */
-    public DiagramGenerator(CompositeEntity comp, boolean isHtml) {
+    public DiagramGenerator(CompositeEntity comp, boolean isHtml, String baseURL) {
 
         this.comp = comp;
         this.isHtml = isHtml;
+        this.baseURL = baseURL;
 
     }
 
@@ -101,6 +104,8 @@ public class DiagramGenerator {
         // Get the root element (the 'svg' element).
         svgRoot = doc.getDocumentElement();
 
+        svgRoot.setAttribute("xmlns:xlink", XLINK_NS);
+
         setDiagramHeight(comp.getHeight() + 200);
         setDiagramWidth(comp.getWidth() + 400);
 
@@ -311,7 +316,18 @@ public class DiagramGenerator {
             Element property = pro.addElement(doc, svgNS, x, y, propLen);
             Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT,
prop);
 
-            svgRoot.appendChild(property);
+            Element child = property;
+            if (baseURL != null) {
+                Element link = doc.createElementNS(svgNS, "a");
+                link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/"
+                    + ent.getName()
+                    + "/properties/"
+                    + prop);
+                link.appendChild(property);
+                child = link;
+            }
+            
+            svgRoot.appendChild(child);
             svgRoot.appendChild(text);
 
             x += (propLen + Constant.SPACING_FOR_COMPONENT_OF_PROPERTY);
@@ -330,8 +346,20 @@ public class DiagramGenerator {
         for (String ref : setRefOrder(ent)) {
             ReferenceArtifact refer = new ReferenceArtifact();
             Element polygon = refer.addElement(doc, svgNS, x, y, refHeight);
+
+            Element child = polygon;
+            if (baseURL != null) {
+                Element link = doc.createElementNS(svgNS, "a");
+                link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/"
+                    + ent.getName()
+                    + "/services/"
+                    + ref);
+                link.appendChild(polygon);
+                child = link;
+            }
+
             Element text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT,
ref);
-            svgRoot.appendChild(polygon);
+            svgRoot.appendChild(child);
             svgRoot.appendChild(text);
 
             y += (refHeight + Constant.SPACING_FOR_COMPONENT_OF_REFERENCE);
@@ -450,7 +478,18 @@ public class DiagramGenerator {
             else
                 text = Text.addTextElement(doc, svgNS, x, y - Constant.SPACING_FOR_TEXT,
"");
 
-            svgRoot.appendChild(polygon);
+            Element child = polygon;
+            if (baseURL != null) {
+                Element link = doc.createElementNS(svgNS, "a");
+                link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/"
+                    + ent.getName()
+                    + "/services/"
+                    + ser);
+                link.appendChild(polygon);
+                child = link;
+            }
+
+            svgRoot.appendChild(child);
             svgRoot.appendChild(text);
 
             y += (serHeight + Constant.SPACING_FOR_COMPONENT_OF_SERVICE);
@@ -558,6 +597,15 @@ public class DiagramGenerator {
         ComponentArtifact comp = new ComponentArtifact();
         //System.err.println(ent.getX());
         Element com = comp.addElement(doc, svgNS, ent.getX(), ent.getY(), ent.getHeight(),
ent.getWidth());
+
+        Element component = com;
+        if (baseURL != null) {
+            Element link = doc.createElementNS(svgNS, "a");
+            link.setAttributeNS(XLINK_NS, "xlink:href", baseURL + "/components/" + ent.getName());
+            link.appendChild(com);
+            component = link;
+        }
+
         Element text =
             Text.addTextElement(doc,
                                 svgNS,
@@ -565,7 +613,7 @@ public class DiagramGenerator {
                                 ent.getY() + (ent.getHeight() + Constant.COMPONENT_TEXT_SPACING),
                                 ent.getName());
 
-        svgRoot.appendChild(com);
+        svgRoot.appendChild(component);
         svgRoot.appendChild(text);
 
         comp.setName(ent.getName());

Modified: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java?rev=1171339&r1=1171338&r2=1171339&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
Fri Sep 16 00:19:27 2011
@@ -118,11 +118,15 @@ public class Main {
         }
         File dir = new File(outFileDir);
         String[] compositeFiles = cli.getArgs();
-        generate(dir, isSvg, isHtml, false, compositeFiles);
+        generate(dir, null, isSvg, isHtml, false, compositeFiles);
     }
 
-    public static void generate(File dir, boolean isSvg, boolean isHtml, boolean isJpeg,
String... compositeFiles)
-        throws Exception {
+    public static void generate(File dir,
+                                String baseURL,
+                                boolean isSvg,
+                                boolean isHtml,
+                                boolean isJpeg,
+                                String... compositeFiles) throws Exception {
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         for (String str : compositeFiles) {
 
@@ -134,7 +138,7 @@ public class Main {
                 EntityBuilder eb = new EntityBuilder(doc);
                 CompositeEntity comp = eb.buildCompositeEntity();
 
-                DiagramGenerator dg = new DiagramGenerator(comp, isHtml);
+                DiagramGenerator dg = new DiagramGenerator(comp, isHtml, baseURL);
                 Document svg = dg.buildSVGDocument();
 
                 if (isJpeg) {

Modified: tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java?rev=1171339&r1=1171338&r2=1171339&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/composite-diagram/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
Fri Sep 16 00:19:27 2011
@@ -25,7 +25,7 @@ public class DiagramGeneratorTestCase {
         for (File xml : new File("input").listFiles()) {
             if (xml.getName().endsWith(".xml")) {
                 System.out.println(xml);
-                Main.generate(new File("target"), true, false, false, xml.toString());
+                Main.generate(new File("target"), null, true, false, false, xml.toString());
             }
         }
     }



Mime
View raw message