X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Fservlet%2FServletModuleComment.java;h=045378fc50d5fae9fac22373797413bff032e6b1;hb=5b2d2279e1d26546a38c5cd3ba3e4f72192e351b;hp=319ba1003f2d37161c590725ed799786537957c4;hpb=3a661e8f0f659ab5ed2ac0e4d982ac0b398d11f1;p=mir.git diff --git a/source/mircoders/servlet/ServletModuleComment.java b/source/mircoders/servlet/ServletModuleComment.java index 319ba100..045378fc 100755 --- a/source/mircoders/servlet/ServletModuleComment.java +++ b/source/mircoders/servlet/ServletModuleComment.java @@ -1,3 +1,34 @@ +/* + * 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. + */ + package mircoders.servlet; import java.io.*; @@ -6,6 +37,7 @@ import java.util.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; +import org.apache.struts.util.MessageResources; import freemarker.template.*; @@ -14,9 +46,14 @@ import mir.module.*; import mir.misc.*; import mir.entity.*; import mir.storage.*; - +import mir.generator.*; import mir.entity.*; +import mir.entity.adapter.*; +import mir.util.*; + import mircoders.storage.*; +import mircoders.global.*; +import mircoders.localizer.*; import mircoders.module.*; /* @@ -29,98 +66,203 @@ 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(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.Comment.Logfile")); - templateListString = Configuration.getProperty("ServletModule.Comment.ListTemplate"); - templateObjektString = Configuration.getProperty("ServletModule.Comment.ObjektTemplate"); - templateConfirmString = Configuration.getProperty("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) { - - //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;i0) { + generationData.put( "previousurl", "module=Comment&do=listarticlecomments&offset="+ + Math.max( 0, anOffset - nrCommentsPerPage )+"&articleid="+anArticleId); + generationData.put("previous", new Integer(Math.max( 0, anOffset - nrCommentsPerPage ))); + } + + if (anOffset + nrCommentsPerPage < totalNrComments) { + generationData.put( "nexturl", "module=Comment&do=listarticlecomments&offset="+ + Math.min( anOffset + nrCommentsPerPage, totalNrComments-1 )+"&articleid="+anArticleId); + generationData.put("next", new Integer(Math.min( anOffset + nrCommentsPerPage, totalNrComments-1 ))); + } + + generator.generate(aWriter, generationData, new PrintWriter(new NullWriter())); + } + catch (Throwable t) { + t.printStackTrace(System.out); + throw new ServletModuleException(t.getMessage()); + } + } + + public void listarticlecomments(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + { + String articleIdString = req.getParameter("articleid"); + String offsetString = req.getParameter("offset"); + int offset = 0; + int articleId = 0; + + try { + offset = Integer.parseInt(offsetString); + } + catch (Throwable t) { + } + + try { + articleId = Integer.parseInt(articleIdString); + + showArticleCommentList( res.getWriter(), offset, articleId, getLocale(req)); + } + catch (ServletModuleException e) { + throw e; + } + catch (Throwable e) { + e.printStackTrace(System.out); + throw new ServletModuleException(e.getMessage()); + } + } + + public void performarticlecommentsoperation(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { + String commentIdString = req.getParameter("commentid"); + String articleIdString = req.getParameter("articleid"); + String offsetString = req.getParameter("offset"); + String operation = req.getParameter("operation"); + int offset = 0; + int articleId = 0; + + try { + articleId = Integer.parseInt(articleIdString); + + showArticleCommentList( res.getWriter(), offset, articleId, getLocale(req)); + } + catch (ServletModuleException e) { + throw e; + } + catch (Throwable e) { + e.printStackTrace(System.out); + throw new ServletModuleException(e.getMessage()); + } + } }