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 = Configuration.getProperty("Producer.DocRoot");
18 protected static String producerStorageRoot = Configuration.getProperty("Producer.StorageRoot");
19 protected static String producerProductionHost = Configuration.getProperty("Producer.ProductionHost");
20 protected static String producerOpenAction = Configuration.getProperty("Producer.OpenAction");;
21 protected static Logfile theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Producer.Logfile"));
22 protected static ModuleTopics topicsModule;
23 protected static ModuleSchwerpunkt schwerpunktModule;
24 protected static ModuleFeature featureModule;
25 protected static ModuleGruppen gruppenModule;
26 protected static ModuleContent contentModule;
27 protected static ModuleImages imageModule;
32 contentModule = new ModuleContent(DatabaseContent.getInstance());
33 gruppenModule = new ModuleGruppen(DatabaseGroups.getInstance());
34 topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
35 schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
36 featureModule = new ModuleFeature(DatabaseFeature.getInstance());
37 imageModule = new ModuleImages(DatabaseImages.getInstance());
38 } catch(StorageObjectException e) {;}
41 public void handle(PrintWriter htmlout, EntityUsers user)
42 throws StorageObjectException, ModuleException {
43 handle(htmlout,user,false,false);
46 abstract public void handle(PrintWriter htmlout, EntityUsers user, boolean forced, boolean sync)
47 throws StorageObjectException, ModuleException;
52 public boolean produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
53 return _produce(template, filename, model, htmlout, false);
56 public boolean produce_compressed(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
57 return _produce(template, filename, model, htmlout, true);
60 private boolean _produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout, boolean compressed) {
62 File f = new File(producerStorageRoot + filename);
63 File dir = new File(f.getParent());
65 FileWriter outputFile = new FileWriter(f);
66 PrintWriter outStream;
67 if (compressed==true) {
68 outStream = new LineFilterWriter(outputFile);
70 outStream = new PrintWriter(outputFile);
73 HTMLTemplateProcessor.process(null,template, model, outStream);
77 printHTML(htmlout, "Produced <a href=\"" + producerProductionHost+ filename + "\">" + filename + "</a>");
78 //theLog.printInfo("Produced: " + producerStorageRoot + filename);
79 //theLog.printDebugInfo("free mem:" + java.lang.Runtime.getRuntime().freeMemory());
80 //theLog.printDebugInfo("total mem:" + java.lang.Runtime.getRuntime().totalMemory());
83 } catch(IOException exception){
84 logHTML(htmlout, "Producer: File konnte nicht zum schreiben geoeffnet werden: " + filename);
86 } catch(HTMLParseException exception){
87 logHTML(htmlout,"Producer: File konnte nicht hatemelisiert werden: " + filename);
92 public boolean produceFile(String filename, byte[] in, PrintWriter htmlout, boolean icon) {
94 boolean retVal = false;
100 f = new File(filename);
101 theLog.printDebugInfo("image: " + filename);
103 f = new File(producerStorageRoot + filename);
104 theLog.printDebugInfo("icon: " + filename);
106 File dir = new File(f.getParent());
109 FileOutputStream outStream;
110 outStream = new FileOutputStream(f);
114 } catch(IOException exception) {
115 logHTML(htmlout, "Producer: File could not be written: " + filename);
126 public String indexFileNameForPageCount(int pc) {
127 return fileNameForPageCount("/index", pc);
130 public String fileNameForPageCount(String stub, int pc) {
131 String fileName = producerDocRoot + stub;
142 public void logHTML(PrintWriter out, String s) {
143 _print(out, s, true);
146 public void printHTML(PrintWriter out, String s) {
147 _print(out, s, false);
150 private void _print(PrintWriter out, String s, boolean log) {
151 if (out != null) { out.println(s+"<br>");out.flush(); }