+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with the com.oreilly.servlet library, any library
+ * licensed under the Apache Software License, The Sun (tm) Java Advanced
+ * Imaging library (JAI), The Sun JIMI library (or with modified versions of
+ * the above that use the same license as the above), and distribute linked
+ * combinations including the two. You must obey the GNU General Public
+ * License in all respects for all of the code used other than the above
+ * mentioned libraries. If you modify this file, you may extend this exception
+ * to your version of the file, but you are not obligated to do so. If you do
+ * not wish to do so, delete this exception statement from your version.
+ */
+
package mircoders.producer;
import java.io.*;
import java.lang.*;
import java.util.*;
-
import freemarker.template.*;
-import com.icl.saxon.trax.Transformer;
-
import mir.misc.*;
import mir.storage.*;
import mir.module.*;
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[]){
-
- Configuration.initConfig("config");
-
- System.out.println(Configuration.getProperty("Producer.DocRoot"));
+ //Configuration.initConfig("config");
+ System.out.println(MirConfig.getProp("Producer.DocRoot"));
try {
-
- new ProducerContent().handle(new PrintWriter(System.out), null, false,false);
-
- } catch(Exception e) { System.err.println(e.toString()); }
-
+ new ProducerContent().handle(new PrintWriter(System.out), null,
+ false,false);
+ } catch(Exception e) {
+ System.err.println(e.toString());
+ }
}
-
-
- public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
-
+ public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
+ boolean sync)
throws StorageObjectException, ModuleException {
handle(htmlout,user,force,sync,null);
-
}
-
-
-
-
- public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
-
- throws StorageObjectException, ModuleException
-
+ public void handle(PrintWriter htmlout, EntityUsers user, boolean force,
+ boolean sync, String id) throws StorageObjectException,
+ ModuleException
{
+ long startTime = System.currentTimeMillis();
+ int pageCount=0;
-
- String contentTemplate = Configuration.getProperty("Producer.Content.Template");
-
- int contentBatchsize = Integer.parseInt(Configuration.getProperty("Producer.Content.Batchsize"));
-
- String extLinkName = Configuration.getProperty("Producer.ExtLinkName");
-
- String intLinkName = Configuration.getProperty("Producer.IntLinkName");
-
- String mailLinkName = Configuration.getProperty("Producer.MailLinkName");
-
- String imageRoot = Configuration.getProperty("Producer.ImageRoot");
-
- long sessionConnectTime = 0;
- long startTime = (new java.util.Date()).getTime();
String whereClause = " ";
String orderBy = " ";
String htmlFileName = null;
- String currentMediaId;
+ String foFileName = null;
+ String pdfFileName = null;
EntityContent currentContent;
EntityList batchEntityList;
+ EntityUsers userEntity=null;
- HashMap currentContentValues;
-
- SimpleHash imageHash = new SimpleHash();
-
- EntityGruppen userEntity=null;
-
-
-
+ int contentBatchsize =
+ Integer.parseInt(MirConfig.getProp("Producer.Content.Batchsize"));
// production of the content-pages
- orderBy="date desc, webdb_lastchange desc";
-
+ /** @todo this should be moved to ModuleContent */
+ orderBy="webdb_lastchange desc";
if(force==true){
-
whereClause="is_published='1'";
-
-
-
// if true: produces a single content item
-
if(id !=null){
-
whereClause += " AND id="+id;
-
+ // I think this avoids a select count(*)...
+ contentBatchsize=-1;
}
-
- batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
-
+ batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
+ contentBatchsize, userEntity);
} else {
-
whereClause="is_produced='0' AND is_published='1'";
-
-
-
//if true produces a single contentitem
-
if(id !=null){
-
whereClause += " AND id="+id;
-
+ // this avoids a select count(*)...
+ contentBatchsize=-1;
}
-
- batchEntityList = contentModule.getContent(whereClause, orderBy, 0, contentBatchsize, userEntity);
-
+ batchEntityList = contentModule.getContent(whereClause, orderBy, 0,
+ contentBatchsize, userEntity);
}
-
-
- while (batchEntityList != null) {
-
+ while (batchEntityList!=null) {
for(int i=0;i<batchEntityList.size();i++) {
-
currentContent = (EntityContent)batchEntityList.elementAt(i);
- currentContentValues = currentContent.getValues();
-
- //currentContentValues.put("content_data",currentContent.getContentData());
-
-
-
-
-
- String date = (String)currentContentValues.get("date");
-
- String year = date.substring(0,4);
-
- String month = date.substring(4,6);
-
-
-
- htmlFileName = producerDocRoot
-
- + "/" + year + "/" + month + "/" + currentContentValues.get("id") + ".shtml";
-
-
-
- currentContentValues.put("content_data",StringUtil.deleteForbiddenTags((String)currentContentValues.get("content_data")));
-
- currentContentValues.put("description",StringUtil.deleteForbiddenTags((String)currentContentValues.get("description")));
-
-
-
- if (currentContentValues.get("is_html").equals("0")) {
-
- String temp = (String)currentContentValues.get("content_data");
-
- theLog.printDebugInfo("länge:"+temp.length());
-
- if(temp!=null && temp.length()>0){
-
- temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
-
- temp = StringUtil.decodeHTMLinTags(temp);
-
- currentContentValues.put("content_data",temp);
-
- }
-
- temp = (String)currentContentValues.get("description");
-
- if(temp!=null && temp.length()>0){
-
- temp = StringUtil.createHTML(temp,imageRoot,mailLinkName,extLinkName,intLinkName);
-
- temp = StringUtil.decodeHTMLinTags(temp);
-
- currentContentValues.put("description",temp);
-
- }
-
- } else {
-
- String temp = (String)currentContentValues.get("content_data");
-
- if(temp!=null && temp.length()>0){
-
- temp = StringUtil.decodeHTMLinTags(temp);
-
- currentContentValues.put("content_data",temp);
-
- }
-
- temp = (String)currentContentValues.get("description");
-
- if(temp!=null && temp.length()>0){
-
- temp = StringUtil.decodeHTMLinTags(temp);
-
- currentContentValues.put("description",temp);
-
- }
-
- }
-
-
-
- SimpleHash mergeData = HTMLTemplateProcessor.makeSimpleHash(currentContentValues);
-
-
-
- // get the images
-
- currentMediaId = currentContent.getValue("to_media");
-
- if (currentMediaId!=null && !currentMediaId.equals("")) {
-
- imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
-
+ try {
+
+ SimpleHash mergeData=new SimpleHash();
+ mergeData.put("content", currentContent);
+
+ /** @todo this should be assembled in entity */
+ String date = currentContent.getValue("date");
+ String year = date.substring(0,4);
+ String month = date.substring(4,6);
+ 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 = "/" + year + "/" + month + "/"
+ + currentContent.getValue("id") + ".fo";
+ boolean foRetVal = produce(contentPrintableTemplate, foFileName,
+ mergeData, htmlout, "UTF8");
+
+ 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) {
+ String errorText = "Producer.Content <font color=red>ERROR</font> while producing content ID:"
+ + currentContent.getId()+", skipping it :: "+e.toString();
+ logHTML(htmlout, errorText);
+ theLog.printError(errorText);
+ e.printStackTrace();
}
-
- mergeData.put("images", imageHash);
-
-
-
- // get the comments for the article
-
- mergeData.put("comments", currentContent.getComments());
-
-
-
- // get the topics of this article
- mergeData.put("topics",HTMLTemplateProcessor.makeSimpleList(DatabaseContentToTopics.getInstance().getTopics(currentContent)));
-
- boolean retVal = produce(contentTemplate, htmlFileName, mergeData, htmlout);
- sessionConnectTime = new java.util.Date().getTime() - startTime;
- if (retVal == true && !"1".equals(currentContent.getValue("is_produced")))
- currentContent.setProduced(true);
- }
-
+ pageCount++;
+ }//for
+ // if next batch get it...
if (batchEntityList.hasNextBatch()){
-
- batchEntityList = contentModule.getContent(whereClause, orderBy, batchEntityList.getNextBatch(),contentBatchsize, userEntity);
-
- //theLog.printDebugInfo("producing next batch");
-
+ batchEntityList = contentModule.getContent(whereClause, orderBy,
+ batchEntityList.getNextBatch(),
+ contentBatchsize, userEntity);
} else {
-
batchEntityList=null;
-
}
-
}
-
- // Finish
-
- sessionConnectTime = new java.util.Date().getTime() - startTime;
-
- logHTML(htmlout, "Producer.Content finished: " + sessionConnectTime + " ms.");
-
-
-
+ logHTMLFinish(htmlout, "Content", pageCount, startTime, System.currentTimeMillis());
+ /** @todo why no syncing here? */
}
+}
-
-
-}
\ No newline at end of file