gvsig-catalog / org.gvsig.catalog / branches / org.gvsig.catalog-CSW2.0.2 / org.gvsig.catalog / org.gvsig.catalog.lib / src / main / java / org / gvsig / catalog / protocols / HTTPGetProtocol.java @ 55
History | View | Annotate | Download (2.59 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.protocols; |
43 |
import java.io.File; |
44 |
import java.net.URL; |
45 |
import java.util.Collection; |
46 |
|
47 |
import org.apache.commons.httpclient.NameValuePair; |
48 |
import org.gvsig.catalog.metadataxml.XMLTree; |
49 |
import org.gvsig.remoteclient.utils.Utilities; |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*
|
54 |
*
|
55 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
56 |
*/
|
57 |
public class HTTPGetProtocol implements IProtocols { |
58 |
|
59 |
/**
|
60 |
*
|
61 |
*
|
62 |
*
|
63 |
* @return
|
64 |
* @param url
|
65 |
* @param object
|
66 |
* @param firstRecord
|
67 |
*/
|
68 |
public Collection doQuery(URL url, Object object, int firstRecord) { |
69 |
NameValuePair[] parameters = (NameValuePair[]) object; |
70 |
File file = null; |
71 |
|
72 |
String sUrl = "http://" + url.getHost() + ":" + |
73 |
url.getPort() + url.getPath(); |
74 |
sUrl = sUrl + createURLParams(parameters); |
75 |
|
76 |
try {
|
77 |
file = Utilities.downloadFile(new URL(sUrl), |
78 |
"catalog-", null); |
79 |
|
80 |
} catch (Exception e) { |
81 |
return null; |
82 |
} |
83 |
|
84 |
Collection col = new java.util.ArrayList(); |
85 |
col.add(XMLTree.xmlToTree(file)); |
86 |
return col;
|
87 |
} |
88 |
|
89 |
/**
|
90 |
* Create and string for a list of params
|
91 |
* @param params
|
92 |
* @return
|
93 |
*/
|
94 |
private String createURLParams(NameValuePair[] params){ |
95 |
StringBuffer buffer = new StringBuffer(); |
96 |
for (int i=0 ; i<params.length ; i++){ |
97 |
if (i==0){ |
98 |
buffer.append("?");
|
99 |
}else{
|
100 |
buffer.append("&");
|
101 |
} |
102 |
buffer.append(params[i].getName()); |
103 |
buffer.append("=");
|
104 |
buffer.append(params[i].getValue()); |
105 |
} |
106 |
return buffer.toString();
|
107 |
} |
108 |
|
109 |
} |