import mir.util.StringRoutines;\r
import mircoders.entity.EntityComment;\r
import mircoders.entity.EntityContent;\r
-import mircoders.global.CacheKey;\r
+//import mircoders.global.CacheKey;\r
import mircoders.global.MirGlobal;\r
import mircoders.media.*;\r
import mircoders.media.UnsupportedMediaFormatExc;\r
* open-postings to the newswire\r
*\r
* @author mir-coders group\r
- * @version $Id: ServletModuleOpenIndy.java,v 1.75 2003/04/18 14:01:41 john Exp $\r
+ * @version $Id: ServletModuleOpenIndy.java,v 1.76 2003/04/18 14:54:54 john Exp $\r
*\r
*/\r
\r
\r
public void getpdf(HttpServletRequest req, HttpServletResponse res)\r
throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure {\r
+ long starttime=System.currentTimeMillis();\r
String ID_REQUEST_PARAM = "id";\r
int maxArticlesInNewsleter = 15; // it is nice not to be dos'ed\r
try {\r
String idParam = req.getParameter(ID_REQUEST_PARAM);\r
if (idParam != null) {\r
- ByteArrayOutputStream out = new ByteArrayOutputStream();\r
- PDFGenerator pdfMaker = new PDFGenerator(out);\r
+ \r
\r
RE re = new RE("[0-9]+");\r
-\r
-\r
+ \r
+ \r
REMatch[] idMatches=re.getAllMatches(idParam);\r
-\r
+ \r
String cacheSelector="";\r
-\r
+ \r
for (int i = 0; i < idMatches.length; i++){\r
cacheSelector= cacheSelector + "," + idMatches[i].toString();\r
}\r
-\r
\r
- if (idMatches.length > 1){\r
- pdfMaker.addLine();\r
- for (int i = 0; i < idMatches.length && i < maxArticlesInNewsleter; i++){\r
- REMatch aMatch = idMatches[i];\r
- String id=aMatch.toString();\r
- EntityContent contentEnt = (EntityContent)contentModule.getById(id);\r
- pdfMaker.addIndexItem(contentEnt);\r
-\r
- }\r
- }\r
-\r
- for (int i = 0; i < idMatches.length; i++){\r
- REMatch aMatch = idMatches[i];\r
-\r
- String id=aMatch.toString();\r
-\r
- EntityContent contentEnt = (EntityContent)contentModule.getById(id);\r
- pdfMaker.add(contentEnt);\r
-\r
- }\r
-\r
- pdfMaker.stop();\r
- res.setContentType("application/pdf");\r
- byte[] content = out.toByteArray();\r
- res.setContentLength(content.length);\r
- res.getOutputStream().write(content);\r
- res.getOutputStream().flush();\r
+ String cacheType="pdf";\r
+ \r
+ String theCacheKey = cacheType+":"+cacheSelector;\r
+ \r
+ byte[] thePDF;\r
+ \r
+ if (MirGlobal.mruCache().hasObject(theCacheKey)){\r
+ logger.warn("fetching pdf from cache");\r
+ thePDF = (byte[]) MirGlobal.mruCache().getObject(theCacheKey);\r
+ }\r
+ else {\r
+ logger.warn("generating pdf and caching it");\r
+ ByteArrayOutputStream out = new ByteArrayOutputStream();\r
+ PDFGenerator pdfMaker = new PDFGenerator(out);\r
+ \r
+ if (idMatches.length > 1){\r
+ pdfMaker.addLine();\r
+ for (int i = 0; i < idMatches.length && i < maxArticlesInNewsleter; i++){\r
+ REMatch aMatch = idMatches[i];\r
+ String id=aMatch.toString();\r
+ EntityContent contentEnt = (EntityContent)contentModule.getById(id);\r
+ pdfMaker.addIndexItem(contentEnt);\r
+ }\r
+ }\r
+ \r
+ for (int i = 0; i < idMatches.length; i++){\r
+ REMatch aMatch = idMatches[i];\r
+ String id=aMatch.toString();\r
+ EntityContent contentEnt = (EntityContent)contentModule.getById(id);\r
+ \r
+ pdfMaker.add(contentEnt);\r
+ }\r
+ \r
+ pdfMaker.stop();\r
+ thePDF = out.toByteArray();\r
+ \r
+ //and save all our hard work!\r
+ MirGlobal.mruCache().storeObject(theCacheKey,thePDF);\r
+ }\r
+ \r
+ res.setContentType("application/pdf");\r
+ res.setContentLength(thePDF.length);\r
+ res.getOutputStream().write(thePDF);\r
+ res.getOutputStream().flush();\r
+ String elapsedtime=(new Long(System.currentTimeMillis()-starttime)).toString();\r
+ logger.warn("pdf retireval took "+elapsedtime + " milliseconds" );\r
\r
}\r
else {\r