the new pdf generator support.
authorjohn <john>
Mon, 14 Apr 2003 19:19:16 +0000 (19:19 +0000)
committerjohn <john>
Mon, 14 Apr 2003 19:19:16 +0000 (19:19 +0000)
still lacks:
-ability to turn off via the config
-the MRU caching thing

source/mircoders/servlet/ServletModuleOpenIndy.java

index db23bc0..dac1b8e 100755 (executable)
@@ -57,10 +57,16 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpSession;
 
+import gnu.regexp.RE;
+import gnu.regexp.REMatch;
+import gnu.regexp.REMatchEnumeration;
+import gnu.regexp.REException;
+
+
 import org.apache.commons.net.smtp.SMTPClient;
 import org.apache.commons.net.smtp.SMTPReply;
-import org.apache.fop.apps.Driver;
-import org.apache.fop.apps.XSLTInputHandler;
+//import org.apache.fop.apps.Driver;
+//import org.apache.fop.apps.XSLTInputHandler;
 import org.apache.log.Hierarchy;
 import org.apache.log.Priority;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -95,6 +101,7 @@ import mircoders.module.ModuleComment;
 import mircoders.module.ModuleContent;
 import mircoders.module.ModuleImages;
 import mircoders.module.ModuleTopics;
+import mircoders.pdf.PDFGenerator;
 import mircoders.search.AudioSearchTerm;
 import mircoders.search.ContentSearchTerm;
 import mircoders.search.ImagesSearchTerm;
@@ -118,7 +125,7 @@ import mircoders.storage.DatabaseTopics;
  *    open-postings to the newswire
  *
  * @author mir-coders group
- * @version $Id: ServletModuleOpenIndy.java,v 1.72 2003/04/10 03:31:47 zapata Exp $
+ * @version $Id: ServletModuleOpenIndy.java,v 1.73 2003/04/14 19:19:16 john Exp $
  *
  */
 
@@ -930,8 +937,71 @@ public class ServletModuleOpenIndy extends ServletModule
   }
 
   /*
+   * Method for dynamically generating a pdf using iText
+   */
+
+
+  public void getpdf(HttpServletRequest req, HttpServletResponse res)
+      throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure {
+    String ID_REQUEST_PARAM = "id";
+    try {
+        String idParam = req.getParameter(ID_REQUEST_PARAM);
+        if (idParam != null) {
+         ByteArrayOutputStream out = new ByteArrayOutputStream();
+          PDFGenerator pdfMaker = new PDFGenerator(out);
+         
+         RE re = new RE("[0-9]+");
+         
+         
+         REMatch[] idMatches=re.getAllMatches(idParam);
+         
+         if (idMatches.length > 1){
+           pdfMaker.addLine();
+           for (int i = 0; i < idMatches.length; i++){
+             REMatch aMatch = idMatches[i];
+             String id=aMatch.toString();
+             EntityContent contentEnt = (EntityContent)contentModule.getById(id);
+             pdfMaker.addIndexItem(contentEnt);
+             
+           }
+         }
+
+         for (int i = 0; i < idMatches.length; i++){
+           REMatch aMatch = idMatches[i];
+           
+           String id=aMatch.toString();
+           
+           EntityContent contentEnt = (EntityContent)contentModule.getById(id);
+           pdfMaker.add(contentEnt);
+           
+         }
+         
+         pdfMaker.stop();
+         res.setContentType("application/pdf");
+         byte[] content = out.toByteArray();
+          res.setContentLength(content.length);
+         res.getOutputStream().write(content);
+          res.getOutputStream().flush();
+
+       }
+       else {
+          throw new ServletModuleExc("Missing id.");
+        }
+    }
+    catch (Throwable t) {
+      logger.error(t.toString());
+      throw new ServletModuleFailure(t);
+    }
+
+  }
+
+
+  /*
    * Method for dynamically generating a pdf from a fo file
+   * (deprecated until fop gets its act together regarding floats)
    */
+
+  /*
   public void getpdf(HttpServletRequest req, HttpServletResponse res)
       throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure {
     String ID_REQUEST_PARAM = "id";
@@ -1001,7 +1071,7 @@ public class ServletModuleOpenIndy extends ServletModule
       throw new ServletModuleExc("Can't generate a PDF because the config tells me not to.");
     }
   }
-
+  */
   protected String createOneTimePasswd(){
     Random r = new Random();
     int random = r.nextInt();
@@ -1055,6 +1125,7 @@ public class ServletModuleOpenIndy extends ServletModule
   public void handleError(HttpServletRequest aRequest, HttpServletResponse aResponse,PrintWriter out, Throwable anException) {
     try {
       logger.error("error: " + anException);
+      anException.printStackTrace();
       Map data = new HashMap();
 
       data.put("errorstring", anException.getMessage());