package mircoders.module;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
import mir.entity.EntityList;
import mir.log.LoggerWrapper;
import mir.module.AbstractModule;
-import mir.module.ModuleException;
+import mir.module.ModuleExc;
+import mir.module.ModuleFailure;
import mir.storage.StorageObject;
-import mir.storage.StorageObjectFailure;
-import mir.util.JDBCStringRoutines;
-import mircoders.entity.EntityUsers;
-import mircoders.storage.DatabaseContentToMedia;
-/*
- * ContentObjekt -
- *
- * @version $Id: ModuleContent.java,v 1.16 2003/03/05 19:23:16 idfx Exp $
- *
- * @author RK, mir-coders
+/**
*
+ * <p>Title: ModuleContent</p>
+ * <p>Description: helper routines to manage articles</p>
+ * <p>Copyright: Copyright (c) 2003</p>
+ * <p>Company: </p>
+ * @author not attributable
+ * @version 1.0
*/
public class ModuleContent extends AbstractModule
this.theStorage = theStorage;
}
-//
-// various methods to retrieve content entities
-
- public EntityList getFeatures(int offset, int limit) throws ModuleException
- {
- return getContent("is_published=true AND to_article_type=2", "webdb_create desc",
- offset, limit);
- }
-
- public EntityList getNewsWire(int offset, int limit) throws ModuleException
- {
- return getContent("is_published=true AND to_article_type = 1",
- "webdb_create desc",offset,limit);
- }
-
- public EntityList getStartArticle() throws ModuleException
- {
- EntityList returnList = getContent("is_published=true AND to_article_type=4",
- "webdb_create desc",0,1);
-//if no startspecial exists
- if (returnList==null || returnList.size()==0)
- returnList = getContent("is_published=true AND to_article_type=3",
- "webdb_create desc",0,1);
-
- return returnList;
- }
-
- public EntityList getContent(Map 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 (StorageObjectFailure 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('%" + JDBCStringRoutines.escapeStringLiteral(aValue) + "%')";
- return getContent(whereClause, orderBy, offset, user);
- }
-
- public EntityList getContent(String whereClause, String orderBy, int offset,
- int limit, EntityUsers user) throws ModuleException {
-
- try {
- if (user!=null){
- if (!user.isAdmin())
- whereClause += " and to_publisher='" + user.getId()+"'";
- }
- return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
- }
- catch (StorageObjectFailure e){ throw new ModuleException(e.toString()); }
- }
-
- public EntityList getContent(String whereClause, String orderBy,int offset, int limit)
- throws ModuleException {
+ public EntityList getContent(String whereClause, String orderBy,int offset, int limit) throws ModuleExc, ModuleFailure {
try {
return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
- } catch (StorageObjectFailure 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="webdb_create desc";
- }
-
- if(whereClause.equals("lastchange")) {
- whereClause=""; orderBy="webdb_lastchange desc";
- }
-
- if(whereClause.equals("media")) {
- return DatabaseContentToMedia.getInstance().getContent();
- }
- }
- return theStorage.selectByWhereClause(whereClause, orderBy, offset);
}
- catch (StorageObjectFailure e) {
- throw new ModuleException(e.toString());
+ catch (Throwable e){
+ throw new ModuleFailure(e);
}
}
}