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;
38 import javax.servlet.*;
39 import javax.servlet.http.*;
49 import mircoders.entity.*;
50 import mircoders.storage.*;
55 * @version $Id: ModuleContent.java,v 1.13 2002/12/14 01:37:43 zapata Exp $
57 * @author RK, mir-coders
61 public class ModuleContent extends AbstractModule
63 static LoggerWrapper logger = new LoggerWrapper("Module.Content");
65 public ModuleContent() {
69 public ModuleContent(StorageObject theStorage) {
70 this.theStorage = theStorage;
74 // various methods to retrieve content entities
76 public EntityList getFeatures(int offset, int limit) throws ModuleException
78 return getContent("is_published=true AND to_article_type=2", "webdb_create desc",
82 public EntityList getNewsWire(int offset, int limit) throws ModuleException
84 return getContent("is_published=true AND to_article_type = 1",
85 "webdb_create desc",offset,limit);
88 public EntityList getStartArticle() throws ModuleException
90 EntityList returnList = getContent("is_published=true AND to_article_type=4",
91 "webdb_create desc",0,1);
92 //if no startspecial exists
93 if (returnList==null || returnList.size()==0)
94 returnList = getContent("is_published=true AND to_article_type=3",
95 "webdb_create desc",0,1);
100 public EntityList getContent(HashMap searchValues, boolean concat, int offset, EntityUsers user)
101 throws ModuleException {
105 String whereClause ="", aField, aValue;
106 boolean first = true;
108 Set set = searchValues.keySet();
109 Iterator it = set.iterator();
110 for (int i=0;i<set.size();i++) {
111 aField = (String)it.next();
112 aValue = (String)searchValues.get(aField);
115 whereClause += (concat) ? " and " : " or ";
121 // default: hier splitten der eintraege und verknupfung mit AND OR NOT
122 StringTokenizer st = new StringTokenizer(aValue);
123 boolean firstToken = true;
124 while(st.hasMoreTokens()) {
125 String notString = "";
126 String tokenConcat = " OR ";
127 String nextToken = st.nextToken();
129 if (nextToken.startsWith("+")) {
130 nextToken = nextToken.substring(1);
131 tokenConcat = " AND ";
133 if (nextToken.startsWith("-")) {
134 nextToken = nextToken.substring(1);
135 tokenConcat = " AND ";
138 if (firstToken == true) {
144 whereClause += tokenConcat + aField + notString + " like '";
145 whereClause += nextToken + "%'";
149 return theStorage.selectByWhereClause(whereClause, offset);
151 catch (StorageObjectException e){
152 throw new ModuleException(e.toString());
157 public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
158 EntityUsers user) throws ModuleException
160 String whereClause = "lower("+aField + ") like lower('%" + JDBCStringRoutines.escapeStringLiteral(aValue) + "%')";
161 return getContent(whereClause, orderBy, offset, user);
164 public EntityList getContent(String whereClause, String orderBy, int offset,
165 int limit, EntityUsers user) throws ModuleException {
170 whereClause += " and to_publisher='" + user.getId()+"'";
172 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
174 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }
177 public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
178 throws ModuleException {
180 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
181 } catch (StorageObjectException e){
182 throw new ModuleException(e.toString());
186 public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
187 throws ModuleException
190 if (whereClause !=null) {
192 // for the different article_types
193 if(whereClause.equals("newswire")) {
194 whereClause="is_published='1' and to_article_type='1'";
195 orderBy = "webdb_create desc";
197 if(whereClause.equals("feature")) {
198 whereClause="is_published='1' and to_article_type='2'";
199 orderBy = "webdb_create desc";
201 if(whereClause.equals("themenspecial")) {
202 whereClause="is_published='1' and to_article_type='3'";
203 orderBy = "webdb_create desc";
205 if(whereClause.equals("special")) {
206 whereClause="is_published='1' and to_article_type='4'";
207 orderBy = "webdb_create desc";
210 if(whereClause.equals("comments")) {
211 whereClause="not (comment is null or comment like '')";
212 orderBy = "webdb_lastchange desc";
215 if(whereClause.equals("nfrei")) {
216 whereClause="is_published='0'"; orderBy="webdb_create desc";
219 if(whereClause.equals("lastchange")) {
220 whereClause=""; orderBy="webdb_lastchange desc";
223 if(whereClause.equals("media")) {
224 return DatabaseContentToMedia.getInstance().getContent();
227 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
229 catch (StorageObjectException e) {
230 throw new ModuleException(e.toString());