<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <%@ page import="java.io.IOException" %> <%@ page import="java.io.InputStream" %> <%@ page import="java.io.BufferedReader" %> <%@ page import="java.io.File" %> <%@ page import="java.nio.charset.Charset" %> <%@ page import="java.io.InputStreamReader" %> <%@ page import="org.apache.log4j.Logger" %> <%@ page import="javax.servlet.http.Cookie" %> <%! public static void dumpCallInfo(HttpServletRequest request, Logger logger) { logger.info("CallInfo..."); logger.info("request.getContentType: " + request.getContentType()); logger.info("Headers: "); for (Object o: java.util.Collections.list(request.getHeaderNames())) { logger.info(o + "=" + request.getHeader(o.toString())); } logger.info("Attributes: "); for (Object o: java.util.Collections.list(request.getAttributeNames())) { logger.info(o + "=" + request.getAttribute(o.toString())); } logger.info("Parameters: "); for (Object o: java.util.Collections.list(request.getParameterNames())) { for (String v: request.getParameterValues(o.toString())) { logger.info(o + "=" + v); } } } %> <% Logger logger = Logger.getLogger("collation_editor/vmrcre_collation"); String requestURI = request.getRequestURI(); // strip the webapp name off the URI requestURI = requestURI.substring(requestURI.indexOf("/", 2)); File collate_cli = new File(getServletContext().getRealPath(requestURI)); collate_cli = new File(collate_cli.getParent(), "collate_cli.py"); boolean reEncode = false; //dumpCallInfo(request, logger); String options = request.getParameter("options"); String action = request.getParameter("action"); if (options != null) { response.setContentType("application/json"); // collation if ("collation".equals(action)) { } // apparatus export else { response.setContentType("text/plain"); response.setHeader("Content-Disposition", "attachment; filename=\"negative-apparatus.xml\""); response.setHeader("Set-Cookie", "fileDownload=true; path=/"); reEncode = true; } String args[] = new String[] { "python3", collate_cli.getAbsolutePath(), "--action=" + action, }; StringBuffer resultBuf = new StringBuffer(); StringBuffer errorBuf = new StringBuffer(); logger.info("About to call Cat's stuff."); logger.info("********************************************************* Action: " + action); logger.info("********************************************************* Input: " + options); runCommand(args, resultBuf, errorBuf, options, logger); logger.info("Finished calling Cat's stuff."); if (reEncode) resultBuf = new StringBuffer(new String(resultBuf.toString().getBytes("iso8859-1"), "UTF-8")); //logger.info("Result: " + resultBuf); logger.info("********************************************************* Result: " + resultBuf + "***** END RESULT *****"); if (errorBuf.length() > 0) logger.error("*********************************************** Collation Error: " + errorBuf); %> <%= resultBuf %> <% return; } %>

vmrcre_collation

collation from the collation_editor to collatex

Parameters

optionsdata from collation_editor
<%! public static Thread startSlurpStreamThreaded(final InputStream is, final StringBuffer outBuf) { Thread t = new Thread() { InputStream myIS = is; StringBuffer myOutBuf = outBuf; public void run() { try { InputStreamReader isr = new InputStreamReader(myIS); BufferedReader br = new BufferedReader(isr); String line=null; while ( (line = br.readLine()) != null) myOutBuf.append(line + "\n"); } catch (IOException ioe) { ioe.printStackTrace(); } } }; t.start(); return t; } public static int runCommand(String command[], StringBuffer result, StringBuffer error, String toStdin, Logger logger) { int retVal = -1; try { File cwd = new File("."); String cmd = ""; for (String s: command) { cmd += " [" + s + "]"; } logger.debug("executing from cwd ("+cwd.getAbsolutePath()+"):" + cmd); java.lang.Process p = Runtime.getRuntime().exec(command, new String[0], cwd); p.getOutputStream().write(toStdin.getBytes(Charset.forName("UTF-8"))); Thread o = startSlurpStreamThreaded(p.getInputStream(), result); Thread e = startSlurpStreamThreaded(p.getErrorStream(), error); p.getOutputStream().close(); retVal = p.waitFor(); o.join(); e.join(); logger.debug("returned from executing executing...."); if (error.length() > 0) { logger.warn("ERROR!!!!!!!!!!!!!!!!!!!!!!: " + error.toString()); } } catch (Exception e) { logger.error("ERROR!!!!!!!!!!!!!!!!!!!!!!!!!!!: " + e + "; retVal: " + retVal + "; stdout: " + result); e.printStackTrace(); } logger.debug("returned: " + retVal + "; stdout: " + result); return retVal; } %>