organizing imports
[mir.git] / source / mircoders / module / ModuleContent.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.module;
33
34 import mir.entity.EntityList;
35 import mir.log.LoggerWrapper;
36 import mir.module.AbstractModule;
37 import mir.module.ModuleExc;
38 import mir.module.ModuleFailure;
39 import mir.storage.StorageObject;
40
41 /*
42  *  ContentObjekt -
43  *
44  * @version $Id: ModuleContent.java,v 1.18 2003/03/09 19:14:21 idfx Exp $
45  *
46  * @author RK, mir-coders
47  *
48  */
49
50 public class ModuleContent extends AbstractModule
51 {
52   static LoggerWrapper logger = new LoggerWrapper("Module.Content");
53
54   public ModuleContent() {
55     super();
56   }
57
58   public ModuleContent(StorageObject theStorage) {
59     this.theStorage = theStorage;
60   }
61
62 //
63 // various methods to retrieve content entities
64
65 //  public EntityList getFeatures(int offset, int limit) throws ModuleExc, ModuleFailure {
66 //    return getContent("is_published=true AND to_article_type=2", "webdb_create desc",
67 //                      offset, limit);
68 //  }
69
70 //  public EntityList getNewsWire(int offset, int limit) throws ModuleExc, ModuleFailure {
71 //    return getContent("is_published=true AND to_article_type = 1",
72 //                      "webdb_create desc",offset,limit);
73 //  }
74
75 //  public EntityList getStartArticle() throws ModuleExc, ModuleFailure {
76 //    EntityList returnList = getContent("is_published=true AND to_article_type=4",
77 //                                       "webdb_create desc",0,1);
78 //if no startspecial exists
79 //    if (returnList==null || returnList.size()==0)
80 //      returnList = getContent("is_published=true AND to_article_type=3",
81 //                              "webdb_create desc",0,1);
82
83 //    return returnList;
84 //  }
85
86 /*
87       public EntityList getContent(Map searchValues, boolean concat, int offset, EntityUsers user) throws ModuleException {
88
89     try {
90
91       String whereClause ="", aField, aValue;
92       boolean first = true;
93
94       Set set = searchValues.keySet();
95       Iterator it = set.iterator();
96       for (int i=0;i<set.size();i++) {
97         aField = (String)it.next();
98         aValue = (String)searchValues.get(aField);
99
100         if (first == false)
101           whereClause +=  (concat) ? " and " : " or ";
102         else
103           first = false;
104
105         whereClause += "(";
106
107 // default: hier splitten der eintraege und verknupfung mit AND OR NOT
108         StringTokenizer st = new StringTokenizer(aValue);
109         boolean firstToken = true;
110         while(st.hasMoreTokens()) {
111           String notString = "";
112           String tokenConcat = " OR ";
113           String nextToken = st.nextToken();
114
115           if (nextToken.startsWith("+")) {
116             nextToken = nextToken.substring(1);
117             tokenConcat = " AND ";
118           }
119           if (nextToken.startsWith("-")) {
120             nextToken = nextToken.substring(1);
121             tokenConcat = " AND ";
122             notString = " NOT ";
123           }
124           if (firstToken == true) {
125             tokenConcat = "";
126             firstToken = false;
127           }
128
129
130           whereClause += tokenConcat + aField + notString + " like '";
131           whereClause += nextToken + "%'";
132         }
133         whereClause += ") ";
134       }
135       return theStorage.selectByWhereClause(whereClause, offset);
136     }
137     catch (StorageObjectFailure e){
138       throw new ModuleException(e.toString());
139     }
140
141   }
142 */
143 /*
144   public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
145                                       EntityUsers user) throws ModuleException
146   {
147     String whereClause = "lower("+aField + ") like lower('%" + JDBCStringRoutines.escapeStringLiteral(aValue) + "%')";
148     return getContent(whereClause, orderBy, offset, user);
149   }
150
151
152   public EntityList getContent(String whereClause, String orderBy, int offset,
153                                int limit, EntityUsers user) throws ModuleException {
154
155     try {
156       if (user!=null){
157         if (!user.isAdmin())
158           whereClause += " and to_publisher='" + user.getId()+"'";
159       }
160       return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
161     }
162     catch (StorageObjectFailure e){     throw new ModuleException(e.toString()); }
163   }
164 */
165
166   public EntityList getContent(String whereClause, String orderBy,int offset, int limit) throws ModuleExc, ModuleFailure {
167     try {
168       return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
169     }
170     catch (Throwable e){
171       throw new ModuleFailure(e);
172     }
173   }
174 /*
175   public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
176       throws ModuleException
177   {
178     try {
179       if (whereClause !=null) {
180
181 // for the different article_types
182         if(whereClause.equals("newswire")) {
183           whereClause="is_published='1' and to_article_type='1'";
184           orderBy = "webdb_create desc";
185         }
186         if(whereClause.equals("feature")) {
187           whereClause="is_published='1' and to_article_type='2'";
188           orderBy = "webdb_create desc";
189         }
190         if(whereClause.equals("themenspecial")) {
191           whereClause="is_published='1' and to_article_type='3'";
192           orderBy = "webdb_create desc";
193         }
194         if(whereClause.equals("special")) {
195           whereClause="is_published='1' and to_article_type='4'";
196           orderBy = "webdb_create desc";
197         }
198
199         if(whereClause.equals("comments")) {
200           whereClause="not (comment is null or comment like '')";
201           orderBy = "webdb_lastchange desc";
202         }
203
204         if(whereClause.equals("nfrei")) {
205           whereClause="is_published='0'"; orderBy="webdb_create desc";
206         }
207
208         if(whereClause.equals("lastchange")) {
209           whereClause=""; orderBy="webdb_lastchange desc";
210         }
211
212         if(whereClause.equals("media")) {
213           return DatabaseContentToMedia.getInstance().getContent();
214         }
215       }
216       return theStorage.selectByWhereClause(whereClause, orderBy, offset);
217     }
218     catch (StorageObjectFailure e) {
219       throw new ModuleException(e.toString());
220     }
221   }
222 */
223 }
224
225