Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wms / WMSStyle.java @ 38579

History | View | Annotate | Download (5.14 KB)

1

    
2
package org.gvsig.remoteclient.wms;
3

    
4
import java.io.IOException;
5

    
6
import org.kxml2.io.KXmlParser;
7
import org.xmlpull.v1.XmlPullParserException;
8

    
9
import org.gvsig.remoteclient.utils.CapabilitiesTags;
10

    
11
/**
12
 * <p>Defines a OGC style. Theme that describes the appeareance of certain layer.</p>
13
 *
14
 */
15
public abstract class WMSStyle {
16

    
17
        //style name, defined in the WMS capabilities
18
        private String name;
19
        //style title, defined in the WMS capabilities
20
        private String title;
21
        // style abstract, defined in the WMS capabilities
22
    private String styleAbstract;
23

    
24
    private org.gvsig.remoteclient.wms.WMSStyle.LegendURL legendURL;
25

    
26
    /**
27
     * <p>Parses the STYLE tag in the WMS capabilities, filling the WMSStyle object
28
     * loading the data in memory to be easily accesed</p>
29
     *
30
     */
31
    public abstract void parse(KXmlParser parser) throws IOException, XmlPullParserException;
32

    
33
    /**
34
     * Parses the legendURL tag.
35
     * @param parser
36
     * @throws IOException
37
     * @throws XmlPullParserException
38
     */
39
    protected void parseLegendURL(KXmlParser parser) throws IOException, XmlPullParserException
40
    {
41
            int currentTag;
42
            boolean end = false;
43

    
44
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LEGENDURL);
45

    
46
            String value = new String();
47
            legendURL = new LegendURL();
48

    
49
            //First of all set whether the layer is Queryable reading the attribute.
50
            value = parser.getAttributeValue("", CapabilitiesTags.WIDTH);
51
            if (value != null)
52
            {
53
                    legendURL.width = Integer.parseInt( value );
54
            }
55
            value = parser.getAttributeValue("", CapabilitiesTags.HEIGHT);
56
            if (value != null)
57
            {
58
                    legendURL.height = Integer.parseInt( value );
59
            }
60
            currentTag = parser.nextTag();
61

    
62
            while (!end)
63
            {
64
                    switch(currentTag)
65
                    {
66
                    case KXmlParser.START_TAG:
67
                            if (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0)
68
                            {
69
                                    legendURL.format = parser.nextText();
70
                            }
71
                            else if (parser.getName().compareTo(CapabilitiesTags.ONLINERESOURCE)==0)
72
                            {
73
                                    value = parser.getAttributeValue("", CapabilitiesTags.XLINK_TYPE);
74
                                    if (value != null)
75
                                            legendURL.onlineResource_type = value;
76
                                    value = parser.getAttributeValue("", CapabilitiesTags.XLINK_HREF);
77
                                    if (value != null)
78
                                            legendURL.onlineResource_href = value;
79
                            }
80
                            break;
81
                    case KXmlParser.END_TAG:
82
                            if (parser.getName().compareTo(CapabilitiesTags.LEGENDURL) == 0)
83
                                    end = true;
84
                            break;
85
                    case KXmlParser.TEXT:
86
                            break;
87
                    }
88
                    if (!end)
89
                    {
90
                            currentTag = parser.next();
91
                    }
92
            }
93
            parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LEGENDURL);
94
    }
95

    
96
    /**
97
     * gets the LegendURL OnlineResource type
98
     */
99
    public String getLegendURLOnlineResourceType()
100
    {
101
            if (legendURL != null)
102
            {
103
                    return legendURL.onlineResource_type;
104
            }
105
            else
106
            {
107
                    return null;
108
            }
109
    }
110

    
111
    /**
112
     * gets the LegendURL OnlineResource href
113
     */
114
    public String getLegendURLOnlineResourceHRef()
115
    {
116
            if (legendURL != null)
117
            {
118
                    return legendURL.onlineResource_href;
119
            }
120
            else
121
            {
122
                    return null;
123
            }
124
    }
125
    public String getLegendURLFormat()
126
    {
127
            if (legendURL != null)
128
            {
129
                    return legendURL.format;
130
            }
131
            else
132
            {
133
                    return null;
134
            }
135
    }
136
    public int getLegendURLWidth()
137
    {
138
            if (legendURL != null)
139
            {
140
                    return legendURL.width;
141
            }
142
            return 0;
143
    }
144
    public int getLegendURLHeight()
145
    {
146
            if (legendURL != null)
147
            {
148
                    return legendURL.height;
149
            }
150
            return 0;
151
    }
152

    
153
    /**
154
     * sets LegendURL
155
     */
156
    protected void setLegendURL(LegendURL legendURL)
157
    {
158
            this.legendURL = legendURL;
159
    }
160

    
161
    /**
162
     * <p>gets the style name</p>
163
     *
164
     * @return style name
165
     */
166
    public String getName() {
167
            return name;
168
    }
169

    
170
    /**
171
     * <p>sets the style name.</p>
172
     *
173
     * @param _name
174
     */
175
    public void setName(String _name) {
176
            name = _name;
177
    }
178

    
179
    /**
180
     * <p>gets the style title</p>
181
     *
182
     *
183
     * @return style title
184
     */
185
    public String getTitle() {
186
            return title;
187
    }
188

    
189
    /**
190
     * <p>Sets style title</p>
191
     *
192
     *
193
     * @param _title
194
     */
195
    public void setTitle(String _title) {
196
            title = _title.trim();
197
    }
198

    
199
    /**
200
     * <p>gets style abstract</p>
201
     *
202
     *
203
     * @return style abstract
204
     */
205
    public String getAbstract() {
206
            return styleAbstract;
207
    }
208

    
209
    /**
210
     * <p>sets style abstract</p>
211
     *
212
     *
213
     * @param _abstract, style abstract
214
     */
215
    public void setAbstract(String _abstract) {
216
            styleAbstract = _abstract;
217
    }
218

    
219
    /**
220
     * <p>Inner class describing the Legend URL defined for styles in the OGC specifications in WMS</p>
221
     *
222
     */
223
    protected class LegendURL
224
    {
225
            public LegendURL()
226
            {
227
                    width = 0;
228
                    height= 0;
229
                    format = new String();
230
                    onlineResource_type = new String();
231
                    onlineResource_href = new String();
232
            }
233

    
234
            public int width;
235
            public int height;
236
            public String format;
237
            public String onlineResource_type;
238
            public String onlineResource_href;
239
    }
240
}