/* Package GeoTools/WMS Implementation * Copyright (C) 2001 Cameron Shorter (camerons@users.sourceforge.net) * Artur Hefczyc (kobit@users.sourceforge.net) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * $Header: /cvsroot/geotools/geotools/src/uk/ac/leeds/ccg/ogc/WFSDataSource.java,v 1.2 2002/02/17 04:10:20 camerons Exp $ * $Author: camerons $ */ package uk.ac.leeds.ccg.ogc; import java.util.*; import java.net.*; import uk.ac.leeds.ccg.geotools.*; /** * WFSDataSource will create a GML filter for use when querying OGC type datasets, * for use in things like the Web Feature Server classes. * It is defined by the "Filter Encoding Specification" provided by * the Open GIS Consortium - http://opengis.org). * This initial implementation is a simplified hack to get thing working. * Eventually it will need to be beafed up, and probably re-written. * * @author Cameron Shorter * @version $Revision: 1.2 $ */ public class WFSDataSource { public boolean DEBUG=true; private GeoRectangle extent; private String typeName; private int maxFeatures=-1; private Vector propertyNames=new Vector(); private String version="1.0.0"; private URL baseURL; private URL proxyURL=null; /** * Set the URL of the base URL of the WFS. */ public void setURL(URL baseURL) { this.baseURL=baseURL; } /** * Set the URL of a proxy server for the WFS. There is a security * constraint in java applets which prevents an applet from accessing a * URL different to the server where the applet came from. So if you want * to access a Web Feature Server from somewhere on the web, you need to set * up a local proxy. A local proxy sits on the server where the applet * came from, it recieves calls from the applet, forwards them onto the * Web Feature Server, and then funnels the responses back to the applet. * @param proxyURL */ public void setProxy(URL proxyURL) { this.proxyURL=proxyURL; } /** * Return the URL of the proxy if set, otherwise return null. */ public URL getProxy(){ return this.proxyURL; } /** * Set the version of the WFS to query, defaults to "1.0.0". */ public void setVersion(String version) { this.version=version; } /** * Set the extent (BBOX) to use in a query. * To do: This should be replaced by a setGlobalFilter interface, and the * extent will be set in the filter object. */ public void setExtent(GeoRectangle extent) { this.extent=extent; } /** * Get the extent that is being used by this object, returns a null if * extent has not been definied. */ public GeoRectangle getExtent(GeoRectangle extent) { return this.extent; } /** * Set the typeName to use in the query. Conceptually, a typeName is like a * table in a database, or a layer in geotools. */ public void setTypeName(String typeName) { this.typeName=typeName; } /** * Get the typeName used by this query. */ public String getTypeName() { return this.typeName; } /** * Set the maximum features to return from the server. This will ensure that * your application will not wait for hours waiting for all the features to * be returned. * @param maxFeatures The max features to return, a value of -1 implies send * all features, this is the default. */ public void setMaxFeatures(int maxFeatures){ this.maxFeatures=maxFeatures; } /** Get the maxFeatures set, if maxFeatures is not set then -1 is returned. */ public int getMaxFeatures(){ return this.maxFeatures; } /** * Add a property to be returned, if this is not set, then all properties * will be returned. This method can be called multiple times to add * multiple properties. */ public void addPropertyName(String propertyName){ propertyNames.add(propertyName); } /** * Build a URL for a GET query to a WFS. */ public URL getURL() { URL url=null; // Eg: http://www.cubewerx.com/ows1/cwwfs.cgi?version=0.0.14&request=getfeature&typename=AEROFACP_1M&BBOX=141.35439345749762,-38.097908309455605,153.57936012416428,-27.589340974212053 try{ url= new URL( baseURL +"?" +"&version=" +version +"&request=getfeature&typename=" +this.typeName +"&BBOX=" +this.extent.toBBoxString()); } catch (Exception e) { System.err.println("WFSDataSource.getURL exception "+e); } return url; } /** * Construct and send a query based on parameters already set. */ public void query() { if(DEBUG){ System.out.println(""); System.out.println(""); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); //System.out.println(" "+this.extent.toGmlCoordinates()); System.out.println(" "+this.extent); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); System.out.println(" "); for(int i=0;i"); System.out.println(" "+propertyNames.elementAt(i)); System.out.println(" "); } System.out.println(" "); System.out.println(""); } } }