tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1171217 - in /tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik: pom.xml src/main/java/org/apache/tuscany/sca/diagram/main/Main.java src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
Date Thu, 15 Sep 2011 18:35:26 GMT
Author: rfeng
Date: Thu Sep 15 18:35:25 2011
New Revision: 1171217

URL: http://svn.apache.org/viewvc?rev=1171217&view=rev
Log:
Allow the generation of jpg

Modified:
    tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml
    tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
    tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java

Modified: tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml?rev=1171217&r1=1171216&r2=1171217&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml (original)
+++ tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/pom.xml Thu
Sep 15 18:35:25 2011
@@ -30,6 +30,8 @@
             <artifactId>commons-cli</artifactId>
             <version>1.2</version>
         </dependency>
+        
+        <!-- 
         <dependency>
             <groupId>org.apache.xmlgraphics</groupId>
             <artifactId>batik-anim</artifactId>
@@ -47,19 +49,22 @@
             <artifactId>batik-css</artifactId>
             <version>1.7</version>
         </dependency>
-
+        
         <dependency>
             <groupId>org.apache.xmlgraphics</groupId>
-            <artifactId>batik-dom</artifactId>
+            <artifactId>batik-ext</artifactId>
             <version>1.7</version>
         </dependency>
+ -->
 
         <dependency>
             <groupId>org.apache.xmlgraphics</groupId>
-            <artifactId>batik-ext</artifactId>
+            <artifactId>batik-dom</artifactId>
             <version>1.7</version>
         </dependency>
 
+
+
         <dependency>
             <groupId>org.apache.xmlgraphics</groupId>
             <artifactId>batik-parser</artifactId>
@@ -91,6 +96,12 @@
         </dependency>
 
         <dependency>
+            <groupId>org.apache.xmlgraphics</groupId>
+            <artifactId>batik-codec</artifactId>
+            <version>1.7</version>
+        </dependency>
+
+        <dependency>
             <groupId>xml-apis</groupId>
             <artifactId>xml-apis-ext</artifactId>
             <version>1.3.04</version>
@@ -127,6 +138,7 @@
                 </configuration>
             </plugin>
 
+<!-- 
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-dependency-plugin</artifactId>
@@ -147,7 +159,7 @@
                     </execution>
                 </executions>
             </plugin>
-
+ -->
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-jar-plugin</artifactId>

Modified: tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java?rev=1171217&r1=1171216&r2=1171217&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
(original)
+++ tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/main/java/org/apache/tuscany/sca/diagram/main/Main.java
Thu Sep 15 18:35:25 2011
@@ -20,7 +20,11 @@
 package org.apache.tuscany.sca.diagram.main;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.StringWriter;
 
 import javax.xml.parsers.DocumentBuilder;
@@ -30,6 +34,12 @@ import javax.xml.transform.TransformerFa
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
+import org.apache.batik.transcoder.Transcoder;
+import org.apache.batik.transcoder.TranscoderException;
+import org.apache.batik.transcoder.TranscoderInput;
+import org.apache.batik.transcoder.TranscoderOutput;
+import org.apache.batik.transcoder.image.JPEGTranscoder;
+import org.apache.batik.transcoder.image.PNGTranscoder;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.HelpFormatter;
@@ -52,9 +62,12 @@ public class Main {
         Option opt2 = new Option("h", "html", false, "Generate HTML documents");
         options.addOption(opt2);
 
-        Option opt3 = new Option("o", "output", true, "Output directory");
+        Option opt3 = new Option("j", "jpeg", false, "Generate JPEG diagrams");
         options.addOption(opt3);
 
+        Option opt4 = new Option("o", "output", true, "Output directory");
+        options.addOption(opt4);
+
         return options;
     }
 
@@ -86,10 +99,12 @@ public class Main {
 
         boolean isHtml = false;
         boolean isSvg = false;
+        boolean isJpeg = false;
         isSvg = cli.hasOption('s');
         isHtml = cli.hasOption('h');
+        isJpeg = cli.hasOption('j');
 
-        if (!isSvg && !isHtml) {
+        if (!isSvg && !isHtml && !isJpeg) {
             isSvg = true;
             isHtml = true;
         }
@@ -103,10 +118,11 @@ public class Main {
         }
         File dir = new File(outFileDir);
         String[] compositeFiles = cli.getArgs();
-        generate(dir, isSvg, isHtml, compositeFiles);
+        generate(dir, isSvg, isHtml, false, compositeFiles);
     }
 
-    public static void generate(File dir, boolean isSvg, boolean isHtml, String... compositeFiles)
throws Exception {
+    public static void generate(File dir, boolean isSvg, boolean isHtml, boolean isJpeg,
String... compositeFiles)
+        throws Exception {
         DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
         for (String str : compositeFiles) {
 
@@ -121,6 +137,11 @@ public class Main {
                 DiagramGenerator dg = new DiagramGenerator(comp, isHtml);
                 Document svg = dg.buildSVGDocument();
 
+                if (isJpeg) {
+                    String jpgFileName = comp.getName() + comp.getFileNameSuffix() + ".jpg";
+                    svgToJPEG(svg, new File(dir, jpgFileName));
+                }
+
                 String svgContent = extractSvg(svg);
 
                 if (isSvg) {
@@ -141,9 +162,9 @@ public class Main {
         HTMLWrapper html = new HTMLWrapper(svg, comp.getName(), htmlFile);
         html.buildHTML();
 
-//        System.err.println("--------------HTML Output for " + comp.getName() + "--------------\n");
-//        System.out.println(content);
-//        System.err.println("--------------------------------------------------------------\n");
+        //        System.err.println("--------------HTML Output for " + comp.getName() +
"--------------\n");
+        //        System.out.println(content);
+        //        System.err.println("--------------------------------------------------------------\n");
 
     }
 
@@ -174,4 +195,85 @@ public class Main {
         return svgString;
     }
 
+    public static void svgToJPEG(File svg, File jpeg) throws IOException, TranscoderException
{
+        // Create the transcoder input.
+        TranscoderInput input = new TranscoderInput(svg.toURI().toString());
+        // Create the transcoder output.
+        OutputStream ostream = new FileOutputStream(jpeg);
+        TranscoderOutput output = new TranscoderOutput(ostream);
+
+        // Create a JPEG transcoder
+        Transcoder t = new JPEGTranscoder();
+
+        // Set the transcoding hints.
+        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
+
+        // Save the image.
+        t.transcode(input, output);
+
+        // Flush and close the stream.
+        ostream.flush();
+        ostream.close();
+    }
+
+    public static void svgToJPEG(Document svg, File jpeg) throws IOException, TranscoderException
{
+        // Create the transcoder input.
+        TranscoderInput input = new TranscoderInput(svg);
+        // Create the transcoder output.
+        OutputStream ostream = new FileOutputStream(jpeg);
+        TranscoderOutput output = new TranscoderOutput(ostream);
+
+        // Create a JPEG transcoder
+        Transcoder t = new JPEGTranscoder();
+
+        // Set the transcoding hints.
+        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
+
+        // Save the image.
+        t.transcode(input, output);
+
+        // Flush and close the stream.
+        ostream.flush();
+        ostream.close();
+    }
+
+    public static void svgToJPEG(InputStream svg, OutputStream jpeg) throws IOException,
TranscoderException {
+        // Create the transcoder input.
+        TranscoderInput input = new TranscoderInput(svg);
+
+        TranscoderOutput output = new TranscoderOutput(jpeg);
+
+        // Create a JPEG transcoder
+        Transcoder t = new JPEGTranscoder();
+
+        // Set the transcoding hints.
+        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));
+
+        // Save the image.
+        t.transcode(input, output);
+
+        // Flush and close the stream.
+        svg.close();
+        jpeg.flush();
+        jpeg.close();
+    }
+
+    public static void svgToPNG(InputStream svg, OutputStream png) throws IOException, TranscoderException
{
+        // Create the transcoder input.
+        TranscoderInput input = new TranscoderInput(svg);
+
+        TranscoderOutput output = new TranscoderOutput(png);
+
+        // Create a JPEG transcoder
+        Transcoder t = new PNGTranscoder();
+
+        // Save the image.
+        t.transcode(input, output);
+
+        // Flush and close the stream.
+        svg.close();
+        png.flush();
+        png.close();
+    }
+
 }

Modified: tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java?rev=1171217&r1=1171216&r2=1171217&view=diff
==============================================================================
--- tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
(original)
+++ tuscany/collaboration/GSoC-2011-Nirmal/CompositeDiagramGeneratorUsingBatik/src/test/java/org/apache/tuscany/sca/diagram/layout/DiagramGeneratorTestCase.java
Thu Sep 15 18:35:25 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, xml.toString());
+                Main.generate(new File("target"), true, false, false, xml.toString());
             }
         }
     }



Mime
View raw message