2cc84bdad3924c2a4f2690c193b37fb73243146a
[mir.git] / source / mircoders / producer / ProducerAll.java
1 /*
2  * Copyright (C) 2001, 2002  The Mir-coders group
3  *
4  * This file is part of Mir.
5  *
6  * Mir is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * Mir is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Mir; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  * In addition, as a special exception, The Mir-coders gives permission to link
21  * the code of this program with the com.oreilly.servlet library, any library
22  * licensed under the Apache Software License, The Sun (tm) Java Advanced
23  * Imaging library (JAI), The Sun JIMI library (or with modified versions of
24  * the above that use the same license as the above), and distribute linked
25  * combinations including the two.  You must obey the GNU General Public
26  * License in all respects for all of the code used other than the above
27  * mentioned libraries.  If you modify this file, you may extend this exception
28  * to your version of the file, but you are not obligated to do so.  If you do
29  * not wish to do so, delete this exception statement from your version.
30  */
31
32 package mircoders.producer;
33
34 import java.io.*;
35 import java.lang.*;
36 import java.util.*;
37
38 import freemarker.template.*;
39
40 import mir.misc.*;
41 import mir.storage.*;
42 import mir.module.*;
43 import mir.entity.*;
44
45 import mircoders.module.*;
46 import mircoders.entity.*;
47 import mircoders.storage.*;
48
49
50 public class ProducerAll extends Producer{
51
52         private boolean rsync;
53
54         public static void main(String argv[])
55         {
56                 try {   new ProducerAll().handle(new PrintWriter(System.out), null, false,false);       }
57                 catch(Exception e) { System.err.println(e.toString()); }
58         }
59
60         // handle all
61         public void handle(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
62     {
63                 printHTML(htmlout, "Producer.All: started");
64
65                 long                sessionConnectTime = 0;
66                 long                startTime = (new java.util.Date()).getTime();
67     
68         try {
69             new ProducerImages().handle(htmlout, user, force,sync);
70         } catch (Exception e) {
71             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
72                 +" in ProducerImages continuing "+ e.toString());
73         }
74         try {
75             new ProducerAudio().handle(htmlout, user, force,sync);
76         } catch (Exception e) {
77             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
78                 +" in ProducerAudio continuing "+ e.toString());
79         }
80         try {
81             new ProducerVideo().handle(htmlout, user, force,sync);
82         } catch (Exception e) {
83             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
84                 +" in ProducerVideo continuing "+ e.toString());
85         }
86         try {
87             new ProducerOther().handle(htmlout, user, force,sync);
88         } catch (Exception e) {
89             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
90                 +" in ProducerOther continuing "+ e.toString());
91         }
92         try {
93             new ProducerStartPage().handle(htmlout, user, force,sync);
94         } catch (Exception e) {
95             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
96                 +" in Producer.StartPage continuing "+ e.toString());
97         }
98         try {
99             new ProducerContent().handle(htmlout, user, force,sync);
100         } catch (Exception e) {
101             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
102                 +" in Producer.Content continuing "+ e.toString());
103         }
104         try {
105             new ProducerOpenPosting().handle(htmlout, user, force,sync);
106         } catch (Exception e) {
107             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
108                 +" in Producer.OpenPosting continuing "+ e.toString());
109         }
110         try {
111             new ProducerTopics().handle(htmlout, user, force,sync);
112         } catch (Exception e) {
113             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
114                 +" in Producer.Topics continuing "+ e.toString());
115         }
116         try {
117             new ProducerNavigation().handle(htmlout, user, force,sync);
118         } catch (Exception e) {
119             logHTML(htmlout, "Producer.All <font color=\"red\">ERROR:</font>"
120                 +" in Producer.Navigation continuing "+ e.toString());
121         }
122
123                 // Finish
124                 sessionConnectTime = new java.util.Date().getTime() - startTime;
125                 logHTML(htmlout, "Producer.All finished: " + sessionConnectTime + " ms.");
126
127                 // do we have to rsync the site
128                 if (sync==true){
129                         sessionConnectTime = 0;
130                         if (Helper.rsync()!=0){
131                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
132                                 logHTML(htmlout, "Rsync failed: " + sessionConnectTime + " ms.");
133                         } else {
134                                 sessionConnectTime = new java.util.Date().getTime() - startTime;
135                                 logHTML(htmlout, "Rsync succeded: " + sessionConnectTime + " ms.");
136                         }
137                 }
138         }
139
140         // handle all
141         public void handle2(PrintWriter htmlout, EntityUsers user, boolean force,boolean sync)
142                 throws StorageObjectException, ModuleException {
143                 printHTML(htmlout, "Producer.All: started");
144
145                 long                sessionConnectTime = 0;
146                 long                startTime = (new java.util.Date()).getTime();
147                 EntityContent   currentContent;
148
149                 //get all new unproduced content-entities
150                 String whereClause="is_produced='0' && to_article_type>0";
151                 String orderBy="date desc";
152                 EntityList entityList = contentModule.getContent(whereClause,orderBy,0,-1,null);
153
154                 //get their values
155                 while (entityList != null) {
156                         for(int i=0;i<entityList.size();i++) {
157                                 currentContent = (EntityContent)entityList.elementAt(i);
158                                 EntityList topicEntityList = DatabaseContentToTopics.getInstance().getTopics(currentContent);
159                                 SimpleHash topicHash = HTMLTemplateProcessor.makeSimpleHash(topicEntityList);
160
161                                 try {
162                                         //check if this content item is related to a topic
163                                         if(currentContent.getId().equals(topicHash.get("content_id"))){
164                                                 // produce the ToicsList
165                                                 new ProducerTopics().handle(htmlout, user, force,sync,topicHash.get("topic_id").toString());
166                                         }
167                                 } catch (TemplateModelException e) {
168                                         logHTML(htmlout, e.toString());
169                                 }
170                         }
171                 }
172
173                 new ProducerContent().handle(htmlout, user, force,sync);
174                 new ProducerOpenPosting().handle(htmlout, user, force,sync);
175                 new ProducerStartPage().handle(htmlout, user, force,sync);
176                 new ProducerTopics().handle(htmlout, user, force,sync);
177
178                 // Finish
179                 sessionConnectTime = new java.util.Date().getTime() - startTime;
180                 logHTML(htmlout, "Producer.All finished: " + sessionConnectTime + " ms.");
181         }
182 }
183