+ /*
+ * Method for dynamically generating a pdf from a fo file
+ */
+ public void getpdf(HttpServletRequest req, HttpServletResponse res)
+ throws ServletModuleException, ServletModuleUserException {
+ String ID_REQUEST_PARAM = "id";
+
+ String generateFO=MirConfig.getProp("GenerateFO");
+ String generatePDF=MirConfig.getProp("GeneratePDF");
+
+ //don't do anything if we are not making FO files, or if we are
+ //pregenerating PDF's
+ if (generateFO.equals("yes") && generatePDF.equals("no")){
+ //fop complains unless you do the logging this way
+ Logger log = null;
+ Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
+ log = hierarchy.getLoggerFor("fop");
+ log.setPriority(Priority.WARN);
+
+ String producerStorageRoot=MirConfig.getProp("Producer.StorageRoot");
+ String producerDocRoot=MirConfig.getProp("Producer.DocRoot");
+ String templateDir=MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir");
+ String xslSheet=templateDir + "/"
+ + MirConfig.getProp("Producer.PrintableContent.html2foStyleSheetName");
+ try {
+ String idParam = req.getParameter(ID_REQUEST_PARAM);
+ if (idParam != null) {
+ EntityContent contentEnt =
+ (EntityContent)contentModule.getById(idParam);
+ String publishPath = contentEnt.getValue("publish_path");
+ String foFile = producerStorageRoot + producerDocRoot + "/"
+ + publishPath + "/" + idParam + ".fo";
+ XSLTInputHandler input = new XSLTInputHandler(new File(foFile),
+ new File(xslSheet));
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ res.setContentType("application/pdf");
+
+ Driver driver = new Driver();
+ driver.setLogger(log);
+ driver.setRenderer(Driver.RENDER_PDF);
+ driver.setOutputStream(out);
+ driver.render(input.getParser(), input.getInputSource());
+
+ byte[] content = out.toByteArray();
+ res.setContentLength(content.length);
+ res.getOutputStream().write(content);
+ res.getOutputStream().flush();
+ } else {
+ throw new ServletModuleUserException("Missing id parameter.");
+ }
+ } catch (Exception ex) {
+ throw new ServletModuleException(ex.toString());
+ }
+ } else {
+ throw new ServletModuleUserException("Can't generate a PDF because the config tells me not to.");
+ }
+ }
+
+ private void _throwBadContentType (String fileName, String contentType)
+ throws ServletModuleUserException {
+
+ theLog.printDebugInfo("Wrong file type uploaded!: " + fileName+" "
+ +contentType);
+ throw new ServletModuleUserException("The file you uploaded is of the "
+ +"following mime-type: "+contentType
+ +", we do not support this mime-type. "
+ +"Error One or more files of unrecognized type. Sorry");
+ }
+
+ protected String createOneTimePasswd(){
+ Random r = new Random();
+ int random = r.nextInt();
+ long l = System.currentTimeMillis();
+ l = (l*l*l*l)/random;
+ if(l<0) l = l * -1;
+ String returnString = ""+l;
+ return returnString.substring(5);
+ }
+
+
+ /* this is an overwritten method of ServletModule in order
+ to use different bundles for open and admin */
+ public void deliver(HttpServletRequest req, HttpServletResponse res,
+ TemplateModelRoot rtm, TemplateModelRoot popups,
+ String templateFilename)
+ throws ServletModuleException {
+ if (rtm == null) rtm = new SimpleHash();
+ try {
+ PrintWriter out = res.getWriter();
+ HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out,
+ getLocale(req), "bundles.open");
+ out.close();
+ } catch (HTMLParseException e) {
+ throw new ServletModuleException(e.toString());
+ } catch (IOException e) {
+ throw new ServletModuleException(e.toString());
+ }
+ }