001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/portal/portlet/modules/map/actions/portlets/FeatureInfoForwardPortletPerform.java $
002 /*----------------------------------------------------------------------------
003 This file is part of deegree, http://deegree.org/
004 Copyright (C) 2001-2009 by:
005 Department of Geography, University of Bonn
006 and
007 lat/lon GmbH
008
009 This library is free software; you can redistribute it and/or modify it under
010 the terms of the GNU Lesser General Public License as published by the Free
011 Software Foundation; either version 2.1 of the License, or (at your option)
012 any later version.
013 This library is distributed in the hope that it will be useful, but WITHOUT
014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
016 details.
017 You should have received a copy of the GNU Lesser General Public License
018 along with this library; if not, write to the Free Software Foundation, Inc.,
019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020
021 Contact information:
022
023 lat/lon GmbH
024 Aennchenstr. 19, 53177 Bonn
025 Germany
026 http://lat-lon.de/
027
028 Department of Geography, University of Bonn
029 Prof. Dr. Klaus Greve
030 Postfach 1147, 53001 Bonn
031 Germany
032 http://www.geographie.uni-bonn.de/deegree/
033
034 e-mail: info@deegree.org
035 ----------------------------------------------------------------------------*/
036 package org.deegree.portal.portlet.modules.map.actions.portlets;
037
038 import java.util.ArrayList;
039 import java.util.List;
040
041 import javax.servlet.ServletContext;
042 import javax.servlet.http.HttpServletRequest;
043
044 import org.apache.jetspeed.portal.Portlet;
045 import org.deegree.framework.log.ILogger;
046 import org.deegree.framework.log.LoggerFactory;
047 import org.deegree.framework.util.StringTools;
048 import org.deegree.model.crs.CoordinateSystem;
049 import org.deegree.model.spatialschema.GeometryFactory;
050 import org.deegree.model.spatialschema.Point;
051 import org.deegree.ogcwebservices.OGCWebServiceException;
052 import org.deegree.portal.PortalException;
053 import org.deegree.portal.context.ContextException;
054 import org.deegree.portal.context.Layer;
055 import org.deegree.portal.context.ViewContext;
056
057 /**
058 *
059 *
060 * @version $Revision: 18195 $
061 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
062 * @author last edited by: $Author: mschneider $
063 *
064 * @version 1.0. $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18. Jun 2009) $
065 *
066 * @since 2.0
067 */
068 public abstract class FeatureInfoForwardPortletPerform extends FeatureInfoPortletPerform {
069
070 private static final ILogger LOG = LoggerFactory.getLogger( FeatureInfoForwardPortletPerform.class );
071
072 /**
073 * @param request
074 * @param portlet
075 * @param servletContext containing servlet information
076 */
077 public FeatureInfoForwardPortletPerform( HttpServletRequest request, Portlet portlet, ServletContext servletContext ) {
078 super( request, portlet, servletContext );
079
080 }
081
082 @Override
083 protected void doGetFeatureInfo()
084 throws PortalException, OGCWebServiceException {
085
086 // a get feature info request only can be performed if a viewcontext
087 // has been initialized before by the MapWindowPortletAction
088 ViewContext vc = getCurrentViewContext( portlet.getID() );
089 if ( vc == null ) {
090 throw new PortalException( "no valid view context available through users session" );
091 }
092 String reqlayer = parameter.get( PARAM_FILAYERS );
093 if ( reqlayer == null || reqlayer.length() == 0 ) {
094 throw new PortalException( "at least one layer/featuretype/coverage must be "
095 + "targeted by a feature info request" );
096 }
097 // update the view contexts bounding box with the current one. This information
098 // will be evaluated when creating a GetFeatureInfo request later
099 String tmp = parameter.get( PARAM_BBOX );
100 if ( tmp == null || tmp.length() == 0 ) {
101 throw new PortalException( "required parameter " + PARAM_BBOX + " is missing!" );
102 }
103 double[] coords = StringTools.toArrayDouble( tmp, "," );
104 CoordinateSystem crs = vc.getGeneral().getBoundingBox()[0].getCoordinateSystem();
105 Point[] pt = new Point[2];
106 pt[0] = GeometryFactory.createPoint( coords[0], coords[1], crs );
107 pt[1] = GeometryFactory.createPoint( coords[2], coords[3], crs );
108 try {
109 vc.getGeneral().setBoundingBox( pt );
110 } catch ( ContextException e ) {
111 LOG.logError( e.getMessage(), e );
112 throw new PortalException( "could not update viewcontexts bbox", e );
113 }
114
115 List<Layer> layerList = new ArrayList<Layer>( 50 );
116 layerList.add( vc.getLayerList().getLayer( reqlayer, null ) );
117 tmp = perform( layerList, vc ).trim();
118 String[] ids = StringTools.toArray( tmp, ";", true );
119
120 List<?> list = performQuery( ids );
121
122 request.setAttribute( "RESULT", list );
123
124 }
125
126 /**
127 * the IDs of the features targeted by a GetFeatureInfo request will be passed. A concrete
128 * implementation of this method may use them to perform a database query, a GetFeature request
129 * or something else.
130 *
131 * @param ids
132 * @return the response of the query
133 */
134 protected abstract List<?> performQuery( String[] ids );
135
136 }