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