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