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