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 / struct / WMTSThemesImpl.java @ 22715

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

    
24
import java.io.IOException;
25
import java.util.ArrayList;
26
import java.util.Collections;
27
import java.util.Comparator;
28
import java.util.List;
29
import org.apache.commons.lang3.StringUtils;
30

    
31
import org.gvsig.raster.wmts.ogc.impl.base.WMTSServerDescription;
32
import org.gvsig.raster.wmts.ogc.struct.WMTSLayer;
33
import org.gvsig.raster.wmts.ogc.struct.WMTSTheme;
34
import org.gvsig.raster.wmts.ogc.struct.WMTSThemes;
35
import org.kxml2.io.KXmlParser;
36
import org.xmlpull.v1.XmlPullParserException;
37

    
38
/**
39
 * Layer hierarchy
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public abstract class WMTSThemesImpl extends ArrayList<WMTSThemeImpl> implements WMTSThemes {
43
        private static final long serialVersionUID = 1L;
44
        
45
    /**
46
     * Parses this service ID
47
     * @param parser
48
     * @param content
49
     * @throws IOException
50
     * @throws XmlPullParserException
51
     */
52
    public abstract void parse(KXmlParser parser) throws IOException, XmlPullParserException; 
53
    
54
    public boolean hasThemes() {
55
            return size() > 0;
56
    }
57
    
58
        /**
59
         * Assign the layer associated
60
         * @param layers
61
         */
62
        public void calculateLayers(List<WMTSLayer> layers) {
63
                for (int i = 0; i < size(); i++) {
64
                        ((WMTSThemeImpl)get(i)).calculateLayers(layers);
65
                }
66
        }
67
        
68
        /**
69
         * Loads this list of themes with the layer information
70
         * @param layers
71
         */
72
        public void loadThemesWithLayerInfo(List<WMTSLayer> layers, WMTSServerDescription status) {
73
                if(size() == 0) {
74
                        for (int i = 0; i < layers.size(); i++) {
75
                                WMTSThemeImpl theme = (WMTSThemeImpl)status.createVersionObject("WMTSTheme");
76
                                WMTSLayerImpl layer = (WMTSLayerImpl)layers.get(i);
77
                                theme.setTitle(layer.getTitle());
78
                                theme.setLayer(layer);
79
                                theme.setAbstract(layer.getAbstract());
80
                                add(theme);
81
                        }
82
                }
83
        }
84
        
85
        /**
86
         * Gets a node by its name
87
         * @param name
88
         * @return
89
         */
90
        public WMTSTheme getNodeByName(String name) {
91
                WMTSTheme result = null;
92
                
93
                for (int i = 0; i < size(); i++) {
94
                        WMTSThemeImpl theme = ((WMTSThemeImpl)get(i));
95
                        String title = theme.getTitle();
96
                        if(title.compareTo(name) == 0)
97
                                result = ((WMTSThemeImpl)get(i));
98
                        else 
99
                                result = theme.getNodeByName(name);
100
                        if(result != null)
101
                                return result;
102
                }
103
                return null;
104
        }
105
        
106
        /**
107
         * Gets the number of nodes
108
         * @param parent
109
         * @return
110
         */
111
        public int getChildCount() {
112
                /*int acum = 0;
113
                for (int i = 0; i < size(); i++) {
114
                        acum += 1 + ((WMTSTheme)get(i)).getChildCount();
115
                }
116
                return acum;
117
                */
118
                return size();
119
        }
120
        
121
        /**
122
         * Gets the children of the index position
123
         * @param index
124
         * @return
125
         */
126
        public WMTSThemeImpl getChildren(int index) {
127
                return (WMTSThemeImpl)get(index);        
128
        }
129
        
130
        /**
131
         * Gets the index of a children
132
         * @param parent
133
         * @param child
134
         * @return
135
         */
136
        public int getIndexOfChild(WMTSTheme child) {
137
                for (int i = 0; i < size(); i++)
138
                        if (child == getChildren(i)) 
139
                                return i;
140
                return -1;
141
        }
142
        
143
        public String toString() {
144
                return "Base";
145
        }
146
    
147
    public void sort() {
148
        Collections.sort(this, new  Comparator<WMTSTheme>() {
149
            @Override
150
            public int compare(WMTSTheme o1, WMTSTheme o2) {
151
                return StringUtils.compare(o1.getTitle(), o2.getTitle(), true);
152
            }
153
        });
154
        for (WMTSThemeImpl theTheme : this) {
155
            theTheme.sort();
156
        }
157
    }
158
}