847ac08e8e98ca5cd495694325072b89791a9fea
[mir.git] / source / mircoders / producer / ProducerTopics.java
1 package mircoders.producer;
2
3 import java.io.*;
4 import java.lang.*;
5 import java.lang.reflect.*;
6 import java.util.*;
7 import java.sql.*;
8
9 import freemarker.template.*;
10
11 import mir.misc.*;
12 import mir.media.*;
13 import mir.storage.*;
14 import mir.module.*;
15 import mir.entity.*;
16
17 import mircoders.entity.*;
18 import mircoders.storage.*;
19
20
21
22 public class ProducerTopics extends ProducerList {
23
24   public String where;
25   String              currentMediaId;
26   EntityList          upMediaEntityList;
27   EntityList          imageEntityList;
28   EntityList          currentMediaList;
29   Entity              mediaType;
30   EntityMedia         uploadedMedia;
31   Class               mediaHandlerClass=null;
32   MirMedia            mediaHandler=null;
33   String              mediaHandlerName=null;
34   Database            mediaStorage=null;
35   String              tinyIcon;
36   String              iconAlt;
37
38   public void setAdditional(String key, TemplateModel value) {
39     additional.put(key,value);
40   }
41
42   public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync, String id)
43     throws StorageObjectException, ModuleException {
44     where=id;
45     handle(htmlout,user,force,sync);
46   }
47
48   public void handle(PrintWriter htmlout, EntityUsers user, boolean force, boolean sync)
49     throws StorageObjectException, ModuleException
50   {
51     long startTime = System.currentTimeMillis();
52     int pageCount =0;
53     logHTML(htmlout, "Producer.List: started");
54
55     /** @todo should be done in static */
56     listTemplate = MirConfig.getProp("Producer.TopicList.Template");
57
58     orderBy="date desc, webdb_create desc";
59     EntityList topicsEntityList;
60     if(where==null){
61       topicsEntityList = topicsModule.getByWhereClause("","title", -1);
62     } else {
63       topicsEntityList = topicsModule.getByWhereClause(where,"title", -1);
64     }
65
66     for(int i=0; i < topicsEntityList.size(); i++){
67
68       EntityTopics currentTopic = (EntityTopics)topicsEntityList.elementAt(i);
69
70       try {
71       EntityList contentEntityList = DatabaseContentToTopics.getInstance().getContent(currentTopic);
72       String whereClauseSpecial=null;
73
74       if (contentEntityList!=null || force==true) {
75         if (contentEntityList!=null){
76           boolean first=true;
77           whereClause="is_published='1' AND to_article_type >= 1 AND to_article_type <=2 AND id IN (";
78           whereClauseSpecial="is_published='1' AND to_article_type=3 AND id IN (";
79           for(int j=0; j < contentEntityList.size(); j++){
80             if(first==false) {
81               whereClause += ",";
82               whereClauseSpecial += ",";
83             }
84             EntityContent currentContent = (EntityContent)contentEntityList.elementAt(j);
85             whereClause += currentContent.getId();
86             whereClauseSpecial += currentContent.getId();
87
88             setAdditional("topic",currentTopic);
89
90             first = false;
91           }
92           whereClause += ")";
93           whereClauseSpecial += ")";
94         }
95
96         if(contentEntityList==null && force==true){
97           //hihi, das ist eigentlich boese
98           whereClause="is_published='1' AND to_article_type>=1 AND id IN (0)";
99         }
100
101         fileDesc = currentTopic.getValue("filename");
102
103         // get the startarticle
104         EntityList entityList = contentModule.getContent(whereClauseSpecial,"date desc, webdb_create desc",0,1);
105         String currentMediaId = null;
106         SimpleHash imageHash = new SimpleHash();
107         EntityContent currentContent;
108         if(entityList != null && entityList.size()==1){
109           currentContent = (EntityContent)entityList.elementAt(0);
110           try {
111               setAdditional("special",currentContent);
112           } catch (Exception e) {
113             theLog.printError("ProducerTopics: problem with start special media: "+currentContent.getId()+" "+e.toString()+" <font color=\"red\">skipping</font>");
114             logHTML(htmlout,"ProducerTopics: problem with start special media: "+currentContent.getId()+" "+e.toString());
115           }
116         }
117
118         //set the list of topics
119         setAdditional("topicslist",topicsEntityList);
120
121         handleIt(htmlout,user,force);
122         pageCount++;
123       }
124       } catch (Exception e) {
125         theLog.printError("ProducerTopics: problem with start special media: "
126         +e.toString()+" <font color=\"red\">skipping</font>");
127         logHTML(htmlout,"ProducerTopics: problem with topic id: "
128         +currentTopic.getId()+ "<font color=\"red\">skipping</font>");
129       }
130     }
131     logHTMLFinish(htmlout, "Topics", pageCount, startTime, System.currentTimeMillis());
132   }
133
134   public static void main(String argv[]){
135     try {
136       new ProducerOpenPosting().handle(new PrintWriter(System.out), null,false, false);
137     } catch(Exception e) {
138       System.err.println(e.toString());
139     }
140   }
141 }