/** * Process the specified HTTP request, and create the corresponding HTTP response (or forward to * another web component that will create it). Return an <code>ActionForward</code> instance * describing where and how control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @exception Exception if business logic throws an exception */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need MessageResources messages = getResources(request); // save errors ActionMessages errors = new ActionMessages(); // START check for login (security) if (!SecurityService.getInstance().checkForLogin(request.getSession(false))) { return (mapping.findForward("welcome")); } // END check for login (security) // START get id of current project from either request, attribute, or cookie // id of project from request String projectId = null; projectId = request.getParameter("projectViewId"); // check attribute in request if (projectId == null) { projectId = (String) request.getAttribute("projectViewId"); } // id of project from cookie if (projectId == null) { projectId = StandardCode.getInstance().getCookie("projectViewId", request.getCookies()); } // default project to last if not in request or cookie if (projectId == null) { java.util.List results = ProjectService.getInstance().getProjectList(); ListIterator iterScroll = null; for (iterScroll = results.listIterator(); iterScroll.hasNext(); iterScroll.next()) {} iterScroll.previous(); Project p = (Project) iterScroll.next(); projectId = String.valueOf(p.getProjectId()); } Integer id = Integer.valueOf(projectId); // END get id of current project from either request, attribute, or cookie // get project Project p = ProjectService.getInstance().getSingleProject(id); // get user (project manager) User u = UserService.getInstance() .getSingleUserRealName( StandardCode.getInstance().getFirstName(p.getPm()), StandardCode.getInstance().getLastName(p.getPm())); // START process pdf try { PdfReader reader = new PdfReader("C://templates/CL01_001.pdf"); // the template // save the pdf in memory ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); // the filled-in pdf PdfStamper stamp = new PdfStamper(reader, pdfStream); // stamp.setEncryption(true, "pass", "pass", PdfWriter.AllowCopy | PdfWriter.AllowPrinting); AcroFields form1 = stamp.getAcroFields(); Date cDate = new Date(); Integer month = cDate.getMonth(); Integer day = cDate.getDate(); Integer year = cDate.getYear() + 1900; String[] monthName = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; // set the field values in the pdf form // form1.setField("", projectId) form1.setField("currentdate", monthName[month] + " " + day + ", " + year); form1.setField( "firstname", StandardCode.getInstance().noNull(p.getContact().getFirst_name())); form1.setField("pm", p.getPm()); form1.setField("emailpm", u.getWorkEmail1()); if (u.getWorkPhoneEx() != null && u.getWorkPhoneEx().length() > 0) { // ext present form1.setField( "phonepm", StandardCode.getInstance().noNull(u.getWorkPhone()) + " ext " + StandardCode.getInstance().noNull(u.getWorkPhoneEx())); } else { // no ext present form1.setField("phonepm", StandardCode.getInstance().noNull(u.getWorkPhone())); } form1.setField("faxpm", StandardCode.getInstance().noNull(u.getLocation().getFax_number())); form1.setField("postalpm", StandardCode.getInstance().printLocation(u.getLocation())); // START add images // if(u.getPicture() != null && u.getPicture().length() > 0) { // PdfContentByte over; // Image img = Image.getInstance("C:/Program Files (x86)/Apache Software // Foundation/Tomcat 7.0/webapps/logo/images/" + u.getPicture()); // img.setAbsolutePosition(200, 200); // over = stamp.getOverContent(1); // over.addImage(img, 54, 0,0, 65, 47, 493); // } // END add images form1.setField("productname", StandardCode.getInstance().noNull(p.getProduct())); form1.setField("project", p.getNumber() + p.getCompany().getCompany_code()); form1.setField("description", StandardCode.getInstance().noNull(p.getProductDescription())); form1.setField("additional", p.getProjectRequirements()); // get sources and targets StringBuffer sources = new StringBuffer(""); StringBuffer targets = new StringBuffer(""); if (p.getSourceDocs() != null) { for (Iterator iterSource = p.getSourceDocs().iterator(); iterSource.hasNext(); ) { SourceDoc sd = (SourceDoc) iterSource.next(); sources.append(sd.getLanguage() + " "); if (sd.getTargetDocs() != null) { for (Iterator iterTarget = sd.getTargetDocs().iterator(); iterTarget.hasNext(); ) { TargetDoc td = (TargetDoc) iterTarget.next(); if (!td.getLanguage().equals("All")) targets.append(td.getLanguage() + " "); } } } } form1.setField("source", sources.toString()); form1.setField("target", targets.toString()); form1.setField( "start", (p.getStartDate() != null) ? DateFormat.getDateInstance(DateFormat.SHORT).format(p.getStartDate()) : ""); form1.setField( "due", (p.getDueDate() != null) ? DateFormat.getDateInstance(DateFormat.SHORT).format(p.getDueDate()) : ""); if (p.getCompany().getCcurrency().equalsIgnoreCase("USD")) { form1.setField( "cost", (p.getProjectAmount() != null) ? "$ " + StandardCode.getInstance().formatDouble(p.getProjectAmount()) : ""); } else { form1.setField( "cost", (p.getProjectAmount() != null) ? "€ " + StandardCode.getInstance() .formatDouble(p.getProjectAmount() / p.getEuroToUsdExchangeRate()) : ""); } // stamp.setFormFlattening(true); stamp.close(); // write to client (web browser) response.setHeader( "Content-disposition", "attachment; filename=" + p.getNumber() + p.getCompany().getCompany_code() + "-Order-Confirmation" + ".pdf"); OutputStream os = response.getOutputStream(); pdfStream.writeTo(os); os.flush(); } catch (Exception e) { System.err.println("PDF Exception:" + e.getMessage()); throw new RuntimeException(e); } // END process pdf // Forward control to the specified success URI return (mapping.findForward("Success")); }
/** * Process the specified HTTP request, and create the corresponding HTTP response (or forward to * another web component that will create it). Return an <code>ActionForward</code> instance * describing where and how control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @exception Exception if business logic throws an exception */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need MessageResources messages = getResources(request); // save errors ActionMessages errors = new ActionMessages(); // START check for login (security) if (!SecurityService.getInstance().checkForLogin(request.getSession(false))) { return (mapping.findForward("welcome")); } // END check for login (security) // START get id of current project from either request, attribute, or cookie // id of project from request String projectId = null; projectId = request.getParameter("projectViewId"); // check attribute in request if (projectId == null) { projectId = (String) request.getAttribute("projectViewId"); } // id of project from cookie if (projectId == null) { projectId = StandardCode.getInstance().getCookie("projectViewId", request.getCookies()); } // default project to last if not in request or cookie if (projectId == null) { List results = ProjectService.getInstance().getProjectList(); ListIterator iterScroll = null; for (iterScroll = results.listIterator(); iterScroll.hasNext(); iterScroll.next()) {} iterScroll.previous(); Project p = (Project) iterScroll.next(); projectId = String.valueOf(p.getProjectId()); } Integer id = Integer.valueOf(projectId); // END get id of current project from either request, attribute, or cookie // get project to edit Project p = ProjectService.getInstance().getSingleProject(id); // get this project's sources Set sources = p.getSourceDocs(); // for each source add each sources' Tasks List totalLinTasks = new ArrayList(); // for each source for (Iterator sourceIter = sources.iterator(); sourceIter.hasNext(); ) { SourceDoc sd = (SourceDoc) sourceIter.next(); // for each target of this source for (Iterator linTargetIter = sd.getTargetDocs().iterator(); linTargetIter.hasNext(); ) { TargetDoc td = (TargetDoc) linTargetIter.next(); // for each lin Task of this target for (Iterator linTaskIter = td.getLinTasks().iterator(); linTaskIter.hasNext(); ) { LinTask lt = (LinTask) linTaskIter.next(); if (lt.getPersonName() != null && lt.getDueDateDate() != null && (lt.getTaskName().equalsIgnoreCase("Translation") || lt.getTaskName().equalsIgnoreCase("Editing") || lt.getTaskName().trim().equalsIgnoreCase("Proofreading") || lt.getTaskName().equalsIgnoreCase("Proofreading / Linguistic QA"))) { totalLinTasks.add(lt); } System.out.println( sd.getLanguage() + "--------" + td.getLanguage() + "---------" + lt.getTaskName()); } } } // Sort by task (orderNum), then source (language), then target (language) Collections.sort(totalLinTasks, CompareTaskLin.getInstance()); Collections.sort(totalLinTasks, CompareTaskLanguages.getInstance()); // array for display in jsp LinTask[] linTasksArray = (LinTask[]) totalLinTasks.toArray(new LinTask[0]); for (int i = 0; i < totalLinTasks.size(); i++) { request.setAttribute(projectId, log); } // place all Tasks for this project into the form for display DynaValidatorForm qvg = (DynaValidatorForm) form; // HERE down is standard and does not need to change when adding task blocks // place this project into request for further display in jsp page request.setAttribute("project", p); // add this project id to cookies; this will remember the last project response.addCookie(StandardCode.getInstance().setCookie("projectViewId", projectId)); // add tab location to cookies; this will remember which tab we are at response.addCookie(StandardCode.getInstance().setCookie("projectViewTab", "Team")); // an update of totals may be required // Forward control to the specified success URI return (mapping.findForward("Success")); }
public static void generateMainPage(File mainFile, File sourceProjDir) throws IOException, ProjectFileParsingException, NeuroMLException { SimpleXMLElement root = new SimpleXMLElement("document"); SimpleXMLElement header = new SimpleXMLElement("header"); root.addChildElement(header); SimpleXMLElement title = new SimpleXMLElement("title"); header.addChildElement(title); SimpleXMLElement body = new SimpleXMLElement("body"); root.addChildElement(body); SimpleXMLElement intro = new SimpleXMLElement("p"); body.addChildElement(intro); if (!mainFile.getParentFile().exists()) mainFile.getParentFile().mkdir(); File targetDownloadDir = new File(mainFile.getParentFile(), "downloads"); if (!targetDownloadDir.exists()) targetDownloadDir.mkdir(); if (sourceProjDir.getName().indexOf("examples") >= 0) { title.addContent("neuroConstruct example projects"); intro.addContent( "Downloadable neuroConstruct example projects. These <strong>illustrate the core " + "functionality of neuroConstruct</strong>, as opposed to providing electrophysiologically accurate " + "models. Projects based on published conductance based models can be found <a href=\"../models/index.html\">here</a>"); } if (sourceProjDir.getName().indexOf("models") >= 0) { title.addContent("neuroConstruct projects based on published neuronal and network models"); intro.addContent( "Downloadable neuroConstruct projects <strong>based on published conductance based models</strong>. " + "Some examples to illustrate the core functionality of neuroConstruct, as opposed to " + "providing electrophysiologically accurate models can be found <a href=\"../samples/index.html\">here</a>." + "<p>Note: These models are currently being moved to a repository to allow open source, collaborative development of NeuroML models.</p>" + "<p>See the <a href=\"http://www.opensourcebrain.org\">Open Source Brain</a> website for full details. " + "<img alt=\"Open Source Brain\" src=\"http://www.opensourcebrain.org/images/logo.png\"/></p>"); } File[] fileArray = sourceProjDir.listFiles(); fileArray = GeneralUtils.reorderAlphabetically(fileArray, true); ArrayList<File> files = GeneralUtils.toArrayList(fileArray); // if (files.contains("")) ArrayList<String> toIgnore = new ArrayList<String>(); // toIgnore.add("Thalamocortical"); // temporarily // toIgnore.add("CA1PyramidalCell"); // temporarily // toIgnore.add("SolinasEtAl-GolgiCell"); // temporarily for (File exProjDir : files) { File morphDir = new File(exProjDir, "cellMechanisms"); if (morphDir.isDirectory() && !toIgnore.contains(exProjDir.getName())) { String projName = exProjDir.getName(); SimpleXMLElement section = new SimpleXMLElement("section"); body.addChildElement(section); SimpleXMLElement secTitle = new SimpleXMLElement("title"); section.addChildElement(secTitle); secTitle.addContent(projName); SimpleXMLElement anchor = new SimpleXMLElement("anchor"); section.addChildElement(anchor); anchor.addAttribute("id", projName); SimpleXMLElement table = new SimpleXMLElement("table"); section.addChildElement(table); SimpleXMLElement row = new SimpleXMLElement("tr"); table.addChildElement(row); String largeImg = "large.png"; String smallImg = "small.png"; File targetImageDir = new File(mainFile.getParentFile(), "images"); if (!targetImageDir.exists()) targetImageDir.mkdir(); File targetProjImageDir = new File(targetImageDir, projName); if (!targetProjImageDir.exists()) targetProjImageDir.mkdir(); File smallImgFile = new File(exProjDir, "images/" + smallImg); File largeImgFile = new File(exProjDir, "images/" + largeImg); if (smallImgFile.exists()) { GeneralUtils.copyFileIntoDir(smallImgFile, targetProjImageDir); SimpleXMLElement col2 = new SimpleXMLElement("td"); row.addChildElement(col2); col2.addAttribute("width", "120"); SimpleXMLElement secImg = new SimpleXMLElement("p"); col2.addChildElement(secImg); SimpleXMLElement img = new SimpleXMLElement("img"); img.addAttribute("src", "images/" + projName + "/small.png"); img.addAttribute("alt", "Screenshot of " + projName); if (largeImgFile.exists()) { GeneralUtils.copyFileIntoDir(largeImgFile, targetProjImageDir); SimpleXMLElement imgRef = new SimpleXMLElement("a"); img.addAttribute("title", "Click to enlarge"); imgRef.addAttribute("href", "images/" + projName + "/" + largeImg); imgRef.addChildElement(img); secImg.addChildElement(imgRef); } else { secImg.addChildElement(img); } } SimpleXMLElement secIntro = new SimpleXMLElement("p"); SimpleXMLElement colMid = new SimpleXMLElement("td"); SimpleXMLElement colRight = new SimpleXMLElement("td"); row.addChildElement(colMid); row.addChildElement(colRight); colRight.addAttribute("width", "150"); colMid.addChildElement(secIntro); secIntro.addContent("Project name: <strong>" + projName + "</strong>"); File projFile = ProjectStructure.findProjectFile(exProjDir); Project project = Project.loadProject(projFile, null); String descFull = project.getProjectDescription(); String breakpoint = "\n\n"; String descShort = new String(descFull); if (descFull.indexOf(breakpoint) > 0) { descShort = descFull.substring(0, descFull.indexOf(breakpoint)); } SimpleXMLElement desc = new SimpleXMLElement("p"); colMid.addChildElement(desc); desc.addContent(GeneralUtils.parseForHyperlinks(descShort)); SimpleXMLElement modified = new SimpleXMLElement("p"); colMid.addChildElement(modified); SimpleDateFormat formatter = new SimpleDateFormat("EEEE MMMM d, yyyy"); java.util.Date date = new java.util.Date(projFile.lastModified()); modified.addContent("Project last modified: " + formatter.format(date)); File zipFile = null; String zipFileName = targetDownloadDir.getAbsolutePath() + "/" + projName + ProjectStructure.getNewProjectZipFileExtension(); ArrayList<String> ignore = new ArrayList<String>(); ArrayList<String> ignoreNone = new ArrayList<String>(); ArrayList<String> ignoreExtns = new ArrayList<String>(); ignore.add("i686"); ignore.add("x86_64"); ignore.add(".svn"); ignore.add("simulations"); ignore.add("generatedNEURON"); ignore.add("generatedNeuroML"); ignore.add("generatedGENESIS"); ignore.add("generatedMOOSE"); ignore.add("generatedPyNN"); ignore.add("generatedPSICS"); ignore.add("dataSets"); ignoreExtns.add("bak"); zipFile = ZipUtils.zipUp(exProjDir, zipFileName, ignore, ignoreExtns); logger.logComment( "The zip file: " + zipFile.getAbsolutePath() + " (" + zipFile.length() + " bytes) contains all of the project files"); SimpleXMLElement downloads = new SimpleXMLElement("p"); colRight.addChildElement(downloads); downloads.addContent("Downloads<a href=\"#downloadInfo\">*</a>:"); SimpleXMLElement downloadProj = new SimpleXMLElement("p"); colRight.addChildElement(downloadProj); SimpleXMLElement link = new SimpleXMLElement("a"); link.addAttribute("href", "downloads/" + zipFile.getName()); link.addContent("neuroConstruct project"); link.addAttribute("title", "Download full project for loading into neuroConstruct"); downloadProj.addChildElement(link); ArrayList<String> noNeuroML = new ArrayList<String>(); noNeuroML.add("Ex3_Morphology"); noNeuroML.add("DentateGyrus"); noNeuroML.add("RothmanEtAl_KoleEtAl_PyrCell"); if (!noNeuroML.contains(projName)) { project.neuromlFileManager.generateNeuroMLFiles( null, new OriginalCompartmentalisation(), 1234, false); File neuroMLDir = ProjectStructure.getNeuroML1Dir(project.getProjectMainDirectory()); String nmlZipFileName = targetDownloadDir.getAbsolutePath() + "/" + projName + "_NeuroML.zip"; zipFile = ZipUtils.zipUp(neuroMLDir, nmlZipFileName, ignoreNone, ignoreNone); SimpleXMLElement downloadNml = new SimpleXMLElement("p"); colRight.addChildElement(downloadNml); // downloadNml.addContent("Download project as pure NeuroML: "); SimpleXMLElement img = new SimpleXMLElement("img"); img.addAttribute("src", "../images/NeuroMLSmall.png"); String info = "Download core project elements in NeuroML format"; img.addAttribute("alt", info); SimpleXMLElement imgRef = new SimpleXMLElement("a"); img.addAttribute("title", info); imgRef.addAttribute("href", "downloads/" + zipFile.getName()); imgRef.addChildElement(img); downloadNml.addChildElement(imgRef); } } } SimpleXMLElement end = new SimpleXMLElement("p"); body.addChildElement(end); end.addContent(" "); SimpleXMLElement infoDlanchor = new SimpleXMLElement("anchor"); body.addChildElement(infoDlanchor); end.addAttribute("id", "downloadInfo"); SimpleXMLElement infoDl = new SimpleXMLElement("p"); body.addChildElement(infoDl); end.addContent( "* Note: neuroConstruct project downloads (most of which are included with the standard software distribution) " + "can be loaded directly into neuroConstruct to generate cell and network scripts for NEURON, GENESIS, etc.," + " but NeuroML downloads just consist of the core elements of the project" + " (morphologies, channels, etc.) which have been exported in NeuroML format. The latter can be useful for testing NeuroML compliant applications. " + "If no NeuroML download link is present, this usually indicates that the model is mainly implemented using channel/synapse mechanisms in a simulator's " + "native language (e.g. mod files) which have not fully been converted to ChannelML yet."); SimpleXMLElement end2 = new SimpleXMLElement("p"); body.addChildElement(end2); end2.addContent(" "); FileWriter fw = null; try { fw = new FileWriter(mainFile); fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); // quick hack, todo: add to // SimpleXMLDoc... fw.write( "<!DOCTYPE document PUBLIC \"-//APACHE//DTD Documentation V2.0//EN\" \"http://forrest.apache.org/dtd/document-v20.dtd\">\n\n"); fw.write(root.getXMLString("", false)); fw.flush(); fw.close(); } catch (IOException ex) { logger.logError("Problem: ", ex); fw.close(); } /* <header> <title>Examples of neuroConstruct in use</title> </header> <body> <p>Some screenshots of neuroConstruct in action are given below. Click on the thumbnails to see a full size version of the screenshots</p> <section> <title>Examples included with distribution</title>*/ }