Statistics
| Revision:

svn-gvsig-desktop / tags / Root_v06 / libraries / libRemoteServices / src / org / gvsig / remoteClient / wms / WMSStyle.java @ 4811

History | View | Annotate | Download (5.16 KB)

1

    
2
package org.gvsig.remoteClient.wms;
3

    
4
import java.io.IOException;
5

    
6
import org.gvsig.remoteClient.utils.CapabilitiesTags;
7
import org.kxml2.io.KXmlParser;
8
import org.xmlpull.v1.XmlPullParserException;
9

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

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

    
23
    private org.gvsig.remoteClient.wms.WMSStyle.LegendURL legendURL;
24
    
25
/**
26
 * <p>Parses the STYLE tag in the WMS capabilities, filling the WMSStyle object
27
 * loading the data in memory to be easily accesed</p>
28
 * 
29
 */
30
    public abstract void parse(KXmlParser parser) throws IOException, XmlPullParserException;
31

    
32
    /**
33
     * Parses the legendURL tag.
34
     * @param parser
35
     * @throws IOException
36
     * @throws XmlPullParserException
37
     */
38
    protected void parseLegendURL(KXmlParser parser) throws IOException, XmlPullParserException
39
    {        
40
            int currentTag;
41
            boolean end = false;
42
            
43
            parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LEGENDURL);
44
            currentTag = parser.nextTag();
45
            
46
            String value = new String();
47
            LegendURL legend = 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
                legend.width = Integer.parseInt( value );
54
        }
55
        value = parser.getAttributeValue("", CapabilitiesTags.HEIGHT);
56
        if (value != null)
57
        {
58
                legend.height = Integer.parseInt( value );
59
        }
60
        
61
        while (!end) 
62
            {
63
                         switch(currentTag)
64
                         {
65
                                case KXmlParser.START_TAG:
66
                                        if (parser.getName().compareTo(CapabilitiesTags.FORMAT)==0)
67
                                        {                                                
68
                                                legend.format = parser.nextText();                                                
69
                                        }        
70
                                        else if (parser.getName().compareTo(CapabilitiesTags.ONLINERESOURCE)==0)
71
                                        {
72
                                                value = parser.getAttributeValue("", CapabilitiesTags.XLINK_TYPE);
73
                                                if (value != null)
74
                                                        legend.onlineResource_type = value;
75
                                                value = parser.getAttributeValue("", CapabilitiesTags.XLINK_HREF);
76
                                                if (value != null)
77
                                                        legend.onlineResource_href = value;
78
                                        }
79
                                        break;
80
                                case KXmlParser.END_TAG:
81
                                        if (parser.getName().compareTo(CapabilitiesTags.LEGENDURL) == 0)
82
                                                end = true;
83
                                        break;
84
                                case KXmlParser.TEXT:                                        
85
                                        break;
86
                         }
87
                         if (!end)
88
                         {
89
                                 currentTag = parser.next();
90
                         }
91
            }
92
            parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LEGENDURL);
93
    }     
94
    
95
    /**
96
     * gets the LegendURL OnlineResource type
97
     */
98
    public String getLegendURLOnlineResourceType()
99
    {
100
            if (legendURL != null)
101
            {
102
                    return legendURL.onlineResource_type;
103
            }
104
            else
105
            {
106
                    return null;
107
            }
108
    }
109

    
110
    /**
111
     * gets the LegendURL OnlineResource href
112
     */
113
    public String getLegendURLOnlineResourceHRef()
114
    {
115
            if (legendURL != null)
116
            {
117
                    return legendURL.onlineResource_href;
118
            }
119
            else
120
            {
121
                    return null;
122
            }
123
    }    
124
    public String getLegendURLFormat()
125
    {
126
            if (legendURL != null)
127
            {
128
                    return legendURL.format;
129
            }
130
            else
131
            {
132
                    return null;
133
            }
134
    }
135
    public int getLegendURLWidth()
136
    {
137
            if (legendURL != null)
138
            {
139
                    return legendURL.width;
140
            }
141
            return 0;
142
    }    
143
    public int getLegendURLHeight()
144
    {
145
            if (legendURL != null)
146
            {
147
                    return legendURL.height;
148
            }
149
            return 0;
150
    }    
151
    
152
    /**
153
     * sets LegendURL
154
     */
155
    protected void setLegendURL(LegendURL legendURL)
156
    {
157
            this.legendURL = legendURL;
158
    }
159
    
160
/**
161
 * <p>gets the style name</p>
162
 * 
163
 * @return style name
164
 */
165
    public String getName() {        
166
            return name;
167
    } 
168

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

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

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

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

    
208
/**
209
 * <p>sets style abstract</p>
210
 * 
211
 * 
212
 * @param _abstract, style abstract 
213
 */
214
    public void setAbstract(String _abstract) {        
215
        styleAbstract = _abstract;
216
    }
217
    
218
    /**
219
     * <p>Inner class describing the Legend URL defined for styles in the OGC specifications in WMS</p>
220
     * 
221
     */
222
    protected class LegendURL
223
    {            
224
            public LegendURL()
225
            {
226
                    width = 0;
227
                    height= 0;
228
                    format = new String();
229
                    onlineResource_type = new String();
230
                    onlineResource_href = new String();
231
            }
232

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