svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extCatalog / src / org / gvsig / catalog / loaders / WFSLayerLoader.java @ 29625
History | View | Annotate | Download (5.08 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.catalog.loaders; |
42 |
|
43 |
import java.net.MalformedURLException; |
44 |
import java.util.HashMap; |
45 |
import java.util.Map; |
46 |
|
47 |
import org.gvsig.andami.PluginServices; |
48 |
import org.gvsig.app.project.documents.view.gui.BaseView; |
49 |
import org.gvsig.catalog.schemas.Resource; |
50 |
import org.gvsig.fmap.dal.DataStoreParameters; |
51 |
import org.gvsig.fmap.dal.store.catalog.CatalogStoreParameters; |
52 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
53 |
import org.gvsig.i18n.Messages; |
54 |
import org.gvsig.tools.ToolsLocator; |
55 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
56 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
57 |
import org.gvsig.utils.extensionPointsOld.ExtensionPointsSingleton; |
58 |
|
59 |
|
60 |
|
61 |
/**
|
62 |
* This class is used to load a WFS layer in gvSIG
|
63 |
*
|
64 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
65 |
*/
|
66 |
public class WFSLayerLoader extends GvSigLayerLoader{ |
67 |
public static final String DYNFIELDNAME_URL = "url"; |
68 |
public static final String DYNFIELDNAME_VERSION = "version"; |
69 |
public static final String DYNFIELDNAME_TYPENAME = "typeName"; |
70 |
public static final String DYNFIELDNAME_NAMESPACE = "namespace"; |
71 |
public static final String DYNFIELDNAME_NAMESPACEPREFIX = "namespacePrefix"; |
72 |
public static final String DYNFIELDNAME_FIELDS = "fields"; |
73 |
public static final String DYNFIELDNAME_FILTERENCODING = "filterEncoding"; |
74 |
public static final String DYNFIELDNAME_MAXFEATURES = "maxFeatures"; |
75 |
public static final String DYNFIELDNAME_TIMEOUT = "timeOut"; |
76 |
public static final String DYNFIELDNAME_USER = "user"; |
77 |
public static final String DYNFIELDNAME_PASSWORD = "password"; |
78 |
|
79 |
public WFSLayerLoader(Resource resource) {
|
80 |
super(resource);
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* This function loads a WFS resource
|
85 |
* @param host
|
86 |
* URL where the server is located
|
87 |
* @param layer
|
88 |
* Layer name
|
89 |
* @throws LayerLoaderException
|
90 |
*/
|
91 |
|
92 |
public void loadLayer() throws LayerLoaderException { |
93 |
DataStoreParameters storeParameters = null;
|
94 |
String host = getResource().getLinkage();
|
95 |
String featureType = getResource().getName();
|
96 |
try {
|
97 |
storeParameters = createWFSStoreParameters(host, featureType); |
98 |
addLayerToView(featureType, storeParameters); |
99 |
} catch (MalformedURLException e) { |
100 |
throw new LayerLoaderException(e.getMessage(),getWindowMessage()); |
101 |
} catch (Exception e) { |
102 |
// TODO Auto-generated catch block
|
103 |
e.printStackTrace(); |
104 |
throw new LayerLoaderException(e.getMessage(),getWindowMessage()); |
105 |
} |
106 |
} |
107 |
|
108 |
private DataStoreParameters createWFSStoreParameters(String host, String featureType) throws Exception{ |
109 |
CatalogStoreParameters dataStoreParameters = new CatalogStoreParameters();
|
110 |
dataStoreParameters.setDynValue(DYNFIELDNAME_URL, host); |
111 |
int index = featureType.indexOf(":"); |
112 |
if (index > 0){ |
113 |
dataStoreParameters.setDynValue(DYNFIELDNAME_NAMESPACEPREFIX, featureType.substring(0, index));
|
114 |
} |
115 |
dataStoreParameters.setDynValue(DYNFIELDNAME_TYPENAME, featureType); |
116 |
dataStoreParameters.setDynValue(DYNFIELDNAME_USER, "");
|
117 |
dataStoreParameters.setDynValue(DYNFIELDNAME_PASSWORD, "");
|
118 |
|
119 |
ExtensionPointManager extensionPointManager = ToolsLocator |
120 |
.getExtensionPointManager(); |
121 |
ExtensionPoint extensionPoint = extensionPointManager.add("CatalogDataStoreParameters");
|
122 |
Object[] args = new Object[1]; |
123 |
args[0] = dataStoreParameters;
|
124 |
|
125 |
try {
|
126 |
return (DataStoreParameters)extensionPoint.create("OGC:WFS", args); |
127 |
} catch(Exception e) { |
128 |
e.printStackTrace(); |
129 |
throw new LayerLoaderException(getErrorMessage(),getWindowMessage()); |
130 |
} |
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
* @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getErrorMessage()
|
136 |
*/
|
137 |
protected String getErrorMessage() { |
138 |
return Messages.getText("wfsError") + ".\n" + |
139 |
Messages.getText("server") + ": " + |
140 |
getResource().getLinkage() + "\n" +
|
141 |
Messages.getText("layer") + ": " + |
142 |
getResource().getName(); |
143 |
} |
144 |
|
145 |
/*
|
146 |
* (non-Javadoc)
|
147 |
* @see es.gva.cit.gvsig.catalogClient.loaders.LayerLoader#getWindowMessage()
|
148 |
*/
|
149 |
protected String getWindowMessage() { |
150 |
return Messages.getText("wfsLoad"); |
151 |
} |
152 |
|
153 |
|
154 |
} |