<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="org.apache.commons.fileupload.*" %> <%@ page import="java.io.BufferedReader" %> <%@ page import="java.io.File" %> <%@ page import="java.io.InputStream" %> <%@ page import="java.io.BufferedOutputStream" %> <%@ page import="java.io.InputStreamReader" %> <%@ page import="java.util.List" %> <%@ page import="org.crosswire.xml.XMLBlock" %> <%@ page import="org.crosswire.sword.keys.VerseKey" %> <% String userID = null; String xml = null; try { DiskFileUpload fu = new DiskFileUpload(); // maximum size before a FileUploadException will be thrown fu.setSizeMax(99000000); // maximum size that will be stored in memory fu.setSizeThreshold(4096); // the location for saving data that is larger than getSizeThreshold() fu.setRepositoryPath(session.getServletContext().getRealPath("tmp/")); List fileItems = fu.parseRequest(request); // assume we know there are two files. The first file is a small // text file, the second is unknown and is written to a file on // the server for (int i = 0; i < fileItems.size(); i++) { FileItem fi = (FileItem)fileItems.get(i); if (fi.isFormField()) { if ("userID".equals(fi.getFieldName())) { userID = fi.getString(); } } else { // filename on the client xml = convertRegToXML(fi.get()); } } } catch (Exception e) { e.printStackTrace(); } %> Regularization Rules Importer

Import Regularization Rules

<% if (xml != null) { %>
<% XMLBlock rules = XMLBlock.createXMLBlock(xml); int i = 0; for (XMLBlock r : rules.getBlocks("rule")) { String q = r.getValue("q"); String verseText = r.getValue("sel_mss"); String verses[] = verseText.split("·"); if (q.indexOf("····") > -1) { q = q.substring(0,q.indexOf("····")); } for (int v = 0; v < verses.length || v < 1; ++v) { if (verseText.length() > 0) { if (verses[v].length() < 2) continue; VerseKey vk = new VerseKey(); vk.setIntros(true); vk.setAutoNormalize(false); vk.setTestament(2); if (verses[v].charAt(0) == 'B' || verses[v].charAt(0) == 'Β') { verses[v] = verses[v].substring(1); int off = verses[v].indexOf("K"); if (off < 0) { off = verses[v].indexOf("Κ"); } if (off > -1) { vk.setBook(Integer.parseInt(verses[v].substring(0, off))); verses[v] = verses[v].substring(off+1); off = verses[v].indexOf("V"); if (off > -1) { vk.setChapter(Integer.parseInt(verses[v].substring(0, off))); verses[v] = verses[v].substring(off+1); int verse = Integer.parseInt(verses[v]); if (verse == 0 && vk.getChapter() > 0) vk.setChapter(1); vk.setVerse(Integer.parseInt(verses[v])); verses[v] = vk.getOSISRef(); } } } } %> <% } } %>
scope mss_sel verse sourceword targetword type owner mss blocks places sel_plcs comment
<%=verseText.length() > 0?"Verse" : "Global"%> <%=verseText%> <%=verses.length > v ? verses[v] : ""%> <%=r.getValue("p")%> <%=q%> Spelling <%=userID%> <%=r.getAttribute("mss")%> <%=r.getAttribute("blocks")%> <%=r.getAttribute("places")%> <%=r.getValue("sel_plcs")%>  


<% } %>
File:
UserID:



<%! public static String convertRegToXML(byte reg[]) { StringBuffer result = new StringBuffer(); StringBuffer error = new StringBuffer(); runCommand(new String[] { "/home/liferay/src/community/webapp/vmr/api/regularization/import/regconvert" }, result, reg, error); System.out.println("stdout: "+result); System.out.println("stderr: "+error); return result.toString(); } public static int runCommand(String command[], StringBuffer result, byte stdin[], StringBuffer error) { int retVal = -1; try { java.lang.Process p = Runtime.getRuntime().exec(command, new String[0], new File("/home/liferay/src/community/webapp/vmr/api/regularization/import")); InputStream es = p.getErrorStream(); InputStreamReader esr = new InputStreamReader(es); BufferedReader errorReader = new BufferedReader(esr); InputStream is = p.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader input = new BufferedReader(isr); BufferedOutputStream os = new BufferedOutputStream(p.getOutputStream()); os.write(stdin, 0, stdin.length); os.close(); String line; while ((line = input.readLine()) != null) { if (result != null) { result.append(line + "\n"); } } StringBuffer e = new StringBuffer(); while ((line = errorReader.readLine()) != null) { e.append(line + "\n"); } if (error != null) error.append(e); retVal = p.waitFor(); if (e.length() > 0) { System.out.println(e.toString()); } } catch (Exception e) {e.printStackTrace();} return retVal; } %>