svn-gvsig-desktop / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / csw / drivers / CSWMessages.java @ 3566
History | View | Annotate | Download (10.1 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 es.gva.cit.catalogClient.csw.drivers; |
43 |
import es.gva.cit.catalogClient.csw.filters.CSWFilter; |
44 |
import es.gva.cit.catalogClient.drivers.IProtocolMessages; |
45 |
import es.gva.cit.catalogClient.protocols.SOAPProtocol; |
46 |
import es.gva.cit.catalogClient.querys.Query; |
47 |
import es.gva.cit.catalogClient.schemas.Schemas; |
48 |
import es.gva.cit.catalogClient.utils.Strings; |
49 |
import org.apache.commons.httpclient.NameValuePair; |
50 |
|
51 |
/**
|
52 |
* This class has methods that return the CSW opearions messages.
|
53 |
*
|
54 |
*
|
55 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
56 |
*/
|
57 |
public class CSWMessages implements IProtocolMessages { |
58 |
/**
|
59 |
*
|
60 |
*
|
61 |
*/
|
62 |
private CSWCatalogServiceDriver driver;
|
63 |
|
64 |
/**
|
65 |
*
|
66 |
*
|
67 |
*
|
68 |
* @param driver
|
69 |
*/
|
70 |
public CSWMessages(CSWCatalogServiceDriver driver) {
|
71 |
this.driver = driver;
|
72 |
} |
73 |
/* (non-Javadoc)
|
74 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPGETCapabilities()
|
75 |
*/
|
76 |
|
77 |
/**
|
78 |
*
|
79 |
*
|
80 |
*
|
81 |
* @return
|
82 |
* @param upper
|
83 |
*/
|
84 |
public NameValuePair[] getHTTPGETCapabilities(boolean upper) { |
85 |
NameValuePair nvp1 = null;
|
86 |
if (upper){
|
87 |
nvp1 = new NameValuePair("request", "GetCapabilities"); |
88 |
}else{
|
89 |
nvp1 = new NameValuePair("request", "getCapabilities"); |
90 |
} |
91 |
|
92 |
NameValuePair nvp2 = new NameValuePair("service", "CSW"); |
93 |
NameValuePair nvp3 = new NameValuePair("acceptversion", driver.getVersion()); |
94 |
return new NameValuePair[] { nvp1, nvp2, nvp3 }; |
95 |
} |
96 |
/* (non-Javadoc)
|
97 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPGETDescribeRecords()
|
98 |
*/
|
99 |
|
100 |
/**
|
101 |
*
|
102 |
*
|
103 |
*
|
104 |
* @return
|
105 |
*/
|
106 |
public NameValuePair[] getHTTPGETDescribeRecords() { |
107 |
NameValuePair nvp1 = new NameValuePair("request", "describeRecord"); |
108 |
NameValuePair nvp2 = new NameValuePair("version", driver.getVersion()); |
109 |
NameValuePair nvp3 = new NameValuePair("outputformat", |
110 |
driver.getOutputFormat()); |
111 |
NameValuePair nvp4 = new NameValuePair("schemalanguage", "XMLSCHEMA"); |
112 |
NameValuePair nvp5 = new NameValuePair("typename", |
113 |
driver.getTypeNames()[0]);
|
114 |
NameValuePair nvp6 = new NameValuePair("namespace", |
115 |
"csw:http://www.opengis.org/csw");
|
116 |
return new NameValuePair[] { nvp1, nvp2, nvp3, nvp4, nvp5, nvp6 }; |
117 |
} |
118 |
/* (non-Javadoc)
|
119 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPGETRecords(es.gva.cit.catalogClient.querys.Query, int)
|
120 |
*/
|
121 |
|
122 |
/**
|
123 |
*
|
124 |
*
|
125 |
*
|
126 |
* @return
|
127 |
* @param query
|
128 |
* @param firstRecord
|
129 |
*/
|
130 |
public NameValuePair[] getHTTPGETRecords(Query query, int firstRecord) { |
131 |
|
132 |
NameValuePair nvp1 = new NameValuePair("request", "GetRecords"); |
133 |
NameValuePair nvp2 = new NameValuePair("version", driver.getVersion()); |
134 |
NameValuePair nvp3 = new NameValuePair("service", "CSW"); |
135 |
NameValuePair nvp4 = new NameValuePair("TypeNames",Strings.getComaSeparated(driver.getTypeNames())); |
136 |
|
137 |
NameValuePair nvp5 = new NameValuePair("outputschema", |
138 |
driver.getOutputSchema()[0]);
|
139 |
|
140 |
NameValuePair nvp6 = new NameValuePair("namespace", |
141 |
"csw:http://www.opengis.org/csw");
|
142 |
|
143 |
NameValuePair nvp7 = new NameValuePair("elementsetname", "full"); |
144 |
|
145 |
NameValuePair nvp8 = new NameValuePair("constraintlanguage", "FILTER"); |
146 |
|
147 |
NameValuePair nvp9 = new NameValuePair("constraint", |
148 |
new CSWFilter().getQuery(query,driver.getServerProfile()));
|
149 |
|
150 |
|
151 |
return new NameValuePair[] { |
152 |
nvp1, nvp2, nvp3, nvp4, nvp5, nvp6, nvp7, nvp8, nvp9 |
153 |
}; |
154 |
} |
155 |
/* (non-Javadoc)
|
156 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPPOSTCapabilities()
|
157 |
*/
|
158 |
|
159 |
/**
|
160 |
*
|
161 |
*
|
162 |
*
|
163 |
* @return
|
164 |
*/
|
165 |
public String getHTTPPOSTCapabilities() { |
166 |
return "<csw:GetCapabilities service=\"CSW\" version=\"2.0.0\" " + |
167 |
"xmlns:csw=\"http://www.opengis.net/cat/csw\" " +
|
168 |
"xmlns:ogc=\"http://www.opengis.net/ogc\">" +
|
169 |
"<AcceptVersions xmlns=\"http://www.opengis.net/ows\">" +
|
170 |
"<Version>" + driver.getVersion() + "</Version>" + "</AcceptVersions>" + |
171 |
"<AcceptFormats xmlns=\"http://www.opengis.net/ows\">" +
|
172 |
"<OutputFormat>text/xml</OutputFormat>" + "</AcceptFormats>" + |
173 |
"</csw:GetCapabilities>";
|
174 |
} |
175 |
/* (non-Javadoc)
|
176 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPPOSTDescribeRecords()
|
177 |
*/
|
178 |
|
179 |
/**
|
180 |
*
|
181 |
*
|
182 |
*
|
183 |
* @return
|
184 |
*/
|
185 |
public String getHTTPPOSTDescribeRecords() { |
186 |
return "<csw:DescribeRecord " + |
187 |
"xmlns:csw=\"http://www.opengis.net/cat/csw\" " +
|
188 |
"xmlns:ogc=\"http://www.opengis.net/ogc\" " + "service=\"CSW\" " + |
189 |
"version=" + driver.getVersion() + " " + "outputFormat=\"test/xml\" " + |
190 |
"schemaLanguage=\"XMLSCHEMA\">" +
|
191 |
"<csw:TypeName>csw:record</csw:TypeName>" +
|
192 |
"</csw:DescribeRecord>";
|
193 |
} |
194 |
/* (non-Javadoc)
|
195 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getHTTPPOSTRecords(es.gva.cit.catalogClient.querys.Query, int)
|
196 |
*/
|
197 |
|
198 |
/**
|
199 |
*
|
200 |
*
|
201 |
*
|
202 |
* @return
|
203 |
* @param query
|
204 |
* @param firstRecord
|
205 |
*/
|
206 |
public String getHTTPPOSTRecords(Query query, int firstRecord) { |
207 |
|
208 |
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + |
209 |
"<GetRecords " + "service=\"CSW\" " + |
210 |
"version=\"2.0.0\" " + "xmlns=\"http://www.opengis.net/cat/csw\" " + |
211 |
"xmlns:ogc=\"http://www.opengis.net/ogc\" " +
|
212 |
"xmlns:gml=\"http://www.opengis.net/gml\" " + "startPosition='" + |
213 |
firstRecord + "' " + "maxRecords='10' " + |
214 |
"outputFormat=\"" + driver.getOutputFormat() + "\" " + |
215 |
"outputSchema=\"" + getOutputSchema(driver.getOutputSchema()) + "\" " + |
216 |
"resultType=\"" +
|
217 |
getResultType(driver.getResultType()) + "\">" +
|
218 |
"<Query typeNames=\"" +
|
219 |
Strings.getBlankSeparated(driver.getTypeNames()) + "\">" +
|
220 |
getElementSetNameLabel() + |
221 |
getMaxSetName(driver.getElementSetName()) + "</ElementSetName>" +
|
222 |
"<Constraint version='1.0.20'>" +
|
223 |
new CSWFilter().getQuery(query,driver.getServerProfile()) +
|
224 |
"</Constraint>" +
|
225 |
"</Query>" +
|
226 |
"</GetRecords>";
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* The IDEC server has some different labels
|
231 |
*
|
232 |
*
|
233 |
* @return
|
234 |
*/
|
235 |
private String getElementSetNameLabel() { |
236 |
if (driver.getServerProfile().equals(Schemas.EBRIM)){
|
237 |
return "<ElementSetName typeNames='Dataset'>"; |
238 |
}else{
|
239 |
return "<ElementSetName>"; |
240 |
} |
241 |
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* It returns the maximum element set name
|
246 |
*
|
247 |
*
|
248 |
* @return
|
249 |
* @param elementSetName
|
250 |
*/
|
251 |
private String getMaxSetName(String[] elementSetName) { |
252 |
if (elementSetName == null) |
253 |
return "summary"; |
254 |
|
255 |
for (int i=0 ; i<elementSetName.length ; i++){ |
256 |
if ((elementSetName[i].equals("full")) || |
257 |
(elementSetName[i].equals("Full")) ||
|
258 |
(elementSetName[i].equals("FULL")))
|
259 |
return elementSetName[i];
|
260 |
} |
261 |
|
262 |
return elementSetName[0]; |
263 |
} |
264 |
|
265 |
/**
|
266 |
* Returns a common reslut type if the getCapabilities doesn't have
|
267 |
* one. Sometimes it works.
|
268 |
*
|
269 |
*
|
270 |
* @return Just one String
|
271 |
* @param resultType The array of result types parsed.
|
272 |
*/
|
273 |
private String getResultType(String[] resultType) { |
274 |
if (resultType == null) |
275 |
return "results"; |
276 |
|
277 |
return resultType[0]; |
278 |
} |
279 |
|
280 |
/**
|
281 |
* Returns the OutputSchema. If the ISO19115 is supported,
|
282 |
* we prefer this
|
283 |
*
|
284 |
* @param OutputFormat The array of outputFormats parsed.
|
285 |
*
|
286 |
* @return Just one String
|
287 |
* @param outputSchemas
|
288 |
*/
|
289 |
private String getOutputSchema(String[] outputSchemas) { |
290 |
for (int i=0 ; i<outputSchemas.length ; i++){ |
291 |
if (outputSchemas[i].equals(Schemas.ISO19115))
|
292 |
return outputSchemas[i];
|
293 |
} |
294 |
return outputSchemas[0]; |
295 |
} |
296 |
/* (non-Javadoc)
|
297 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getSOAPCapabilities()
|
298 |
*/
|
299 |
|
300 |
/**
|
301 |
*
|
302 |
*
|
303 |
*
|
304 |
* @return
|
305 |
*/
|
306 |
public String getSOAPCapabilities() { |
307 |
return SOAPProtocol.setSOAPMessage(getHTTPPOSTCapabilities(),null); |
308 |
} |
309 |
/* (non-Javadoc)
|
310 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getSOAPDescribeRecords()
|
311 |
*/
|
312 |
|
313 |
/**
|
314 |
*
|
315 |
*
|
316 |
*
|
317 |
* @return
|
318 |
*/
|
319 |
public String getSOAPDescribeRecords() { |
320 |
return SOAPProtocol.setSOAPMessage(getHTTPPOSTDescribeRecords(),null); |
321 |
} |
322 |
/* (non-Javadoc)
|
323 |
* @see es.gva.cit.catalogClient.drivers.messages.IProtocolOperations#getSOAPRecords(es.gva.cit.catalogClient.querys.Query, int)
|
324 |
*/
|
325 |
|
326 |
/**
|
327 |
*
|
328 |
*
|
329 |
*
|
330 |
* @return
|
331 |
* @param query
|
332 |
* @param firstRecord
|
333 |
*/
|
334 |
public String getSOAPRecords(Query query, int firstRecord) { |
335 |
return SOAPProtocol.setSOAPMessage(getHTTPPOSTRecords(query,
|
336 |
firstRecord),null);
|
337 |
} |
338 |
} |