Statistics
| Revision:

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

History | View | Annotate | Download (4.38 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.compat.CompatLocator;
28
import org.gvsig.remoteclient.utils.CapabilitiesTags;
29
import org.gvsig.remoteclient.wmts.struct.WMTSBaseStruct;
30
import org.gvsig.remoteclient.wmts.struct.WMTSTileMatrix;
31
import org.kxml2.io.KXmlParser;
32
import org.xmlpull.v1.XmlPullParserException;
33

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