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("Producer");
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());
40 } catch(StorageObjectException e) {;}
43 public void handle(PrintWriter htmlout, EntityUsers user)
44 throws StorageObjectException, ModuleException {
45 handle(htmlout,user,false,false);
48 abstract public void handle(PrintWriter htmlout, EntityUsers user, boolean forced, boolean sync)
49 throws StorageObjectException, ModuleException;
52 // Methods for producing files
54 public boolean produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
55 return _produce(template, filename, model, htmlout, false);
58 public boolean produce_compressed(String template, String filename, TemplateModelRoot model, PrintWriter htmlout) {
59 return _produce(template, filename, model, htmlout, true);
62 private boolean _produce(String template, String filename, TemplateModelRoot model, PrintWriter htmlout, boolean compressed) {
64 File f = new File(producerStorageRoot + filename);
65 File dir = new File(f.getParent());
67 FileWriter outputFile = new FileWriter(f);
68 PrintWriter outStream;
69 if (compressed==true) {
70 outStream = new LineFilterWriter(outputFile);
72 outStream = new PrintWriter(outputFile);
75 HTMLTemplateProcessor.process(null,template, model, outStream);
79 printHTML(htmlout, "Produced <a href=\"" + producerProductionHost+ filename + "\">" + filename + "</a>");
80 //theLog.printInfo("Produced: " + producerStorageRoot + filename);
81 //theLog.printDebugInfo("free mem:" + java.lang.Runtime.getRuntime().freeMemory());
82 //theLog.printDebugInfo("total mem:" + java.lang.Runtime.getRuntime().totalMemory());
85 } catch(IOException exception){
86 logHTML(htmlout, "Producer: File could not be written " + filename);
88 } catch(HTMLParseException exception){
89 logHTML(htmlout,"Producer: Error in HTML-parsing: " + filename);
94 public boolean produceFile(String filename, byte[] in, PrintWriter htmlout, boolean icon) {
96 boolean retVal = false;
102 f = new File(filename);
103 theLog.printDebugInfo("image: " + filename);
105 f = new File(producerStorageRoot + filename);
106 theLog.printDebugInfo("icon: " + filename);
108 File dir = new File(f.getParent());
111 FileOutputStream outStream;
112 outStream = new FileOutputStream(f);
116 } catch(IOException exception) {
117 logHTML(htmlout, "Producer: File could not be written: " + filename);
128 public String indexFileNameForPageCount(int pc) {
129 return fileNameForPageCount("/index", pc);
132 public String fileNameForPageCount(String stub, int pc) {
133 String fileName = producerDocRoot + stub;
144 public void logHTML(PrintWriter out, String s) {
145 _print(out, s, true);
148 public void printHTML(PrintWriter out, String s) {
149 _print(out, s, false);
152 private void _print(PrintWriter out, String s, boolean log) {
153 if (out != null) { out.println(s+"<br>");out.flush(); }