2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
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.
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.
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
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.
32 package mircoders.module;
37 import javax.servlet.*;
38 import javax.servlet.http.*;
46 import mircoders.entity.*;
47 import mircoders.storage.*;
56 public class ModuleContent extends AbstractModule
58 static Logfile theLog;
60 public ModuleContent() {
62 if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
65 public ModuleContent(StorageObject theStorage) {
66 this.theStorage = theStorage;
67 if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
71 // methoden, um an ContentEntities zu kommen
73 public EntityList getFeatures(int offset, int limit) throws ModuleException
75 return getContent("is_published=true AND to_article_type=2", "date desc, webdb_create desc",
79 public EntityList getNewsWire(int offset, int limit) throws ModuleException
81 return getContent("is_published=true AND to_article_type = 1",
82 "date desc, webdb_create desc",offset,limit);
85 public EntityList getStartArticle() throws ModuleException
87 EntityList returnList = getContent("is_published=true AND to_article_type=4",
88 "date desc, webdb_create desc",0,1);
89 //if no startspecial exists
90 if (returnList==null || returnList.size()==0)
91 returnList = getContent("is_published=true AND to_article_type=3",
92 "date desc, webdb_create desc",0,1);
97 public EntityList getContent(HashMap searchValues, boolean concat, int offset, EntityUsers user)
98 throws ModuleException {
102 String whereClause ="", aField, aValue;
103 boolean first = true;
105 Set set = searchValues.keySet();
106 Iterator it = set.iterator();
107 for (int i=0;i<set.size();i++) {
108 aField = (String)it.next();
109 aValue = (String)searchValues.get(aField);
112 whereClause += (concat) ? " and " : " or ";
118 // default: hier splitten der eintraege und verknupfung mit AND OR NOT
119 StringTokenizer st = new StringTokenizer(aValue);
120 boolean firstToken = true;
121 while(st.hasMoreTokens()) {
122 String notString = "";
123 String tokenConcat = " OR ";
124 String nextToken = st.nextToken();
126 if (nextToken.startsWith("+")) {
127 nextToken = nextToken.substring(1);
128 tokenConcat = " AND ";
130 if (nextToken.startsWith("-")) {
131 nextToken = nextToken.substring(1);
132 tokenConcat = " AND ";
135 if (firstToken == true) {
141 whereClause += tokenConcat + aField + notString + " like '";
142 whereClause += nextToken + "%'";
146 return theStorage.selectByWhereClause(whereClause, offset);
148 catch (StorageObjectException e){
149 throw new ModuleException(e.toString());
154 public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
155 EntityUsers user) throws ModuleException
157 String whereClause = "lower("+aField + ") like lower('%" + StringUtil.quote(aValue) + "%')";
158 return getContent(whereClause, orderBy, offset, user);
161 public EntityList getContent(String whereClause, String orderBy, int offset,
162 int limit, EntityUsers user) throws ModuleException {
167 whereClause += " and to_publisher='" + user.getId()+"'";
169 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
171 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }
174 public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
175 throws ModuleException {
177 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
178 } catch (StorageObjectException e){
179 throw new ModuleException(e.toString());
183 public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
184 throws ModuleException
187 if (whereClause !=null) {
189 // for the different article_types
190 if(whereClause.equals("newswire")) {
191 whereClause="is_published='1' and to_article_type='1'";
192 orderBy = "webdb_create desc";
194 if(whereClause.equals("feature")) {
195 whereClause="is_published='1' and to_article_type='2'";
196 orderBy = "webdb_create desc";
198 if(whereClause.equals("themenspecial")) {
199 whereClause="is_published='1' and to_article_type='3'";
200 orderBy = "webdb_create desc";
202 if(whereClause.equals("special")) {
203 whereClause="is_published='1' and to_article_type='4'";
204 orderBy = "webdb_create desc";
207 if(whereClause.equals("comments")) {
208 whereClause="not (comment is null or comment like '')";
209 orderBy = "webdb_lastchange desc";
212 if(whereClause.equals("nfrei")) {
213 whereClause="is_published='0'"; orderBy="date desc";
216 if(whereClause.equals("lastchange")) {
217 whereClause=""; orderBy="webdb_lastchange desc";
220 if(whereClause.equals("media")) {
221 return DatabaseContentToMedia.getInstance().getContent();
224 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
226 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }