- String language = req.getParameter("language");
- String generateFO=configuration.getString("GenerateFO");
- String generatePDF=configuration.getString("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
- org.apache.log.Logger log = null;
- Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
- log = hierarchy.getLoggerFor("fop");
- log.setPriority(Priority.WARN);
-
- String producerStorageRoot=configuration.getString("Producer.StorageRoot");
- String producerDocRoot=configuration.getString("Producer.DocRoot");
- // String templateDir=MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir");
- String xslSheet=configuration.getString("Producer.HTML2FOStyleSheet");
- try {
- String idParam = req.getParameter(ID_REQUEST_PARAM);
- if (idParam != null) {
- EntityContent contentEnt =
- (EntityContent)contentModule.getById(idParam);
- String publishPath = StringUtil.webdbDate2path(contentEnt.getValue("date"));
- String foFile;
-
- if (language == null){
- foFile = producerStorageRoot + producerDocRoot + "/"
- + publishPath + idParam + ".fo";
- }
- else{
- foFile = producerStorageRoot + producerDocRoot + "/"
- + language + publishPath + idParam + ".fo";
- }
- logger.debug("USING FILES" + foFile + " and " + xslSheet);
- 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 ServletModuleExc("Missing id.");
- }
+ int maxArticlesInNewsleter = 15; // it is nice not to be dos'ed
+ try {
+ String idParam = req.getParameter(ID_REQUEST_PARAM);
+ if (idParam != null) {
+
+
+ RE re = new RE("[0-9]+");
+
+
+ REMatch[] idMatches=re.getAllMatches(idParam);
+
+ String cacheSelector="";
+
+ for (int i = 0; i < idMatches.length; i++){
+ cacheSelector= cacheSelector + "," + idMatches[i].toString();
+ }
+
+ String cacheType="pdf";
+
+ CacheKey theCacheKey = new CacheKey(cacheType,cacheSelector);
+
+ byte[] thePDF;
+
+ if (MirGlobal.mruCache().hasObject(theCacheKey)){
+ logger.info("fetching pdf from cache");
+ thePDF = (byte[]) MirGlobal.mruCache().getObject(theCacheKey);
+ }
+ else {
+ logger.info("generating pdf and caching it");
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PDFGenerator pdfMaker = new PDFGenerator(out);
+
+ if (idMatches.length > 1){
+ pdfMaker.addLine();
+ for (int i = 0; i < idMatches.length && i < maxArticlesInNewsleter; i++){
+ REMatch aMatch = idMatches[i];
+ String id=aMatch.toString();
+ EntityContent contentEnt = (EntityContent)contentModule.getById(id);
+ pdfMaker.addIndexItem(contentEnt);