source: other-projects/nz-flag-design/trunk/design-2d/svg-data-to-file.jsp@ 33141

Last change on this file since 33141 was 29916, checked in by davidb, 9 years ago

SVG saving 1st-class citizen with PNG operations

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1<%@ page contentType="text/html; charset=UTF-8" %>
2<!DOCTYPE html>
3<html>
4 <head>
5 </head>
6
7 <body>
8
9 <div style="display: none;">
10
11 <script>
12 // Set up a fallback position in case this page is accessed outside of a JSP context
13 // (i.e., the JSP blocks aren't executed)
14 var message = "Failed to execute JSP code blocks";
15 var exit_val = 404; // not currently used
16
17 </script>
18
19 <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter" %>
20
21 <%!
22
23 void writeImageDataToFile(File image_file, String svg_data)
24 {
25 if (svg_data == null) {
26 // Some fake data (a small arrow icon) useful for testing purposes when svg_data is not supplied in the URL
27 svg_data = "<svg width=\"400\" height=\"110\">rect width=\"300\" height=\"100\" style=\"fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)\" /></svg>";
28
29 }
30
31 try {
32 //FileOutputStream fos = new FileOutputStream(image_file);
33 BufferedWriter bw = new BufferedWriter(new FileWriter(image_file));
34 //bw.write("<html><head></head><body>");
35 bw.write(svg_data);
36 //bw.write("</body></html>");
37
38 bw.close();
39 }
40 catch (Exception e) {
41 e.printStackTrace();
42 }
43 }
44
45 %>
46
47
48 <%
49 String doc_base = getServletContext().getRealPath("/");
50 File render_dir = new File(doc_base,"render-3d");
51 File render_images_dir = new File(render_dir,"images");
52 //File flag_file = new File(render_images_dir,"flag.svg");
53
54 String svg_data = request.getParameter("svgData");
55
56 String svg_filename = request.getParameter("svgFilename");
57 if (svg_filename == null) {
58 svg_filename = "flag.svg";
59 }
60 File full_svg_file = new File(render_images_dir,svg_filename);
61
62 writeImageDataToFile(full_svg_file,svg_data);
63
64 out.println("<script>");
65 out.println("message = \"Image File Saved: &lt;docBase&gt;/render-3d/images/" + svg_filename + "\";");
66 out.println("</script>");
67
68 %>
69
70 </div>
71
72 <script>
73
74 document.write("<div>" + message + "</div>\n");
75
76 </script>
77
78 </body>
79
80</html>
Note: See TracBrowser for help on using the repository browser.