Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wmts / wmts_1_0_0 / struct / WMTSBoundingBox_1_0_0.java @ 38525

History | View | Annotate | Download (3.88 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.struct;
23

    
24
import java.io.IOException;
25

    
26
import org.gvsig.compat.CompatLocator;
27
import org.gvsig.remoteclient.utils.CapabilitiesTags;
28
import org.gvsig.remoteclient.wmts.struct.WMTSBaseStruct;
29
import org.gvsig.remoteclient.wmts.struct.WMTSBoundingBox;
30
import org.kxml2.io.KXmlParser;
31
import org.xmlpull.v1.XmlPullParserException;
32

    
33
/**
34
 * Describes the bounding box of a layer in a WMTS server
35
 *
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class WMTSBoundingBox_1_0_0 extends WMTSBoundingBox {
39
        
40
        /**
41
         * Parses a WGS84BoundingBox object
42
         * @param parser
43
         * @throws IOException
44
         * @throws XmlPullParserException
45
         */
46
        public void parse(KXmlParser parser) throws IOException, XmlPullParserException {
47
                int currentTag;
48
                boolean end = false;
49

    
50
                currentTag = parser.next();
51

    
52
                while (!end) {
53
                        switch(currentTag) {
54
                        case KXmlParser.START_TAG:
55
                                if (compareName(parser, CapabilitiesTags.WMTS_LOWERCORNER)) {
56
                                        String v = parser.nextText();
57
                                        if(v != null) {
58
                                                String[] list = CompatLocator.getStringUtils().split(v, " ");
59
                                                if(list.length == 2) {
60
                                                        try {
61
                                                                //if(!forceLongitudeFirstAxisOrder) {
62
                                                                        getLowerCorner()[0] = Double.parseDouble(list[0]);
63
                                                                        getLowerCorner()[1] = Double.parseDouble(list[1]);
64
                                                                /*} else {
65
                                                                        getLowerCorner()[1] = Double.parseDouble(list[0]);
66
                                                                        getLowerCorner()[0] = Double.parseDouble(list[1]);
67
                                                                }*/
68
                                                        } catch (NumberFormatException e) {
69
                                                        }
70
                                                }
71
                                        }
72
                                } else if (compareName(parser, CapabilitiesTags.WMTS_UPPERCORNER)) {
73
                                        String v = parser.nextText();
74
                                        if(v != null) {
75
                                                String[] list = CompatLocator.getStringUtils().split(v, " ");
76
                                                if(list.length == 2) {
77
                                                        try {
78
                                                                //if(!forceLongitudeFirstAxisOrder) {
79
                                                                        getUpperCorner()[0] = Double.parseDouble(list[0]);
80
                                                                        getUpperCorner()[1] = Double.parseDouble(list[1]);
81
                                                                /*} else {
82
                                                                        getUpperCorner()[1] = Double.parseDouble(list[0]);
83
                                                                        getUpperCorner()[0] = Double.parseDouble(list[1]);
84
                                                                }*/
85
                                                        } catch (NumberFormatException e) {
86
                                                        }
87
                                                }
88
                                        }
89
                                } else if (compareName(parser, CapabilitiesTags.WMTS_CRS)) {
90
                                        setCrs(parser.nextText()); 
91
                                } else if (compareName(parser, CapabilitiesTags.WMTS_DIMENSIONS)) {
92
                                        try {
93
                                                setDimensions(Integer.parseInt(parser.nextText()));
94
                                        } catch (NumberFormatException e) {
95
                                        }
96
                                }                        
97
                                break;
98
                        case KXmlParser.END_TAG:
99
                                if (compareName(parser, CapabilitiesTags.WMTS_WGS84BOUNDINGBOX) || compareName(parser, CapabilitiesTags.WMTS_BOUNDINGBOX))
100
                                        end = true;
101
                                break;
102
                        case KXmlParser.TEXT:                                        
103
                                break;
104
                        }
105
                        if (!end)
106
                                currentTag = parser.next();
107
                }
108
        }
109

    
110
        /**
111
         * Compares the next name in the selected parser with the string passed
112
         * by value.
113
         * @param parser
114
         * @param name
115
         * @return
116
         */
117
        public boolean compareName(KXmlParser parser, String name) {
118
                String s = parser.getName();
119
                if(s.compareTo(name) == 0 || s.compareTo(WMTSBaseStruct.gmlTag + name) == 0)
120
                        return true;
121
                return false;
122
        }
123
}