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.*;
52 * @version $Id: ModuleContent.java,v 1.10 2002/11/27 07:48:02 mh Exp $
54 * @author RK, mir-coders
58 public class ModuleContent extends AbstractModule
60 static Logfile theLog;
62 public ModuleContent() {
64 if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
67 public ModuleContent(StorageObject theStorage) {
68 this.theStorage = theStorage;
69 if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
73 // methoden, um an ContentEntities zu kommen
75 public EntityList getFeatures(int offset, int limit) throws ModuleException
77 return getContent("is_published=true AND to_article_type=2", "webdb_create desc",
81 public EntityList getNewsWire(int offset, int limit) throws ModuleException
83 return getContent("is_published=true AND to_article_type = 1",
84 "webdb_create desc",offset,limit);
87 public EntityList getStartArticle() throws ModuleException
89 EntityList returnList = getContent("is_published=true AND to_article_type=4",
90 "webdb_create desc",0,1);
91 //if no startspecial exists
92 if (returnList==null || returnList.size()==0)
93 returnList = getContent("is_published=true AND to_article_type=3",
94 "webdb_create desc",0,1);
99 public EntityList getContent(HashMap searchValues, boolean concat, int offset, EntityUsers user)
100 throws ModuleException {
104 String whereClause ="", aField, aValue;
105 boolean first = true;
107 Set set = searchValues.keySet();
108 Iterator it = set.iterator();
109 for (int i=0;i<set.size();i++) {
110 aField = (String)it.next();
111 aValue = (String)searchValues.get(aField);
114 whereClause += (concat) ? " and " : " or ";
120 // default: hier splitten der eintraege und verknupfung mit AND OR NOT
121 StringTokenizer st = new StringTokenizer(aValue);
122 boolean firstToken = true;
123 while(st.hasMoreTokens()) {
124 String notString = "";
125 String tokenConcat = " OR ";
126 String nextToken = st.nextToken();
128 if (nextToken.startsWith("+")) {
129 nextToken = nextToken.substring(1);
130 tokenConcat = " AND ";
132 if (nextToken.startsWith("-")) {
133 nextToken = nextToken.substring(1);
134 tokenConcat = " AND ";
137 if (firstToken == true) {
143 whereClause += tokenConcat + aField + notString + " like '";
144 whereClause += nextToken + "%'";
148 return theStorage.selectByWhereClause(whereClause, offset);
150 catch (StorageObjectException e){
151 throw new ModuleException(e.toString());
156 public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
157 EntityUsers user) throws ModuleException
159 String whereClause = "lower("+aField + ") like lower('%" + StringUtil.quote(aValue) + "%')";
160 return getContent(whereClause, orderBy, offset, user);
163 public EntityList getContent(String whereClause, String orderBy, int offset,
164 int limit, EntityUsers user) throws ModuleException {
169 whereClause += " and to_publisher='" + user.getId()+"'";
171 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
173 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }
176 public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
177 throws ModuleException {
179 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
180 } catch (StorageObjectException e){
181 throw new ModuleException(e.toString());
185 public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
186 throws ModuleException
189 if (whereClause !=null) {
191 // for the different article_types
192 if(whereClause.equals("newswire")) {
193 whereClause="is_published='1' and to_article_type='1'";
194 orderBy = "webdb_create desc";
196 if(whereClause.equals("feature")) {
197 whereClause="is_published='1' and to_article_type='2'";
198 orderBy = "webdb_create desc";
200 if(whereClause.equals("themenspecial")) {
201 whereClause="is_published='1' and to_article_type='3'";
202 orderBy = "webdb_create desc";
204 if(whereClause.equals("special")) {
205 whereClause="is_published='1' and to_article_type='4'";
206 orderBy = "webdb_create desc";
209 if(whereClause.equals("comments")) {
210 whereClause="not (comment is null or comment like '')";
211 orderBy = "webdb_lastchange desc";
214 if(whereClause.equals("nfrei")) {
215 whereClause="is_published='0'"; orderBy="webdb_create desc";
218 if(whereClause.equals("lastchange")) {
219 whereClause=""; orderBy="webdb_lastchange desc";
222 if(whereClause.equals("media")) {
223 return DatabaseContentToMedia.getInstance().getContent();
226 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
228 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }