Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / applications / appCatalogAndGazetteerClient / src / es / gva / cit / gazetteer / wfsg / drivers / WFSGServiceDriver.java @ 18851

History | View | Annotate | Download (4.52 KB)

1
package es.gva.cit.gazetteer.wfsg.drivers;
2

    
3
import java.io.File;
4
import java.io.IOException;
5
import java.net.ConnectException;
6
import java.net.MalformedURLException;
7
import java.net.URI;
8
import java.net.URL;
9
import java.net.UnknownHostException;
10
import java.util.Collection;
11

    
12
import org.gvsig.i18n.Messages;
13
import org.gvsig.remoteClient.gml.exceptions.GMLException;
14
import org.gvsig.remoteClient.utils.Utilities;
15

    
16
import com.iver.utiles.swing.jcomboServer.ServerData;
17

    
18
import es.gva.cit.catalog.drivers.DiscoveryServiceCapabilities;
19
import es.gva.cit.catalog.metadataxml.XMLNode;
20
import es.gva.cit.catalog.protocols.HTTPPostProtocol;
21
import es.gva.cit.gazetteer.drivers.GazetteerCapabilities;
22
import es.gva.cit.gazetteer.querys.Feature;
23
import es.gva.cit.gazetteer.querys.GazetteerQuery;
24
import es.gva.cit.gazetteer.wfs.drivers.WFSServiceDriver;
25
import es.gva.cit.gazetteer.wfsg.parsers.WfsgCapabilitiesParser;
26
import es.gva.cit.gazetteer.wfsg.parsers.WfsgFeatureParser;
27

    
28
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
29
 *
30
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
31
 *
32
 * This program is free software; you can redistribute it and/or
33
 * modify it under the terms of the GNU General Public License
34
 * as published by the Free Software Foundation; either version 2
35
 * of the License, or (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
45
 *
46
 * For more information, contact:
47
 *
48
 *  Generalitat Valenciana
49
 *   Conselleria d'Infraestructures i Transport
50
 *   Av. Blasco Ib??ez, 50
51
 *   46010 VALENCIA
52
 *   SPAIN
53
 *
54
 *      +34 963862235
55
 *   gvsig@gva.es
56
 *      www.gvsig.gva.es
57
 *
58
 *    or
59
 *
60
 *   IVER T.I. S.A
61
 *   Salamanca 50
62
 *   46005 Valencia
63
 *   Spain
64
 *
65
 *   +34 963163400
66
 *   dac@iver.es
67
 */
68
/* CVS MESSAGES:
69
 *
70
 * $Id: WFSGServiceDriver.java 539 2007-07-26 11:21:38Z jpiera $
71
 * $Log$
72
 * Revision 1.1.2.2  2007/07/13 12:00:35  jorpiell
73
 * Add the posibility to add a new panel
74
 *
75
 * Revision 1.1.2.1  2007/07/10 11:18:04  jorpiell
76
 * Added the registers
77
 *
78
 *
79
 */
80
/**
81
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
82
 */
83
public class WFSGServiceDriver extends WFSServiceDriver {
84
        //TODO use the download manager instead of this
85
        private static final String tempDirectoryPath = System.getProperty("java.io.tmpdir")+"/tmp-andami";
86
        
87
        /*
88
         * (non-Javadoc)
89
         * @see es.gva.cit.gazetteer.wfs.drivers.WFSServiceDriver#getCapabilities(java.net.URI)
90
         */
91
        public DiscoveryServiceCapabilities getCapabilities(URI uri) {
92
                URL url = null;
93
                try {
94
                        url = uri.toURL();
95
                } catch (MalformedURLException e) {
96
                        setServerAnswerReady("errorServerNotFound");
97
                        return null;
98
                }
99
                Collection nodes = new HTTPPostProtocol().doQuery(url,
100
                                WFSGMessages.getHTTPPOSTCapabilities(), 0);
101
                
102
                GazetteerCapabilities capabilities = new GazetteerCapabilities();
103
                if (nodes != null){
104
                        capabilities.setFeatureTypes(new WfsgCapabilitiesParser(this).parse((XMLNode)nodes.toArray()[0]));
105
                }else{
106
                        capabilities.setAvailable(false);
107
                        capabilities.setServerMessage(Messages.getText("errorNotParsedReply"));
108
                }
109
                return capabilities;                
110
        }
111
        
112
        /*
113
         * (non-Javadoc)
114
         * @see es.gva.cit.gazetteer.wfs.drivers.WFSServiceDriver#getFeature(java.net.URI, es.gva.cit.gazetteer.querys.Query)
115
         */
116
         public Feature[] getFeature(URI uri, GazetteerQuery query) throws GMLException {        
117
                 URL url = null;
118
                        try {
119
                                url = uri.toURL();
120
                        } catch (MalformedURLException e) {
121
                                setServerAnswerReady("errorServerNotFound");
122
                                return null;
123
                        }
124
                        query.setFieldAttribute("geographicIdentifier");                        
125
                        try {
126
                                File file = Utilities.downloadFile(url, WFSGMessages.getHTTPPOSTFeature(query,0), "wfsg_getFeature.xml", null);
127
                                return parseOutputFile(file,query.getFieldAttribute());
128
                        } catch (Exception e) {
129
                                throw new GMLException(e);
130
                        }                                  
131
         }
132

    
133
        /*
134
         * (non-Javadoc)
135
         * @see es.gva.cit.gazetteer.drivers.AsbtractGazetteerServiceDriver#isDescribeFeatureTypeNeeded()
136
         */
137
        public boolean isDescribeFeatureTypeNeeded(){
138
                return false;
139
        }
140

    
141
        /*
142
         * (non-Javadoc)
143
         * @see es.gva.cit.gazetteer.drivers.IGazetteerServiceDriver#getServiceName()
144
         */
145
        public String getServiceName() {
146
                return ServerData.SERVER_SUBTYPE_GAZETTEER_WFSG;
147
        }        
148
}