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;
34 import java.util.Iterator;
37 import java.util.StringTokenizer;
39 import mir.entity.EntityList;
40 import mir.log.LoggerWrapper;
41 import mir.module.AbstractModule;
42 import mir.module.ModuleExc;
43 import mir.module.ModuleFailure;
44 import mir.storage.StorageObject;
45 import mir.storage.StorageObjectFailure;
46 import mir.util.JDBCStringRoutines;
47 import mircoders.entity.EntityUsers;
48 import mircoders.storage.DatabaseContentToMedia;
53 * @version $Id: ModuleContent.java,v 1.17 2003/03/09 03:53:11 zapata Exp $
55 * @author RK, mir-coders
59 public class ModuleContent extends AbstractModule
61 static LoggerWrapper logger = new LoggerWrapper("Module.Content");
63 public ModuleContent() {
67 public ModuleContent(StorageObject theStorage) {
68 this.theStorage = theStorage;
72 // various methods to retrieve content entities
74 // public EntityList getFeatures(int offset, int limit) throws ModuleExc, ModuleFailure {
75 // return getContent("is_published=true AND to_article_type=2", "webdb_create desc",
79 // public EntityList getNewsWire(int offset, int limit) throws ModuleExc, ModuleFailure {
80 // return getContent("is_published=true AND to_article_type = 1",
81 // "webdb_create desc",offset,limit);
84 // public EntityList getStartArticle() throws ModuleExc, ModuleFailure {
85 // EntityList returnList = getContent("is_published=true AND to_article_type=4",
86 // "webdb_create desc",0,1);
87 //if no startspecial exists
88 // if (returnList==null || returnList.size()==0)
89 // returnList = getContent("is_published=true AND to_article_type=3",
90 // "webdb_create desc",0,1);
96 public EntityList getContent(Map searchValues, boolean concat, int offset, EntityUsers user) throws ModuleException {
100 String whereClause ="", aField, aValue;
101 boolean first = true;
103 Set set = searchValues.keySet();
104 Iterator it = set.iterator();
105 for (int i=0;i<set.size();i++) {
106 aField = (String)it.next();
107 aValue = (String)searchValues.get(aField);
110 whereClause += (concat) ? " and " : " or ";
116 // default: hier splitten der eintraege und verknupfung mit AND OR NOT
117 StringTokenizer st = new StringTokenizer(aValue);
118 boolean firstToken = true;
119 while(st.hasMoreTokens()) {
120 String notString = "";
121 String tokenConcat = " OR ";
122 String nextToken = st.nextToken();
124 if (nextToken.startsWith("+")) {
125 nextToken = nextToken.substring(1);
126 tokenConcat = " AND ";
128 if (nextToken.startsWith("-")) {
129 nextToken = nextToken.substring(1);
130 tokenConcat = " AND ";
133 if (firstToken == true) {
139 whereClause += tokenConcat + aField + notString + " like '";
140 whereClause += nextToken + "%'";
144 return theStorage.selectByWhereClause(whereClause, offset);
146 catch (StorageObjectFailure e){
147 throw new ModuleException(e.toString());
153 public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
154 EntityUsers user) throws ModuleException
156 String whereClause = "lower("+aField + ") like lower('%" + JDBCStringRoutines.escapeStringLiteral(aValue) + "%')";
157 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 (StorageObjectFailure e){ throw new ModuleException(e.toString()); }
175 public EntityList getContent(String whereClause, String orderBy,int offset, int limit) throws ModuleExc, ModuleFailure {
177 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
180 throw new ModuleFailure(e);
184 public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
185 throws ModuleException
188 if (whereClause !=null) {
190 // for the different article_types
191 if(whereClause.equals("newswire")) {
192 whereClause="is_published='1' and to_article_type='1'";
193 orderBy = "webdb_create desc";
195 if(whereClause.equals("feature")) {
196 whereClause="is_published='1' and to_article_type='2'";
197 orderBy = "webdb_create desc";
199 if(whereClause.equals("themenspecial")) {
200 whereClause="is_published='1' and to_article_type='3'";
201 orderBy = "webdb_create desc";
203 if(whereClause.equals("special")) {
204 whereClause="is_published='1' and to_article_type='4'";
205 orderBy = "webdb_create desc";
208 if(whereClause.equals("comments")) {
209 whereClause="not (comment is null or comment like '')";
210 orderBy = "webdb_lastchange desc";
213 if(whereClause.equals("nfrei")) {
214 whereClause="is_published='0'"; orderBy="webdb_create desc";
217 if(whereClause.equals("lastchange")) {
218 whereClause=""; orderBy="webdb_lastchange desc";
221 if(whereClause.equals("media")) {
222 return DatabaseContentToMedia.getInstance().getContent();
225 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
227 catch (StorageObjectFailure e) {
228 throw new ModuleException(e.toString());