001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/portal/standard/PortalRequestDispatcher.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53177 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042: ---------------------------------------------------------------------------*/
043:
044: package org.deegree.portal.standard;
045:
046: import java.io.File;
047: import java.io.IOException;
048: import java.net.MalformedURLException;
049: import java.net.URL;
050: import java.util.Map;
051: import java.util.Set;
052:
053: import javax.servlet.ServletConfig;
054: import javax.servlet.ServletException;
055: import javax.servlet.http.HttpServletRequest;
056: import javax.servlet.http.HttpServletResponse;
057: import javax.servlet.http.HttpSession;
058:
059: import org.deegree.enterprise.control.RequestDispatcher;
060: import org.deegree.framework.log.ILogger;
061: import org.deegree.framework.log.LoggerFactory;
062: import org.deegree.framework.version.Version;
063: import org.deegree.portal.Constants;
064: import org.deegree.portal.context.ViewContext;
065: import org.deegree.portal.context.WebMapContextFactory;
066:
067: /**
068: * This is a <code>RequestDispatcher</code> which creates a event out of
069: * a GET or POST requests.<P>
070: *
071: * Furthermore this class implements
072: *
073: * <HR>
074: * <B>Design Patterns:</B>:<BR>
075: *
076: * The following Design Patterns are used:
077: * <UL>
078: * <LI> Proxy
079: * </UL>
080: *
081: * @author <a href="mailto:friebe@gmx.net">Torsten Friebe</a>
082: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
083: *
084: * @version $Revision: 9346 $ $Date: 2007-12-27 08:39:07 -0800 (Thu, 27 Dec 2007) $
085: *
086: */
087: public class PortalRequestDispatcher extends RequestDispatcher {
088:
089: private static final ILogger LOG = LoggerFactory
090: .getLogger(PortalRequestDispatcher.class);
091:
092: protected ViewContext vc = null;
093:
094: /**
095: * This method initializes the servlet.
096: *
097: * @param cfg the servlet configuration
098: *
099: * @throws ServletException an exception
100: */
101: public void init(ServletConfig cfg) throws ServletException {
102: super .init(cfg);
103:
104: String clientContext = this
105: .getInitParameter("MapContext.configFile");
106: if (!(new File(clientContext).exists())) {
107: clientContext = getServletContext().getRealPath(
108: clientContext);
109: }
110: try {
111: File file = new File(clientContext);
112: vc = WebMapContextFactory.createViewContext(file.toURL(),
113: null, null);
114: } catch (Exception e) {
115: e.printStackTrace();
116: }
117:
118: try {
119: if (this .getInitParameter("UserRepository") != null) {
120: URL userRepository = new URL(this
121: .getInitParameter("UserRepository"));
122: getServletContext().setAttribute(
123: Constants.USERREPOSITORY, userRepository);
124: }
125: } catch (MalformedURLException e1) {
126: e1.printStackTrace();
127: }
128:
129: LOG.logInfo("Starting deegree version " + Version.getVersion()
130: + " on server: "
131: + this .getServletContext().getServerInfo()
132: + " / Java version: "
133: + System.getProperty("java.version"));
134: }
135:
136: /**
137: *
138: *
139: * @param request
140: * @param response
141: *
142: * @throws ServletException
143: * @throws IOException
144: */
145: protected void service(HttpServletRequest request,
146: HttpServletResponse response) throws ServletException,
147: IOException {
148: Map<String, String[]> params = request.getParameterMap();
149: Set<String> keys = params.keySet();
150: for (String key : keys) {
151: String[] array = params.get(key);
152: for (String k : array) {
153: LOG.logDebug("found parameter for key: " + key
154: + " param: " + k);
155: }
156: }
157: String[] rpcCalls = request.getParameterValues("rpc");
158:
159: if (rpcCalls != null) {
160: if (rpcCalls.length > 1) {
161: LOG.logDebug("found multiple rpc parameters");
162:
163: }
164: for (String tmp : rpcCalls) {
165: LOG.logDebug("Found parameter: " + tmp);
166: }
167: }
168: HttpSession session = request.getSession(true);
169: session.setAttribute(Constants.DEFAULTMAPCONTEXT, vc);
170: if (session.getAttribute(Constants.CURRENTMAPCONTEXT) == null) {
171: session.setAttribute(Constants.CURRENTMAPCONTEXT, vc);
172: }
173: super.service(request, response);
174: }
175:
176: }
|