|
| 1 | +Index: plugin.jelly |
| 2 | +=================================================================== |
| 3 | +RCS file: /home/cvspublic/maven/plugins/svg/plugin.jelly,v |
| 4 | +retrieving revision 1.6 |
| 5 | +diff -u -r1.6 plugin.jelly |
| 6 | +--- plugin.jelly 22 May 2004 11:39:25 -0000 1.6 |
| 7 | ++++ plugin.jelly 19 Jan 2005 13:16:32 -0000 |
| 8 | +@@ -25,7 +25,8 @@ |
| 9 | + <j:set var="svgSrcDir" value="${maven.svg.src.dir}"/> |
| 10 | + <j:set var="svgCleanup" value="${maven.svg.cleanup}"/> |
| 11 | + <j:set var="svgTarget" value="${maven.svg.target}"/> |
| 12 | +- |
| 13 | ++ <j:set var="svgTarget" value="${maven.svg.target}"/> |
| 14 | ++ <j:set var="svgExecuteOnload" value="${maven.svg.onload}"/> |
| 15 | + |
| 16 | + <define:taglib uri="svgConverter"> |
| 17 | + <define:jellybean |
| 18 | +@@ -59,19 +60,12 @@ |
| 19 | + <j:if test="${convert != null}"> |
| 20 | + <j:forEach var="file" items="${svgFiles.iterator()}"> |
| 21 | + <echo>Converting ${file} to ${svgDestDir} using type ${svgTarget}</echo> |
| 22 | +- <j:if test="${svgTarget.equalsIgnoreCase('both')}"> |
| 23 | +- <svgConverter:convert type="jpg" |
| 24 | +- file="${file}" |
| 25 | +- destination="${svgDestDir}"/> |
| 26 | +- <svgConverter:convert type="png" |
| 27 | +- file="${file}" |
| 28 | +- destination="${svgDestDir}"/> |
| 29 | +- </j:if> |
| 30 | +- <j:if test="${!(svgTarget.equalsIgnoreCase('both'))}"> |
| 31 | +- <svgConverter:convert type="${svgTarget}" |
| 32 | +- file="${file}" |
| 33 | +- destination="${svgDestDir}"/> |
| 34 | +- </j:if> |
| 35 | ++ <svgConverter:convert |
| 36 | ++ type="${svgTarget}" |
| 37 | ++ file="${file}" |
| 38 | ++ destination="${svgDestDir}" |
| 39 | ++ executeOnload="${svgExecuteOnload}" |
| 40 | ++ /> |
| 41 | + <!-- Todo : clean up after ourselves ? --> |
| 42 | + </j:forEach> |
| 43 | + </j:if> |
| 44 | +Index: project.xml |
| 45 | +=================================================================== |
| 46 | +RCS file: /home/cvspublic/maven/plugins/svg/project.xml,v |
| 47 | +retrieving revision 1.6 |
| 48 | +diff -u -r1.6 project.xml |
| 49 | +--- project.xml 22 May 2004 11:39:25 -0000 1.6 |
| 50 | ++++ project.xml 19 Jan 2005 13:16:32 -0000 |
| 51 | +@@ -156,7 +156,14 @@ |
| 52 | + <url>http://xml.apache.org/batik</url> |
| 53 | + </dependency> |
| 54 | + |
| 55 | +-<!-- <dependency> |
| 56 | ++ <dependency> |
| 57 | ++ <groupId>rhino</groupId> |
| 58 | ++ <artifactId>js</artifactId> |
| 59 | ++ <version>1.6R1</version> |
| 60 | ++ <url>http://xml.apache.org/batik</url> |
| 61 | ++ </dependency> |
| 62 | ++ |
| 63 | ++ <!-- <dependency> |
| 64 | + <id>junit</id> |
| 65 | + <version>3.8.1</version> |
| 66 | + </dependency> |
| 67 | +Index: src/java/org/mvdb/maven/plugins/svg/SVGConverter.java |
| 68 | +=================================================================== |
| 69 | +RCS file: /home/cvspublic/maven/plugins/svg/src/java/org/mvdb/maven/plugins/svg/SVGConverter.java,v |
| 70 | +retrieving revision 1.4 |
| 71 | +diff -u -r1.4 SVGConverter.java |
| 72 | +--- src/java/org/mvdb/maven/plugins/svg/SVGConverter.java 20 May 2004 23:38:27 -0000 1.4 |
| 73 | ++++ src/java/org/mvdb/maven/plugins/svg/SVGConverter.java 19 Jan 2005 13:16:32 -0000 |
| 74 | +@@ -29,6 +29,7 @@ |
| 75 | + import org.apache.batik.transcoder.image.ImageTranscoder; |
| 76 | + import org.apache.batik.transcoder.image.JPEGTranscoder; |
| 77 | + import org.apache.batik.transcoder.image.PNGTranscoder; |
| 78 | ++import org.apache.batik.transcoder.image.TIFFTranscoder; |
| 79 | + |
| 80 | + /** |
| 81 | + * This class converts svg images to png, jpg and tiff. |
| 82 | +@@ -50,6 +51,10 @@ |
| 83 | + * The destination of the file |
| 84 | + */ |
| 85 | + private String destination; |
| 86 | ++ /** |
| 87 | ++ * True iff any onload script should be executed |
| 88 | ++ */ |
| 89 | ++ private boolean executeOnload = false; |
| 90 | + |
| 91 | + /** |
| 92 | + * |
| 93 | +@@ -63,11 +68,27 @@ |
| 94 | + * It defaults to png. |
| 95 | + */ |
| 96 | + public void convert() { |
| 97 | +- if ("jpg".equalsIgnoreCase(getType())) { |
| 98 | ++ String type = getType(); |
| 99 | ++ if(type==null) { |
| 100 | ++ type = "png"; |
| 101 | ++ } |
| 102 | ++ if ("all".equalsIgnoreCase(type) || "both".equalsIgnoreCase(type)) { |
| 103 | ++ convertToTIFF(); |
| 104 | + convertToJPG(); |
| 105 | +- } else { |
| 106 | + convertToPNG(); |
| 107 | + } |
| 108 | ++ else if("png".equalsIgnoreCase(type)) { |
| 109 | ++ convertToPNG(); |
| 110 | ++ } |
| 111 | ++ else if("jpg".equalsIgnoreCase(type) || "jpeg".equalsIgnoreCase(type)) { |
| 112 | ++ convertToJPG(); |
| 113 | ++ } |
| 114 | ++ else if("tif".equalsIgnoreCase(type) || "tiff".equalsIgnoreCase(type)) { |
| 115 | ++ convertToTIFF(); |
| 116 | ++ } |
| 117 | ++ else { |
| 118 | ++ throw new IllegalArgumentException("Don't know how to handle type: " + type); |
| 119 | ++ } |
| 120 | + } |
| 121 | + |
| 122 | + /** |
| 123 | +@@ -88,6 +109,12 @@ |
| 124 | + transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8)); |
| 125 | + convertTo(transcoder, ".jpg"); |
| 126 | + } |
| 127 | ++ |
| 128 | ++ public void convertToTIFF() { |
| 129 | ++ setType("tif"); |
| 130 | ++ TIFFTranscoder transcoder = new TIFFTranscoder(); |
| 131 | ++ convertTo(transcoder, ".tif"); |
| 132 | ++ } |
| 133 | + |
| 134 | + /** |
| 135 | + * Converts the svg file to the target file |
| 136 | +@@ -118,18 +145,18 @@ |
| 137 | + try { |
| 138 | + out = new FileOutputStream(pngFileName); |
| 139 | + TranscoderOutput output = new TranscoderOutput(out); |
| 140 | +-// System.out.println("hints : " + transcoder.getTranscodingHints()); |
| 141 | ++ if(executeOnload) { |
| 142 | ++ transcoder.addTranscodingHint(ImageTranscoder.KEY_EXECUTE_ONLOAD, Boolean.TRUE); |
| 143 | ++ } |
| 144 | + transcoder.transcode(input, output); |
| 145 | ++ } catch(FileNotFoundException e) { |
| 146 | ++ throw new IllegalArgumentException("Cannot find file " + pngFileName); |
| 147 | ++ } catch(TranscoderException e) { |
| 148 | ++ Exception te = ((TranscoderException)e).getException(); |
| 149 | ++ te.printStackTrace(System.err); |
| 150 | ++ throw new IllegalArgumentException("Exception : \n" + te); |
| 151 | + } catch (Exception e) { |
| 152 | +- if (e instanceof FileNotFoundException) { |
| 153 | +- throw new IllegalArgumentException("Cannot find file " + pngFileName); |
| 154 | +- } else if (e instanceof TranscoderException) { |
| 155 | +- Exception te = ((TranscoderException)e).getException(); |
| 156 | +- te.printStackTrace(System.err); |
| 157 | +- throw new IllegalArgumentException("Exception : \n" + te); |
| 158 | +- } else { |
| 159 | +- e.printStackTrace(System.err); |
| 160 | +- } |
| 161 | ++ e.printStackTrace(System.err); |
| 162 | + } finally { |
| 163 | + if (out != null) { |
| 164 | + try { |
| 165 | +@@ -183,5 +210,19 @@ |
| 166 | + public void setType(String type) { |
| 167 | + this.type = type; |
| 168 | + } |
| 169 | +- |
| 170 | ++ |
| 171 | ++ |
| 172 | ++ /** |
| 173 | ++ * @return Returns the executeOnload. |
| 174 | ++ */ |
| 175 | ++ public boolean isExecuteOnload() { |
| 176 | ++ return executeOnload; |
| 177 | ++ } |
| 178 | ++ |
| 179 | ++ /** |
| 180 | ++ * @param executeOnload The executeOnload to set. |
| 181 | ++ */ |
| 182 | ++ public void setExecuteOnload(boolean executeOnload) { |
| 183 | ++ this.executeOnload = executeOnload; |
| 184 | ++ } |
| 185 | + } |
| 186 | +Index: src/test/org/mvdb/maven/plugins/svg/SVGConverterTest.java |
| 187 | +=================================================================== |
| 188 | +RCS file: /home/cvspublic/maven/plugins/svg/src/test/org/mvdb/maven/plugins/svg/SVGConverterTest.java,v |
| 189 | +retrieving revision 1.2 |
| 190 | +diff -u -r1.2 SVGConverterTest.java |
| 191 | +--- src/test/org/mvdb/maven/plugins/svg/SVGConverterTest.java 1 Mar 2004 17:17:45 -0000 1.2 |
| 192 | ++++ src/test/org/mvdb/maven/plugins/svg/SVGConverterTest.java 19 Jan 2005 13:16:33 -0000 |
| 193 | +@@ -182,4 +182,20 @@ |
| 194 | + file.delete(); |
| 195 | + new File("tmp").delete(); |
| 196 | + } |
| 197 | ++ |
| 198 | ++ public void testScripted() { |
| 199 | ++ System.out.println("testScripted"); |
| 200 | ++ SVGConverter converter = new SVGConverter(); |
| 201 | ++ converter.setDestination("tmp/"); |
| 202 | ++ converter.setFile("src/test-resources/scripted.svg"); |
| 203 | ++ converter.setExecuteOnload(true); |
| 204 | ++ File destDir = new File("tmp"); |
| 205 | ++ destDir.mkdir(); |
| 206 | ++ converter.convert(); |
| 207 | ++ |
| 208 | ++ File destFile = new File("tmp/scripted.png"); |
| 209 | ++ assertTrue(destFile.exists()); |
| 210 | ++ destFile.delete(); |
| 211 | ++ destDir.delete(); |
| 212 | ++ } |
| 213 | + } |
| 214 | +Index: src/test-resources/scripted.svg |
| 215 | +=================================================================== |
| 216 | +RCS file: src/test-resources/scripted.svg |
| 217 | +diff -N src/test-resources/scripted.svg |
| 218 | +--- /dev/null 1 Jan 1970 00:00:00 -0000 |
| 219 | ++++ src/test-resources/scripted.svg 1 Jan 1970 00:00:00 -0000 |
| 220 | +@@ -0,0 +1,23 @@ |
| 221 | ++<?xml version="1.0" standalone="no"?> |
| 222 | ++<svg id="root" width="100" height="100" x="0" y="0"> |
| 223 | ++ <script type="text/ecmascript"> |
| 224 | ++ var namespace = "http://www.w3.org/2000/svg"; |
| 225 | ++ |
| 226 | ++ function drawCircle(evt) { |
| 227 | ++ first = evt.target.getFirstChild(); |
| 228 | ++ e = document.createElementNS(namespace, "circle"); |
| 229 | ++ e.setAttributeNS(null, "cx", 50); |
| 230 | ++ e.setAttributeNS(null, "cy", 50); |
| 231 | ++ e.setAttributeNS(null, "r", 45); |
| 232 | ++ e.setAttributeNS(null, "stroke", "red"); |
| 233 | ++ e.setAttributeNS(null, "stroke-width", 1); |
| 234 | ++ e.setAttributeNS(null, "fill", "yellow"); |
| 235 | ++ e.appendChild(document.createTextNode(this.name)); |
| 236 | ++ evt.target.insertBefore(e,first); |
| 237 | ++ } |
| 238 | ++ </script> |
| 239 | ++ |
| 240 | ++ <g onload="drawCircle(evt)"> |
| 241 | ++ <rect x="20" y="20" width="60" height="60" stroke="red" stroke-width="1" fill="yellow"/> |
| 242 | ++ </g> |
| 243 | ++</svg> |
0 commit comments