1 package jimm.datavision.gui.applet; 2 import jimm.datavision.Report; 3 import jimm.datavision.ErrorHandler; 4 import jimm.datavision.gui.Designer; 5 import jimm.datavision.gui.AskStringDialog; 6 import jimm.util.I18N; 7 import jimm.util.XMLWriter; 8 import java.io.InputStreamReader ; 9 import java.io.IOException ; 10 import java.net.URL ; 11 import java.net.URLConnection ; 12 import org.xml.sax.InputSource ; 13 14 20 class DesignApplet extends Designer { 21 22 DesignApplet(DVApplet applet) { 23 super(null, null, applet, null); 24 25 reportFilePath = getAppletViaCheapTrick().getSaveURL(); 26 } 27 28 38 protected boolean readReport(String fileName, String databasePassword) { 39 report = new Report(); 40 String url = getAppletViaCheapTrick().getReportURL(); 41 try { 42 if (url != null && url.length() > 0) 43 report.read(new InputSource (url)); 44 } 45 catch (Exception e) { 46 ErrorHandler.error(e); 47 } 48 49 reportFilePath = null; 50 return false; } 52 53 61 protected DVApplet getAppletViaCheapTrick() { 62 return (DVApplet)rootPaneContainer; 63 } 64 65 68 protected void saveReportAs() { 69 String name = new AskStringDialog(getFrame(), 70 I18N.get("DesignApplet.new_url_title"), 71 I18N.get("DesignApplet.new_url_prompt"), 72 reportFilePath) 73 .getString(); 74 75 if (name != null) { 76 reportFilePath = name; 77 writeReportFile(reportFilePath); 78 } 79 } 80 81 88 protected void writeReportFile(String fileName) { 89 URLConnection conn = null; 90 91 try { 92 URL url = new URL (fileName); 93 conn = url.openConnection(); 94 conn.setDoOutput(true); 95 96 sendData(conn); 97 receiveResponse(conn); 100 } 101 catch (Exception e) { 102 ErrorHandler.error(e); 103 } 104 105 commandHistory.setBaseline(); 107 } 108 109 protected void sendData(URLConnection conn) throws IOException { 110 XMLWriter out = null; 111 try { 112 out = new XMLWriter(conn.getOutputStream()); 113 report.writeXML(out); 114 out.flush(); 115 } 116 catch (IOException e) { 117 throw e; 118 } 119 finally { 120 if (out != null) out.close(); 121 } 122 } 123 124 protected void receiveResponse(URLConnection conn) throws IOException { 125 InputStreamReader in = null; 126 try { 127 in = new InputStreamReader (conn.getInputStream()); 128 char[] buf = new char[1024]; 129 while (in.read(buf) > 0) ; 130 } 131 catch (IOException e) { 132 throw e; 133 } 134 finally { 135 if (in != null) in.close(); 136 } 137 } 138 139 } 140 | Popular Tags |