Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wmts / wmts_1_0_0 / WMTSProtocolHandler1_0_0.java @ 40769

History | View | Annotate | Download (7.56 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.remoteclient.wmts.wmts_1_0_0;
25

    
26
import java.io.File;
27
import java.io.IOException;
28

    
29
import org.gvsig.remoteclient.utils.CapabilitiesTags;
30
import org.gvsig.remoteclient.utils.EncodingXMLParser;
31
import org.gvsig.remoteclient.wmts.WMTSProtocolHandler;
32
import org.gvsig.remoteclient.wmts.WMTSServerDescription;
33
import org.gvsig.remoteclient.wmts.WMTSServiceInformation;
34
import org.gvsig.remoteclient.wmts.WMTSStatus;
35
import org.gvsig.remoteclient.wmts.request.WMTSGetCapabilitiesRequest;
36
import org.gvsig.remoteclient.wmts.request.WMTSGetFeatureInfoRequest;
37
import org.gvsig.remoteclient.wmts.request.WMTSGetTileRequest;
38
import org.gvsig.remoteclient.wmts.struct.WMTSLayer;
39
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixSet;
40
import org.gvsig.remoteclient.wmts.wmts_1_0_0.request.WMTSGetCapabilitiesRequest1_0_0;
41
import org.gvsig.remoteclient.wmts.wmts_1_0_0.request.WMTSGetFeatureInfoRequest1_0_0;
42
import org.gvsig.remoteclient.wmts.wmts_1_0_0.request.WMTSGetTileRequest1_0_0;
43
import org.kxml2.io.KXmlParser;
44
import org.xmlpull.v1.XmlPullParserException;
45

    
46
/**
47
 * Describes the handler to comunicate to a WMTS 1.0.0
48
 *
49
 * @author Nacho Brodin (nachobrodin@gmail.com)
50
 */
51
public class WMTSProtocolHandler1_0_0 extends WMTSProtocolHandler {
52
        private String                    gmlTag             = CapabilitiesTags.WMTS_GMLTAG;
53
        private WMTSServerDescription     serverDescription  = null;
54
    
55
        public WMTSProtocolHandler1_0_0() {
56
                this.version = "1.0.0";
57
                this.name = "WMS1.0.0";
58
                this.serviceInfo = new WMTSServiceInformation(); 
59
        }
60
        
61
        /**
62
         * Sets the status object
63
         */
64
        public void setServerDescription(WMTSServerDescription serverDescription) {
65
                this.serverDescription = serverDescription;
66
        }
67

    
68
        public boolean parseCapabilities(File f) {       
69
            int tag;
70
            EncodingXMLParser parser = null;
71
            parser = new EncodingXMLParser();
72
            if(serverDescription != null)
73
                    serverDescription.clear();
74
            try {
75
                    parser.setInput(f);
76
                    parser.nextTag();
77
                    if ( parser.getEventType() != KXmlParser.END_DOCUMENT ) {                    
78
                            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WMTS_CAPABILITIES);                            
79
                            tag = parser.nextTag();
80
                                 while(tag != KXmlParser.END_DOCUMENT) {
81
                     switch(tag) {
82
                         
83
                                                case KXmlParser.START_TAG:
84
                                                        if (compareName(parser, CapabilitiesTags.WMTS_SERVICEID)) {
85
                                                                serverDescription.getServiceIdentification().parse(parser);
86
                                                        } else if (compareName(parser, CapabilitiesTags.WMTS_SERVICEPROV )) {
87
                                                                serverDescription.getServiceProvider().parse(parser);
88
                                                        } else if (compareName(parser, CapabilitiesTags.WMTS_OPMETADATA)) {
89
                                                                parser.skipSubTree();
90
                                                        } else if (compareName(parser, CapabilitiesTags.WMTS_CONTENTS )) {
91
                                                                parseServiceContent(parser, serverDescription);
92
                                                        } else if (compareName(parser, CapabilitiesTags.WMTS_THEMES )) {
93
                                                                serverDescription.getThemes().parse(parser);
94
                                                        }
95
                                                        break;
96
                                                case KXmlParser.END_TAG:                                                        
97
                                                        break;
98
                                                case KXmlParser.TEXT:
99
                                                                                                
100
                                                break;
101
                                         }
102
                                     tag = parser.next();
103
                             }
104

    
105
                            parser.require(KXmlParser.END_DOCUMENT, null, null);
106
                    }
107
            } catch(XmlPullParserException parser_ex) {
108
                    parser_ex.printStackTrace();
109
                    return false;
110
            } catch (IOException ioe) {                        
111
                           ioe.printStackTrace();
112
                           return false;
113
                } 
114
            
115
            //Calcula las referencias a las capas dentro de los temas
116
            serverDescription.getThemes().calculateLayers(serverDescription.getLayerList());
117
            //Si no hay temas definidos se calcula un tema por capa en forma de lista
118
            serverDescription.getThemes().loadThemesWithLayerInfo(serverDescription.getLayerList(), serverDescription);
119
            //Asocia los TileMatrixSet a los TileMatrixLimits
120
            for (int i = 0; i < serverDescription.getLayerList().size(); i++) {
121
                        WMTSLayer layer = (WMTSLayer)serverDescription.getLayerList().get(i);
122
                        layer.linkTileMatrixSets(serverDescription.getTileMatrixSet());
123
                }
124
        return true;
125
    } 
126
    
127
    /**
128
     * Parses the Content section    
129
     * @param parser
130
     * @throws IOException
131
     * @throws XmlPullParserException
132
     */
133
    private void parseServiceContent(KXmlParser parser, WMTSServerDescription content) throws IOException, XmlPullParserException {
134
            int currentTag;
135
            boolean end = false;
136
            
137
            currentTag = parser.next();
138
            
139
            while (!end) {
140
                         switch(currentTag) {
141
                                case KXmlParser.START_TAG:
142
                                        if (compareName(parser, CapabilitiesTags.WMTS_LAYER)) {
143
                                                WMTSLayer layer = content.buildNewLayer();
144
                                                layer.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder);
145
                                                layer.parse(parser);
146
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_OTHERSRC)) {
147
                                                parseOtherSource(parser); 
148
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TILEMATRIXSET)) {
149
                                                WMTSTileMatrixSet mSet = (WMTSTileMatrixSet)content.createVersionObject("WMTSTileMatrixSet");
150
                                                mSet.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder);
151
                                                mSet.parse(parser, content.getTileMatrixSet()); 
152
                                        }                        
153
                                        break;
154
                                case KXmlParser.END_TAG:
155
                                        if (compareName(parser, CapabilitiesTags.WMTS_CONTENTS))
156
                                                end = true;
157
                                        break;
158
                                case KXmlParser.TEXT:                                        
159
                                break;
160
                         }
161
             if (!end)
162
                 currentTag = parser.next();
163
            }
164
    }
165
    
166
    private void parseOtherSource(KXmlParser parser) throws IOException, XmlPullParserException {
167
            parser.skipSubTree();
168
    }
169
    
170
    /**
171
     * Compares the next name in the selected parser with the string passed
172
     * by value.
173
     * @param parser
174
     * @param name
175
     * @return
176
     */
177
    private boolean compareName(KXmlParser parser, String name) {
178
            String s = parser.getName();
179
            if(s.compareTo(name) == 0 || s.compareTo(gmlTag + name) == 0)
180
                    return true;
181
            return false;
182
    }
183

    
184
    /*
185
     * (non-Javadoc)
186
     * @see org.gvsig.remoteclient.wmts.WMTSProtocolHandler#createGetCapabilitiesRequest(org.gvsig.remoteclient.wms.WMSStatus)
187
     */
188
        protected WMTSGetCapabilitiesRequest createGetCapabilitiesRequest() {
189
                return new WMTSGetCapabilitiesRequest1_0_0(serverDescription, this);
190
        }
191
        
192
        /*
193
         * (non-Javadoc)
194
         * @see org.gvsig.remoteclient.wmts.WMTSProtocolHandler#createGetTileRequest()
195
         */
196
        protected WMTSGetTileRequest createGetTileRequest(WMTSStatus status) {
197
                return new WMTSGetTileRequest1_0_0(status, this);
198
        }
199
        
200
        /*
201
         * (non-Javadoc)
202
         * @see org.gvsig.remoteclient.wmts.WMTSProtocolHandler#createGetFeatureInfoRequest(org.gvsig.remoteclient.wmts.WMTSStatus, int, int)
203
         */
204
        protected WMTSGetFeatureInfoRequest createGetFeatureInfoRequest(WMTSStatus status, int x, int y) {
205
                return new WMTSGetFeatureInfoRequest1_0_0(status, this, x, y);
206
        }
207
}