KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > www > WebUIDispatchServlet


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: WebUIDispatchServlet.java,v 1.10 2007/01/07 06:14:09 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21  
22 package org.opensubsystems.core.www;
23
24 import java.io.IOException JavaDoc;
25
26 import javax.servlet.ServletConfig JavaDoc;
27 import javax.servlet.ServletException JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30
31 import org.opensubsystems.core.error.OSSException;
32
33 /**
34  * This is a simple servlet which doesn't do anything else but redirects the
35  * request to specified JSP page or some other destination. Since it is derived
36  * from WebUIServlet/WebSessionServlet it is ensured that the security is taken
37  * care of before the page is displayed. This is usueful if we have some pages
38  * which are very simple and doesn't require logic or pages, for which the logic
39  * doesn't exist yet, for example when demo application is being created.
40  *
41  * @version $Id: WebUIDispatchServlet.java,v 1.10 2007/01/07 06:14:09 bastafidli Exp $
42  * @author Miro Halas
43  * @code.reviewer Miro Halas
44  * @code.reviewed 1.8 2006/04/29 00:25:48 jlegeny
45  */

46 public class WebUIDispatchServlet extends WebUIServlet
47 {
48    // Configuration settings ///////////////////////////////////////////////////
49

50    /**
51     * Name of the property for page which should be displayed upon request.
52     */

53    public static final String JavaDoc DISPATCH_PAGE = "dispatch.page";
54    
55    // Constants ////////////////////////////////////////////////////////////////
56

57    /**
58     * Names of the current domain parameter.
59     */

60    public static final String JavaDoc ACTIVE_MODULE_NAME = "activemodule";
61
62    // Attributes ///////////////////////////////////////////////////////////////
63

64    /**
65     * Generated serial version id for this class.
66     */

67    private static final long serialVersionUID = 322547463691937622L;
68
69    // Public methods ///////////////////////////////////////////////////////////
70

71    /**
72     * {@inheritDoc}
73     */

74    public void init(
75       ServletConfig JavaDoc scConfig
76    ) throws ServletException JavaDoc
77    {
78       super.init(scConfig);
79
80       // Load UI page for the main screen display
81
cacheUIPath(scConfig, DISPATCH_PAGE,
82                   "Path to page to display is not set in property " + DISPATCH_PAGE);
83    }
84
85    /**
86     * {@inheritDoc}
87     */

88    public String JavaDoc getServletInfo(
89    )
90    {
91       return this.getClass().getName();
92    }
93
94    /**
95     * {@inheritDoc}
96     */

97    protected void doGet(
98       HttpServletRequest JavaDoc hsrqRequest,
99       HttpServletResponse JavaDoc hsrpResponse
100    ) throws ServletException JavaDoc,
101             IOException JavaDoc
102    {
103       String JavaDoc strModuleName = null;
104       // try to find out from actual request path, what module is active
105
// and set up parameter 'activemodule' into the request
106
try
107       {
108          strModuleName = WebModuleDefinitionManager.getInstance(
109                             ).getModuleNameFromURL(hsrqRequest.getServletPath());
110       }
111       catch (OSSException osseExc)
112       {
113          throw new ServletException JavaDoc("An unexpected exception has occured " +
114                                     "while getting web module name from URL.", osseExc);
115       }
116       
117       if ((strModuleName != null) && (strModuleName.length() > 0))
118       {
119          // set up active module name into the request parameter
120
hsrqRequest.setAttribute(ACTIVE_MODULE_NAME, strModuleName);
121       }
122       
123       // Right now there is no action
124
displayUI(DISPATCH_PAGE, hsrqRequest, hsrpResponse);
125    }
126 }
127
Popular Tags