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");;
22 /** @todo same as in HTMLTemplateProcessor, this should be dynamically set */
23 protected static String actionRoot = MirConfig.getProp("RootUri") + "/servlet/Mir";
25 protected static Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home") + "/" + MirConfig.getProp("Producer.Logfile"));
26 protected static ModuleTopics topicsModule;
27 protected static ModuleLinksImcs linksImcsModule;
28 protected static ModuleSchwerpunkt schwerpunktModule;
29 protected static ModuleFeature featureModule;
30 protected static ModuleContent contentModule;
31 protected static ModuleImages imageModule;
32 protected static ModuleUploadedMedia uploadedMediaModule;
38 contentModule = new ModuleContent(DatabaseContent.getInstance());
39 topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
40 linksImcsModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
41 schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
42 featureModule = new ModuleFeature(DatabaseFeature.getInstance());
43 imageModule = new ModuleImages(DatabaseImages.getInstance());
44 uploadedMediaModule = new ModuleUploadedMedia(DatabaseImages.getInstance());
47 catch(StorageObjectException e)
49 System.err.println("*** failed to initialize Producer " + e.toString());
53 public void handle(PrintWriter htmlout, EntityUsers user)
54 throws StorageObjectException, ModuleException {
55 handle(htmlout,user,false,false);
58 abstract public void handle(PrintWriter htmlout, EntityUsers user, boolean forced, boolean sync)
59 throws StorageObjectException, ModuleException;
62 // Methods for producing files
64 public boolean produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
65 return _produce(template, filename, model, htmlout, false);
68 public boolean produce_compressed(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
69 return _produce(template, filename, model, htmlout, true);
72 private boolean _produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout, boolean compressed) {
74 File f = new File(producerStorageRoot + filename);
75 File dir = new File(f.getParent());
77 FileWriter outputFile = new FileWriter(f);
78 PrintWriter outStream;
79 if (compressed==true) {
80 outStream = new LineFilterWriter(outputFile);
82 outStream = new PrintWriter(outputFile);
85 HTMLTemplateProcessor.process(null,template, model, outStream);
89 printHTML(htmlout, "Produced <a href=\"" + producerProductionHost+ filename + "\">" + filename + "</a>");
90 //theLog.printInfo("Produced: " + producerStorageRoot + filename);
91 //theLog.printDebugInfo("free mem:" + java.lang.Runtime.getRuntime().freeMemory());
92 //theLog.printDebugInfo("total mem:" + java.lang.Runtime.getRuntime().totalMemory());
95 } catch(IOException exception){
96 logHTML(htmlout, "Producer: File could not be written " + filename);
98 } catch(HTMLParseException exception){
99 logHTML(htmlout,"Producer: Error in HTML-parsing: " + filename);
104 public boolean produceFile(String filename, byte[] in, PrintWriter htmlout, boolean icon) {
106 boolean retVal = false;
112 f = new File(filename);
113 theLog.printDebugInfo("image: " + filename);
115 f = new File(producerStorageRoot + filename);
116 theLog.printDebugInfo("icon: " + filename);
118 File dir = new File(f.getParent());
121 FileOutputStream outStream;
122 outStream = new FileOutputStream(f);
126 } catch(IOException exception) {
127 logHTML(htmlout, "Producer: File could not be written: " + filename);
138 public String indexFileNameForPageCount(int pc) {
139 return fileNameForPageCount("/index", pc);
142 public String fileNameForPageCount(String stub, int pc) {
143 String fileName = producerDocRoot + stub;
154 public void logHTML(PrintWriter out, String s) {
155 _print(out, s, true);
158 public void printHTML(PrintWriter out, String s) {
159 _print(out, s, false);
162 private void _print(PrintWriter out, String s, boolean log) {
163 if (out != null) { out.println(s+"<br>");out.flush(); }