[mhk] r1080 committed - Editing and saving kleio and gedcom files @ mhk_families

2 views
Skip to first unread message

codesite...@google.com

unread,
Jun 6, 2013, 6:21:11 PM6/6/13
to mhk-dis...@googlegroups.com
Revision: 1080
Author: tbc...@gmail.com
Date: Thu Jun 6 14:02:11 2013
Log: Editing and saving kleio and gedcom files @ mhk_families
http://code.google.com/p/mhk/source/detail?r=1080

Added:
/branches/mhk_families/idb/etc/template/new/edit_files.vm
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/DoEdit.java
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/DoSaveFile.java
Modified:
/branches/mhk_families/idb/etc/template/new/sources_page.vm

/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/resources/MHKStrings.properties

/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/resources/MHKStrings_pt.properties
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/CentralServlet.java

=======================================
--- /dev/null
+++ /branches/mhk_families/idb/etc/template/new/edit_files.vm Thu Jun 6
14:02:11 2013
@@ -0,0 +1,87 @@
+#set ( $title = "$mhks.get('time.link') - $mhks.get('edit.documents')")
+
+#parse("new/head.vm")
+
+</head>
+
+<body>
+
+#parse("new/header.vm")
+
+#parse("new/setup.vm")
+
+ <table>
+ <tr><td>File: $filename</td></tr>
+ <tr>
+ <td colspan="3">
+ <textarea id="file_content"
style="width:512px;height:256px"></textarea>
+ </td>
+ </tr>
+ <tr>
+ <td>Filename to Save As:</td>
+ <td><input id="file_name"></input></td>
+ <td><button onclick="saveFile()">Save File</a></td>
+ </tr>
+ ## <tr>
+ ## <td>Select a File to Load:</td>
+ ## <td><input type="file" id="fileToLoad">
+ ## <td><button onclick="loadFileAsText()">Load Selected
File</a><td>
+ ## </tr>
+ </table>
+
+#parse("new/footer.vm")
+
+</body>
+<script type='text/javascript'>
+ ##alert("${file_content}");
+ var java_text="${file_content}";
+ ##var final_text = java_text.replace(/\n/g , "<br>");
+ ##alert(final_text)
+
+ ##var text="W3Schools----\"-----<br>---\"";
+
+ document.getElementById("file_content").value=java_text;
+ ##alert(fileToLoad);
+ ##var fileReader = new FileReader();
+ ##fileReader.onload = function(fileLoadedEvent)
+ ## {
+ ## var textFromFileLoaded = fileLoadedEvent.target.result;
+ ## document.getElementById("inputTextToSave").value =
textFromFileLoaded;
+ ##};
+ ##fileReader.readAsText(fileToLoad, "UTF-8");
+
+## function saveFile()
+## {
+## var textToWrite = document.getElementById("file_content").value;
+ ##var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
+## var fileNameToSaveAs =
document.getElementById("inputFileNameToSaveAs").value;
+
+ ##var downloadLink = document.createElement("a");
+ ##var url = (window.webkitURL != null ? window.webkitURL :
window.URL);
+ ##downloadLink.href = url.createObjectURL(textFileAsBlob);
+ ##downloadLink.download = fileNameToSaveAs;
+ ##downloadLink.click();
+## saveAs(textFileAsBlob,fileNameToSaveAs);
+## }
+
+ function saveFile()
+ {
+ ##alert("${currentdir}");
+ var filename=document.getElementById("file_name").value;
+ var file_content=document.getElementById("file_content").value;
+ ##alert(file_content);
+ var final_content=file_content.replace(/\n/g , "<br>");
+ var xmlhttp;
+ if (window.XMLHttpRequest)
+ {## code for IE7+, Firefox, Chrome, Opera, Safari
+ xmlhttp=new XMLHttpRequest();
+ }
+ else
+ {## code for IE6, IE5
+ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
+ }
+
xmlhttp.open("GET","${uri}?dbname=$db.dbname&action=save_file&script=show_sources.vm&currentdir=$currentdir&extension=$extension&filename="+filename+"&file_content="+final_content,true);
+ xmlhttp.send();
+ }
+</script>
+</html>
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/DoEdit.java Thu
Jun 6 14:02:11 2013
@@ -0,0 +1,73 @@
+/*
+ * Created by Tiago Ceia
+ * Date: Jun 01, 2013
+ */
+
+package pt.uc.cisuc.jrc.mhk.servlet;
+
+import org.apache.velocity.context.Context;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+
+/**
+ * This command launches the edition of a Kleio or Gedcom file.
+ * * The following parameters are allowed in the request:
+ * * kleiofile: name of kleio file to be edited
+ * * gedcomfile: name of gedcom file to be edited
+ * * currentdir: the path to the current dir: this is just passed to
the template context, so that
+ * * the directory from which the translator was launched can be
kept.
+ */
+public class DoEdit extends Command {
+
+ public DoEdit(ServletContext con, HttpServletRequest req,
HttpServletResponse resp) {
+ super(con, req, resp);
+ }
+
+ public String exec(Context ctx) {
+ System.out.println("DoEdit");
+ String filename=null;
+
+ if(request.getParameter("kleiofile")!=null){//IF KLEIO EDITION
+ filename = request.getParameter("kleiofile");
+ ctx.put("extension",".cli");
+ }
+ else{ //IF GEDCOM EDITION
+ filename = request.getParameter("gedcomfile");
+ ctx.put("extension",".ged");
+ }
+ BufferedReader br=null;
+ String file_content=null;
+ try {
+
+ String line;
+ br = new BufferedReader(new FileReader(filename));
+ while ((line = br.readLine()) != null)
+ file_content+="\\n"+line;
+ } catch (IOException e) {
+ System.out.println("[DoEdit] Problem reading file "+filename+"!");
+ } finally {
+ try {
+ if (br != null)br.close();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ String currentdir = request.getParameter("currentdir");
+ file_content=file_content.replace("\"", "\\\"");
+ currentdir=currentdir.replace('\\','/');
+ //System.out.println(currentdir);
+// System.out.println(currentdir);
+// filename=filename.replace('\\','/');
+// System.out.println(file_content);
+ ctx.put("file_content",file_content);
+ ctx.put("currentdir", currentdir);
+ ctx.put("filename", filename);
+ return "edit_files.vm";
+ }
+}
=======================================
--- /dev/null
+++ /branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/DoSaveFile.java
Thu Jun 6 14:02:11 2013
@@ -0,0 +1,55 @@
+/*
+ * Created by Tiago Ceia
+ * Date: Jun 01, 2013
+ */
+
+package pt.uc.cisuc.jrc.mhk.servlet;
+
+import org.apache.velocity.context.Context;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+import java.io.FileWriter;
+
+/**
+ * This command saves a file to the server disk ()
+ * * The following parameters are allowed in the request:
+ * * filename: name of the file to be saved
+ * * file_content:The file itself
+ * * currentdir: the path to the current dir: this is just passed to
the template context, so that
+ * * the directory from which the translator was launched can be
kept.
+ */
+public class DoSaveFile extends Command {
+
+ public DoSaveFile(ServletContext con, HttpServletRequest req,
HttpServletResponse resp) {
+ super(con, req, resp);
+ }
+
+ public String exec(Context ctx) {
+ System.out.println("DoSaveFile");
+ String currentdir = request.getParameter("currentdir");
+ String filename = request.getParameter("filename");
+ String extension = request.getParameter("extension");
+ String file_content = request.getParameter("file_content");
+ System.out.println(currentdir);
+ String path=currentdir+"/"+filename+extension;
+ System.out.println(path);
+ System.out.println(file_content);
+ file_content=file_content.replaceAll("<br>", "\\\n");;
+ FileWriter fw=null;
+
+ try{
+ fw = new FileWriter(path);
+ fw.write(file_content);
+ fw.close();
+ } catch (IOException e1) {
+ System.out.println("[DoSaveFiles] Problem writing file.");
+ }
+
+ ctx.put("currentdir", currentdir);
+ return "edit_files.vm";
+ }
+}
=======================================
--- /branches/mhk_families/idb/etc/template/new/sources_page.vm Wed May 1
11:03:41 2013
+++ /branches/mhk_families/idb/etc/template/new/sources_page.vm Thu Jun 6
14:02:11 2013
@@ -203,8 +203,8 @@
#set ($inkcolor = "BLACK")
#end

- <FONT size="-1" COLOR="$inkcolor"><img
src="${baseaddr}/images/file.png">&nbsp;$source.kleioFile.getName()</FONT>
-
+
+ <A
HREF="${uri}?dbname=$!dbname&action=edit&kleiofile=$source.kleioFile.getPath()&currentdir=$currentdir"><FONT
size="-1" COLOR="$inkcolor"><img
src="${baseaddr}/images/file.png">&nbsp;$source.kleioFile.getName()</FONT></a>
</TD>

<TD><small>$source.kleioFileAltered</small></TD> <!-- altered date -->
@@ -433,7 +433,7 @@
#set ($inkcolor = "BLACK")
#end

- <FONT size="-1" COLOR="$inkcolor"><img
src="${baseaddr}/images/file.png">&nbsp;$source.gedcomFile.getName()</FONT>
+ <A
HREF="${uri}?dbname=$!dbname&action=edit&gedcomfile=$source.gedcomFile.getPath()&currentdir=$currentdir"><FONT
size="-1" COLOR="$inkcolor"><img
src="${baseaddr}/images/file.png">&nbsp;$source.gedcomFile.getName()</FONT></a>

</TD>

=======================================
---
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/resources/MHKStrings.properties
Thu May 2 14:30:39 2013
+++
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/resources/MHKStrings.properties
Thu Jun 6 14:02:11 2013
Binary file, no diff available.
=======================================
---
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/resources/MHKStrings_pt.properties
Thu May 2 17:39:56 2013
+++
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/resources/MHKStrings_pt.properties
Thu Jun 6 14:02:11 2013
Binary file, no diff available.
=======================================
---
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/CentralServlet.java
Thu May 2 16:40:41 2013
+++
/branches/mhk_families/idb/pt/uc/cisuc/jrc/mhk/servlet/CentralServlet.java
Thu Jun 6 14:02:11 2013
@@ -1189,6 +1189,12 @@
} else if (name.equalsIgnoreCase("translate") && level > 2 &&
adminUser.equals(user)) {
c = new DoTranslate(appcontext, req, resp);
template = c.exec(context);
+ } else if (name.equalsIgnoreCase("edit") && level > 2 &&
adminUser.equals(user)) {
+ c = new DoEdit(appcontext, req, resp);
+ template = c.exec(context);
+ } else if (name.equalsIgnoreCase("save_file") && level > 2 &&
adminUser.equals(user)) {
+ c = new DoSaveFile(appcontext, req, resp);
+ template = c.exec(context);
} else if (name.equalsIgnoreCase("import") && level > 2 &&
adminUser.equals(user)) {
c = new DoImport(appcontext, req, resp);
template = c.exec(context);
Reply all
Reply to author
Forward
0 new messages