1 package mircoders.module;
6 import javax.servlet.*;
7 import javax.servlet.http.*;
15 import mircoders.entity.*;
16 import mircoders.storage.*;
25 public class ModuleContent extends AbstractModule
27 static Logfile theLog;
29 public ModuleContent() {
31 if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
34 public ModuleContent(StorageObject theStorage) {
35 this.theStorage = theStorage;
36 if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
40 // methoden, um an ContentEntities zu kommen
43 public EntityList getContent(HashMap searchValues, boolean concat, int offset, EntityUsers user)
44 throws ModuleException {
48 String whereClause ="", aField, aValue;
51 Set set = searchValues.keySet();
52 Iterator it = set.iterator();
53 for (int i=0;i<set.size();i++) {
54 aField = (String)it.next();
55 aValue = (String)searchValues.get(aField);
58 whereClause += (concat) ? " and " : " or ";
64 // default: hier splitten der eintraege und verknupfung mit AND OR NOT
65 StringTokenizer st = new StringTokenizer(aValue);
66 boolean firstToken = true;
67 while(st.hasMoreTokens()) {
68 String notString = "";
69 String tokenConcat = " OR ";
70 String nextToken = st.nextToken();
72 if (nextToken.startsWith("+")) {
73 nextToken = nextToken.substring(1);
74 tokenConcat = " AND ";
76 if (nextToken.startsWith("-")) {
77 nextToken = nextToken.substring(1);
78 tokenConcat = " AND ";
81 if (firstToken == true) {
87 whereClause += tokenConcat + aField + notString + " like '";
88 whereClause += nextToken + "%'";
92 return theStorage.selectByWhereClause(whereClause, offset);
94 catch (StorageObjectException e){
95 throw new ModuleException(e.toString());
100 public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
101 EntityUsers user) throws ModuleException
103 String whereClause = "lower("+aField + ") like lower('%" + StringUtil.quote(aValue) + "%')";
104 return getContent(whereClause, orderBy, offset, user);
107 public EntityList getContent(String whereClause, String orderBy, int offset,
108 int limit, EntityUsers user) throws ModuleException {
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 return DatabaseContentToMedia.getInstance().getContent();
170 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
172 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }