<%@ page contentType="text/html; charset=UTF-8" %> NZ Flag Design @ The University of Waikato (<%=request.getParameter("pub-name")%>) <%@ page import="java.io.*,java.util.*,java.awt.image.*,javax.imageio.*,javax.xml.bind.DatatypeConverter,java.nio.file.*,org.json.*" %> <%! private static void copyFile(File source, File dest) throws IOException { InputStream input = null; OutputStream output = null; try { input = new FileInputStream(source); output = new FileOutputStream(dest); byte[] buf = new byte[1024]; int bytesRead; while ((bytesRead = input.read(buf)) > 0) { output.write(buf, 0, bytesRead); } } finally { input.close(); output.close(); } } /* private static void copyFileChannels(File source, File dest) throws IOException { FileChannel inputChannel = null; FileChannel outputChannel = null; try { inputChannel = new FileInputStream(source).getChannel(); outputChannel = new FileOutputStream(dest).getChannel(); outputChannel.transferFrom(inputChannel, 0, inputChannel.size()); } finally { inputChannel.close(); outputChannel.close(); } } */ /* public static void copyFile_JAVA17( 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").replace("\n"," ").replace("\r"," "); BufferedWriter bw = new BufferedWriter(new FileWriter(full_pub_json_file)); JSONObject obj = new JSONObject(); obj.append("pubName",pub_name); obj.append("name",name); obj.append("email",email); obj.append("desc",desc); obj.write(bw); // bw.write("{ \"pubName\": \"" + pub_name + "\", \"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").replace("\n"," ").replace("\r"," ").replace(" "," "); } 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(); String line_sep = System.getProperty("line.separator"); while (line != null) { sb.append(line); sb.append(line_sep); line = br.readLine(); } everything = sb.toString(); } catch (Exception e) { e.printStackTrace(); } finally { br.close(); } JSONObject obj = new JSONObject(everything); try { name = obj.getString("name"); } catch (Exception e) { name = obj.getJSONArray("name").getString(0); } try { email = obj.getString("email"); } catch (Exception e) { email = obj.getJSONArray("email").getString(0); } try { desc = obj.getString("desc"); } catch (Exception e) { desc = obj.getJSONArray("desc").getString(0); } } // For use in Javascript pub_name = pub_name.replace("\"","\\\""); name = name.replace("\"","\\\""); email = email.replace("\"","\\\""); desc = desc.replace("\"","\\\""); %> <% //String action = request.getParameter("action"); // only add FB like ability if visiting the item after it has been published if (action == null) { %>
<% } %>

My Design '<%=request.getParameter("pub-name")%>' @ The University of Waikato

— The New Zealand Flag Debate

VS
" data-layout="standard" data-action="like" data-show-faces="false" data-share="false">

Share this design:

Or else view other flags designed at Fieldays through this link

Interactive Flag Design Website by: The Centre for Open Source Innovation (COSI)
at the University of Waikato