gvsig-raster / org.gvsig.raster.wmts / trunk / org.gvsig.raster.wmts / org.gvsig.raster.wmts.ogc / org.gvsig.raster.wmts.ogc.impl / src / main / java / org / gvsig / raster / wmts / ogc / impl / wmts_1_0_0 / WMTSProtocolHandler1_0_0.java @ 1811
History | View | Annotate | Download (7.02 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.wmts.ogc.impl.wmts_1_0_0; |
23 |
|
24 |
import java.io.File; |
25 |
import java.io.IOException; |
26 |
|
27 |
import org.gvsig.raster.wmts.ogc.impl.EncodingXMLParser; |
28 |
import org.gvsig.raster.wmts.ogc.impl.Tags; |
29 |
import org.gvsig.raster.wmts.ogc.impl.base.WMTSProtocolHandler; |
30 |
import org.gvsig.raster.wmts.ogc.impl.base.WMTSServerDescription; |
31 |
import org.gvsig.raster.wmts.ogc.impl.base.WMTSServiceInformation; |
32 |
import org.gvsig.raster.wmts.ogc.impl.base.WMTSStatusImpl; |
33 |
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetCapabilitiesRequest; |
34 |
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetFeatureInfoRequest; |
35 |
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetTileRequest; |
36 |
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSLayerImpl; |
37 |
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSTileMatrixSetImpl; |
38 |
import org.gvsig.raster.wmts.ogc.impl.wmts_1_0_0.request.WMTSGetCapabilitiesRequest1_0_0; |
39 |
import org.gvsig.raster.wmts.ogc.impl.wmts_1_0_0.request.WMTSGetFeatureInfoRequest1_0_0; |
40 |
import org.gvsig.raster.wmts.ogc.impl.wmts_1_0_0.request.WMTSGetTileRequest1_0_0; |
41 |
import org.kxml2.io.KXmlParser; |
42 |
import org.xmlpull.v1.XmlPullParserException; |
43 |
|
44 |
/**
|
45 |
* Describes the handler to comunicate to a WMTS 1.0.0
|
46 |
*
|
47 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
48 |
*/
|
49 |
public class WMTSProtocolHandler1_0_0 extends WMTSProtocolHandler { |
50 |
private String gmlTag = Tags.WMTS_GMLTAG; |
51 |
private WMTSServerDescription serverDescription = null; |
52 |
|
53 |
public WMTSProtocolHandler1_0_0() {
|
54 |
this.version = "1.0.0"; |
55 |
this.name = "WMS1.0.0"; |
56 |
this.serviceInfo = new WMTSServiceInformation(); |
57 |
} |
58 |
|
59 |
/**
|
60 |
* Sets the status object
|
61 |
*/
|
62 |
public void setServerDescription(WMTSServerDescription serverDescription) { |
63 |
this.serverDescription = serverDescription;
|
64 |
} |
65 |
|
66 |
public boolean parseCapabilities(File f) { |
67 |
int tag;
|
68 |
EncodingXMLParser parser = null;
|
69 |
parser = new EncodingXMLParser();
|
70 |
if(serverDescription != null) |
71 |
serverDescription.clear(); |
72 |
try {
|
73 |
parser.setInput(f); |
74 |
parser.nextTag(); |
75 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT ) {
|
76 |
parser.require(KXmlParser.START_TAG, null, Tags.WMTS_CAPABILITIES);
|
77 |
tag = parser.nextTag(); |
78 |
while(tag != KXmlParser.END_DOCUMENT) {
|
79 |
switch(tag) {
|
80 |
|
81 |
case KXmlParser.START_TAG:
|
82 |
if (compareName(parser, Tags.WMTS_SERVICEID)) {
|
83 |
serverDescription.getServiceIdentification().parse(parser); |
84 |
} else if (compareName(parser, Tags.WMTS_SERVICEPROV )) { |
85 |
serverDescription.getServiceProvider().parse(parser); |
86 |
} else if (compareName(parser, Tags.WMTS_OPMETADATA)) { |
87 |
parser.skipSubTree(); |
88 |
} else if (compareName(parser, Tags.WMTS_CONTENTS )) { |
89 |
parseServiceContent(parser, serverDescription); |
90 |
} else if (compareName(parser, Tags.WMTS_THEMES )) { |
91 |
serverDescription.getThemes().parse(parser); |
92 |
} |
93 |
break;
|
94 |
case KXmlParser.END_TAG:
|
95 |
break;
|
96 |
case KXmlParser.TEXT:
|
97 |
|
98 |
break;
|
99 |
} |
100 |
tag = parser.next(); |
101 |
} |
102 |
|
103 |
parser.require(KXmlParser.END_DOCUMENT, null, null); |
104 |
} |
105 |
} catch(XmlPullParserException parser_ex) {
|
106 |
parser_ex.printStackTrace(); |
107 |
return false; |
108 |
} catch (IOException ioe) { |
109 |
ioe.printStackTrace(); |
110 |
return false; |
111 |
} |
112 |
|
113 |
//Calcula las referencias a las capas dentro de los temas
|
114 |
serverDescription.getThemes().calculateLayers(serverDescription.getLayerList()); |
115 |
//Si no hay temas definidos se calcula un tema por capa en forma de lista
|
116 |
serverDescription.getThemes().loadThemesWithLayerInfo(serverDescription.getLayerList(), serverDescription); |
117 |
//Asocia los TileMatrixSet a los TileMatrixLimits
|
118 |
for (int i = 0; i < serverDescription.getLayerList().size(); i++) { |
119 |
WMTSLayerImpl layer = (WMTSLayerImpl)serverDescription.getLayerList().get(i); |
120 |
layer.linkTileMatrixSets(serverDescription.getTileMatrixSet()); |
121 |
} |
122 |
return true; |
123 |
} |
124 |
|
125 |
/**
|
126 |
* Parses the Content section
|
127 |
* @param parser
|
128 |
* @throws IOException
|
129 |
* @throws XmlPullParserException
|
130 |
*/
|
131 |
private void parseServiceContent(KXmlParser parser, WMTSServerDescription content) throws IOException, XmlPullParserException { |
132 |
int currentTag;
|
133 |
boolean end = false; |
134 |
|
135 |
currentTag = parser.next(); |
136 |
|
137 |
while (!end) {
|
138 |
switch(currentTag) {
|
139 |
case KXmlParser.START_TAG:
|
140 |
if (compareName(parser, Tags.WMTS_LAYER)) {
|
141 |
WMTSLayerImpl layer = content.buildNewLayer(); |
142 |
layer.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder); |
143 |
layer.parse(parser); |
144 |
} else if (compareName(parser, Tags.WMTS_OTHERSRC)) { |
145 |
parseOtherSource(parser); |
146 |
} else if (compareName(parser, Tags.WMTS_TILEMATRIXSET)) { |
147 |
WMTSTileMatrixSetImpl mSet = (WMTSTileMatrixSetImpl)content.createVersionObject("WMTSTileMatrixSet");
|
148 |
mSet.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder); |
149 |
mSet.parse(parser, content.getTileMatrixSet()); |
150 |
} |
151 |
break;
|
152 |
case KXmlParser.END_TAG:
|
153 |
if (compareName(parser, Tags.WMTS_CONTENTS))
|
154 |
end = true;
|
155 |
break;
|
156 |
case KXmlParser.TEXT:
|
157 |
break;
|
158 |
} |
159 |
if (!end)
|
160 |
currentTag = parser.next(); |
161 |
} |
162 |
} |
163 |
|
164 |
private void parseOtherSource(KXmlParser parser) throws IOException, XmlPullParserException { |
165 |
parser.skipSubTree(); |
166 |
} |
167 |
|
168 |
/**
|
169 |
* Compares the next name in the selected parser with the string passed
|
170 |
* by value.
|
171 |
* @param parser
|
172 |
* @param name
|
173 |
* @return
|
174 |
*/
|
175 |
private boolean compareName(KXmlParser parser, String name) { |
176 |
String s = parser.getName();
|
177 |
if(s.compareTo(name) == 0 || s.compareTo(gmlTag + name) == 0) |
178 |
return true; |
179 |
return false; |
180 |
} |
181 |
|
182 |
public WMTSGetCapabilitiesRequest createGetCapabilitiesRequest() {
|
183 |
return new WMTSGetCapabilitiesRequest1_0_0(serverDescription, this); |
184 |
} |
185 |
|
186 |
public WMTSGetTileRequest createGetTileRequest(WMTSStatusImpl status) {
|
187 |
return new WMTSGetTileRequest1_0_0(status, this); |
188 |
} |
189 |
|
190 |
public WMTSGetFeatureInfoRequest createGetFeatureInfoRequest(WMTSStatusImpl status, int x, int y) { |
191 |
return new WMTSGetFeatureInfoRequest1_0_0(status, this, x, y); |
192 |
} |
193 |
} |