Statistics
| Revision:

root / trunk / applications / appCatalogYNomenclatorClient / src / es / gva / cit / gazetteer / parsers / wfsg / WfsgCapabilitiesParser.java @ 3069

History | View | Annotate | Download (5.39 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*
19
* For more information, contact:
20
*
21
*  Generalitat Valenciana
22
*   Conselleria d'Infraestructures i Transport
23
*   Av. Blasco Ib??ez, 50
24
*   46010 VALENCIA
25
*   SPAIN
26
*
27
*      +34 963862235
28
*   gvsig@gva.es
29
*      www.gvsig.gva.es
30
*
31
*    or
32
*
33
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package es.gva.cit.gazetteer.parsers.wfsg;
42

    
43
import java.util.Vector;
44

    
45
import org.w3c.dom.Node;
46

    
47
import es.gva.cit.catalogClient.metadataXML.XMLTree;
48
import es.gva.cit.catalogClient.querys.Coordinates;
49
import es.gva.cit.gazetteer.drivers.WFSGazetteerServiceDriver;
50
import es.gva.cit.gazetteer.querys.ThesaurusName;
51

    
52
/**
53
 * This class parses a WFs-G getCapabilities file
54
 * 
55
 * @author Jorge Piera Llodra (piera_jor@gva.es)
56
 */
57
public class WfsgCapabilitiesParser {
58
    WFSGazetteerServiceDriver driver;
59
    Node rootNode = null;
60
  
61
    public WfsgCapabilitiesParser(WFSGazetteerServiceDriver driver) {
62
        this.driver = driver;
63
    }
64
    
65
    public boolean parse(Node node){
66
        setRootNode(node);
67
        
68
        driver.setServerAnswerReady(XMLTree.searchNodeValue(node,
69
                "Service->Title") + "\n" +
70
                XMLTree.searchNodeValue(node,
71
                "Service->Abstract"));
72
            
73
        parseGetCapabilities();
74
        parseDescribeFeatureType();
75
        parseGetFeature();
76
        parseFeatures();
77
             
78
        return true;
79
    }
80
    
81
    /**
82
     * It parses the getCapabilities operation options
83
     *
84
     */
85
    public void parseGetCapabilities() {
86
            driver.setOperations(new WfsgProtocolsOperations());
87
        driver.getOperations().setGetCapabilities(getOperations("GetCapabilities"));
88
    }
89
    
90
    /**
91
     * It parses the DescribeFeatureType operation options
92
     *
93
     */    
94
    public void parseDescribeFeatureType(){
95
        driver.getOperations().setDescribeFeatureType(getOperations("DescribeFeatureType"));
96
    }
97
    
98
    /**
99
     * It parses the GetFeature operation options
100
     *
101
     */
102
    public void parseGetFeature(){
103
        driver.getOperations().setGetFeature(getOperations("GetFeature"));
104
    }
105
    
106
    /**
107
     * It parses the Feature Types
108
     *
109
     */    
110
    public void parseFeatures(){
111
        Node[] features = XMLTree.searchMultipleNode(getRootNode(),"FeatureTypeList->FeatureType");
112
        Vector v = new Vector();
113
        for (int i=0 ; i<features.length ; i++){
114
            v.add(parseFeature(features[i]));
115
        }
116
        driver.setVectorFeatures(v);
117
        
118
    }
119
    
120
    /**
121
     * It parses a Feature Node.
122
     * @param featureNode
123
     * @return
124
     */
125
    public ThesaurusName parseFeature(Node featureNode){
126
        ThesaurusName f = new ThesaurusName();
127
        f.setName(XMLTree.searchNodeValue(featureNode,"Name"));
128
        f.setTitle(XMLTree.searchNodeValue(featureNode,"Title"));
129
        f.setAbstract(XMLTree.searchNodeValue(featureNode,"Abstract"));
130
        f.setKeywords(XMLTree.searchNodeValue(featureNode,"Keywords"));
131
        f.setSrs(XMLTree.searchNodeValue(featureNode,"SRS"));
132
        f.setCoordinates(new Coordinates(XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","minx"),
133
                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","miny"),
134
                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","maxx"),
135
                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","maxy")));
136
              
137
        return f;
138
    }
139
    /**
140
     * This function parses the protocols of an operation
141
     * @param operation
142
     * Operation to find the supported protocols
143
     * @return
144
     */
145
    
146
    public String[] getOperations(String operation){
147
        Node[] protocols = XMLTree.searchMultipleNode(getRootNode(),"Capability->Request->" + operation + "->DCPType");
148
        Vector vProtocols = new Vector();
149
          
150
        for (int i=0 ; i<protocols.length ; i++){
151
            if (XMLTree.searchNode(protocols[i],"HTTP->Get") != null){
152
                vProtocols.add("GET");
153
            }
154
            if (XMLTree.searchNode(protocols[i],"HTTP->Post") != null){
155
                vProtocols.add("POST");
156
            }
157
            
158
        }  
159
        
160
        String[] sProtocols = new String[vProtocols.size()];
161
        for (int i=0 ; i<vProtocols.size() ; i++){
162
            sProtocols[i] = (String) vProtocols.get(i);
163
        }        
164
        
165
       return sProtocols;
166
    }
167
    
168
    /**
169
     * @return Returns the rootNode.
170
     */
171
    public Node getRootNode() {
172
        return rootNode;
173
    }
174
    /**
175
     * @param rootNode The rootNode to set.
176
     */
177
    public void setRootNode(Node rootNode) {
178
        this.rootNode = rootNode;
179
    }
180
}