⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiaerrordisplay.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// $Id: JahiaErrorDisplay.java,v 1.5 2002/11/22 18:34:13 shuber Exp $////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////package org.jahia.bin;/** * Title:        Jahia * desc:  Portal & Publishing server project by Jahia * Copyright:    Copyright (c) 2002 * Company:      Jahia Ltd * @author Serge Huber * @version 1.0 */import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import java.net.InetAddress;import java.util.Properties;import java.util.Date;import java.util.Enumeration;import javax.mail.*;import javax.mail.internet.*;import org.jahia.settings.*;import org.jahia.exceptions.*;import java.lang.reflect.*;import org.jahia.utils.JahiaConsole;/** * This class is in charge of generating output to the client of error messages. * It is kept simple because it's aim is to be quite solid, and this is easier to * achieve by keeping it minimal. It includes a hardcoded HTML display method in * the case where a dispatching ressource is not available (such as an error in * the configuration of Jahia). * * When throwing a JahiaException, if its "userErrorMsg" message starts with an integer, * ie. "404 Page not found" then this class forwards the error to the "404.jsp" page * if found in the errors directory. For details about those error codes, * see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10">RFC 2616</a> */public class JahiaErrorDisplay {    private static final String DISPATCH_DESTINATION = "/jsp/jahia/errors/error.jsp";    private	static final String DISPATCH_DIRECTORY = "/jsp/jahia/errors/";    private static final String DISPATCH_PREFIX="error_";    private static final boolean IS_STACK_INCLUDED = true;    static {        JahiaConsole.println("JahiaErrorDisplay.staticConstructor",                             "Initialized with destination = [" +                             DISPATCH_DESTINATION + "]");    }    public JahiaErrorDisplay() {    }    /**     * This is a fallback method that is called in the case where the dispatching     * to a ressource is not possible. It is hardcoded in order to be as failproof     * as possible.     */    public static boolean HTMLFallBackDisplay(HttpServletRequest request, HttpServletResponse response, Throwable t) {        PrintWriter out = null;        try {            out = response.getWriter();        } catch (Throwable newt) {            return false;        }        if (out != null) {            /** @todo : fixme : this is not update to date with the lastest             *  chaining stuff             */            out.println("<html>");            out.println("  <head>");            out.println("    <title>Jahia Error</title>");            out.println("  </head>");            out.println("  <body>");            out.println("  <table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");            out.println("    <tr>");            out.println("      <td colspan=\"2\"><h1>Jahia Error</h1></td>");            out.println("    </tr>");            out.println("    <tr>");            out.println("      <td colspan=\"2\">An error has occured while Jahia was processing data. Consult the info below for more precise information</td>");            out.println("    </tr>");            out.println("    <tr>");            out.println("      <td>Exception :</td>");            out.println("      <td>" + t.getMessage() + "</td>");            out.println("    </tr>");            if (IS_STACK_INCLUDED) {                out.println("    <tr>");                out.println("      <td>Stack trace : </td>");                out.println("      <td><pre>");                String stackTraceStr = stackTraceToString(t);                out.println(stackTraceStr);                out.println("      </pre></td>");                out.println("    </tr>");            }            out.println("  </table>");            out.println("  </body>");            out.println("</html>");        } else {            ;        }        return false;    }    public static boolean DisplayException(HttpServletRequest request,                                           HttpServletResponse response,                                           ServletContext context,                                           Throwable t) {        return DisplayException(request, response, context, null, t);    }    /**     * Displays an exception on a HTML browser using either JSP pages or     * static hardcoded HTML output. Also sends out an email to the administrator     * is this feature was activated.     *     */    public static boolean DisplayException(HttpServletRequest request,                                           HttpServletResponse response,                                           ServletContext context,                                           JahiaPrivateSettings jSettings,                                           Throwable t) {        try {            if ((request == null) ||                (response == null) ||                (context == null) ||                (t == null)) {                JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                     "Can't display exception, not enough information available...");                return false;            }            // let's log the exception in Tomcat's log system.            context.log(throwableToString(t, request, response));            if (response.isCommitted()) {                JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                     "Response already committed, aborting client display, exception has been logged...");                return false;            }            if (t instanceof JahiaException) {                JahiaException je = (JahiaException) t;                JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                     "ERROR : " + je.getUserErrorMsg() +                                     ", " + je.getJahiaErrorMsg());                JahiaConsole.printe("JahiaErrorDisplay.DisplayException",                                    t);            } else {                JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                     "ERROR : "+t.getMessage());                JahiaConsole.printe("JahiaErrorDisplay.DisplayException",                                    t);            }            // By default, uses the standard error message            String fullPathToDestination = context.getRealPath(DISPATCH_DESTINATION);            String contextPathToDestination = DISPATCH_DESTINATION;            File jspFile = new File(fullPathToDestination);            File jspFileErrorCode = null;            // check if error contains a standard HTTP/1.1 error code, if so, tries to forward to            // the corresponding JSP            String	errorstring = "";            try {                errorstring = t.getMessage().trim();            } catch (Throwable tho) {}            int		errorint = 0;            try            {                if (errorstring.indexOf(" ")!=-1) {                    errorstring = errorstring.substring (0, errorstring.indexOf(" "));                }            } catch (IndexOutOfBoundsException ioobe) {}            try {                errorint = Integer.parseInt(errorstring);            } catch (NumberFormatException nfe) {}              catch (Throwable th) {}            // yes the error string contains an error code! let's specify the special jsp!            if (errorint!=0)            {                response.setStatus(errorint);  // sets response status                fullPathToDestination = context.getRealPath (DISPATCH_DIRECTORY + DISPATCH_PREFIX + errorint + ".jsp");                jspFileErrorCode = new File(fullPathToDestination);                if (jspFileErrorCode.exists())                    {   jspFile = jspFileErrorCode;                        contextPathToDestination = DISPATCH_DIRECTORY + DISPATCH_PREFIX + errorint + ".jsp";                        JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                "Forwarding error to "+fullPathToDestination);                    } else 	{                        JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                "Dispatcher not found at "+fullPathToDestination+ " - using standard error");                    }            }            if (jSettings != null) {                JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                     "Jahia Settings available, mailing...");                MailException(t, request, response, jSettings, errorint);            } else {                JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                     "No Jahia Settings, can't mail...");            }            JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                 "context is : "+contextPathToDestination);            // forwards to the jsp            if (jspFile.exists()) {                RequestDispatcher dispatcher = context.getRequestDispatcher( contextPathToDestination );                if (dispatcher != null) {                    request.setAttribute("org.jahia.exception.Message", t.getMessage());                    if (IS_STACK_INCLUDED) {                        String stackTraceStr = stackTraceToString(t);                        request.setAttribute("org.jahia.exception.StackTrace", stackTraceStr);                    }                    dispatcher.forward(request, response);                    return true;                } else {                    return HTMLFallBackDisplay(request, response, t);                }            } else {                JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                     "JSP file " + fullPathToDestination +                                     " not found, defaulting to built-in message generator");                return HTMLFallBackDisplay(request, response, t);            }        } catch (ServletException se) {            JahiaConsole.println("JahiaErrorDisplay.DisplayException",                                 "JSP caused a Servlet Exception : " + se.getMessage());            JahiaConsole.printe("JahiaErrorDisplay.DisplayException", se);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -