From 173478835cfb302ea95fd259a41479288b6e0959 Mon Sep 17 00:00:00 2001 From: zapata Date: Sat, 14 Dec 2002 15:54:58 +0000 Subject: [PATCH] support added for local additions to admin.properties --- bundles/admin_de.properties | 12 +- bundles/admin_en.properties | 16 +- bundles/admin_es.properties | 20 +- etc/bundles/adminlocal.properties | 3 + source/mir/misc/HTMLTemplateProcessor.java | 822 +++++++++++---------- source/mir/misc/MessageMethodModel.java | 260 +++---- source/mir/servlet/ServletModule.java | 4 +- .../mir/util/ResourceBundleGeneratorFunction.java | 24 +- source/mircoders/servlet/ServletHelper.java | 7 +- .../mircoders/servlet/ServletModuleProducer.java | 5 +- templates/admin/comment.template | 2 +- templates/admin/commentlist.template | 40 +- templates/admin/content.template | 2 +- templates/admin/contentlist.template | 2 +- templates/admin/start_admin.template | 2 +- 15 files changed, 660 insertions(+), 561 deletions(-) create mode 100755 etc/bundles/adminlocal.properties diff --git a/bundles/admin_de.properties b/bundles/admin_de.properties index cb0e71ea..d8ab36f1 100755 --- a/bundles/admin_de.properties +++ b/bundles/admin_de.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: deutsch / german -# $Id: admin_de.properties,v 1.20 2002/12/13 21:00:03 zapata Exp $ +# $Id: admin_de.properties,v 1.21 2002/12/14 15:55:23 zapata Exp $ # general yes=ja @@ -238,6 +238,7 @@ start.content.with_comments=mit internen kommentaren start.content.all=alle start.content.search=Suche +start.allarticlesoftype=alle Artikel vom Typ {0} start.generate.title=MANUELL GENERIEREN start.generate.all.title=Alle Bereiche @@ -320,6 +321,15 @@ head.logged_in=logged in foot.top=top +# article types +articletypes.openposting=Open posting +articletypes.newswire=Newswire +articletypes.feature=Feature +articletypes.topicspecial=Themen special +articletypes.startspecial=Startpage special + + + ########## error ########## error.htmltitle=das system ist der fehler diff --git a/bundles/admin_en.properties b/bundles/admin_en.properties index 4f1fd477..ecf1b36d 100755 --- a/bundles/admin_en.properties +++ b/bundles/admin_en.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: english -# $Id: admin_en.properties,v 1.28 2002/12/13 21:00:03 zapata Exp $ +# $Id: admin_en.properties,v 1.29 2002/12/14 15:55:23 zapata Exp $ # general yes=yes @@ -232,10 +232,6 @@ start.content.title=ARTICLES start.content.new=new article start.show=show -start.content.newswire=newswire -start.content.feature=feature -start.content.topicspecial=topic-specials -start.content.startspecial=startpage-specials start.content.hidden=hidden articles start.content.not_published=not (yet) published articles start.content.with_media=with media @@ -244,6 +240,8 @@ start.content.with_comments=with internal comments start.content.all=all articles start.content.search=search +start.allarticlesoftype=View all "{0}" articles + start.producers.title=GENERATE MANUALLY start.producers.produceAllNew=Generate all new @@ -345,7 +343,15 @@ head.logged_in=logged in foot.top=top +# Article types +articletypes.openposting=Open posting +articletypes.newswire=Newswire +articletypes.feature=Feature +articletypes.topicspecial=Topic-special +articletypes.startspecial=Startpage-special +# Comment status values +commentstatus.normal=Normal ########## error ########## diff --git a/bundles/admin_es.properties b/bundles/admin_es.properties index 6feb7364..4176ace9 100755 --- a/bundles/admin_es.properties +++ b/bundles/admin_es.properties @@ -1,6 +1,6 @@ ########## admin ########## # language: espanol / spanish -# $Id: admin_es.properties,v 1.12 2002/12/13 21:00:03 zapata Exp $ +# $Id: admin_es.properties,v 1.13 2002/12/14 15:55:23 zapata Exp $ # general yes=sí @@ -179,6 +179,8 @@ login.language.qu=Quechua login.language.tr=Turkish login.submit= Envíar + + # mediafolder mediafolder.htmltitle=carpeta de recursos mediáticos mediafolder.date=fecha @@ -220,10 +222,7 @@ start.breaking.new= start.content.title=ARTICULOS start.content.new=nuevos artículos start.show=mostrar -start.content.newswire=newswire -start.content.feature=presentación -start.content.topicspecial=especiales-por-tema -start.content.startspecial=especiales-página-de-inicio + start.content.not_published=artículos aun sin publicar start.content.with_media=con recursos mediáticos start.content.last_changes=últimos cambios @@ -253,7 +252,9 @@ start.content.hidden=hidden articles # needs to b start.editfiles.title=EDIT FILES # needs to be translated start.editfiles.include=Include files # needs to be translated -start.superusermenu=Superuser menu (use with care!) # needs translation +start.superusermenu=Superuser menu (use with care!) # needs translation + +start.allarticlesoftype=Todos articulos con type {0} @@ -337,6 +338,13 @@ head.logged_in=est foot.top=arriba +# article types +articletypes.openposting=Envio abierto +articletypes.newswire=Newswire +articletypes.feature=Presentación +articletypes.topicspecial=Especiale-por-tema +articletypes.startspecial=Especiale-página-de-inicio + ########## error ########## diff --git a/etc/bundles/adminlocal.properties b/etc/bundles/adminlocal.properties new file mode 100755 index 00000000..7395e489 --- /dev/null +++ b/etc/bundles/adminlocal.properties @@ -0,0 +1,3 @@ +# put your own local admin properties in this file +# (like for custom article types) + diff --git a/source/mir/misc/HTMLTemplateProcessor.java b/source/mir/misc/HTMLTemplateProcessor.java index 7b4cef9a..fb3b612a 100755 --- a/source/mir/misc/HTMLTemplateProcessor.java +++ b/source/mir/misc/HTMLTemplateProcessor.java @@ -1,390 +1,432 @@ -/* - * 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 mir.misc; - -import freemarker.template.*; -import mir.util.*; -import mir.generator.*; -import mir.entity.Entity; -import mir.entity.EntityList; -import mir.storage.StorageObjectException; -import org.apache.struts.util.MessageResources; - -import javax.servlet.http.HttpServletResponse; -import java.io.PrintWriter; -import java.net.URLEncoder; -import java.util.*; - - -/** - * Hilfsklasse zum Mergen von Template und Daten - */ -public final class HTMLTemplateProcessor { - - public static String templateDir; - private static FileTemplateCache templateCache; - private static Logfile theLog; - private static String docRoot; - private static String actionRoot; - - static { - templateDir = MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir"); - templateCache = new FileTemplateCache(templateDir); - templateCache.setLoadingPolicy(templateCache.LOAD_ON_DEMAND); - // gone in freemarker 1.7.1: templateCache.startAutoUpdate(); - theLog = Logfile.getInstance(MirConfig.getPropWithHome("HTMLTemplateProcessor.Logfile")); - - docRoot = MirConfig.getProp("RootUri"); - try { - actionRoot = docRoot + MirConfig.getProp("Producer.ActionServlet"); - } catch (ConfigException ce) { - // if Producer.ActionServlet is not set in the conf file - actionRoot = docRoot + "/Mir"; - } - } - - /** - * empty private constructor, to avoid instantiation - */ - private HTMLTemplateProcessor() { - } - - - // process-methods to merge different datastructures - // with freemarker templates - - - /** - * Wandelt anEntity in freemarker-Struktur um, mischt die Daten mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @param templateFilename - * @param anEntity - * @param out - * @exception HTMLParseException - */ - - public static void process(String templateFilename, Entity anEntity, PrintWriter out) - throws HTMLParseException { - if (anEntity == null) - throw new HTMLParseException("entity is empty!"); - else - process(templateFilename, anEntity, out); - } - - - /** - * Wandelt Liste mit Entities entList in freemarker-Struktur um, mischt die Daten mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @param templateFilename - * @param entList - * @param out - * @exception HTMLParseException - */ - public static void process(HttpServletResponse res, String templateFilename, - EntityList entList, PrintWriter out, Locale locale) - throws HTMLParseException { - process(res, templateFilename, entList, (String) null, (TemplateModelRoot) null, out, locale); - } - - /** - * Wandelt Entitylist in freemarker-Struktur um, fügt additionalModel - * unter dem Namen additionalModelName ein und mischt die Daten mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @param templateFilename - * @param entList - * @param additionalModelName - * @param additionalModel - * @param out - * @exception HTMLParseException - */ - public static void process(HttpServletResponse res, String templateFilename, - EntityList entList, String additionalModelName, - TemplateModelRoot additionalModel, PrintWriter out, - Locale locale) - throws HTMLParseException { - - SimpleHash modelRoot = new SimpleHash(); - - if (entList == null) { - process(null, templateFilename, modelRoot, out, locale); - } else { - try { - modelRoot = makeSimpleHashWithEntitylistInfos(entList); - - // Quickhack um mal ein Popup mit reinzunhemen .. - if (additionalModelName != null && additionalModel != null) - modelRoot.put(additionalModelName, additionalModel); - - process(res, templateFilename, modelRoot, out, locale); - } catch (StorageObjectException e) { - throw new HTMLParseException(e.toString()); - } - } - } - - /** - * Gibt Template templateFilename an den PrintWriter - * out - * - * @param templateFilename - * @param mergeData - * @param out - * @exception HTMLParseException - */ - public static void process(String templateFilename, PrintWriter out, - Locale locale) - throws HTMLParseException { - process(null, templateFilename, (TemplateModelRoot) null, out, locale); - } - - - /** - * Mischt die freemarker-Struktur tmr mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @param templateFilename - * @param mergeData - * @param out - * @exception HTMLParseException - */ - public static void process(HttpServletResponse res, String templateFilename, - TemplateModelRoot tmr, PrintWriter out, Locale locale) - throws HTMLParseException { - process(res, templateFilename, tmr, null, out, locale, "bundles.admin"); - // this method is - } - - /** - * Mischt die freemarker-Struktur tmr mit - * Template templateFilename und gibt das Ergebnis an den PrintWriter - * out - * - * @param templateFilename - * @param mergeData - * @param out - * @exception HTMLParseException - */ - public static void process(HttpServletResponse res, String templateFilename, - TemplateModelRoot tmr, TemplateModelRoot extra, - PrintWriter out, Locale locale, String bundles) - throws HTMLParseException { - if (out == null) throw new HTMLParseException("no outputstream"); - Template tmpl = getTemplateFor(templateFilename); - if (tmpl == null) throw new HTMLParseException("no template: " + templateFilename); - if (tmr == null) tmr = new SimpleHash(); - - /** @todo what is this for? (rk) */ - String session = ""; - if (res != null) { - session = res.encodeURL(""); - } - - SimpleHash configHash = new SimpleHash(); - - // pass the whole config hash to the templates - Enumeration en = MirConfig.getResourceKeys(); - String key; - while (en.hasMoreElements()) { - key = (String) en.nextElement(); - configHash.put(key, new SimpleScalar(MirConfig.getProp(key))); - } - - // this does not come directly from the config file - configHash.put("docRoot", new SimpleScalar(docRoot)); - configHash.put("actionRoot", new SimpleScalar(actionRoot + session)); - configHash.put("now", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); - - // this conform to updated freemarker syntax - configHash.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace()); - - SimpleHash utilityHash = new SimpleHash(); - try { - utilityHash.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace()); - utilityHash.put("encodeURI", FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions.encodeURIGeneratorFunction())); - utilityHash.put("encodeHTML", FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction())); - utilityHash.put("isOdd", FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions.isOddFunction())); - utilityHash.put("increment", FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions.incrementFunction())); - } - catch (Throwable t) { - throw new HTMLParseException(t.getMessage()); - } - - - SimpleHash outPutHash = new SimpleHash(); - - if (extra != null) { - outPutHash.put("extra", extra); - try { - while (((SimpleList) extra).hasNext()) { - theLog.printDebugInfo(((SimpleList) extra).next().toString()); - } - } catch (Exception e) { - } - } - outPutHash.put("data", tmr); - outPutHash.put("config", configHash); - outPutHash.put("utility", utilityHash); - - MessageResources messages = MessageResources.getMessageResources(bundles); - outPutHash.put("lang", new MessageMethodModel(locale, messages)); - - tmpl.process(outPutHash, out); - } - - - /** - * Converts Entity-List to SimpleList of SimpleHashes. - * @param aList ist eine Liste von Entity - * @return eine freemarker.template.SimpleList von SimpleHashes. - * - * @deprecated EntityLists comply with TemplateListModel now. - */ - public static SimpleList makeSimpleList(EntityList aList) throws StorageObjectException { - theLog.printWarning("## using deprecated makeSimpleList(entityList) - a waste of resources"); - SimpleList simpleList = new SimpleList(); - if (aList != null) { - for (int i = 0; i < aList.size(); i++) { - simpleList.add(aList.elementAt(i)); - } - } - return simpleList; - } - - /** - * Konvertiert ein EntityList in ein freemarker.template.SimpleHash-Modell. Im Hash - * sind die einzelnen Entities ueber ihre id zu erreichen. - * @param aList ist die EntityList - * @return SimpleHash mit den entsprechenden freemarker Daten - * - */ - public static SimpleHash makeSimpleHash(EntityList aList) throws StorageObjectException { - SimpleHash simpleHash = new SimpleHash(); - Entity currentEntity; - - if (aList != null) { - for (int i = 0; i < aList.size(); i++) { - currentEntity = (Entity) aList.elementAt(i); - simpleHash.put(currentEntity.getId(), currentEntity); - } - } - return simpleHash; - } - - /** - * Konvertiert ein Hashtable mit den keys und values als String - * in ein freemarker.template.SimpleHash-Modell - * @param mergeData der HashMap mit den String / String Daten - * @return SimpleHash mit den entsprechenden freemarker Daten - * - */ - public static SimpleHash makeSimpleHash(HashMap mergeData) { - SimpleHash modelRoot = new SimpleHash(); - String aField; - if (mergeData != null) { - Set set = mergeData.keySet(); - Iterator it = set.iterator(); - for (int i = 0; i < set.size(); i++) { - aField = (String) it.next(); - modelRoot.put(aField, (String) mergeData.get(aField)); - } - } - return modelRoot; - } - - - /** - * Converts EntityList in SimpleHash and adds additional information - * to the returned SimpleHash - * - * @param entList - * @return SimpleHash returns SimpleHash with the converted EntityList plus - * additional Data about the list. - * @exception StorageObjectException - */ - - public static SimpleHash makeSimpleHashWithEntitylistInfos(EntityList entList) throws StorageObjectException { - SimpleHash modelRoot = new SimpleHash(); - if (entList != null) { - modelRoot.put("contentlist", entList); - modelRoot.put("count", new SimpleScalar((new Integer(entList.getCount())).toString())); - if (entList.getWhere() != null) { - modelRoot.put("where", new SimpleScalar(entList.getWhere())); - modelRoot.put("where_encoded", new SimpleScalar(URLEncoder.encode(entList.getWhere()))); - } - if (entList.getOrder() != null) { - modelRoot.put("order", new SimpleScalar(entList.getOrder())); - modelRoot.put("order_encoded", new SimpleScalar(URLEncoder.encode(entList.getOrder()))); - } - modelRoot.put("from", new SimpleScalar((new Integer(entList.getFrom())).toString())); - modelRoot.put("to", new SimpleScalar((new Integer(entList.getTo())).toString())); - - if (entList.hasNextBatch()) - modelRoot.put("next", new SimpleScalar((new Integer(entList.getNextBatch())).toString())); - if (entList.hasPrevBatch()) - modelRoot.put("prev", new SimpleScalar((new Integer(entList.getPrevBatch())).toString())); - } - return modelRoot; - } - - /** - * Private methods to get template from a templateFilename - * @param templateFilename - * @return Template - * @exception HTMLParseException - */ - private static Template getTemplateFor(String templateFilename) throws HTMLParseException { - Template returnTemplate = null; - if (templateFilename != null) - returnTemplate = (Template) templateCache.getItem(templateFilename, "template"); - - - if (returnTemplate == null) { - theLog.printError("CACHE (ERR): Unknown template: " + templateFilename); - throw new HTMLParseException("Templatefile: " + templateFilename + " not found."); - } - - return returnTemplate; - } - - public static void stopAutoUpdate() { - templateCache.stopAutoUpdate(); - templateCache = null; - } - -} +/* + * 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 mir.misc; + +import freemarker.template.*; +import mir.util.*; +import mir.generator.*; +import mir.entity.Entity; +import mir.entity.EntityList; +import mir.storage.StorageObjectException; +import org.apache.struts.util.MessageResources; + +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; +import java.net.URLEncoder; +import java.util.*; + + +/** + * Hilfsklasse zum Mergen von Template und Daten + */ +public final class HTMLTemplateProcessor { + + public static String templateDir; + private static FileTemplateCache templateCache; + private static Logfile theLog; + private static String docRoot; + private static String actionRoot; + + static { + templateDir = MirConfig.getPropWithHome("HTMLTemplateProcessor.Dir"); + templateCache = new FileTemplateCache(templateDir); + templateCache.setLoadingPolicy(templateCache.LOAD_ON_DEMAND); + // gone in freemarker 1.7.1: templateCache.startAutoUpdate(); + theLog = Logfile.getInstance(MirConfig.getPropWithHome( + "HTMLTemplateProcessor.Logfile")); + + docRoot = MirConfig.getProp("RootUri"); + try { + actionRoot = docRoot + MirConfig.getProp("Producer.ActionServlet"); + } + catch (ConfigException ce) { + // if Producer.ActionServlet is not set in the conf file + actionRoot = docRoot + "/Mir"; + } + } + + /** + * empty private constructor, to avoid instantiation + */ + private HTMLTemplateProcessor() { + } + + // process-methods to merge different datastructures + // with freemarker templates + + /** + * Wandelt anEntity in freemarker-Struktur um, mischt die Daten mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @param templateFilename + * @param anEntity + * @param out + * @exception HTMLParseException + */ + + public static void process(String templateFilename, Entity anEntity, + PrintWriter out) throws HTMLParseException { + if (anEntity == null) + throw new HTMLParseException("entity is empty!"); + else + process(templateFilename, anEntity, out); + } + + /** + * Wandelt Liste mit Entities entList in freemarker-Struktur um, mischt die Daten mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @param templateFilename + * @param entList + * @param out + * @exception HTMLParseException + */ + public static void process(HttpServletResponse res, String templateFilename, + EntityList entList, PrintWriter out, Locale locale) throws HTMLParseException { + process(res, templateFilename, entList, (String)null, (TemplateModelRoot)null, + out, locale); + } + + /** + * Wandelt Entitylist in freemarker-Struktur um, fügt additionalModel + * unter dem Namen additionalModelName ein und mischt die Daten mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @param templateFilename + * @param entList + * @param additionalModelName + * @param additionalModel + * @param out + * @exception HTMLParseException + */ + public static void process(HttpServletResponse res, String templateFilename, + EntityList entList, String additionalModelName, + TemplateModelRoot additionalModel, PrintWriter out, + Locale locale) throws HTMLParseException { + + SimpleHash modelRoot = new SimpleHash(); + + if (entList == null) { + process(null, templateFilename, modelRoot, out, locale); + } + else { + try { + modelRoot = makeSimpleHashWithEntitylistInfos(entList); + + // Quickhack um mal ein Popup mit reinzunhemen .. + if (additionalModelName != null && additionalModel != null) + modelRoot.put(additionalModelName, additionalModel); + + process(res, templateFilename, modelRoot, out, locale); + } + catch (StorageObjectException e) { + throw new HTMLParseException(e.toString()); + } + } + } + + /** + * Gibt Template templateFilename an den PrintWriter + * out + * + * @param templateFilename + * @param mergeData + * @param out + * @exception HTMLParseException + */ + public static void process(String templateFilename, PrintWriter out, + Locale locale) throws HTMLParseException { + process(null, templateFilename, (TemplateModelRoot)null, out, locale); + } + + /** + * Mischt die freemarker-Struktur tmr mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @param templateFilename + * @param mergeData + * @param out + * @exception HTMLParseException + */ + public static void process(HttpServletResponse res, String templateFilename, + TemplateModelRoot tmr, PrintWriter out, + Locale locale) throws HTMLParseException { + process(res, templateFilename, tmr, null, out, locale); + } + + public static void process(HttpServletResponse res, String templateFilename, + TemplateModelRoot tmr, TemplateModelRoot extra, + PrintWriter out, Locale locale) throws HTMLParseException { + process(res, templateFilename, tmr, extra, out, locale, "bundles.adminlocal", "bundles.admin"); + } + + public static void process(HttpServletResponse res, String templateFilename, + TemplateModelRoot tmr, TemplateModelRoot extra, PrintWriter out, + Locale locale, String bundles) throws HTMLParseException { + process(res, templateFilename, tmr, extra, out, locale, bundles, null); + } + + /** + * Mischt die freemarker-Struktur tmr mit + * Template templateFilename und gibt das Ergebnis an den PrintWriter + * out + * + * @param templateFilename + * @param mergeData + * @param out + * @exception HTMLParseException + */ + public static void process(HttpServletResponse res, String templateFilename, + TemplateModelRoot tmr, TemplateModelRoot extra, + PrintWriter out, Locale locale, String bundles, + String bundles2) throws + HTMLParseException { + if (out == null) + throw new HTMLParseException("no outputstream"); + Template tmpl = getTemplateFor(templateFilename); + if (tmpl == null) + throw new HTMLParseException("no template: " + templateFilename); + if (tmr == null) + tmr = new SimpleHash(); + + /** @todo what is this for? (rk) */ + String session = ""; + if (res != null) { + session = res.encodeURL(""); + } + + SimpleHash configHash = new SimpleHash(); + + // pass the whole config hash to the templates + Enumeration en = MirConfig.getResourceKeys(); + String key; + while (en.hasMoreElements()) { + key = (String) en.nextElement(); + configHash.put(key, new SimpleScalar(MirConfig.getProp(key))); + } + + // this does not come directly from the config file + configHash.put("docRoot", new SimpleScalar(docRoot)); + configHash.put("actionRoot", new SimpleScalar(actionRoot + session)); + configHash.put("now", + new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); + + // this conform to updated freemarker syntax + configHash.put("compressWhitespace", + new freemarker.template.utility.CompressWhitespace()); + + SimpleHash utilityHash = new SimpleHash(); + try { + utilityHash.put("compressWhitespace", + new freemarker.template.utility.CompressWhitespace()); + utilityHash.put("encodeURI", + FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions. + encodeURIGeneratorFunction())); + utilityHash.put("encodeHTML", + FreemarkerGenerator.makeAdapter(new GeneratorHTMLFunctions. + encodeHTMLGeneratorFunction())); + utilityHash.put("isOdd", + FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions. + isOddFunction())); + utilityHash.put("increment", + FreemarkerGenerator.makeAdapter(new GeneratorIntegerFunctions. + incrementFunction())); + } + catch (Throwable t) { + throw new HTMLParseException(t.getMessage()); + } + + SimpleHash outPutHash = new SimpleHash(); + + if (extra != null) { + outPutHash.put("extra", extra); + try { + while ( ( (SimpleList) extra).hasNext()) { + theLog.printDebugInfo( ( (SimpleList) extra).next().toString()); + } + } + catch (Exception e) { + } + } + outPutHash.put("data", tmr); + outPutHash.put("config", configHash); + outPutHash.put("utility", utilityHash); + + MessageResources messages = MessageResources.getMessageResources(bundles); + if (bundles2!=null) { + outPutHash.put("lang", new MessageMethodModel(locale, MessageResources.getMessageResources(bundles), MessageResources.getMessageResources(bundles2))); + } + else { + outPutHash.put("lang", new MessageMethodModel(locale, MessageResources.getMessageResources(bundles))); + } + + tmpl.process(outPutHash, out); + } + + /** + * Converts Entity-List to SimpleList of SimpleHashes. + * @param aList ist eine Liste von Entity + * @return eine freemarker.template.SimpleList von SimpleHashes. + * + * @deprecated EntityLists comply with TemplateListModel now. + */ + public static SimpleList makeSimpleList(EntityList aList) throws + StorageObjectException { + theLog.printWarning( + "## using deprecated makeSimpleList(entityList) - a waste of resources"); + SimpleList simpleList = new SimpleList(); + if (aList != null) { + for (int i = 0; i < aList.size(); i++) { + simpleList.add(aList.elementAt(i)); + } + } + return simpleList; + } + + /** + * Konvertiert ein EntityList in ein freemarker.template.SimpleHash-Modell. Im Hash + * sind die einzelnen Entities ueber ihre id zu erreichen. + * @param aList ist die EntityList + * @return SimpleHash mit den entsprechenden freemarker Daten + * + */ + public static SimpleHash makeSimpleHash(EntityList aList) throws + StorageObjectException { + SimpleHash simpleHash = new SimpleHash(); + Entity currentEntity; + + if (aList != null) { + for (int i = 0; i < aList.size(); i++) { + currentEntity = (Entity) aList.elementAt(i); + simpleHash.put(currentEntity.getId(), currentEntity); + } + } + return simpleHash; + } + + /** + * Konvertiert ein Hashtable mit den keys und values als String + * in ein freemarker.template.SimpleHash-Modell + * @param mergeData der HashMap mit den String / String Daten + * @return SimpleHash mit den entsprechenden freemarker Daten + * + */ + public static SimpleHash makeSimpleHash(HashMap mergeData) { + SimpleHash modelRoot = new SimpleHash(); + String aField; + if (mergeData != null) { + Set set = mergeData.keySet(); + Iterator it = set.iterator(); + for (int i = 0; i < set.size(); i++) { + aField = (String) it.next(); + modelRoot.put(aField, (String) mergeData.get(aField)); + } + } + return modelRoot; + } + + /** + * Converts EntityList in SimpleHash and adds additional information + * to the returned SimpleHash + * + * @param entList + * @return SimpleHash returns SimpleHash with the converted EntityList plus + * additional Data about the list. + * @exception StorageObjectException + */ + + public static SimpleHash makeSimpleHashWithEntitylistInfos(EntityList entList) throws + StorageObjectException { + SimpleHash modelRoot = new SimpleHash(); + if (entList != null) { + modelRoot.put("contentlist", entList); + modelRoot.put("count", + new SimpleScalar( (new Integer(entList.getCount())).toString())); + if (entList.getWhere() != null) { + modelRoot.put("where", new SimpleScalar(entList.getWhere())); + modelRoot.put("where_encoded", + new SimpleScalar(URLEncoder.encode(entList.getWhere()))); + } + if (entList.getOrder() != null) { + modelRoot.put("order", new SimpleScalar(entList.getOrder())); + modelRoot.put("order_encoded", + new SimpleScalar(URLEncoder.encode(entList.getOrder()))); + } + modelRoot.put("from", + new SimpleScalar( (new Integer(entList.getFrom())).toString())); + modelRoot.put("to", + new SimpleScalar( (new Integer(entList.getTo())).toString())); + + if (entList.hasNextBatch()) + modelRoot.put("next", + new SimpleScalar( (new Integer(entList.getNextBatch())). + toString())); + if (entList.hasPrevBatch()) + modelRoot.put("prev", + new SimpleScalar( (new Integer(entList.getPrevBatch())). + toString())); + } + return modelRoot; + } + + /** + * Private methods to get template from a templateFilename + * @param templateFilename + * @return Template + * @exception HTMLParseException + */ + private static Template getTemplateFor(String templateFilename) throws + HTMLParseException { + Template returnTemplate = null; + if (templateFilename != null) + returnTemplate = (Template) templateCache.getItem(templateFilename, + "template"); + + if (returnTemplate == null) { + theLog.printError("CACHE (ERR): Unknown template: " + templateFilename); + throw new HTMLParseException("Templatefile: " + templateFilename + + " not found."); + } + + return returnTemplate; + } + + public static void stopAutoUpdate() { + templateCache.stopAutoUpdate(); + templateCache = null; + } + +} \ No newline at end of file diff --git a/source/mir/misc/MessageMethodModel.java b/source/mir/misc/MessageMethodModel.java index b33f18b8..b97d42cb 100755 --- a/source/mir/misc/MessageMethodModel.java +++ b/source/mir/misc/MessageMethodModel.java @@ -1,124 +1,136 @@ -/* - * 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 mir.misc; - -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateMethodModel; -import freemarker.template.TemplateModel; -import org.apache.struts.util.MessageResources; - -import java.util.List; -import java.util.Locale; - -/** - * A FreeMarker TemplateMethodModel that provides access to a - * Struts MessageResources, for use in Interantionalized templates. - * - * @author Kellan - */ - -public class MessageMethodModel implements TemplateMethodModel { - - /** - * The perferred locale for this instance of MessageMethod. - */ - private Locale locale; - - /** - * The MessageResources to query, a single instance shared for - * the lifetime of servlet. - */ - private MessageResources messages; - - - /** - * Construct a MessageMethod that uses the JVM's default locale. - * - * @param message The MessageResources object to query - */ - public MessageMethodModel(MessageResources messages) { - this(null, messages); - } - - /** - * Construct a MessageMethod - * - * @param locale a Locale object, persumably initialized - * from users Accept-Language header field - * - * @param message The MessageResources object to query - */ - public MessageMethodModel(Locale locale, MessageResources messages) { - this.locale = locale; - this.messages = messages; - } - - - /** - * Takes the first argument as a resource key, then looks up - * a string in the MessagesResources, based on that key, and the Locale - * - * TODO: error messages should be i18n :) - * - * @param arguments List passed in by FM, first arguement is a string used as the key - * all subsequent arguments are used as described in MessageResources - * (they are filled into the placehoders of the string being returned) - */ - public TemplateModel exec(List arguments) { - if (arguments != null) { - String key = (String) arguments.get(0); - arguments.remove(0); - String mesg = messages.getMessage(locale, key, arguments.toArray()); - - if (mesg == null) { - return new SimpleScalar(errUnknownTag+key); - } - return new SimpleScalar(mesg); - } - else { - return missingKeyScalar; - } - } - - // i'm not real clear on how this is used - kellan :) - public boolean isEmpty() { - if (messages == null) - return true; - else - return false; - } - - private static String errUnknownTag = "MESSAGE NOT FOUND: "; - private static String missingKey = "MESSAGE CALL WITHOUT KEY"; - private static SimpleScalar missingKeyScalar = - new SimpleScalar(missingKey); -} +/* + * 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 mir.misc; + +import freemarker.template.SimpleScalar; +import freemarker.template.TemplateMethodModel; +import freemarker.template.TemplateModel; +import org.apache.struts.util.MessageResources; + +import java.util.List; +import java.util.Locale; + +/** + * A FreeMarker TemplateMethodModel that provides access to a + * Struts MessageResources, for use in Interantionalized templates. + * + * @author Kellan + */ + +public class MessageMethodModel implements TemplateMethodModel { + + /** + * The perferred locale for this instance of MessageMethod. + */ + private Locale locale; + + /** + * The MessageResources to query, a single instance shared for + * the lifetime of servlet. + */ + private MessageResources messages; + private MessageResources messages2; + + + /** + * Construct a MessageMethod that uses the JVM's default locale. + * + * @param message The MessageResources object to query + */ + public MessageMethodModel(MessageResources messages) { + this(null, messages); + } + + /** + * Construct a MessageMethod + * + * @param locale a Locale object, persumably initialized + * from users Accept-Language header field + * + * @param message The MessageResources object to query + */ + public MessageMethodModel(Locale aLocale, MessageResources aMessages) { + this(aLocale, aMessages, null); + } + + public MessageMethodModel(Locale aLocale, MessageResources aMessages, + MessageResources aMessages2) { + locale = aLocale; + messages = aMessages; + messages2 = aMessages2; + } + + /** + * Takes the first argument as a resource key, then looks up + * a string in the MessagesResources, based on that key, and the Locale + * + * TODO: error messages should be i18n :) + * + * @param arguments List passed in by FM, first arguement is a string used as the key + * all subsequent arguments are used as described in MessageResources + * (they are filled into the placehoders of the string being returned) + */ + public TemplateModel exec(List arguments) { + if (arguments != null) { + String key = (String) arguments.get(0); + arguments.remove(0); + String mesg = null; + + if (messages!=null) + mesg = messages.getMessage(locale, key, arguments.toArray()); + + if (mesg == null && messages2!=null) { + mesg = messages2.getMessage(locale, key, arguments.toArray()); + } + + if (mesg == null) { + return new SimpleScalar(errUnknownTag + key); + } + return new SimpleScalar(mesg); + } + else { + return missingKeyScalar; + } + } + + // i'm not real clear on how this is used - kellan :) + public boolean isEmpty() { + if (messages == null) + return true; + else + return false; + } + + private static String errUnknownTag = "MESSAGE NOT FOUND: "; + private static String missingKey = "MESSAGE CALL WITHOUT KEY"; + private static SimpleScalar missingKeyScalar = new SimpleScalar(missingKey); +} diff --git a/source/mir/servlet/ServletModule.java b/source/mir/servlet/ServletModule.java index e2e1d2ab..f3f008ba 100755 --- a/source/mir/servlet/ServletModule.java +++ b/source/mir/servlet/ServletModule.java @@ -322,8 +322,8 @@ public abstract class ServletModule { if (rtm == null) rtm = new SimpleHash(); try { PrintWriter out = res.getWriter(); - HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out, - getLocale(req), "bundles.admin"); + HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out, getLocale(req)); + // we default to admin bundles here, which is not exactly beautiful... // but this whole producer stuff is going to be rewritten soon. // ServletModuleOpenIndy overwrites deliver() to use open bundles diff --git a/source/mir/util/ResourceBundleGeneratorFunction.java b/source/mir/util/ResourceBundleGeneratorFunction.java index a44a61f3..356a140f 100755 --- a/source/mir/util/ResourceBundleGeneratorFunction.java +++ b/source/mir/util/ResourceBundleGeneratorFunction.java @@ -37,12 +37,24 @@ import org.apache.struts.util.MessageResources; import mir.generator.*; public class ResourceBundleGeneratorFunction implements Generator.GeneratorFunction { - private MessageResources messages; + private List messages; private Locale locale; public ResourceBundleGeneratorFunction(Locale aLocale, MessageResources aMessages) { - this.locale = aLocale; - this.messages = aMessages; + this(aLocale, new MessageResources[] {aMessages} ); + } + + public ResourceBundleGeneratorFunction(Locale aLocale, MessageResources aMessages1, MessageResources aMessages2) { + this(aLocale, new MessageResources[] {aMessages1, aMessages2} ); + } + + public ResourceBundleGeneratorFunction(Locale aLocale, MessageResources[] aMessages) { + locale = aLocale; + messages = new Vector(); + + for(int i=0; i diff --git a/templates/admin/commentlist.template b/templates/admin/commentlist.template index 151a3817..cd1f62d9 100755 --- a/templates/admin/commentlist.template +++ b/templates/admin/commentlist.template @@ -87,24 +87,28 @@ - ${lang("comment.article")} - - ${utility.encodeHTML(entry.to_content.title)} - -
- - ${entry.status.name} - ${entry.title}
- - ${lang("comment.creator")}: ${entry.creator}
- ${entry.description} -
URL: ${entry.main_url}
-
${lang("edit")} - | - - - [${op}] - - + + ${lang("comment.article")} + + ${utility.encodeHTML(entry.to_content.title)} + +
+ + + ${lang("commentstatus." + entry.status.name)} - + + ${entry.title}
+ + ${lang("comment.creator")}: ${entry.creator}
+ ${entry.description} +
URL: ${entry.main_url}
+
${lang("edit")} + | + + + [${op}] + +
diff --git a/templates/admin/content.template b/templates/admin/content.template index bf3403c1..8a22e04e 100755 --- a/templates/admin/content.template +++ b/templates/admin/content.template @@ -79,7 +79,7 @@ diff --git a/templates/admin/contentlist.template b/templates/admin/contentlist.template index 86e79221..acc7d0f9 100755 --- a/templates/admin/contentlist.template +++ b/templates/admin/contentlist.template @@ -36,7 +36,7 @@ - ${entry.article_type.name} - + ${lang("articletypes." + entry.article_type.name)} - ${entry.title}
diff --git a/templates/admin/start_admin.template b/templates/admin/start_admin.template index 1088ace7..625cf30c 100755 --- a/templates/admin/start_admin.template +++ b/templates/admin/start_admin.template @@ -49,7 +49,7 @@ ${lang("start.show")}:
  - ${a.name}
+ ${lang("start.allarticlesoftype", lang("articletypes."+a.name))}

-- 2.11.0