Statistics
| Revision:

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

History | View | Annotate | Download (11.3 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;
42

    
43
import java.io.IOException;
44

    
45
import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser;
46
import org.gvsig.remoteClient.sld.SLDStroke;
47
import org.gvsig.remoteClient.sld.SLDTags;
48
import org.gvsig.remoteClient.sld.SLDUtils;
49
import org.gvsig.remoteClient.sld.filterEncoding.FExpression;
50
import org.gvsig.remoteClient.sld.filterEncoding.FilterTags;
51
import org.gvsig.remoteClient.sld.filterEncoding.FilterUtils;
52
import org.xmlpull.v1.XmlPullParserException;
53

    
54
import com.iver.cit.gvsig.fmap.drivers.legend.LegendDriverException;
55
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder;
56

    
57
/**
58
 * Implements the Stroke element of an SLD specification which
59
 * encapsulates the graphical-symbolization parameters for linear
60
 * geometries
61
 * 
62
 * @see http://portal.opengeospatial.org/files/?artifact_id=1188
63
 * 
64
 * @author pepe vidal salvador - jose.vidal.salvador@iver.es
65
 */
66
public class SLDStroke1_0_0 extends SLDStroke {
67

    
68
        String cad;
69

    
70
        public void parse(XMLSchemaParser parser, int cuTag, String expressionType) throws XmlPullParserException, IOException, LegendDriverException {
71

    
72
                int currentTag;
73
                boolean end = false;
74
                parser.require(XMLSchemaParser.START_TAG, null, SLDTags.STROKE);
75
                currentTag = parser.next();
76

    
77
                while (!end)
78
                {
79
                        switch(currentTag)
80
                        {
81
                        case XMLSchemaParser.START_TAG:
82
                                if (parser.getName().compareTo(SLDTags.GRAPHICFILL)==0 ||
83
                                                parser.getName().compareTo(SLDTags.GRAPHICSTROKE)==0)  {
84
                                        String name = parser.getName();
85
                                        SLDGraphic1_0_0 graphic = new SLDGraphic1_0_0();
86
                                        graphic.parse(parser,currentTag,parser.getName());
87
                                        setGraphic(graphic);
88

    
89
                                        if (name.compareTo(SLDTags.GRAPHICFILL)== 0)
90
                                                setHasGraphicFill(true);
91
                                        if (name.compareTo(SLDTags.GRAPHICSTROKE)== 0)
92
                                                setHasGraphicStroke(true);
93
                                }
94
                                else if (parser.getName().compareTo(SLDTags.CSSPARAMETER)==0) {
95
                                        if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.STROKE_WIDTH_ATTR)==0) {
96
                                                FExpression expressionWidth = new FExpression();
97

    
98
                                                try {
99
                                                        expressionWidth.parse(parser,parser.nextTag(), parser.getName());
100
                                                }
101
                                                catch(XmlPullParserException e) {
102
                                                        String s = parser.getText().trim();
103
                                                        expressionWidth.setLiteral(s);
104
                                                }
105

    
106
                                                if (!SLDUtils.isANumber(expressionWidth.getLiteral()))
107
                                                        throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
108

    
109
                                                setExpressionWidth(expressionWidth);
110
                                        }
111
                                        else if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.STROKE_ATTR)==0) {
112
                                                FExpression expressionColor = new FExpression();
113

    
114

    
115
                                                try {
116
                                                        expressionColor.parse(parser, parser.nextTag(),parser.getName());
117
                                                }
118
                                                catch(XmlPullParserException e) {
119
                                                        String s = parser.getText().trim();
120
                                                        expressionColor.setLiteral(s);
121
                                                }
122

    
123
                                                if (!SLDUtils.isColor(expressionColor.getLiteral()))
124
                                                        throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
125

    
126
                                                setExpressionColor(expressionColor);
127
                                        }
128
                                        else if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.STROKE_OPACITY_ATTR)==0) {
129
                                                FExpression expressionOpacity = new FExpression();
130

    
131

    
132

    
133
                                                try {
134
                                                        expressionOpacity.parse(parser,parser.nextTag(), parser.getName());
135
                                                }
136
                                                catch(XmlPullParserException e) {
137
                                                        String s = parser.getText().trim();
138
                                                        expressionOpacity.setLiteral(s);
139
                                                }
140

    
141
                                                if (!SLDUtils.isANumber(expressionOpacity.getLiteral()))
142
                                                        throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
143

    
144
                                                setExpressionOpacity(expressionOpacity);
145
                                        }
146
                                        else if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.STROKE_LINEJOIN_ATTR)==0) {
147

    
148
                                                FExpression expressionLineJoin = new FExpression();
149

    
150
                                                try {
151
                                                        expressionLineJoin.parse(parser,parser.nextTag(), parser.getName());
152
                                                }
153
                                                catch(XmlPullParserException e) {
154
                                                        String s = parser.getText().trim();
155
                                                        expressionLineJoin.setLiteral(s);
156
                                                }
157

    
158
                                                if (!SLDUtils.isLineJoin(expressionLineJoin.getLiteral()))
159
                                                        throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
160

    
161
                                                setExpressionLineJoin(expressionLineJoin);
162
                                        }
163
                                        else if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.STROKE_LINECAP_ATTR)==0) {
164

    
165
                                                FExpression expressionLineCap = new FExpression();
166

    
167
                                                try {
168
                                                        expressionLineCap.parse(parser,parser.nextTag(), parser.getName());
169
                                                }
170
                                                catch(XmlPullParserException e) {
171
                                                        String s = parser.getText().trim();
172
                                                        expressionLineCap.setLiteral(s);
173
                                                }
174

    
175
                                                if (!SLDUtils.isLineCap(expressionLineCap.getLiteral()))
176
                                                        throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
177

    
178
                                                setExpressionLineCap(expressionLineCap);
179
                                        }
180
                                        else if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.STROKE_DASHARRAY_ATTR)==0) {
181
                                                
182
                                                
183
                                                FExpression expressionDashArray =  new FExpression();
184
                                                try {
185
                                                        expressionDashArray.parse(parser,parser.nextTag(), parser.getName());
186
                                                        cad = expressionDashArray.getLiteral();
187
                                                        if (cad == null)
188
                                                                cad = parser.getText().trim();
189
                                                }
190
                                                catch(XmlPullParserException e) {
191
                                                        cad = parser.getText().trim();
192
                                                }
193
                                                
194
                                                if (cad==null /*|| "".equals(cad)*/) {
195
                                                        throw new LegendDriverException (LegendDriverException.PARSE_LEGEND_FILE_ERROR);
196
                                                } else {
197
                                                        String x="",y="";
198
                                                        int cont = 0;
199

    
200
                                                        for(int i=0;i < cad.length();i++) {
201
                                                                x = String.valueOf(cad.charAt(i));
202
                                                                if(x.compareTo(",") == 0) {
203
                                                                        if (SLDUtils.isANumber(y)) {
204
                                                                                dashArray.add(Float.valueOf(y));
205
                                                                                y = "";
206
                                                                                cont++;
207
                                                                        }
208
                                                                        else 
209
                                                                                throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
210
                                                                }
211
                                                                else {
212
                                                                        if(x.compareTo(" ") != 0)
213
                                                                                y += String.valueOf(cad.charAt(i));
214
                                                                        if ( i == cad.length()-1 ) {
215
                                                                                if (SLDUtils.isANumber(y)) {
216
                                                                                        dashArray.add(Float.valueOf(y));
217
                                                                                        cont++;
218
                                                                                }
219
                                                                                else 
220
                                                                                        throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
221
                                                                        }
222

    
223
                                                                }
224
                                                        }        
225
                                                }
226
                                        }
227

    
228
                                        else if(parser.getAttributeValue("", SLDTags.NAME_ATTR).compareTo(SLDTags.STROKE_DASHOFFSET_ATTR)==0) {
229
                                                FExpression expressionDashOffset = new FExpression();
230

    
231

    
232
                                                try {
233
                                                        expressionDashOffset.parse(parser,parser.nextTag(), parser.getName());
234
                                                }
235
                                                catch(XmlPullParserException e) {
236
                                                        String s = parser.getText().trim();
237
                                                        expressionDashOffset.setLiteral(s);
238
                                                }
239

    
240
                                                if (!SLDUtils.isANumber(expressionDashOffset.getLiteral()))
241
                                                        throw new LegendDriverException(LegendDriverException.PARSE_LEGEND_FILE_ERROR);
242

    
243
                                                setExpressionDashOffset(expressionDashOffset);        
244
                                        }
245
                                }
246

    
247
                                break;
248
                        case XMLSchemaParser.END_TAG:
249
                                if (parser.getName().compareTo(SLDTags.STROKE) == 0)
250
                                        end = true;
251
                                break;
252
                        case XMLSchemaParser.TEXT:
253
                                break;
254
                        }
255
                        if (!end)
256
                                currentTag = parser.next();
257
                }
258

    
259
                parser.require(XMLSchemaParser.END_TAG, null, SLDTags.STROKE);
260

    
261
        }
262

    
263

    
264
        private void parserDashArray(XMLSchemaParser parser, int i, String name) throws XmlPullParserException, IOException, LegendDriverException {
265

    
266
                int currentTag;
267
                boolean end = false;
268
                currentTag = i;
269

    
270
                while (!end)
271
                {
272
                        switch(currentTag)
273
                        {
274
                        case XMLSchemaParser.START_TAG:
275

    
276
                                if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.LITERAL))==0) {
277
                                        this.cad = parser.nextText();
278
                                        end = true;
279

    
280
                                }
281
                        case XMLSchemaParser.END_TAG:        
282
                                if (parser.getName().compareTo(FilterUtils.remNameSpace(SLDTags.CSSPARAMETER)) == 0) {
283
                                        parser.next();
284
                                }
285
                        }
286
                        break;        
287
                }
288
                if (!end)
289
                        currentTag = parser.next();
290

    
291
        }
292

    
293

    
294
        public String toXML() {
295
                XmlBuilder xmlBuilder = new XmlBuilder();
296

    
297
                xmlBuilder.openTag(SLDTags.STROKE);
298
                if (getGraphic() != null) {
299
                        xmlBuilder.writeRaw(getGraphic().toXML());
300
                }
301
                if(getExpressionColor().getLiteral() != null){
302
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.STROKE_ATTR);
303
                        xmlBuilder.writeTag(FilterTags.LITERAL, getExpressionColor().getLiteral());
304
                        xmlBuilder.closeTag();
305
                }
306
                if(getExpressionOpacity().getLiteral() != null){
307
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.STROKE_OPACITY_ATTR);
308
                        xmlBuilder.writeTag(FilterTags.LITERAL, getExpressionOpacity().getLiteral());
309
                        xmlBuilder.closeTag();
310
                }
311
                if(getExpressionWidth().getLiteral() != null){
312
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.STROKE_WIDTH_ATTR);
313
                        xmlBuilder.writeTag(FilterTags.LITERAL, getExpressionWidth().getLiteral());
314
                        xmlBuilder.closeTag();
315
                }
316
                if(getExpressionLineCap().getLiteral() != null){
317
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.STROKE_LINECAP_ATTR);
318
                        xmlBuilder.writeTag(FilterTags.LITERAL, getExpressionLineCap().getLiteral());
319
                        xmlBuilder.closeTag();
320
                }
321
                if(getExpressionLineJoin().getLiteral() != null){
322
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.STROKE_LINEJOIN_ATTR);
323
                        xmlBuilder.writeTag(FilterTags.LITERAL, getExpressionLineJoin().getLiteral());
324
                        xmlBuilder.closeTag();
325
                }
326
                if(getDashArray() != null && getDashArray().size() > 0){
327
                        String myDash = "";
328
                        for (int i = 0; i <getDashArray().size(); i++) {
329
                                myDash += getDashArray().get(i);
330
                                if ((i+1) < getDashArray().size())
331
                                        myDash += ", ";
332
                        }
333

    
334
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.STROKE_DASHARRAY_ATTR);
335
                        xmlBuilder.writeTag(FilterTags.LITERAL, myDash);
336
                        xmlBuilder.closeTag();
337
                }
338
                if(getExpressionDashOffset().getLiteral() != null){
339
                        xmlBuilder.openTag(SLDTags.CSSPARAMETER,SLDTags.NAME_ATTR,SLDTags.STROKE_DASHOFFSET_ATTR);
340
                        xmlBuilder.writeTag(FilterTags.LITERAL, getExpressionDashOffset().getLiteral());
341
                        xmlBuilder.closeTag();
342
                }
343
                xmlBuilder.closeTag();
344

    
345
                return xmlBuilder.getXML();
346
        }
347

    
348

    
349

    
350
}