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

History | View | Annotate | Download (4.57 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(nextText(parser));
58
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TITLE)) {
59
                                                setTitle(nextText(parser));
60
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_ABSTRACT)) {
61
                                                setAbstract(nextText(parser));
62
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_KEYWORDS)) {
63
                                                parser.skipSubTree();
64
                                                //setKeywords(nextText(parser));
65
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_SCALEDENOMINATOR)) {
66
                                                try {
67
                                                        setScaleDenominator(Double.parseDouble(nextText(parser)));
68
                                                } catch (NumberFormatException e) {
69
                                                }
70
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TOPLEFTCORNER)) {
71
                                                String v = nextText(parser);
72
                                                if(v != null) {
73
                                                        String[] list = CompatLocator.getStringUtils().split(v, " ");
74
                                                        if(list.length == 2) {
75
                                                                try {
76
                                                                        if(!forceLongitudeFirstAxisOrder) {
77
                                                                                getTopLeftCorner()[0] = Double.parseDouble(list[0]);
78
                                                                                getTopLeftCorner()[1] = Double.parseDouble(list[1]);
79
                                                                        } else {
80
                                                                                getTopLeftCorner()[1] = Double.parseDouble(list[0]);
81
                                                                                getTopLeftCorner()[0] = Double.parseDouble(list[1]);
82
                                                                        }
83
                                                                } catch (NumberFormatException e) {
84
                                                                }
85
                                                        }
86
                                                }
87
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TILEWIDTH)) {
88
                                                try {
89
                                                        setTileWidth(Integer.parseInt(nextText(parser)));
90
                                                } catch (NumberFormatException e) {
91
                                                }
92
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_TILEHEIGHT)) {
93
                                                try {
94
                                                        setTileHeight(Integer.parseInt(nextText(parser)));
95
                                                } catch (NumberFormatException e) {
96
                                                }
97
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_MATRIXWIDTH)) {
98
                                                try {
99
                                                        setMatrixWidth(Long.parseLong(nextText(parser)));
100
                                                } catch (NumberFormatException e) {
101
                                                }
102
                                        } else if (compareName(parser, CapabilitiesTags.WMTS_MATRIXHEIGHT)) {
103
                                                try {
104
                                                        setMatrixHeight(Long.parseLong(nextText(parser)));
105
                                                } catch (NumberFormatException e) {
106
                                                }
107
                                        }
108
                                        break;
109
                                case KXmlParser.END_TAG:
110
                                        if (compareName(parser, CapabilitiesTags.WMTS_TILEMATRIX))
111
                                                end = true;
112
                                        break;
113
                                case KXmlParser.TEXT:                                        
114
                                break;
115
                         }
116
             if (!end)
117
                 currentTag = parser.next();
118
            }
119
            tileMatrixList.add(this);
120
    }
121
        
122
    /**
123
     * Compares the next name in the selected parser with the string passed
124
     * by value.
125
     * @param parser
126
     * @param name
127
     * @return
128
     */
129
    public boolean compareName(KXmlParser parser, String name) {
130
            String s = parser.getName();
131
            if(s.compareTo(name) == 0 || s.compareTo(WMTSBaseStruct.gmlTag + name) == 0)
132
                    return true;
133
            return false;
134
    }
135
}