svn-gvsig-desktop / branches / v10 / applications / appCatalogAndGazetteerClient / src / es / gva / cit / gazetteer / adl / drivers / ADLGazetteerServiceDriver.java @ 18851
History | View | Annotate | Download (5.86 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.gazetteer.adl.drivers; |
43 |
import java.net.MalformedURLException; |
44 |
import java.net.URI; |
45 |
import java.net.URL; |
46 |
import java.util.Collection; |
47 |
|
48 |
import org.gvsig.i18n.Messages; |
49 |
|
50 |
import com.iver.utiles.swing.jcomboServer.ServerData; |
51 |
|
52 |
import es.gva.cit.catalog.drivers.DiscoveryServiceCapabilities; |
53 |
import es.gva.cit.catalog.metadataxml.XMLNode; |
54 |
import es.gva.cit.catalog.protocols.HTTPPostProtocol; |
55 |
import es.gva.cit.gazetteer.adl.filters.ADLFilter; |
56 |
import es.gva.cit.gazetteer.adl.parsers.AdlCapabilitiesParser; |
57 |
import es.gva.cit.gazetteer.adl.parsers.AdlFeatureParser; |
58 |
import es.gva.cit.gazetteer.drivers.AbstractGazetteerServiceDriver; |
59 |
import es.gva.cit.gazetteer.drivers.GazetteerCapabilities; |
60 |
import es.gva.cit.gazetteer.querys.Feature; |
61 |
import es.gva.cit.gazetteer.querys.GazetteerQuery; |
62 |
|
63 |
/**
|
64 |
* This class implements the driver to connect with a
|
65 |
* ADL gazetteer service
|
66 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
67 |
* @see http://alexandria.sdc.ucsb.edu/
|
68 |
*/
|
69 |
public class ADLGazetteerServiceDriver extends AbstractGazetteerServiceDriver { |
70 |
|
71 |
/*
|
72 |
* (non-Javadoc)
|
73 |
* @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getCapabilities(java.net.URI)
|
74 |
*/
|
75 |
public DiscoveryServiceCapabilities getCapabilities(URI uri) { |
76 |
GazetteerCapabilities capabilities = new GazetteerCapabilities();
|
77 |
Collection nodes = new java.util.ArrayList(); |
78 |
URL url = null; |
79 |
try {
|
80 |
url = uri.toURL(); |
81 |
} catch (MalformedURLException e) { |
82 |
capabilities.setServerMessage("errorServerNotFound");
|
83 |
capabilities.setAvailable(false);
|
84 |
return capabilities;
|
85 |
} |
86 |
try {
|
87 |
nodes = new HTTPPostProtocol().doQuery(uri.toURL(),
|
88 |
getPOSTMessageCapabilities(), 0);
|
89 |
} catch (MalformedURLException e) { |
90 |
capabilities.setServerMessage(e.getMessage()); |
91 |
capabilities.setAvailable(false);
|
92 |
return capabilities;
|
93 |
} |
94 |
if (nodes != null){ |
95 |
new AdlCapabilitiesParser(this).parse((XMLNode)nodes.toArray()[0]); |
96 |
capabilities.setFeatureTypes(getFeatureTypes()); |
97 |
capabilities.setServerMessage(getServerAnswerReady()); |
98 |
}else{
|
99 |
capabilities.setAvailable(false);
|
100 |
capabilities.setServerMessage(Messages.getText("errorNotParsedReply"));
|
101 |
} |
102 |
return capabilities;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* It creates the XML for the getCapabilities request
|
107 |
* @return Name-value pair with a XML request
|
108 |
*/
|
109 |
private String getPOSTMessageCapabilities() { |
110 |
return "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + |
111 |
"<gazetteer-service " +
|
112 |
"xmlns=\"http://www.alexandria.ucsb.edu/gazetteer\" " +
|
113 |
"version=\"1.2\">" +
|
114 |
"<get-capabilities-request/>" +
|
115 |
"</gazetteer-service>";
|
116 |
} |
117 |
|
118 |
/*
|
119 |
* (non-Javadoc)
|
120 |
* @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getFeature(java.net.URI, es.gva.cit.gazetteer.querys.Query)
|
121 |
*/
|
122 |
public Feature[] getFeature(URI uri, GazetteerQuery query) { |
123 |
Collection nodes = new java.util.ArrayList(); |
124 |
setQuery(query); |
125 |
URL url = null; |
126 |
try {
|
127 |
url = uri.toURL(); |
128 |
} catch (MalformedURLException e) { |
129 |
setServerAnswerReady("errorServerNotFound");
|
130 |
return null; |
131 |
} |
132 |
System.out.println("**************POST*************"); |
133 |
System.out.println(getPOSTGetFeature(getQuery(),true)); |
134 |
nodes = new HTTPPostProtocol().doQuery(url,
|
135 |
getPOSTGetFeature(getQuery(),true), 0); |
136 |
|
137 |
if (nodes == null){ |
138 |
System.out.println(getPOSTGetFeature(getQuery(),false)); |
139 |
nodes = new HTTPPostProtocol().doQuery(url,
|
140 |
getPOSTGetFeature(getQuery(),false), 0); |
141 |
} |
142 |
if ((nodes != null) && (nodes.size() == 1)){ |
143 |
return AdlFeatureParser.parse((XMLNode)nodes.toArray()[0]); |
144 |
}else{
|
145 |
return null; |
146 |
} |
147 |
} |
148 |
|
149 |
/**
|
150 |
* It creates the XML for the getFeature request
|
151 |
* @return Name-value pair with a XML request
|
152 |
* @param query
|
153 |
*/
|
154 |
private String getPOSTGetFeature(GazetteerQuery query,boolean withAccents) { |
155 |
return "<gazetteer-service " + |
156 |
"xmlns=\"http://www.alexandria.ucsb.edu/gazetteer\" " +
|
157 |
"xmlns:gml=\"http://www.opengis.net/gml\" " +
|
158 |
"version=\"1.2\">" +
|
159 |
new ADLFilter(withAccents).getQuery(query) +
|
160 |
"</gazetteer-service>" ;
|
161 |
} |
162 |
|
163 |
/*
|
164 |
* (non-Javadoc)
|
165 |
* @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#isProtocolSupported(java.net.URI)
|
166 |
*/
|
167 |
public boolean isProtocolSupported(URI uri) { |
168 |
// TODO Auto-generated method stub
|
169 |
return true; |
170 |
} |
171 |
|
172 |
/*
|
173 |
* (non-Javadoc)
|
174 |
* @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getDefaultPort()
|
175 |
*/
|
176 |
public int getDefaultPort() { |
177 |
return 80; |
178 |
} |
179 |
|
180 |
/*
|
181 |
* (non-Javadoc)
|
182 |
* @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getDefaultSchema()
|
183 |
*/
|
184 |
public String getDefaultSchema() { |
185 |
return "http"; |
186 |
} |
187 |
|
188 |
/*
|
189 |
* (non-Javadoc)
|
190 |
* @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getServiceName()
|
191 |
*/
|
192 |
public String getServiceName() { |
193 |
return ServerData.SERVER_SUBTYPE_GAZETTEER_ADL;
|
194 |
} |
195 |
} |