Index: other-projects/nz-flag-design/trunk/main-form/my-design.jsp
===================================================================
--- other-projects/nz-flag-design/trunk/main-form/my-design.jsp	(revision 29917)
+++ other-projects/nz-flag-design/trunk/main-form/my-design.jsp	(revision 29917)
@@ -0,0 +1,297 @@
+<%@ page contentType="text/html; charset=UTF-8" %>
+<!DOCTYPE html>  
+<html id="story">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+    <meta name="viewport" content="width=device-width, initial-scale=1"/>
+    <title>NZ Flag Design @ The University of Waikato</title>
+	
+    <script src="css/source-sans-pro.js"></script>
+    <link href="css/styles.css" rel="stylesheet"/>
+    <link href="css/storystyle.css" rel="stylesheet"/>
+	
+    
+    <link rel="stylesheet"  href="lib-slider/css/jquery.mobile-1.3.0.css"/>
+    <link rel="stylesheet" href="lib-slider/css/jqm-demos.css"/>
+    <link rel="stylesheet" href="lib-slider/css/swipe-page.css"/>
+    <link rel="shortcut icon" href="lib-slider/favicon.ico"/>		
+
+    <script src="lib/jquery-1.8.2.min.js"></script>
+    
+    <script src="lib-slider/js/jquery.mobile.demos.js"></script>
+    <script src="lib-slider/js/jquery.mobile-1.3.0.js"></script> 
+
+
+
+  <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter,java.nio.file.Files,org.json.*" %>
+
+  <%!
+     public static void copyFile( File from, File to ) throws IOException {
+       Files.copy( from.toPath(), to.toPath() );
+     }
+
+     public static void publishFile(File myFlagFile, File pubFlagFile) 
+     {
+       try {
+         copyFile(myFlagFile,pubFlagFile);
+       }
+       catch (Exception e) {
+         e.printStackTrace();
+       }
+     }
+
+     public String publishFlag(HttpServletRequest request)
+     {
+       String doc_base = getServletContext().getRealPath("/");
+       File render_dir = new File(doc_base,"render-3d");
+       File render_images_dir = new File(render_dir,"images");
+
+       String png_filename = null;
+       String svg_filename = null;
+
+       String myid = request.getParameter("myid");
+       if (myid == null) {
+  	  png_filename = "flag.png";
+	  svg_filename = "flag.svg";
+       }
+       else {     
+  	  png_filename = "flag-" + myid + ".png";
+	  svg_filename = "flag-" + myid + ".svg";
+       }
+     
+       File full_my_png_file  = new File(render_images_dir,png_filename);
+       File full_my_svg_file  = new File(render_images_dir,svg_filename);
+
+       File pub_dir = new File(doc_base,"published");
+       String pub_name = request.getParameter("pub-name");
+       if (pub_name == null) {
+         pub_name = "tmp";
+       }
+
+       File my_pub_dir = new File(pub_dir,pub_name);
+       if (!my_pub_dir.exists()) {
+         my_pub_dir.mkdir();
+       }
+       File full_pub_my_png_file = new File(my_pub_dir,"myflag.png");
+       File full_pub_my_svg_file = new File(my_pub_dir,"myflag.svg");
+
+       publishFile(full_my_png_file,full_pub_my_png_file);
+       publishFile(full_my_svg_file,full_pub_my_svg_file);
+
+       return pub_name;
+     }
+
+
+     void savePubInfo(HttpServletRequest request, String pub_name) 
+     {
+       String doc_base = getServletContext().getRealPath("/");
+       File pub_dir = new File(doc_base,"published");
+       File my_pub_dir = new File(pub_dir,pub_name);
+
+       File full_pub_json_file = new File(my_pub_dir,"pubinfo.json");
+
+       try {
+         String name  = request.getParameter("name");
+         String email = request.getParameter("email");
+         String desc  = request.getParameter("desc");
+
+	 BufferedWriter bw = new BufferedWriter(new FileWriter(full_pub_json_file));
+         bw.write("{ \"name\": \"" + name + "\", \"email\": \"" + email + "\", \"desc\": \"" + desc + "\"}");
+         bw.close();
+       }
+       catch (Exception e) {
+         e.printStackTrace();
+       }
+     }
+
+   %>
+
+
+  <%
+     
+     String action = request.getParameter("action");
+
+     String my_flag_png = "myflag.png";
+     String my_flag_svg = "myflag.svg";
+
+     String pub_name = null;
+
+     String name  = null;
+     String email = null;
+     String desc  = null;
+
+
+     if ((action != null) && action.equals("publish")) {
+       pub_name = publishFlag(request);
+       savePubInfo(request,pub_name);
+       name  = request.getParameter("name");
+       email = request.getParameter("email");
+       desc  = request.getParameter("desc");
+     }
+     else {
+       // read in JSON file and get details
+       // set them up as Java variables for producing the page through Javascript
+
+       pub_name = request.getParameter("pub-name");
+       if (pub_name == null) {
+         pub_name = "tmp";
+       }
+
+       String doc_base = getServletContext().getRealPath("/");
+       File pub_dir = new File(doc_base,"published");
+       File my_pub_dir = new File(pub_dir,pub_name);       
+       File full_pub_json_file = new File(my_pub_dir,"pubinfo.json");
+
+       String everything = null;
+       BufferedReader br = new BufferedReader(new FileReader(full_pub_json_file));
+       try {
+
+         StringBuilder sb = new StringBuilder();
+         String line = br.readLine();
+
+         while (line != null) {
+            sb.append(line);
+            sb.append(System.lineSeparator());
+            line = br.readLine();
+         }
+         everything = sb.toString();
+       }
+       catch (Exception e) {
+         e.printStackTrace();
+       }
+       finally {
+          br.close();
+       }
+
+       JSONObject obj = new JSONObject(everything);
+       name  = obj.getString("name");
+       email = obj.getString("email");
+       desc  = obj.getString("desc");
+     }
+
+     
+   %>
+
+    <style>
+      .vertical-align {
+        position: relative;
+        top: 50%;
+        -webkit-transform: translateY(-50%);
+        -ms-transform: translateY(-50%);
+        transform: translateY(-50%);
+      }
+    </style>
+
+  </head>
+
+  <body>
+    <div data-role="page" id="innovation-story-01" class="demo-page">
+      
+      <div data-role="content">
+	  
+ 	<a target="_parent" href="../index.html" class="back-button back-left"></a>
+										  
+	<div class="story-page" id="static-info-page">
+	  <!-- put custom content here -->
+	  
+	  <div class="story-title" style="margin-left: 25px;">
+
+	    <h1 class="center">My Design @ The University of Waikato</h1>
+
+	    <p class="center" style="margin: 6px;">-- The New Zealand Flag Debate</p>
+	    
+	    <div class="center" style="height: 220px; position: relative;">
+	      <div style="display: inline-block; position: relative;">
+		<img alt="" src="//upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Flag_of_New_Zealand.svg/250px-Flag_of_New_Zealand.svg.png" srcset="//upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Flag_of_New_Zealand.svg/375px-Flag_of_New_Zealand.svg.png 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Flag_of_New_Zealand.svg/500px-Flag_of_New_Zealand.svg.png 2x" data-file-width="1200" data-file-height="600" height="200" widthXX="350" />
+	      </div>
+	      <div style="height: 200px; font-size: 300%; display: inline-block;" class="vertical-alignXX">VS</div>
+	      <div style="display: inline-block; position: relative">
+		<a id="myflag-svg" data-ajax="false" ><img id="myflag-png" height="200" style="border: none;"/></a>
+	      </div>
+	    </div>
+
+
+
+<script type="text/javascript">
+
+var published_id = "<%= request.getParameter("pub-name") %>";
+var name  = "<%= name %>";
+var email = "<%= email %>";
+var desc  = "<%= desc %>";
+
+document.write("<center>");
+document.write("  <div style=\"width: 500px; background: #181818; padding: 5px; margin: 10px;\">");
+document.write("    <p>Designer: " + name + "<p/>");
+document.write("    <p>Email: " + email + "<p/>");
+document.write("    <p>Description: " + desc + "<p/>");
+document.write("  </div>");
+document.write("</center>");
+
+
+var a2a_config = a2a_config || {};
+a2a_config.linkname = "NZ Flag Design @ University of Waikato";
+
+var base_url = location.protocol + '//' + location.host + location.pathname;
+
+a2a_config.linkurl = base_url + "?pub-name=" + published_id
+
+</script>
+
+<!-- AddToAny BEGIN -->
+<center>
+<div class="a2a_kit a2a_kit_size_32 a2a_default_style" style="width: 260px;">
+<a class="a2a_dd" href="https://www.addtoany.com/share_save"></a>
+<a class="a2a_button_email"></a>
+<a class="a2a_button_facebook"></a>
+<a class="a2a_button_google_plus"></a>
+<a class="a2a_button_google_gmail"></a>
+<a class="a2a_button_twitter"></a>
+<a class="a2a_button_tumblr"></a>
+</div>
+</center>
+
+<script type="text/javascript" src="//static.addtoany.com/menu/page.js"></script>
+<!-- AddToAny END -->
+
+
+    <center>
+    <p style="font-size: 200%;">
+      <i>
+      <a href="../index.html">Interactive Flag Design Website</a> by:
+       <a target="_blank" href="http://cosi.cms.waikato.ac.nz">The Centre for Open Source Innovation</a>
+       <a target="_blank" href="http://cosi.cms.waikato.ac.nz">(COSI)</a> at the <a href="http://www.waikato.ac.nz">University of Waikato</a>	
+     </i>
+    </p>	
+    </center>
+
+
+	  </div>
+	  <!-- end of putting custom content -->
+
+	</div> <!-- end story-page-->		
+	
+      </div><!-- /content -->
+      
+    </div><!-- /page -->
+
+    <script>
+      $(document).ready( function() {
+      
+      var my_flag_png = "<%= "../published/" + pub_name + "/" + my_flag_png %>";
+      var my_flag_svg = "<%= "../published/" + pub_name + "/" + my_flag_svg %>";
+
+      $('#myflag-png').attr("src",  my_flag_png);
+      $('#myflag-svg').attr("href", my_flag_svg);
+
+      });
+
+    </script>
+
+  </body>
+</html>
+  
+
+
+
+
+
