fixed comment/article search + configurable icon sizes
[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;
35 import java.util.HashMap;
36 import java.util.Iterator;
37 import java.util.Map;
38
39 import mir.config.MirPropertiesConfiguration;
40 import mir.config.MirPropertiesConfiguration.PropertiesConfigExc;
41 import mir.entity.EntityList;
42 import mir.entity.adapter.EntityAdapter;
43 import mir.entity.adapter.EntityIteratorAdapter;
44 import mir.log.LoggerWrapper;
45 import mir.misc.StringUtil;
46 import mir.util.DateToMapAdapter;
47 import mir.util.GeneratorHTMLFunctions;
48 import mir.util.GeneratorIntegerFunctions;
49 import mir.util.GeneratorListFunctions;
50 import mir.util.GeneratorStringFunctions;
51 import mircoders.global.MirGlobal;
52 import mircoders.localizer.MirProducerAssistantLocalizer;
53 import mircoders.module.ModuleLanguage;
54 import mircoders.module.ModuleTopics;
55 import mircoders.storage.DatabaseLanguage;
56 import mircoders.storage.DatabaseTopics;
57
58 public class MirBasicProducerAssistantLocalizer implements MirProducerAssistantLocalizer {
59   protected LoggerWrapper logger;
60
61   public void initializeGenerationValueSet(Map aValueSet) {
62     Iterator i;
63
64     Map configMap = new HashMap();
65     Map utilityMap = new HashMap();
66
67     logger = new LoggerWrapper("Localizer.Basic.ProducerAssistant");
68
69 // obsolete:
70     configMap.put("producerDocRoot", MirGlobal.getConfigProperty("Producer.DocRoot"));
71     configMap.put("storageRoot", MirGlobal.getConfigProperty("Producer.StorageRoot"));
72     configMap.put("productionHost", MirGlobal.getConfigProperty("Producer.ProductionHost"));
73     configMap.put("openAction", MirGlobal.getConfigProperty("Producer.OpenAction"));
74     configMap.put("docRoot", MirGlobal.getConfigProperty("RootUri"));
75     configMap.put("actionRoot", MirGlobal.getConfigProperty("RootUri")+"/servlet/Mir");
76     configMap.put("now", new DateToMapAdapter((new GregorianCalendar()).getTime()));
77     configMap.put("videoHost", MirGlobal.getConfigProperty("Producer.Video.Host"));
78     configMap.put("audioHost", MirGlobal.getConfigProperty("Producer.Audio.Host"));
79     configMap.put("imageHost", MirGlobal.getConfigProperty("Producer.Image.Host"));
80     configMap.put("imagePath", MirGlobal.getConfigProperty("Producer.Image.Path"));
81     configMap.put("mirVersion", MirGlobal.getConfigProperty("Mir.Version"));
82     configMap.put("defEncoding", MirGlobal.getConfigProperty("Mir.DefaultEncoding"));
83
84 // "new":
85     try {
86       configMap.putAll( MirPropertiesConfiguration.instance().allSettings() );
87     } catch (PropertiesConfigExc e) {
88       e.printStackTrace(System.err);
89     }
90
91     utilityMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() );
92     utilityMap.put("encodeHTML", new GeneratorHTMLFunctions.encodeHTMLGeneratorFunction());
93     utilityMap.put("encodeXML", new GeneratorHTMLFunctions.encodeXMLGeneratorFunction());
94     utilityMap.put("encodeURI", new GeneratorHTMLFunctions.encodeURIGeneratorFunction());
95     utilityMap.put("subString", new GeneratorStringFunctions.subStringFunction());
96     utilityMap.put("subList", new GeneratorListFunctions.subListFunction());
97     utilityMap.put("isOdd", new GeneratorIntegerFunctions.isOddFunction());
98     utilityMap.put("increment", new GeneratorIntegerFunctions.incrementFunction());
99
100
101     aValueSet.put("config", configMap);
102     aValueSet.put("utility", utilityMap);
103
104
105     EntityList topicList=null;
106     EntityList entityList=null;
107     EntityList languageList=null;
108
109     try {
110       ModuleTopics topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
111       ModuleLanguage languageModule = new ModuleLanguage(DatabaseLanguage.getInstance());
112
113       topicList = topicsModule.getTopicsList();
114       languageList = languageModule.getByWhereClause("", "id", -1);
115
116     }
117     catch (Throwable t) {
118       logger.error("initializeGenerationValueSet: Exception "+t.getMessage());
119     }
120
121     aValueSet.put("topics", topicList);
122     aValueSet.put("imclist", entityList);
123
124     Map articleTypeMap = new HashMap();
125     articleTypeMap.put("openposting", "0");
126     articleTypeMap.put("newswire", "1");
127     articleTypeMap.put("feature", "2");
128     articleTypeMap.put("topicspecial", "3");
129     articleTypeMap.put("startspecial", "4");
130
131     try {
132       i = new EntityIteratorAdapter( "", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "articleType"  );
133
134       while (i.hasNext()) {
135         EntityAdapter articleType = (EntityAdapter) i.next();
136
137         articleTypeMap.put(articleType.get("name"), articleType.get("id"));
138       }
139     }
140     catch (Throwable t) {
141       logger.error("initializeGenerationValueSet: Exception while collecting article types "+t.getMessage());
142     }
143     aValueSet.put("articletype", articleTypeMap);
144
145     Map commentStatusMap = new HashMap();
146     try {
147       i = new EntityIteratorAdapter( "", "", 20, MirGlobal.localizer().dataModel().adapterModel(), "commentStatus"  );
148
149       while (i.hasNext()) {
150         EntityAdapter commentStatus = (EntityAdapter) i.next();
151
152         commentStatusMap.put(commentStatus.get("name"), commentStatus.get("id"));
153       }
154     }
155     catch (Throwable t) {
156       logger.error("initializeGenerationValueSet: Exception while collecting comment statuses"+t.getMessage());
157     }
158     aValueSet.put("commentstatus", commentStatusMap);
159
160   };
161
162   public String filterText(String aText) {
163     return StringUtil.createHTML(
164         StringUtil.deleteForbiddenTags(aText),
165         MirGlobal.getConfigProperty("Producer.ImageRoot"),
166         MirGlobal.getConfigProperty("Producer.MailLinkName"),
167         MirGlobal.getConfigProperty("Producer.ExtLinkName"),
168         MirGlobal.getConfigProperty("Producer.IntLinkName")
169     );
170   }
171 }