View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.street;
24  
25  import javax.servlet.http.HttpServletRequest;
26  
27  import com.gisgraphy.geoloc.GeolocQuery;
28  import com.gisgraphy.geoloc.GeolocQueryHttpBuilder;
29  import com.gisgraphy.servlet.GisgraphyServlet;
30  import com.gisgraphy.servlet.StreetServlet;
31  import com.vividsolutions.jts.geom.Point;
32  
33  /**
34   *  a query to be execute by the @link {@link StreetSearchEngine}
35   * 
36   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
37   *
38   */
39  public class StreetSearchQueryHttpBuilder extends GeolocQueryHttpBuilder {
40  	
41      private static StreetSearchQueryHttpBuilder instance = new StreetSearchQueryHttpBuilder();
42  	
43  	public static StreetSearchQueryHttpBuilder getInstance() {
44  		return instance;
45  	}
46      
47  	@Override
48  	protected StreetSearchQuery constructMinimalQuery(Point point, double radius) {
49  		StreetSearchQuery streetSearchQuery = new StreetSearchQuery(point,radius);
50  		return streetSearchQuery;
51  	}
52  	
53      @Override
54      public StreetSearchQuery buildFromHttpRequest(HttpServletRequest req) {
55  	StreetSearchQuery streetSearchQuery = (StreetSearchQuery) super.buildFromHttpRequest(req);
56  	//streettype
57  	streetSearchQuery.withStreetType(StreetType.getFromString(req
58  	.getParameter(StreetSearchQuery.STREETTYPE_PARAMETER)));
59  	
60  	//OneWay
61  	String oneWayParameter = req
62  		.getParameter(StreetSearchQuery.ONEWAY_PARAMETER);
63  	if ("true".equalsIgnoreCase(oneWayParameter)
64  		|| "on".equalsIgnoreCase(oneWayParameter)) {
65  		streetSearchQuery.withOneWay(Boolean.TRUE);
66  	}
67  	else if ("false".equalsIgnoreCase(oneWayParameter)){
68  		streetSearchQuery.withOneWay(Boolean.FALSE);
69  	}
70  	//name
71  	streetSearchQuery.withName(req.getParameter(StreetSearchQuery.NAME_PARAMETER));
72  	
73  	String StreetSearchModeparameter = req.getParameter(StreetServlet.STREET_SEARCH_MODE_PARAMETER);
74  	streetSearchQuery.withStreetSearchMode(StreetSearchMode.getFromString(StreetSearchModeparameter));
75  	
76  	// apiKey
77  	String apiKey = req.getParameter(GisgraphyServlet.APIKEY_PARAMETER);
78  	streetSearchQuery.setApikey(apiKey);
79  	
80  	return streetSearchQuery;
81  
82      }
83  
84  	
85         /**
86  	 * @return true if the point is required
87  	 */
88      @Override
89  	protected boolean isPointRequired(){
90  		return  false;
91  	    }
92     
93      @Override
94      protected int getMaxResults() {
95  		return StreetSearchQuery.DEFAULT_MAX_RESULTS;
96  	}
97  	
98      
99  }