-/*
- * 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 mircoders.localizer.basic;
-
-import java.util.*;
-import java.io.*;
-import freemarker.template.utility.*;
-import mir.misc.*;
-import mir.entity.*;
-import mir.entity.adapter.*;
-import mir.util.*;
-import mircoders.module.*;
-import mircoders.storage.*;
-import mircoders.localizer.*;
-import mircoders.global.*;
-
-public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantLocalizer {
- protected static Logfile logger = Logfile.getInstance( MirGlobal.getConfigProperty("Home") + "/" + MirGlobal.getConfigProperty("Mir.Localizer.Logfile"));
-
- public void initializeGenerationValueSet(Map aValueSet) {
- Iterator i;
-
- Map configMap = new HashMap();
- Map utilityMap = new HashMap();
-
-// obsolete:
- configMap.put("producerDocRoot", MirGlobal.getConfigProperty("Producer.DocRoot"));
- configMap.put("storageRoot", MirGlobal.getConfigProperty("Producer.StorageRoot"));
- configMap.put("productionHost", MirGlobal.getConfigProperty("Producer.ProductionHost"));
- configMap.put("openAction", MirGlobal.getConfigProperty("Producer.OpenAction"));
- configMap.put("docRoot", MirGlobal.getConfigProperty("RootUri"));
- configMap.put("actionRoot", MirGlobal.getConfigProperty("RootUri")+"/servlet/Mir");
- configMap.put("now", new DateToMapAdapter((new GregorianCalendar()).getTime()));
- configMap.put("videoHost", MirGlobal.getConfigProperty("Producer.Video.Host"));
- configMap.put("audioHost", MirGlobal.getConfigProperty("Producer.Audio.Host"));
- configMap.put("imageHost", MirGlobal.getConfigProperty("Producer.Image.Host"));
- configMap.put("imagePath", MirGlobal.getConfigProperty("Producer.Image.Path"));
- configMap.put("mirVersion", MirGlobal.getConfigProperty("Mir.Version"));
- configMap.put("defEncoding", MirGlobal.getConfigProperty("Mir.DefaultEncoding"));
-
-// "new":
- configMap.putAll( MirConfig.allSettings() );
-
- utilityMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() );
- utilityMap.put("encodeHTML", new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction());
- utilityMap.put("encodeURI", new GeneratorHTMLFunctions.encodeURIGeneratorFunction());
-
- aValueSet.put("config", configMap);
- aValueSet.put("utility", utilityMap);
-
- EntityList topicList=null;
- EntityList entityList=null;
- EntityList parentList=null;
- EntityList languageList=null;
-
- try {
- ModuleTopics topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
- ModuleLanguage languageModule = new ModuleLanguage(DatabaseLanguage.getInstance());
-
- topicList = topicsModule.getTopicsList();
- languageList = languageModule.getByWhereClause("", "id", -1);
- }
- catch (Throwable t) {
- logger.printError("initializeGenerationValueSet: Exception "+t.getMessage());
- }
-
- aValueSet.put("topics", topicList);
- aValueSet.put("imclist", entityList);
- aValueSet.put("parentlist", parentList);
-
- Map articleTypeMap = new HashMap();
- articleTypeMap.put("openposting", "0");
- articleTypeMap.put("newswire", "1");
- articleTypeMap.put("feature", "2");
- articleTypeMap.put("topicspecial", "3");
- articleTypeMap.put("startspecial", "4");
-
- try {
- i = new EntityIteratorAdapter( "", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "articleType" );
-
- while (i.hasNext()) {
- EntityAdapter articleType = (EntityAdapter) i.next();
-
- articleTypeMap.put(articleType.get("name"), articleType.get("id"));
- }
- }
- catch (Throwable t) {
- logger.printError("initializeGenerationValueSet: Exception "+t.getMessage());
- }
-
- aValueSet.put("articletype", articleTypeMap);
- };
-
- public String filterText(String aText) {
- return StringUtil.createHTML(
- StringUtil.deleteForbiddenTags(aText),
- MirGlobal.getConfigProperty("Producer.ImageRoot"),
- MirGlobal.getConfigProperty("Producer.MailLinkName"),
- MirGlobal.getConfigProperty("Producer.ExtLinkName"),
- MirGlobal.getConfigProperty("Producer.IntLinkName")
- );
- }
-}
+/*\r
+ * Copyright (C) 2001, 2002 The Mir-coders group\r
+ *\r
+ * This file is part of Mir.\r
+ *\r
+ * Mir is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * Mir is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with Mir; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ *\r
+ * In addition, as a special exception, The Mir-coders gives permission to link\r
+ * the code of this program with any library licensed under the Apache Software License,\r
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
+ * (or with modified versions of the above that use the same license as the above),\r
+ * and distribute linked combinations including the two. You must obey the\r
+ * GNU General Public License in all respects for all of the code used other than\r
+ * the above mentioned libraries. If you modify this file, you may extend this\r
+ * exception to your version of the file, but you are not obligated to do so.\r
+ * If you do not wish to do so, delete this exception statement from your version.\r
+ */\r
+package mircoders.localizer.basic;\r
+\r
+import java.util.GregorianCalendar;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+\r
+import mir.config.MirPropertiesConfiguration;\r
+import mir.entity.adapter.EntityAdapter;\r
+import mir.entity.adapter.EntityIteratorAdapter;\r
+import mir.log.LoggerWrapper;\r
+import mir.misc.StringUtil;\r
+import mir.util.GeneratorDateTimeFunctions;\r
+import mir.util.GeneratorExpressionFunctions;\r
+import mir.util.GeneratorFormatAdapters;\r
+import mir.util.GeneratorHTMLFunctions;\r
+import mir.util.GeneratorIntegerFunctions;\r
+import mir.util.GeneratorListFunctions;\r
+import mir.util.GeneratorRegularExpressionFunctions;\r
+import mir.util.GeneratorStringFunctions;\r
+import mircoders.global.MirGlobal;\r
+import mircoders.localizer.MirLocalizerExc;\r
+import mircoders.localizer.MirLocalizerFailure;\r
+import mircoders.localizer.MirProducerAssistantLocalizer;\r
+\r
+public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantLocalizer {\r
+ protected LoggerWrapper logger;\r
+\r
+ public void initializeGenerationValueSet(Map aValueSet) throws MirLocalizerExc, MirLocalizerFailure {\r
+ try {\r
+ Iterator i;\r
+\r
+ Map configMap = new HashMap();\r
+ Map utilityMap = new HashMap();\r
+\r
+ logger = new LoggerWrapper("Localizer.ProducerAssistant");\r
+\r
+// obsolete:\r
+ configMap.put("producerDocRoot", MirGlobal.config().getString("Producer.DocRoot"));\r
+ configMap.put("storageRoot", MirGlobal.config().getString("Producer.StorageRoot"));\r
+ configMap.put("productionHost", MirGlobal.config().getString("Producer.ProductionHost"));\r
+ configMap.put("openAction", MirGlobal.config().getString("Producer.OpenAction"));\r
+ configMap.put("docRoot", MirGlobal.config().getString("RootUri"));\r
+ configMap.put("actionRoot", MirGlobal.config().getString("RootUri") + "/servlet/Mir");\r
+ configMap.put("now", new GeneratorFormatAdapters.DateFormatAdapter(new GregorianCalendar().getTime(), MirGlobal.config().getString("Mir.DefaultTimezone")));\r
+ configMap.put("videoHost", MirGlobal.config().getString("Producer.Video.Host"));\r
+ configMap.put("audioHost", MirGlobal.config().getString("Producer.Audio.Host"));\r
+ configMap.put("imageHost", MirGlobal.config().getString("Producer.Image.Host"));\r
+ configMap.put("imagePath", MirGlobal.config().getString("Producer.Image.Path"));\r
+ configMap.put("mirVersion", MirGlobal.config().getString("Mir.Version"));\r
+ configMap.put("defEncoding", MirGlobal.config().getString("Mir.DefaultEncoding"));\r
+\r
+// "new":\r
+ configMap.putAll(MirPropertiesConfiguration.instance().allSettings());\r
+\r
+ utilityMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace());\r
+ utilityMap.put("encodeHTML", new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction());\r
+ utilityMap.put("prettyEncodeHTML", new GeneratorHTMLFunctions.prettyEncodeHTMLGeneratorFunction());\r
+ utilityMap.put("encodeXML", new GeneratorHTMLFunctions.encodeXMLGeneratorFunction());\r
+ utilityMap.put("encodeURI", new GeneratorHTMLFunctions.encodeURIGeneratorFunction());\r
+ utilityMap.put("subString", new GeneratorStringFunctions.subStringFunction());\r
+ utilityMap.put("subList", new GeneratorListFunctions.subListFunction());\r
+ utilityMap.put("isOdd", new GeneratorIntegerFunctions.isOddFunction());\r
+ utilityMap.put("increment", new GeneratorIntegerFunctions.incrementFunction());\r
+ utilityMap.put("evaluate", new GeneratorExpressionFunctions.evaluateExpressionFunction());\r
+ utilityMap.put("constructString", new GeneratorStringFunctions.constructStructuredStringFunction());\r
+ utilityMap.put("parseStructuredString", new GeneratorStringFunctions.structuredStringParserFunction());\r
+ utilityMap.put("escapeJDBCString", new GeneratorStringFunctions.jdbcStringEscapeFunction());\r
+ utilityMap.put("regexpreplace", new GeneratorRegularExpressionFunctions.regularExpressionReplaceFunction());\r
+ utilityMap.put("regexpmatch", new GeneratorRegularExpressionFunctions.regularExpressionMatchFunction());\r
+ utilityMap.put("datetime", new GeneratorDateTimeFunctions.DateTimeFunctions(\r
+ MirPropertiesConfiguration.instance().getString("Mir.DefaultTimezone")));\r
+\r
+ aValueSet.put("config", configMap);\r
+ aValueSet.put("utility", utilityMap);\r
+\r
+ aValueSet.put("languages",\r
+ new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "language"));\r
+\r
+ aValueSet.put("topics",\r
+ new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "topic"));\r
+\r
+ Map articleTypeMap = new HashMap();\r
+ articleTypeMap.put("openposting", "0");\r
+ articleTypeMap.put("newswire", "1");\r
+ articleTypeMap.put("feature", "2");\r
+ articleTypeMap.put("topicspecial", "3");\r
+ articleTypeMap.put("startspecial", "4");\r
+\r
+ i = new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "articleType");\r
+ while (i.hasNext()) {\r
+ EntityAdapter articleType = (EntityAdapter) i.next();\r
+\r
+ articleTypeMap.put(articleType.get("name"), articleType.get("id"));\r
+ }\r
+ aValueSet.put("articletype", articleTypeMap);\r
+\r
+ Map commentStatusMap = new HashMap();\r
+ i = new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "commentStatus");\r
+ while (i.hasNext()) {\r
+ EntityAdapter commentStatus = (EntityAdapter) i.next();\r
+\r
+ commentStatusMap.put(commentStatus.get("name"), commentStatus.get("id"));\r
+ }\r
+ aValueSet.put("commentstatus", commentStatusMap);\r
+ }\r
+ catch (Throwable t) {\r
+ logger.error("initializeGenerationValueSet: Exception while collecting comment statuses" + t.getMessage());\r
+ throw new RuntimeException(t.getMessage());\r
+ }\r
+\r
+ };\r
+\r
+ public String filterNonHTMLText(String aText) {\r
+\r
+ logger.debug("about to filter non HTML Text of length " + aText.length());\r
+ try {\r
+ String result =\r
+ StringUtil.createHTML(\r
+ StringUtil.removeHTMLTags(aText),\r
+ MirGlobal.config().getString("Producer.ImageRoot"),\r
+ MirGlobal.config().getString("Producer.MailLinkName"),\r
+ MirGlobal.config().getString("Producer.ExtLinkName"),\r
+ MirGlobal.config().getString("Producer.IntLinkName")\r
+ );\r
+ logger.debug("done filtering non-HTML text ");\r
+ return result;\r
+ }\r
+ catch (Throwable t) {\r
+ logger.error("error while filtering non-HTML text: " + t.toString());\r
+\r
+ throw new RuntimeException(t.toString());\r
+ }\r
+ }\r
+\r
+ public String filterHTMLText(String aText) {\r
+ return StringUtil.deleteForbiddenTags(aText);\r
+ }\r
+}\r