1 package mircoders.producer;
5 import freemarker.template.*;
11 import mircoders.module.*;
12 import mircoders.entity.*;
13 import mircoders.storage.*;
15 abstract public class Producer {
17 protected static String producerDocRoot = MirConfig.getProp("Producer.DocRoot");
18 protected static String producerStorageRoot = MirConfig.getProp("Producer.StorageRoot");
19 protected static String producerProductionHost = MirConfig.getProp("Producer.ProductionHost");
20 protected static String producerOpenAction = MirConfig.getProp("Producer.OpenAction");;
21 protected static String actionRoot = null;
23 protected static Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home") + "/" + MirConfig.getProp("Producer.Logfile"));
24 protected static ModuleTopics topicsModule;
25 protected static ModuleLinksImcs linksImcsModule;
26 protected static ModuleSchwerpunkt schwerpunktModule;
27 protected static ModuleFeature featureModule;
28 protected static ModuleContent contentModule;
29 protected static ModuleImages imageModule;
30 protected static ModuleUploadedMedia uploadedMediaModule;
35 contentModule = new ModuleContent(DatabaseContent.getInstance());
36 topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
37 linksImcsModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
38 schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
39 featureModule = new ModuleFeature(DatabaseFeature.getInstance());
40 imageModule = new ModuleImages(DatabaseImages.getInstance());
41 uploadedMediaModule = new ModuleUploadedMedia(DatabaseImages.getInstance());
42 /** @todo same as in HTMLTemplateProcessor, this should be dynamically set */
43 actionRoot = producerDocRoot + "/servlet/Mir";
45 catch(StorageObjectException e)
47 System.err.println("*** failed to initialize Producer " + e.toString());
51 public void handle(PrintWriter htmlout, EntityUsers user)
52 throws StorageObjectException, ModuleException {
53 handle(htmlout,user,false,false);
56 abstract public void handle(PrintWriter htmlout, EntityUsers user, boolean forced, boolean sync)
57 throws StorageObjectException, ModuleException;
60 // Methods for producing files
62 public boolean produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
63 return _produce(template, filename, model, htmlout, false);
66 public boolean produce_compressed(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
67 return _produce(template, filename, model, htmlout, true);
70 private boolean _produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout, boolean compressed) {
72 File f = new File(producerStorageRoot + filename);
73 File dir = new File(f.getParent());
75 FileWriter outputFile = new FileWriter(f);
76 PrintWriter outStream;
77 if (compressed==true) {
78 outStream = new LineFilterWriter(outputFile);
80 outStream = new PrintWriter(outputFile);
83 HTMLTemplateProcessor.process(null,template, model, outStream);
87 printHTML(htmlout, "Produced <a href=\"" + producerProductionHost+ filename + "\">" + filename + "</a>");
88 //theLog.printInfo("Produced: " + producerStorageRoot + filename);
89 //theLog.printDebugInfo("free mem:" + java.lang.Runtime.getRuntime().freeMemory());
90 //theLog.printDebugInfo("total mem:" + java.lang.Runtime.getRuntime().totalMemory());
93 } catch(IOException exception){
94 logHTML(htmlout, "Producer: File could not be written " + filename);
96 } catch(HTMLParseException exception){
97 logHTML(htmlout,"Producer: Error in HTML-parsing: " + filename);
102 public boolean produceFile(String filename, byte[] in, PrintWriter htmlout, boolean icon) {
104 boolean retVal = false;
110 f = new File(filename);
111 theLog.printDebugInfo("image: " + filename);
113 f = new File(producerStorageRoot + filename);
114 theLog.printDebugInfo("icon: " + filename);
116 File dir = new File(f.getParent());
119 FileOutputStream outStream;
120 outStream = new FileOutputStream(f);
124 } catch(IOException exception) {
125 logHTML(htmlout, "Producer: File could not be written: " + filename);
136 public String indexFileNameForPageCount(int pc) {
137 return fileNameForPageCount("/index", pc);
140 public String fileNameForPageCount(String stub, int pc) {
141 String fileName = producerDocRoot + stub;
152 public void logHTML(PrintWriter out, String s) {
153 _print(out, s, true);
156 public void printHTML(PrintWriter out, String s) {
157 _print(out, s, false);
160 private void _print(PrintWriter out, String s, boolean log) {
161 if (out != null) { out.println(s+"<br>");out.flush(); }