af9e4ebf9d9c5aeff9c747cf1cc4355d0b875add
[mir.git] / source / mircoders / producer / TopicStartPageProducerFactory.java
1 package mircoders.producer;
2
3 import java.util.*;
4 import mir.entity.*;
5 import mir.producer.*;
6 import mir.util.*;
7 import mircoders.storage.*;
8 import mircoders.module.*;
9 import mircoders.entity.*;
10
11
12 public class TopicStartPageProducerFactory implements ProducerFactory {
13   private String generatorIdentifier;
14   private String resourceBundle;
15   private String outputFileNameExpression;
16   private int nrNewswireItems;
17   private int nrFeatures;
18
19   public TopicStartPageProducerFactory(
20     String aGeneratorIdentifier,
21     String aResourceBundle,
22     String anOutputFileNameExpression,
23     int aNrFeatures,
24     int aNrNewswireItems) {
25
26     generatorIdentifier = aGeneratorIdentifier;
27     resourceBundle = aResourceBundle;
28     outputFileNameExpression = anOutputFileNameExpression;
29     nrFeatures = aNrFeatures;
30     nrNewswireItems = aNrNewswireItems;
31   }
32
33
34   public mir.producer.Producer makeProducer(String aVerb) throws ProducerException {
35     CompositeProducer result = new CompositeProducer();
36     Map values = new HashMap();
37
38     try {
39       ModuleContent contentModule = new ModuleContent(DatabaseContent.getInstance());
40       ModuleTopics topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
41       ModuleBreaking breakingModule = new ModuleBreaking(DatabaseBreaking.getInstance());
42
43       EntityBrowser topicBrowser = new EntityBrowser(
44           DatabaseTopics.getInstance(),
45           "",
46           "",
47           100);
48
49       while (topicBrowser.hasNext()) {
50         Entity topic = (Entity) topicBrowser.next();
51         values.put("title", topic.getValue("title"));
52         values.put("filename", topic.getValue("filename"));
53         values.put("main_url", topic.getValue("main_url"));
54         values.put("archiv_url", topic.getValue("archiv_url"));
55
56
57         // ML: ok, this is way to low-level for this place:
58         String orderBy = "webdb_create desc";
59         String topicSelection = "exists (select * from content_x_topic where content_id=content.id and topic_id='"+topic.getValue("id")+"')";
60         String featureWhereClause = "is_published='1' and to_article_type='2' and "+topicSelection;
61         String newsWireWhereClause = "is_published='1' and to_article_type='1' and "+topicSelection;
62
63         result.addProducer(
64
65             //  "exists (select * from content_x_topic where content_id=content.id and topic_id="+topic.getValue("id")
66             new StartPageProducer(
67                     generatorIdentifier,
68                     resourceBundle,
69                     ParameterExpander.expandExpression(values, outputFileNameExpression),
70                     contentModule.getContent(newsWireWhereClause, orderBy, 0,nrNewswireItems),
71                     contentModule.getContent(featureWhereClause, orderBy, 0,nrFeatures),
72                     topicsModule .getTopicsList(),
73                     breakingModule.getBreakingNews()));
74       }
75
76       return result;
77
78
79     }
80     catch (Throwable e) {
81       throw new ProducerException(e);
82     }
83   };
84
85   public Iterator verbs() {
86     Vector verbList = new Vector();
87
88     verbList.add("all");
89
90     return verbList.iterator();
91   };
92 }
93