Revision 4488 trunk/applications/appCatalogYNomenclatorClient/src/es/gva/cit/gazetteer/wfsg/parsers/WfsgCapabilitiesParser.java

View differences:

WfsgCapabilitiesParser.java
1 1

  
2 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
*/
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 42
package es.gva.cit.gazetteer.wfsg.parsers;
43 43
import es.gva.cit.catalogClient.metadataXML.XMLNode;
44 44
import es.gva.cit.catalogClient.metadataXML.XMLTree;
......
54 54
 * @author Jorge Piera Llodra (piera_jor@gva.es)
55 55
 */
56 56
public class WfsgCapabilitiesParser {
57
/**
58
 * 
59
 * 
60
 */
61
    WFSGazetteerServiceDriver driver;
62
/**
63
 * 
64
 * 
65
 */
66
    XMLNode rootNode = null;
57
	/**
58
	 * 
59
	 * 
60
	 */
61
	WFSGazetteerServiceDriver driver;
62
	/**
63
	 * 
64
	 * 
65
	 */
66
	XMLNode rootNode = null;
67 67

  
68
/**
69
 * 
70
 * 
71
 * 
72
 * @param driver 
73
 */
74
    public  WfsgCapabilitiesParser(WFSGazetteerServiceDriver driver) {        
75
        this.driver = driver;
76
    } 
68
	/**
69
	 * 
70
	 * 
71
	 * 
72
	 * @param driver 
73
	 */
74
	public  WfsgCapabilitiesParser(WFSGazetteerServiceDriver driver) {        
75
		this.driver = driver;
76
	} 
77 77

  
78
/**
79
 * 
80
 * 
81
 * 
82
 * @return 
83
 * @param node 
84
 */
85
    public boolean parse(XMLNode node) {        
86
        if ((node == null) || !(node.getName().equals("WFS_Capabilities"))){
87
            driver.setServerAnswerReady("El servidor no soporta el protocolo " +
88
                    "especificado");
89
            return false;
90
        }
91
        
92
        
93
        setRootNode(node);
94
        
95
        driver.setServerAnswerReady(XMLTree.searchNodeValue(node,
96
                "Service->Title") + "\n" +
97
                XMLTree.searchNodeValue(node,
98
                "Service->Abstract"));
99
            
100
        parseGetCapabilities();
101
        parseDescribeFeatureType();
102
        parseGetFeature();
103
        parseFeatures();
104
             
105
        return true;
106
    } 
78
	/**
79
	 * 
80
	 * 
81
	 * 
82
	 * @return 
83
	 * @param node 
84
	 */
85
	public boolean parse(XMLNode node) {        
86
		if ((node == null) || !(node.getName().equals("WFS_Capabilities"))){
87
			driver.setServerAnswerReady("El servidor no soporta el protocolo " +
88
			"especificado");
89
			return false;
90
		}
107 91

  
108
/**
109
 * It parses the getCapabilities operation options
110
 * 
111
 */
112
    public void parseGetCapabilities() {        
113
    	driver.setOperations(new WfsgProtocolsOperations());
114
        driver.getOperations().setGetCapabilities(getOperations("GetCapabilities"));
115
    } 
116 92

  
117
/**
118
 * It parses the DescribeFeatureType operation options
119
 * 
120
 */
121
    public void parseDescribeFeatureType() {        
122
        driver.getOperations().setDescribeFeatureType(getOperations("DescribeFeatureType"));
123
    } 
93
		setRootNode(node);
124 94

  
125
/**
126
 * It parses the GetFeature operation options
127
 * 
128
 */
129
    public void parseGetFeature() {        
130
        driver.getOperations().setGetFeature(getOperations("GetFeature"));
131
    } 
95
		driver.setServerAnswerReady(XMLTree.searchNodeValue(node,
96
		"Service->Title") + "\n" +
97
		XMLTree.searchNodeValue(node,"Service->Abstract"));
132 98

  
133
/**
134
 * It parses the Feature Types
135
 * 
136
 */
137
    public void parseFeatures() {        
138
        XMLNode[] features = XMLTree.searchMultipleNode(getRootNode(),"FeatureTypeList->FeatureType");
139
        Vector v = new Vector();
140
        for (int i=0 ; i<features.length ; i++){
141
            v.add(parseFeature(features[i]));
142
        }
143
        driver.setVectorFeatures(v);
144
        
145
    } 
99
		parseGetCapabilities();
100
		parseDescribeFeatureType();
101
		parseGetFeature();
102
		parseFeatures();
103
		parseProjection();
104
		return true;
105
	} 
146 106

  
147
/**
148
 * It parses a Feature Node.
149
 * 
150
 * 
151
 * @return 
152
 * @param featureNode 
153
 */
154
    public ThesaurusName parseFeature(XMLNode featureNode) {        
155
        ThesaurusName f = new ThesaurusName();
156
        f.setName(XMLTree.searchNodeValue(featureNode,"Name"));
157
        f.setTitle(XMLTree.searchNodeValue(featureNode,"Title"));
158
        if (f.getTitle() == null)
159
            f.setTitle(f.getName());
160
        f.setAbstract(XMLTree.searchNodeValue(featureNode,"Abstract"));
161
        f.setKeywords(XMLTree.searchNodeValue(featureNode,"Keywords"));
162
        f.setSrs(XMLTree.searchNodeValue(featureNode,"SRS"));
163
        f.setCoordinates(new Coordinates(XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","minx"),
164
                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","miny"),
165
                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","maxx"),
166
                XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","maxy")));
167
              
168
        return f;
169
    } 
107
	/**
108
	 * Parses the server projection
109
	 */
110
	public void parseProjection(){
111
		driver.setProjection(XMLTree.searchNodeValue(getRootNode(),"FeatureTypeList->FeatureType->SRS"));
112
	}
113
	/**
114
	 * It parses the getCapabilities operation options
115
	 * 
116
	 */
117
	public void parseGetCapabilities() {        
118
		driver.setOperations(new WfsgProtocolsOperations());
119
		driver.getOperations().setGetCapabilities(getOperations("GetCapabilities"));
120
	} 
170 121

  
171
/**
172
 * This function parses the protocols of an operation
173
 * 
174
 * 
175
 * @return 
176
 * @param operation Operation to find the supported protocols
177
 */
178
    public String[] getOperations(String operation) {        
179
        XMLNode[] protocols = XMLTree.searchMultipleNode(getRootNode(),"Capability->Request->" + operation + "->DCPType");
180
        Vector vProtocols = new Vector();
181
          
182
        for (int i=0 ; i<protocols.length ; i++){
183
            if (XMLTree.searchNode(protocols[i],"HTTP->Get") != null){
184
                vProtocols.add("GET");
185
            }
186
            if (XMLTree.searchNode(protocols[i],"HTTP->Post") != null){
187
                vProtocols.add("POST");
188
            }
189
            
190
        }  
191
        
192
        String[] sProtocols = new String[vProtocols.size()];
193
        for (int i=0 ; i<vProtocols.size() ; i++){
194
            sProtocols[i] = (String) vProtocols.get(i);
195
        }        
196
        
197
       return sProtocols;
198
    } 
122
	/**
123
	 * It parses the DescribeFeatureType operation options
124
	 * 
125
	 */
126
	public void parseDescribeFeatureType() {        
127
		driver.getOperations().setDescribeFeatureType(getOperations("DescribeFeatureType"));
128
	} 
199 129

  
200
/**
201
 * 
202
 * 
203
 * 
204
 * @return Returns the rootNode.
205
 */
206
    public XMLNode getRootNode() {        
207
        return rootNode;
208
    } 
130
	/**
131
	 * It parses the GetFeature operation options
132
	 * 
133
	 */
134
	public void parseGetFeature() {        
135
		driver.getOperations().setGetFeature(getOperations("GetFeature"));
136
	} 
209 137

  
210
/**
211
 * 
212
 * 
213
 * 
214
 * @param rootNode The rootNode to set.
215
 */
216
    public void setRootNode(XMLNode rootNode) {        
217
        this.rootNode = rootNode;
218
    } 
219
 }
138
	/**
139
	 * It parses the Feature Types
140
	 * 
141
	 */
142
	public void parseFeatures() {        
143
		XMLNode[] features = XMLTree.searchMultipleNode(getRootNode(),"FeatureTypeList->FeatureType");
144
		Vector v = new Vector();
145
		for (int i=0 ; i<features.length ; i++){
146
			v.add(parseFeature(features[i]));
147
		}
148
		driver.setVectorFeatures(v);
149

  
150
	} 
151

  
152
	/**
153
	 * It parses a Feature Node.
154
	 * 
155
	 * 
156
	 * @return 
157
	 * @param featureNode 
158
	 */
159
	public ThesaurusName parseFeature(XMLNode featureNode) {        
160
		ThesaurusName f = new ThesaurusName();
161
		f.setName(XMLTree.searchNodeValue(featureNode,"Name"));
162
		f.setTitle(XMLTree.searchNodeValue(featureNode,"Title"));
163
		if (f.getTitle() == null)
164
			f.setTitle(f.getName());
165
		f.setAbstract(XMLTree.searchNodeValue(featureNode,"Abstract"));
166
		f.setKeywords(XMLTree.searchNodeValue(featureNode,"Keywords"));
167
		f.setSrs(XMLTree.searchNodeValue(featureNode,"SRS"));
168
		f.setCoordinates(new Coordinates(XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","minx"),
169
				XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","miny"),
170
				XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","maxx"),
171
				XMLTree.searchNodeAtribute(featureNode,"LatLongBoundingBox","maxy")));
172

  
173
		return f;
174
	} 
175

  
176
	/**
177
	 * This function parses the protocols of an operation
178
	 * 
179
	 * 
180
	 * @return 
181
	 * @param operation Operation to find the supported protocols
182
	 */
183
	public String[] getOperations(String operation) {        
184
		XMLNode[] protocols = XMLTree.searchMultipleNode(getRootNode(),"Capability->Request->" + operation + "->DCPType");
185
		Vector vProtocols = new Vector();
186

  
187
		for (int i=0 ; i<protocols.length ; i++){
188
			if (XMLTree.searchNode(protocols[i],"HTTP->Get") != null){
189
				vProtocols.add("GET");
190
			}
191
			if (XMLTree.searchNode(protocols[i],"HTTP->Post") != null){
192
				vProtocols.add("POST");
193
			}
194

  
195
		}  
196

  
197
		String[] sProtocols = new String[vProtocols.size()];
198
		for (int i=0 ; i<vProtocols.size() ; i++){
199
			sProtocols[i] = (String) vProtocols.get(i);
200
		}        
201

  
202
		return sProtocols;
203
	} 
204

  
205
	/**
206
	 * 
207
	 * 
208
	 * 
209
	 * @return Returns the rootNode.
210
	 */
211
	public XMLNode getRootNode() {        
212
		return rootNode;
213
	} 
214

  
215
	/**
216
	 * 
217
	 * 
218
	 * 
219
	 * @param rootNode The rootNode to set.
220
	 */
221
	public void setRootNode(XMLNode rootNode) {        
222
		this.rootNode = rootNode;
223
	} 
224
}

Also available in: Unified diff