1 package mircoders.module;
6 import javax.servlet.*;
7 import javax.servlet.http.*;
9 import webdb.servlet.*;
10 import webdb.module.*;
11 import webdb.entity.*;
13 import webdb.storage.*;
24 public class ModuleContent extends AbstractModule
26 static Logfile theLog;
28 public ModuleContent() {
30 if (theLog == null) theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Module.Content.Logfile"));
33 public ModuleContent(StorageObject theStorage) {
34 this.theStorage = theStorage;
35 if (theLog == null) theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Module.Content.Logfile"));
39 // methoden, um an ContentEntities zu kommen
42 public EntityList getContent(HashMap searchValues, boolean concat, int offset, EntityUsers user)
43 throws ModuleException {
47 String whereClause ="", aField, aValue;
50 Set set = searchValues.keySet();
51 Iterator it = set.iterator();
52 for (int i=0;i<set.size();i++) {
53 aField = (String)it.next();
54 aValue = (String)searchValues.get(aField);
57 whereClause += (concat) ? " and " : " or ";
63 // default: hier splitten der eintraege und verknupfung mit AND OR NOT
64 StringTokenizer st = new StringTokenizer(aValue);
65 boolean firstToken = true;
66 while(st.hasMoreTokens()) {
67 String notString = "";
68 String tokenConcat = " OR ";
69 String nextToken = st.nextToken();
71 if (nextToken.startsWith("+")) {
72 nextToken = nextToken.substring(1);
73 tokenConcat = " AND ";
75 if (nextToken.startsWith("-")) {
76 nextToken = nextToken.substring(1);
77 tokenConcat = " AND ";
80 if (firstToken == true) {
86 whereClause += tokenConcat + aField + notString + " like '";
87 whereClause += nextToken + "%'";
91 return theStorage.selectByWhereClause(whereClause, offset);
93 catch (StorageObjectException e){
94 throw new ModuleException(e.toString());
99 public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
100 EntityUsers user) throws ModuleException
102 String whereClause = "lower("+aField + ") like lower('%" + StringUtil.quote(aValue) + "%')";
103 return getContent(whereClause, orderBy, offset, user);
106 public EntityList getContent(String whereClause, String orderBy, int offset, int limit, EntityGruppen user)
107 throws ModuleException {
111 //theLog.printInfo("user!=null admin: "+ user.getValue("admin"));
112 if (user.getValue("is_admin").equals("0"))
113 whereClause += " and to_publisher='" + user.getId()+"'";
115 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
117 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }
120 public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
121 throws ModuleException {
123 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
124 } catch (StorageObjectException e){
125 throw new ModuleException(e.toString());
129 public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
130 throws ModuleException
133 if (whereClause !=null) {
135 // for the different article_types
136 if(whereClause.equals("newswire")) {
137 whereClause="is_published='1' and to_article_type='1'";
138 orderBy = "webdb_create desc";
140 if(whereClause.equals("feature")) {
141 whereClause="is_published='1' and to_article_type='2'";
142 orderBy = "webdb_create desc";
144 if(whereClause.equals("themenspecial")) {
145 whereClause="is_published='1' and to_article_type='3'";
146 orderBy = "webdb_create desc";
148 if(whereClause.equals("special")) {
149 whereClause="is_published='1' and to_article_type='4'";
150 orderBy = "webdb_create desc";
153 if(whereClause.equals("comments")) {
154 whereClause="not (comment is null or comment like '')";
155 orderBy = "webdb_lastchange desc";
158 if(whereClause.equals("nfrei")) {
159 whereClause="is_published='0'"; orderBy="date desc";
162 if(whereClause.equals("lastchange")) {
163 whereClause=""; orderBy="webdb_lastchange desc";
166 if(whereClause.equals("media")) {
167 whereClause="to_media > 0"; orderBy="webdb_lastchange desc";
170 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
172 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }