From d96e301d3d5b64037f4bd72c12e6ac0f7de69ec7 Mon Sep 17 00:00:00 2001 From: zapata Date: Thu, 6 Mar 2003 05:40:38 +0000 Subject: [PATCH] ServletModule exception cleanup + different error templates for admin + open postings + misc. fixes here and there --- etc/open/error.template | 37 ++ etc/open/usererror.template | 37 ++ source/Mir.java | 490 --------------------- source/OpenMir.java | 79 ++-- source/default.properties | 37 +- source/mir/config/MirPropertiesConfiguration.java | 78 ++-- source/mir/servlet/AbstractServlet.java | 389 ++++++++-------- source/mir/servlet/ServletModule.java | 100 ++--- source/mir/servlet/ServletModuleDispatch.java | 27 +- ...uleUserException.java => ServletModuleExc.java} | 19 +- ...uleException.java => ServletModuleFailure.java} | 95 ++-- source/mir/servlet/ServletModuleShow.java | 209 ++++----- .../ServletModuleUserExc.java} | 27 +- source/mir/util/ExceptionFunctions.java | 79 ++++ source/mircoders/media/MediaHandlerGeneric.java | 6 +- source/mircoders/module/ModuleComment.java | 2 +- .../mircoders/producer/IndexingProducerNode.java | 9 +- .../producer/PDFGeneratingProducerNode.java | 2 +- .../mircoders/producer/UnIndexingProducerNode.java | 6 +- source/mircoders/servlet/ServletHelper.java | 15 +- source/mircoders/servlet/ServletModuleAdmin.java | 11 +- .../mircoders/servlet/ServletModuleBreaking.java | 11 +- source/mircoders/servlet/ServletModuleComment.java | 30 +- source/mircoders/servlet/ServletModuleContent.java | 90 ++-- .../mircoders/servlet/ServletModuleFileEdit.java | 34 +- source/mircoders/servlet/ServletModuleHidden.java | 12 +- .../mircoders/servlet/ServletModuleLinksImcs.java | 29 +- .../mircoders/servlet/ServletModuleLocalizer.java | 17 +- .../servlet/ServletModuleMediafolder.java | 3 +- source/mircoders/servlet/ServletModuleMessage.java | 14 +- .../mircoders/servlet/ServletModuleOpenIndy.java | 144 +++--- .../mircoders/servlet/ServletModuleProducer.java | 36 +- .../servlet/ServletModuleUploadedMedia.java | 94 ++-- source/mircoders/servlet/ServletModuleUsers.java | 41 +- .../mircoders/storage/DatabaseContentToMedia.java | 7 +- 35 files changed, 948 insertions(+), 1368 deletions(-) create mode 100755 etc/open/error.template create mode 100755 etc/open/usererror.template rename source/mir/servlet/{ServletModuleUserException.java => ServletModuleExc.java} (82%) rename source/mir/servlet/{ServletModuleException.java => ServletModuleFailure.java} (84%) rename source/mir/{misc/XmlStyler.java => servlet/ServletModuleUserExc.java} (80%) create mode 100755 source/mir/util/ExceptionFunctions.java diff --git a/etc/open/error.template b/etc/open/error.template new file mode 100755 index 00000000..2a0395d0 --- /dev/null +++ b/etc/open/error.template @@ -0,0 +1,37 @@ + + + ${config["Mir.Name"]} | ${lang("error.htmltitle")} + + + + + + + + + + + + + + + + + +
+

${lang("error.title")}

+
+
+

${lang("error.text", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} +

+

+

${data.date} -- ${data.errorstring} +

+

+

+ ${lang("error.text2", config["Mir.Tech-email.address"], config["Mir.Tech-email.name"])} +

+

+ + + diff --git a/etc/open/usererror.template b/etc/open/usererror.template new file mode 100755 index 00000000..fc61c25c --- /dev/null +++ b/etc/open/usererror.template @@ -0,0 +1,37 @@ + + +${lang("usererror.htmltitle")} + + + + + + + + + + + + + + + + +
+

${lang("usererror.title")}

+
+
+

${lang("usererror.text")} +

+

+

${data.errorstring} +

+

+

+

${lang("usererror.what_to_do")} + +

+

+ + + diff --git a/source/Mir.java b/source/Mir.java index dc7cca00..e69de29b 100755 --- a/source/Mir.java +++ b/source/Mir.java @@ -1,490 +0,0 @@ -/* - * 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.IOException; -import java.io.PrintWriter; -import java.lang.reflect.Method; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Vector; - -import javax.servlet.ServletException; -import javax.servlet.UnavailableException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import mir.config.MirPropertiesConfiguration; -import mir.generator.FreemarkerGenerator; -import mir.log.LoggerWrapper; -import mir.misc.HTMLTemplateProcessor; -import mir.misc.StringUtil; -import mir.servlet.AbstractServlet; -import mir.servlet.ServletModule; -import mir.servlet.ServletModuleDispatch; -import mir.servlet.ServletModuleException; -import mir.servlet.ServletModuleUserException; -import mir.util.StringRoutines; -import mircoders.entity.EntityUsers; -import mircoders.global.MirGlobal; -import mircoders.module.ModuleMessage; -import mircoders.module.ModuleUsers; -import mircoders.storage.DatabaseArticleType; -import mircoders.storage.DatabaseMessages; -import mircoders.storage.DatabaseUsers; - -import org.apache.struts.util.MessageResources; - -import freemarker.template.SimpleHash; -import freemarker.template.SimpleList; -import freemarker.template.SimpleScalar; -import freemarker.template.TemplateModel; - - - -/** - * Mir.java - main servlet, that dispatches to servletmodules - * - * @author $Author: idfx $ - * @version $Id: Mir.java,v 1.32 2003/03/05 19:23:14 idfx Exp $ - * - */ -public class Mir extends AbstractServlet { - private static ModuleUsers usersModule = null; - private static ModuleMessage messageModule = null; - private final static Map servletModuleInstanceHash = new HashMap(); - - //I don't know about making this static cause it removes the - //possibility to change the config on the fly.. -mh - private static List loginLanguages = null; - public HttpSession session; - - public void doGet(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { - doPost(req, res); - } - - protected TemplateModel getLoginLanguages() throws ServletException { - synchronized (Mir.class) { - try { - if (loginLanguages == null) { - MessageResources messageResources2 = - MessageResources.getMessageResources("bundles.admin"); - MessageResources messageResources = - MessageResources.getMessageResources("bundles.adminlocal"); - List languages = - StringRoutines.splitString(MirGlobal.getConfigPropertyWithDefault( - "Mir.Login.Languages", "en"), ";"); - - loginLanguages = new Vector(); - - Iterator i = languages.iterator(); - - while (i.hasNext()) { - String code = (String) i.next(); - Locale locale = new Locale(code, ""); - String name = messageResources.getMessage(locale, "languagename"); - - if (name == null) { - name = messageResources2.getMessage(locale, "languagename"); - } - - if (name == null) { - name = code; - } - - Map record = new HashMap(); - record.put("name", name); - record.put("code", code); - loginLanguages.add(record); - } - } - - return FreemarkerGenerator.makeAdapter(loginLanguages); - } catch (Throwable t) { - throw new ServletException(t.getMessage()); - } - } - } - - // FIXME: this should probalby go into AbstractServlet so it can be used in - // OpenMir as well -mh - protected String getDefaultLanguage(HttpServletRequest req) { - String defaultlanguage = - MirGlobal.getConfigPropertyWithDefault("Mir.Login.DefaultLanguage", ""); - - if (defaultlanguage.length() == 0) { - Locale locale = req.getLocale(); - defaultlanguage = locale.getLanguage(); - } - - return defaultlanguage; - } - - public void doPost(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException, UnavailableException { - long startTime = System.currentTimeMillis(); - long sessionConnectTime = 0; - EntityUsers userEntity; - String http = ""; - - if ((configuration.getString("RootUri") == null) || - configuration.getString("RootUri").equals("")) { - configuration.setProperty("RootUri", req.getContextPath()); - } - - configuration.addProperty("ServletName", getServletName()); - - //*** test - // Log.info(this, "blalalala"); - session = req.getSession(true); - userEntity = (EntityUsers) session.getAttribute("login.uid"); - - if (req.getServerPort() == 443) { - http = "https"; - } else { - http = "http"; - } - - //make sure client browsers don't cache anything - setNoCaching(res); - - //FIXME: this seems kind of hackish and only here because we can have - // default other than the one that the browser is set to. - Locale locale = new Locale(getDefaultLanguage(req), ""); - MessageResources messageResources = - MessageResources.getMessageResources("bundles.admin"); - String htmlcharset = messageResources.getMessage(locale, "htmlcharset"); - - res.setContentType("text/html; charset=" + htmlcharset); - - String moduleName = req.getParameter("module"); - checkLanguage(session, req); - - /** @todo for cleanup and readability this should be moved to - * method loginIfNecessary() */ - if ((moduleName != null) && moduleName.equals("direct")) { - //... - } - - // Authentication - if (((moduleName != null) && moduleName.equals("login")) || - (userEntity == null)) { - String user = req.getParameter("login"); - String passwd = req.getParameter("password"); - logger.debug("--login: evaluating for user: " + user); - userEntity = allowedUser(user, passwd); - - if (userEntity == null) { - // login failed: redirecting to login - logger.warn("--login: failed!"); - _sendLoginPage(res, req, res.getWriter()); - - return; - } else if ((moduleName != null) && moduleName.equals("login")) { - // login successful - logger.info("--login: successful! setting uid: " + userEntity.getId()); - session.setAttribute("login.uid", userEntity); - logger.debug("--login: trying to retrieve login.target"); - - String target = (String) session.getAttribute("login.target"); - - if (target != null) { - logger.debug("Redirect: " + target); - - int serverPort = req.getServerPort(); - String redirect = ""; - String redirectString = ""; - - if (serverPort == 80) { - redirect = - res.encodeURL(http + "://" + req.getServerName() + target); - redirectString = - "going Mir"; - } else { - redirect = - res.encodeURL(http + "://" + req.getServerName() + ":" + - req.getServerPort() + target); - redirectString = - "going Mir"; - } - - res.getWriter().println(redirectString); - - //res.sendRedirect(redirect); - } else { - // redirecting to default target - logger.debug("--login: no target - redirecting to default"); - _sendStartPage(res, req, res.getWriter(), userEntity); - } - - return; - } - // if login succesful - } - // if login - - if ((moduleName != null) && moduleName.equals("logout")) { - logger.info("--logout"); - session.invalidate(); - - //session = req.getSession(true); - //checkLanguage(session, req); - _sendLoginPage(res, req, res.getWriter()); - - return; - } - - // Check if authed! - if (userEntity == null) { - // redirect to loginpage - String redirectString = req.getRequestURI(); - String queryString = req.getQueryString(); - - if ((queryString != null) && !queryString.equals("")) { - redirectString += ("?" + req.getQueryString()); - logger.debug("STORING: " + redirectString); - session.setAttribute("login.target", redirectString); - } - - _sendLoginPage(res, req, res.getWriter()); - - return; - } - - // If no module is specified goto standard startpage - if ((moduleName == null) || moduleName.equals("")) { - logger.debug("no module: redirect to standardpage"); - _sendStartPage(res, req, res.getWriter(), userEntity); - - return; - } - - // end of auth - // From now on regular dispatching... - try { - // get servletmodule by parameter and continue with dispacher - ServletModule smod = getServletModuleForName(moduleName); - ServletModuleDispatch.dispatch(smod, req, res); - } catch (ServletModuleException e) { - handleError(req, res, res.getWriter(), - "ServletException in Module " + moduleName + " -- " + e.getMessage()); - } catch (ServletModuleUserException e) { - handleUserError(req, res, res.getWriter(), e.getMessage()); - } - - // timing... - sessionConnectTime = System.currentTimeMillis() - startTime; - logger.info("EXECTIME (" + moduleName + "): " + sessionConnectTime + " ms"); - } - - /** - * Private method getServletModuleForName returns ServletModule - * from Cache - * - * @param moduleName - * @return ServletModule - * - */ - private static ServletModule getServletModuleForName(String moduleName) - throws ServletModuleException { - // Instance in Map ? - if (!servletModuleInstanceHash.containsKey(moduleName)) { - // was not found in hash... - try { - Class theServletModuleClass = null; - - try { - // first we try to get ServletModule from stern.che3.servlet - theServletModuleClass = - Class.forName("mircoders.servlet.ServletModule" + moduleName); - } catch (ClassNotFoundException e) { - // on failure, we try to get it from lib-layer - theServletModuleClass = - Class.forName("mir.servlet.ServletModule" + moduleName); - } - - Method m = theServletModuleClass.getMethod("getInstance", null); - ServletModule smod = (ServletModule) m.invoke(null, null); - - // we put it into map for further reference - servletModuleInstanceHash.put(moduleName, smod); - - return smod; - } catch (Exception e) { - throw new ServletModuleException("*** error resolving classname for " + - moduleName + " -- " + e.getMessage()); - } - } else { - return (ServletModule) servletModuleInstanceHash.get(moduleName); - } - } - - private void handleError(HttpServletRequest req, HttpServletResponse res, - PrintWriter out, String errorString) { - try { - logger.error(errorString); - - SimpleHash modelRoot = new SimpleHash(); - modelRoot.put("errorstring", new SimpleScalar(errorString)); - modelRoot.put("date", - new SimpleScalar(StringUtil.date2readableDateTime( - new GregorianCalendar()))); - HTMLTemplateProcessor.process(res, - MirPropertiesConfiguration.instance().getString("Mir.ErrorTemplate"), - modelRoot, out, getLocale(req)); - out.close(); - } - catch (Exception e) { - logger.error("Error in ErrorTemplate: " + e.getMessage()); - e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - } - } - - private void handleUserError(HttpServletRequest req, HttpServletResponse res, - PrintWriter out, String errorString) { - try { - logger.error(errorString); - - SimpleHash modelRoot = new SimpleHash(); - modelRoot.put("errorstring", new SimpleScalar(errorString)); - modelRoot.put("date", - new SimpleScalar(StringUtil.date2readableDateTime( - new GregorianCalendar()))); - HTMLTemplateProcessor.process(res, - MirPropertiesConfiguration.instance().getString("Mir.UserErrorTemplate"), - modelRoot, out, getLocale(req)); - out.close(); - } - catch (Exception e) { - logger.error("Error in UserErrorTemplate"); - } - } - - /** - * evaluate login for user / password - */ - protected EntityUsers allowedUser(String user, String password) { - try { - if (usersModule == null) { - usersModule = new ModuleUsers(DatabaseUsers.getInstance()); - } - - return usersModule.getUserForLogin(user, password); - } catch (Exception e) { - logger.debug(e.getMessage()); - e.printStackTrace(); - - return null; - } - } - - // Redirect-methods - private void _sendLoginPage(HttpServletResponse res, HttpServletRequest req, - PrintWriter out) { - String loginTemplate = configuration.getString("Mir.LoginTemplate"); - String sessionUrl = res.encodeURL(""); - - try { - SimpleHash mergeData = new SimpleHash(); - SimpleList languages = new SimpleList(); - - mergeData.put("session", sessionUrl); - - mergeData.put("defaultlanguage", getDefaultLanguage(req)); - mergeData.put("languages", getLoginLanguages()); - - HTMLTemplateProcessor.process(res, loginTemplate, mergeData, out, - getLocale(req)); - } catch (Throwable e) { - handleError(req, res, out, "Error sending login page: " + e.getMessage()); - } - } - - private void _sendStartPage(HttpServletResponse res, HttpServletRequest req, - PrintWriter out, EntityUsers userEntity) { - String startTemplate = "templates/admin/start_admin.template"; - String sessionUrl = res.encodeURL(""); - - try { - // merge with logged in user and messages - SimpleHash mergeData = new SimpleHash(); - mergeData.put("session", sessionUrl); - mergeData.put("login_user", userEntity); - - if (messageModule == null) { - messageModule = new ModuleMessage(DatabaseMessages.getInstance()); - } - - mergeData.put("messages", - messageModule.getByWhereClause(null, "webdb_create desc", 0, 10)); - - mergeData.put("articletypes", - DatabaseArticleType.getInstance().selectByWhereClause("", "id", 0, 20)); - - HTMLTemplateProcessor.process(res, startTemplate, mergeData, out, - getLocale(req)); - } - catch (Exception e) { - e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - handleError(req, res, out, "error while trying to send startpage. " + e.getMessage()); - } - } - - public String getServletInfo() { - return "Mir " + configuration.getString("Mir.Version"); - } - - private void checkLanguage(HttpSession session, HttpServletRequest req) { - // a lang parameter always sets the language - String lang = req.getParameter("language"); - - if (lang != null) { - logger.info("selected language " + lang + " overrides accept-language"); - setLanguage(session, lang); - setLocale(session, new Locale(lang, "")); - } - // otherwise store language from accept header in session - else if (session.getAttribute("Language") == null) { - logger.info("accept-language is " + req.getLocale().getLanguage()); - setLanguage(session, req.getLocale().getLanguage()); - setLocale(session, req.getLocale()); - } - } -} diff --git a/source/OpenMir.java b/source/OpenMir.java index 8235d74d..ca0377ca 100755 --- a/source/OpenMir.java +++ b/source/OpenMir.java @@ -44,8 +44,11 @@ import mir.misc.HTMLTemplateProcessor; import mir.misc.StringUtil; import mir.servlet.AbstractServlet; import mir.servlet.ServletModuleDispatch; -import mir.servlet.ServletModuleException; -import mir.servlet.ServletModuleUserException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleUserExc; +import mir.servlet.ServletModuleFailure; +import mir.util.ExceptionFunctions; + import mircoders.servlet.ServletModuleOpenIndy; import freemarker.template.SimpleHash; import freemarker.template.SimpleScalar; @@ -54,71 +57,69 @@ import freemarker.template.SimpleScalar; * OpenMir.java - main servlet for open posting and comment feature to articles * * @author RK 1999-2001, the mir-coders group - * @version $Id: OpenMir.java,v 1.21 2003/03/05 19:23:14 idfx Exp $ + * @version $Id: OpenMir.java,v 1.22 2003/03/06 05:40:38 zapata Exp $ * */ public class OpenMir extends AbstractServlet { - - //private static boolean confed=false; private static String lang; public HttpSession session; - public void doGet(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { - doPost(req,res); + public void doGet(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException { + doPost(aRequest,aResponse); } - public void doPost(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { - + public void doPost(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletException, IOException { long startTime = System.currentTimeMillis(); long sessionConnectTime=0; - session = req.getSession(); + session = aRequest.getSession(); if(session.getAttribute("Language")==null){ - if (req.getParameter("language")!=null) { - setLanguage(session, req.getParameter("language")); + if (aRequest.getParameter("language")!=null) { + setLanguage(session, aRequest.getParameter("language")); } else { - setLanguage(session, getAcceptLanguage(req)); + setLanguage(session, getAcceptLanguage(aRequest)); } } - if (req.getParameter("language")!=null) - setLocale(session, new Locale(req.getParameter("language"), "") ); + if (session.getAttribute("language")!=null) + setLocale(session, new Locale((String) session.getAttribute("language"), "") ); //make sure client browsers don't cache anything - setNoCaching(res); + setNoCaching(aResponse); + + aResponse.setContentType("text/html"); + //aResponse.setContentType("text/html; charset="+MirPropertiesConfiguration.instance().getString("Mir.DefaultHTMLCharset")); - res.setContentType("text/html"); - //res.setContentType("text/html; charset="+MirPropertiesConfiguration.instance().getString("Mir.DefaultHTMLCharset")); try { - ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(),req,res); + ServletModuleDispatch.dispatch(ServletModuleOpenIndy.getInstance(), aRequest, aResponse); } - catch (ServletModuleUserException e) { - handleUserError(req,res,res.getWriter(), e.getMessage()); - } - catch (ServletModuleException e){ - e.printStackTrace(); - handleError(req,res,res.getWriter(), "OpenIndy :: ServletException in Module ServletModule -- " + e.getMessage()); + catch (Throwable e) { + Throwable cause = ExceptionFunctions.traceCauseException(e); + + if (cause instanceof ServletModuleUserExc) + handleUserError(aRequest, aResponse, aResponse.getWriter(), (ServletModuleUserExc) cause); + else + handleError(aRequest, aResponse, aResponse.getWriter(), cause); + } - // timing... + sessionConnectTime = System.currentTimeMillis() - startTime; logger.debug("EXECTIME (ServletModuleOpenIndy): " + sessionConnectTime + " ms"); } - private void handleUserError(HttpServletRequest req, HttpServletResponse res, - PrintWriter out, String errorString) { + private void handleUserError(HttpServletRequest aRequest, HttpServletResponse aResponse, + PrintWriter out, Throwable anException) { try { - logger.error(errorString); + logger.info("user error: " + anException.getMessage()); SimpleHash modelRoot = new SimpleHash(); - modelRoot.put("errorstring", new SimpleScalar(errorString)); + modelRoot.put("errorstring", new SimpleScalar(anException.getMessage())); modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime(new GregorianCalendar()))); - HTMLTemplateProcessor.process(res,MirPropertiesConfiguration.instance().getString("Mir.UserErrorTemplate"), - modelRoot, out, req.getLocale() ); + HTMLTemplateProcessor.process(aResponse,MirPropertiesConfiguration.instance().getString("Mir.UserErrorTemplate"), + modelRoot, out, aRequest.getLocale() ); out.close(); } catch (Exception e) { @@ -127,16 +128,16 @@ public class OpenMir extends AbstractServlet { } - private void handleError(HttpServletRequest req, HttpServletResponse res,PrintWriter out, String errorString) { + private void handleError(HttpServletRequest aRequest, HttpServletResponse aResponse,PrintWriter out, Throwable anException) { try { - logger.error(errorString); + logger.error("error: " + anException); SimpleHash modelRoot = new SimpleHash(); - modelRoot.put("errorstring", new SimpleScalar(errorString)); + modelRoot.put("errorstring", new SimpleScalar(anException.getMessage())); modelRoot.put("date", new SimpleScalar(StringUtil.date2readableDateTime( new GregorianCalendar()))); - HTMLTemplateProcessor.process(res,MirPropertiesConfiguration.instance().getString("Mir.ErrorTemplate"), - modelRoot,out, req.getLocale()); + HTMLTemplateProcessor.process(aResponse,MirPropertiesConfiguration.instance().getString("Mir.ErrorTemplate"), + modelRoot,out, aRequest.getLocale()); out.close(); } catch (Exception e) { diff --git a/source/default.properties b/source/default.properties index 62cabf0f..0b5d417d 100755 --- a/source/default.properties +++ b/source/default.properties @@ -253,9 +253,30 @@ HTMLTemplateProcessor.Dir= # also used for the HTML charset meta tag. Mir.DefaultEncoding=UTF8 + + +# +# config used for OpenIndy +ServletModule.OpenIndy.CommentTemplate=etc/open/comment.template +ServletModule.OpenIndy.CommentDoneTemplate=etc/open/comment_done.template +ServletModule.OpenIndy.CommentDupeTemplate=etc/open/comment_dupe.template +ServletModule.OpenIndy.PostingTemplate=etc/open/posting.template +ServletModule.OpenIndy.PostingDoneTemplate=etc/open/posting_done.template +ServletModule.OpenIndy.PostingDupeTemplate=etc/open/posting_dupe.template +ServletModule.OpenIndy.SearchResultsTemplate=etc/open/search_results.template +ServletModule.OpenIndy.PrepareMailTemplate=etc/open/prepare_mail.template +ServletModule.OpenIndy.SentMailTemplate=etc/open/sent_mail.template +ServletModule.OpenIndy.EmailIsFrom=mailer@somewhere.org +ServletModule.OpenIndy.SMTPServer=localhost +ServletModule.OpenIndy.ErrorTemplate=etc/open/error.template +ServletModule.OpenIndy.UserErrorTemplate=etc/open/usererror.template + + + +Mir.LoginTemplate=templates/admin/login.template + Mir.ErrorTemplate=templates/error.template Mir.UserErrorTemplate=templates/usererror.template -Mir.LoginTemplate=templates/admin/login.template ServletModule.Schwerpunkt.ConfirmTemplate=templates/admin/confirm.template ServletModule.Schwerpunkt.ObjektTemplate=templates/admin/feature.template @@ -302,20 +323,6 @@ ServletModule.Mediafolder.ObjektTemplate=templates/admin/mediafolder.template ServletModule.Mediafolder.ListTemplate=templates/admin/mediafolderlist.template # -# config used for OpenIndy -ServletModule.OpenIndy.CommentTemplate=etc/open/comment.template -ServletModule.OpenIndy.CommentDoneTemplate=etc/open/comment_done.template -ServletModule.OpenIndy.CommentDupeTemplate=etc/open/comment_dupe.template -ServletModule.OpenIndy.PostingTemplate=etc/open/posting.template -ServletModule.OpenIndy.PostingDoneTemplate=etc/open/posting_done.template -ServletModule.OpenIndy.PostingDupeTemplate=etc/open/posting_dupe.template -ServletModule.OpenIndy.SearchResultsTemplate=etc/open/search_results.template -ServletModule.OpenIndy.PrepareMailTemplate=etc/open/prepare_mail.template -ServletModule.OpenIndy.SentMailTemplate=etc/open/sent_mail.template -ServletModule.OpenIndy.EmailIsFrom=mailer@somewhere.org -ServletModule.OpenIndy.SMTPServer=localhost - -# # config for ServletModuleComment - browsing/editing/deleting comments ServletModule.Comment.ConfirmTemplate=templates/admin/confirm.template ServletModule.Comment.ObjektTemplate=templates/admin/comment.template diff --git a/source/mir/config/MirPropertiesConfiguration.java b/source/mir/config/MirPropertiesConfiguration.java index 4d2775bb..2e39bfb9 100755 --- a/source/mir/config/MirPropertiesConfiguration.java +++ b/source/mir/config/MirPropertiesConfiguration.java @@ -53,16 +53,16 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { private static ServletContext context; private static String contextPath; - //if one of these properties is not present a new + //if one of these properties is not present a new //property is added with its default value; private static NeededProperty[] neededWithValue = { - new NeededProperty("Producer.DocRoot",""), - new NeededProperty("Producer.ImageRoot",""), - new NeededProperty("Producer.Image.Path",""), - new NeededProperty("Producer.Media.Path",""), - new NeededProperty("Producer.RealMedia.Path",""), - new NeededProperty("Producer.Image.IconPath","") + new NeededProperty("Producer.DocRoot",""), + new NeededProperty("Producer.ImageRoot",""), + new NeededProperty("Producer.Image.Path",""), + new NeededProperty("Producer.Media.Path",""), + new NeededProperty("Producer.RealMedia.Path",""), + new NeededProperty("Producer.Image.IconPath","") }; /** @@ -110,10 +110,10 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { return context; } - /** - * Returns all properties in a Map - * @return Map - */ + /** + * Returns all properties in a Map + * @return Map + */ public Map allSettings() { Iterator iterator = this.getKeys(); Map returnMap = new HashMap(); @@ -153,11 +153,11 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { * Checks if one property is missing and adds a default value */ private void checkMissing() { - for (int i = 0; i < neededWithValue.length; i++) { - if (super.getProperty(neededWithValue[i].getKey()) == null) { - addProperty(neededWithValue[i].getKey(), neededWithValue[i].getValue()); - } - } + for (int i = 0; i < neededWithValue.length; i++) { + if (super.getProperty(neededWithValue[i].getKey()) == null) { + addProperty(neededWithValue[i].getKey(), neededWithValue[i].getValue()); + } + } } public File getFile(String key) throws FileNotFoundException { @@ -217,28 +217,28 @@ public class MirPropertiesConfiguration extends PropertiesConfiguration { public PropertiesConfigFailure(String msg, Throwable cause) { super(msg, cause); } - + } - - /** - * A Class for properties to be checked - * @author idefix - */ - private static class NeededProperty { - private String _key; - private String _value; - - public NeededProperty(String key, String value) { - _key = key; - _value = value; - } - - public String getKey() { - return _key; - } - - public String getValue() { - return _value; - } - } + + /** + * A Class for properties to be checked + * @author idefix + */ + private static class NeededProperty { + private String _key; + private String _value; + + public NeededProperty(String key, String value) { + _key = key; + _value = value; + } + + public String getKey() { + return _key; + } + + public String getValue() { + return _value; + } + } } diff --git a/source/mir/servlet/AbstractServlet.java b/source/mir/servlet/AbstractServlet.java index 4435521b..281118d0 100755 --- a/source/mir/servlet/AbstractServlet.java +++ b/source/mir/servlet/AbstractServlet.java @@ -1,193 +1,196 @@ -/* - * 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 mir.servlet; - -import java.util.Locale; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import mir.config.MirPropertiesConfiguration; -import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; -import mir.log.LoggerWrapper; -import mir.storage.DatabaseAdaptor; - -import com.codestudio.util.JDBCPool; -import com.codestudio.util.JDBCPoolMetaData; -import com.codestudio.util.SQLManager; - -/** - * Title: Mir - * Description: Abstract servlet-class - * Copyright: Copyright (c) 2001, 2002 - * Company: Mir-coders group - * @author idfx, the Mir-coders group - * @version $Id: AbstractServlet.java,v 1.22 2003/02/20 16:05:33 zapata Exp $ - */ - -public abstract class AbstractServlet extends HttpServlet { - protected static String lang; - protected LoggerWrapper logger; - protected MirPropertiesConfiguration configuration; - - /** - * Constructor for AbstractServlet. - */ - public AbstractServlet() { - super(); - logger = new LoggerWrapper("Servlet"); - } - - protected void setNoCaching(HttpServletResponse res) { - //nothing in Mir can or should be cached as it's all dynamic... - // - //this needs to be done here and not per page (via meta tags) as some - //browsers have problems w/ it per-page -mh - res.setHeader("Pragma", "no-cache"); - res.setDateHeader("Expires", 0); - res.setHeader("Cache-Control", "no-cache"); - } - - /** - * Bind the language to the session - */ - protected void setLanguage(HttpSession session, String language) { - session.setAttribute("Language", language); - } - - protected void setLocale(HttpSession session, Locale loc) { - session.setAttribute("Locale", loc); - } - - /** - * Get the session-bound language - */ - protected String getLanguage(HttpServletRequest req, HttpSession session) { - String lang = (String) session.getAttribute("Language"); - if (lang == null || lang.equals("")) { - return getAcceptLanguage(req); - } - else { - return lang; - } - } - - /** - * get the locale either from the session or the accept-language header ot the request - * this supersedes getLanguage for the new i18n - */ - public Locale getLocale(HttpServletRequest req) { - Locale loc=null; - HttpSession session = req.getSession(false); - if (session!=null) { - // session can be null in case of logout - loc = (Locale) session.getAttribute("Locale"); - } - // if there is nothing in the session get it fron the accept-language - if (loc == null) { - loc = req.getLocale(); - } - return loc; - } - - /** - * Checks the Accept-Language of the client browser. - * If this language is available it returns its country-code, - * else it returns the standard-language - */ - protected String getAcceptLanguage(HttpServletRequest req) { - Locale loc = req.getLocale(); - lang = loc.getLanguage(); - return lang; - } - /** - * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) - */ - public void init(ServletConfig config) throws ServletException { - super.init(config); - MirPropertiesConfiguration.setContext(config.getServletContext()); - try { - configuration = MirPropertiesConfiguration.instance(); - } catch (PropertiesConfigExc e) { - throw new ServletException(e); - } - - String dbUser=configuration.getString("Database.Username"); - String dbPassword=configuration.getString("Database.Password"); - String dbHost=configuration.getString("Database.Host"); - String dbAdapName=configuration.getString("Database.Adaptor"); - String dbName=configuration.getString("Database.Name"); - - DatabaseAdaptor adaptor; - try { - adaptor = (DatabaseAdaptor)Class.forName(dbAdapName).newInstance(); - } catch (Exception e) { - throw new ServletException("Could not load DB adapator: "+ - e.toString()); - } - - String dbDriver; - String dbUrl; - try{ - dbDriver=adaptor.getDriver(); - dbUrl=adaptor.getURL(dbUser,dbPassword, dbHost); - } catch (Exception e) { - throw new ServletException(e); - } - - JDBCPoolMetaData meta = new JDBCPoolMetaData(); - meta.setDbname(dbName); - meta.setDriver(dbDriver); - meta.setURL(dbUrl); - meta.setUserName(dbUser); - meta.setPassword(dbPassword); - meta.setJNDIName("mir"); - meta.setMaximumSize(10); - meta.setMinimumSize(1); - meta.setPoolPreparedStatements(false); - meta.setCacheEnabled(false); - meta.setCacheSize(15); - meta.setDebugging(false); -// meta.setLogFile(dblogfile+".pool"); - - SQLManager manager = SQLManager.getInstance(); - JDBCPool pool = null; - if(manager != null){ - pool = manager.createPool(meta); - } - } - -} +/* + * 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 mir.servlet; + +import java.util.Locale; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import mir.config.MirPropertiesConfiguration; +import mir.config.MirPropertiesConfiguration.PropertiesConfigExc; +import mir.log.LoggerWrapper; +import mir.storage.DatabaseAdaptor; + +import com.codestudio.util.JDBCPool; +import com.codestudio.util.JDBCPoolMetaData; +import com.codestudio.util.SQLManager; + +/** + * Title: Mir + * Description: Abstract servlet-class + * Copyright: Copyright (c) 2001, 2002 + * Company: Mir-coders group + * @author idfx, the Mir-coders group + * @version $Id: AbstractServlet.java,v 1.23 2003/03/06 05:40:39 zapata Exp $ + */ + +public abstract class AbstractServlet extends HttpServlet { + protected static String lang; + protected LoggerWrapper logger; + protected MirPropertiesConfiguration configuration; + + /** + * Constructor for AbstractServlet. + */ + public AbstractServlet() { + super(); + logger = new LoggerWrapper("Servlet"); + } + + protected void setNoCaching(HttpServletResponse aResponse) { + //nothing in Mir can or should be cached as it's all dynamic... + // + //this needs to be done here and not per page (via meta tags) as some + //browsers have problems w/ it per-page -mh + aResponse.setHeader("Pragma", "no-cache"); + aResponse.setDateHeader("Expires", 0); + aResponse.setHeader("Cache-Control", "no-cache"); + } + + /** + * Bind the language to the session + */ + protected void setLanguage(HttpSession session, String language) { + session.setAttribute("Language", language); + } + + protected void setLocale(HttpSession session, Locale loc) { + session.setAttribute("Locale", loc); + } + + /** + * Get the session-bound language + */ + protected String getLanguage(HttpServletRequest aRequest, HttpSession session) { + String lang = (String) session.getAttribute("Language"); + + if (lang == null || lang.length()==0) { + lang = getAcceptLanguage(aRequest); + } + + return lang; + } + + /** + * get the locale either from the session or the accept-language header ot the request + * this supersedes getLanguage for the new i18n + */ + public Locale getLocale(HttpServletRequest aRequest) { + Locale loc = null; + HttpSession session = aRequest.getSession(false); + if (session != null) { + // session can be null in case of logout + loc = (Locale) session.getAttribute("Locale"); + } + // if there is nothing in the session get it fron the accept-language + if (loc == null) { + loc = aRequest.getLocale(); + } + return loc; + } + + /** + * Checks the Accept-Language of the client browser. + * If this language is available it returns its country-code, + * else it returns the standard-language + */ + protected String getAcceptLanguage(HttpServletRequest aRequest) { + Locale loc = aRequest.getLocale(); + lang = loc.getLanguage(); + return lang; + } + + /** + * @see javax.servlet.Servlet#init(javax.servlet.ServletConfig) + */ + public void init(ServletConfig config) throws ServletException { + super.init(config); + MirPropertiesConfiguration.setContext(config.getServletContext()); + try { + configuration = MirPropertiesConfiguration.instance(); + } + catch (PropertiesConfigExc e) { + throw new ServletException(e); + } + + String dbUser = configuration.getString("Database.Username"); + String dbPassword = configuration.getString("Database.Password"); + String dbHost = configuration.getString("Database.Host"); + String dbAdapName = configuration.getString("Database.Adaptor"); + String dbName = configuration.getString("Database.Name"); + + DatabaseAdaptor adaptor; + try { + adaptor = (DatabaseAdaptor) Class.forName(dbAdapName).newInstance(); + } + catch (Exception e) { + throw new ServletException("Could not load DB adapator: " + + e.toString()); + } + + String dbDriver; + String dbUrl; + try { + dbDriver = adaptor.getDriver(); + dbUrl = adaptor.getURL(dbUser, dbPassword, dbHost); + } + catch (Exception e) { + throw new ServletException(e); + } + + JDBCPoolMetaData meta = new JDBCPoolMetaData(); + meta.setDbname(dbName); + meta.setDriver(dbDriver); + meta.setURL(dbUrl); + meta.setUserName(dbUser); + meta.setPassword(dbPassword); + meta.setJNDIName("mir"); + meta.setMaximumSize(10); + meta.setMinimumSize(1); + meta.setPoolPreparedStatements(false); + meta.setCacheEnabled(false); + meta.setCacheSize(15); + meta.setDebugging(false); +// meta.setLogFile(dblogfile+".pool"); + + SQLManager manager = SQLManager.getInstance(); + JDBCPool pool = null; + if (manager != null) { + pool = manager.createPool(meta); + } + } +} diff --git a/source/mir/servlet/ServletModule.java b/source/mir/servlet/ServletModule.java index 1e9185da..76bb1512 100755 --- a/source/mir/servlet/ServletModule.java +++ b/source/mir/servlet/ServletModule.java @@ -76,7 +76,7 @@ public abstract class ServletModule { public String defaultAction; protected LoggerWrapper logger; - protected MirPropertiesConfiguration configuration; + protected MirPropertiesConfiguration configuration; protected AbstractModule mainModule; protected String templateListString; protected String templateObjektString; @@ -138,12 +138,12 @@ public abstract class ServletModule { return loc; } - public void redirect(HttpServletResponse aResponse, String aQuery) throws ServletModuleException { + public void redirect(HttpServletResponse aResponse, String aQuery) throws ServletModuleExc, ServletModuleFailure { try { aResponse.sendRedirect(MirPropertiesConfiguration.instance().getString("RootUri") + "/Mir?"+aQuery); } catch (Throwable t) { - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure("ServletModule.redirect: " +t.getMessage(), t); } } @@ -156,7 +156,7 @@ public abstract class ServletModule { * @param res Http-Response, die vom Dispatcher durchgereicht wird */ public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { EntityList theList; String offsetParam = req.getParameter("offset"); @@ -179,8 +179,8 @@ public abstract class ServletModule { HTMLTemplateProcessor.process(res, templateListString, theList, out, getLocale(req)); } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -192,15 +192,15 @@ public abstract class ServletModule { * @param res Http-Response, die vom Dispatcher durchgereicht wird */ public void add(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { SimpleHash mergeData = new SimpleHash(); mergeData.put("new", "1"); deliver(req, res, mergeData, templateObjektString); } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -214,7 +214,7 @@ public abstract class ServletModule { * @param res Http-Response, die vom Dispatcher durchgereicht wird */ public void insert(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { Map withValues = getIntersectingValues(req, mainModule.getStorageObject()); logger.debug("--trying to add..."); @@ -222,8 +222,8 @@ public abstract class ServletModule { logger.debug("--trying to deliver..." + id); list(req, res); } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -232,12 +232,13 @@ public abstract class ServletModule { * */ - public void delete(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException, ServletModuleUserException { + public void delete(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { String idParam = req.getParameter("id"); if (idParam == null) - throw new ServletModuleException("Invalid call to delete: no id supplied"); + throw new ServletModuleExc("Invalid call to delete: no id supplied"); String confirmParam = req.getParameter("confirm"); String cancelParam = req.getParameter("cancel"); @@ -273,8 +274,8 @@ public abstract class ServletModule { } } } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -287,7 +288,7 @@ public abstract class ServletModule { * @param res Http-Response, die vom Dispatcher durchgereicht wird */ public void edit(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { edit(req, res, req.getParameter("id")); } @@ -300,12 +301,12 @@ public abstract class ServletModule { * @param res Http-Response, die vom Dispatcher durchgereicht wird */ public void edit(HttpServletRequest aRequest, HttpServletResponse aResponse, String anIdentifier) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { deliver(aRequest, aResponse, mainModule.getById(anIdentifier), templateObjektString); } - catch (ModuleException e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -319,7 +320,7 @@ public abstract class ServletModule { */ public void update(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { String idParam = req.getParameter("id"); Map withValues = getIntersectingValues(req, mainModule.getStorageObject()); @@ -335,8 +336,8 @@ public abstract class ServletModule { edit(req, res); } } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -351,11 +352,11 @@ public abstract class ServletModule { * @param tmpl Name des Templates * @exception ServletModuleException */ - public void deliver(HttpServletRequest req, HttpServletResponse res, - TemplateModelRoot rtm, TemplateModelRoot popups, - String templateFilename) - throws ServletModuleException { - if (rtm == null) rtm = new SimpleHash(); + public void deliver(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot rtm, + TemplateModelRoot popups, String templateFilename) throws ServletModuleFailure { + if (rtm == null) + rtm = new SimpleHash(); + try { PrintWriter out = res.getWriter(); HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out, getLocale(req)); @@ -366,10 +367,8 @@ public abstract class ServletModule { // (br1) out.close(); } - catch (HTMLParseException e) { - throw new ServletModuleException(e.getMessage()); - } catch (IOException e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -386,8 +385,7 @@ public abstract class ServletModule { * @exception ServletModuleException */ public void deliver(HttpServletRequest req, HttpServletResponse res, - TemplateModelRoot rtm, String templateFilename) - throws ServletModuleException { + TemplateModelRoot rtm, String templateFilename) throws ServletModuleFailure { deliver(req, res, rtm, null, templateFilename); } @@ -404,7 +402,7 @@ public abstract class ServletModule { */ public void deliver_compressed(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot rtm, String templateFilename) - throws ServletModuleException { + throws ServletModuleFailure { if (rtm == null) rtm = new SimpleHash(); try { PrintWriter out = new LineFilterWriter(res.getWriter()); @@ -412,11 +410,8 @@ public abstract class ServletModule { HTMLTemplateProcessor.process(res, templateFilename, rtm, out, getLocale(req)); out.close(); } - catch (HTMLParseException e) { - throw new ServletModuleException(e.getMessage()); - } - catch (IOException e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -433,8 +428,14 @@ public abstract class ServletModule { */ private void deliver(HttpServletResponse res, HttpServletRequest req, PrintWriter out, TemplateModelRoot rtm, String templateFilename) - throws HTMLParseException { - HTMLTemplateProcessor.process(res, templateFilename, rtm, out, getLocale(req)); + throws ServletModuleFailure { + try { + HTMLTemplateProcessor.process(res, templateFilename, rtm, out, + getLocale(req)); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } } /** @@ -449,22 +450,13 @@ public abstract class ServletModule { } /** - * Hier kann vor der Datenaufbereitung schon mal ein response geschickt - * werden (um das subjektive Antwortverhalten bei langsamen Verbindungen - * zu verbessern). - */ - public void predeliver(HttpServletRequest req, HttpServletResponse res) { - ; - } - - /** * Gets the fields from a httprequest and matches them with the metadata from * the storage object. Returns the keys that match, with their values. * * @return Map with the values */ public Map getIntersectingValues(HttpServletRequest req, StorageObject theStorage) - throws ServletModuleException { + throws ServletModuleExc, ServletModuleFailure { try { HTTPRequestParser parser; @@ -499,8 +491,8 @@ public abstract class ServletModule { } catch (Throwable e) { e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - throw new ServletModuleException( - "ServletModule.getIntersectingValues: " + e.getMessage()); + + throw new ServletModuleFailure( "ServletModule.getIntersectingValues: " + e.getMessage(), e); } } diff --git a/source/mir/servlet/ServletModuleDispatch.java b/source/mir/servlet/ServletModuleDispatch.java index 0c9d2c89..1c58dd99 100755 --- a/source/mir/servlet/ServletModuleDispatch.java +++ b/source/mir/servlet/ServletModuleDispatch.java @@ -44,7 +44,7 @@ import mir.log.LoggerWrapper; * Dispatcher, calls the method passed to ServletModule Class, through the "do" * Parameter (via POST or GET) * - * @version $Id: ServletModuleDispatch.java,v 1.12 2003/01/25 17:45:19 idfx Exp $ + * @version $Id: ServletModuleDispatch.java,v 1.13 2003/03/06 05:40:39 zapata Exp $ * * @Author rk * @@ -76,7 +76,7 @@ public final class ServletModuleDispatch { */ public static void dispatch(ServletModule sMod, HttpServletRequest req, - HttpServletResponse res) throws ServletModuleException, ServletModuleUserException + HttpServletResponse res) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { //sMod.predeliver(req,res); @@ -86,7 +86,7 @@ public final class ServletModuleDispatch { if (sMod.defaultAction() != null) doParam = sMod.defaultAction(); else - throw new ServletModuleException("no parameter do supplied!"); + throw new ServletModuleExc("no parameter do supplied!"); } try { @@ -98,26 +98,21 @@ public final class ServletModuleDispatch { else logger.debug("method lookup unsuccesful"); } catch ( NoSuchMethodException e) { - throw new ServletModuleException("no such method '"+doParam+"' (" + e.getMessage() + ")"); + throw new ServletModuleFailure("no such method '"+doParam+"' (" + e.getMessage() + ")", e); } catch ( SecurityException e) { - throw new ServletModuleException("method not allowed!" + e.getMessage()); + throw new ServletModuleFailure("method not allowed!" + e.getMessage(), e); } catch ( InvocationTargetException e) { logger.debug( "invocation target exception: " + e.getMessage()); - if (e.getTargetException() instanceof ServletModuleUserException) { - throw new ServletModuleUserException(e.getTargetException().getMessage()); - } - else { - e.printStackTrace(); - throw new ServletModuleException(e.getTargetException().getMessage()); - } + + throw new ServletModuleFailure(e.getTargetException().getMessage(), e.getTargetException()); } catch ( IllegalAccessException e) { - throw new ServletModuleException("illegal method not allowed!" + e.getMessage()); + throw new ServletModuleFailure("illegal method not allowed!" + e.getMessage(), e); + } + catch (Throwable t) { + throw new ServletModuleFailure(t); } - -//hopefully we don't get here ... - throw new ServletModuleException("delivery failed! -- "); } } diff --git a/source/mir/servlet/ServletModuleUserException.java b/source/mir/servlet/ServletModuleExc.java similarity index 82% rename from source/mir/servlet/ServletModuleUserException.java rename to source/mir/servlet/ServletModuleExc.java index 5150788b..3a4fe89c 100755 --- a/source/mir/servlet/ServletModuleUserException.java +++ b/source/mir/servlet/ServletModuleExc.java @@ -31,21 +31,10 @@ package mir.servlet; +import multex.Exc; -/* - * ServletModuleUserException - - * Return an Exception with a simple String Message Method - * Differentiates user errors from System bugs/errors. - * - * - * @version 02.2002 - * @author mh - */ - -public final class ServletModuleUserException extends Exception -{ - public ServletModuleUserException(String msg) { - super(msg); +public class ServletModuleExc extends Exc { + public ServletModuleExc(String aMessage) { + super(aMessage); } } - diff --git a/source/mir/servlet/ServletModuleException.java b/source/mir/servlet/ServletModuleFailure.java similarity index 84% rename from source/mir/servlet/ServletModuleException.java rename to source/mir/servlet/ServletModuleFailure.java index e82d6ba5..c83d391a 100755 --- a/source/mir/servlet/ServletModuleException.java +++ b/source/mir/servlet/ServletModuleFailure.java @@ -1,50 +1,45 @@ -/* - * 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 mir.servlet; - - -/* - * ServletModuleException - - * wird vom ServletModule geschmissen - * - * - * @version 28.6.199 - * @author RK - */ - -public final class ServletModuleException extends Exception -{ - public ServletModuleException(String msg) { - super(msg); - } -} - +/* + * 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 mir.servlet; + +import multex.Failure; + +public class ServletModuleFailure extends Failure { + + public ServletModuleFailure(String aMessage,Throwable aCause) { + super(aMessage, aCause); + } + + public ServletModuleFailure(Throwable aCause) { + this (aCause.getMessage(), aCause); + } +} diff --git a/source/mir/servlet/ServletModuleShow.java b/source/mir/servlet/ServletModuleShow.java index f001f11e..d3d376d5 100755 --- a/source/mir/servlet/ServletModuleShow.java +++ b/source/mir/servlet/ServletModuleShow.java @@ -1,104 +1,105 @@ -/* - * 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 mir.servlet; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import freemarker.template.TemplateModelRoot; - - -/** - * Standard ServletModule, dass eine Template anzeigt, und nicht - * mit Daten mischt. Damit ist es moeglich, einfache HTML-Seiten - * als templates zu benutzen. Damit kann auf einfache Weise die - * Funktionalitaet der Freemarker-Bibliothek (beispielsweise Navigationen - * per include einzubauen) benutzt werden. Die Templates - * werden aus dem per Konfiguration angegebenem template-Verzeichnis - * im Ordner "/html" genommen. - * - * @author RK - */ -public class ServletModuleShow extends ServletModule { - private static ServletModuleShow instance = new ServletModuleShow(); - - /** - * Ein ServletModuleShow-Objekt wird ?ber getInstance geliefert. Es gibt zur - * Laufzeit nur ein Objekt (Singleton) - * @return ServletModuleShow - */ - public static ServletModule getInstance () { - return instance; - } - - /** - * Initialisierung leer. - */ - private ServletModuleShow () { - } - - /** - * defaultAction (s.a ServletModule) - * @return "show" - */ - public String defaultAction () { - return "show"; - } - - /** - * Standardmethode, die die Funktionalitaet des ServletModules implementiert. - * - * @param req Http-Request, das vom Dispatcher durchgereicht wird - * @param res Http-Response, die vom Dispatcher durchgereicht wird - * @return String fuer Logfile - * @exception ServletModuleException - */ - public void show(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { - try { - String idParam = req.getParameter("tmpl"); - if (!(idParam==null || idParam.equals(""))) { - deliver(req, res, (TemplateModelRoot)null, "html/"+idParam+".template"); - } - else { - throw new ServletModuleException("Falsches template: " + idParam); - } - } - catch (Exception e) { - throw new ServletModuleException(e.toString()); - } - } - -} - - - - +/* + * 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 mir.servlet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import freemarker.template.TemplateModelRoot; + + +/** + * Standard ServletModule, dass eine Template anzeigt, und nicht + * mit Daten mischt. Damit ist es moeglich, einfache HTML-Seiten + * als templates zu benutzen. Damit kann auf einfache Weise die + * Funktionalitaet der Freemarker-Bibliothek (beispielsweise Navigationen + * per include einzubauen) benutzt werden. Die Templates + * werden aus dem per Konfiguration angegebenem template-Verzeichnis + * im Ordner "/html" genommen. + * + * @author RK + */ +public class ServletModuleShow extends ServletModule { + private static ServletModuleShow instance = new ServletModuleShow(); + + /** + * Ein ServletModuleShow-Objekt wird ?ber getInstance geliefert. Es gibt zur + * Laufzeit nur ein Objekt (Singleton) + * @return ServletModuleShow + */ + public static ServletModule getInstance() { + return instance; + } + + /** + * Initialisierung leer. + */ + private ServletModuleShow() { + } + + /** + * defaultAction (s.a ServletModule) + * @return "show" + */ + public String defaultAction() { + return "show"; + } + + /** + * Standardmethode, die die Funktionalitaet des ServletModules implementiert. + * + * @param req Http-Request, das vom Dispatcher durchgereicht wird + * @param res Http-Response, die vom Dispatcher durchgereicht wird + * @return String fuer Logfile + * @exception ServletModuleException + */ + public void show(HttpServletRequest req, HttpServletResponse res) throws + ServletModuleExc { + try { + String idParam = req.getParameter("tmpl"); + if (! (idParam == null || idParam.equals(""))) { + deliver(req, res, (TemplateModelRoot)null, + "html/" + idParam + ".template"); + } + else { + throw new ServletModuleExc("Invalid template: " + idParam); + } + } + catch (Throwable e) { + throw new ServletModuleFailure(e); + } + } +} + + + + diff --git a/source/mir/misc/XmlStyler.java b/source/mir/servlet/ServletModuleUserExc.java similarity index 80% rename from source/mir/misc/XmlStyler.java rename to source/mir/servlet/ServletModuleUserExc.java index ff5f0002..5d42ff30 100755 --- a/source/mir/misc/XmlStyler.java +++ b/source/mir/servlet/ServletModuleUserExc.java @@ -29,25 +29,12 @@ * not wish to do so, delete this exception statement from your version. */ -package mir.misc; +package mir.servlet; -import java.io.InputStream; -import java.io.OutputStream; +import multex.Exc; -import org.xml.sax.SAXException; - -/** - * Title: XmLStyler - * Description: - * Copyright: Copyright (c) 2001 - * Company: Indymedia - * @author idfx - * @version 1.0 - */ - -public interface XmlStyler { - - void style( String styleKey, InputStream is, OutputStream os ) - throws SAXException; - -} \ No newline at end of file +public class ServletModuleUserExc extends Exc { + public ServletModuleUserExc(String aMessage) { + super(aMessage); + } +} diff --git a/source/mir/util/ExceptionFunctions.java b/source/mir/util/ExceptionFunctions.java new file mode 100755 index 00000000..5c06501d --- /dev/null +++ b/source/mir/util/ExceptionFunctions.java @@ -0,0 +1,79 @@ +/* + * 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 mir.util; + +import multex.Failure; +import org.xml.sax.SAXException; +import java.lang.reflect.InvocationTargetException; + +/** + * + *

Title: ExceptionFunctions

+ *

Description: Functions to assist handling and throwing exceptions

+ *

Copyright: Copyright (c) 2003

+ *

Company: Mir coders

+ * @author Zapata + * @version 1.0 + */ + +public class ExceptionFunctions { + private ExceptionFunctions() { + } + + /** + * Traces an exception to it's root cause, using all known exception types that support + * cause exceptions. + * + * @param anException + * @return the cause (if found) + */ + + public static Throwable traceCauseException(Throwable anException) { + Throwable result = anException; + + while (true) { + if ((result instanceof Failure) && (((Failure) result).getCause()!=null)) { + result = ((Failure) result).getCause(); + } + else if ((result instanceof SAXException) && (((SAXException) result).getException()!=null)) { + result = ((SAXException) result).getException(); + } + else if ((result instanceof InvocationTargetException) && (((InvocationTargetException) result).getTargetException()!=null)) { + result = ((InvocationTargetException) result).getTargetException(); + } + else + break; + } + + return result; + } +} diff --git a/source/mircoders/media/MediaHandlerGeneric.java b/source/mircoders/media/MediaHandlerGeneric.java index 6518e61c..66b11cff 100755 --- a/source/mircoders/media/MediaHandlerGeneric.java +++ b/source/mircoders/media/MediaHandlerGeneric.java @@ -64,7 +64,7 @@ import freemarker.template.SimpleList; * * @see mir.media.MirMedia * @author mh - * @version $Id: MediaHandlerGeneric.java,v 1.15 2003/03/05 19:23:16 idfx Exp $ + * @version $Id: MediaHandlerGeneric.java,v 1.16 2003/03/06 05:40:39 zapata Exp $ */ public class MediaHandlerGeneric implements MirMedia @@ -78,8 +78,8 @@ public class MediaHandlerGeneric implements MirMedia static { try { configuration = MirPropertiesConfiguration.instance(); - } catch (PropertiesConfigExc e) { - e.printStackTrace(); + } + catch (PropertiesConfigExc e) { } imageHost = configuration.getString("Producer.Image.Host"); imageRoot = configuration.getString("Producer.ImageRoot"); diff --git a/source/mircoders/module/ModuleComment.java b/source/mircoders/module/ModuleComment.java index c57a920b..35791843 100755 --- a/source/mircoders/module/ModuleComment.java +++ b/source/mircoders/module/ModuleComment.java @@ -104,7 +104,7 @@ public class ModuleComment extends AbstractModule } catch (StorageObjectFailure e){ logger.error("ModuleComment.set: " + e.getMessage()); - e.printStackTrace(new PrintWriter(new LoggerToWriterAdapter(logger, LoggerWrapper.DEBUG_MESSAGE))); + e.printStackTrace(logger.asPrintWriter(logger.DEBUG_MESSAGE)); throw new ModuleException(e.toString()); } catch (StorageObjectExc e) { diff --git a/source/mircoders/producer/IndexingProducerNode.java b/source/mircoders/producer/IndexingProducerNode.java index f647533a..74e20ab9 100755 --- a/source/mircoders/producer/IndexingProducerNode.java +++ b/source/mircoders/producer/IndexingProducerNode.java @@ -165,11 +165,12 @@ public class IndexingProducerNode implements ProducerNode { //} //theDoc.add(Field.UnStored("comments",commentsAggregate)); indexWriter.addDocument(theDoc); - } catch (Throwable t) { + } + catch (Throwable t) { aLogger.error("Error while indexing content: " + t.getMessage()); - t.printStackTrace(new PrintWriter( - new LoggerToWriterAdapter(aLogger, LoggerWrapper.DEBUG_MESSAGE))); - } finally { + t.printStackTrace(aLogger.asPrintWriter(aLogger.DEBUG_MESSAGE)); + } + finally { if (indexWriter != null) { try { indexWriter.close(); diff --git a/source/mircoders/producer/PDFGeneratingProducerNode.java b/source/mircoders/producer/PDFGeneratingProducerNode.java index 6a2b063e..82327eee 100755 --- a/source/mircoders/producer/PDFGeneratingProducerNode.java +++ b/source/mircoders/producer/PDFGeneratingProducerNode.java @@ -71,7 +71,7 @@ public class PDFGeneratingProducerNode implements ProducerNode { } catch (Throwable t) { - t.printStackTrace(); + t.printStackTrace(aLogger.asPrintWriter(aLogger.DEBUG_MESSAGE)); aLogger.error(" error while generating: " + t.getMessage() + t.toString()); } endTime = System.currentTimeMillis(); diff --git a/source/mircoders/producer/UnIndexingProducerNode.java b/source/mircoders/producer/UnIndexingProducerNode.java index 4ceaf843..05ec4259 100755 --- a/source/mircoders/producer/UnIndexingProducerNode.java +++ b/source/mircoders/producer/UnIndexingProducerNode.java @@ -80,13 +80,13 @@ public class UnIndexingProducerNode implements ProducerNode { aLogger.info("UnIndexing " + (String) entity.getValue("id") + " out of " + index); IndexUtil.unindexEntity((EntityContent) entity,index); - + } catch (Throwable t) { aLogger.error("Error while unindexing content: " + t.getMessage()); - t.printStackTrace(new PrintWriter(new LoggerToWriterAdapter(aLogger, LoggerWrapper.DEBUG_MESSAGE))); + t.printStackTrace(aLogger.asPrintWriter(aLogger.DEBUG_MESSAGE)); } - + endTime = System.currentTimeMillis(); aLogger.info(" UnIndexTime: " + (endTime-startTime) + " ms
"); diff --git a/source/mircoders/servlet/ServletHelper.java b/source/mircoders/servlet/ServletHelper.java index fc9d76cf..a294cce6 100755 --- a/source/mircoders/servlet/ServletHelper.java +++ b/source/mircoders/servlet/ServletHelper.java @@ -7,10 +7,11 @@ import java.util.Map; import mir.entity.adapter.EntityIteratorAdapter; import mir.generator.Generator; -import mir.servlet.ServletModuleException; -import mir.util.CachingRewindableIterator; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; import mir.util.NullWriter; import mir.util.ResourceBundleGeneratorFunction; +import mir.util.CachingRewindableIterator; import mircoders.global.MirGlobal; import org.apache.struts.util.MessageResources; @@ -20,7 +21,7 @@ import org.apache.struts.util.MessageResources; public class ServletHelper { // ML: add logging! - static Map makeGenerationData(Locale aLocale) throws ServletModuleException { + static Map makeGenerationData(Locale aLocale) throws ServletModuleExc { try { Map result = new HashMap(); @@ -58,11 +59,11 @@ public class ServletHelper { return result; } catch (Throwable t) { - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } - static void generateResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleException { + static void generateResponse(PrintWriter aWriter, Map aGenerationData, String aGenerator) throws ServletModuleExc { Generator generator; @@ -72,7 +73,7 @@ public class ServletHelper { generator.generate(aWriter, aGenerationData, new PrintWriter(new NullWriter())); } catch (Throwable t) { - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } -} \ No newline at end of file +} diff --git a/source/mircoders/servlet/ServletModuleAdmin.java b/source/mircoders/servlet/ServletModuleAdmin.java index 67829099..88b119df 100755 --- a/source/mircoders/servlet/ServletModuleAdmin.java +++ b/source/mircoders/servlet/ServletModuleAdmin.java @@ -40,7 +40,7 @@ import javax.servlet.http.HttpServletResponse; import mir.log.LoggerToWriterAdapter; import mir.log.LoggerWrapper; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleFailure; import mir.util.URLBuilder; public class ServletModuleAdmin extends ServletModule @@ -53,10 +53,7 @@ public class ServletModuleAdmin extends ServletModule defaultAction = "showSuperUserMenu"; } - public void superusermenu(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { - // ML: experiment in using the producer's generation system instead of the - // old one... - + public void superusermenu(HttpServletRequest aRequest, HttpServletResponse aResponse) { URLBuilder urlBuilder = new URLBuilder(); int count; @@ -70,9 +67,7 @@ public class ServletModuleAdmin extends ServletModule ServletHelper.generateResponse(aResponse.getWriter(), responseData, "superusermenu.template"); } catch (Throwable e) { - e.printStackTrace(new PrintWriter(new LoggerToWriterAdapter(logger, LoggerWrapper.ERROR_MESSAGE))); - - throw new ServletModuleException(e.getMessage()); + throw new ServletModuleFailure(e); } } } diff --git a/source/mircoders/servlet/ServletModuleBreaking.java b/source/mircoders/servlet/ServletModuleBreaking.java index 0ca07cba..0b057a91 100755 --- a/source/mircoders/servlet/ServletModuleBreaking.java +++ b/source/mircoders/servlet/ServletModuleBreaking.java @@ -43,7 +43,7 @@ import mir.log.LoggerWrapper; import mir.misc.HTMLTemplateProcessor; import mir.module.ModuleException; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleFailure; import mircoders.module.ModuleBreaking; import mircoders.storage.DatabaseBreaking; import freemarker.template.SimpleHash; @@ -66,7 +66,7 @@ public class ServletModuleBreaking extends ServletModule private ServletModuleBreaking() { logger = new LoggerWrapper("ServletModule.Breaking"); try { - configuration = MirPropertiesConfiguration.instance(); + configuration = MirPropertiesConfiguration.instance(); templateListString = configuration.getString("ServletModule.Breaking.ListTemplate"); templateObjektString = configuration.getString("ServletModule.Breaking.ObjektTemplate"); @@ -81,7 +81,6 @@ public class ServletModuleBreaking extends ServletModule } public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { logger.debug("-- breaking: list"); // fetch and deliver @@ -107,8 +106,8 @@ public class ServletModuleBreaking extends ServletModule // raus damit HTMLTemplateProcessor.process(res, templateListString, mergeData, res.getWriter(), getLocale(req)); } - catch (ModuleException e) {throw new ServletModuleException(e.toString());} - catch (IOException e) {throw new ServletModuleException(e.toString());} - catch (Exception e) {throw new ServletModuleException(e.toString());} + catch (Exception e) { + throw new ServletModuleFailure(e); + } } } diff --git a/source/mircoders/servlet/ServletModuleComment.java b/source/mircoders/servlet/ServletModuleComment.java index 416a1c66..1e1c652e 100755 --- a/source/mircoders/servlet/ServletModuleComment.java +++ b/source/mircoders/servlet/ServletModuleComment.java @@ -43,7 +43,8 @@ import mir.entity.adapter.EntityIteratorAdapter; import mir.log.LoggerToWriterAdapter; import mir.log.LoggerWrapper; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; import mir.util.CachingRewindableIterator; import mir.util.HTTPRequestParser; import mir.util.JDBCStringRoutines; @@ -93,17 +94,17 @@ public class ServletModuleComment extends ServletModule } } - public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String idParam = req.getParameter("id"); if (idParam == null) - throw new ServletModuleException("Invalid call: id not supplied "); + throw new ServletModuleExc("Invalid call: id not supplied "); showComment(idParam, req, res); } - public void showComment(String anId, HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void showComment(String anId, HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { try { SimpleHash extraInfo = new SimpleHash(); TemplateModelRoot data; @@ -115,13 +116,13 @@ public class ServletModuleComment extends ServletModule deliver(aRequest, aResponse, data, extraInfo, templateObjektString); } - catch (Exception e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } - public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException + public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); @@ -132,7 +133,7 @@ public class ServletModuleComment extends ServletModule returnCommentList(aRequest, aResponse, where, order, offset); } - public void search(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException + public void search(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); SQLQueryBuilder queryBuilder = new SQLQueryBuilder(); @@ -175,7 +176,7 @@ public class ServletModuleComment extends ServletModule returnCommentList(aRequest, aResponse, queryBuilder.getWhereClause(), queryBuilder.getOrderByClause(), 0); } - public void articlecomments(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void articlecomments(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String articleIdString = req.getParameter("articleid"); int articleId; @@ -185,16 +186,13 @@ public class ServletModuleComment extends ServletModule returnCommentList( req, res, "to_media="+articleId, "webdb_create desc", 0); } - catch (ServletModuleException e) { - throw e; - } catch (Throwable e) { - throw new ServletModuleException(e.getMessage()); + throw new ServletModuleFailure(e); } } public void returnCommentList(HttpServletRequest aRequest, HttpServletResponse aResponse, - String aWhereClause, String anOrderByClause, int anOffset) throws ServletModuleException { + String aWhereClause, String anOrderByClause, int anOffset) throws ServletModuleExc { // ML: experiment in using the producer's generation system instead of the // old one... @@ -258,9 +256,7 @@ public class ServletModuleComment extends ServletModule 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()); + throw new ServletModuleFailure(e); } } } diff --git a/source/mircoders/servlet/ServletModuleContent.java b/source/mircoders/servlet/ServletModuleContent.java index f22923f0..0300a589 100755 --- a/source/mircoders/servlet/ServletModuleContent.java +++ b/source/mircoders/servlet/ServletModuleContent.java @@ -48,7 +48,9 @@ import mir.log.LoggerWrapper; import mir.misc.StringUtil; import mir.module.ModuleException; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleUserExc; +import mir.servlet.ServletModuleFailure; import mir.storage.StorageObjectFailure; import mir.util.CachingRewindableIterator; import mir.util.HTTPRequestParser; @@ -72,7 +74,7 @@ import freemarker.template.SimpleHash; * ServletModuleContent - * deliver html for the article admin form. * - * @version $Id: ServletModuleContent.java,v 1.39 2003/03/05 19:23:16 idfx Exp $ + * @version $Id: ServletModuleContent.java,v 1.40 2003/03/06 05:40:40 zapata Exp $ * @author rk, mir-coders * */ @@ -101,7 +103,7 @@ public class ServletModuleContent extends ServletModule } } - public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException + public void list(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); @@ -113,7 +115,7 @@ public class ServletModuleContent extends ServletModule returnArticleList(aRequest, aResponse, where, order, offset, selectArticleUrl); } - public void search(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void search(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc, ServletModuleFailure { try { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); SQLQueryBuilder queryBuilder = new SQLQueryBuilder(); @@ -160,16 +162,16 @@ public class ServletModuleContent extends ServletModule returnArticleList(aRequest, aResponse, queryBuilder.getWhereClause(), queryBuilder.getOrderByClause(), 0, selectArticleUrl); } catch (Throwable e) { - throw new ServletModuleException(e.toString()); + throw new ServletModuleFailure(e); } } - public void add(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { + public void add(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { _showObject(null, req, res); } - public void insert(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void insert(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { //theLog.printDebugInfo(":: content :: trying to insert"); try { @@ -191,20 +193,17 @@ public class ServletModuleContent extends ServletModule _showObject(id, req, res); } - catch (StorageObjectFailure e) { - throw new ServletModuleException(e.toString()); - } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } - public void delete(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void delete(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { EntityUsers user = _getUser(req); String idParam = req.getParameter("id"); - if (idParam == null) throw new ServletModuleException("Invalid call: id missing"); + if (idParam == null) throw new ServletModuleExc("Invalid call: id missing"); String confirmParam = req.getParameter("confirm"); String cancelParam = req.getParameter("cancel"); @@ -241,14 +240,8 @@ public class ServletModuleContent extends ServletModule } } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); - } - catch (StorageObjectFailure e) { - throw new ServletModuleException(e.toString()); - } - catch (IOException e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } list(req,res); } @@ -259,20 +252,20 @@ public class ServletModuleContent extends ServletModule } } - public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String idParam = req.getParameter("id"); if (idParam == null) - throw new ServletModuleException("Invalid call: id not supplied "); + throw new ServletModuleExc("Invalid call: id not supplied "); _showObject(idParam, req, res); } // methods for attaching media file - public void attach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void attach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String mediaIdParam = req.getParameter("mid"); String idParam = req.getParameter("cid"); - if (idParam == null||mediaIdParam==null) throw new ServletModuleException("smod content :: attach :: cid/mid missing"); + if (idParam == null||mediaIdParam==null) throw new ServletModuleExc("smod content :: attach :: cid/mid missing"); try { EntityContent entContent = (EntityContent)mainModule.getById(idParam); @@ -288,12 +281,14 @@ public class ServletModuleContent extends ServletModule _showObject(idParam, req, res); } - public void dettach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void dettach(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String cidParam = req.getParameter("cid"); String midParam = req.getParameter("mid"); - if (cidParam == null) throw new ServletModuleException("smod content :: dettach :: cid missing"); - if (midParam == null) throw new ServletModuleException("smod content :: dettach :: mid missing"); + if (cidParam == null) + throw new ServletModuleExc("smod content :: dettach :: cid missing"); + if (midParam == null) + throw new ServletModuleExc("smod content :: dettach :: mid missing"); try { EntityContent entContent = (EntityContent)mainModule.getById(cidParam); @@ -309,8 +304,7 @@ public class ServletModuleContent extends ServletModule _showObject(cidParam, req, res); } - public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) - throws ServletModuleException + public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { try { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); @@ -318,7 +312,8 @@ public class ServletModuleContent extends ServletModule String returnUrl = requestParser.getParameter("returnurl"); String idParam = aRequest.getParameter("id"); - if (idParam == null) throw new ServletModuleException("Wrong call: (id) is missing"); + if (idParam == null) + throw new ServletModuleExc("Wrong call: (id) is missing"); Map withValues = getIntersectingValues(aRequest, DatabaseContent.getInstance()); String[] topic_id = aRequest.getParameterValues("to_topic"); @@ -343,7 +338,7 @@ public class ServletModuleContent extends ServletModule _showObject(idParam, aRequest, aResponse); } catch (Throwable e) { - throw new ServletModuleException(e.toString()); + throw new ServletModuleFailure(e); } } @@ -354,8 +349,7 @@ public class ServletModuleContent extends ServletModule * article. */ public void _showObject(String id, HttpServletRequest aRequest, HttpServletResponse aResponse) - throws ServletModuleException { - + throws ServletModuleExc { try { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); Map responseData = ServletHelper.makeGenerationData(getLocale(aRequest)); @@ -392,8 +386,8 @@ public class ServletModuleContent extends ServletModule ServletHelper.generateResponse(aResponse.getWriter(), responseData, editTemplate); } - catch (Exception e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } @@ -403,7 +397,7 @@ public class ServletModuleContent extends ServletModule String aWhereClause, String anOrderByClause, int anOffset, - String aSelectArticleUrl) throws ServletModuleException { + String aSelectArticleUrl) throws ServletModuleExc { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); URLBuilder urlBuilder = new URLBuilder(); @@ -472,11 +466,11 @@ public class ServletModuleContent extends ServletModule ServletHelper.generateResponse(aResponse.getWriter(), responseData, listTemplate); } catch (Throwable e) { - throw new ServletModuleException(e.toString()); + throw new ServletModuleFailure(e); } } - public void selectparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException + public void selectparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { try { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); @@ -490,27 +484,27 @@ public class ServletModuleContent extends ServletModule returnArticleList(aRequest, aResponse, "", "", 0, urlBuilder.getQuery()); } catch (Throwable e) { - throw new ServletModuleException(e.getMessage()); + throw new ServletModuleFailure(e); } } - public void listchildren(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException + public void listchildren(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { try { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); String articleId = requestParser.getParameter("article_id"); if (articleId == null) - throw new ServletModuleException("ServletModuleContent.listchildren: article_id not set!"); + throw new ServletModuleExc("ServletModuleContent.listchildren: article_id not set!"); returnArticleList(aRequest, aResponse, "to_content = " + articleId, "", 0, null); } catch (Throwable e) { - throw new ServletModuleException(e.getMessage()); + throw new ServletModuleFailure(e); } } - public void setparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException + public void setparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); String articleId = aRequest.getParameter("childid"); @@ -525,13 +519,13 @@ public class ServletModuleContent extends ServletModule } catch(Throwable e) { logger.error("ServletModuleContent.setparent: " + e.getMessage()); - throw new ServletModuleException("ServletModuleContent.setparent: " + e.getMessage()); + throw new ServletModuleFailure(e); } redirect(aResponse, returnUrl); } - public void clearparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException + public void clearparent(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); String articleId = requestParser.getParameter("id"); @@ -547,7 +541,7 @@ public class ServletModuleContent extends ServletModule e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); logger.error("ServletModuleContent.clearparent: " + e.getMessage()); - throw new ServletModuleException("ServletModuleContent.clearparent: " + e.getMessage()); + throw new ServletModuleFailure("ServletModuleContent.clearparent: " + e.getMessage(), e); } redirect(aResponse, returnUrl); diff --git a/source/mircoders/servlet/ServletModuleFileEdit.java b/source/mircoders/servlet/ServletModuleFileEdit.java index 97ba55f6..c93712e5 100755 --- a/source/mircoders/servlet/ServletModuleFileEdit.java +++ b/source/mircoders/servlet/ServletModuleFileEdit.java @@ -45,7 +45,8 @@ import mir.log.LoggerWrapper; import mir.misc.FileExtFilter; import mir.misc.HTMLTemplateProcessor; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; import freemarker.template.SimpleHash; import freemarker.template.SimpleList; @@ -55,7 +56,7 @@ import freemarker.template.SimpleList; * in the config file. * * @author $Author: zapata $ - * @version $Revision: 1.5 $ $Date: 2003/02/23 05:00:15 $ + * @version $Revision: 1.6 $ $Date: 2003/03/06 05:40:40 $ * */ @@ -84,8 +85,7 @@ public class ServletModuleFileEdit extends ServletModule templateConfirmString =configuration.getString("ServletModule.FileEdit.ConfirmTemplate"); } - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + public void list(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { // fetch and deliver try { @@ -105,15 +105,15 @@ public class ServletModuleFileEdit extends ServletModule 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());} + catch (Throwable e) { + throw new ServletModuleFailure(e); + } } - public void edit(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String filename = req.getParameter("filename"); - if (filename == null) throw new ServletModuleException("No filename specified"); + if (filename == null) throw new ServletModuleExc("No filename specified"); try { File f = new File(_dirName, filename); @@ -131,16 +131,17 @@ public class ServletModuleFileEdit extends ServletModule deliver(req, res, withValues, null, templateObjektString); - } catch (Exception e) { - throw new ServletModuleException(e.toString()); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); } } - public void update(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + public void update(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String filename = req.getParameter("filename"); - if (filename == null) throw new ServletModuleException("No filename specified"); + + if (filename == null) throw new ServletModuleExc("No filename specified"); try { File f = new File(_dirName, filename); @@ -154,8 +155,9 @@ public class ServletModuleFileEdit extends ServletModule out.close(); edit(req, res); - } catch (Exception e) { - throw new ServletModuleException(e.toString()); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); } } } diff --git a/source/mircoders/servlet/ServletModuleHidden.java b/source/mircoders/servlet/ServletModuleHidden.java index 9182107c..bae412b8 100755 --- a/source/mircoders/servlet/ServletModuleHidden.java +++ b/source/mircoders/servlet/ServletModuleHidden.java @@ -41,7 +41,8 @@ import mir.log.LoggerWrapper; import mir.misc.HTMLTemplateProcessor; import mir.module.ModuleException; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; import mir.storage.StorageObjectFailure; import mircoders.module.ModuleContent; import mircoders.storage.DatabaseContent; @@ -74,8 +75,7 @@ public class ServletModuleHidden extends ServletModule } - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + public void list(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { // determine parameter SimpleHash mergeData = new SimpleHash(); @@ -120,8 +120,8 @@ public class ServletModuleHidden extends ServletModule // raus damit HTMLTemplateProcessor.process(res, templateListString, mergeData, res.getWriter(), getLocale(req)); } - catch (ModuleException e) {throw new ServletModuleException(e.toString());} - catch (IOException e) {throw new ServletModuleException(e.toString());} - catch (Exception e) {throw new ServletModuleException(e.toString());} + catch (Throwable e) { + throw new ServletModuleFailure(e); + } } } diff --git a/source/mircoders/servlet/ServletModuleLinksImcs.java b/source/mircoders/servlet/ServletModuleLinksImcs.java index efb4313c..dc740ea3 100755 --- a/source/mircoders/servlet/ServletModuleLinksImcs.java +++ b/source/mircoders/servlet/ServletModuleLinksImcs.java @@ -44,7 +44,8 @@ import mir.misc.HTMLParseException; import mir.misc.HTMLTemplateProcessor; import mir.module.ModuleException; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; import mir.storage.StorageObjectFailure; import mircoders.module.ModuleLanguage; import mircoders.module.ModuleLinksImcs; @@ -87,8 +88,7 @@ public class ServletModuleLinksImcs extends ServletModule { } } - public void add(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + public void add(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { try { SimpleHash modelRoot = new SimpleHash(); EntityList theParentList; @@ -110,19 +110,12 @@ public class ServletModuleLinksImcs extends ServletModule { } } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); - } - catch (HTMLParseException e) { - throw new ServletModuleException(e.toString()); - } - catch (IOException e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + public void list(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { try { SimpleHash modelRoot = new SimpleHash(); @@ -197,13 +190,13 @@ public class ServletModuleLinksImcs extends ServletModule { HTMLTemplateProcessor.process(res, templateListString, modelRoot, res.getWriter(), getLocale(req)); } - catch (Exception e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } public void edit(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + throws ServletModuleExc { try { SimpleHash modelRoot = new SimpleHash(); @@ -223,8 +216,8 @@ public class ServletModuleLinksImcs extends ServletModule { deliver(req, res, modelRoot, templateObjektString); } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } diff --git a/source/mircoders/servlet/ServletModuleLocalizer.java b/source/mircoders/servlet/ServletModuleLocalizer.java index ce39a6ab..6f122b24 100755 --- a/source/mircoders/servlet/ServletModuleLocalizer.java +++ b/source/mircoders/servlet/ServletModuleLocalizer.java @@ -40,7 +40,8 @@ import javax.servlet.http.HttpSession; import mir.entity.adapter.EntityAdapter; import mir.log.LoggerWrapper; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; import mir.util.StringRoutines; import mircoders.entity.EntityComment; import mircoders.entity.EntityContent; @@ -71,14 +72,14 @@ public class ServletModuleLocalizer extends ServletModule { } } - private EntityAdapter getActiveUser(HttpServletRequest aRequest) throws ServletModuleException { + private EntityAdapter getActiveUser(HttpServletRequest aRequest) throws ServletModuleExc { try { HttpSession session = aRequest.getSession(false); return MirGlobal.localizer().dataModel().adapterModel().makeEntityAdapter ("user", (EntityUsers) session.getAttribute("login.uid")); } - catch (Exception e) { - throw new ServletModuleException("ServletModuleLocalizer.getActiveUser: " + e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure("ServletModuleLocalizer.getActiveUser: " + e.getMessage(), e); } } @@ -103,7 +104,7 @@ public class ServletModuleLocalizer extends ServletModule { } } - public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void commentoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { String commentIdString = aRequest.getParameter("id"); String operationString = aRequest.getParameter("operation"); String returnUrlString = aRequest.getParameter("returnurl"); @@ -113,7 +114,7 @@ public class ServletModuleLocalizer extends ServletModule { redirect(aResponse, returnUrlString); } - public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { String returnUrlString = aRequest.getParameter("returnurl"); String[] operations = aRequest.getParameterValues("operation"); @@ -161,7 +162,7 @@ public class ServletModuleLocalizer extends ServletModule { } } - public void articleoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void articleoperation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { String articleIdString = aRequest.getParameter("articleid"); String operationString = aRequest.getParameter("operation"); String returnUrlString = aRequest.getParameter("returnurl"); @@ -170,7 +171,7 @@ public class ServletModuleLocalizer extends ServletModule { redirect(aResponse, returnUrlString); } - public void articleoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void articleoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc { String returnUrlString = aRequest.getParameter("returnurl"); String[] operations = aRequest.getParameterValues("operation"); diff --git a/source/mircoders/servlet/ServletModuleMediafolder.java b/source/mircoders/servlet/ServletModuleMediafolder.java index 9f7a1f83..022e6be8 100755 --- a/source/mircoders/servlet/ServletModuleMediafolder.java +++ b/source/mircoders/servlet/ServletModuleMediafolder.java @@ -46,7 +46,6 @@ import javax.servlet.http.HttpServletResponse; import mir.log.LoggerWrapper; import mir.misc.StringUtil; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; import mir.storage.StorageObjectFailure; import mircoders.module.ModuleMediafolder; import mircoders.storage.DatabaseMediafolder; @@ -75,7 +74,7 @@ public class ServletModuleMediafolder extends ServletModule } } - public void add(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void add(HttpServletRequest req, HttpServletResponse res) { SimpleHash mergeData = new SimpleHash(); mergeData.put("new", "1"); diff --git a/source/mircoders/servlet/ServletModuleMessage.java b/source/mircoders/servlet/ServletModuleMessage.java index 16950c99..fbe12e93 100755 --- a/source/mircoders/servlet/ServletModuleMessage.java +++ b/source/mircoders/servlet/ServletModuleMessage.java @@ -42,7 +42,8 @@ import mir.log.LoggerWrapper; import mir.misc.HTMLTemplateProcessor; import mir.module.ModuleException; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; import mir.storage.StorageObjectFailure; import mircoders.module.ModuleMessage; import mircoders.storage.DatabaseMessages; @@ -79,11 +80,12 @@ public class ServletModuleMessage extends ServletModule } catch (StorageObjectFailure e) { logger.error("initialization of ServletModuleMessage failed!: " + e.getMessage()); + + throw new ServletModuleFailure(e); } } - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + public void list(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { // fetch and deliver try { @@ -108,9 +110,9 @@ public class ServletModuleMessage extends ServletModule HTMLTemplateProcessor.process(res, templateListString, mergeData, res.getWriter(), getLocale(req)); } - catch (ModuleException e) {throw new ServletModuleException(e.toString());} - catch (IOException e) {throw new ServletModuleException(e.toString());} - catch (Exception e) {throw new ServletModuleException(e.toString());} + catch (Throwable e) { + throw new ServletModuleFailure(e); + } } diff --git a/source/mircoders/servlet/ServletModuleOpenIndy.java b/source/mircoders/servlet/ServletModuleOpenIndy.java index 55def123..beb854b7 100755 --- a/source/mircoders/servlet/ServletModuleOpenIndy.java +++ b/source/mircoders/servlet/ServletModuleOpenIndy.java @@ -67,8 +67,9 @@ import mir.misc.StringUtil; import mir.misc.WebdbMultipartRequest; import mir.module.ModuleException; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; -import mir.servlet.ServletModuleUserException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleUserExc; +import mir.servlet.ServletModuleFailure; import mir.storage.StorageObjectFailure; import mir.util.StringRoutines; import mircoders.entity.EntityComment; @@ -121,7 +122,7 @@ import freemarker.template.TemplateModelRoot; * open-postings to the newswire * * @author mir-coders group - * @version $Id: ServletModuleOpenIndy.java,v 1.62 2003/03/05 19:23:16 idfx Exp $ + * @version $Id: ServletModuleOpenIndy.java,v 1.63 2003/03/06 05:40:40 zapata Exp $ * */ @@ -177,7 +178,8 @@ public class ServletModuleOpenIndy extends ServletModule * Method for making a comment */ - public void addcomment(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void addcomment(HttpServletRequest req, HttpServletResponse res) + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { String aid = req.getParameter("aid"); // the article id the comment will belong to String language = req.getParameter("language"); @@ -208,10 +210,10 @@ public class ServletModuleOpenIndy extends ServletModule deliver(req, res, mergeData, extraInfo, commentFormTemplate); } catch (Throwable t) { - throw new ServletModuleException("ServletModuleOpenIndy.addcomment: " + t.getMessage()); + throw new ServletModuleFailure("ServletModuleOpenIndy.addcomment: " + t.getMessage(), t); } } - else throw new ServletModuleException("aid not set!"); + else throw new ServletModuleExc("aid not set!"); } /** @@ -220,7 +222,7 @@ public class ServletModuleOpenIndy extends ServletModule */ public void inscomment(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException,ServletModuleUserException + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { String aid = req.getParameter("to_media"); // the article id the comment will belong to if (aid!=null && !aid.equals("")) @@ -244,11 +246,11 @@ public class ServletModuleOpenIndy extends ServletModule HttpSession session = req.getSession(false); String sessionPasswd = (String)session.getAttribute("passwd"); if ( sessionPasswd == null){ - throw new ServletModuleUserException("Lost password"); + throw new ServletModuleUserExc("Lost password"); } String passwd = req.getParameter("passwd"); if ( passwd == null || (!sessionPasswd.equals(passwd))) { - throw new ServletModuleUserException("Missing password"); + throw new ServletModuleUserExc("Missing password"); } session.invalidate(); } @@ -267,7 +269,7 @@ public class ServletModuleOpenIndy extends ServletModule MirGlobal.localizer().openPostings().afterCommentPosting(comment); } catch (Throwable t) { - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleExc(t.getMessage()); } } @@ -276,11 +278,11 @@ public class ServletModuleOpenIndy extends ServletModule SimpleHash mergeData = new SimpleHash(); deliver(req, res, mergeData, commentFormDoneTemplate); } - catch (StorageObjectFailure e) { throw new ServletModuleException(e.toString());} - catch (ModuleException e) { throw new ServletModuleException(e.toString());} - + catch (Throwable e) { + throw new ServletModuleFailure(e); + } } - else throw new ServletModuleException("aid not set!"); + else throw new ServletModuleExc("aid not set!"); } @@ -289,7 +291,8 @@ public class ServletModuleOpenIndy extends ServletModule */ public void addposting(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure + { SimpleHash mergeData = new SimpleHash(); // onetimepasswd @@ -331,7 +334,8 @@ public class ServletModuleOpenIndy extends ServletModule } catch (Exception e) { logger.error("languagePopUpData or getTopicslist failed "+e.toString()); - throw new ServletModuleException("OpenIndy -- failed getting language or topics: "+e.toString()); + + throw new ServletModuleFailure("OpenIndy -- failed getting language or topics: "+e.toString(), e); } @@ -345,7 +349,7 @@ public class ServletModuleOpenIndy extends ServletModule */ public void insposting(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { SimpleHash mergeData = new SimpleHash(); boolean setMedia=false; @@ -362,9 +366,7 @@ public class ServletModuleOpenIndy extends ServletModule mediaList = mediaReq.getEntityList(); } catch (FileHandlerUserException e) { - throw new ServletModuleUserException(e.getMessage()); - } catch (PropertiesConfigExc e) { - throw new ServletModuleUserException(e.getMessage()); + throw new ServletModuleFailure(e); } Map withValues = mp.getParameters(); @@ -374,11 +376,11 @@ public class ServletModuleOpenIndy extends ServletModule HttpSession session = req.getSession(false); String sessionPasswd = (String)session.getAttribute("passwd"); if ( sessionPasswd == null){ - throw new ServletModuleUserException("Lost password"); + throw new ServletModuleUserExc("Lost password"); } String passwd = (String)withValues.get("passwd"); if ( passwd == null || (!sessionPasswd.equals(passwd))) { - throw new ServletModuleUserException("Missing password"); + throw new ServletModuleUserExc("Missing password"); } session.invalidate(); } @@ -386,7 +388,7 @@ public class ServletModuleOpenIndy extends ServletModule if ((((String)withValues.get("title")).length() == 0) || (((String)withValues.get("description")).length() == 0) || (((String)withValues.get("content_data")).length() == 0)) - throw new ServletModuleUserException("Missing field"); + throw new ServletModuleUserExc("Missing field"); // call the routines that escape html @@ -447,7 +449,7 @@ public class ServletModuleOpenIndy extends ServletModule catch (Exception e) { logger.error("setting content_x_topic failed"); contentModule.deleteById(cid); - throw new ServletModuleException("smod - openindy :: insposting: setting content_x_topic failed: "+e.toString()); + throw new ServletModuleExc("smod - openindy :: insposting: setting content_x_topic failed: "+e.toString()); } //end try } //end if @@ -462,16 +464,12 @@ public class ServletModuleOpenIndy extends ServletModule (EntityContent)contentModule.getById(cid)); } catch (Throwable t) { - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } - catch (FileHandlerException e) { - e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - throw new ServletModuleException("MediaException: "+ e.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } - catch (IOException e) { throw new ServletModuleException("IOException: "+ e.getMessage());} - catch (StorageObjectFailure e) { throw new ServletModuleException("StorageObjectException" + e.getMessage());} - catch (ModuleException e) { throw new ServletModuleException("ModuleException"+e.getMessage());} deliver(req, res, mergeData, postingFormDoneTemplate); } @@ -481,10 +479,11 @@ public class ServletModuleOpenIndy extends ServletModule */ public void mail(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure + { String aid = req.getParameter("mail_aid"); if (aid == null){ - throw new ServletModuleUserException("An article id must be specified in requests to email an article. Something therefore went badly wrong...."); + throw new ServletModuleUserExc("An article id must be specified in requests to email an article. Something therefore went badly wrong...."); } String to = req.getParameter("mail_to"); @@ -508,7 +507,7 @@ public class ServletModuleOpenIndy extends ServletModule else { //run checks on to and from and mail_language to make sure no monkey business occurring if (mail_language.indexOf('.') != -1 || mail_language.indexOf('/') != -1 ){ - throw new ServletModuleUserException("Sorry, you've entered an illegal character into the language field. Go back and try again, asshole."); + throw new ServletModuleUserExc("Sorry, you've entered an illegal character into the language field. Go back and try again, asshole."); } if (to.indexOf('\n') != -1 || to.indexOf('\r') != -1 @@ -516,14 +515,14 @@ public class ServletModuleOpenIndy extends ServletModule || from.indexOf('\n') != -1 || from.indexOf('\r') != -1 || from.indexOf(',') != -1 ){ - throw new ServletModuleUserException("Sorry, you've entered an illegal character into the from or to field. Go back and try again."); + throw new ServletModuleUserExc("Sorry, you've entered an illegal character into the from or to field. Go back and try again."); } EntityContent contentEnt; try{ contentEnt = (EntityContent)contentModule.getById(aid); } - catch (ModuleException e){ - throw new ServletModuleUserException("Couldn't get content for article "+aid); + catch (Throwable e){ + throw new ServletModuleFailure("Couldn't get content for article "+aid + ": " + e.getMessage(), e); } String producerStorageRoot=configuration.getString("Producer.StorageRoot"); String producerDocRoot=configuration.getString("Producer.DocRoot"); @@ -545,10 +544,10 @@ public class ServletModuleOpenIndy extends ServletModule content= out.toString(); } catch (FileNotFoundException e){ - throw new ServletModuleUserException("No text file found in " + txtFilePath); + throw new ServletModuleFailure("No text file found in " + txtFilePath, e); } catch (IOException e){ - throw new ServletModuleUserException("Problem reading file in " + txtFilePath); + throw new ServletModuleFailure("Problem reading file in " + txtFilePath, e); } // add some headers content = "To: " + to + "\nReply-To: "+ from + "\n" + content; @@ -558,16 +557,16 @@ public class ServletModuleOpenIndy extends ServletModule try { content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",commentTextToInsert); } - catch (Exception e){ - throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString()); + catch (Throwable e){ + throw new ServletModuleFailure("Problem doing regular expression replacement " + e.toString(), e); } } else{ try { content=StringRoutines.performRegularExpressionReplacement(content,"!COMMENT!",""); } - catch (Exception e){ - throw new ServletModuleUserException("Problem doing regular expression replacement " + e.toString()); + catch (Throwable e){ + throw new ServletModuleFailure("Problem doing regular expression replacement " + e.toString(), e); } } @@ -580,7 +579,7 @@ public class ServletModuleOpenIndy extends ServletModule if (!SMTPReply.isPositiveCompletion(reply)) { client.disconnect(); - throw new ServletModuleUserException("SMTP server refused connection."); + throw new ServletModuleExc("SMTP server refused connection."); } client.sendSimpleMessage(configuration.getString("ServletModule.OpenIndy.EmailIsFrom"), to, content); @@ -597,7 +596,7 @@ public class ServletModuleOpenIndy extends ServletModule // do nothing } } - throw new ServletModuleUserException(e.toString()); + throw new ServletModuleFailure(e); } } } @@ -607,7 +606,7 @@ public class ServletModuleOpenIndy extends ServletModule * Method for querying a lucene index */ public void search(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { int increment=10; @@ -715,7 +714,7 @@ public class ServletModuleOpenIndy extends ServletModule } catch(IOException e) { logger.debug("Can't open indexPath: " + indexPath); - throw new ServletModuleUserException("Problem with Search Index! : "+ e.toString()); + throw new ServletModuleExc("Problem with Search Index! : "+ e.toString()); } Query query = null; @@ -725,7 +724,7 @@ public class ServletModuleOpenIndy extends ServletModule catch(Exception e) { searcher.close(); logger.debug("Query don't parse: " + queryString); - throw new ServletModuleUserException("Problem with Query String! (was '"+queryString+"')"); + throw new ServletModuleExc("Problem with Query String! (was '"+queryString+"')"); } Hits hits = null; @@ -735,7 +734,7 @@ public class ServletModuleOpenIndy extends ServletModule catch(IOException e) { searcher.close(); logger.debug("Can't get hits: " + e.toString()); - throw new ServletModuleUserException("Problem getting hits!"); + throw new ServletModuleExc("Problem getting hits!"); } int start = 0; @@ -743,7 +742,7 @@ public class ServletModuleOpenIndy extends ServletModule String sortBy=req.getParameter("search_sort"); if (sortBy == null || sortBy.equals("")){ - throw new ServletModuleUserException("Please let me sort by something!(missing search_sort)"); + throw new ServletModuleExc("Please let me sort by something!(missing search_sort)"); } // here is where the documents will go for storage across sessions @@ -777,7 +776,7 @@ public class ServletModuleOpenIndy extends ServletModule } else{ if (!sortBy.equals("date_asc")){ - throw new ServletModuleUserException("don't know how to sort by: "+ sortBy); + throw new ServletModuleExc("don't know how to sort by: "+ sortBy); } } ListIterator keyTraverser = keyList.listIterator(); @@ -795,7 +794,7 @@ public class ServletModuleOpenIndy extends ServletModule } catch (IOException e){ logger.debug("Can't close searcher: " + e.toString()); - throw new ServletModuleUserException("Problem closing searcher(normal)!"); + throw new ServletModuleFailure("Problem closing searcher(normal):" + e.getMessage(), e); } @@ -810,7 +809,7 @@ public class ServletModuleOpenIndy extends ServletModule } catch (IOException e){ logger.debug("Can't close searcher: " + e.toString()); - throw new ServletModuleUserException("Problem closing searcher!"); + throw new ServletModuleFailure("Problem closing searcher: " + e.getMessage(), e); } } } @@ -855,17 +854,17 @@ public class ServletModuleOpenIndy extends ServletModule mergeData.put("hits",theHits); } } - catch (Exception e) { - logger.debug("Can't iterate over hits: " + e.toString()); - throw new ServletModuleUserException("Problem getting hits!"); + catch (Throwable e) { + logger.error("Can't iterate over hits: " + e.toString()); + + throw new ServletModuleFailure("Problem getting hits: " + e.getMessage(), e); } mergeData.put("queryString",queryString); deliver(req,res,mergeData,searchResultsTemplate); } catch (NullPointerException n){ - n.printStackTrace(); - throw new ServletModuleUserException("Null Pointer"+n.toString()); + throw new ServletModuleFailure("Null Pointer: "+n.toString(), n); } } @@ -873,7 +872,7 @@ public class ServletModuleOpenIndy extends ServletModule * Method for dynamically generating a pdf from a fo file */ public void getpdf(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { String ID_REQUEST_PARAM = "id"; String language = req.getParameter("language"); String generateFO=configuration.getString("GenerateFO"); @@ -926,24 +925,26 @@ public class ServletModuleOpenIndy extends ServletModule res.setContentLength(content.length); res.getOutputStream().write(content); res.getOutputStream().flush(); - } else { - throw new ServletModuleUserException("Missing id parameter."); } - } catch (Exception ex) { + else { + throw new ServletModuleUserExc("Missing id parameter."); + } + } + catch (Exception ex) { logger.error(ex.toString()); - throw new ServletModuleException(ex.toString()); + throw new ServletModuleFailure(ex); } } else { - throw new ServletModuleUserException("Can't generate a PDF because the config tells me not to."); + throw new ServletModuleExc("Can't generate a PDF because the config tells me not to."); } } private void _throwBadContentType (String fileName, String contentType) - throws ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { logger.error("Wrong file type uploaded!: " + fileName+" " +contentType); - throw new ServletModuleUserException("The file you uploaded is of the " + throw new ServletModuleUserExc("The file you uploaded is of the " +"following mime-type: "+contentType +", we do not support this mime-type. " +"Error One or more files of unrecognized type. Sorry"); @@ -964,18 +965,17 @@ public class ServletModuleOpenIndy extends ServletModule to use different bundles for open and admin */ public void deliver(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot rtm, TemplateModelRoot popups, - String templateFilename) - throws ServletModuleException { + String templateFilename) throws ServletModuleFailure + { if (rtm == null) rtm = new SimpleHash(); try { PrintWriter out = res.getWriter(); HTMLTemplateProcessor.process(res, templateFilename, rtm, popups, out, getLocale(req), "bundles.open"); out.close(); - } catch (HTMLParseException e) { - throw new ServletModuleException(e.toString()); - } catch (IOException e) { - throw new ServletModuleException(e.toString()); + } + catch (Throwable e) { + throw new ServletModuleFailure(e); } } } diff --git a/source/mircoders/servlet/ServletModuleProducer.java b/source/mircoders/servlet/ServletModuleProducer.java index cdebe680..0fe5755e 100755 --- a/source/mircoders/servlet/ServletModuleProducer.java +++ b/source/mircoders/servlet/ServletModuleProducer.java @@ -46,7 +46,8 @@ import mir.generator.Generator; import mir.log.LoggerWrapper; import mir.producer.ProducerFactory; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleFailure; import mir.util.NullWriter; import mir.util.ResourceBundleGeneratorFunction; import mircoders.global.MirGlobal; @@ -64,7 +65,7 @@ public class ServletModuleProducer extends ServletModule int totalNrComments; List producersData; - void generateResponse(String aGeneratorIdentifier, PrintWriter aWriter, Map aResponseData, Locale aLocale) throws ServletModuleException { + void generateResponse(String aGeneratorIdentifier, PrintWriter aWriter, Map aResponseData, Locale aLocale) { try { generator = MirGlobal.localizer().generators().makeAdminGeneratorLibrary().makeGenerator(aGeneratorIdentifier); MirGlobal.localizer().producerAssistant().initializeGenerationValueSet(aResponseData); @@ -72,7 +73,7 @@ public class ServletModuleProducer extends ServletModule generator.generate(aWriter, aResponseData, new PrintWriter(new NullWriter())); } catch (Throwable t) { - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } @@ -82,7 +83,7 @@ public class ServletModuleProducer extends ServletModule defaultAction="showProducerQueueStatus"; } - public void showMessage(PrintWriter aWriter, Locale aLocale, String aMessage, String anArgument1, String anArgument2) throws ServletModuleException { + public void showMessage(PrintWriter aWriter, Locale aLocale, String aMessage, String anArgument1, String anArgument2) { Map responseData; try { responseData = new HashMap(); @@ -92,12 +93,12 @@ public class ServletModuleProducer extends ServletModule generateResponse("infomessage.template", aWriter, responseData, aLocale); } catch (Throwable t) { - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } - public void showProducerQueueStatus(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void showProducerQueueStatus(HttpServletRequest aRequest, HttpServletResponse aResponse) { Object comments; Map generationData; Generator generator; @@ -138,12 +139,11 @@ public class ServletModuleProducer extends ServletModule generator.generate(aResponse.getWriter(), generationData, new PrintWriter(new NullWriter())); } catch (Throwable t) { - t.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE)); - throw new ServletModuleException(t.getMessage()); + throw new ServletModuleFailure(t); } } - public void produce(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { + public void produce(HttpServletRequest req, HttpServletResponse res) { /* * This method will only be called by external scripts (e.g. from cron jobs). * The output therefore is very simple. @@ -161,22 +161,22 @@ public class ServletModuleProducer extends ServletModule out.println("job added"); } } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable t) { + throw new ServletModuleFailure(t); } } - public void produceAllNew(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void produceAllNew(HttpServletRequest aRequest, HttpServletResponse aResponse) { try { MirGlobal.localizer().producers().produceAllNew(); showMessage(aResponse.getWriter(), getLocale(aRequest), "produceAllNewAddedToQueue", "", ""); } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable t) { + throw new ServletModuleFailure(t); } } - public void enqueue(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void enqueue(HttpServletRequest aRequest, HttpServletResponse aResponse) { try { if (aRequest.getParameter("producer")!=null) { String producerParam = aRequest.getParameter("producer"); @@ -187,12 +187,12 @@ public class ServletModuleProducer extends ServletModule showProducerQueueStatus(aRequest, aResponse); } } - catch (Exception e) { - throw new ServletModuleException(e.getMessage()); + catch (Throwable t) { + throw new ServletModuleFailure(t); } } - public void cancelAbortJob(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException { + public void cancelAbortJob(HttpServletRequest aRequest, HttpServletResponse aResponse) { // ML: to be coded } } diff --git a/source/mircoders/servlet/ServletModuleUploadedMedia.java b/source/mircoders/servlet/ServletModuleUploadedMedia.java index 6e0275b0..2ba86132 100755 --- a/source/mircoders/servlet/ServletModuleUploadedMedia.java +++ b/source/mircoders/servlet/ServletModuleUploadedMedia.java @@ -55,8 +55,9 @@ import mir.misc.FileHandlerUserException; import mir.misc.WebdbMultipartRequest; import mir.module.ModuleException; import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; -import mir.servlet.ServletModuleUserException; +import mir.servlet.ServletModuleExc; +import mir.servlet.ServletModuleUserExc; +import mir.servlet.ServletModuleFailure; import mir.storage.StorageObjectFailure; import mircoders.entity.EntityContent; import mircoders.entity.EntityUploadedMedia; @@ -71,7 +72,7 @@ import freemarker.template.SimpleList; * ServletModuleBilder - * liefert HTML fuer Bilder * - * @version $Id: ServletModuleUploadedMedia.java,v 1.18 2003/03/05 19:23:17 idfx Exp $ + * @version $Id: ServletModuleUploadedMedia.java,v 1.19 2003/03/06 05:40:40 zapata Exp $ * @author RK, the mir-coders group */ @@ -90,7 +91,7 @@ public abstract class ServletModuleUploadedMedia } public void insert(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException, ServletModuleUserException { + throws ServletModuleExc, ServletModuleUserExc { try { EntityUsers user = _getUser(req); MediaRequest mediaReq = new MediaRequest(user.getId(), false); @@ -134,28 +135,26 @@ public abstract class ServletModuleUploadedMedia } catch (FileHandlerUserException e) { logger.error("ServletModuleUploadedMedia.insert: " + e.getMessage()); - throw new ServletModuleUserException(e.getMessage()); + throw new ServletModuleUserExc(e.getMessage()); } catch (FileHandlerException e) { - throw new ServletModuleException( - "upload -- media handling exception " + e.toString()); + throw new ServletModuleFailure("upload -- media handling exception " + e.toString(), e); } catch (StorageObjectFailure e) { - throw new ServletModuleException("upload -- storageobjectexception " - + e.toString()); + throw new ServletModuleFailure("upload -- storageobjectexception " + e.toString(), e); } catch (IOException e) { - throw new ServletModuleException("upload -- ioexception " + e.toString()); + throw new ServletModuleFailure("upload -- ioexception " + e.toString(), e); } catch (PropertiesConfigExc e) { - throw new ServletModuleException("upload -- configexception " + e.toString()); + throw new ServletModuleFailure("upload -- configexception " + e.toString(), e); } catch (Throwable t) { - throw new ServletModuleException("upload -- exception " + t.toString()); + throw new ServletModuleFailure("upload -- exception " + t.toString(), t); } } - public void update(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException { + public void update(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { try { EntityUsers user = _getUser(req); @@ -171,21 +170,14 @@ public abstract class ServletModuleUploadedMedia logger.debug("update: media ID = " + id); _edit(id, req, res); } - catch (IOException e) { - throw new ServletModuleException("upload -- ioexception " + e.toString()); - } - catch (ModuleException e) { - throw new ServletModuleException("upload -- moduleexception " + e.toString()); - } - catch (Exception e) { - throw new ServletModuleException("upload -- exception " + e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure("upload -- exception " + e.toString(), e); } } - public void list(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + public void list(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { // Parameter auswerten SimpleHash mergeData = new SimpleHash(); SimpleHash popups = new SimpleHash(); @@ -252,17 +244,13 @@ public abstract class ServletModuleUploadedMedia deliver(req, res, mergeData, popups, templateListString); } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); - } - catch (Exception e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } - public void add(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + public void add(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { try { SimpleHash mergeData = new SimpleHash(); SimpleHash popups = new SimpleHash(); @@ -290,19 +278,18 @@ public abstract class ServletModuleUploadedMedia mergeData.put("medianum",numOfMedia); mergeData.put("mediafields",mediaFields); deliver(req, res, mergeData, popups, templateObjektString); - } catch (Exception e) { - throw new ServletModuleException(e.toString()); + } + catch (Exception e) { + throw new ServletModuleFailure(e); } } - public void edit(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String idParam = req.getParameter("id"); _edit(idParam, req, res); } - private void _edit(String idParam, HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException { + private void _edit(String idParam, HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { if (idParam != null && !idParam.equals("")) { try { SimpleHash popups = new SimpleHash(); @@ -310,15 +297,12 @@ public abstract class ServletModuleUploadedMedia deliver(req, res, mainModule.getById(idParam), popups, templateObjektString); } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); - } - catch (StorageObjectFailure e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } else { - throw new ServletModuleException("ServletmoduleUploadedMedia :: _edit without id"); + throw new ServletModuleExc("ServletmoduleUploadedMedia :: _edit without id"); } } @@ -329,8 +313,7 @@ public abstract class ServletModuleUploadedMedia return (EntityUsers) session.getAttribute("login.uid"); } - public void getMedia(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + public void getMedia(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String idParam = req.getParameter("id"); if (idParam!=null && !idParam.equals("")) { @@ -358,22 +341,15 @@ public abstract class ServletModuleUploadedMedia out.close(); } - catch (IOException e) { - throw new ServletModuleException(e.toString()); - } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); - } - catch (Exception e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } else logger.error("id not specified."); // no exception allowed } - public void getIcon(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + public void getIcon(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String idParam = req.getParameter("id"); if (idParam!=null && !idParam.equals("")) { @@ -401,14 +377,8 @@ public abstract class ServletModuleUploadedMedia out.close(); } - catch (IOException e) { - throw new ServletModuleException(e.toString()); - } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); - } - catch (Exception e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } else logger.error("getIcon: id not specified."); diff --git a/source/mircoders/servlet/ServletModuleUsers.java b/source/mircoders/servlet/ServletModuleUsers.java index 5955b05c..09b3ebcf 100755 --- a/source/mircoders/servlet/ServletModuleUsers.java +++ b/source/mircoders/servlet/ServletModuleUsers.java @@ -38,9 +38,7 @@ import javax.servlet.http.HttpServletResponse; import mir.log.LoggerWrapper; import mir.module.ModuleException; -import mir.servlet.ServletModule; -import mir.servlet.ServletModuleException; -import mir.servlet.ServletModuleUserException; +import mir.servlet.*; import mir.storage.StorageObjectFailure; import mir.util.HTTPRequestParser; import mircoders.module.ModuleUsers; @@ -76,33 +74,35 @@ public class ServletModuleUsers extends ServletModule } } - public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleException + public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc { String idParam = req.getParameter("id"); if (idParam == null) - throw new ServletModuleException("ServletModuleUser.edit: invalid call: (id) not specified"); + throw new ServletModuleExc("ServletModuleUser.edit: invalid call: (id) not specified"); try { deliver(req, res, mainModule.getById(idParam), templateObjektString); } - catch (ModuleException e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } public void add(HttpServletRequest req, HttpServletResponse res) - throws ServletModuleException + throws ServletModuleExc { try { SimpleHash mergeData = new SimpleHash(); mergeData.put("new", "1"); deliver(req, res, mergeData, templateObjektString); } - catch (Exception e) { throw new ServletModuleException(e.toString());} + catch (Throwable e) { + throw new ServletModuleFailure(e); + } } - public String checkPassword(HTTPRequestParser aRequestParser) throws ServletModuleException, ServletModuleUserException + public String checkPassword(HTTPRequestParser aRequestParser) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { if ( (aRequestParser.getParameter("newpassword") != null && aRequestParser.getParameter("newpassword").length() > 0) || @@ -113,13 +113,11 @@ public class ServletModuleUsers extends ServletModule String newPassword2 = aRequestParser.getParameterWithDefault("newpassword2", ""); if (newPassword.length() == 0 || newPassword2.length() == 0) { - throw new ServletModuleUserException( - "The new password must be entered twice!"); + throw new ServletModuleUserExc("The new password must be entered twice!"); } if (!newPassword.equals(newPassword2)) { - throw new ServletModuleUserException( - "New password differes from confirmation"); + throw new ServletModuleUserExc("New password differes from confirmation"); } return newPassword; @@ -129,7 +127,7 @@ public class ServletModuleUsers extends ServletModule } public void insert(HttpServletRequest aRequest, HttpServletResponse aResponse) - throws ServletModuleException + throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); @@ -139,7 +137,7 @@ public class ServletModuleUsers extends ServletModule if (newPassword!=null) withValues.put("password", newPassword); else - throw new ServletModuleUserException("Password is empty"); + throw new ServletModuleUserExc("Password is empty"); String id = mainModule.add(withValues); if (requestParser.hasParameter("returnurl")) @@ -147,12 +145,12 @@ public class ServletModuleUsers extends ServletModule else list(aRequest, aResponse); } - catch (Exception e) { - throw new ServletModuleException(e.toString()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } } - public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleException, ServletModuleUserException + public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure { try { HTTPRequestParser requestParser = new HTTPRequestParser(aRequest); @@ -170,10 +168,9 @@ public class ServletModuleUsers extends ServletModule else list(aRequest, aResponse); } - catch (Throwable t) { - throw new ServletModuleException("ServletModuleUsers: " + t.getMessage()); + catch (Throwable e) { + throw new ServletModuleFailure(e); } - } diff --git a/source/mircoders/storage/DatabaseContentToMedia.java b/source/mircoders/storage/DatabaseContentToMedia.java index 5c32f72b..5f98ad69 100755 --- a/source/mircoders/storage/DatabaseContentToMedia.java +++ b/source/mircoders/storage/DatabaseContentToMedia.java @@ -48,7 +48,7 @@ import mircoders.entity.EntityUploadedMedia; * implements abstract DB connection to the content_x_media SQL table * * @author RK, mir-coders group - * @version $Id: DatabaseContentToMedia.java,v 1.14 2003/03/05 19:23:17 idfx Exp $ + * @version $Id: DatabaseContentToMedia.java,v 1.15 2003/03/06 05:40:40 zapata Exp $ * */ @@ -239,10 +239,8 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ "id"); } catch (Exception e) { - e.printStackTrace(); logger.error("DatabaseContentToMedia.getOther: " + e.toString()); - throw new StorageObjectFailure("DatabaseContentToMedia.getOther: " + - e.toString(), e); + throw new StorageObjectFailure("DatabaseContentToMedia.getOther: " + e.toString(), e); } } return returnList; @@ -270,7 +268,6 @@ public class DatabaseContentToMedia extends Database implements StorageObject{ "id"); } catch (Exception e) { - e.printStackTrace(); logger.error("DatabaseContentToMedia.getUploadedMedia: " + e.toString()); throw new StorageObjectFailure( "DatabaseContentToMedia.getUploadedMedia: " + e.toString(), e); -- 2.11.0