Statistics
| Revision:

svn-gvsig-desktop / branches / v02_desarrollo / libraries / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.api / src / main / java / org / gvsig / sldsupport / version / sld1_0_0 / symbolizers / SLDPolygonSymbolizer1_0_0.java @ 40749

History | View | Annotate | Download (5.57 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.sldsupport.version.sld1_0_0.symbolizers;
42

    
43
import java.io.IOException;
44

    
45
import org.gvsig.sldsupport.exception.SLDReadException;
46
import org.gvsig.sldsupport.symbolizer.SLDPolygonSymbolizer;
47
import org.gvsig.sldsupport.util.SLDTags;
48
import org.gvsig.sldsupport.util.XmlBuilder;
49
import org.gvsig.sldsupport.version.sld1_0_0.SLDFill1_0_0;
50
import org.gvsig.sldsupport.version.sld1_0_0.SLDStroke1_0_0;
51
import org.xmlpull.v1.XmlPullParser;
52
import org.xmlpull.v1.XmlPullParserException;
53

    
54
/**
55
 * Implements the PolygonSymbolizer element of an SLD implementation specification 
56
 * (version 1.0.0).<p>
57
 * 
58
 * PolygonSymbolizer is used draw a polygon (or other area-type geometries),
59
 * including filling its interior and stroking its border (outline).<p>
60
 * 
61
 * @see SLDStroke1_0_0
62
 * @see SLDFill1_0_0
63
 * @see http://portal.opengeospatial.org/files/?artifact_id=1188
64
 * 
65
 * 
66
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
67
 */
68
public class SLDPolygonSymbolizer1_0_0 extends SLDPolygonSymbolizer {
69

    
70
        
71
        /**
72
         * Parses the xml data retrieved from the SLD, it will parse the PolygonSymbolizer
73
         *  element</p>
74
         * @throws SLDReadException 
75
         */
76
        public void parse(XmlPullParser parser)throws IOException, XmlPullParserException, SLDReadException  {
77
                int currentTag;
78
                boolean end = false;
79

    
80
                parser.require(XmlPullParser.START_TAG, null, SLDTags.POLYGONSYMBOLIZER);
81
                currentTag = parser.next();
82

    
83
                while (!end)
84
                {
85
                        switch(currentTag)
86
                        {
87
                        case XmlPullParser.START_TAG:
88
                                if (parser.getName().compareTo(SLDTags.GEOMETRY)==0) {
89
                                        parseGeometry(parser);
90
                                }
91
                                else if (parser.getName().compareTo(SLDTags.FILL)==0) {
92
                                        SLDFill1_0_0 fill = new SLDFill1_0_0();
93
                                        fill.parse(parser,currentTag,null);
94
                                        setFill(fill);
95
                                }
96
                                else if (parser.getName().compareTo(SLDTags.STROKE)==0) {
97
                                        SLDStroke1_0_0 stroke = new SLDStroke1_0_0();
98
                                        stroke.parse(parser,currentTag,null);
99
                                        setStroke(stroke);
100
                                }
101
                                break;
102
                        case XmlPullParser.END_TAG:
103
                                if (parser.getName().compareTo(SLDTags.POLYGONSYMBOLIZER) == 0)
104
                                        end = true;
105
                                break;
106
                        case XmlPullParser.TEXT:
107
                                break;
108
                        }
109
                        if (!end)
110
                                currentTag = parser.next();
111
                }
112

    
113
                parser.require(XmlPullParser.END_TAG, null, SLDTags.POLYGONSYMBOLIZER);
114

    
115
        }
116

    
117
        /**
118
         * Parses the xml data retrieved from the SLD, it will parse the Geometry element</p>
119
         * The Geometry element of a Symbolizer defines the geometry to be used
120
         * for styling. The Geometry element is optional and if it is absent then the
121
         * ?default? geometry property of the feature type that is used in the containing 
122
         * FeatureStyleType is used. The precise meaning of ?default? geometry property is
123
         * system-dependent. Most frequently, feature types will have only a single geometry
124
         * property.<p>
125
         * The only method available for defining a geometry is to reference a geometry 
126
         * property using the ogc:PropertyName element (defined in the WFS Specification). 
127
         * The content of the element gives the property name in XPath syntax. In principle, 
128
         * a fixed geometry could be defined using GML or operators could be defined for 
129
         * computing the geometry from references or literals. However, using a feature 
130
         * property directly is by far the most commonly useful method.
131
         *
132
         */
133
        private void parseGeometry(XmlPullParser parser) throws IOException, XmlPullParserException{
134
                int currentTag;
135
                boolean end = false;
136

    
137
                parser.require(XmlPullParser.START_TAG, null, SLDTags.GEOMETRY);
138
                currentTag = parser.next();
139

    
140
                while (!end)
141
                {
142
                        switch(currentTag)
143
                        {
144
                        case XmlPullParser.START_TAG:
145
                                if (parser.getName().compareTo(SLDTags.PROPERTY_NAME)==0) {
146
                                        setGeometry(parser.nextText());
147
                                }
148

    
149
                                break;
150
                        case XmlPullParser.END_TAG:
151
                                if (parser.getName().compareTo(SLDTags.GEOMETRY) == 0)
152
                                        end = true;
153
                                break;
154
                        case XmlPullParser.TEXT:
155
                                break;
156
                        }
157
                        if (!end)
158
                                currentTag = parser.next();
159
                }
160

    
161
                parser.require(XmlPullParser.END_TAG, null, SLDTags.GEOMETRY);
162

    
163
        }
164

    
165
        
166
        
167

    
168
        public String toXML() {
169
                XmlBuilder xmlBuilder = new XmlBuilder();
170

    
171
                xmlBuilder.openTag(SLDTags.POLYGONSYMBOLIZER);
172
                if(fill != null) {
173
                        xmlBuilder.writeRaw(getFill().toXML());
174
                }
175
                if(stroke != null) {
176
                        xmlBuilder.writeRaw(getStroke().toXML());
177
                }
178
                xmlBuilder.closeTag();
179

    
180
                return xmlBuilder.getXML();
181
        }
182

    
183

    
184
}