KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > applications > actions > ErrorPageAction


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23
24
25 package org.infoglue.deliver.applications.actions;
26
27 import javax.servlet.RequestDispatcher JavaDoc;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29
30 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
31 import org.infoglue.cms.util.CmsPropertyHandler;
32
33
34 /**
35  * This is an error page action. Used to send out the right error codes and the right html
36  *
37  * @author Mattias Bogeblad
38  */

39
40 public class ErrorPageAction extends InfoGlueAbstractAction
41 {
42     private int responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
43     
44     /**
45      * This is the excecute method - it will send the right error codes and also show the right error message.
46      */

47     
48     public String JavaDoc doExecute() throws Exception JavaDoc
49     {
50         String JavaDoc responseCodeAttribute = (String JavaDoc)this.getRequest().getAttribute("responseCode");
51         if(responseCodeAttribute != null)
52             responseCode = Integer.parseInt(responseCodeAttribute);
53         
54         String JavaDoc responseCodeParameter = (String JavaDoc)this.getRequest().getParameter("responseCode");
55         if(responseCodeParameter != null)
56             responseCode = Integer.parseInt(responseCodeParameter);
57
58         Exception JavaDoc e = (Exception JavaDoc)this.getRequest().getAttribute("error");
59         if(e != null)
60         {
61             setError(e, e.getCause());
62         }
63                 
64         this.getResponse().setContentType("text/html; charset=UTF-8");
65         this.getResponse().setStatus(responseCode);
66
67         String JavaDoc errorUrl = CmsPropertyHandler.getErrorUrl();
68         if(errorUrl != null && errorUrl.indexOf("@errorUrl@") == -1)
69         {
70             if(errorUrl.indexOf("http") > -1)
71                 this.getResponse().sendRedirect(errorUrl);
72             else
73             {
74                 RequestDispatcher JavaDoc dispatch = this.getRequest().getRequestDispatcher(errorUrl);
75                 this.getRequest().setAttribute("error", e);
76                 //dispatch.forward(this.getRequest(), this.getResponse());
77
dispatch.include(this.getRequest(), this.getResponse());
78             }
79             
80             return NONE;
81         }
82         else
83             return SUCCESS;
84     }
85
86     /**
87      * This is the busy method - it will send the right error codes and also show the right error message.
88      */

89     
90     public String JavaDoc doBusy() throws Exception JavaDoc
91     {
92         String JavaDoc responseCodeAttribute = (String JavaDoc)this.getRequest().getAttribute("responseCode");
93         if(responseCodeAttribute != null)
94             responseCode = Integer.parseInt(responseCodeAttribute);
95         
96         String JavaDoc responseCodeParameter = (String JavaDoc)this.getRequest().getParameter("responseCode");
97         if(responseCodeParameter != null)
98             responseCode = Integer.parseInt(responseCodeParameter);
99
100         Exception JavaDoc e = (Exception JavaDoc)this.getRequest().getAttribute("error");
101         if(e != null)
102         {
103             setError(e, e.getCause());
104         }
105                 
106         this.getResponse().setContentType("text/html; charset=UTF-8");
107         this.getResponse().setStatus(responseCode);
108
109         String JavaDoc errorUrl = CmsPropertyHandler.getErrorBusyUrl();
110         if(errorUrl != null && errorUrl.indexOf("@errorBusyUrl@") == -1)
111         {
112             if(errorUrl.indexOf("http") > -1)
113                 this.getResponse().sendRedirect(errorUrl);
114             else
115             {
116                 RequestDispatcher JavaDoc dispatch = this.getRequest().getRequestDispatcher(errorUrl);
117                 this.getRequest().setAttribute("error", e);
118                 //dispatch.forward(this.getRequest(), this.getResponse());
119
dispatch.include(this.getRequest(), this.getResponse());
120             }
121             
122             return NONE;
123         }
124         else
125             return SUCCESS;
126     }
127
128     public int getResponseCode()
129     {
130         return responseCode;
131     }
132 }
133
Popular Tags