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