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 Logfile theLog = Logfile.getInstance(MirConfig.getProp("Home") + "/" + MirConfig.getProp("Producer.Logfile"));
22 protected static ModuleTopics topicsModule;
23 protected static ModuleLinksImcs linksImcsModule;
24 protected static ModuleSchwerpunkt schwerpunktModule;
25 protected static ModuleFeature featureModule;
26 protected static ModuleContent contentModule;
27 protected static ModuleImages imageModule;
28 protected static ModuleUploadedMedia uploadedMediaModule;
33 contentModule = new ModuleContent(DatabaseContent.getInstance());
34 topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
35 linksImcsModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
36 schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
37 featureModule = new ModuleFeature(DatabaseFeature.getInstance());
38 imageModule = new ModuleImages(DatabaseImages.getInstance());
39 uploadedMediaModule = new ModuleUploadedMedia(DatabaseImages.getInstance());
41 catch(StorageObjectException e)
43 System.err.println("*** failed to initialize Producer " + e.toString());
47 public void handle(PrintWriter htmlout, EntityUsers user)
48 throws StorageObjectException, ModuleException {
49 handle(htmlout,user,false,false);
52 abstract public void handle(PrintWriter htmlout, EntityUsers user, boolean forced, boolean sync)
53 throws StorageObjectException, ModuleException;
56 // Methods for producing files
58 public boolean produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
59 return _produce(template, filename, model, htmlout, false);
62 public boolean produce_compressed(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
63 return _produce(template, filename, model, htmlout, true);
66 private boolean _produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout, boolean compressed) {
68 File f = new File(producerStorageRoot + filename);
69 File dir = new File(f.getParent());
71 FileWriter outputFile = new FileWriter(f);
72 PrintWriter outStream;
73 if (compressed==true) {
74 outStream = new LineFilterWriter(outputFile);
76 outStream = new PrintWriter(outputFile);
79 HTMLTemplateProcessor.process(null,template, model, outStream);
83 printHTML(htmlout, "Produced <a href=\"" + producerProductionHost+ filename + "\">" + filename + "</a>");
84 //theLog.printInfo("Produced: " + producerStorageRoot + filename);
85 //theLog.printDebugInfo("free mem:" + java.lang.Runtime.getRuntime().freeMemory());
86 //theLog.printDebugInfo("total mem:" + java.lang.Runtime.getRuntime().totalMemory());
89 } catch(IOException exception){
90 logHTML(htmlout, "Producer: File could not be written " + filename);
92 } catch(HTMLParseException exception){
93 logHTML(htmlout,"Producer: Error in HTML-parsing: " + filename);
98 public boolean produceFile(String filename, byte[] in, PrintWriter htmlout, boolean icon) {
100 boolean retVal = false;
106 f = new File(filename);
107 theLog.printDebugInfo("image: " + filename);
109 f = new File(producerStorageRoot + filename);
110 theLog.printDebugInfo("icon: " + filename);
112 File dir = new File(f.getParent());
115 FileOutputStream outStream;
116 outStream = new FileOutputStream(f);
120 } catch(IOException exception) {
121 logHTML(htmlout, "Producer: File could not be written: " + filename);
132 public String indexFileNameForPageCount(int pc) {
133 return fileNameForPageCount("/index", pc);
136 public String fileNameForPageCount(String stub, int pc) {
137 String fileName = producerDocRoot + stub;
148 public void logHTML(PrintWriter out, String s) {
149 _print(out, s, true);
152 public void printHTML(PrintWriter out, String s) {
153 _print(out, s, false);
156 private void _print(PrintWriter out, String s, boolean log) {
157 if (out != null) { out.println(s+"<br>");out.flush(); }