001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.action;
006:
007: import org.apache.struts.Globals;
008: import org.apache.struts.action.ActionError;
009: import org.apache.struts.action.ActionErrors;
010: import org.apache.struts.action.ActionForm;
011: import org.apache.struts.action.ActionForward;
012: import org.apache.struts.action.ActionMapping;
013: import org.vfny.geoserver.config.DataConfig;
014: import org.vfny.geoserver.config.GlobalConfig;
015: import org.vfny.geoserver.config.WCSConfig;
016: import org.vfny.geoserver.config.WFSConfig;
017: import org.vfny.geoserver.config.WMSConfig;
018: import org.vfny.geoserver.config.validation.ValidationConfig;
019: import org.vfny.geoserver.global.ApplicationState;
020: import org.vfny.geoserver.global.Data;
021: import org.vfny.geoserver.global.UserContainer;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.servlet.http.HttpServletResponse;
024:
025: /**
026: * GeoConfigAction is a common super class used by STRUTS Actions.
027: *
028: * <p>
029: * ConfigAction is used to store shared services, such as looking up the
030: * Configuration Model.
031: * </p>
032: * Capabilities:
033: *
034: * <ul>
035: * <li>
036: * Config (Model) Access: Convience routines have been writen to allow access
037: * to the Config Model from the Web Container.
038: * </li>
039: * <li>Since configuraiton should only be attempted when logged in, an effort has been made to smooth the
040: * required login check required by most geoserver config actions.
041: * </li>
042: * </ul>
043: * <p>
044: * Most config actions require the follow check to be made:
045: * <pre><code>
046: * <b>class</b> MyConfigAction <b>extends</b> ConfigAction {
047: * Redirect execute( HttpServletRequest request, ){
048: * <b>if</b>( !isLoggedIn( request )){
049: * return new Redirect(�Login Page�);
050: * }
051: * UserContainer user = getUserContainer( request );
052: * �
053: * <b>return new</b> Redirect(�my.jsp�);
054: * }
055: * }
056: * </code></pre>
057: * </p>
058: * <p>
059: * To prevent the duplication of the above code in each and every config
060: * action pleaes make use of the alternate execute method:
061: * <pre><code>
062: * <b>class</b> MyConfigAction <b>extends</b> ConfigAction {
063: * Redirect execute( UserContainer user, HttpServletRequest request ){
064: * �
065: * <b>return new</b> Redirect(�my.jsp�);
066: * }
067: * }
068: * </code></pre>
069: * </p>
070: * Please remember that Actions (like servlets) should never make use of
071: * instance variables in order to remain thread-safe.
072: * </p>
073: *
074: * @author Jody Garnett, Refractions Research, Inc.
075: * @author jive
076: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last modification)
077: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last modification)
078: * @version $Id: ConfigAction.java 6958 2007-06-08 16:20:59Z aaime $
079: */
080: public class ConfigAction extends GeoServerAction {
081: /**
082: * Execute method that redirects user if not loggin in.
083: * <p>
084: * The UserContainer is gathered from the session context using the
085: * GeoServerAction.getUserContainer( request method ).
086: * </p>
087: * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
088: */
089: public ActionForward execute(ActionMapping mapping,
090: ActionForm form, HttpServletRequest request,
091: HttpServletResponse response) throws Exception {
092: // if (!isLoggedIn(request)) {
093: // ActionErrors errors = new ActionErrors();
094: // errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.login.required"));
095: // request.setAttribute(Globals.ERROR_KEY, errors);
096: // request.setAttribute("forward", mapping.getForward());
097: //
098: // return mapping.findForward("login");
099: // }
100: return execute(mapping, form, getUserContainer(request),
101: request, response);
102: }
103:
104: /**
105: * A "safe" execute method, only called after the user has logged in.
106: * <p>
107: * You may still override the normal execute method if you do not require
108: * this service.
109: * </p>
110: */
111: public ActionForward execute(ActionMapping mapping,
112: ActionForm form, UserContainer user,
113: HttpServletRequest request, HttpServletResponse response)
114: throws Exception {
115: return null;
116: }
117:
118: /**
119: * Access Web Map Server Configuration Model from the WebContainer.
120: *
121: * <p>
122: * Note that this represents the Configuration and not the state of the Web
123: * Feature Server.
124: * </p>
125: *
126: * @return Configuration information for the Web Map Server
127: */
128: protected WMSConfig getWMSConfig() {
129: return (WMSConfig) getServlet().getServletContext()
130: .getAttribute(WMSConfig.CONFIG_KEY);
131: }
132:
133: /**
134: * Access Web Feature Server Configuration Model from the WebContainer.
135: *
136: * <p>
137: * Note that this represents the Configuration and not the state of the Web
138: * Feature Server.
139: * </p>
140: *
141: * @return Configuration information for Web Feature Server
142: */
143: protected WFSConfig getWFSConfig() {
144: return (WFSConfig) getServlet().getServletContext()
145: .getAttribute(WFSConfig.CONFIG_KEY);
146: }
147:
148: /**
149: * Access Web Coverage Server Configuration Model from the WebContainer.
150: *
151: * <p>
152: * Note that this represents the Configuration and not the state of the Web
153: * Coverage Server.
154: * </p>
155: *
156: * @return Configuration information for Web Coverage Server
157: */
158: protected WCSConfig getWCSConfig() {
159: return (WCSConfig) getServlet().getServletContext()
160: .getAttribute(WCSConfig.CONFIG_KEY);
161: }
162:
163: /**
164: * Access Web Map Server Configuration Model from the WebContainer.
165: *
166: * @return Configuration model for Global information.
167: */
168: protected GlobalConfig getGlobalConfig() {
169: return (GlobalConfig) getServlet().getServletContext()
170: .getAttribute(GlobalConfig.CONFIG_KEY);
171: }
172:
173: /**
174: * Access Catalog Configuration Model from the WebContainer.
175: *
176: * @return Configuration model for Catalog information.
177: */
178: protected DataConfig getDataConfig() {
179: return (DataConfig) getServlet().getServletContext()
180: .getAttribute(DataConfig.CONFIG_KEY);
181: }
182:
183: /**
184: * Access Catalog Model from the WebContainer.
185: *
186: * @return Configuration model for Catalog information.
187: */
188: protected Data getData() {
189: return (Data) getServlet().getServletContext().getAttribute(
190: Data.WEB_CONTAINER_KEY);
191: }
192:
193: /**
194: * Access Catalog Configuration Model from the WebContainer.
195: *
196: * @return Configuration model for Catalog information.
197: */
198: protected ValidationConfig getValidationConfig() {
199: return (ValidationConfig) getServlet().getServletContext()
200: .getAttribute(ValidationConfig.CONFIG_KEY);
201: }
202:
203: /**
204: * Access Catalog Configuration Model from the WebContainer.
205: *
206: * @return Configuration model for Catalog information.
207: */
208: protected ApplicationState getApplicationState() {
209: return (ApplicationState) getServlet().getServletContext()
210: .getAttribute(ApplicationState.WEB_CONTAINER_KEY);
211: }
212: }
|