Statistics
| Revision:

root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / gazetteer / adl / drivers / ADLGazetteerServiceDriver.java @ 15558

History | View | Annotate | Download (5.69 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.catalog.drivers.DiscoveryServiceCapabilities;
51
import es.gva.cit.catalog.metadataxml.XMLNode;
52
import es.gva.cit.catalog.protocols.HTTPPostProtocol;
53
import es.gva.cit.gazetteer.adl.filters.ADLFilter;
54
import es.gva.cit.gazetteer.adl.parsers.AdlCapabilitiesParser;
55
import es.gva.cit.gazetteer.adl.parsers.AdlFeatureParser;
56
import es.gva.cit.gazetteer.drivers.AbstractGazetteerServiceDriver;
57
import es.gva.cit.gazetteer.drivers.GazetteerCapabilities;
58
import es.gva.cit.gazetteer.querys.Feature;
59
import es.gva.cit.gazetteer.querys.GazetteerQuery;
60

    
61
/**
62
 * This class implements the driver to connect with a
63
 * ADL gazetteer service
64
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
65
 * @see http://alexandria.sdc.ucsb.edu/
66
 */
67
public class ADLGazetteerServiceDriver extends AbstractGazetteerServiceDriver {
68

    
69
        /*
70
         * (non-Javadoc)
71
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getCapabilities(java.net.URI)
72
         */
73
        public DiscoveryServiceCapabilities getCapabilities(URI uri) {        
74
                GazetteerCapabilities capabilities = new GazetteerCapabilities();
75
                Collection nodes = new java.util.ArrayList();  
76
                 URL url = null;
77
                        try {
78
                                url = uri.toURL();
79
                        } catch (MalformedURLException e) {
80
                                capabilities.setServerMessage("errorServerNotFound");
81
                                capabilities.setAvailable(false);
82
                                return capabilities;
83
                        }        
84
                try {
85
                        nodes = new HTTPPostProtocol().doQuery(uri.toURL(),
86
                                        getPOSTMessageCapabilities(), 0);
87
                } catch (MalformedURLException e) {
88
                        capabilities.setServerMessage(e.getMessage());
89
                        capabilities.setAvailable(false);
90
                        return capabilities;
91
                }                
92
                new AdlCapabilitiesParser(this).parse((XMLNode)nodes.toArray()[0]);
93
                capabilities.setFeatureTypes(getFeatureTypes());
94
                capabilities.setServerMessage(getServerAnswerReady());
95
                return capabilities;
96
        } 
97
        
98
        /**
99
         * It creates the XML for the getCapabilities request
100
         * @return Name-value pair with a XML request
101
         */
102
        private String getPOSTMessageCapabilities() {        
103
                return "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" +
104
                "<gazetteer-service " +
105
                "xmlns=\"http://www.alexandria.ucsb.edu/gazetteer\" " +
106
                "version=\"1.2\">" +
107
                "<get-capabilities-request/>" +
108
                "</gazetteer-service>";        
109
        }         
110
        
111
        /*
112
         * (non-Javadoc)
113
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getFeature(java.net.URI, es.gva.cit.gazetteer.querys.Query)
114
         */
115
        public Feature[] getFeature(URI uri, GazetteerQuery query) {        
116
                Collection nodes = new java.util.ArrayList();
117
                setQuery(query);
118
                URL url = null;
119
                try {
120
                        url = uri.toURL();
121
                } catch (MalformedURLException e) {
122
                        setServerAnswerReady("errorServerNotFound");
123
                        return null;
124
                }    
125
                System.out.println("**************POST*************");
126
                System.out.println(getPOSTGetFeature(getQuery(),true));
127
                nodes = new HTTPPostProtocol().doQuery(url,
128
                                getPOSTGetFeature(getQuery(),true), 0);
129

    
130
                if (nodes == null){
131
                        System.out.println(getPOSTGetFeature(getQuery(),false));
132
                        nodes = new HTTPPostProtocol().doQuery(url,
133
                                        getPOSTGetFeature(getQuery(),false), 0);
134
                }
135
                if ((nodes != null) && (nodes.size() == 1)){
136
                        return AdlFeatureParser.parse((XMLNode)nodes.toArray()[0]);
137
                }else{
138
                        return null;
139
                }
140
        } 
141

    
142
        /**
143
         * It creates the XML for the getFeature request
144
         * @return Name-value pair with a XML request
145
         * @param query 
146
         */
147
        private String getPOSTGetFeature(GazetteerQuery query,boolean withAccents) {        
148
                return  "<gazetteer-service " +
149
                "xmlns=\"http://www.alexandria.ucsb.edu/gazetteer\" " +
150
                "xmlns:gml=\"http://www.opengis.net/gml\" " +
151
                "version=\"1.2\">" +
152
                new ADLFilter(withAccents).getQuery(query) +
153
                "</gazetteer-service>" ;
154
        } 
155
        
156
        /*
157
         * (non-Javadoc)
158
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#isProtocolSupported(java.net.URI)
159
         */
160
        public boolean isProtocolSupported(URI uri) {        
161
                // TODO Auto-generated method stub
162
                return true;
163
        }         
164

    
165
        /*
166
         * (non-Javadoc)
167
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getDefaultPort()
168
         */
169
        public int getDefaultPort() {
170
                return 80;
171
        }
172

    
173
        /*
174
         * (non-Javadoc)
175
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getDefaultSchema()
176
         */
177
        public String getDefaultSchema() {
178
                return "http";
179
        }
180

    
181
        /*
182
         * (non-Javadoc)
183
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getServiceName()
184
         */
185
        public String getServiceName() {
186
                return ServerData.SERVER_SUBTYPE_GAZETTEER_ADL;
187
        }
188
}