yet another rewrite of the producers...
[mir.git] / source / mircoders / localizer / basic / MirBasicProducerToolLocalizer.java
1 package mircoders.localizer.basic;
2
3 import java.util.*;
4 import java.io.*;
5 import freemarker.template.utility.*;
6 import mir.misc.*;
7 import mir.entity.*;
8 import mircoders.module.*;
9 import mircoders.storage.*;
10 import mircoders.localizer.*;
11 import mircoders.global.*;
12
13 public class MirBasicProducerToolLocalizer implements MirProducerToolLocalizer {
14
15   public void initializeGenerationValueSet(Map aValueSet) {
16     // ML: these config settings will be included more beautifully as soon as the new config system is in place
17
18     Map configMap = new HashMap();
19
20                 configMap.put("producerDocRoot", "");//MirGlobal.getConfigProperty("Producer.DocRoot"));
21                 configMap.put("storageRoot", MirGlobal.getConfigProperty("Producer.StorageRoot"));
22     configMap.put("productionHost", MirGlobal.getConfigProperty("Producer.ProductionHost"));
23                 configMap.put("openAction", MirGlobal.getConfigProperty("Producer.OpenAction"));
24                 configMap.put("docRoot", MirGlobal.getConfigProperty("RootUri"));
25                 configMap.put("now", StringUtil.date2readableDateTime(new GregorianCalendar()));
26                 configMap.put("videoHost", MirGlobal.getConfigProperty("Producer.Video.Host"));
27                 configMap.put("audioHost", MirGlobal.getConfigProperty("Producer.Audio.Host"));
28                 configMap.put("imageHost", MirGlobal.getConfigProperty("Producer.Image.Host"));
29                 configMap.put("imagePath", MirGlobal.getConfigProperty("Producer.Image.Path"));
30                 configMap.put("mirVersion", MirGlobal.getConfigProperty("Mir.Version"));
31                 configMap.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() );
32                 configMap.put("defEncoding", MirGlobal.getConfigProperty("Mir.DefaultEncoding"));
33
34     aValueSet.put("config", configMap);
35
36     EntityList topicList=null;
37     EntityList entityList=null;
38     EntityList parentList=null;
39     EntityList languageList=null;
40
41     try {
42       ModuleLinksImcs linksImcsModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
43       ModuleTopics topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
44       ModuleLanguage languageModule = new ModuleLanguage(DatabaseLanguage.getInstance());
45
46       topicList = topicsModule.getTopicsList();
47       entityList = linksImcsModule.getByWhereClause("", "sortpriority, title", -1);
48       parentList = linksImcsModule.getByWhereClause("to_parent_id=NULL", "sortpriority, title", -1);
49       languageList = languageModule.getByWhereClause("", "id", -1);
50     }
51     catch (Throwable t) {
52       System.out.println("initializeGenerationValueSet: Exception "+t.getMessage());
53       t.printStackTrace(System.out);
54     }
55
56     aValueSet.put("topics", topicList);
57     aValueSet.put("imclist", entityList);
58     aValueSet.put("parentlist", parentList);
59   };
60
61   public PrintWriter openWriter(String anIdentifier) throws MirLocalizerFailure {
62     File file;
63     File dir;
64
65     try {
66       file = new File( anIdentifier );
67       dir = new File(file.getParent());
68         if (dir!=null && !dir.exists()){
69           dir.mkdirs();
70       }
71
72       return new PrintWriter(
73         new OutputStreamWriter(
74           new FileOutputStream(file), MirGlobal.getConfigProperty("Mir.DefaultEncoding")
75         )
76       );
77     }
78     catch (Throwable t) {
79       throw new MirLocalizerFailure("Failure while opening a PrintWriter",t);
80     }
81   };
82
83   public void closeWriter(PrintWriter aWriter) {
84     aWriter.close();
85   };
86
87   public String filterText(String aText) {
88     return StringUtil.createHTML(
89         StringUtil.deleteForbiddenTags(aText),
90         MirGlobal.getConfigProperty("Producer.ImageRoot"),
91         MirGlobal.getConfigProperty("Producer.MailLinkName"),
92         MirGlobal.getConfigProperty("Producer.ExtLinkName"),
93         MirGlobal.getConfigProperty("Producer.IntLinkName")
94     );
95   }
96 }