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, int limit, EntityGruppen user)
108 throws ModuleException {
112 //theLog.printInfo("user!=null admin: "+ user.getValue("admin"));
113 if (user.getValue("is_admin").equals("0"))
114 whereClause += " and to_publisher='" + user.getId()+"'";
116 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
118 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }
121 public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
122 throws ModuleException {
124 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
125 } catch (StorageObjectException e){
126 throw new ModuleException(e.toString());
130 public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
131 throws ModuleException
134 if (whereClause !=null) {
136 // for the different article_types
137 if(whereClause.equals("newswire")) {
138 whereClause="is_published='1' and to_article_type='1'";
139 orderBy = "webdb_create desc";
141 if(whereClause.equals("feature")) {
142 whereClause="is_published='1' and to_article_type='2'";
143 orderBy = "webdb_create desc";
145 if(whereClause.equals("themenspecial")) {
146 whereClause="is_published='1' and to_article_type='3'";
147 orderBy = "webdb_create desc";
149 if(whereClause.equals("special")) {
150 whereClause="is_published='1' and to_article_type='4'";
151 orderBy = "webdb_create desc";
154 if(whereClause.equals("comments")) {
155 whereClause="not (comment is null or comment like '')";
156 orderBy = "webdb_lastchange desc";
159 if(whereClause.equals("nfrei")) {
160 whereClause="is_published='0'"; orderBy="date desc";
163 if(whereClause.equals("lastchange")) {
164 whereClause=""; orderBy="webdb_lastchange desc";
167 if(whereClause.equals("media")) {
168 return DatabaseContentToMedia.getInstance().getContent();
171 return theStorage.selectByWhereClause(whereClause, orderBy, offset);
173 catch (StorageObjectException e){ throw new ModuleException(e.toString()); }