From: zapata Date: Sun, 16 Jul 2006 03:14:10 +0000 (+0000) Subject: added better support for article urls in PDF files X-Git-Tag: LATEST_MERGED_1_1~57 X-Git-Url: http://erislabs.net/gitweb/?p=mir.git;a=commitdiff_plain;h=a875630822ea537e068f2ad31687f517437b082a added better support for article urls in PDF files --- diff --git a/build.xml b/build.xml index 0cb5cf32..e56f8d4f 100755 --- a/build.xml +++ b/build.xml @@ -248,7 +248,7 @@ - + diff --git a/doc/style/html.xsl b/doc/style/html.xsl index b2ad005e..76547f49 100755 --- a/doc/style/html.xsl +++ b/doc/style/html.xsl @@ -1,5 +1,5 @@ - + mirdoc.css 1 diff --git a/source/default.properties b/source/default.properties index 9db014a3..8093fb0c 100755 --- a/source/default.properties +++ b/source/default.properties @@ -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 diff --git a/source/mircoders/pdf/PDFGenerator.java b/source/mircoders/pdf/PDFGenerator.java index 1a158685..8405ae0b 100755 --- a/source/mircoders/pdf/PDFGenerator.java +++ b/source/mircoders/pdf/PDFGenerator.java @@ -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) { diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index d8df5dc8..6769e429 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -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");