Statistics
| Revision:

root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / gazetteer / idec / drivers / IDECGazetteerServiceDriver.java @ 15558

History | View | Annotate | Download (5.64 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.idec.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.apache.commons.httpclient.NameValuePair;
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.HTTPGetProtocol;
55
import es.gva.cit.catalog.protocols.HTTPPostProtocol;
56
import es.gva.cit.catalog.utils.Strings;
57
import es.gva.cit.gazetteer.drivers.AbstractGazetteerServiceDriver;
58
import es.gva.cit.gazetteer.drivers.GazetteerCapabilities;
59
import es.gva.cit.gazetteer.idec.parsers.IdecCapabilitiesParser;
60
import es.gva.cit.gazetteer.idec.parsers.IdecFeatureParser;
61
import es.gva.cit.gazetteer.querys.Feature;
62
import es.gva.cit.gazetteer.querys.GazetteerQuery;
63

    
64
/**
65
 * This class connects with the IDEC gazetteer service
66
 * 
67
 * 
68
 * @author Jorge Piera Llodra (piera_jor@gva.es)
69
 */
70
public class IDECGazetteerServiceDriver extends AbstractGazetteerServiceDriver {
71

    
72
        /*
73
         * (non-Javadoc)
74
         * @see es.gva.cit.catalogClient.drivers.IDiscoveryServiceDriver#getCapabilities(java.net.URI)
75
         */
76
        public DiscoveryServiceCapabilities getCapabilities(URI uri) {        
77
                Collection nodes = new java.util.ArrayList();
78
                URL url = null;
79
                try {
80
                        url = uri.toURL();
81
                } catch (MalformedURLException e) {
82
                        setServerAnswerReady("errorServerNotFound");
83
                        return null;
84
                }       
85
                nodes = new HTTPGetProtocol().doQuery(url, getMessageCapabilities(), 0);
86
                IdecCapabilitiesParser.parse(this,(XMLNode)nodes.toArray()[0]);
87
                GazetteerCapabilities capabilities = new GazetteerCapabilities();
88
                capabilities.setFeatureTypes(getFeatureTypes());
89
                return capabilities;
90
        } 
91

    
92
        /**
93
         * It creates the name-value pairs for the getCapabilities request
94
         * @return Name-Value pair array
95
         */
96
        private NameValuePair[] getMessageCapabilities() {        
97
                NameValuePair nvp1 = new NameValuePair("wsdl", "");
98
                return new NameValuePair[] { nvp1 };
99
        }         
100
        
101
        /*
102
         * (non-Javadoc)
103
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getFeature(java.net.URI, es.gva.cit.gazetteer.querys.Query)
104
         */
105
        public Feature[] getFeature(URI uri, GazetteerQuery query) {        
106
                Collection nodes = new java.util.ArrayList();
107
                  URL url = null;
108
                        try {
109
                                url = uri.toURL();
110
                        } catch (MalformedURLException e) {
111
                                setServerAnswerReady("errorServerNotFound");
112
                                return null;
113
                        }       
114
                setQuery(query);
115
                System.out.println(getPOSTGetFeature(query));
116
                nodes = new HTTPPostProtocol().doQuery(url,getPOSTGetFeature(query),0);
117
                if ((nodes != null) && (nodes.size() == 1)){
118
                        return IdecFeatureParser.parse((XMLNode)nodes.toArray()[0]);
119
                }else{
120
                        return null;
121
                }
122
        } 
123

    
124
        /**
125
         * It creates the XML for the getFeature request
126
         * @return Name-value pair with a XML request
127
         * @param query 
128
         */
129
        private String getPOSTGetFeature(GazetteerQuery query) {        
130
                String name = query.getName();
131
                if (query.getOptions().getSearch().isWithAccents()){
132
                        name = Strings.removeAccents(name);
133
                }            
134
                return "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" +
135
                "<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:si=\"http://soapinterop.org/xsd\" xmlns:tns=\"urn:idecwsdl\">" +
136
                "<SOAP-ENV:Body><tns:getCoordenadesUTM xmlns:tns=\"urn:idecwsdl\">" +
137
                "<key xsi:type=\"xsd:string\">CV81HP6</key>" +
138
                "<toponim xsi:type=\"xsd:string\">" + name + "</toponim>" +
139
                "</tns:getCoordenadesUTM>" +
140
                "</SOAP-ENV:Body>" +
141
                "</SOAP-ENV:Envelope>";
142
        } 
143
        
144
        /*
145
         * (non-Javadoc)
146
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#isProtocolSupported(java.net.URI)
147
         */
148
        public boolean isProtocolSupported(URI uri) {        
149
                // TODO Auto-generated method stub
150
                return true;
151
        } 
152
        
153
        /*
154
         * (non-Javadoc)
155
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getDefaultPort()
156
         */
157
        public int getDefaultPort() {
158
                return 80;
159
        }
160

    
161
        /*
162
         * (non-Javadoc)
163
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getDefaultSchema()
164
         */
165
        public String getDefaultSchema() {
166
                return "http";
167
        }
168

    
169
        /*
170
         * (non-Javadoc)
171
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getServiceName()
172
         */
173
        public String getServiceName() {
174
                return ServerData.SERVER_SUBTYPE_GAZETTEER_IDEC;
175
        } 
176
}