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;
}
- 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
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 = "";
addArticleMetaInfo(ct, theTitle, theCreator, theDate);
addArticleDescription(ct, theDescription);
addArticleContent(ct, theContent, images);
- addArticleSource(ct, theSource);
+ addArticleSource(ct, source);
}
public int getFontByName(String fontName) {
* 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();
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]+");
throw new ServletModuleExc("Illegal article");
}
- pdfMaker.add(article);
+ pdfMaker.add(article, getLocale(aRequest));
}
pdfMaker.stop();
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");