Added specific mp3 media handler. modified RealAudio handler to inherit from
[mir.git] / source / mircoders / module / ModuleContent.java
1 package mircoders.module;
2
3 import java.io.*;
4 import java.util.*;
5 import java.sql.*;
6 import javax.servlet.*;
7 import javax.servlet.http.*;
8
9 import mir.servlet.*;
10 import mir.module.*;
11 import mir.entity.*;
12 import mir.misc.*;
13 import mir.storage.*;
14
15 import mircoders.entity.*;
16 import mircoders.storage.*;
17
18 /*
19  *  ContentObjekt -
20  *
21  *
22  * @author RK
23  */
24
25 public class ModuleContent extends AbstractModule
26 {
27         static Logfile     theLog;
28
29         public ModuleContent() {
30                 super();
31                 if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
32         }
33
34         public ModuleContent(StorageObject theStorage) {
35                 this.theStorage = theStorage;
36                 if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
37         }
38
39         //
40         // methoden, um an ContentEntities zu kommen
41
42
43         public EntityList getContent(HashMap searchValues, boolean concat, int offset, EntityUsers user)
44                 throws ModuleException {
45
46                 try {
47
48                         String whereClause ="", aField, aValue;
49                         boolean first = true;
50
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);
56
57                         if (first == false)
58                                 whereClause +=  (concat) ? " and " : " or ";
59                         else
60                                 first = false;
61
62                         whereClause += "(";
63
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();
71
72                                 if (nextToken.startsWith("+")) {
73                                         nextToken = nextToken.substring(1);
74                                         tokenConcat = " AND ";
75                                 }
76                                 if (nextToken.startsWith("-")) {
77                                                 nextToken = nextToken.substring(1);
78                                                 tokenConcat = " AND ";
79                                                 notString = " NOT ";
80                                 }
81                                 if (firstToken == true) {
82                                         tokenConcat = "";
83                                         firstToken = false;
84                                 }
85
86
87                                 whereClause += tokenConcat + aField + notString + " like '";
88                                 whereClause += nextToken + "%'";
89                         }
90                         whereClause += ") ";
91                         }
92                         return theStorage.selectByWhereClause(whereClause, offset);
93         }
94         catch (StorageObjectException e){
95                         throw new ModuleException(e.toString());
96         }
97
98                 }
99
100         public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
101                                 EntityUsers user) throws ModuleException
102         {
103                 String whereClause = "lower("+aField + ") like lower('%" + StringUtil.quote(aValue) + "%')";
104                 return getContent(whereClause, orderBy, offset, user);
105         }
106
107         public EntityList getContent(String whereClause, String orderBy, int offset,
108     int limit, EntityUsers user) throws ModuleException {
109
110                 try {
111                         if (user!=null){
112                                 if (!user.isAdmin())
113                                         whereClause += " and to_publisher='" + user.getId()+"'";
114                                 }
115                                 return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
116                         }
117                 catch (StorageObjectException e){       throw new ModuleException(e.toString()); }
118         }
119
120         public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
121                 throws ModuleException {
122                 try {
123                         return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
124                 } catch (StorageObjectException e){
125                         throw new ModuleException(e.toString());
126                 }
127         }
128
129         public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
130                 throws ModuleException
131         {
132                 try {
133                         if (whereClause !=null) {
134
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";
139                                 }
140                                 if(whereClause.equals("feature")) {
141                                         whereClause="is_published='1' and to_article_type='2'";
142                                         orderBy = "webdb_create desc";
143                                 }
144                                 if(whereClause.equals("themenspecial")) {
145                                         whereClause="is_published='1' and to_article_type='3'";
146                                         orderBy = "webdb_create desc";
147                                 }
148                                 if(whereClause.equals("special")) {
149                                         whereClause="is_published='1' and to_article_type='4'";
150                                         orderBy = "webdb_create desc";
151                                 }
152
153                                 if(whereClause.equals("comments")) {
154                                         whereClause="not (comment is null or comment like '')";
155                                         orderBy = "webdb_lastchange desc";
156                                 }
157
158                                 if(whereClause.equals("nfrei")) {
159                                         whereClause="is_published='0'"; orderBy="date desc";
160                                 }
161
162                                 if(whereClause.equals("lastchange")) {
163                                         whereClause=""; orderBy="webdb_lastchange desc";
164                                 }
165
166                                 if(whereClause.equals("media")) {
167                                         return DatabaseContentToMedia.getInstance().getContent();
168                                 }
169                         }
170                         return theStorage.selectByWhereClause(whereClause, orderBy, offset);
171                 }
172                 catch (StorageObjectException e){       throw new ModuleException(e.toString()); }
173         }
174
175
176 }
177
178