--- /dev/null
+package mircoders.module;
+
+import java.io.*;
+import java.util.*;
+import java.sql.*;
+import javax.servlet.*;
+import javax.servlet.http.*;
+
+import webdb.servlet.*;
+import webdb.module.*;
+import webdb.entity.*;
+import webdb.misc.*;
+import webdb.storage.*;
+
+import mir.entity.*;
+
+/*
+ * ContentObjekt -
+ *
+ *
+ * @author RK
+ */
+
+public class ModuleContent extends AbstractModule
+{
+ static Logfile theLog;
+
+ public ModuleContent() {
+ super();
+ if (theLog == null) theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Module.Content.Logfile"));
+ }
+
+ public ModuleContent(StorageObject theStorage) {
+ this.theStorage = theStorage;
+ if (theLog == null) theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("Module.Content.Logfile"));
+ }
+
+ //
+ // methoden, um an ContentEntities zu kommen
+
+
+ public EntityList getContent(HashMap searchValues, boolean concat, int offset, EntityUsers user)
+ throws ModuleException {
+
+ try {
+
+ String whereClause ="", aField, aValue;
+ boolean first = true;
+
+ Set set = searchValues.keySet();
+ Iterator it = set.iterator();
+ for (int i=0;i<set.size();i++) {
+ aField = (String)it.next();
+ aValue = (String)searchValues.get(aField);
+
+ if (first == false)
+ whereClause += (concat) ? " and " : " or ";
+ else
+ first = false;
+
+ whereClause += "(";
+
+ // default: hier splitten der eintraege und verknupfung mit AND OR NOT
+ StringTokenizer st = new StringTokenizer(aValue);
+ boolean firstToken = true;
+ while(st.hasMoreTokens()) {
+ String notString = "";
+ String tokenConcat = " OR ";
+ String nextToken = st.nextToken();
+
+ if (nextToken.startsWith("+")) {
+ nextToken = nextToken.substring(1);
+ tokenConcat = " AND ";
+ }
+ if (nextToken.startsWith("-")) {
+ nextToken = nextToken.substring(1);
+ tokenConcat = " AND ";
+ notString = " NOT ";
+ }
+ if (firstToken == true) {
+ tokenConcat = "";
+ firstToken = false;
+ }
+
+
+ whereClause += tokenConcat + aField + notString + " like '";
+ whereClause += nextToken + "%'";
+ }
+ whereClause += ") ";
+ }
+ return theStorage.selectByWhereClause(whereClause, offset);
+ }
+ catch (StorageObjectException e){
+ throw new ModuleException(e.toString());
+ }
+
+ }
+
+ public EntityList getContentByField(String aField, String aValue, String orderBy, int offset,
+ EntityUsers user) throws ModuleException
+ {
+ String whereClause = "lower("+aField + ") like lower('%" + StringUtil.quote(aValue) + "%')";
+ return getContent(whereClause, orderBy, offset, user);
+ }
+
+ public EntityList getContent(String whereClause, String orderBy, int offset, int limit, EntityGruppen user)
+ throws ModuleException {
+
+ try {
+ if (user!=null){
+ //theLog.printInfo("user!=null admin: "+ user.getValue("admin"));
+ if (user.getValue("is_admin").equals("0"))
+ whereClause += " and to_publisher='" + user.getId()+"'";
+ }
+ return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
+ }
+ catch (StorageObjectException e){ throw new ModuleException(e.toString()); }
+ }
+
+ public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
+ throws ModuleException {
+ try {
+ return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
+ } catch (StorageObjectException e){
+ throw new ModuleException(e.toString());
+ }
+ }
+
+ public EntityList getContent(String whereClause, String orderBy, int offset, EntityUsers user)
+ throws ModuleException
+ {
+ try {
+ if (whereClause !=null) {
+
+ // for the different article_types
+ if(whereClause.equals("newswire")) {
+ whereClause="is_published='1' and to_article_type='1'";
+ orderBy = "webdb_create desc";
+ }
+ if(whereClause.equals("feature")) {
+ whereClause="is_published='1' and to_article_type='2'";
+ orderBy = "webdb_create desc";
+ }
+ if(whereClause.equals("themenspecial")) {
+ whereClause="is_published='1' and to_article_type='3'";
+ orderBy = "webdb_create desc";
+ }
+ if(whereClause.equals("special")) {
+ whereClause="is_published='1' and to_article_type='4'";
+ orderBy = "webdb_create desc";
+ }
+
+ if(whereClause.equals("comments")) {
+ whereClause="not (comment is null or comment like '')";
+ orderBy = "webdb_lastchange desc";
+ }
+
+ if(whereClause.equals("nfrei")) {
+ whereClause="is_published='0'"; orderBy="date desc";
+ }
+
+ if(whereClause.equals("lastchange")) {
+ whereClause=""; orderBy="webdb_lastchange desc";
+ }
+
+ if(whereClause.equals("media")) {
+ whereClause="to_media > 0"; orderBy="webdb_lastchange desc";
+ }
+ }
+ return theStorage.selectByWhereClause(whereClause, orderBy, offset);
+ }
+ catch (StorageObjectException e){ throw new ModuleException(e.toString()); }
+ }
+
+
+}
+
+