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
42 public EntityList getFeatures(int offset, int limit) throws ModuleException
44 return getContent("is_published=true AND to_article_type=2", "date desc, webdb_create desc",
48 public EntityList getNewsWire(int offset, int limit) throws ModuleException
50 return getContent("is_published=true AND to_article_type = 1",
51 "date desc, webdb_create desc",offset,limit);
54 public EntityList getStartArticle() throws ModuleException
56 EntityList returnList = getContent("is_published=true AND to_article_type=4",
57 "date desc, webdb_create desc",0,1);
58 //if no startspecial exists
59 if (returnList==null || returnList.size()==0)
60 returnList = getContent("is_published=true AND to_article_type=3",
61 "date desc, webdb_create desc",0,1);
66 public EntityList getContent(HashMap searchValues, boolean concat, int offset, EntityUsers user)
67 throws ModuleException {
71 String whereClause ="", aField, aValue;
74 Set set = searchValues.keySet();
75 Iterator it = set.iterator();
76 for (int i=0;i<set.size();i++) {
77 aField = (String)it.next();
78 aValue = (String)searchValues.get(aField);
81 whereClause += (concat) ? " and " : " or ";
87 // default: hier splitten der eintraege und verknupfung mit AND OR NOT
88 StringTokenizer st = new StringTokenizer(aValue);
89 boolean firstToken = true;
90 while(st.hasMoreTokens()) {
91 String notString = "";
92 String tokenConcat = " OR ";
93 String nextToken = st.nextToken();
95 if (nextToken.startsWith("+")) {
96 nextToken = nextToken.substring(1);
97 tokenConcat = " AND ";
99 if (nextToken.startsWith("-")) {
100 nextToken = nextToken.substring(1);
101 tokenConcat = " AND ";
104 if (firstToken == true) {
110 whereClause += tokenConcat + aField + notString + " like '";
111 whereClause += nextToken + "%'";
115 return theStorage.selectByWhereClause(whereClause, offset);
117 catch (StorageObjectException e){
118 throw new ModuleException(e.toString());
123 public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
124 EntityUsers user) throws ModuleException
126 String whereClause = "lower("+aField + ") like lower('%" + StringUtil.quote(aValue) + "%')";
127 return getContent(whereClause, orderBy, offset, user);
130 public EntityList getContent(String whereClause, String orderBy, int offset,
131 int limit, EntityUsers user) throws ModuleException {
136 whereClause += " and to_publisher='" + user.getId()+"'";
138 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
140 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }
143 public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
144 throws ModuleException {
146 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
147 } catch (StorageObjectException e){
148 throw new ModuleException(e.toString());
152 public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
153 throws ModuleException
156 if (whereClause !=null) {
158 // for the different article_types
159 if(whereClause.equals("newswire")) {
160 whereClause="is_published='1' and to_article_type='1'";
161 orderBy = "webdb_create desc";
163 if(whereClause.equals("feature")) {
164 whereClause="is_published='1' and to_article_type='2'";
165 orderBy = "webdb_create desc";
167 if(whereClause.equals("themenspecial")) {
168 whereClause="is_published='1' and to_article_type='3'";
169 orderBy = "webdb_create desc";
171 if(whereClause.equals("special")) {
172 whereClause="is_published='1' and to_article_type='4'";
173 orderBy = "webdb_create desc";
176 if(whereClause.equals("comments")) {
177 whereClause="not (comment is null or comment like '')";
178 orderBy = "webdb_lastchange desc";
181 if(whereClause.equals("nfrei")) {
182 whereClause="is_published='0'"; orderBy="date desc";
185 if(whereClause.equals("lastchange")) {
186 whereClause=""; orderBy="webdb_lastchange desc";
189 if(whereClause.equals("media")) {
190 return DatabaseContentToMedia.getInstance().getContent();
193 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
195 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }