Statistics
| Revision:

root / trunk / extensions / extSymbology / src / org / gvsig / remoteClient / sld / sld1_0_0 / symbolizers / SLDPolygonSymbolizer1_0_0.java @ 20768

History | View | Annotate | Download (5.65 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.remoteClient.sld.sld1_0_0.symbolizers;
42

    
43
import java.io.IOException;
44

    
45
import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser;
46
import org.gvsig.remoteClient.sld.SLDTags;
47
import org.gvsig.remoteClient.sld.sld1_0_0.SLDFill1_0_0;
48
import org.gvsig.remoteClient.sld.sld1_0_0.SLDStroke1_0_0;
49
import org.gvsig.remoteClient.sld.symbolizers.SLDPolygonSymbolizer;
50
import org.xmlpull.v1.XmlPullParserException;
51

    
52
import com.iver.cit.gvsig.fmap.drivers.legend.LegendDriverException;
53
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
54

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

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

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

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

    
114
                parser.require(XMLSchemaParser.END_TAG, null, SLDTags.POLYGONSYMBOLIZER);
115

    
116
        }
117

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

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

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

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

    
162
                parser.require(XMLSchemaParser.END_TAG, null, SLDTags.GEOMETRY);
163

    
164
        }
165

    
166
        
167
        
168

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

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

    
181
                return xmlBuilder.getXML();
182
        }
183

    
184

    
185
}