001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.catalog.wfs;
017:
018: import org.geotools.catalog.Catalog;
019: import org.geotools.catalog.Service;
020: import org.geotools.catalog.ServiceFactory;
021: import org.geotools.catalog.wfs.WFSService.MyWFSDataStore;
022: import org.geotools.data.wfs.WFSDataStoreFactory;
023: import java.net.MalformedURLException;
024: import java.net.URI;
025: import java.net.URISyntaxException;
026: import java.net.URL;
027: import java.util.HashMap;
028: import java.util.Map;
029:
030: /**
031: * Provides ...TODO summary sentence
032: *
033: * <p>
034: * TODO Description
035: * </p>
036: *
037: * @since 0.6
038: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/wfs/src/main/java/org/geotools/catalog/wfs/WFSServiceFactory.java $
039: */
040: public class WFSServiceFactory implements ServiceFactory {
041: private static WFSDataStoreFactory wfsDSFactory;
042:
043: /**
044: * TODO summary sentence for getWFSDSFactory ...
045: *
046: * @return x
047: */
048: public static WFSDataStoreFactory getWFSDSFactory() {
049: if (wfsDSFactory == null) {
050: wfsDSFactory = new WFSDataStoreFactory();
051: }
052:
053: return wfsDSFactory;
054: }
055:
056: /**
057: * TODO summary sentence for createService ...
058: *
059: * @param parent DOCUMENT ME!
060: * @param id
061: * @param params
062: *
063: * @return x
064: */
065: public Service createService(Catalog parent, URI id, Map params) {
066: if ((params == null)
067: || !params.containsKey(WFSDataStoreFactory.URL.key)) {
068: return null;
069: }
070:
071: try {
072: if (id == null) {
073: URL base = (URL) params
074: .get(WFSDataStoreFactory.URL.key);
075: base = (base == null) ? null : MyWFSDataStore
076: .createGetCapabilitiesRequest(base);
077:
078: return new WFSService(parent, new URI(base
079: .toExternalForm()), params);
080: }
081:
082: return new WFSService(parent, id, params);
083: } catch (URISyntaxException e) {
084: return null;
085: }
086: }
087:
088: /**
089: * TODO summary sentence for createParams ...
090: *
091: * @param uri
092: *
093: * @return x
094: *
095: * @see net.refractions.udig.catalog.ServiceExtension#createParams(java.net.URL)
096: */
097: public Map createParams(URI uri) {
098: URL url;
099:
100: try {
101: url = uri.toURL();
102: } catch (MalformedURLException e) {
103: return null;
104: }
105:
106: if (!isWFS(url)) {
107: return null;
108: }
109:
110: // wfs check
111: Map params = new HashMap();
112: params.put(WFSDataStoreFactory.URL.key, url);
113:
114: // don't check ... it blocks
115: // (XXX: but we are using that to figure out if the service will work?)
116: return params;
117: }
118:
119: public boolean canProcess(URI uri) {
120: try {
121: URL url = uri.toURL();
122:
123: return isWFS(url);
124: } catch (MalformedURLException e) {
125: return false;
126: }
127: }
128:
129: /**
130: * A couple quick checks on the url
131: *
132: * @param url DOCUMENT ME!
133: *
134: * @return DOCUMENT ME!
135: */
136: private static final boolean isWFS(URL url) {
137: String PATH = url.getPath();
138: String QUERY = url.getQuery();
139: String PROTOCOL = url.getProtocol();
140:
141: if (!"http".equals(PROTOCOL)) { //$NON-NLS-1$
142:
143: return false;
144: }
145:
146: if ((QUERY != null)
147: && (QUERY.toUpperCase().indexOf("SERVICE=") != -1)) { //$NON-NLS-1$
148: // we have a service! it better be wfs
149:
150: return QUERY.toUpperCase().indexOf("SERVICE=WFS") != -1; //$NON-NLS-1$
151: }
152:
153: if ((PATH != null)
154: && (PATH.toUpperCase().indexOf("GEOSERVER/WFS") != -1)) { //$NON-NLS-1$
155:
156: return true;
157: }
158:
159: return true; // try it anyway
160: }
161: }
|