6133a1759a11639e82c6680e9097e24a6ae45f63
[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     orderBy="date desc, webdb_create desc";
52     listTemplate = MirConfig.getProp("Producer.TopicList.Template");
53
54     EntityList topicsEntityList;
55     if(where==null){
56       topicsEntityList = topicsModule.getByWhereClause("","title", -1);
57     } else {
58       topicsEntityList = topicsModule.getByWhereClause(where,"title", -1);
59     }
60
61     for(int i=0; i < topicsEntityList.size(); i++){
62
63       EntityTopics currentTopic = (EntityTopics)topicsEntityList.elementAt(i);
64
65       try {
66       EntityList contentEntityList = DatabaseContentToTopics.getInstance().getContent(currentTopic);
67       String whereClauseSpecial=null;
68
69       if (contentEntityList!=null || force==true) {
70         if (contentEntityList!=null){
71           boolean first=true;
72           whereClause="is_published='1' AND to_article_type >= 1 AND to_article_type <=2 AND id IN (";
73           whereClauseSpecial="is_published='1' AND to_article_type=3 AND id IN (";
74           for(int j=0; j < contentEntityList.size(); j++){
75             if(first==false) {
76               whereClause += ",";
77               whereClauseSpecial += ",";
78             }
79             EntityContent currentContent = (EntityContent)contentEntityList.elementAt(j);
80             whereClause += currentContent.getId();
81             whereClauseSpecial += currentContent.getId();
82
83             setAdditional("topic",currentTopic);
84
85             first = false;
86           }
87           whereClause += ")";
88           whereClauseSpecial += ")";
89         }
90
91         if(contentEntityList==null && force==true){
92           //hihi, das ist eigentlich boese
93           whereClause="is_published='1' AND to_article_type>=1 AND id IN (0)";
94         }
95
96         fileDesc = currentTopic.getValue("filename");
97
98         // get the startarticle
99         EntityList entityList = contentModule.getContent(whereClauseSpecial,"date desc, webdb_create desc",0,1);
100         String currentMediaId = null;
101         SimpleHash imageHash = new SimpleHash();
102         EntityContent currentContent;
103         if(entityList != null && entityList.size()==1){
104           currentContent = (EntityContent)entityList.elementAt(0);
105           try {
106               setAdditional("special",currentContent);
107           } catch (Exception e) {
108             theLog.printError("ProducerTopics: problem with start special media: "+currentContent.getId()+" "+e.toString()+" <font color=\"red\">skipping</font>");
109             logHTML(htmlout,"ProducerTopics: problem with start special media: "+currentContent.getId()+" "+e.toString());
110           }
111         }
112
113         //set the list of topics
114         setAdditional("topicslist",topicsEntityList);
115
116         handleIt(htmlout,user,force);
117       }
118       } catch (Exception e) {
119         theLog.printError("ProducerTopics: problem with start special media: "
120         +e.toString()+" <font color=\"red\">skipping</font>");
121         logHTML(htmlout,"ProducerTopics: problem with topic id: "
122         +currentTopic.getId()+ "<font color=\"red\">skipping</font>");
123       }
124     }
125   }
126
127   public static void main(String argv[]){
128     try {
129       new ProducerOpenPosting().handle(new PrintWriter(System.out), null,false, false);
130     } catch(Exception e) {
131       System.err.println(e.toString());
132     }
133   }
134 }