From: <se...@us...> - 2008-05-06 09:39:00
|
Revision: 89 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=89&view=rev Author: sem62 Date: 2008-05-06 02:39:02 -0700 (Tue, 06 May 2008) Log Message: ----------- * Added php service * Added Settings class. It will collect all settings information. * initalize settings value with applet's params tags. * delete some not needed resource files. Modified Paths: -------------- WebEditor/src/deploy.jardesc WebEditor/src/edu/lnu/FireFly/WebEditor/WSClients/WebEditorServiceClient.java WebEditor/src/edu/lnu/FireFly/WebEditor/WebEditor.java WebEditor/src/resources/index.html Added Paths: ----------- WebEditor/src/edu/lnu/FireFly/WebEditor/Settings.java WebEditor/src/service/ WebEditor/src/service/config.inc.php WebEditor/src/service/copyFromTemplate.php WebEditor/src/service/getFileContent.php WebEditor/src/service/setFileContent.php Modified: WebEditor/src/deploy.jardesc =================================================================== --- WebEditor/src/deploy.jardesc 2008-05-05 15:58:05 UTC (rev 88) +++ WebEditor/src/deploy.jardesc 2008-05-06 09:39:02 UTC (rev 89) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="WINDOWS-1251" standalone="no"?> <jardesc> - <jar path="E:/ACMContester/out/web/WebEditor/webeditor.jar"/> + <jar path="s:/WebEditor/webeditor.jar"/> <options buildIfNeeded="true" compress="true" descriptionLocation="/webEditor/src/deploy.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="true" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/> <storedRefactorings deprecationInfo="true" structuralOnly="false"/> <selectedProjects/> Added: WebEditor/src/edu/lnu/FireFly/WebEditor/Settings.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/Settings.java (rev 0) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/Settings.java 2008-05-06 09:39:02 UTC (rev 89) @@ -0,0 +1,42 @@ +package edu.lnu.FireFly.WebEditor; + +public class Settings { + private String courseLocation = ""; + private String templateLocation = ""; + private String serviceLocation = ""; + + public static Settings obj = null; + + public static Settings getInstance(){ + + if (obj == null){ + obj = new Settings(); + } + + return obj; + } + + public String getCourseLocation() { + return courseLocation; + } + + public void setCourseLocation(String courseLocation) { + this.courseLocation = courseLocation; + } + + public String getTemplateLocation() { + return templateLocation; + } + + public void setTemplateLocation(String templateLocation) { + this.templateLocation = templateLocation; + } + + public String getServiceLocation() { + return serviceLocation; + } + + public void setServiceLocation(String serviceLocation) { + this.serviceLocation = serviceLocation; + } +} Modified: WebEditor/src/edu/lnu/FireFly/WebEditor/WSClients/WebEditorServiceClient.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/WSClients/WebEditorServiceClient.java 2008-05-05 15:58:05 UTC (rev 88) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/WSClients/WebEditorServiceClient.java 2008-05-06 09:39:02 UTC (rev 89) @@ -1,51 +1,129 @@ package edu.lnu.FireFly.WebEditor.WSClients; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.net.URL; +import java.net.URLConnection; +import java.net.URLEncoder; +import edu.lnu.FireFly.WebEditor.Settings; + public class WebEditorServiceClient { - public static String getFileContent(String fName){ - try{ - WSConnection conn = new WSConnection(); - conn.setServiceURL(new URL ("http://localhost:8080/WebEditor/WebEditorServiceService")); - conn.setServiseNameSpace("http://WebEditorServer.FireFly.lnu.edu/"); - String value = GetFileContentWSResponse.getValue(conn.invoke(new GetFileContentWSRequest(fName))); + public static String getFileContent(String fName) { + String result = ""; + try { + // Construct data + String data = URLEncoder.encode("fName", "UTF-8") + "=" + + URLEncoder.encode(fName, "UTF-8"); + + // Send data + URL url = new URL(Settings.getInstance().getServiceLocation() + + "getFileContent.php"); -// value = new String(new sun.misc.BASE64Decoder().decodeBuffer(value)); + URLConnection conn = url.openConnection(); + conn.setDoOutput(true); - return value; - } - catch (Exception e) { + 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(); - return null; } + + return result; } public static void setFileContent(String fName, String content) { - try{ - WSConnection conn = new WSConnection(); - conn.setServiceURL(new URL ("http://localhost:8080/WebEditor/WebEditorServiceService")); - conn.setServiseNameSpace("http://WebEditorServer.FireFly.lnu.edu/"); + String result = ""; + try { + // Construct data + String data = URLEncoder.encode("fName", "UTF-8") + "=" + + URLEncoder.encode(fName, "UTF-8"); + data += "&" + URLEncoder.encode("content", "UTF-8") + "=" + + URLEncoder.encode(content, "UTF-8"); + + // Send data + URL url = new URL(Settings.getInstance().getServiceLocation() + + "setFileContent.php"); - conn.invoke(new SetFileContentWSRequest(fName, content)); -// conn.invoke(new SetFileContentWSRequest(fName, new BASE64Encoder().encode(content.getBytes()))); - } - catch (Exception e) { + 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("setFileContent(). result is:"); + System.out.println(result); } - public static boolean copyFromTemplate(String fNameInTemplate, String fNameInCourse){ - try{ - WSConnection conn = new WSConnection(); - conn.setServiceURL(new URL ("http://localhost:8080/WebEditor/WebEditorServiceService")); - conn.setServiseNameSpace("http://WebEditorServer.FireFly.lnu.edu/"); + 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"); - return CopyFromTemplateWSResponse.getValue(conn.invoke(new CopyFromTemplateWSRequest(fNameInTemplate, fNameInCourse))); - } - catch (Exception e) { + 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(); - return false; } + + System.out.println("copyFromTemplate(). result is:"); + System.out.println(result); + + return true; } - } Modified: WebEditor/src/edu/lnu/FireFly/WebEditor/WebEditor.java =================================================================== --- WebEditor/src/edu/lnu/FireFly/WebEditor/WebEditor.java 2008-05-05 15:58:05 UTC (rev 88) +++ WebEditor/src/edu/lnu/FireFly/WebEditor/WebEditor.java 2008-05-06 09:39:02 UTC (rev 89) @@ -84,6 +84,11 @@ @Override public void init() { + + Settings.getInstance().setCourseLocation(getParameter("courseLocation")); + Settings.getInstance().setServiceLocation(getParameter("serviceLocation")); + Settings.getInstance().setTemplateLocation(getParameter("templateLocation")); + instance = this; initMenu(); @@ -168,7 +173,7 @@ .findResourceByIdentifier(item.identifierref); if (resource != null) { getAppletContext().showDocument( - new URL("http://localhost:8080/WebEditor/course/" + new URL(Settings.getInstance().getCourseLocation() + resource.getFullHref()), "ContentFrame"); System.out.print("redirected\n"); } Modified: WebEditor/src/resources/index.html =================================================================== --- WebEditor/src/resources/index.html 2008-05-05 15:58:05 UTC (rev 88) +++ WebEditor/src/resources/index.html 2008-05-06 09:39:02 UTC (rev 89) @@ -3,7 +3,7 @@ <title>Learning system :: Editor of courses</title> <script type="text/javascript" src="api.js"></script> <script type="text/javascript" src="navigation.js"></script> - + <style> .left-corn { width: 20px; @@ -57,7 +57,7 @@ padding: 4px; } </style> - + </head> <body onUnload="exit_clicked(false);" bgcolor='#215E21'> @@ -86,6 +86,9 @@ <tr height='*'> <td class='side-body'> <applet mayscript="" name="player" archive="webeditor.jar,RTEValidators.jar,FFManifest.jar, dom4j.jar" code=edu.lnu.FireFly.WebEditor.WebEditor.class width="100%" height="100%"> + <PARAM NAME="courseLocation" VALUE="http://127.0.0.1/sem/course/"> + <PARAM NAME="serviceLocation" VALUE="http://127.0.0.1/sem/WebEditor/service/"> + <PARAM NAME="templateLocation" VALUE="http://127.0.0.1/sem/WebEditor/template"> </applet> </td> </tr> @@ -113,7 +116,7 @@ </table> </table> </td> - </tr> + </tr> </tbody> </table> </table> Added: WebEditor/src/service/config.inc.php =================================================================== --- WebEditor/src/service/config.inc.php (rev 0) +++ WebEditor/src/service/config.inc.php 2008-05-06 09:39:02 UTC (rev 89) @@ -0,0 +1,6 @@ +<? + $base_dir = "../../"; + + $course_location = $base_dir . "course/"; + $template_location = $base_dir . "WebEditor/template/"; +?> \ No newline at end of file Added: WebEditor/src/service/copyFromTemplate.php =================================================================== --- WebEditor/src/service/copyFromTemplate.php (rev 0) +++ WebEditor/src/service/copyFromTemplate.php 2008-05-06 09:39:02 UTC (rev 89) @@ -0,0 +1,10 @@ +<? + require_once("config.inc.php"); + + if (isset($_POST['fNameInTemplate']) && isset($_POST['fNameInCourse'])){ + $log = fopen('service.txt', 'a'); + $source = $template_location . $_POST['fNameInTemplate']; + $dest = $course_location . $_POST['fNameInCourse']; + echo copy($source, $dest); + } +?> \ No newline at end of file Added: WebEditor/src/service/getFileContent.php =================================================================== --- WebEditor/src/service/getFileContent.php (rev 0) +++ WebEditor/src/service/getFileContent.php 2008-05-06 09:39:02 UTC (rev 89) @@ -0,0 +1,7 @@ +<? + require_once("config.inc.php"); + + if (isset($_POST['fName'])){ + readfile ($course_location . $_POST['fName']); + } +?> \ No newline at end of file Added: WebEditor/src/service/setFileContent.php =================================================================== --- WebEditor/src/service/setFileContent.php (rev 0) +++ WebEditor/src/service/setFileContent.php 2008-05-06 09:39:02 UTC (rev 89) @@ -0,0 +1,9 @@ +<? + require_once("config.inc.php"); + + if (isset($_POST['fName']) && isset($_POST['content'])){ + $fp = fopen($course_location . $_POST['fName'], 'w'); + fwrite($fp, $_POST['content']); + fclose($fp); + } +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |