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 / struct / WMTSTileMatrix_1_0_0.java @ 1806

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

    
24
import java.io.IOException;
25
import java.util.List;
26

    
27
import org.gvsig.compat.CompatLocator;
28
import org.gvsig.raster.wmts.ogc.WMTSTileMatrix;
29
import org.gvsig.raster.wmts.ogc.impl.Tags;
30
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSBaseStruct;
31
import org.gvsig.raster.wmts.ogc.impl.struct.WMTSTileMatrixImpl;
32
import org.kxml2.io.KXmlParser;
33
import org.xmlpull.v1.XmlPullParserException;
34

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