X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fservlet%2FServletModuleComment.java;h=5fcc9e23c5eacc8d445d0076b7fb7f6ae87922e5;hb=d90c1bbdd5e1823253436f24dce80de4f0abbfcb;hp=5478e20dfa62794278ef51ddf212f180410f2f07;hpb=d7ff9b48279d6b8f94089cf36fde6e8290fb631d;p=mir.git diff --git a/source/mircoders/servlet/ServletModuleComment.java b/source/mircoders/servlet/ServletModuleComment.java index 5478e20d..5fcc9e23 100755 --- a/source/mircoders/servlet/ServletModuleComment.java +++ b/source/mircoders/servlet/ServletModuleComment.java @@ -1,23 +1,62 @@ -package mircoders.servlet; +/* + * Copyright (C) 2001, 2002 The Mir-coders group + * + * This file is part of Mir. + * + * Mir is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Mir is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Mir; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * In addition, as a special exception, The Mir-coders gives permission to link + * the code of this program with the com.oreilly.servlet library, any library + * licensed under the Apache Software License, The Sun (tm) Java Advanced + * Imaging library (JAI), The Sun JIMI library (or with modified versions of + * the above that use the same license as the above), and distribute linked + * combinations including the two. You must obey the GNU General Public + * License in all respects for all of the code used other than the above + * mentioned libraries. If you modify this file, you may extend this exception + * to your version of the file, but you are not obligated to do so. If you do + * not wish to do so, delete this exception statement from your version. + */ -import java.io.*; -import java.sql.*; -import java.util.*; -import java.net.*; -import javax.servlet.*; -import javax.servlet.http.*; +package mircoders.servlet; -import freemarker.template.*; +import java.io.PrintWriter; +import java.util.Map; -import mir.servlet.*; -import mir.module.*; -import mir.misc.*; -import mir.entity.*; -import mir.storage.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; -import mir.entity.*; -import mircoders.storage.*; -import mircoders.module.*; +import mir.config.MirPropertiesConfiguration; +import mir.entity.adapter.EntityAdapterModel; +import mir.entity.adapter.EntityIteratorAdapter; +import mir.log.LoggerToWriterAdapter; +import mir.log.LoggerWrapper; +import mir.servlet.ServletModule; +import mir.servlet.ServletModuleException; +import mir.util.CachingRewindableIterator; +import mir.util.HTTPRequestParser; +import mir.util.JDBCStringRoutines; +import mir.util.URLBuilder; +import mircoders.global.MirGlobal; +import mircoders.module.ModuleComment; +import mircoders.module.ModuleContent; +import mircoders.storage.DatabaseComment; +import mircoders.storage.DatabaseCommentStatus; +import mircoders.storage.DatabaseContent; +import mircoders.storage.DatabaseLanguage; +import freemarker.template.SimpleHash; +import freemarker.template.TemplateModelRoot; /* * ServletModuleComment - controls navigation for Comments @@ -29,99 +68,209 @@ import mircoders.module.*; public class ServletModuleComment extends ServletModule { - private ModuleContent moduleContent; - - // Singelton / Kontruktor - private static ServletModuleComment instance = new ServletModuleComment(); - public static ServletModule getInstance() { return instance; } - - private ServletModuleComment() { - theLog = Logfile.getInstance(MirConfig.getProp("Home") + MirConfig.getProp("ServletModule.Comment.Logfile")); - templateListString = MirConfig.getProp("ServletModule.Comment.ListTemplate"); - templateObjektString = MirConfig.getProp("ServletModule.Comment.ObjektTemplate"); - templateConfirmString = MirConfig.getProp("ServletModule.Comment.ConfirmTemplate"); - try { - mainModule = new ModuleComment(DatabaseComment.getInstance()); - moduleContent = new ModuleContent(DatabaseContent.getInstance()); - } - catch (StorageObjectException e) { - theLog.printError("servletmodule: comment could not be initialized"); - } - } - - - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException - { - // Parameter auswerten - SimpleHash mergeData = new SimpleHash(); - String query_text = req.getParameter("query_text"); - mergeData.put("query_text",query_text); - if (query_text!=null) mergeData.put("query_text_encoded",URLEncoder.encode(query_text)); - String query_field = req.getParameter("query_field"); - mergeData.put("query_field",query_field); - String query_is_published = req.getParameter("query_is_published"); - mergeData.put("query_is_published",query_is_published); - - String offset = req.getParameter("offset"); - if (offset==null || offset.equals("")) offset="0"; - mergeData.put("offset",offset); - - // patching order - String order = req.getParameter("order"); - if(order!=null) { - mergeData.put("order", order); - mergeData.put("order_encoded", URLEncoder.encode(order)); - if (order.equals("webdb_create")) order="webdb_create desc"; - } - - // sql basteln - String whereClause=""; boolean isFirst=true; - if (query_text!=null && !query_text.equalsIgnoreCase("")) { - whereClause += "lower("+query_field+") like lower('%"+query_text+"%')"; isFirst=false;} - if (query_is_published != null && !query_is_published.equals("")) { - if (isFirst==false) whereClause+=" and "; - whereClause += "is_published='"+query_is_published+"'"; - isFirst=false; - } - - theLog.printDebugInfo("sql-whereclause: " + whereClause + " order: " + order + " offset: " + offset); - - // fetch und ausliefern - try { - - if (query_text!=null || query_is_published!=null ) { - EntityList theList = mainModule.getByWhereClause(whereClause, order, (new Integer(offset)).intValue()); - if (theList!=null && theList.size()>0) { - - //make articleHash for comment - StringBuffer buf= new StringBuffer("id in (");boolean first=true; - for(int i=0;i=anOffset+nrCommentsPerPage) { + urlBuilder.setValue("offset", anOffset + nrCommentsPerPage); + responseData.put("nexturl" , urlBuilder.getQuery()); + } + + if (anOffset>0) { + urlBuilder.setValue("offset", Math.max(anOffset - nrCommentsPerPage, 0)); + responseData.put("prevurl" , urlBuilder.getQuery()); + } + + responseData.put("comments", commentList); + responseData.put("from" , Integer.toString(anOffset+1)); + responseData.put("count", Integer.toString(count)); + responseData.put("to", Integer.toString(Math.min(anOffset+nrCommentsPerPage, count))); + + ServletHelper.generateResponse(aResponse.getWriter(), responseData, "commentlist.template"); + } + catch (Throwable e) { + e.printStackTrace(new PrintWriter(new LoggerToWriterAdapter(logger, LoggerWrapper.ERROR_MESSAGE))); + + throw new ServletModuleException(e.getMessage()); + } + } } +