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 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;
44 * @version $Id: ModuleContent.java,v 1.18 2003/03/09 19:14:21 idfx Exp $
46 * @author RK, mir-coders
50 public class ModuleContent extends AbstractModule
52 static LoggerWrapper logger = new LoggerWrapper("Module.Content");
54 public ModuleContent() {
58 public ModuleContent(StorageObject theStorage) {
59 this.theStorage = theStorage;
63 // various methods to retrieve content entities
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",
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);
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);
87 public EntityList getContent(Map searchValues, boolean concat, int offset, EntityUsers user) throws ModuleException {
91 String whereClause ="", aField, aValue;
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);
101 whereClause += (concat) ? " and " : " or ";
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();
115 if (nextToken.startsWith("+")) {
116 nextToken = nextToken.substring(1);
117 tokenConcat = " AND ";
119 if (nextToken.startsWith("-")) {
120 nextToken = nextToken.substring(1);
121 tokenConcat = " AND ";
124 if (firstToken == true) {
130 whereClause += tokenConcat + aField + notString + " like '";
131 whereClause += nextToken + "%'";
135 return theStorage.selectByWhereClause(whereClause, offset);
137 catch (StorageObjectFailure e){
138 throw new ModuleException(e.toString());
144 public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
145 EntityUsers user) throws ModuleException
147 String whereClause = "lower("+aField + ") like lower('%" + JDBCStringRoutines.escapeStringLiteral(aValue) + "%')";
148 return getContent(whereClause, orderBy, offset, user);
152 public EntityList getContent(String whereClause, String orderBy, int offset,
153 int limit, EntityUsers user) throws ModuleException {
158 whereClause += " and to_publisher='" + user.getId()+"'";
160 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
162 catch (StorageObjectFailure e){ throw new ModuleException(e.toString()); }
166 public EntityList getContent(String whereClause, String orderBy,int offset, int limit) throws ModuleExc, ModuleFailure {
168 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
171 throw new ModuleFailure(e);
175 public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
176 throws ModuleException
179 if (whereClause !=null) {
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";
186 if(whereClause.equals("feature")) {
187 whereClause="is_published='1' and to_article_type='2'";
188 orderBy = "webdb_create desc";
190 if(whereClause.equals("themenspecial")) {
191 whereClause="is_published='1' and to_article_type='3'";
192 orderBy = "webdb_create desc";
194 if(whereClause.equals("special")) {
195 whereClause="is_published='1' and to_article_type='4'";
196 orderBy = "webdb_create desc";
199 if(whereClause.equals("comments")) {
200 whereClause="not (comment is null or comment like '')";
201 orderBy = "webdb_lastchange desc";
204 if(whereClause.equals("nfrei")) {
205 whereClause="is_published='0'"; orderBy="webdb_create desc";
208 if(whereClause.equals("lastchange")) {
209 whereClause=""; orderBy="webdb_lastchange desc";
212 if(whereClause.equals("media")) {
213 return DatabaseContentToMedia.getInstance().getContent();
216 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
218 catch (StorageObjectFailure e) {
219 throw new ModuleException(e.toString());