package mircoders.module;
-import java.io.*;
-import java.util.*;
-import java.sql.*;
-import javax.servlet.*;
-import javax.servlet.http.*;
-
-import mir.servlet.*;
-import mir.module.*;
-import mir.entity.*;
-import mir.misc.*;
-import mir.storage.*;
-
-import mircoders.entity.*;
-import mircoders.storage.*;
-
-/*
- * ContentObjekt -
- *
- * @version $Id: ModuleContent.java,v 1.9 2002/11/04 04:35:22 mh Exp $
- *
- * @author RK
- *
- * $Log: ModuleContent.java,v $
- * Revision 1.9 2002/11/04 04:35:22 mh
- * merge media InputStream changes from MIR_1_0 branch
- *
- * Revision 1.7.4.3 2002/11/01 05:38:20 mh
- * Converted media Interface to use streams (Java IO) instead of byte buffers of
- * the entire uplaoded files. These saves loads of unecessary memory use. JAI
- * still consumes quite a bit though.
- *
- * A new temporary file (for JAI) parameter is necessary and is in the config.properties file.
- *
- * A nice side effect of this work is the FileHandler interface which is
- * basically a call back mechanism for WebdbMultipartRequest which allows the
- * uploaded file to handled by different classes. For example, for a media
- * upload, the content-type, etc.. needs to be determined, but if say the
- * FileEditor had a feature to upload static files... another handler wood be
- * needed. Right now only the MediaRequest handler exists.
- *
+import mir.entity.EntityList;
+import mir.log.LoggerWrapper;
+import mir.module.AbstractModule;
+import mir.module.ModuleExc;
+import mir.module.ModuleFailure;
+import mir.storage.StorageObject;
+
+/**
*
+ * <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
{
- static Logfile theLog;
-
- public ModuleContent() {
- super();
- if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
- }
-
- public ModuleContent(StorageObject theStorage) {
- this.theStorage = theStorage;
- if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile"));
- }
+ static LoggerWrapper logger = new LoggerWrapper("Module.Content");
- //
- // methoden, um an ContentEntities zu kommen
-
- 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 ModuleContent() {
+ super();
}
- 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 ModuleContent(StorageObject theStorage) {
+ this.theStorage = theStorage;
}
- 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(String whereClause, String orderBy,int offset, int limit) throws ModuleExc, ModuleFailure {
+ try {
+ return theStorage.selectByWhereClause(whereClause, orderBy, offset, limit);
+ }
+ catch (Throwable e){
+ throw new ModuleFailure(e);
+ }
}
-
- 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, 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 (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="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 (StorageObjectException e){ throw new ModuleException(e.toString()); }
- }
-
-
}