- topiclist now optionally with checkboxes on article edit form
[mir.git] / source / mircoders / localizer / basic / MirBasicProducerAssistantLocalizer.java
1 /*\r
2  * Copyright (C) 2001, 2002  The Mir-coders group\r
3  *\r
4  * This file is part of Mir.\r
5  *\r
6  * Mir is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 2 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Mir is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with Mir; if not, write to the Free Software\r
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19  *\r
20  * In addition, as a special exception, The Mir-coders gives permission to link\r
21  * the code of this program with the com.oreilly.servlet library, any library\r
22  * licensed under the Apache Software License, The Sun (tm) Java Advanced\r
23  * Imaging library (JAI), The Sun JIMI library (or with modified versions of\r
24  * the above that use the same license as the above), and distribute linked\r
25  * combinations including the two.  You must obey the GNU General Public\r
26  * License in all respects for all of the code used other than the above\r
27  * mentioned libraries.  If you modify this file, you may extend this exception\r
28  * to your version of the file, but you are not obligated to do so.  If you do\r
29  * not wish to do so, delete this exception statement from your version.\r
30  */\r
31 \r
32 package mircoders.localizer.basic;\r
33 \r
34 import java.util.GregorianCalendar;\r
35 import java.util.HashMap;\r
36 import java.util.Iterator;\r
37 import java.util.Map;\r
38 \r
39 import mir.config.MirPropertiesConfiguration;\r
40 import mir.entity.adapter.EntityAdapter;\r
41 import mir.entity.adapter.EntityIteratorAdapter;\r
42 import mir.log.LoggerWrapper;\r
43 import mir.misc.StringUtil;\r
44 import mir.util.DateToMapAdapter;\r
45 import mir.util.GeneratorHTMLFunctions;\r
46 import mir.util.GeneratorIntegerFunctions;\r
47 import mir.util.GeneratorListFunctions;\r
48 import mir.util.GeneratorStringFunctions;\r
49 import mircoders.global.MirGlobal;\r
50 import mircoders.localizer.MirProducerAssistantLocalizer;\r
51 \r
52 public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantLocalizer {\r
53   protected LoggerWrapper logger;\r
54 \r
55   public void initializeGenerationValueSet(Map aValueSet) {\r
56     try {\r
57       Iterator i;\r
58 \r
59       Map configMap = new HashMap();\r
60       Map utilityMap = new HashMap();\r
61 \r
62       logger = new LoggerWrapper("Localizer.ProducerAssistant");\r
63 \r
64 // obsolete:\r
65       configMap.put("producerDocRoot", MirGlobal.config().getString("Producer.DocRoot"));\r
66       configMap.put("storageRoot", MirGlobal.config().getString("Producer.StorageRoot"));\r
67       configMap.put("productionHost", MirGlobal.config().getString("Producer.ProductionHost"));\r
68       configMap.put("openAction", MirGlobal.config().getString("Producer.OpenAction"));\r
69       configMap.put("docRoot", MirGlobal.config().getString("RootUri"));\r
70       configMap.put("actionRoot", MirGlobal.config().getString("RootUri") + "/servlet/Mir");\r
71       configMap.put("now", new DateToMapAdapter( (new GregorianCalendar()).getTime()));\r
72       configMap.put("videoHost", MirGlobal.config().getString("Producer.Video.Host"));\r
73       configMap.put("audioHost", MirGlobal.config().getString("Producer.Audio.Host"));\r
74       configMap.put("imageHost", MirGlobal.config().getString("Producer.Image.Host"));\r
75       configMap.put("imagePath", MirGlobal.config().getString("Producer.Image.Path"));\r
76       configMap.put("mirVersion", MirGlobal.config().getString("Mir.Version"));\r
77       configMap.put("defEncoding", MirGlobal.config().getString("Mir.DefaultEncoding"));\r
78 \r
79 // "new":\r
80       configMap.putAll(MirPropertiesConfiguration.instance().allSettings());\r
81 \r
82       utilityMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace());\r
83       utilityMap.put("encodeHTML", new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction());\r
84       utilityMap.put("encodeXML", new GeneratorHTMLFunctions.encodeXMLGeneratorFunction());\r
85       utilityMap.put("encodeURI", new GeneratorHTMLFunctions.encodeURIGeneratorFunction());\r
86       utilityMap.put("subString", new GeneratorStringFunctions.subStringFunction());\r
87       utilityMap.put("subList", new GeneratorListFunctions.subListFunction());\r
88       utilityMap.put("isOdd", new GeneratorIntegerFunctions.isOddFunction());\r
89       utilityMap.put("increment", new GeneratorIntegerFunctions.incrementFunction());\r
90 \r
91       aValueSet.put("config", configMap);\r
92       aValueSet.put("utility", utilityMap);\r
93 \r
94       aValueSet.put("languages",\r
95         new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "language"));\r
96 \r
97       aValueSet.put("topics",\r
98         new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "topic"));\r
99 \r
100       Map articleTypeMap = new HashMap();\r
101       articleTypeMap.put("openposting", "0");\r
102       articleTypeMap.put("newswire", "1");\r
103       articleTypeMap.put("feature", "2");\r
104       articleTypeMap.put("topicspecial", "3");\r
105       articleTypeMap.put("startspecial", "4");\r
106 \r
107       i = new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "articleType");\r
108       while (i.hasNext()) {\r
109         EntityAdapter articleType = (EntityAdapter) i.next();\r
110 \r
111         articleTypeMap.put(articleType.get("name"), articleType.get("id"));\r
112       }\r
113       aValueSet.put("articletype", articleTypeMap);\r
114 \r
115       Map commentStatusMap = new HashMap();\r
116       i = new EntityIteratorAdapter("", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "commentStatus");\r
117       while (i.hasNext()) {\r
118         EntityAdapter commentStatus = (EntityAdapter) i.next();\r
119 \r
120         commentStatusMap.put(commentStatus.get("name"), commentStatus.get("id"));\r
121       }\r
122       aValueSet.put("commentstatus", commentStatusMap);\r
123     }\r
124     catch (Throwable t) {\r
125       logger.error("initializeGenerationValueSet: Exception while collecting comment statuses" + t.getMessage());\r
126       throw new RuntimeException(t.getMessage());\r
127     }\r
128 \r
129   };\r
130 \r
131   public String filterText(String aText) {\r
132     return StringUtil.createHTML(\r
133         StringUtil.deleteForbiddenTags(aText),\r
134         MirGlobal.config().getString("Producer.ImageRoot"),\r
135         MirGlobal.config().getString("Producer.MailLinkName"),\r
136         MirGlobal.config().getString("Producer.ExtLinkName"),\r
137         MirGlobal.config().getString("Producer.IntLinkName")\r
138     );\r
139   }\r
140 }\r