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