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