i changed the exception-handling of the new producers and localizers to use the multe...
[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
40     try {
41       ModuleLinksImcs linksImcsModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
42       ModuleTopics topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
43
44       topicList = topicsModule.getTopicsList();
45       entityList = linksImcsModule.getByWhereClause("", "sortpriority, title", -1);
46       parentList = linksImcsModule.getByWhereClause("to_parent_id=NULL", "sortpriority, title", -1);
47
48     }
49     catch (Throwable t) {
50       System.out.println("initializeGenerationValueSet: Exception "+t.getMessage());
51       t.printStackTrace(System.out);
52     }
53
54     aValueSet.put("topics", topicList);
55     aValueSet.put("imclist", entityList);
56     aValueSet.put("parentlist", parentList);
57   };
58
59   public PrintWriter openWriter(String anIdentifier) throws MirLocalizerFailure {
60     File file;
61     File dir;
62
63     try {
64       file = new File( anIdentifier );
65       dir = new File(file.getParent());
66         if (dir!=null && !dir.exists()){
67           dir.mkdirs();
68       }
69
70       return new PrintWriter(
71         new OutputStreamWriter(
72           new FileOutputStream(file), MirGlobal.getConfigProperty("Mir.DefaultEncoding")
73         )
74       );
75     }
76     catch (Throwable t) {
77       throw new MirLocalizerFailure("Failure while opening a PrintWriter",t);
78     }
79   };
80
81   public void closeWriter(PrintWriter aWriter) {
82     aWriter.close();
83   };
84 }