Statistics
| Revision:

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 @ 2613

History | View | Annotate | Download (6.81 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.WMTSStatusImpl;
32
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetCapabilitiesRequest;
33
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetFeatureInfoRequest;
34
import org.gvsig.raster.wmts.ogc.impl.request.WMTSGetTileRequest;
35
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSLayerImpl;
36
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSTileMatrixSetImpl;
37
import org.gvsig.raster.wmts.ogc.impl.wmts_1_0_0.request.WMTSGetCapabilitiesRequest1_0_0;
38
import org.gvsig.raster.wmts.ogc.impl.wmts_1_0_0.request.WMTSGetFeatureInfoRequest1_0_0;
39
import org.gvsig.raster.wmts.ogc.impl.wmts_1_0_0.request.WMTSGetTileRequest1_0_0;
40
import org.kxml2.io.KXmlParser;
41
import org.xmlpull.v1.XmlPullParserException;
42

    
43
/**
44
 * Describes the handler to comunicate to a WMTS 1.0.0
45
 *
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class WMTSProtocolHandler1_0_0 extends WMTSProtocolHandler {
49
        private String                    gmlTag             = Tags.WMTS_GMLTAG;
50
    
51
        public WMTSProtocolHandler1_0_0() {
52
                this.version = "1.0.0";
53
                this.name = "WMS1.0.0";
54
                //this.serviceInfo = new WMTSServiceInformation(); 
55
        }
56
        
57
        public boolean parseCapabilities(File f) {       
58
            int tag;
59
            EncodingXMLParser parser = null;
60
            parser = new EncodingXMLParser();
61
            if(getServerDescription() != null)
62
                    getServerDescription().clear();
63
            try {
64
                    parser.setInput(f);
65
                    parser.nextTag();
66
                    if ( parser.getEventType() != KXmlParser.END_DOCUMENT ) {                    
67
                            parser.require(KXmlParser.START_TAG, null, Tags.WMTS_CAPABILITIES);                            
68
                            tag = parser.nextTag();
69
                                 while(tag != KXmlParser.END_DOCUMENT) {
70
                     switch(tag) {
71
                         
72
                                                case KXmlParser.START_TAG:
73
                                                        if (compareName(parser, Tags.WMTS_SERVICEID)) {
74
                                                                getServerDescription().getServiceIdentification().parse(parser);
75
                                                        } else if (compareName(parser, Tags.WMTS_SERVICEPROV )) {
76
                                                                getServerDescription().getServiceProvider().parse(parser);
77
                                                        } else if (compareName(parser, Tags.WMTS_OPMETADATA)) {
78
                                                                getServerDescription().getOperationsMetadata().parse(parser);
79
                                                        } else if (compareName(parser, Tags.WMTS_CONTENTS )) {
80
                                                                parseServiceContent(parser, getServerDescription());
81
                                                        } else if (compareName(parser, Tags.WMTS_THEMES )) {
82
                                                                getServerDescription().getThemes().parse(parser);
83
                                                        }
84
                                                        break;
85
                                                case KXmlParser.END_TAG:                                                        
86
                                                        break;
87
                                                case KXmlParser.TEXT:
88
                                                                                                
89
                                                break;
90
                                         }
91
                                     tag = parser.next();
92
                             }
93

    
94
                            parser.require(KXmlParser.END_DOCUMENT, null, null);
95
                    }
96
            } catch(XmlPullParserException parser_ex) {
97
                    parser_ex.printStackTrace();
98
                    return false;
99
            } catch (IOException ioe) {                        
100
                           ioe.printStackTrace();
101
                           return false;
102
                } 
103
            
104
            //Calcula las referencias a las capas dentro de los temas
105
            getServerDescription().getThemes().calculateLayers(getServerDescription().getLayerList());
106
            //Se calculan los temas como lista de capas
107
            getServerDescription().getLayerListAsThemes().loadThemesWithLayerInfo(getServerDescription().getLayerList(), getServerDescription());
108
            
109
            //Asocia los TileMatrixSet a los TileMatrixLimits
110
            for (int i = 0; i < getServerDescription().getLayerList().size(); i++) {
111
                        WMTSLayerImpl layer = (WMTSLayerImpl)getServerDescription().getLayerList().get(i);
112
                        layer.linkTileMatrixSets(getServerDescription().getTileMatrixSet());
113
                }
114
        return true;
115
    } 
116
    
117
    /**
118
     * Parses the Content section    
119
     * @param parser
120
     * @throws IOException
121
     * @throws XmlPullParserException
122
     */
123
    private void parseServiceContent(KXmlParser parser, WMTSServerDescription content) throws IOException, XmlPullParserException {
124
            int currentTag;
125
            boolean end = false;
126
            
127
            currentTag = parser.next();
128
            
129
            while (!end) {
130
                         switch(currentTag) {
131
                                case KXmlParser.START_TAG:
132
                                        if (compareName(parser, Tags.WMTS_LAYER)) {
133
                                                WMTSLayerImpl layer = content.buildNewLayer();
134
                                                layer.setForceChangeAxisOrder(forceChangeAxisOrder);
135
                                                layer.parse(parser);
136
                                        } else if (compareName(parser, Tags.WMTS_OTHERSRC)) {
137
                                                parseOtherSource(parser); 
138
                                        } else if (compareName(parser, Tags.WMTS_TILEMATRIXSET)) {
139
                                                WMTSTileMatrixSetImpl mSet = (WMTSTileMatrixSetImpl)content.createVersionObject("WMTSTileMatrixSet");
140
                                                mSet.setForceChangeAxisOrder(forceChangeAxisOrder);
141
                                                mSet.parse(parser, content.getTileMatrixSet()); 
142
                                        }                        
143
                                        break;
144
                                case KXmlParser.END_TAG:
145
                                        if (compareName(parser, Tags.WMTS_CONTENTS))
146
                                                end = true;
147
                                        break;
148
                                case KXmlParser.TEXT:                                        
149
                                break;
150
                         }
151
             if (!end)
152
                 currentTag = parser.next();
153
            }
154
    }
155
    
156
    private void parseOtherSource(KXmlParser parser) throws IOException, XmlPullParserException {
157
            parser.skipSubTree();
158
    }
159
    
160
    /**
161
     * Compares the next name in the selected parser with the string passed
162
     * by value.
163
     * @param parser
164
     * @param name
165
     * @return
166
     */
167
    private boolean compareName(KXmlParser parser, String name) {
168
            String s = parser.getName();
169
            if(s.compareTo(name) == 0 || s.compareTo(gmlTag + name) == 0)
170
                    return true;
171
            return false;
172
    }
173

    
174
    public WMTSGetCapabilitiesRequest createGetCapabilitiesRequest() {
175
                return new WMTSGetCapabilitiesRequest1_0_0(getServerDescription(), this);
176
        }
177
        
178
        public WMTSGetTileRequest createGetTileRequest(WMTSStatusImpl status) {
179
                return new WMTSGetTileRequest1_0_0(status, this);
180
        }
181
        
182
        public WMTSGetFeatureInfoRequest createGetFeatureInfoRequest(WMTSStatusImpl status, int x, int y) {
183
                return new WMTSGetFeatureInfoRequest1_0_0(status, this, x, y);
184
        }
185
}