* open-postings to the newswire
*
* @author mir-coders group
- * @version $Id: ServletModuleOpenIndy.java,v 1.85 2003/05/04 11:42:07 john Exp $
+ * @version $Id: ServletModuleOpenIndy.java,v 1.86 2003/05/04 12:56:33 john Exp $
*
*/
private String commentFormTemplate, commentFormDoneTemplate, commentFormDupeTemplate;
private String postingFormTemplate, postingFormDoneTemplate, postingFormDupeTemplate;
private String searchResultsTemplate;
- private String prepareMailTemplate,sentMailTemplate;
+ private String prepareMailTemplate,sentMailTemplate,emailAnArticleTemplate;
private ModuleContent contentModule;
private ModuleComment commentModule;
private ModuleImages imageModule;
searchResultsTemplate = configuration.getString("ServletModule.OpenIndy.SearchResultsTemplate");
prepareMailTemplate = configuration.getString("ServletModule.OpenIndy.PrepareMailTemplate");
+ emailAnArticleTemplate = configuration.getString("ServletModule.OpenIndy.MailableArticleTemplate");
sentMailTemplate = configuration.getString("ServletModule.OpenIndy.SentMailTemplate");
directOp = configuration.getString("DirectOpenposting").toLowerCase();
commentModule = new ModuleComment(DatabaseComment.getInstance());
if (from.indexOf('\n') != -1 || from.indexOf('\r') != -1 || from.indexOf(',') != -1 ) {
throw new ServletModuleUserExc("email.error.invalidfromaddress", new String[] {from});
}
-
-
- EntityContent contentEnt;
- try{
- contentEnt = (EntityContent)contentModule.getById(aid);
+
+ CacheKey theCacheKey=new CacheKey("email",aid+mail_language);
+ String theEmailText;
+
+ if (MirGlobal.mruCache().hasObject(theCacheKey)){
+ logger.info("fetching email text for article "+aid+" from cache");
+ theEmailText = (String) MirGlobal.mruCache().getObject(theCacheKey);
}
- catch (Throwable e){
- throw new ServletModuleFailure("Couldn't get content for article "+aid + ": " + e.getMessage(), e);
+ else {
+ EntityContent contentEnt;
+ try{
+ contentEnt = (EntityContent)contentModule.getById(aid);
+ StringWriter theEMailTextWriter=new StringWriter();
+ PrintWriter dest = new PrintWriter(theEMailTextWriter);
+ Map articleData = new HashMap();
+ articleData.put("article",mir.generator.FreemarkerGenerator.makeAdapter(contentEnt));
+ articleData.put("languagecode",mail_language);
+ deliver(dest,req, res, articleData, null, emailAnArticleTemplate,mail_language);
+ theEmailText=theEMailTextWriter.toString();
+ MirGlobal.mruCache().storeObject(theCacheKey,theEmailText);
+ }
+ catch (Throwable e){
+ throw new ServletModuleFailure("Couldn't get content for article "+aid + mail_language + ": " + e.getMessage(), e);
+ }
}
+
+ String content = theEmailText;
-
-
- String producerStorageRoot=configuration.getString("Producer.StorageRoot");
- String producerDocRoot=configuration.getString("Producer.DocRoot");
- String publishPath = contentEnt.getValue("publish_path");
- String txtFilePath = producerStorageRoot + producerDocRoot + "/" + mail_language +
- publishPath + "/" + aid + ".txt";
-
-
- File inputFile = new File(txtFilePath);
- String content;
-
- try{
- FileReader in = new FileReader(inputFile);
- StringWriter out = new StringWriter();
- int c;
- while ((c = in.read()) != -1)
- out.write(c);
- in.close();
- content= out.toString();
- }
- catch (FileNotFoundException e){
- throw new ServletModuleFailure("No text file found in " + txtFilePath, e);
- }
- catch (IOException e){
- throw new ServletModuleFailure("Problem reading file in " + txtFilePath, e);
- }
// add some headers
content = "To: " + to + "\nReply-To: "+ from + "\n" + content;
// put in the comment where it should go
}
}
+ public void deliver(PrintWriter anOutputWriter, HttpServletRequest aRequest, HttpServletResponse aResponse, Map aData, Map anExtra, String aGenerator,String aLocaleString)
+ throws ServletModuleFailure {
+ try {
+ Map responseData = ServletHelper.makeGenerationData(new Locale[] { new Locale(aLocaleString,""), getFallbackLocale(aRequest)}, "bundles.open");
+ responseData.put("data", aData);
+ responseData.put("extra", anExtra);
+
+
+ Generator generator = MirGlobal.localizer().generators().makeOpenPostingGeneratorLibrary().makeGenerator(aGenerator);
+ generator.generate(anOutputWriter, responseData, logger);
+
+ anOutputWriter.close();
+ }
+ catch (Throwable e) {
+ logger.error("Error while generating " + aGenerator + ": " + e.getMessage());
+
+ throw new ServletModuleFailure(e);
+ }
+ }
+
+
public void handleError(HttpServletRequest aRequest, HttpServletResponse aResponse,PrintWriter out, Throwable anException) {
try {
logger.error("error: " + anException);