Modified config system:
[mir.git] / source / mircoders / producer / ProducerTopics.java
1 package mircoders.producer;
2
3 import java.io.*;
4 import java.lang.*;
5 import java.util.*;
6 import java.sql.*;
7
8 import freemarker.template.*;
9
10 import mir.misc.*;
11 import mir.storage.*;
12 import mir.module.*;
13 import mir.entity.*;
14
15 import mircoders.entity.*;
16 import mircoders.storage.*;
17
18
19
20 public class ProducerTopics extends ProducerList {
21
22         public String where;
23
24         public void setAdditional(String key, TemplateModel value) {
25                 additional.put(key,value);
26         }
27
28   public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
29     throws StorageObjectException, ModuleException {
30     where=id;
31     handle(htmlout,user,force,sync);
32   }
33
34         public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
35                 throws StorageObjectException, ModuleException {
36
37                 orderBy="date desc, webdb_create desc";
38                 listTemplate = MirConfig.getProp("Producer.TopicList.Template");
39
40     EntityList topicsEntityList;
41     if(where==null){
42       topicsEntityList = topicsModule.getByWhereClause("","title", -1);
43     } else {
44       topicsEntityList = topicsModule.getByWhereClause(where,"title", -1);
45     }
46                 SimpleList topicsList = HTMLTemplateProcessor.makeSimpleList(topicsEntityList);
47
48                 for(int i=0; i < topicsEntityList.size(); i++){
49
50                         EntityTopics currentTopic = (EntityTopics)topicsEntityList.elementAt(i);
51                         EntityList contentEntityList = DatabaseContentToTopics.getInstance().getContent(currentTopic);
52       String whereClauseSpecial=null;
53
54       if (contentEntityList!=null || force==true) {
55         if (contentEntityList!=null){
56           boolean first=true;
57           whereClause="is_published='1' AND to_article_type >= 1 AND to_article_type <=2 AND id IN (";
58           whereClauseSpecial="is_published='1' AND to_article_type=3 AND id IN (";
59           for(int j=0; j < contentEntityList.size(); j++){
60             if(first==false) {
61               whereClause += ",";
62               whereClauseSpecial += ",";
63             }
64             EntityContent currentContent = (EntityContent)contentEntityList.elementAt(j);
65             whereClause += currentContent.getId();
66             whereClauseSpecial += currentContent.getId();
67
68             setAdditional("topic",HTMLTemplateProcessor.makeSimpleHash(currentTopic));
69
70             first = false;
71           }
72           whereClause += ")";
73           whereClauseSpecial += ")";
74         }
75
76         if(contentEntityList==null && force==true){
77           //hihi, das ist eigentlich boese
78           whereClause="is_published='1' AND to_article_type>=1 AND id IN (0)";
79         }
80
81         fileDesc = currentTopic.getValue("filename");
82
83         // get the startarticle
84         EntityList entityList = contentModule.getContent(whereClauseSpecial,"date desc, webdb_create desc",0,1);
85         SimpleList specialList = HTMLTemplateProcessor.makeSimpleList(entityList);
86         String currentMediaId = null;
87         SimpleHash imageHash = new SimpleHash();
88         EntityContent currentContent;
89         if(entityList != null){
90           for (int k=0; k < entityList.size();k++) {
91             currentContent = (EntityContent)entityList.elementAt(k);
92             currentMediaId = currentContent.getValue("to_media");
93             if (currentMediaId!=null && !currentMediaId.equals("")) {
94               imageHash.put(currentMediaId, HTMLTemplateProcessor.makeSimpleHash(imageModule.getById(currentMediaId)));
95             }
96           }
97           setAdditional("specialimage",imageHash);
98         }
99         setAdditional("special",specialList);
100
101         //set the list of topics
102         setAdditional("topicslist",topicsList);
103
104         handleIt(htmlout,user,force);
105       }
106     }
107         }
108
109         public static void main(String argv[]){
110                 try {
111                         new ProducerOpenPosting().handle(new PrintWriter(System.out), null,false, false);
112                 } catch(Exception e) {
113                         System.err.println(e.toString());
114                 }
115         }
116 }