KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > system > SystemStatusFilter


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created August, 2006
14  * @author Marc Batchelor
15  *
16  */

17 package org.pentaho.core.system;
18
19 import java.io.IOException JavaDoc;
20
21 import javax.servlet.Filter JavaDoc;
22 import javax.servlet.FilterChain JavaDoc;
23 import javax.servlet.FilterConfig JavaDoc;
24 import javax.servlet.RequestDispatcher JavaDoc;
25 import javax.servlet.ServletException JavaDoc;
26 import javax.servlet.ServletRequest JavaDoc;
27 import javax.servlet.ServletResponse JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29
30
31 /**
32  * The purpose of this filter is to check to make sure that the platform is
33  * properly initialized before letting requests in.
34  *
35  */

36 public class SystemStatusFilter implements Filter JavaDoc {
37
38   private String JavaDoc redirectToOnInitError;
39   private boolean systemInitializedOk;
40   
41   public void init(FilterConfig JavaDoc filterConfig) throws ServletException JavaDoc {
42     String JavaDoc failurePage = filterConfig.getInitParameter("initFailurePage"); //$NON-NLS-1$
43
if ( (failurePage == null) || (failurePage.length() == 0)) {
44       failurePage = "InitFailure"; //$NON-NLS-1$
45
}
46     redirectToOnInitError = "/" + failurePage; //$NON-NLS-1$
47
systemInitializedOk = PentahoSystem.getInitializedOK();
48   }
49
50   public void doFilter(ServletRequest JavaDoc request, ServletResponse JavaDoc response,
51       FilterChain JavaDoc filterChain) throws IOException JavaDoc, ServletException JavaDoc {
52     if (systemInitializedOk) {
53       filterChain.doFilter(request, response);
54     } else {
55       HttpServletRequest JavaDoc req = (HttpServletRequest JavaDoc)request;
56       if (req.getServletPath().endsWith(redirectToOnInitError)) {
57         filterChain.doFilter(request, response);
58       } else {
59         RequestDispatcher JavaDoc dispatcher = request.getRequestDispatcher(redirectToOnInitError);
60         dispatcher.forward(request, response);
61       }
62     }
63   }
64
65   public void destroy() {
66   }
67
68 }
69
Popular Tags