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