From 97a33333e6920e0b2578e506475f04c6d1d45a38 Mon Sep 17 00:00:00 2001 From: zapata Date: Fri, 29 Nov 2002 13:43:41 +0000 Subject: [PATCH] - all servletmodules and all modules now use log4j for logging - preparing ServletModuleContent for some localization - some minor general maintenance --- source/mir/module/AbstractModule.java | 300 ++++++++-------- source/mir/servlet/ServletModule.java | 16 +- source/mir/servlet/ServletModuleDispatch.java | 8 +- source/mir/util/GeneratorHTMLFunctions.java | 3 +- source/mir/util/HTMLRoutines.java | 7 + .../basic/MirBasicDataModelLocalizer.java | 16 + source/mircoders/module/ModuleBreaking.java | 24 +- source/mircoders/module/ModuleComment.java | 18 +- source/mircoders/module/ModuleContent.java | 290 ++++++++-------- source/mircoders/module/ModuleFeature.java | 30 +- source/mircoders/module/ModuleImages.java | 35 +- source/mircoders/module/ModuleLanguage.java | 18 +- source/mircoders/module/ModuleLinksImcs.java | 22 +- source/mircoders/module/ModuleMediafolder.java | 32 +- source/mircoders/module/ModuleMessage.java | 26 +- source/mircoders/module/ModuleSchwerpunkt.java | 32 +- source/mircoders/module/ModuleTopics.java | 15 +- source/mircoders/module/ModuleUploadedMedia.java | 15 +- source/mircoders/module/ModuleUsers.java | 86 +++-- source/mircoders/servlet/ServletHelper.java | 51 +++ source/mircoders/servlet/ServletModuleAudio.java | 8 +- .../mircoders/servlet/ServletModuleBreaking.java | 94 ++--- source/mircoders/servlet/ServletModuleComment.java | 9 +- source/mircoders/servlet/ServletModuleContent.java | 318 +++++++---------- .../mircoders/servlet/ServletModuleFileEdit.java | 83 ++--- source/mircoders/servlet/ServletModuleHidden.java | 135 ++++---- source/mircoders/servlet/ServletModuleImages.java | 13 +- .../mircoders/servlet/ServletModuleLanguage.java | 17 +- .../mircoders/servlet/ServletModuleLinksImcs.java | 20 +- .../servlet/ServletModuleMediafolder.java | 54 +-- source/mircoders/servlet/ServletModuleMessage.java | 110 +++--- .../mircoders/servlet/ServletModuleOpenIndy.java | 385 ++++++++++----------- .../mircoders/servlet/ServletModuleOtherMedia.java | 12 +- .../mircoders/servlet/ServletModuleProducer.java | 10 +- .../servlet/ServletModuleSchwerpunkt.java | 29 +- source/mircoders/servlet/ServletModuleTopics.java | 25 +- .../servlet/ServletModuleUploadedMedia.java | 23 +- source/mircoders/servlet/ServletModuleUsers.java | 95 ++--- source/mircoders/servlet/ServletModuleVideo.java | 6 +- 39 files changed, 1246 insertions(+), 1244 deletions(-) create mode 100755 source/mircoders/servlet/ServletHelper.java diff --git a/source/mir/module/AbstractModule.java b/source/mir/module/AbstractModule.java index 7a945429..a7d195b9 100755 --- a/source/mir/module/AbstractModule.java +++ b/source/mir/module/AbstractModule.java @@ -52,171 +52,171 @@ import mir.entity.*; */ public class AbstractModule { - protected StorageObject theStorage; + protected StorageObject theStorage; public void setStorage(StorageObject storage) { - this.theStorage = storage; - } - - /** - * Liefert das Standard-StorageObject zurück, mit dem das Module assoziiert ist. - * @return Standard-StorageObject - */ - public StorageObject getStorageObject () { - return theStorage; - } - - /** - * Holt eine Entity anhand der Id via StorageObject - * @param String der Entity - * @return Entity - */ - public Entity getById (String id) throws ModuleException { - try { - if (theStorage == null) - throw new ModuleException("No StorageObject set!"); - Entity entity = (Entity)theStorage.selectById(id); - if (entity == null) - throw new ModuleException("No object for id = " + id); - else return entity; - } - catch (StorageObjectException e){ - throw new ModuleException(e.toString()); - } - } + this.theStorage = storage; + } + + /** + * Liefert das Standard-StorageObject zurück, mit dem das Module assoziiert ist. + * @return Standard-StorageObject + */ + public StorageObject getStorageObject () { + return theStorage; + } + + /** + * Holt eine Entity anhand der Id via StorageObject + * @param String der Entity + * @return Entity + */ + public Entity getById (String id) throws ModuleException { + try { + if (theStorage == null) + throw new ModuleException("No StorageObject set!"); + Entity entity = (Entity)theStorage.selectById(id); + if (entity == null) + throw new ModuleException("No object for id = " + id); + else return entity; + } + catch (StorageObjectException e){ + throw new ModuleException(e.toString()); + } + } + + /** + * Holt eine EntityListe anhand des WhereClause via StorageObject + * @param String whereclause + * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden + * @return EntityList Liste der gematchten Datensätze + */ + public EntityList getByWhereClause (String whereClause, int offset) throws ModuleException { + try { + if (theStorage == null) + throw new ModuleException("Kein StorageObject gesetzt"); + return theStorage.selectByWhereClause(whereClause, offset); + } + catch (StorageObjectException e){ + throw new ModuleException(e.toString()); + } + } + + /** + * Holt eine EntityListe anhand des WhereClause aus dem StorageObject + * @param String where WhereClause + * @param String order Sortierreihenfolge + * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden + * @return EntityList Liste der gematchten Datensätze + */ + public EntityList getByWhereClause (String where, String order, int offset) throws ModuleException { + try { + if (theStorage==null) throw new ModuleException("Kein StorageObject gesetzt"); + return theStorage.selectByWhereClause(where, order, offset); + } + catch (StorageObjectException e){ + throw new ModuleException(e.toString()); + } + } + /** + * Executes a where clause on the StorageObject with order criteria + * fetching from offset the number of limit objects + * + * @param String where + * @param String order + * @param int offset + * @param int limit + * @return EntityList + */ + + public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleException + { + try { + if (theStorage==null) throw new ModuleException("StorageObject not set!"); + return theStorage.selectByWhereClause(where, order, offset, limit); + } + catch (StorageObjectException e){ + throw new ModuleException(e.toString()); + } + } + + /** + * Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject + * @param String aField - Feldname im StorageObject + * @param String aValue - Wert in Feld im StorageObject + * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden + * @return EntityList Liste der gematchten Datensätze + */ + public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleException { + String whereClause; + whereClause = aField + " like '%" + aValue + "%'"; + return getByWhereClause(whereClause, offset); + } + + /** + * Standardfunktion, um einen Datensatz via StorageObject einzufügen + * @param theValues Hash mit Spalte/Wert-Paaren + * @return Id des eingefügten Objekts + * @exception ModuleException + */ + public String add (HashMap theValues) throws ModuleException { + try { + Entity theEntity = (Entity)theStorage.getEntityClass().newInstance(); + theEntity.setStorage(theStorage); + theEntity.setValues(theValues); + return theEntity.insert(); + } catch (Exception e) { + throw new ModuleException(e.toString()); + } + } /** - * Holt eine EntityListe anhand des WhereClause via StorageObject - * @param String whereclause - * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden - * @return EntityList Liste der gematchten Datensätze - */ - public EntityList getByWhereClause (String whereClause, int offset) throws ModuleException { - try { - if (theStorage == null) - throw new ModuleException("Kein StorageObject gesetzt"); - return theStorage.selectByWhereClause(whereClause, offset); - } - catch (StorageObjectException e){ - throw new ModuleException(e.toString()); - } - } - - /** - * Holt eine EntityListe anhand des WhereClause aus dem StorageObject - * @param String where WhereClause - * @param String order Sortierreihenfolge - * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden - * @return EntityList Liste der gematchten Datensätze - */ - public EntityList getByWhereClause (String where, String order, int offset) throws ModuleException { - try { - if (theStorage==null) throw new ModuleException("Kein StorageObject gesetzt"); - return theStorage.selectByWhereClause(where, order, offset); - } - catch (StorageObjectException e){ - throw new ModuleException(e.toString()); - } - } - /** - * Executes a where clause on the StorageObject with order criteria - * fetching from offset the number of limit objects - * - * @param String where - * @param String order - * @param int offset - * @param int limit - * @return EntityList - */ - - public EntityList getByWhereClause(String where, String order, int offset, int limit) throws ModuleException - { - try { - if (theStorage==null) throw new ModuleException("StorageObject not set!"); - return theStorage.selectByWhereClause(where, order, offset, limit); - } - catch (StorageObjectException e){ - throw new ModuleException(e.toString()); - } - } - - /** - * Holt eine EntityListe anhand des Wertes aValue von Feld aField aus dem StorageObject - * @param String aField - Feldname im StorageObject - * @param String aValue - Wert in Feld im StorageObject - * @param offset - ab welchem Datensatz die gematchten Entities zurueckgeliefert werden - * @return EntityList Liste der gematchten Datensätze - */ - public EntityList getByFieldValue (String aField, String aValue, int offset) throws ModuleException { - String whereClause; - whereClause = aField + " like '%" + aValue + "%'"; - return getByWhereClause(whereClause, offset); - } - - /** - * Standardfunktion, um einen Datensatz via StorageObject einzufügen - * @param theValues Hash mit Spalte/Wert-Paaren - * @return Id des eingefügten Objekts - * @exception ModuleException - */ - public String add (HashMap theValues) throws ModuleException { - try { - Entity theEntity = (Entity)theStorage.getEntityClass().newInstance(); - theEntity.setStorage(theStorage); - theEntity.setValues(theValues); - return theEntity.insert(); - } catch (Exception e) { - throw new ModuleException(e.toString()); - } - } - - /** - * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren - * @param theValues Hash mit Spalte/Wert-Paaren - * @return Id des eingefügten Objekts - * @exception ModuleException - */ - public String set (HashMap theValues) throws ModuleException { - try { - Entity theEntity = theStorage.selectById((String)theValues.get("id")); - if (theEntity == null) - throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id")); - theEntity.setValues(theValues); - theEntity.update(); - return theEntity.getId(); - } - catch (StorageObjectException e){ - e.printStackTrace(System.err); - throw new ModuleException(e.toString()); - } - } - - /** - * Löscht einen Datensatz anhand seiner Id - * @param idParam - * @exception ModuleException - */ - public void deleteById (String idParam) throws ModuleException { + * Standardfunktion, um einen Datensatz via StorageObject zu aktualisieren + * @param theValues Hash mit Spalte/Wert-Paaren + * @return Id des eingefügten Objekts + * @exception ModuleException + */ + public String set (HashMap theValues) throws ModuleException { try { - theStorage.delete(idParam); + Entity theEntity = theStorage.selectById((String)theValues.get("id")); + if (theEntity == null) + throw new ModuleException("Kein Objekt mit id in Datenbank id: " + theValues.get("id")); + theEntity.setValues(theValues); + theEntity.update(); + return theEntity.getId(); + } + catch (StorageObjectException e){ + e.printStackTrace(System.err); + throw new ModuleException(e.toString()); + } + } + + /** + * Deletes a record using an id + * @param idParam + * @exception ModuleException + */ + public void deleteById (String idParam) throws ModuleException { + try { + theStorage.delete(idParam); } catch (StorageObjectException e){ throw new ModuleException(e.toString()); } } - /** - * Liefert den Lookuptable aller Objekte des StorageObjects - * @return freemarker.template.SimpleHash - */ - public SimpleHash getHashData() { - return theStorage.getHashData(); - } + /** + * Liefert den Lookuptable aller Objekte des StorageObjects + * @return freemarker.template.SimpleHash + */ + public SimpleHash getHashData() { + return theStorage.getHashData(); + } /** * returns the number of rows */ public int getSize(String where) - throws SQLException,StorageObjectException { + throws SQLException,StorageObjectException { return theStorage.getSize(where); } diff --git a/source/mir/servlet/ServletModule.java b/source/mir/servlet/ServletModule.java index d15b61dd..9cb95642 100755 --- a/source/mir/servlet/ServletModule.java +++ b/source/mir/servlet/ServletModule.java @@ -36,6 +36,7 @@ import freemarker.template.TemplateModelRoot; import freemarker.template.TemplateModel; import mir.entity.EntityList; +import mir.log.*; import mir.misc.*; import mir.module.AbstractModule; import mir.module.ModuleException; @@ -68,7 +69,8 @@ import java.util.Locale; public abstract class ServletModule { public String defaultAction; - protected Logfile theLog; + protected LoggerWrapper logger; + protected AbstractModule mainModule; protected String templateListString; protected String templateObjektString; @@ -116,6 +118,14 @@ public abstract class ServletModule { public void process(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { } + public void redirect(HttpServletResponse aResponse, String aQuery) throws ServletModuleException { + try { + aResponse.sendRedirect(MirConfig.getProp("RootUri") + "/Mir?"+aQuery); + } + catch (Throwable t) { + throw new ServletModuleException(t.getMessage()); + } + } /** * list(req,res) - generische Listmethode. Wennn die Funktionalitaet @@ -192,9 +202,9 @@ public abstract class ServletModule { throws ServletModuleException, ServletModuleUserException { try { HashMap withValues = getIntersectingValues(req, mainModule.getStorageObject()); - theLog.printDebugInfo("--trying to add..."); + logger.debug("--trying to add..."); String id = mainModule.add(withValues); - theLog.printDebugInfo("--trying to deliver..." + id); + logger.debug("--trying to deliver..." + id); list(req, res); } catch (Exception e) { diff --git a/source/mir/servlet/ServletModuleDispatch.java b/source/mir/servlet/ServletModuleDispatch.java index b98d35f2..04cec990 100755 --- a/source/mir/servlet/ServletModuleDispatch.java +++ b/source/mir/servlet/ServletModuleDispatch.java @@ -42,20 +42,16 @@ import mir.log.*; * Dispatcher, calls the method passed to ServletModule Class, through the "do" * Parameter (via POST or GET) * - * @version $Id: ServletModuleDispatch.java,v 1.8 2002/10/25 03:25:15 zapata Exp $ + * @version $Id: ServletModuleDispatch.java,v 1.9 2002/11/29 13:43:41 zapata Exp $ * * @Author rk * */ public final class ServletModuleDispatch { - private static LoggerWrapper logger; + private static LoggerWrapper logger = new LoggerWrapper("servlet.dispatch"); private static final Class[] SIGNATURE = { HttpServletRequest.class, HttpServletResponse.class }; - static { - logger = new LoggerWrapper("servlet.dispatch"); - } - /** * private constructor to prevent unwanted instantiation; */ diff --git a/source/mir/util/GeneratorHTMLFunctions.java b/source/mir/util/GeneratorHTMLFunctions.java index cd6364bb..394522da 100755 --- a/source/mir/util/GeneratorHTMLFunctions.java +++ b/source/mir/util/GeneratorHTMLFunctions.java @@ -32,7 +32,6 @@ package mir.util; import java.util.*; -import java.net.*; import mir.misc.*; import mir.generator.*; @@ -49,7 +48,7 @@ public class GeneratorHTMLFunctions { if (!(aParameters.get(0) instanceof String)) throw new GeneratorExc("encodeURIGeneratorFunction: parameter must be a string (not a "+aParameters.get(0).getClass().getName()+")"); - return URLEncoder.encode((String) aParameters.get(0)); + return HTMLRoutines.encodeURL((String) aParameters.get(0)); }; } diff --git a/source/mir/util/HTMLRoutines.java b/source/mir/util/HTMLRoutines.java index 6e8dfaa6..076f4cef 100755 --- a/source/mir/util/HTMLRoutines.java +++ b/source/mir/util/HTMLRoutines.java @@ -31,7 +31,14 @@ package mir.util; +import java.net.*; + public class HTMLRoutines { + + public static String encodeURL(String aString) { + return URLEncoder.encode(aString); + } + public static String encodeHTML(String aText) { final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' }; final String[] ESCAPE_CODES = { "&", "<", ">", """, "'" }; diff --git a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java index e103e6d8..4b66e94d 100755 --- a/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicDataModelLocalizer.java @@ -73,6 +73,8 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { anEntityAdapterDefinition.addCalculatedField("to_media_other", new ContentToMediaField( "otherMedia" )); anEntityAdapterDefinition.addCalculatedField("to_media_icon", new ContentToIconField()); + anEntityAdapterDefinition.addCalculatedField("article_type", new ContentToArticleTypeField()); + anEntityAdapterDefinition.addCalculatedField("description_parsed", new FilteredField("description")); anEntityAdapterDefinition.addCalculatedField("content_data_parsed", new FilteredField("content_data")); } @@ -212,6 +214,20 @@ public class MirBasicDataModelLocalizer implements MirDataModelLocalizer { } } + protected class ContentToArticleTypeField implements EntityAdapterDefinition.CalculatedField { + public Object getValue(EntityAdapter anEntityAdapter) { + try { + return anEntityAdapter.getToOneRelation( + "id="+anEntityAdapter.get("to_article_type"), + "id", + "articleType" ); + } + catch (Throwable t) { + throw new RuntimeException(t.getMessage()); + } + } + } + protected class ContentToCommentsField implements EntityAdapterDefinition.CalculatedField { public Object getValue(EntityAdapter anEntityAdapter) { try { diff --git a/source/mircoders/module/ModuleBreaking.java b/source/mircoders/module/ModuleBreaking.java index 7448d520..7a116bd2 100755 --- a/source/mircoders/module/ModuleBreaking.java +++ b/source/mircoders/module/ModuleBreaking.java @@ -45,13 +45,12 @@ import mir.module.*; import mir.entity.*; import mir.misc.*; import mir.storage.*; +import mir.log.*; -import mir.entity.*; -import mir.storage.*; /* - * ContentObjekt - + * * * * @author RK @@ -59,25 +58,22 @@ import mir.storage.*; public class ModuleBreaking extends AbstractModule { - static Logfile theLog; + static LoggerWrapper logger = new LoggerWrapper("Module.Breaking"); - // Kontruktor - - public ModuleBreaking (StorageObject theStorage) - { - if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Breaking.Logfile")); - if (theStorage == null) theLog.printWarning("ModuleBreaking -- StorageObject was null!"); - this.theStorage = theStorage; - } + public ModuleBreaking (StorageObject theStorage) + { + if (theStorage == null) logger.warn("ModuleBreaking -- StorageObject was null!"); + this.theStorage = theStorage; + } - // Methoden +// Methoden public EntityList getBreakingNews() { EntityList returnList = null; try { returnList = getByWhereClause(null,"webdb_create desc",0,5); } catch (Exception ex) { - theLog.printWarning("--getBreakingNews(): could not fetch Breaking News" + ex.toString()); + logger.error("--getBreakingNews(): could not fetch Breaking News" + ex.toString()); } return returnList; } diff --git a/source/mircoders/module/ModuleComment.java b/source/mircoders/module/ModuleComment.java index 0d1be135..4a483b17 100755 --- a/source/mircoders/module/ModuleComment.java +++ b/source/mircoders/module/ModuleComment.java @@ -45,6 +45,7 @@ import mir.module.*; import mir.entity.*; import mir.misc.*; import mir.storage.*; +import mir.log.*; import mircoders.storage.*; @@ -57,13 +58,12 @@ import mircoders.storage.*; public class ModuleComment extends AbstractModule { - static Logfile theLog; + static LoggerWrapper logger = new LoggerWrapper("Module.Comment"); // Contructor public ModuleComment(StorageObject theStorage) { - if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Comment.Logfile")); - if (theStorage == null) theLog.printWarning("StorageObject was null!"); + if (theStorage == null) logger.warn("StorageObject was null!"); this.theStorage = theStorage; } @@ -71,11 +71,12 @@ public class ModuleComment extends AbstractModule public SimpleList getCommentAsSimpleList() throws ModuleException { try { return ((DatabaseComment)theStorage).getPopupData(); - } catch (StorageObjectException e) { + } + catch (StorageObjectException e) { throw new ModuleException(e.toString()); } } - + /** * setValues in the Entity and updates them on the StorageObject */ @@ -88,8 +89,11 @@ public class ModuleComment extends AbstractModule theEntity.setValues(theValues); theEntity.update(); return theEntity.getId(); - } catch (StorageObjectException e){ - e.printStackTrace(System.err); + } + catch (StorageObjectException e){ + logger.error("ModuleComment.set: " + e.getMessage()); + e.printStackTrace(new PrintWriter(new LoggerToWriterAdapter(logger, LoggerWrapper.DEBUG_MESSAGE))); + throw new ModuleException(e.toString()); } } diff --git a/source/mircoders/module/ModuleContent.java b/source/mircoders/module/ModuleContent.java index d66d0cf6..9cff5b0f 100755 --- a/source/mircoders/module/ModuleContent.java +++ b/source/mircoders/module/ModuleContent.java @@ -34,6 +34,7 @@ package mircoders.module; import java.io.*; import java.util.*; import java.sql.*; + import javax.servlet.*; import javax.servlet.http.*; @@ -42,6 +43,7 @@ import mir.module.*; import mir.entity.*; import mir.misc.*; import mir.storage.*; +import mir.log.*; import mircoders.entity.*; import mircoders.storage.*; @@ -49,7 +51,7 @@ import mircoders.storage.*; /* * ContentObjekt - * - * @version $Id: ModuleContent.java,v 1.10 2002/11/27 07:48:02 mh Exp $ + * @version $Id: ModuleContent.java,v 1.11 2002/11/29 13:43:42 zapata Exp $ * * @author RK, mir-coders * @@ -57,20 +59,18 @@ import mircoders.storage.*; public class ModuleContent extends AbstractModule { - static Logfile theLog; + static LoggerWrapper logger = new LoggerWrapper("Module.Content"); - public ModuleContent() { - super(); - if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile")); - } + public ModuleContent() { + super(); + } - public ModuleContent(StorageObject theStorage) { - this.theStorage = theStorage; - if (theLog == null) theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("Module.Content.Logfile")); - } + public ModuleContent(StorageObject theStorage) { + this.theStorage = theStorage; + } - // - // methoden, um an ContentEntities zu kommen +// +// various methods to retrieve content entities public EntityList getFeatures(int offset, int limit) throws ModuleException { @@ -81,14 +81,14 @@ public class ModuleContent extends AbstractModule public EntityList getNewsWire(int offset, int limit) throws ModuleException { return getContent("is_published=true AND to_article_type = 1", - "webdb_create desc",offset,limit); + "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 + "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); @@ -96,139 +96,137 @@ public class ModuleContent extends AbstractModule return returnList; } - 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;i1) { - SimpleHash modelRoot = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(theList); - modelRoot.put("themenHashData", themenModule.getHashData()); - modelRoot.put("schwerpunktHashData", schwerpunktModule.getHashData()); - modelRoot.put("articletypeHash", DatabaseArticleType.getInstance().getHashData()); - deliver(req, res, modelRoot, templateListString); - } else { // count = 1 - _showObject(theList.elementAt(0).getId(),req,res); - } - } catch (StorageObjectException e) { - throw new ServletModuleException(e.toString()); - } - } + Map responseData = ServletHelper.makeGenerationData(getLocale(aRequest)); + model = MirGlobal.localizer().dataModel().adapterModel(); - public void _listop(EntityList theList, HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + Object contentList = + new CachingRewindableIterator( + new EntityIteratorAdapter( aWhereClause, anOrderByClause, 20, + MirGlobal.localizer().dataModel().adapterModel(), "content", nrArticlesPerPage, anOffset) + ); - try { - // delivering html - if (theList == null || theList.getCount() == 0 || theList.getCount()>1) { - SimpleHash modelRoot = HTMLTemplateProcessor.makeSimpleHashWithEntitylistInfos(theList); - modelRoot.put("articletypeHash", DatabaseArticleType.getInstance().getHashData()); - - EntityContent currentContent; - EntityList upMediaEntityList; - EntityList imageEntityList; - EntityList currentMediaList; - Entity mediaType; - EntityMedia uploadedMedia; - SimpleList opList; - String imageRoot = MirConfig.getProp("Producer.ImageRoot"); - - SimpleHash contentHash; - Class mediaHandlerClass=null; - MirMedia mediaHandler=null; - String mediaHandlerName=null; - Database mediaStorage=null; - String tinyIcon; - String iconAlt; - - for (int i=0; i < theList.size();i++) { - currentContent = (EntityContent)theList.elementAt(i); - //fetching/setting the images - upMediaEntityList = DatabaseContentToMedia.getInstance().getUploadedMedia(currentContent); - if (upMediaEntityList!=null && upMediaEntityList.getCount()>=1) { - tinyIcon = null; - iconAlt = null; - mediaHandler = null; - mediaHandlerName = null; - for (int n=0; n < upMediaEntityList.size();n++) { - uploadedMedia = (EntityMedia)upMediaEntityList.elementAt(n); - mediaType = uploadedMedia.getMediaType(); - - //must of had a non-existant to_media_type entry.. - //let's save our ass. - if (mediaType != null) { - try { - mediaHandlerName = mediaType.getValue("classname"); - mediaHandlerClass = Class.forName("mir.media.MediaHandler"+mediaHandlerName); - mediaHandler = (MirMedia)mediaHandlerClass.newInstance(); - } catch (Exception e) { - theLog.printError("ProducerStartpage:problem in reflection: "+mediaHandlerName); - } - - //the "best" media type to show - if (mediaHandler.isVideo()) { - tinyIcon = MirConfig.getProp("Producer.Icon.TinyVideo"); - iconAlt = "Video"; - break; - } else if (mediaHandler.isAudio()) { - tinyIcon = MirConfig.getProp("Producer.Icon.TinyAudio"); - iconAlt = "Audio"; - } else if (tinyIcon == null && !mediaHandler.isImage()) { - tinyIcon = mediaHandler.getTinyIconName(); - iconAlt = mediaHandler.getIconAltName(); - } - } - } - //it only has image(s) - if (tinyIcon == null) { - tinyIcon = MirConfig.getProp("Producer.Icon.TinyImage"); - iconAlt = "Image"; - } - - // uploadedMedia Entity list is empty. - // we only have text - } else { - tinyIcon = MirConfig.getProp("Producer.Icon.TinyText"); - iconAlt = "Text"; - } + responseData.put("nexturl", null); + responseData.put("prevurl", null); + + count=mainModule.getSize(aWhereClause); - try{ - //mediaList = HTMLTemplateProcessor.makeSimpleList(upMediaEntityList); - contentHash = (SimpleHash)theList.get(i); - contentHash.put("tiny_icon", imageRoot+"/"+tinyIcon); - contentHash.put("icon_alt", iconAlt); - } catch (Exception e){} + if (count>=anOffset+nrArticlesPerPage) { + responseData.put("nexturl" , + "module=Content&do=list&where=" + HTMLRoutines.encodeURL(aWhereClause) + + "&order=" + HTMLRoutines.encodeURL(anOrderByClause) + + "&offset=" + anOffset + nrArticlesPerPage); + } + if (anOffset>0) { + responseData.put("prevurl" , + "module=Content&do=list&where=" + HTMLRoutines.encodeURL(aWhereClause) + + "&order=" + HTMLRoutines.encodeURL(anOrderByClause) + + "&offset=" + Math.max(anOffset - nrArticlesPerPage, 0)); } + responseData.put("articles", contentList); - deliver(req, res, modelRoot, templateListString); - } else { // count = 1 - _showObject(theList.elementAt(0).getId(), req, res); - } - } catch (StorageObjectException e) { + responseData.put("thisurl" , + "module=Content&do=list&where=" + HTMLRoutines.encodeURL(aWhereClause) + + "&order=" + HTMLRoutines.encodeURL(anOrderByClause) + + "&offset=" + anOffset); + + responseData.put("from" , Integer.toString(anOffset+1)); + responseData.put("count", Integer.toString(count)); + responseData.put("to", Integer.toString(Math.min(anOffset+nrArticlesPerPage, count))); + responseData.put("offset" , Integer.toString(anOffset)); + responseData.put("order", anOrderByClause); + responseData.put("where" , aWhereClause); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, "contentlist.template"); + } + catch (Throwable e) { throw new ServletModuleException(e.toString()); } } @@ -546,4 +485,3 @@ public class ServletModuleContent extends ServletModule return (EntityUsers)session.getAttribute("login.uid"); } } - diff --git a/source/mircoders/servlet/ServletModuleFileEdit.java b/source/mircoders/servlet/ServletModuleFileEdit.java index c954ddc7..1981aeb4 100755 --- a/source/mircoders/servlet/ServletModuleFileEdit.java +++ b/source/mircoders/servlet/ServletModuleFileEdit.java @@ -33,59 +33,63 @@ package mircoders.servlet; import java.io.*; import java.net.*; + import javax.servlet.http.*; import javax.servlet.*; + import freemarker.template.*; + import mir.servlet.*; import mir.misc.*; import mir.misc.FileExtFilter; +import mir.log.*; /* * ServletModuleFileEdit - * Allows one to do a basic edit of a file in a directory specified * in the config file. * - * @author $Author: mh $ - * @version $Revision: 1.2 $ $Date: 2002/09/01 22:05:57 $ + * @author $Author: zapata $ + * @version $Revision: 1.3 $ $Date: 2002/11/29 13:43:42 $ * */ public class ServletModuleFileEdit extends ServletModule { - // Singelton / Kontruktor +// Singelton / Kontruktor - private static ServletModuleFileEdit instance = - new ServletModuleFileEdit(); - public static ServletModule getInstance() { return instance; } + private static ServletModuleFileEdit instance = + new ServletModuleFileEdit(); + public static ServletModule getInstance() { return instance; } private String _dirName; private String _extName; - private ServletModuleFileEdit() { - - theLog = Logfile.getInstance( - MirConfig.getPropWithHome("ServletModule.FileEdit.Logfile")); - _dirName = MirConfig.getProp("ServletModule.FileEdit.FileDirectory"); - _extName = MirConfig.getProp("ServletModule.FileEdit.ExtFilter"); - - templateListString = - MirConfig.getProp("ServletModule.FileEdit.ListTemplate"); - templateObjektString = - MirConfig.getProp("ServletModule.FileEdit.ObjektTemplate"); - templateConfirmString = - MirConfig.getProp("ServletModule.FileEdit.ConfirmTemplate"); - } - - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - // fetch and deliver - try { - SimpleHash mergeData = new SimpleHash(); - String offset = req.getParameter("offset"); - if (offset==null || offset.equals("")) offset="0"; - mergeData.put("offset",offset); + private ServletModuleFileEdit() { + + logger = new LoggerWrapper("ServletModule.FileEdit"); + + _dirName = MirConfig.getProp("ServletModule.FileEdit.FileDirectory"); + _extName = MirConfig.getProp("ServletModule.FileEdit.ExtFilter"); + + templateListString = + MirConfig.getProp("ServletModule.FileEdit.ListTemplate"); + templateObjektString = + MirConfig.getProp("ServletModule.FileEdit.ObjektTemplate"); + templateConfirmString = + MirConfig.getProp("ServletModule.FileEdit.ConfirmTemplate"); + } + + public void list(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleException + { +// fetch and deliver + try { + SimpleHash mergeData = new SimpleHash(); + String offset = req.getParameter("offset"); + if (offset==null || offset.equals("")) offset="0"; + mergeData.put("offset",offset); File dir = new File(_dirName); System.out.println("DIRNAME: "+_dirName); FileExtFilter extFilter = new FileExtFilter(_extName); @@ -97,15 +101,14 @@ public class ServletModuleFileEdit extends ServletModule } mergeData.put("filelist",theList); - // raus damit - HTMLTemplateProcessor.process(res, templateListString, mergeData, res.getWriter(), getLocale(req)); - } - catch (IOException e) {throw new ServletModuleException(e.toString());} - catch (Exception e) {throw new ServletModuleException(e.toString());} - } + HTMLTemplateProcessor.process(res, templateListString, mergeData, res.getWriter(), getLocale(req)); + } + catch (IOException e) {throw new ServletModuleException(e.toString());} + catch (Exception e) {throw new ServletModuleException(e.toString());} + } public void edit(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + throws ServletModuleException { String filename = req.getParameter("filename"); if (filename == null) throw new ServletModuleException("No filename specified"); @@ -124,7 +127,7 @@ public class ServletModuleFileEdit extends ServletModule withValues.put("text", out.toString()); withValues.put("filename", filename); - + deliver(req, res, withValues, null, templateObjektString); } catch (Exception e) { throw new ServletModuleException(e.toString()); @@ -132,7 +135,7 @@ public class ServletModuleFileEdit extends ServletModule } public void update(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + throws ServletModuleException { String filename = req.getParameter("filename"); if (filename == null) throw new ServletModuleException("No filename specified"); @@ -153,6 +156,4 @@ public class ServletModuleFileEdit extends ServletModule throw new ServletModuleException(e.toString()); } } - - } diff --git a/source/mircoders/servlet/ServletModuleHidden.java b/source/mircoders/servlet/ServletModuleHidden.java index e277ba1a..db11fc84 100755 --- a/source/mircoders/servlet/ServletModuleHidden.java +++ b/source/mircoders/servlet/ServletModuleHidden.java @@ -45,8 +45,9 @@ import mir.module.*; import mir.misc.*; import mir.entity.*; import mir.storage.*; - import mir.entity.*; +import mir.log.*; + import mircoders.storage.*; import mircoders.module.*; @@ -60,70 +61,70 @@ import mircoders.module.*; public class ServletModuleHidden extends ServletModule { - // Singelton / Kontruktor - private static ServletModuleHidden instance = new ServletModuleHidden(); - public static ServletModule getInstance() { return instance; } - - private ServletModuleHidden() { - theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Hidden.Logfile")); - templateListString = MirConfig.getProp("ServletModule.Hidden.ListTemplate"); - try { - mainModule = new ModuleContent(DatabaseContent.getInstance()); - } - catch (StorageObjectException e) { - theLog.printError("servletmoduleHidden could not be initialized"); - } - } - - - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - // Parameter auswerten - SimpleHash mergeData = new SimpleHash(); - String query_year = req.getParameter("year"); - String query_month = req.getParameter("month"); - String order = "webdb_create"; - - // sql basteln - String whereClause = "is_published=false AND webdb_create LIKE '"+ - query_year+"-"+query_month+"%'"; - - theLog.printDebugInfo("sql-whereclause: " + whereClause); - - // fetch und ausliefern - try { - - if ((query_year!=null && !query_year.equals("")) - && (query_month!=null && !query_month.equals(""))) { - EntityList theList = mainModule.getByWhereClause(whereClause, order, -1); - if (theList!=null && theList.size()>0) { - - //make articleHash for comment - StringBuffer buf= new StringBuffer("id in (");boolean first=true; - for(int i=0;i0) { + +//make articleHash for comment + StringBuffer buf= new StringBuffer("id in (");boolean first=true; + for(int i=0;i Integer.parseInt(maxMedia)) { numOfMedia = maxMedia; } - + int mediaNum = Integer.parseInt(numOfMedia); SimpleList mediaFields = new SimpleList(); for(int i =0; i