Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wmts / wmts_1_0_0 / struct / WMTSTileMatrix_1_0_0.java @ 34308

History | View | Annotate | Download (4.31 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
import java.util.ArrayList;
26

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

    
33
/**
34
 * Describes the attributes of a layer in a WMTS server using the protocol version 1.0.0
35
 *
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class WMTSTileMatrix_1_0_0 extends WMTSTileMatrix {
39
        
40
        /**
41
     * Parses the tile matrix
42
     * @param parser
43
     * @throws IOException
44
     * @throws XmlPullParserException
45
     */
46
        @SuppressWarnings("unchecked")
47
        public void parse(KXmlParser parser, ArrayList tileMatrixList) throws IOException, XmlPullParserException {
48
            int currentTag;
49
            boolean end = false;
50
            
51
            currentTag = parser.next();
52
            
53
            while (!end) {
54
                         switch(currentTag) {
55
                                case KXmlParser.START_TAG:
56
                                        if (compareName(parser, CapabilitiesTags.WMTS_IDENTIFIER)) {
57
                                                setIdentifier(parser.nextText());
58
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TITLE)) {
59
                                                setTitle(parser.nextText());
60
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_ABSTRACT)) {
61
                                                setAbstract(parser.nextText());
62
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_KEYWORDS)) {
63
                                                setKeywords(parser.nextText());
64
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_SCALEDENOMINATOR)) {
65
                                                try {
66
                                                        setScaleDenominator(Double.parseDouble(parser.nextText()));
67
                                                } catch (NumberFormatException e) {
68
                                                }
69
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TOPLEFTCORNER)) {
70
                                                String v = parser.nextText();
71
                                                if(v != null) {
72
                                                        String[] list = v.split(" ");
73
                                                        if(list.length == 2) {
74
                                                                try {
75
                                                                        getTopLeftCorner()[0] = Double.parseDouble(list[0]);
76
                                                                        getTopLeftCorner()[1] = Double.parseDouble(list[1]);
77
                                                                } catch (NumberFormatException e) {
78
                                                                }
79
                                                        }
80
                                                }
81
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TILEWIDTH)) {
82
                                                try {
83
                                                        setTileWidth(Integer.parseInt(parser.nextText()));
84
                                                } catch (NumberFormatException e) {
85
                                                }
86
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TILEHEIGHT)) {
87
                                                try {
88
                                                        setTileHeight(Integer.parseInt(parser.nextText()));
89
                                                } catch (NumberFormatException e) {
90
                                                }
91
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_MATRIXWIDTH)) {
92
                                                try {
93
                                                        setMatrixWidth(Long.parseLong(parser.nextText()));
94
                                                } catch (NumberFormatException e) {
95
                                                }
96
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_MATRIXHEIGHT)) {
97
                                                try {
98
                                                        setMatrixHeight(Long.parseLong(parser.nextText()));
99
                                                } catch (NumberFormatException e) {
100
                                                }
101
                                        }
102
                                        break;
103
                                case KXmlParser.END_TAG:
104
                                        if (compareName(parser, CapabilitiesTags.WMTS_TILEMATRIX))
105
                                                end = true;
106
                                        break;
107
                                case KXmlParser.TEXT:                                        
108
                                break;
109
                         }
110
             if (!end)
111
                 currentTag = parser.next();
112
            }
113
            tileMatrixList.add(this);
114
    }
115
        
116
    /**
117
     * Compares the next name in the selected parser with the string passed
118
     * by value.
119
     * @param parser
120
     * @param name
121
     * @return
122
     */
123
    public boolean compareName(KXmlParser parser, String name) {
124
            String s = parser.getName();
125
            if(s.compareTo(name) == 0 || s.compareTo(WMTSBaseStruct.gmlTag + name) == 0)
126
                    return true;
127
            return false;
128
    }
129
}