Statistics
| Revision:

root / trunk / applications / appCatalogAndGazetteerClient / src / es / gva / cit / gazetteer / wfsg / parsers / WfsgCapabilitiesParser.java @ 15558

History | View | Annotate | Download (4.74 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.wfsg.parsers;
43
import java.util.Vector;
44

    
45
import es.gva.cit.catalog.metadataxml.XMLNode;
46
import es.gva.cit.catalog.metadataxml.XMLTree;
47
import es.gva.cit.catalog.querys.Coordinates;
48
import es.gva.cit.gazetteer.querys.FeatureType;
49
import es.gva.cit.gazetteer.wfs.drivers.WFSServiceDriver;
50

    
51
/**
52
 * This class parses a WFs-G getCapabilities file
53
 * 
54
 * 
55
 * @author Jorge Piera Llodra (piera_jor@gva.es)
56
 */
57
public class WfsgCapabilitiesParser {
58
        WFSServiceDriver driver;
59
        XMLNode rootNode = null;
60

    
61
        /**
62
         * @param driver 
63
         */
64
        public  WfsgCapabilitiesParser(WFSServiceDriver driver) {        
65
                this.driver = driver;
66
        } 
67

    
68
        /**
69
         * @return 
70
         * @param node 
71
         */
72
        public FeatureType[] parse(XMLNode node) {        
73
                if ((node == null) || !(node.getName().equals("WFS_Capabilities"))){
74
                        driver.setServerAnswerReady("El servidor no soporta el protocolo " +
75
                        "especificado");
76
                        return null;
77
                }
78

    
79

    
80
                setRootNode(node);
81

    
82
                driver.setServerAnswerReady(XMLTree.searchNodeValue(node,
83
                "Service->Title") + "\n" +
84
                XMLTree.searchNodeValue(node,"Service->Abstract"));
85
                FeatureType[] features = parseFeatures();
86
                parseProjection();
87
                return features;
88
        } 
89

    
90
        /**
91
         * Parses the server projection
92
         */
93
        public void parseProjection(){
94
                driver.setProjection(XMLTree.searchNodeValue(getRootNode(),"FeatureTypeList->FeatureType->SRS"));
95
        }
96

    
97

    
98
        /**
99
         * It parses the Feature Types
100
         * 
101
         */
102
        public FeatureType[] parseFeatures() {        
103
                XMLNode[] nodes = XMLTree.searchMultipleNode(getRootNode(),"FeatureTypeList->FeatureType");
104
                FeatureType[] features = new FeatureType[nodes.length];
105
                for (int i=0 ; i<features.length ; i++){
106
                        features[i] = (parseFeature(nodes[i]));
107
                }
108
                return features;
109
        } 
110

    
111
        /**
112
         * It parses a Feature Node.
113
         * @return 
114
         * @param featureNode 
115
         */
116
        public FeatureType parseFeature(XMLNode featureNode) {        
117
                FeatureType f = new FeatureType();
118
                f.setName(XMLTree.searchNodeValue(featureNode,"Name"));
119
                f.setTitle(XMLTree.searchNodeValue(featureNode,"Title"));
120
                if (f.getTitle() == null)
121
                        f.setTitle(f.getName());
122
                f.setAbstract(XMLTree.searchNodeValue(featureNode,"Abstract"));
123
                f.setKeywords(XMLTree.searchNodeValue(featureNode,"Keywords"));
124
                f.setSrs(XMLTree.searchNodeValue(featureNode,"SRS"));
125
                f.setCoordinates(new Coordinates(XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","minx"),
126
                                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","miny"),
127
                                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","maxx"),
128
                                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","maxy")));
129

    
130
                return f;
131
        } 
132

    
133
        /**
134
         * This function parses the protocols of an operation
135
         * @return 
136
         * @param operation Operation to find the supported protocols
137
         */
138
        public String[] getOperations(String operation) {        
139
                XMLNode[] protocols = XMLTree.searchMultipleNode(getRootNode(),"Capability->Request->" + operation + "->DCPType");
140
                Vector vProtocols = new Vector();
141

    
142
                for (int i=0 ; i<protocols.length ; i++){
143
                        if (XMLTree.searchNode(protocols[i],"HTTP->Get") != null){
144
                                vProtocols.add("GET");
145
                        }
146
                        if (XMLTree.searchNode(protocols[i],"HTTP->Post") != null){
147
                                vProtocols.add("POST");
148
                        }
149

    
150
                }  
151

    
152
                String[] sProtocols = new String[vProtocols.size()];
153
                for (int i=0 ; i<vProtocols.size() ; i++){
154
                        sProtocols[i] = (String) vProtocols.get(i);
155
                }        
156

    
157
                return sProtocols;
158
        } 
159

    
160
        /**
161
         * @return Returns the rootNode.
162
         */
163
        public XMLNode getRootNode() {        
164
                return rootNode;
165
        } 
166

    
167
        /**
168
         * @param rootNode The rootNode to set.
169
         */
170
        public void setRootNode(XMLNode rootNode) {        
171
                this.rootNode = rootNode;
172
        } 
173
}