minor cleanup
[mir.git] / source / mircoders / producer / ProducerContent.java
index 0296d12..a4e14a5 100755 (executable)
@@ -23,28 +23,15 @@ 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");
+       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?
-                * Can someone please explain this?
-                * Hope I didn't break anything
-                * -mh. <heckmann@hbe.ca>
-                *
-                * This is the entry point for standalone production. The code
-                * is then running in a new virtual machine, e.g. when called
-                * from cron-script. In that case the config has to be initliased.
-                * Don't know if is ok that way //rk
-                *
-                * ok, i figured that out a few months ago.. -mh
-                *
-                */
                //Configuration.initConfig("config");
                System.out.println(MirConfig.getProp("Producer.DocRoot"));
 
@@ -56,8 +43,6 @@ public class ProducerContent extends Producer {
                }
        }
 
-
-
        public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
                                                                                boolean sync)
                throws StorageObjectException, ModuleException {
@@ -123,42 +108,43 @@ public class ProducerContent extends Producer {
                                        String date = currentContent.getValue("date");
                                        String year = date.substring(0,4);
                                        String month = date.substring(4,6);
-                                       htmlFileName =  producerDocRoot + "/" + year + "/" + month + "/" +
+                                       htmlFileName =  "/" + 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);
+            foFileName =  "/" + year + "/" + month + "/"
+                          + currentContent.getValue("id") + ".fo";
+            boolean foRetVal = produce(contentPrintableTemplate, foFileName,
+                                        mergeData, htmlout, "UTF8");
                                        
-                                       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());                       
-                                           }
+            if (generatePDF.toLowerCase().equals("yes")){
+              pdfFileName =  producerStorageRoot + "/" + 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)
-                               {
+                               } catch(Exception e) {
                                        String errorText = "Producer.Content <font color=red>ERROR</font> while producing content ID:"
                                                                                + currentContent.getId()+", skipping it :: "+e.toString();
                                        logHTML(htmlout, errorText);
@@ -169,25 +155,15 @@ public class ProducerContent extends Producer {
                        }//for
                        // if next batch get it...
                        if (batchEntityList.hasNextBatch()){
-                               //batchEntityList = contentModule.getByWhereClause(whereClause,
-                               //                                                                                                              null, batchEntityList.getNextBatch(),
-                               //                                                                                                              contentBatchsize);
-               batchEntityList = contentModule.getContent(whereClause, orderBy,
-                                                batchEntityList.getNextBatch(),
-                                                contentBatchsize, userEntity);
+                               batchEntityList = contentModule.getContent(whereClause, orderBy,
+                                                                                                                                                               batchEntityList.getNextBatch(),
+                                                                                                                                                               contentBatchsize, userEntity);
                        } else {
                                batchEntityList=null;
                        }
-
                }
-
-
-
                logHTMLFinish(htmlout, "Content", pageCount, startTime, System.currentTimeMillis());
-
                /** @todo why no syncing here? */
-
        }
-
 }