Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wmts / wmts_1_0_0 / WMTSProtocolHandler1_0_0.java @ 35469

History | View | Annotate | Download (7.54 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.wmts.WMTSProtocolHandler;
30
import org.gvsig.remoteclient.wmts.WMTSServerDescription;
31
import org.gvsig.remoteclient.wmts.WMTSServiceInformation;
32
import org.gvsig.remoteclient.wmts.WMTSStatus;
33
import org.gvsig.remoteclient.wmts.request.WMTSGetCapabilitiesRequest;
34
import org.gvsig.remoteclient.wmts.request.WMTSGetFeatureInfoRequest;
35
import org.gvsig.remoteclient.wmts.request.WMTSGetTileRequest;
36
import org.gvsig.remoteclient.wmts.struct.WMTSLayer;
37
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrixSet;
38
import org.gvsig.remoteclient.wmts.wmts_1_0_0.request.WMTSGetCapabilitiesRequest1_0_0;
39
import org.gvsig.remoteclient.wmts.wmts_1_0_0.request.WMTSGetFeatureInfoRequest1_0_0;
40
import org.gvsig.remoteclient.wmts.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             = CapabilitiesTags.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 setStatus(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
            try {
71
                    parser.setInput(f);
72
                    parser.nextTag();
73
                    if ( parser.getEventType() != KXmlParser.END_DOCUMENT ) {                    
74
                            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WMTS_CAPABILITIES);                            
75
                            tag = parser.nextTag();
76
                                 while(tag != KXmlParser.END_DOCUMENT) {
77
                     switch(tag) {
78
                         
79
                                                case KXmlParser.START_TAG:
80
                                                        if(serverDescription == null)
81
                                                                serverDescription = new WMTSServerDescription(version);
82
                                                        if (compareName(parser, CapabilitiesTags.WMTS_SERVICEID)) {
83
                                                                serverDescription.getServiceIdentification().parse(parser);
84
                                                        } else if (compareName(parser, CapabilitiesTags.WMTS_SERVICEPROV )) {
85
                                                                serverDescription.getServiceProvider().parse(parser);
86
                                                        } else if (compareName(parser, CapabilitiesTags.WMTS_OPMETADATA)) {
87
                                                                parser.skipSubTree();
88
                                                        } else if (compareName(parser, CapabilitiesTags.WMTS_CONTENTS )) {
89
                                                                parseServiceContent(parser, serverDescription);
90
                                                        } else if (compareName(parser, CapabilitiesTags.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
                        WMTSLayer layer = (WMTSLayer)serverDescription.getLayerList().get(i);
120
                        layer.linkTileMatrixSets(serverDescription.getTileMatrixSet());
121
                        System.out.println();
122
                }
123
        return true;
124
    } 
125
    
126
    /**
127
     * Parses the Content section    
128
     * @param parser
129
     * @throws IOException
130
     * @throws XmlPullParserException
131
     */
132
    private void parseServiceContent(KXmlParser parser, WMTSServerDescription content) throws IOException, XmlPullParserException {
133
            int currentTag;
134
            boolean end = false;
135
            
136
            currentTag = parser.next();
137
            
138
            while (!end) {
139
                         switch(currentTag) {
140
                                case KXmlParser.START_TAG:
141
                                        if (compareName(parser, CapabilitiesTags.WMTS_LAYER)) {
142
                                                WMTSLayer layer = content.buildNewLayer();
143
                                                layer.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder);
144
                                                layer.parse(parser);
145
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_OTHERSRC)) {
146
                                                parseOtherSource(parser); 
147
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TILEMATRIXSET)) {
148
                                                WMTSTileMatrixSet mSet = (WMTSTileMatrixSet)content.createVersionObject("WMTSTileMatrixSet");
149
                                                mSet.setForceLongitudeFirstAxisOrder(forceLongitudeFirstAxisOrder);
150
                                                mSet.parse(parser, content.getTileMatrixSet()); 
151
                                        }                        
152
                                        break;
153
                                case KXmlParser.END_TAG:
154
                                        if (compareName(parser, CapabilitiesTags.WMTS_CONTENTS))
155
                                                end = true;
156
                                        break;
157
                                case KXmlParser.TEXT:                                        
158
                                break;
159
                         }
160
             if (!end)
161
                 currentTag = parser.next();
162
            }
163
    }
164
    
165
    private void parseOtherSource(KXmlParser parser) throws IOException, XmlPullParserException {
166
            parser.skipSubTree();
167
    }
168
    
169
    /**
170
     * Compares the next name in the selected parser with the string passed
171
     * by value.
172
     * @param parser
173
     * @param name
174
     * @return
175
     */
176
    private boolean compareName(KXmlParser parser, String name) {
177
            String s = parser.getName();
178
            if(s.compareTo(name) == 0 || s.compareTo(gmlTag + name) == 0)
179
                    return true;
180
            return false;
181
    }
182

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