From: <se...@us...> - 2008-05-09 18:45:00
|
Revision: 112 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=112&view=rev Author: sem62 Date: 2008-05-09 11:43:59 -0700 (Fri, 09 May 2008) Log Message: ----------- Transfer data optimization. * If you download the same file againe - use content in hashMap. * If you set content the same as previous one - it's ignore. Modified Paths: -------------- WebEditor/src/edu/lnu/FireFly/WebEditor/WSClients/WebEditorServiceClient.java Modified: WebEditor/src/edu/lnu/FireFly/WebEditor/WSClients/WebEditorServiceClient.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/WSClients/WebEditorServiceClient.java 2008-05-09 16:45:53 UTC (rev 111) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/WSClients/WebEditorServiceClient.java 2008-05-09 18:43:59 UTC (rev 112) @@ -13,11 +13,13 @@ public class WebEditorServiceClient { private HashMap<String, String> templates; + private HashMap<String, String> contents; private static WebEditorServiceClient obj = null; private WebEditorServiceClient(){ templates = new HashMap<String, String>(); + contents = new HashMap<String, String>(); } public static WebEditorServiceClient getInstance(){ @@ -38,11 +40,15 @@ if (location.equalsIgnoreCase("template")){ String template = templates.get(fName); if (template != null){ - - System.out.println("Founded in hash."); - + System.out.println("Founded in templates hash."); return template; } + } else { + String content = contents.get(fName); + if (content != null){ + System.out.println("Founded in contents hash."); + return content; + } } String result = ""; @@ -82,7 +88,9 @@ if (location.equalsIgnoreCase("template")){ templates.put(fName, result); - } + } else { + contents.put(fName, result); + } System.out.print("result: " + result); return result; @@ -91,6 +99,14 @@ public void setFileContent(String fName, String content) { System.out.println("Setting file's content (fName=" + fName + ")..."); + String hashedContent = contents.get(fName); + if (content.equals(hashedContent)){ + System.out.println("Not modified."); + return ; + } + + contents.put(fName, content); + String result = ""; try { // Construct data @@ -128,46 +144,4 @@ System.out.println("setFileContent(). result is:"); System.out.println(result); } - -// public static boolean copyFromTemplate(String fNameInTemplate, -// String fNameInCourse) { -// String result = ""; -// try { -// // Construct data -// String data = URLEncoder.encode("fNameInTemplate", "UTF-8") + "=" -// + URLEncoder.encode(fNameInTemplate, "UTF-8"); -// data += "&" + URLEncoder.encode("fNameInCourse", "UTF-8") + "=" -// + URLEncoder.encode(fNameInCourse, "UTF-8"); -// -// // Send data -// URL url = new URL(Settings.getInstance().getServiceLocation() -// + "copyFromTemplate.php"); -// -// URLConnection conn = url.openConnection(); -// conn.setDoOutput(true); -// -// OutputStreamWriter wr = new OutputStreamWriter(conn -// .getOutputStream()); -// -// wr.write(data); -// wr.flush(); -// -// // Get the response -// BufferedReader rd = new BufferedReader(new InputStreamReader(conn -// .getInputStream())); -// String line; -// while ((line = rd.readLine()) != null) { -// result += line + "\n"; -// } -// wr.close(); -// rd.close(); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// -// System.out.println("copyFromTemplate(). result is:"); -// System.out.println(result); -// -// return true; -// } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |