source: other-projects/nz-flag-design/trunk/main-form/my-design.jsp@ 29961

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

Switched to using local verison of NZ flag

  • Property svn:executable set to *
File size: 10.8 KB
Line 
1<%@ page contentType="text/html; charset=UTF-8" %>
2<!DOCTYPE html>
3<html id="story">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6 <meta name="viewport" content="width=device-width, initial-scale=1"/>
7 <title>NZ Flag Design @ The University of Waikato (<%=request.getParameter("pub-name")%>)</title>
8
9 <script src="css/source-sans-pro.js"></script>
10 <link href="css/styles.css" rel="stylesheet"/>
11 <link href="css/storystyle.css" rel="stylesheet"/>
12
13
14 <link rel="stylesheet" href="lib-slider/css/jquery.mobile-1.3.0.css"/>
15 <link rel="stylesheet" href="lib-slider/css/jqm-demos.css"/>
16 <link rel="stylesheet" href="lib-slider/css/swipe-page.css"/>
17 <link rel="shortcut icon" href="lib-slider/nzflag-icon64-padded.png"/>
18
19 <script src="lib/jquery-1.8.2.min.js"></script>
20
21 <script src="lib-slider/js/jquery.mobile.demos.js"></script>
22 <script src="lib-slider/js/jquery.mobile-1.3.0.js"></script>
23
24
25
26 <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter,java.nio.file.*,org.json.*" %>
27
28 <%!
29
30
31private static void copyFile(File source, File dest)
32 throws IOException {
33 InputStream input = null;
34 OutputStream output = null;
35 try {
36 input = new FileInputStream(source);
37 output = new FileOutputStream(dest);
38 byte[] buf = new byte[1024];
39 int bytesRead;
40 while ((bytesRead = input.read(buf)) > 0) {
41 output.write(buf, 0, bytesRead);
42 }
43 } finally {
44 input.close();
45 output.close();
46 }
47}
48/*
49 private static void copyFileChannels(File source, File dest)
50 throws IOException {
51 FileChannel inputChannel = null;
52 FileChannel outputChannel = null;
53 try {
54 inputChannel = new FileInputStream(source).getChannel();
55 outputChannel = new FileOutputStream(dest).getChannel();
56 outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
57 } finally {
58 inputChannel.close();
59 outputChannel.close();
60 }
61 }
62
63*/
64/*
65 public static void copyFile_JAVA17( File from, File to ) throws IOException {
66 Files.copy( from.toPath(), to.toPath() );
67 }
68*/
69
70 public static void publishFile(File myFlagFile, File pubFlagFile)
71 {
72 try {
73 copyFile(myFlagFile,pubFlagFile);
74 }
75 catch (Exception e) {
76 e.printStackTrace();
77 }
78 }
79
80 public String publishFlag(HttpServletRequest request)
81 {
82 String doc_base = getServletContext().getRealPath("/");
83 File render_dir = new File(doc_base,"render-3d");
84 File render_images_dir = new File(render_dir,"images");
85
86 String png_filename = null;
87 String svg_filename = null;
88
89 String myid = request.getParameter("myid");
90 if (myid == null) {
91 png_filename = "flag.png";
92 svg_filename = "flag.svg";
93 }
94 else {
95 png_filename = "flag-" + myid + ".png";
96 svg_filename = "flag-" + myid + ".svg";
97 }
98
99 File full_my_png_file = new File(render_images_dir,png_filename);
100 File full_my_svg_file = new File(render_images_dir,svg_filename);
101
102 File pub_dir = new File(doc_base,"published");
103 String pub_name = request.getParameter("pub-name");
104 if (pub_name == null) {
105 pub_name = "tmp";
106 }
107
108 File my_pub_dir = new File(pub_dir,pub_name);
109 if (!my_pub_dir.exists()) {
110 my_pub_dir.mkdir();
111 }
112 File full_pub_my_png_file = new File(my_pub_dir,"myflag.png");
113 File full_pub_my_svg_file = new File(my_pub_dir,"myflag.svg");
114
115 publishFile(full_my_png_file,full_pub_my_png_file);
116 publishFile(full_my_svg_file,full_pub_my_svg_file);
117
118 return pub_name;
119 }
120
121
122 void savePubInfo(HttpServletRequest request, String pub_name)
123 {
124 String doc_base = getServletContext().getRealPath("/");
125 File pub_dir = new File(doc_base,"published");
126 File my_pub_dir = new File(pub_dir,pub_name);
127
128 File full_pub_json_file = new File(my_pub_dir,"pubinfo.json");
129
130 try {
131 String name = request.getParameter("name");
132 String email = request.getParameter("email");
133 String desc = request.getParameter("desc").replace("\n"," ").replace("\r"," ");
134
135 BufferedWriter bw = new BufferedWriter(new FileWriter(full_pub_json_file));
136 bw.write("{ \"name\": \"" + name + "\", \"email\": \"" + email + "\", \"desc\": \"" + desc + "\"}");
137 bw.close();
138 }
139 catch (Exception e) {
140 e.printStackTrace();
141 }
142 }
143
144 %>
145
146
147 <%
148
149 String action = request.getParameter("action");
150
151 String my_flag_png = "myflag.png";
152 String my_flag_svg = "myflag.svg";
153
154 String pub_name = null;
155
156 String name = null;
157 String email = null;
158 String desc = null;
159
160
161 if ((action != null) && action.equals("publish")) {
162 pub_name = publishFlag(request);
163 savePubInfo(request,pub_name);
164 name = request.getParameter("name");
165 email = request.getParameter("email");
166 desc = request.getParameter("desc").replace("\n"," ").replace("\r"," ").replace(" "," ");
167 }
168 else {
169 // read in JSON file and get details
170 // set them up as Java variables for producing the page through Javascript
171
172 pub_name = request.getParameter("pub-name");
173 if (pub_name == null) {
174 pub_name = "tmp";
175 }
176
177 String doc_base = getServletContext().getRealPath("/");
178 File pub_dir = new File(doc_base,"published");
179 File my_pub_dir = new File(pub_dir,pub_name);
180 File full_pub_json_file = new File(my_pub_dir,"pubinfo.json");
181
182 String everything = null;
183 BufferedReader br = new BufferedReader(new FileReader(full_pub_json_file));
184 try {
185
186 StringBuilder sb = new StringBuilder();
187 String line = br.readLine();
188
189 String line_sep = System.getProperty("line.separator");
190 while (line != null) {
191 sb.append(line);
192 sb.append(line_sep);
193 line = br.readLine();
194 }
195 everything = sb.toString();
196 }
197 catch (Exception e) {
198 e.printStackTrace();
199 }
200 finally {
201 br.close();
202 }
203
204 JSONObject obj = new JSONObject(everything);
205 name = obj.getString("name");
206 email = obj.getString("email");
207 desc = obj.getString("desc");
208 }
209
210
211 %>
212
213 <style>
214 .vertical-align {
215 position: relative;
216 top: 50%;
217 -webkit-transform: translateY(-50%);
218 -ms-transform: translateY(-50%);
219 transform: translateY(-50%);
220 }
221 </style>
222
223 </head>
224
225 <body>
226<div id="fb-root"></div>
227<script>(function(d, s, id) {
228 var js, fjs = d.getElementsByTagName(s)[0];
229 if (d.getElementById(id)) return;
230 js = d.createElement(s); js.id = id;
231 js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.3&appId=538218162984944";
232 fjs.parentNode.insertBefore(js, fjs);
233}(document, 'script', 'facebook-jssdk'));</script>
234
235 <div data-role="page" id="innovation-story-01" class="demo-page">
236
237 <div data-role="content">
238
239 <a target="_parent" href="../index.html" class="back-button back-left"></a>
240
241 <div class="story-page" id="static-info-page">
242 <!-- put custom content here -->
243
244 <div class="story-title" style="margin-left: 25px;">
245
246 <h1 class="center">My Design '<%=request.getParameter("pub-name")%>' @ The University of Waikato</h1>
247
248 <p class="center" style="margin: 6px;">&mdash; The New Zealand Flag Debate</p>
249
250 <div class="center" style="height: 220px; position: relative;">
251 <div style="display: inline-block; position: relative;">
252 <img alt="" src="250px-Flag_of_New_Zealand.svg.png"
253 height="200" widthXX="350" />
254 </div>
255 <div style="height: 200px; font-size: 300%; display: inline-block;" class="vertical-alignXX">VS</div>
256 <div style="display: inline-block; position: relative">
257 <div>
258 <a id="myflag-svg" data-ajax="false" ><img id="myflag-png" height="200" style="border: none;"/></a>
259 </div>
260
261 <div class="fb-like"
262 style="position: absolute; left:10px; width:200px;"
263 data-href="http://www.greenstone.org/nz-flag-design/main-form/my-design.jsp?pub-name=<%=request.getParameter("pub-name")%>"
264 data-layout="standard" data-action="like" data-show-faces="false" data-share="false"></div>
265
266 </div>
267 </div>
268
269 </div>
270
271
272<center>
273
274<script type="text/javascript">
275
276var published_id = "<%= request.getParameter("pub-name") %>";
277var name = "<%= name %>";
278var email = "<%= email %>";
279var desc = "<%= desc %>";
280
281document.write(" <div style=\"width: 500px; background: #181818; padding: 5px; margin: 10px;\">");
282document.write(" <p>Designer: " + name + "<p/>");
283document.write(" <p>Email: " + email + "<p/>");
284document.write(" <p>Description: " + desc + "<p/>");
285document.write(" </div>");
286
287
288var a2a_config = a2a_config || {};
289a2a_config.linkname = "NZ Flag Design @ University of Waikato (" + published_id + ")";
290
291var base_url = location.protocol + '//' + location.host + location.pathname;
292
293a2a_config.linkurl = base_url + "?pub-name=" + published_id
294
295</script>
296
297
298</center>
299
300
301<div style="clear:both;"></div>
302
303
304
305<!-- AddToAny BEGIN -->
306<center>
307<p>
308 Share this design:
309</p>
310
311<div class="a2a_kit a2a_kit_size_32 a2a_default_style" style="width: 260px;">
312<a class="a2a_dd" href="https://www.addtoany.com/share_save"></a>
313<a class="a2a_button_email"></a>
314<a class="a2a_button_facebook"></a>
315<a class="a2a_button_google_plus"></a>
316<a class="a2a_button_google_gmail"></a>
317<a class="a2a_button_twitter"></a>
318<a class="a2a_button_tumblr"></a>
319</div>
320</center>
321
322<script type="text/javascript" src="//static.addtoany.com/menu/page.js"></script>
323<!-- AddToAny END -->
324
325
326
327 <center>
328 <p style="font-size: 200%;">
329 <i>
330 <a href="../index.html">Interactive Flag Design Website</a> by:
331 <a target="_blank" href="http://cosi.cms.waikato.ac.nz">The Centre for Open Source Innovation</a>
332 <a target="_blank" href="http://cosi.cms.waikato.ac.nz">(COSI)</a><br />
333 at the <a href="http://www.waikato.ac.nz">University of Waikato</a>
334 </i>
335 </p>
336 </center>
337
338
339 </div>
340 <!-- end of putting custom content -->
341
342 </div> <!-- end story-page-->
343
344 </div><!-- /content -->
345
346 </div><!-- /page -->
347
348 <script>
349 $(document).ready( function() {
350
351 var my_flag_png = "<%= "../published/" + pub_name + "/" + my_flag_png %>";
352 var my_flag_svg = "<%= "../published/" + pub_name + "/" + my_flag_svg %>";
353
354 $('#myflag-png').attr("src", my_flag_png);
355 $('#myflag-svg').attr("href", my_flag_svg);
356
357 });
358
359 </script>
360
361 </body>
362</html>
363
364
365
366
367
368
Note: See TracBrowser for help on using the repository browser.