svn-gvsig-desktop / tags / v1_1_Build_1008 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / CatalogClient.java @ 12520
History | View | Annotate | Download (9.36 KB)
1 | 3566 | jorpiell | |
---|---|---|---|
2 | 3593 | jorpiell | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 | 2820 | jorpiell | *
|
4 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | * For more information, contact:
|
||
21 | *
|
||
22 | * Generalitat Valenciana
|
||
23 | * Conselleria d'Infraestructures i Transport
|
||
24 | 3593 | jorpiell | * Av. Blasco Ib??ez, 50
|
25 | 2820 | jorpiell | * 46010 VALENCIA
|
26 | * SPAIN
|
||
27 | *
|
||
28 | * +34 963862235
|
||
29 | * gvsig@gva.es
|
||
30 | * www.gvsig.gva.es
|
||
31 | *
|
||
32 | * or
|
||
33 | *
|
||
34 | * IVER T.I. S.A
|
||
35 | * Salamanca 50
|
||
36 | * 46005 Valencia
|
||
37 | * Spain
|
||
38 | *
|
||
39 | * +34 963163400
|
||
40 | * dac@iver.es
|
||
41 | */
|
||
42 | 2047 | luisw | package es.gva.cit.catalogClient; |
43 | 3613 | jorpiell | import es.gva.cit.catalogClient.csw.drivers.CSWCatalogServiceDriver; |
44 | import es.gva.cit.catalogClient.drivers.ICatalogServiceDriver; |
||
45 | import es.gva.cit.catalogClient.querys.Query; |
||
46 | 6077 | jorpiell | import es.gva.cit.catalogClient.schemas.Schemas; |
47 | 3613 | jorpiell | import es.gva.cit.catalogClient.srw.drivers.SRWCatalogServiceDriver; |
48 | 4302 | jorpiell | import com.iver.utiles.swing.jcomboServer.ServerData; |
49 | 3613 | jorpiell | import es.gva.cit.catalogClient.z3950.drivers.Z3950CatalogServiceDriver; |
50 | 3566 | jorpiell | import java.io.IOException; |
51 | import java.net.MalformedURLException; |
||
52 | import java.net.Socket; |
||
53 | import java.net.URL; |
||
54 | import java.net.UnknownHostException; |
||
55 | import java.util.Collection; |
||
56 | 2150 | jorpiell | |
57 | 2820 | jorpiell | /**
|
58 | 2852 | jorpiell | * This class represents a catalogClient. It must be created to
|
59 | * use the catalog service
|
||
60 | *
|
||
61 | 3566 | jorpiell | *
|
62 | 2820 | jorpiell | * @author Jorge Piera Llodra (piera_jor@gva.es)
|
63 | */
|
||
64 | 2724 | jorpiell | public class CatalogClient { |
65 | 3566 | jorpiell | |
66 | /**
|
||
67 | *
|
||
68 | *
|
||
69 | */
|
||
70 | 2724 | jorpiell | private URL url = null; |
71 | 3566 | jorpiell | |
72 | /**
|
||
73 | *
|
||
74 | *
|
||
75 | */
|
||
76 | 3225 | jorpiell | private String sURL = null; |
77 | 3566 | jorpiell | |
78 | /**
|
||
79 | *
|
||
80 | *
|
||
81 | */
|
||
82 | 2724 | jorpiell | private String protocol = null; |
83 | 3566 | jorpiell | /**
|
84 | *
|
||
85 | *
|
||
86 | */
|
||
87 | 2724 | jorpiell | private ICatalogServiceDriver lnkICatalogServerDriver;
|
88 | 3566 | jorpiell | |
89 | /**
|
||
90 | *
|
||
91 | *
|
||
92 | */
|
||
93 | 3510 | jorpiell | private String serverStatus = null; |
94 | 2047 | luisw | |
95 | 3566 | jorpiell | /**
|
96 | * Constructor
|
||
97 | *
|
||
98 | *
|
||
99 | * @param url Server url
|
||
100 | * @param protocol Server protocol
|
||
101 | * @param database Database name. This param only is used when the protocol
|
||
102 | * is z39.50
|
||
103 | */
|
||
104 | public CatalogClient(String url, String protocol, String database) { |
||
105 | 2724 | jorpiell | setProtocol(protocol); |
106 | 3225 | jorpiell | setSURL(url); |
107 | 2724 | jorpiell | //This is necessary. Otherwise it will throw the exception
|
108 | if (!(url.regionMatches(0, "http://", 0, 7))) { |
||
109 | url = "http://" + url;
|
||
110 | } |
||
111 | try {
|
||
112 | this.setUrl(new URL(url)); |
||
113 | //if protocol is z39.50 we have to add the database to the URL
|
||
114 | 3486 | jorpiell | if (!(protocol.equals(new String(ServerData.SERVER_SUBTYPE_CATALOG_Z3950)))) { |
115 | 2724 | jorpiell | database = getUrl().getPath(); |
116 | } |
||
117 | //if protocol is http, we have to set the port manually
|
||
118 | if (getUrl().getPort() == -1) { |
||
119 | setUrl(new URL("http", getUrl().getHost(), 80, database)); |
||
120 | } else {
|
||
121 | setUrl(new URL("http", getUrl().getHost(), getUrl().getPort(), |
||
122 | database)); |
||
123 | } |
||
124 | } catch (MalformedURLException e) { |
||
125 | // TODO Auto-generated catch block
|
||
126 | System.out.println("La URL no es correcta"); |
||
127 | } |
||
128 | //Casting to the respective driver
|
||
129 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_CATALOG_SRW))) { |
130 | 2724 | jorpiell | lnkICatalogServerDriver = new SRWCatalogServiceDriver();
|
131 | } |
||
132 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_CATALOG_CSW))) { |
133 | 2724 | jorpiell | lnkICatalogServerDriver = new CSWCatalogServiceDriver();
|
134 | } |
||
135 | 3486 | jorpiell | if (protocol.equals(new String(ServerData.SERVER_SUBTYPE_CATALOG_Z3950))) { |
136 | 2724 | jorpiell | lnkICatalogServerDriver = new Z3950CatalogServiceDriver();
|
137 | } |
||
138 | 3566 | jorpiell | } |
139 | |||
140 | /**
|
||
141 | *
|
||
142 | *
|
||
143 | 3613 | jorpiell | *
|
144 | 3566 | jorpiell | * @return
|
145 | */
|
||
146 | 6112 | jorpiell | public String getCapabilities() { |
147 | 3510 | jorpiell | //try to connect
|
148 | if (!serverReady()) {
|
||
149 | serverStatus = ("errorServerNotFound");
|
||
150 | } else if (!getLnkICatalogServerDriver().isProtocolSupported(getUrl())) { |
||
151 | serverStatus = "errorNotSupportedProtocol";
|
||
152 | } else {
|
||
153 | //getCapabilities
|
||
154 | 3566 | jorpiell | Collection nodesCapabilities = getLnkICatalogServerDriver()
|
155 | 3510 | jorpiell | .getCapabilities(getUrl()); |
156 | if (nodesCapabilities == null) { |
||
157 | serverStatus = "errorNotSupportedCapabilities";
|
||
158 | } else {
|
||
159 | //Configure the client
|
||
160 | if (!getLnkICatalogServerDriver().setParameters(nodesCapabilities,getUrl())) {
|
||
161 | if (!(getLnkICatalogServerDriver()
|
||
162 | .getServerAnswerReady().equals(""))) {
|
||
163 | serverStatus = getLnkICatalogServerDriver().getServerAnswerReady(); |
||
164 | } else {
|
||
165 | serverStatus = "errorNotParsedReply";
|
||
166 | } |
||
167 | } else {
|
||
168 | //Show the answer
|
||
169 | serverStatus = getLnkICatalogServerDriver().getServerAnswerReady(); |
||
170 | 6112 | jorpiell | return "2.0.0"; |
171 | 3510 | jorpiell | } |
172 | } |
||
173 | 6077 | jorpiell | if (getLnkICatalogServerDriver() instanceof CSWCatalogServiceDriver){ |
174 | ((CSWCatalogServiceDriver)getLnkICatalogServerDriver()).setVersion("2.0.1");
|
||
175 | ((CSWCatalogServiceDriver)getLnkICatalogServerDriver()).setService("http://www.opengis.net/cat/csw");
|
||
176 | ((CSWCatalogServiceDriver)getLnkICatalogServerDriver()).setServerProfile(Schemas.EBRIM); |
||
177 | nodesCapabilities = getLnkICatalogServerDriver().getCapabilities(getUrl()); |
||
178 | if (nodesCapabilities == null) { |
||
179 | serverStatus = "errorNotSupportedCapabilities";
|
||
180 | } else {
|
||
181 | //Configure the client
|
||
182 | if (!getLnkICatalogServerDriver().setParameters(nodesCapabilities,getUrl())) {
|
||
183 | if (!(getLnkICatalogServerDriver()
|
||
184 | .getServerAnswerReady().equals(""))) {
|
||
185 | serverStatus = getLnkICatalogServerDriver().getServerAnswerReady(); |
||
186 | } else {
|
||
187 | serverStatus = "errorNotParsedReply";
|
||
188 | } |
||
189 | } else {
|
||
190 | //Show the answer
|
||
191 | serverStatus = getLnkICatalogServerDriver().getServerAnswerReady(); |
||
192 | 6112 | jorpiell | return "2.0.1"; |
193 | 6077 | jorpiell | } |
194 | } |
||
195 | } |
||
196 | 3510 | jorpiell | } |
197 | |||
198 | 6112 | jorpiell | return null; |
199 | 3566 | jorpiell | } |
200 | 3613 | jorpiell | |
201 | /**
|
||
202 | *
|
||
203 | *
|
||
204 | *
|
||
205 | * @return Node array with the retrieved records
|
||
206 | * @param url Server URL
|
||
207 | * @param query It contains the values to do the query (title="XXX",abstract="YYY",...)
|
||
208 | * @param firstRecord Number of the first record to retrieve
|
||
209 | */
|
||
210 | public Collection getRecords(URL url, Query query, int firstRecord) { |
||
211 | 3598 | jorpiell | |
212 | return getLnkICatalogServerDriver().getRecords(url,query,firstRecord);
|
||
213 | |||
214 | |||
215 | 3613 | jorpiell | } |
216 | |||
217 | 3566 | jorpiell | /**
|
218 | * This method is used to create a new Query
|
||
219 | *
|
||
220 | *
|
||
221 | * @return
|
||
222 | */
|
||
223 | public Query createNewQuery() { |
||
224 | return new Query(); |
||
225 | } |
||
226 | |||
227 | /**
|
||
228 | * It tries if the server is ready
|
||
229 | *
|
||
230 | *
|
||
231 | * @return boolean
|
||
232 | * true --> server is ready
|
||
233 | * false --> server is not ready
|
||
234 | */
|
||
235 | private boolean serverReady() { |
||
236 | try {
|
||
237 | new Socket(this.getUrl().getHost(),this.getUrl().getPort()); |
||
238 | } catch (UnknownHostException e) { |
||
239 | // TODO Auto-generated catch block
|
||
240 | return false; |
||
241 | } catch (IOException e) { |
||
242 | // TODO Auto-generated catch block
|
||
243 | return false; |
||
244 | } |
||
245 | return true; |
||
246 | } |
||
247 | |||
248 | /**
|
||
249 | *
|
||
250 | *
|
||
251 | *
|
||
252 | * @return Returns the lnkICatalogServerDriver.
|
||
253 | */
|
||
254 | public ICatalogServiceDriver getLnkICatalogServerDriver() {
|
||
255 | 2724 | jorpiell | return lnkICatalogServerDriver;
|
256 | 3566 | jorpiell | } |
257 | 2047 | luisw | |
258 | 3566 | jorpiell | /**
|
259 | *
|
||
260 | *
|
||
261 | *
|
||
262 | * @param lnkICatalogServerDriver The lnkICatalogServerDriver to set.
|
||
263 | */
|
||
264 | public void setLnkICatalogServerDriver(ICatalogServiceDriver lnkICatalogServerDriver) { |
||
265 | 2724 | jorpiell | this.lnkICatalogServerDriver = lnkICatalogServerDriver;
|
266 | 3566 | jorpiell | } |
267 | 2145 | jorpiell | |
268 | 3566 | jorpiell | /**
|
269 | *
|
||
270 | *
|
||
271 | *
|
||
272 | * @return Returns the protocol.
|
||
273 | */
|
||
274 | public String getProtocol() { |
||
275 | 2724 | jorpiell | return protocol;
|
276 | 3566 | jorpiell | } |
277 | 2724 | jorpiell | |
278 | 3566 | jorpiell | /**
|
279 | *
|
||
280 | *
|
||
281 | *
|
||
282 | * @param protocol The protocol to set.
|
||
283 | */
|
||
284 | public void setProtocol(String protocol) { |
||
285 | 2724 | jorpiell | this.protocol = protocol;
|
286 | 3566 | jorpiell | } |
287 | 2724 | jorpiell | |
288 | 3566 | jorpiell | /**
|
289 | *
|
||
290 | *
|
||
291 | *
|
||
292 | * @return Returns the url.
|
||
293 | */
|
||
294 | public URL getUrl() { |
||
295 | 2724 | jorpiell | return url;
|
296 | 3566 | jorpiell | } |
297 | |||
298 | /**
|
||
299 | *
|
||
300 | *
|
||
301 | *
|
||
302 | * @return Returns the sUrl.
|
||
303 | */
|
||
304 | public String getSUrl() { |
||
305 | 3225 | jorpiell | return sURL;
|
306 | 3566 | jorpiell | } |
307 | 2724 | jorpiell | |
308 | 3566 | jorpiell | /**
|
309 | *
|
||
310 | *
|
||
311 | *
|
||
312 | * @param url The url to set.
|
||
313 | */
|
||
314 | public void setUrl(URL url) { |
||
315 | 2724 | jorpiell | this.url = url;
|
316 | 3566 | jorpiell | } |
317 | 2724 | jorpiell | |
318 | 3566 | jorpiell | /**
|
319 | *
|
||
320 | *
|
||
321 | *
|
||
322 | * @return Returns the sURL.
|
||
323 | */
|
||
324 | public String getSURL() { |
||
325 | return sURL;
|
||
326 | } |
||
327 | 2145 | jorpiell | |
328 | 3566 | jorpiell | /**
|
329 | *
|
||
330 | *
|
||
331 | *
|
||
332 | * @param surl The sURL to set.
|
||
333 | */
|
||
334 | public void setSURL(String surl) { |
||
335 | 3225 | jorpiell | sURL = surl; |
336 | 3566 | jorpiell | } |
337 | 3510 | jorpiell | |
338 | 3566 | jorpiell | /**
|
339 | *
|
||
340 | *
|
||
341 | *
|
||
342 | * @return Returns the serverStatus.
|
||
343 | */
|
||
344 | public String getServerStatus() { |
||
345 | 3510 | jorpiell | return serverStatus;
|
346 | 3566 | jorpiell | } |
347 | 8765 | jjdelcerro | |
348 | /**
|
||
349 | * Return true if the services search is supported
|
||
350 | * @return
|
||
351 | */
|
||
352 | public boolean isServicesSeachSupported(){ |
||
353 | if (url.getHost().equals("laits.gmu.edu")){ |
||
354 | return true; |
||
355 | } |
||
356 | return false; |
||
357 | } |
||
358 | 3566 | jorpiell | } |