the PDF stuff gets done here.
authorjohn <john>
Wed, 27 Mar 2002 15:14:38 +0000 (15:14 +0000)
committerjohn <john>
Wed, 27 Mar 2002 15:14:38 +0000 (15:14 +0000)
logging needs to be unified with our logging system.
needs to let the regular content page know where to find a printable version

source/mircoders/producer/ProducerContent.java

index 195a3e7..0296d12 100755 (executable)
@@ -14,11 +14,22 @@ import mir.entity.*;
 import mircoders.entity.*;
 import mircoders.storage.*;
 
+//for pdf production
+import org.apache.fop.apps.* ;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.apache.log.*;
 
 public class ProducerContent extends Producer {
 
        private String contentTemplate=MirConfig.getProp("Producer.Content.Template");
-
+        private String contentPrintableTemplate=MirConfig.getProp("Producer.PrintableContent.Template");
+        private String html2foStyleSheetName=MirConfig.getProp("Producer.PrintableContent.html2foStyleSheetName");
+        private String generateFO=MirConfig.getProp("GenerateFO");
+        private String generatePDF=MirConfig.getProp("GeneratePDF");
+        private String producerStorageRoot=MirConfig.getProp("Producer.StorageRoot");
+        private Logger fopLog=null;
+        private String templateDir = MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir");
        public static void main(String argv[]){
                /**
                 * Why are we reloading the config here?
@@ -65,6 +76,8 @@ public class ProducerContent extends Producer {
                String              whereClause = " ";
                String              orderBy = " ";
                String              htmlFileName = null;
+               String              foFileName = null;
+               String              pdfFileName = null;
                EntityContent       currentContent;
                EntityList          batchEntityList;
                EntityUsers         userEntity=null;
@@ -112,11 +125,37 @@ public class ProducerContent extends Producer {
                                        String month = date.substring(4,6);
                                        htmlFileName =  producerDocRoot + "/" + year + "/" + month + "/" +
                                                                                                        currentContent.getValue("id") + ".shtml";
+                                       
+                                       
+                                       
 
                                        //produce html
                                        boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
                                        if ( retVal ) currentContent.setProduced(true);
-
+                                       
+                                       //produce xsl:fo and pdf version(if desired)
+                                       if (generateFO.toLowerCase().equals("yes")){
+                                       foFileName =  producerDocRoot + "/" + year + "/" + month + "/" + currentContent.getValue("id") + ".fo";
+                                       boolean foRetVal = produce(contentPrintableTemplate, foFileName, mergeData, htmlout);
+                                       
+                                       if (generatePDF.toLowerCase().equals("yes")){
+                                           pdfFileName =  producerStorageRoot + producerDocRoot +"/" + year + "/" + month + "/" + currentContent.getValue("id") + ".pdf";
+                                           Driver driver = new Driver();
+                                           
+                                           Hierarchy hierarchy = Hierarchy.getDefaultHierarchy();
+                                           fopLog = hierarchy.getLoggerFor("fop");
+                                           fopLog.setPriority(Priority.WARN);
+                                           
+                                           driver.setLogger(fopLog);
+                                           driver.setRenderer(Driver.RENDER_PDF);
+                                           File foFile=new File(producerStorageRoot + foFileName);
+                                           File html2foStyleSheet=new File(templateDir+"/"+html2foStyleSheetName);
+                                           InputHandler inputHandler = new XSLTInputHandler(foFile, html2foStyleSheet);
+                                           XMLReader parser = inputHandler.getParser();
+                                           driver.setOutputStream(new FileOutputStream(pdfFileName));
+                                           driver.render(parser, inputHandler.getInputSource());                       
+                                           }
+                                       }
                                }
                                catch(Exception e)
                                {
@@ -124,6 +163,7 @@ public class ProducerContent extends Producer {
                                                                                + currentContent.getId()+", skipping it :: "+e.toString();
                                        logHTML(htmlout, errorText);
                                        theLog.printError(errorText);
+                                       e.printStackTrace();
                                }
                                pageCount++;
                        }//for