root/other-projects/nz-flag-design/trunk/design-2d/image-data-to-file.jsp @ 29566

Revision 29566, 2.3 KB (checked in by davidb, 5 years ago)

Next round of changes: these ones export the design-2d SVG as a PNG to the file system (through a JSP script) when the 'render 3d' accordion bar is clicked on

  • Property svn:executable set to *
Line 
1<!DOCTYPE html> 
2<html>
3  <head> 
4  </head>
5
6  <body>
7
8  <div style="display: none;">
9
10  <script>
11    // Set up a fallback position in case this page is accessed outside of a JSP context
12    // (i.e., the JSP blocks aren't executed)
13    var message  = "Failed to execute JSP code blocks";
14    var exit_val = 404; // not currently used
15
16  </script>
17
18  <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter" %>
19
20  <%!
21
22     void writeImageDataToFile(File image_file, String image_data)
23     {
24       if (image_data == null) {
25         // Some fake data (a small arrow icon) useful for testing purposes when image_data is not supplied in the URL
26         image_data = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABL0lEQVR42q2TLW/DMBCG+1OKworCzMzMAsMCQw0zaGgaahwaXKmsoxuaVD66X3G995Jzk/Rj0rSTXsW+j8cXf+x2/22X7wu1Y0cmVlQEK8IYPsReFiOpjI7CZyFK50gDKx4DtUObQU+LXV9zcifFMHz7o5/ViZBzB0FrsvLoGeDp9HUiNUDgWwq5q98BsUo1+aERLQEK0Zhq1QWIDQNUW4BCNN7Ne7UCuHDT+DHSI3v/eZM4ADidDNjzpOxM1iMAutJ4kzztlwDQDqHM2gIw15jlbmveg1UH2BDbV3xEk5YAjNXvUiWbbbdHiSM5RDsHbQbga6IVwQ8AVkfu3a2U69tP7aEQKqPhYkM2wV9LDDkvbyPoLk3JLV8sCGP4EHtavH1MRbT5MRVz4a+P6S92BSaqyCgd7GKfAAAAAElFTkSuQmCC";
27       }
28       else {
29         // skip over 'data:image/png;base64'
30         image_data = image_data.replace("data:image/png;base64","");
31       }
32
33       byte[] image_bytes = DatatypeConverter.parseBase64Binary(image_data); 
34     
35       try {
36         FileOutputStream fos = new FileOutputStream(image_file);
37         fos.write(image_bytes); 
38         fos.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.png");
53
54     String image_data = request.getParameter("imageData");
55
56
57
58     writeImageDataToFile(flag_file,image_data);
59     
60     out.println("<script>");
61     out.println("message = \"Image File Saved: &lt;docBase&gt;/render-3d/images/" + flag_file.getName() + "\";");
62     out.println("</script>");
63
64   %>
65
66  </div>
67
68  <script>
69
70    document.write("<div>" + message + "</div>\n");
71
72  </script>
73
74  </body>
75
76</html>
Note: See TracBrowser for help on using the browser.