gvsig-catalog / trunk / appCatalog / src / org / gvsig / catalog / srw / drivers / SRWCatalogServiceDriver.java @ 6
History | View | Annotate | Download (6.67 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
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 |
* Av. Blasco Ib??ez, 50
|
25 |
* 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 |
package org.gvsig.catalog.srw.drivers; |
43 |
import java.net.MalformedURLException; |
44 |
import java.net.URI; |
45 |
import java.net.URL; |
46 |
import java.util.Collection; |
47 |
import java.util.StringTokenizer; |
48 |
|
49 |
import org.gvsig.catalog.drivers.AbstractCatalogServiceDriver; |
50 |
import org.gvsig.catalog.drivers.CatalogCapabilities; |
51 |
import org.gvsig.catalog.drivers.DiscoveryServiceCapabilities; |
52 |
import org.gvsig.catalog.drivers.GetRecordsReply; |
53 |
import org.gvsig.catalog.metadataxml.XMLNode; |
54 |
import org.gvsig.catalog.metadataxml.XMLTree; |
55 |
import org.gvsig.catalog.protocols.HTTPGetProtocol; |
56 |
import org.gvsig.catalog.protocols.SOAPProtocol; |
57 |
import org.gvsig.catalog.querys.CatalogQuery; |
58 |
import org.gvsig.catalog.srw.parsers.SrwCapabilitiesParser; |
59 |
import org.gvsig.utils.swing.jcomboServer.ServerData; |
60 |
|
61 |
|
62 |
|
63 |
/**
|
64 |
* This class implements the CSW protocol.
|
65 |
*
|
66 |
*
|
67 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
68 |
* @see http://www.loc.gov/z3950/agency/zing/srw/
|
69 |
*/
|
70 |
public class SRWCatalogServiceDriver extends AbstractCatalogServiceDriver { |
71 |
private String version = "1.1"; |
72 |
private String recordXPath; |
73 |
private String resultSetTTL; |
74 |
|
75 |
/*
|
76 |
* (non-Javadoc)
|
77 |
* @see es.gva.cit.catalogClient.drivers.ICatalogServiceDriver#getCapabilities(java.net.URI)
|
78 |
*/
|
79 |
public DiscoveryServiceCapabilities getCapabilities(URI uri) { |
80 |
URL url = null; |
81 |
try {
|
82 |
url = uri.toURL(); |
83 |
} catch (MalformedURLException e) { |
84 |
setServerAnswerReady("errorServerNotFound");
|
85 |
return null; |
86 |
} |
87 |
SRWMessages messages = new SRWMessages(this); |
88 |
Collection nodes = new HTTPGetProtocol().doQuery(url, |
89 |
messages.getHTTPGETCapabilities(true), 0); |
90 |
|
91 |
nodes = new SOAPProtocol().doQuery(url, messages.getSOAPCapabilities(), 0); |
92 |
new SrwCapabilitiesParser(this).parse((XMLNode)nodes.toArray()[0]); |
93 |
CatalogCapabilities capabilities = new CatalogCapabilities();
|
94 |
capabilities.setVersion(version); |
95 |
capabilities.setServerMessage(getServerAnswerReady()); |
96 |
return capabilities;
|
97 |
} |
98 |
|
99 |
/*
|
100 |
* (non-Javadoc)
|
101 |
* @see es.gva.cit.catalogClient.drivers.ICatalogServiceDriver#getRecords(java.net.URI, es.gva.cit.catalogClient.querys.Query, int)
|
102 |
*/
|
103 |
public GetRecordsReply getRecords(URI uri, CatalogQuery query, int firstRecord) { |
104 |
URL url = null; |
105 |
try {
|
106 |
url = uri.toURL(); |
107 |
} catch (MalformedURLException e) { |
108 |
setServerAnswerReady("errorServerNotFound");
|
109 |
return null; |
110 |
} |
111 |
setQuery(query); |
112 |
SRWMessages messages = new SRWMessages(this); |
113 |
Collection nodes = new java.util.ArrayList(); |
114 |
|
115 |
//TODO remove this comparation
|
116 |
if (url.getHost().equals("idee.unizar.es")){ |
117 |
try {
|
118 |
url = new URL("http://idee.unizar.es/SRW/servlet/search/SRW"); |
119 |
} catch (MalformedURLException e) { |
120 |
// It will never throws
|
121 |
} |
122 |
} |
123 |
|
124 |
XMLNode root = null;
|
125 |
nodes = new SOAPProtocol().doQuery(url,
|
126 |
messages.getSOAPRecords(getQuery(), firstRecord), firstRecord); |
127 |
root = (XMLNode)nodes.toArray()[0];
|
128 |
root = root.getSubNode(0).getSubNode(0); |
129 |
|
130 |
String prefix = new StringTokenizer(root.getName(), ":").nextToken(); |
131 |
if (prefix.equals(root.getName())) {
|
132 |
prefix = "";
|
133 |
} else {
|
134 |
prefix = prefix + ":";
|
135 |
} |
136 |
int numberOfRecords = getNumberOfRecords(root,
|
137 |
prefix + "numberOfRecords",
|
138 |
null);
|
139 |
|
140 |
if (numberOfRecords == -1) { |
141 |
return null; |
142 |
} |
143 |
GetRecordsReply recordsReply = new GetRecordsReply(numberOfRecords);
|
144 |
|
145 |
parseRecords(root,recordsReply,uri,prefix,numberOfRecords,firstRecord); |
146 |
return recordsReply;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Parser the XML
|
151 |
* @param node
|
152 |
* @param recordsReply
|
153 |
* @param uri
|
154 |
* @param prefix
|
155 |
* @param numberOfRecords
|
156 |
* @param firstRecord
|
157 |
*/
|
158 |
private void parseRecords(XMLNode node, GetRecordsReply recordsReply, URI uri, String prefix, int numberOfRecords, int firstRecord) { |
159 |
|
160 |
XMLNode[] auxNodes = XMLTree.searchMultipleNode(node,
|
161 |
prefix + "records->" + prefix + "record"); |
162 |
for (int i = 1; (i <= numberOfRecords) && (i <= 10) && (i <= (numberOfRecords - firstRecord + 1)); i++){ |
163 |
recordsReply.addRecord(uri, auxNodes[i - 1]);
|
164 |
} |
165 |
|
166 |
} |
167 |
|
168 |
/**
|
169 |
*
|
170 |
*
|
171 |
*
|
172 |
* @return Returns the recordXPath.
|
173 |
*/
|
174 |
public String getRecordXPath() { |
175 |
return recordXPath;
|
176 |
} |
177 |
|
178 |
/**
|
179 |
*
|
180 |
*
|
181 |
*
|
182 |
* @param recordXPath The recordXPath to set.
|
183 |
*/
|
184 |
public void setRecordXPath(String recordXPath) { |
185 |
this.recordXPath = recordXPath;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
*
|
190 |
*
|
191 |
*
|
192 |
* @return Returns the resultSetTTL.
|
193 |
*/
|
194 |
public String getResultSetTTL() { |
195 |
return resultSetTTL;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
*
|
200 |
*
|
201 |
*
|
202 |
* @param resultSetTTL The resultSetTTL to set.
|
203 |
*/
|
204 |
public void setResultSetTTL(String resultSetTTL) { |
205 |
this.resultSetTTL = resultSetTTL;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
*
|
210 |
*
|
211 |
*
|
212 |
* @return Returns the version.
|
213 |
*/
|
214 |
public String getVersion() { |
215 |
return version;
|
216 |
} |
217 |
|
218 |
/**
|
219 |
*
|
220 |
*
|
221 |
*
|
222 |
* @param version The version to set.
|
223 |
*/
|
224 |
public void setVersion(String version) { |
225 |
this.version = version;
|
226 |
} |
227 |
|
228 |
/*
|
229 |
* (non-Javadoc)
|
230 |
* @see es.gva.cit.catalogClient.drivers.ICatalogServiceDriver#isProtocolSupported(java.net.URI)
|
231 |
*/
|
232 |
public boolean isProtocolSupported(URI uri) { |
233 |
return SOAPProtocol.isProtocolSupported(null); |
234 |
} |
235 |
|
236 |
/*
|
237 |
* (non-Javadoc)
|
238 |
* @see es.gva.cit.catalogClient.drivers.ICatalogServiceDriver#getServiceName()
|
239 |
*/
|
240 |
public String getServiceName() { |
241 |
return ServerData.SERVER_SUBTYPE_CATALOG_SRW;
|
242 |
} |
243 |
|
244 |
/*
|
245 |
* (non-Javadoc)
|
246 |
* @see es.gva.cit.catalogClient.drivers.ICatalogServiceDriver#getDefaultPort()
|
247 |
*/
|
248 |
public int getDefaultPort() { |
249 |
return 80; |
250 |
} |
251 |
|
252 |
/*
|
253 |
* (non-Javadoc)
|
254 |
* @see es.gva.cit.catalogClient.drivers.ICatalogServiceDriver#getDefaultSchema()
|
255 |
*/
|
256 |
public String getDefaultSchema() { |
257 |
return "http"; |
258 |
} |
259 |
} |