response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
HttpSession session = request.getSession();
FilterForm form = (FilterForm)session.getAttribute("filterForm");
if (form==null || form.getDirectory()==null) {
form = new FilterForm();
form.setMessage("Directory is null");
session.setAttribute("filterForm",form);
response.sendRedirect("./mainMenu.jsp");
}
// flags de processamento
boolean detailedOutput = request.getParameter("detailedOutput")!=null;
boolean methodStack = request.getParameter("methodsStack")!=null;
boolean objectsStack = request.getParameter("objectsStack")!=null;
boolean useIteractionsOnOutput = request.getParameter("useIteractionsOnOutput")!=null;
boolean processReleaseObjects = request.getParameter("releaseObjects")!=null;
String directory = form.getDirectory();
String pid = request.getParameter("selectedPID");
form.setSelectedPID(pid);
File fileDirectory = new File(directory);
if (!fileDirectory.isDirectory()) {
form.setMessage(directory + " isn't a directory");
response.sendRedirect("./errorSelection.jsp");
return;
}
File[] mainFile = fileDirectory.listFiles(new SPYFilterMain(pid));
if (mainFile.length==0) {
form.setMessage("PID Main File not found");
response.sendRedirect("./errorSelection.jsp");
return;
}
if (mainFile.length>1) {
form.setMessage("Cannot process more than one file");
response.sendRedirect("./errorSelection.jsp");
return;
}
out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"./imgs/cssdef.css\">");
out.println("<html><head><title>Processing PID " + request.getParameter("selectedPID") + "</title></head><body>");
File[] files = fileDirectory.listFiles(new SPYFilterThread(pid));
StreamHolder mainStream = openStream(mainFile[0]);
InputStream[] paramStreams = new InputStream[files.length];
StreamHolder[] holders = new StreamHolder[files.length];
// total number of bytes to be processed
long totalLength=mainFile[0].length();
for (int i=0;i<files.length;i++) {
out.println("<br>Opening "+ files[i].getAbsolutePath());
holders[i] = openStream(files[i]);
paramStreams[i] = holders[i].inputStream;
totalLength += files[i].length();
}
out.flush();
SpyReader reader = new SpyReader(mainStream.inputStream,paramStreams);
LogFileEngine engine = new LogFileEngine(reader);
ProcessListener listener = new ProcessListener(mainStream, holders, out, totalLength);
engine.addRunnerEventListener(listener);
engine.setOutputDirectory(fileDirectory);
engine.setProcessStackOnObjects(objectsStack);
engine.setProcessStackOnMethods(methodStack);
engine.setUseIteractionsOnOutput(useIteractionsOnOutput);
engine.setProcessReleaseOnObjects(processReleaseObjects);
String methodSignature = request.getParameter("methodSignature");
if (methodSignature!=null && methodSignature.trim().length()>0) {
engine.addDetailMethod(methodSignature); // voltar
}
if (detailedOutput) System.out.println("using detailedOutput");
engine.doProcess(detailedOutput,pid); // nao gera output com os arquivos html.gz
form.setJbpProcess(engine.getProcess());
for (int i=0;i<paramStreams.length;i++) {
paramStreams[i].close();
}
mainStream.inputStream.close();
out.println("<br><b><font size=6>Process Finished.... <a href=\"./processMethods.jsp\">click here</a></font></b>");