added better support for article urls in PDF files
authorzapata <zapata>
Sun, 16 Jul 2006 03:14:10 +0000 (03:14 +0000)
committerzapata <zapata>
Sun, 16 Jul 2006 03:14:10 +0000 (03:14 +0000)
build.xml
doc/style/html.xsl
source/default.properties
source/mircoders/pdf/PDFGenerator.java
source/mircoders/servlet/ServletModuleOpenIndy.java

index 0cb5cf3..e56f8d4 100755 (executable)
--- a/build.xml
+++ b/build.xml
   <target name="prepare-html">
     <mkdir dir="${build}/xslt"/>
  
-    <unzip dest="${build}/xslt" src="doc/lib/docbook-xsl-1.66.1.zip"/>
+    <unzip dest="${build}/xslt" src="doc/lib/docbook-xsl-1.70.1.zip"/>
  
     <copy todir="${build}/xslt">
       <fileset dir="doc/style">
index b2ad005..76547f4 100755 (executable)
@@ -1,5 +1,5 @@
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
-    <xsl:import href="docbook-xsl-1.66.1/html/docbook.xsl"/>
+    <xsl:import href="docbook-xsl-1.70.1/html/docbook.xsl"/>
     <xsl:param name="html.stylesheet">mirdoc.css</xsl:param>
     <xsl:param name="navig.showtitles">1</xsl:param>
     <xsl:param name="section.autolabel" select="1"/>
index 9db014a..8093fb0 100755 (executable)
@@ -290,8 +290,10 @@ PDF.Title.FontSize=24
 PDF.Title.LineHeight=28
 PDF.Title.FontFamily=courier
 
-# footer is about two lines of small text which will appear at the bottom of every page
+# Source will be expanded to come to a URL to the article
+PDF.Source=${config["Producer.PublicationHost"]}${config['Mir.Login.DefaultLanguage']}/${article.date.formatted['yyyy/MM']}/${article.id}.shtml
 
+# footer is about two lines of small text which will appear at the bottom of every page
 PDF.Footer.String=Indymedia does blah.  Content is good, and free to use for non-commercial purposes under the Open Content license. if you have questions, email someone.
 PDF.Footer.Height=54
 PDF.Footer.FontSize=12
index 1a15868..8405ae0 100755 (executable)
@@ -37,19 +37,23 @@ import gnu.regexp.REMatchEnumeration;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
 
 import mir.config.MirPropertiesConfiguration;
 import mir.entity.EntityBrowser;
+import mir.entity.adapter.EntityAdapter;
 import mir.log.LoggerWrapper;
 import mir.misc.StringUtil;
 import mir.util.DateTimeRoutines;
 import mir.util.HTMLRoutines;
+import mir.util.ParameterExpander;
+import mir.generator.GeneratorHelper;
+import mir.generator.GeneratorExc;
 import mircoders.entity.EntityContent;
 import mircoders.entity.EntityImages;
 import mircoders.storage.DatabaseImages;
+import mircoders.global.MirGlobal;
+import mircoders.localizer.MirLocalizerExc;
 
 import com.lowagie.text.BadElementException;
 import com.lowagie.text.Document;
@@ -614,8 +618,8 @@ public class PDFGenerator {
   }
 
 
-  public void add(EntityContent entityContent) {
-    logger.error("adding a content Entity");
+  public void add(EntityContent anArticle, Locale aLocale) throws GeneratorExc, MirLocalizerExc, Exception {
+    logger.debug("adding a content Entity");
 
     /*
      * initialize
@@ -633,23 +637,33 @@ public class PDFGenerator {
     extraTables.add("content_x_media cxm");
     Iterator images = new EntityBrowser(
         DatabaseImages.getInstance(), "i", extraTables,
-        "cxm.content_id=" + entityContent.getId() + "and cxm.media_id=i.id",
+        "cxm.content_id=" + anArticle.getId() + "and cxm.media_id=i.id",
         "i.id desc", 30, -1, 0);
 
-    String isHTML = entityContent.getFieldValue("is_html");
-    String theTitle = entityContent.getFieldValue("title");
-    String theCreator = entityContent.getFieldValue("creator");
+    String isHTML = anArticle.getFieldValue("is_html");
+    String theTitle = anArticle.getFieldValue("title");
+    String theCreator = anArticle.getFieldValue("creator");
     String theDate = DateTimeRoutines.advancedDateFormat(
         configuration.getString("RDF.Meta.DateFormat"),
-        StringUtil.convertMirInternalDateToDate(entityContent.getFieldValue("webdb_create")),
+        StringUtil.convertMirInternalDateToDate(anArticle.getFieldValue("webdb_create")),
         configuration.getString("Mir.DefaultTimezone"));
 
 
-    String theDescriptionRaw = entityContent.getFieldValue("description");
-    String theContentRaw = entityContent.getFieldValue("content_data");
-    String theSource = configuration.getString("Producer.PublicationHost") + "/" + configuration.getString("StandardLanguage") + entityContent.getFieldValue("publish_path") + entityContent.getFieldValue("id") + ".shtml";
+    String theDescriptionRaw = anArticle.getFieldValue("description");
+    String theContentRaw = anArticle.getFieldValue("content_data");
 
+    MirPropertiesConfiguration configuration = MirPropertiesConfiguration.instance();
+    Map variables = GeneratorHelper.makeBasicGenerationData(new Locale[] {
+            aLocale ,new Locale(configuration.getString("Mir.Admin.FallbackLanguage", "en"), "")},
+            "bundles.open","bundles.open");
 
+    EntityAdapter article =
+            MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter("content", anArticle);
+    variables.put("article", article);
+    String source = ParameterExpander.expandExpression(
+            variables,
+            configuration.getString("PDF.Source")
+    );
     String theContent = "";
     String theDescription = "";
 
@@ -763,7 +777,7 @@ public class PDFGenerator {
     addArticleMetaInfo(ct, theTitle, theCreator, theDate);
     addArticleDescription(ct, theDescription);
     addArticleContent(ct, theContent, images);
-    addArticleSource(ct, theSource);
+    addArticleSource(ct, source);
   }
 
   public int getFontByName(String fontName) {
index d8df5dc..6769e42 100755 (executable)
@@ -652,7 +652,7 @@ public class ServletModuleOpenIndy extends ServletModule {
    * Method for dynamically generating a pdf using iText
    */
 
-  public void getpdf(HttpServletRequest req, HttpServletResponse res)
+  public void getpdf(HttpServletRequest aRequest, HttpServletResponse aResponse)
       throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure {
 
     long starttime = System.currentTimeMillis();
@@ -660,7 +660,7 @@ public class ServletModuleOpenIndy extends ServletModule {
     String ID_REQUEST_PARAM = "id";
     int maxArticlesInNewsleter = 15; // it is nice not to be dos'ed
     try {
-      String idParam = req.getParameter(ID_REQUEST_PARAM);
+      String idParam = aRequest.getParameter(ID_REQUEST_PARAM);
       if (idParam != null) {
         RE re = new RE("[0-9]+");
 
@@ -707,7 +707,7 @@ public class ServletModuleOpenIndy extends ServletModule {
               throw new ServletModuleExc("Illegal article");
             }
 
-            pdfMaker.add(article);
+            pdfMaker.add(article, getLocale(aRequest));
           }
 
           pdfMaker.stop();
@@ -717,10 +717,10 @@ public class ServletModuleOpenIndy extends ServletModule {
           MirGlobal.mruCache().storeObject(theCacheKey, thePDF);
         }
 
-        res.setContentType("application/pdf");
-        res.setContentLength(thePDF.length);
-        res.getOutputStream().write(thePDF);
-        res.getOutputStream().flush();
+        aResponse.setContentType("application/pdf");
+        aResponse.setContentLength(thePDF.length);
+        aResponse.getOutputStream().write(thePDF);
+        aResponse.getOutputStream().flush();
         String elapsedtime = (new Long(System.currentTimeMillis() - starttime)).toString();
         getLogger().info("pdf retireval took " + elapsedtime + " milliseconds");