Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / sld2gvl / SLD2GVL.java @ 9641

History | View | Annotate | Download (37.8 KB)

1
package com.iver.cit.gvsig.fmap.rendering.sld2gvl;
2

    
3
import java.awt.BasicStroke;
4
import java.awt.Color;
5
import java.io.BufferedReader;
6
import java.io.File;
7
import java.io.FileNotFoundException;
8
import java.io.FileOutputStream;
9
import java.io.FileReader;
10
import java.io.IOException;
11
import java.io.OutputStreamWriter;
12
import java.io.StringReader;
13
import java.io.UnsupportedEncodingException;
14
import java.util.ArrayList;
15
import java.util.StringTokenizer;
16

    
17
import org.exolab.castor.xml.MarshalException;
18
import org.exolab.castor.xml.Marshaller;
19
import org.exolab.castor.xml.ValidationException;
20
import org.w3c.dom.Document;
21
import org.w3c.dom.Element;
22
import org.w3c.dom.NamedNodeMap;
23
import org.w3c.dom.Node;
24
import org.w3c.dom.NodeList;
25
import org.xml.sax.InputSource;
26

    
27
import com.hardcode.gdbms.engine.values.DoubleValue;
28
import com.hardcode.gdbms.engine.values.IntValue;
29
import com.hardcode.gdbms.engine.values.NumericValue;
30
import com.hardcode.gdbms.engine.values.Value;
31
import com.hardcode.gdbms.engine.values.ValueFactory;
32
import com.iver.cit.gvsig.fmap.core.FShape;
33
import com.iver.cit.gvsig.fmap.core.IGeometry;
34
import com.iver.cit.gvsig.fmap.core.SLDTags;
35
import com.iver.cit.gvsig.fmap.core.SLDUtils;
36
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
37
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
38
import com.iver.cit.gvsig.fmap.rendering.FInterval;
39
import com.iver.cit.gvsig.fmap.rendering.Legend;
40
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
41
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
42
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
43
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
44
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.BetweenFilter;
45
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.CompareFilter;
46
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.FidFilter;
47
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.Filter;
48
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.GeometryDistanceFilter;
49
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.GeometryFilter;
50
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.LikeFilter;
51
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.LogicFilter;
52
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.NullFilter;
53

    
54

    
55
public class SLD2GVL {
56
        /** Number of children in a between filter. */
57
        private static final int NUM_BETWEEN_CHILDREN = 3;
58

    
59
        private InputSource source;
60

    
61
        private Document dom;
62

    
63
        public static void main(String[] args) {
64

    
65
                StringBuffer sb = new StringBuffer();
66
                try {
67
                        BufferedReader bf = new BufferedReader(new FileReader(
68
                                        "c:/valoresunicos.sld"));
69
                        String cadena;
70
                        while ((cadena = bf.readLine()) != null) {
71
                                System.out.println(cadena);
72
                                sb.append(cadena);
73
                        }
74
                        SLD2GVL sld2avl = new SLD2GVL();
75
                        Legend legend = sld2avl.loadLegend(sb.toString());
76
                        export(legend);
77
                } catch (FileNotFoundException e) {
78
                        e.printStackTrace();
79
                } catch (IOException e) {
80
                        e.printStackTrace();
81
                }
82

    
83
        }
84
        public static VectorialLegend sld2gvl(File file) {
85

    
86
                StringBuffer sb = new StringBuffer();
87
                try {
88
                        BufferedReader bf = new BufferedReader(new FileReader(file));
89
                        String cadena;
90
                        while ((cadena = bf.readLine()) != null) {
91
                                sb.append(cadena);
92
                        }
93
                        SLD2GVL sld2avl = new SLD2GVL();
94
                        VectorialLegend legend = sld2avl.loadLegend(sb.toString());
95
                        export(legend);
96
                        return legend;
97
                } catch (FileNotFoundException e) {
98
                        e.printStackTrace();
99
                } catch (IOException e) {
100
                        e.printStackTrace();
101
                }
102
                return null;
103
        }
104
        private static void export(Legend legend) {
105
                try {
106
                String encoding = "UTF-8"; // o la codificaci?n que deseemos
107
                 FileOutputStream fos;
108

    
109
                        fos = new FileOutputStream(new File("c:/pruebaLegend.gvl"));
110

    
111
                 OutputStreamWriter writer = new OutputStreamWriter(fos, encoding);
112
                 Marshaller m = new Marshaller(writer);
113
                 m.setEncoding(encoding);
114
                 m.marshal(legend.getXMLEntity().getXmlTag());
115
                } catch (FileNotFoundException e) {
116
                        e.printStackTrace();
117
                } catch (UnsupportedEncodingException e) {
118
                        e.printStackTrace();
119
                } catch (IOException e) {
120
                        e.printStackTrace();
121
                } catch (MarshalException e) {
122
                        e.printStackTrace();
123
                } catch (ValidationException e) {
124
                        e.printStackTrace();
125
                }
126
        }
127

    
128
        private VectorialLegend loadLegend(final String xml) {
129
                StringReader sr = new StringReader(xml);
130
                source = new InputSource(sr);
131
                javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory
132
                                .newInstance();
133
                dbf.setNamespaceAware(true);
134
                try {
135
                        javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
136
                        dom = db.parse(source);
137
                } catch (javax.xml.parsers.ParserConfigurationException pce) {
138
                        throw new RuntimeException(pce);
139
                } catch (org.xml.sax.SAXException se) {
140
                        throw new RuntimeException(se);
141
                } catch (java.io.IOException ie) {
142
                        throw new RuntimeException(ie);
143
                }
144
//                 for our next trick do something with the dom.
145
                NodeList nodes = findElements(dom, SLDTags.USERSTYLE);
146
                if (nodes == null)
147
                        return new SingleSymbolLegend();
148

    
149
                VectorialLegend[] legends = new VectorialLegend[nodes.getLength()];
150

    
151
                for (int i = 0; i < nodes.getLength(); i++) {
152
                        legends[i] = parseLegend(nodes.item(i));
153
                }
154
                return legends[0];
155
        }
156

    
157
        public VectorialLegend parseLegend(Node n) {
158
                VectorialLegend legend = new SingleSymbolLegend();
159
                NodeList children = n.getChildNodes();
160

    
161
                for (int j = 0; j < children.getLength(); j++) {
162
                        Node child = children.item(j);
163

    
164
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)
165
                                        || (child.getFirstChild() == null)) {
166
                                continue;
167
                        }
168
                        String childName = child.getLocalName();
169
                        if (childName == null) {
170
                                childName = child.getNodeName();
171
                        }
172
                        if (childName.equalsIgnoreCase(SLDTags.NAME)) {
173
//                                TODO unsuported
174
                                // legend.setName(child.getFirstChild().getNodeValue());
175
                        }
176

    
177
                        if (childName.equalsIgnoreCase(SLDTags.TITLE)) {
178
//                                TODO unsuported
179
                                // legend.setTitle(child.getFirstChild().getNodeValue());
180
                        }
181

    
182
                        if (childName.equalsIgnoreCase(SLDTags.ABSTRACT)) {
183
//                                TODO unsuported
184
                                // legend.setAbstract(child.getFirstChild().getNodeValue());
185
                        }
186

    
187
                        if (childName.equalsIgnoreCase(SLDTags.FEATURETYPESTYLE)) {
188
                                legend = createFeatureTypeStyle(child);
189
                        }
190
                }
191

    
192
                return legend;
193
        }
194

    
195
        private VectorialLegend createFeatureTypeStyle(Node style) {
196
                ArrayList rules = new ArrayList();
197
                ArrayList sti = new ArrayList();
198
                NodeList children = style.getChildNodes();
199

    
200
                for (int i = 0; i < children.getLength(); i++) {
201
                        Node child = children.item(i);
202

    
203
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
204
                                continue;
205
                        }
206

    
207
                        String childName = child.getLocalName();
208
                        if (childName == null) {
209
                                childName = child.getNodeName();
210
                        }
211
                        if (childName.equalsIgnoreCase(SLDTags.NAME)) {
212
//                                TODO unsuported
213
                                // ft.setName(child.getFirstChild().getNodeValue());
214
                        }
215

    
216
                        if (childName.equalsIgnoreCase(SLDTags.TITLE)) {
217
//                                TODO unsuported
218
                                // ft.setTitle(child.getFirstChild().getNodeValue());
219
                        }
220

    
221
                        if (childName.equalsIgnoreCase(SLDTags.ABSTRACT)) {
222
//                                TODO unsuported
223
                                // ft.setAbstract(child.getFirstChild().getNodeValue());
224
                        }
225

    
226
                        if (childName.equalsIgnoreCase(SLDTags.FEATURETYPENAME)) {
227
//                                TODO unsuported
228
                                // ft.setFeatureTypeName(child.getFirstChild().getNodeValue());
229
                        }
230

    
231
                        if (childName.equalsIgnoreCase(SLDTags.SEMANTICTYPEIDENTIFIER)) {
232
                                sti.add(child.getFirstChild().getNodeValue());
233
                        }
234

    
235
                        if (childName.equalsIgnoreCase(SLDTags.RULE)) {
236
                                rules.add(parseRule(child));
237
                        }
238
                }
239

    
240
                if (sti.size() > 0) {
241
                        // ft.setSemanticTypeIdentifiers((String[]) sti.toArray(new
242
                        // String[0]));
243
                }
244
                return getVectorialLegend((Rule[])rules.toArray(new Rule[0]));
245
        }
246

    
247
        private VectorialLegend getVectorialLegend(Rule[] rules) {
248
                VectorialLegend vl=null;
249
                for (int j=0;j<rules.length;j++) {
250
                         ISymbol[] symbols=rules[j].getSymbols();
251

    
252
                         Filter filter=rules[j].getFilter();
253
                         if (filter instanceof LogicFilter) {
254
                                LogicFilter lf=(LogicFilter)filter;
255
                                 if (lf.getType().equals(SLDTags.AND)) {
256
                                        System.err.println("LogicFilter");
257
                                        double[] values = new double[filter.getNumFilters()];
258
                                        if (vl ==null) {
259
                                                vl = new VectorialIntervalLegend(rules[0].getType());
260
                                        }
261
                                        if (!(vl instanceof VectorialIntervalLegend)) {
262
                                                if (vl instanceof VectorialUniqueValueLegend) {
263
                                                        VectorialUniqueValueLegend uvl=(VectorialUniqueValueLegend)vl;
264
                                                        vl = new VectorialIntervalLegend(rules[0].getType());
265
                                                        for (int i=0;i<uvl.getValues().length;i++) {
266
                                                                NumericValue value=(NumericValue)uvl.getValues()[i];
267
                                                                FInterval interval=new FInterval(value.doubleValue(),value.doubleValue());
268
                                                                if ((value.doubleValue() == Double.NEGATIVE_INFINITY || value.doubleValue() == -9.0E99)
269
                                                                                || (value.doubleValue() == Double.POSITIVE_INFINITY || value.doubleValue() == 9.0E99)) {
270
                                                                        ((VectorialIntervalLegend) vl).addSymbol(new FInterval(0,0),
271
                                                                                        uvl.getSymbolByValue(value));
272
                                                                } else
273
                                                                                ((VectorialIntervalLegend) vl).addSymbol(interval,
274
                                                                                                uvl.getSymbolByValue(value));
275
                                                                }
276
                                                }
277
                                        }
278

    
279
                                        for (int i = 0; i < filter.getNumFilters(); i++) {
280
                                                Filter f = ((LogicFilter) filter).getFilter(i);
281
                                                if (f instanceof CompareFilter) {
282

    
283
                                                        CompareFilter cf = (CompareFilter) f;
284
                                                        ((VectorialIntervalLegend) vl).setFieldName(cf
285
                                                                        .getLeftValue().toString());
286

    
287
                                                        values[i] = ((NumericValue) cf.getRightValue())
288
                                                                        .doubleValue();
289
                                                        System.err.println(cf.getLeftValue() + " == "
290
                                                                        + cf.getRightValue());
291
                                                }
292
                                        }
293
                                        symbols[0].setDescription(rules[j].getName());
294
                                        FInterval interval = new FInterval(values[1], values[0]);
295
                                        if ((values[1] == Double.NEGATIVE_INFINITY || values[1] == -9.0E99)
296
                                                        && (values[0] == Double.POSITIVE_INFINITY || values[0] == 9.0E99)) {
297
                                                ((VectorialIntervalLegend) vl).addSymbol(new FInterval(0,0),
298
                                                                symbols[0]);
299
                                        }else
300
                                                ((VectorialIntervalLegend) vl).addSymbol(interval,
301
                                                                symbols[0]);
302
                                }else if (lf.getType().equals(SLDTags.OR)){
303
                                         System.err.println("Unsuported Filter " + "LogicFilter = "+lf.getType());
304
                                }else if (lf.getType().equals(SLDTags.NOT)) {
305
                                         System.err.println("Unsuported Filter " + "LogicFilter = "+lf.getType());
306
                                }
307

    
308
                         }else if (filter instanceof BetweenFilter) {
309
                                 System.err.println("Unsuported Filter " + "LogicFilter = "+filter.getType());
310
                         }else if (filter instanceof CompareFilter) {
311
                                 CompareFilter cf=(CompareFilter)filter;
312
                                 symbols[0].setDescription(rules[j].getName());
313

    
314
                                 if (cf.getType().equals(SLDTags.PROPERTYISEQUALTO) || cf.getType().equals(SLDTags.PROPERTYISLIKE)) {
315
                                         if (vl == null
316
                                                                || !(vl instanceof VectorialUniqueValueLegend))
317
                                                        vl = new VectorialUniqueValueLegend(rules[0].getType());
318
                                        ((VectorialUniqueValueLegend) vl).setFieldName(cf
319
                                                                .getLeftValue().toString());
320
                                        Value value = cf.getRightValue();
321
                                        if (value instanceof DoubleValue
322
                                                        && ((((DoubleValue) value).doubleValue() == Double.NEGATIVE_INFINITY ||((DoubleValue) value).doubleValue() == -9.0E99) ||
323
                                                                        (((DoubleValue) value).doubleValue() == Double.POSITIVE_INFINITY)||((DoubleValue) value).doubleValue() == 9.0E99)) {
324
                                                ((VectorialUniqueValueLegend) vl)
325
                                                                .setDefaultSymbol(symbols[0]);
326
                                        }else {
327
                                                ((VectorialUniqueValueLegend) vl).addSymbol(value,
328
                                                                symbols[0]);
329
                                        }
330

    
331
                                 }else if (cf.getType().equals(SLDTags.PROPERTYISGREATEROREQUALTHAN)) {
332
                                         System.err.println("Unsuported Filter " + "CompareFilter = "+cf.getType());
333
                                 }else if (cf.getType().equals(SLDTags.PROPERTYISGREATERTHAN)) {
334
                                         System.err.println("Unsuported Filter " + "CompareFilter = "+cf.getType());
335
                                 }else if (cf.getType().equals(SLDTags.PROPERTYISLESSOREQUALTHAN)) {
336
                                         System.err.println("Unsuported Filter " + "CompareFilter = "+cf.getType());
337
                                 }else if (cf.getType().equals(SLDTags.PROPERTYISLESSTHAN)) {
338
                                         System.err.println("Unsuported Filter " + "CompareFilter = "+cf.getType());
339
                                 }else if (cf.getType().equals(SLDTags.PROPERTYISNOTEQUALTO)) {
340
                                         System.err.println("Unsuported Filter " + "CompareFilter = "+cf.getType());
341
                                 }else if (cf.getType().equals(SLDTags.PROPERTYISNULL)) {
342
                                         System.err.println("Unsuported Filter " + "CompareFilter = "+cf.getType());
343
                                 }
344
                         }else if (filter instanceof FidFilter) {
345
                                        System.err.println("FidFilter");
346
                         }else if (filter instanceof GeometryDistanceFilter) {
347
                                        System.err.println("GeometryDistanceFilter");
348
                         }else if (filter instanceof GeometryFilter) {
349
                                        System.err.println("GeometryFilter");
350
                         }else if (filter instanceof LikeFilter) {
351
                                        System.err.println("LikeFilter");
352
                         }else if (filter instanceof NullFilter) {
353
                                        System.err.println("NullFilter");
354
                         }else {
355
                                 vl=new SingleSymbolLegend(symbols[0]);
356
                         }
357
                 }
358
                return vl;
359
        }
360

    
361
        private Rule parseRule(Node ruleNode) {
362
                Rule rule=new Rule();
363
                ArrayList symbols = new ArrayList();
364
                NodeList children = ruleNode.getChildNodes();
365

    
366
                for (int i = 0; i < children.getLength(); i++) {
367
                        Node child = children.item(i);
368

    
369
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
370
                                continue;
371
                        }
372
                        String childName = child.getLocalName();
373
                        if (childName == null) {
374
                                childName = child.getNodeName();
375
                        }
376

    
377
                        if (childName.indexOf(':') != -1) {
378
                                // the DOM parser wasnt properly set to handle namespaces...
379
                                childName = childName.substring(childName.indexOf(':') + 1);
380
                        }
381

    
382
                        if (childName.equalsIgnoreCase(SLDTags.NAME)) {
383
                                rule.setName(child.getFirstChild().getNodeValue());
384
                        }
385

    
386
                        if (childName.equalsIgnoreCase(SLDTags.TITLE)) {
387
                                rule.setTitle(child.getFirstChild().getNodeValue());
388
                        }
389

    
390
                        if (childName.equalsIgnoreCase(SLDTags.ABSTRACT)) {
391
                                rule.setAbstract(child.getFirstChild().getNodeValue());
392
                        }
393

    
394
                        if (childName.equalsIgnoreCase(SLDTags.MINSCALEDENOMINATOR)) {
395
                                rule.setMinScaleDenominator(Double.parseDouble(child
396
                                                .getFirstChild().getNodeValue()));
397
                        }
398

    
399
                        if (childName.equalsIgnoreCase(SLDTags.MAXSCALEDENOMINATOR)) {
400
                                rule.setMaxScaleDenominator(Double.parseDouble(child
401
                                                .getFirstChild().getNodeValue()));
402
                        }
403

    
404
                        if (childName.equalsIgnoreCase(SLDTags.FILTER)) {
405
                                NodeList list = child.getChildNodes();
406
                                Node kid = null;
407

    
408
                                for (int k = 0; k < list.getLength(); k++) {
409
                                        kid = list.item(k);
410

    
411
                                        if ((kid == null)
412
                                                        || (kid.getNodeType() != Node.ELEMENT_NODE)) {
413
                                                continue;
414
                                        }
415

    
416
                                        Filter filter = parseFilter(kid);
417
                                        rule.setFilter(filter);
418
                                }
419
                        }
420

    
421
                        if (childName.equalsIgnoreCase(SLDTags.ELSEFILTER)) {
422
                                rule.setIsElseFilter(true);
423
                        }
424

    
425
                        if (childName.equalsIgnoreCase(SLDTags.LEGENDGRAPHIC)) {
426
//                                TODO unsuported
427
//                                findElements(((Element) child), graphicSt);
428
//                                NodeList g = findElements(((Element) child), graphicSt);
429
//                                ArrayList legends = new ArrayList();
430
//
431
//                                for (int k = 0; k < g.getLength(); k++) {
432
//                                        legends.add(parseGraphic(g.item(k)));
433
//                                }
434
//
435
//                                rule.setLegendGraphic((Graphic[]) legends
436
//                                                .toArray(new Graphic[0]));
437
                        }
438

    
439
                        if (childName.equalsIgnoreCase(SLDTags.LINESYMBOLIZER)) {
440
                                rule.setType(FShape.LINE);
441
                                symbols.add(parseLineSymbol(child));
442
                        }
443

    
444
                        if (childName.equalsIgnoreCase(SLDTags.POLYGONSYMBOLIZER)) {
445
                                rule.setType(FShape.POLYGON);
446
                                symbols.add(parsePolygonSymbol(child));
447
                        }
448

    
449
                        if (childName.equalsIgnoreCase(SLDTags.POINTSYMBOLIZER)) {
450
                                rule.setType(FShape.POINT);
451
                                symbols.add(parsePointSymbol(child));
452
                        }
453

    
454
                        if (childName.equalsIgnoreCase(SLDTags.TEXTSYMBOLIZER)) {
455
                                rule.setType(FShape.TEXT);
456
                                symbols.add(parseTextSymbol(child));
457
                        }
458

    
459
                        if (childName.equalsIgnoreCase(SLDTags.RASTERSYMBOLIZER)) {
460
//                                TODO unsuported
461
                                //symbols.add(parseRasterSymbolizer(child));
462
                        }
463
                }
464

    
465
                rule.setSymbols((ISymbol[]) symbols
466
                                .toArray(new ISymbol[0]));
467

    
468
                return rule;
469
        }
470

    
471
        private FSymbol parseTextSymbol(Node root) {
472
                FSymbol text=new FSymbol(FShape.TEXT);
473
                ArrayList fonts = new ArrayList();
474
                NodeList children = root.getChildNodes();
475

    
476
                for (int i = 0; i < children.getLength(); i++) {
477
                        Node child = children.item(i);
478

    
479
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
480
                                continue;
481
                        }
482
                        String childName = child.getLocalName();
483
                        if (childName == null) {
484
                                childName = child.getNodeName();
485
                        }
486
                        if (childName.equalsIgnoreCase(SLDTags.GEOMETRY)) {
487
                                parseGeometryName(child,text);
488
                        }
489

    
490
                        if (childName.equalsIgnoreCase(SLDTags.FILL)) {
491
                                parseFill(child,text);
492
                        }
493

    
494
                        if (childName.equalsIgnoreCase(SLDTags.LABEL)) {
495
                                parseGeometryName(child,text);
496
                                //symbol.setLabel(parseCssParameter(child));
497
                        }
498

    
499
                        if (childName.equalsIgnoreCase(SLDTags.FONT)) {
500
                                parseFont(child,text);
501
                        }
502

    
503
                        if (childName.equalsIgnoreCase(SLDTags.LABELPLACEMENT)) {
504
//                                TODO unsuported
505
//                                symbol.setPlacement(parseLabelPlacement(child));
506
                        }
507

    
508
                        if (childName.equalsIgnoreCase(SLDTags.HALO)) {
509
//                                TODO unsuported
510
//                                symbol.setHalo(parseHalo(child));
511
                        }
512
                        if (childName.equalsIgnoreCase(SLDTags.GRAPHIC)) {
513
                                parseGraphic(child,text);
514
//                                if (symbol instanceof TextSymbolizer2)
515
//                                {
516
//                                        ((TextSymbolizer2)symbol).setGraphic(parseGraphic(child));
517
//                                }
518
                        }
519

    
520

    
521
                        if (childName.equalsIgnoreCase(SLDTags.PRIORITY_ATTR)){
522
//                                TODO unsuported
523
//                                symbol.setPriority(parseCssParameter(child));
524
                        }
525
                        if (childName.equalsIgnoreCase(SLDTags.VENDOROPTION_ATTR)){
526
//                                TODO unsuported
527
//                                parseVendorOption(symbol,child);
528
                        }
529

    
530
                }
531
                return text;
532
        }
533

    
534

    
535
        private void parseFont(Node root,FSymbol symbol) {
536
                NodeList list = findElements(((Element) root), SLDTags.CSSPARAMETER);
537

    
538
                for (int i = 0; i < list.getLength(); i++) {
539
                        Node child = list.item(i);
540

    
541
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
542
                                continue;
543
                        }
544

    
545
                        Element param = (Element) child;
546
                        org.w3c.dom.NamedNodeMap map = param.getAttributes();
547

    
548
                        for (int k = 0; k < map.getLength(); k++) {
549
                                String res = map.item(k).getNodeValue();
550

    
551
                                if (res.equalsIgnoreCase(SLDTags.FONTFAMILY_ATTR)) {
552
//                                        TODO unsuported
553
//                                        font.setFontFamily(parseCssParameter(child));
554
                                }
555

    
556
                                if (res.equalsIgnoreCase(SLDTags.FONTSTYLE_ATTR)) {
557
//                                        TODO unsuported
558
//                                        font.setFontStyle(parseCssParameter(child));
559
                                }
560

    
561
                                if (res.equalsIgnoreCase(SLDTags.FONTSIZE_ATTR)) {
562
                                        symbol.setFontSize(((NumericValue)getValue(child,SLDTags.CSSPARAMETER)).floatValue());
563
                                }
564

    
565
                                if (res.equalsIgnoreCase(SLDTags.FONTWEIGHT_ATTR)) {
566
//                                        TODO unsuported
567
//                                        font.setFontWeight(parseCssParameter(child));
568
                                }
569
                        }
570
                }
571
        }
572

    
573
        private FSymbol parsePointSymbol(Node root) {
574
                FSymbol point=new FSymbol(FShape.POINT);
575
                NodeList children = root.getChildNodes();
576

    
577
                for (int i = 0; i < children.getLength(); i++) {
578
                        Node child = children.item(i);
579

    
580
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
581
                                continue;
582
                        }
583
                        String childName = child.getLocalName();
584
                        if (childName == null) {
585
                                childName = child.getNodeName();
586
                        }
587
                        if (childName.equalsIgnoreCase(SLDTags.GEOMETRY)) {
588
                                parseGeometryName(child,point);
589
                        }
590

    
591
                        if (childName.equalsIgnoreCase(SLDTags.GRAPHIC)) {
592
                                parseGraphic(child,point);
593
                        }
594
                }
595

    
596
                return point;
597
        }
598

    
599
        public static Filter parseFilter(Node root) {
600
                if ((root == null) || (root.getNodeType() != Node.ELEMENT_NODE)) {
601
                        System.out.println("bad node input ");
602
                        return null;
603
                }
604

    
605
                Node child = root;
606
                String childName = child.getLocalName();
607
                if (childName == null) {
608
                        childName = child.getNodeName();// HACK ?
609
                }
610
                if (childName.indexOf(':') != -1) {
611
                        // the DOM parser wasnt properly set to handle namespaces...
612
                        childName = childName.substring(childName.indexOf(':') + 1);
613
                }
614

    
615
                if (SLDTags.PROPERTYFEATUREID.equals(childName)) {
616
                        FidFilter fidFilter = new FidFilter(childName);
617
                        Element fidElement = (Element) child;
618
                        fidFilter.addFid(fidElement.getAttribute(SLDTags.FID_ATTR));
619

    
620
                        Node sibling = fidElement.getNextSibling();
621

    
622
                        while (sibling != null) {
623
                                if (sibling.getNodeType() == Node.ELEMENT_NODE) {
624
                                        fidElement = (Element) sibling;
625

    
626
                                        String fidElementName = fidElement.getLocalName();
627
                                        if (fidElementName == null) {
628
                                                fidElementName = fidElement.getNodeName();// HACK
629
                                                // ?
630
                                        }
631
                                        if (fidElementName.indexOf(':') != -1) {
632
                                                // the DOM parser wasnt properly set to handle
633
                                                // namespaces...
634
                                                fidElementName = fidElementName
635
                                                                .substring(fidElementName.indexOf(':') + 1);
636
                                        }
637
                                        if (SLDTags.PROPERTYFEATUREID.equals(fidElementName)) {
638
                                                fidFilter.addFid(fidElement.getAttribute(SLDTags.FID_ATTR));
639
                                        }
640
                                }
641

    
642
                                sibling = sibling.getNextSibling();
643
                        }
644

    
645
                        return fidFilter;
646
                } else if (SLDTags.PROPERTYISBETWEEN.equals(childName)) {
647
                        BetweenFilter betweenfilter = new BetweenFilter(childName);
648
                        NodeList kids = child.getChildNodes();
649

    
650
                        if (kids.getLength() < NUM_BETWEEN_CHILDREN) {
651
                                // throw new IllegalFilterException(
652
                                // "wrong number of children in Between filter: expected 3 got "
653
                                // + kids.getLength());
654
                        }
655

    
656
                        Node value = child.getFirstChild();
657

    
658
                        while (value.getNodeType() != Node.ELEMENT_NODE) {
659
                                value = value.getNextSibling();
660
                        }
661

    
662
                        betweenfilter.addMiddleValue(((NumericValue) getValue(value,
663
                                        SLDTags.CSSPARAMETER)).doubleValue());
664

    
665
                        for (int i = 0; i < kids.getLength(); i++) {
666
                                Node kid = kids.item(i);
667

    
668
                                String kidName = (kid.getLocalName() != null) ? kid
669
                                                .getLocalName() : kid.getNodeName();
670
                                if (kidName.indexOf(':') != -1) {
671
                                        // the DOM parser wasnt properly set to handle
672
                                        // namespaces...
673
                                        kidName = kidName.substring(kidName.indexOf(':') + 1);
674
                                }
675
                                if (kidName.equalsIgnoreCase(SLDTags.LOWERBOUNDARY)) {
676
                                        value = kid.getFirstChild();
677

    
678
                                        while (value.getNodeType() != Node.ELEMENT_NODE) {
679
                                                value = value.getNextSibling();
680
                                        }
681

    
682
                                        betweenfilter.addLeftValue(((NumericValue) getValue(value,
683
                                                        SLDTags.CSSPARAMETER)).doubleValue());
684
                                }
685

    
686
                                if (kidName.equalsIgnoreCase(SLDTags.UPPERBOUNDARY)) {
687
                                        value = kid.getFirstChild();
688

    
689
                                        while (value.getNodeType() != Node.ELEMENT_NODE) {
690
                                                value = value.getNextSibling();
691
                                        }
692

    
693
                                        betweenfilter.addRightValue(((NumericValue) getValue(value,
694
                                                        SLDTags.CSSPARAMETER)).doubleValue());
695
                                }
696
                        }
697

    
698
                        return betweenfilter;
699
                } else if (SLDTags.PROPERTYISLIKE.equals(childName)) {
700
                        String wildcard = null;
701
                        String single = null;
702
                        String escape = null;
703
                        String pattern = null;
704
                        Value value = null;
705
                        NodeList map = child.getChildNodes();
706

    
707
                        for (int i = 0; i < map.getLength(); i++) {
708
                                Node kid = map.item(i);
709

    
710
                                if ((kid == null) || (kid.getNodeType() != Node.ELEMENT_NODE)) {
711
                                        continue;
712
                                }
713

    
714
                                String res = (kid.getLocalName() != null) ? kid.getLocalName()
715
                                                : kid.getNodeName();
716
                                if (res.indexOf(':') != -1) {
717
                                        // the DOM parser wasnt properly set to handle
718
                                        // namespaces...
719
                                        res = res.substring(res.indexOf(':') + 1);
720
                                }
721

    
722
                                if (res.equalsIgnoreCase(SLDTags.PROPERTYNAME)) {
723
                                        value = getValue(kid, SLDTags.PROPERTYNAME);
724
                                }
725

    
726
                                if (res.equalsIgnoreCase(SLDTags.LITERAL)) {
727
                                        pattern = getValue(kid, SLDTags.LITERAL).toString();
728
                                }
729
                        }
730

    
731
                        NamedNodeMap kids = child.getAttributes();
732

    
733
                        for (int i = 0; i < kids.getLength(); i++) {
734
                                Node kid = kids.item(i);
735

    
736
                                String res = (kid.getLocalName() != null) ? kid.getLocalName()
737
                                                : kid.getNodeName();
738
                                if (res.indexOf(':') != -1) {
739
                                        // the DOM parser wasnt properly set to handle
740
                                        // namespaces...
741
                                        res = res.substring(res.indexOf(':') + 1);
742
                                }
743
                                if (res.equalsIgnoreCase(SLDTags.WILDCARD_ATTR)) {
744
                                        wildcard = kid.getNodeValue();
745
                                }
746

    
747
                                if (res.equalsIgnoreCase(SLDTags.SINGLECHAR_ATTR)) {
748
                                        single = kid.getNodeValue();
749
                                }
750

    
751
                                if (res.equalsIgnoreCase(SLDTags.ESCAPECHAR_ATTR)
752
                                                || res.equalsIgnoreCase(SLDTags.ESCAPE_ATTR)) {
753
                                        escape = kid.getNodeValue();
754
                                }
755
                        }
756

    
757
                        if (!((wildcard == null) || (single == null) || (escape == null) || (pattern == null))) {
758
                                LikeFilter lfilter = new LikeFilter(childName);
759
                                lfilter.setValue(value);
760
                                lfilter.setPattern(pattern, wildcard, single, escape);
761

    
762
                                return lfilter;
763
                        }
764
                        return null;
765
                } else if (SLDTags.PROPERTYISNULL.equals(childName)) {
766
                        NullFilter nFilter = new NullFilter(childName);
767
                        Node value = child.getFirstChild();
768

    
769
                        while (value.getNodeType() != Node.ELEMENT_NODE) {
770
                                value = value.getNextSibling();
771
                        }
772
                        nFilter.nullCheckValue(getValue(value, SLDTags.CSSPARAMETER));
773

    
774
                        return nFilter;
775
                } else if (SLDTags.PROPERTYISEQUALTO.equals(childName)
776
                                || SLDTags.PROPERTYISGREATEROREQUALTHAN.equals(childName)
777
                                || SLDTags.PROPERTYISGREATERTHAN.equals(childName)
778
                                || SLDTags.PROPERTYISLESSOREQUALTHAN.equals(childName)
779
                                || SLDTags.PROPERTYISLESSTHAN.equals(childName)
780
                                || SLDTags.PROPERTYISNOTEQUALTO.equals(childName)) {
781
                        CompareFilter cFilter = null;
782
                        cFilter = new CompareFilter(childName);
783

    
784
                        // find and parse left and right values
785
                        Node value = child.getFirstChild();
786

    
787
                        while (value.getNodeType() != Node.ELEMENT_NODE) {
788
                                value = value.getNextSibling();
789
                        }
790

    
791
                        cFilter.addLeftValue(getValue(value, SLDTags.PROPERTYNAME));
792
                        value = value.getNextSibling();
793

    
794
                        while (value.getNodeType() != Node.ELEMENT_NODE) {
795
                                value = value.getNextSibling();
796
                        }
797

    
798
                        cFilter.addRightValue(getValue(value, SLDTags.LITERAL));
799
                        return cFilter;
800
                }
801
                if (SLDTags.EQUALS.equals(childName) || SLDTags.BBOX.equals(childName)
802
                                || SLDTags.BEYOND.equals(childName)
803
                                || SLDTags.CONTAINS.equals(childName)
804
                                || SLDTags.CROSSES.equals(childName)
805
                                || SLDTags.DISJOINT.equals(childName)
806
                                || SLDTags.INTERSECTS.equals(childName)
807
                                || SLDTags.OVERLAPS.equals(childName)
808
                                || SLDTags.TOUCHES.equals(childName)
809
                                || SLDTags.WITHIN.equals(childName)) {
810
                        GeometryFilter gFilter = new GeometryFilter(childName);
811
                        Node value = child.getFirstChild();
812
                        while (value.getNodeType() != Node.ELEMENT_NODE) {
813
                                value = value.getNextSibling();
814
                        }
815
                        gFilter.addLeftGeometry(getGeometry(value));
816
                        value = value.getNextSibling();
817

    
818
                        while (value.getNodeType() != Node.ELEMENT_NODE) {
819
                                value = value.getNextSibling();
820
                        }
821

    
822
                        String valueName = (value.getLocalName() != null) ? value
823
                                        .getLocalName() : value.getNodeName();
824
                        if (valueName.indexOf(':') != -1) {
825
                                // the DOM parser wasnt properly set to handle namespaces...
826
                                valueName = valueName.substring(valueName.indexOf(':') + 1);
827
                        }
828

    
829
                        if (!(valueName.equalsIgnoreCase(SLDTags.LITERAL) || valueName
830
                                        .equalsIgnoreCase(SLDTags.PROPERTYNAME))) {
831
                                Element literal = value.getOwnerDocument().createElement(
832
                                                SLDTags.LITERAL_ATTR);
833

    
834
                                literal.appendChild(value);
835
                                value = literal;
836
                        }
837

    
838
                        gFilter.addRightGeometry(getGeometry(value));
839

    
840
                        return gFilter;
841
                }
842
                if (SLDTags.AND.equals(childName) || SLDTags.OR.equals(childName)
843
                                || SLDTags.NOT.equals(childName)) {
844
                        LogicFilter filter = new LogicFilter(childName);
845
                        NodeList map = child.getChildNodes();
846

    
847
                        for (int i = 0; i < map.getLength(); i++) {
848
                                Node kid = map.item(i);
849

    
850
                                if ((kid == null) || (kid.getNodeType() != Node.ELEMENT_NODE)) {
851
                                        continue;
852
                                }
853
                                filter.addFilter(parseFilter(kid));
854
                        }
855

    
856
                        return filter;
857
                }
858
                return null;
859
        }
860

    
861
        private static IGeometry getGeometry(Node value) {
862
//                TODO unsuported
863
                return null;
864
        }
865

    
866
        private NodeList findElements(final org.w3c.dom.Document document,
867
                        final String name) {
868
                NodeList nodes = document.getElementsByTagNameNS("*", name);
869

    
870
                if (nodes.getLength() == 0) {
871
                        nodes = document.getElementsByTagName(name);
872
                }
873

    
874
                return nodes;
875
        }
876
        public static Value getValue(Node root, String name) {
877
                if ((root == null) || (root.getNodeType() != Node.ELEMENT_NODE)) {
878
                        return null;
879
                }
880
                Node child = root;
881

    
882
                String childName = (child.getLocalName() != null) ? child
883
                                .getLocalName() : child.getNodeName();
884

    
885
                if (childName.indexOf(':') != -1) {
886
                        // the DOM parser wasnt properly set to handle namespaces...
887
                        childName = childName.substring(childName.indexOf(':') + 1);
888
                }
889

    
890
                if (childName.equalsIgnoreCase(name)) {
891

    
892
                        NodeList kidList = child.getChildNodes();
893

    
894
                        for (int i = 0; i < kidList.getLength(); i++) {
895
                                Node kid = kidList.item(i);
896

    
897
                                if (kid == null) {
898
                                        continue;
899
                                }
900
                                if (kid.getNodeValue().trim().length() == 0) {
901
                                        continue;
902
                                }
903

    
904
                                String nodeValue = kid.getNodeValue();
905
                                System.out.println("Node value is: " + nodeValue);
906
                                // see if it's an int
907
                                        try {
908
                                                Integer intLit = new Integer(nodeValue);
909
                                                return ValueFactory.createValue(intLit.intValue());
910
                                        } catch (NumberFormatException e) {
911
                                                /* really empty */
912
                                        }
913

    
914
////                                         A float?
915
//                                        try {
916
//                                                Float floatLit = new Float(nodeValue);
917
//                                                return ValueFactory.createValue(floatLit.floatValue());
918
//                                        } catch (NumberFormatException e) {
919
//                                                /* really empty */
920
//                                        }
921
                                        // A double?
922
                                        try {
923
                                                Double doubleLit = new Double(nodeValue);
924
                                                return ValueFactory.createValue(doubleLit.doubleValue());
925
                                        } catch (NumberFormatException e) {
926
                                                /* really empty */
927
                                        }
928

    
929
                                        // must be a string (or we have a problem)
930
                                        return ValueFactory.createValue(nodeValue);
931
                        }
932
                }
933

    
934
                return null;
935

    
936
        }
937

    
938
        private ISymbol parseLineSymbol(Node root) {
939
                FSymbol line = new FSymbol(FShape.LINE);//factory.createLineSymbolizer();
940
                NodeList children = root.getChildNodes();
941

    
942
                for (int i = 0; i < children.getLength(); i++) {
943
                        Node child = children.item(i);
944

    
945
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
946
                                continue;
947
                        }
948
                        String childName = child.getLocalName();
949
                        if (childName == null) {
950
                                childName = child.getNodeName();
951
                        }
952
                        if (childName.equalsIgnoreCase(SLDTags.GEOMETRY)) {
953
                                parseGeometryName(child,line);
954
                        }
955

    
956
                        if (childName.equalsIgnoreCase(SLDTags.STROKE)) {
957
                                parseStroke(child,line);
958
                        }
959
                }
960

    
961
                return line;
962
        }
963
        private FSymbol parsePolygonSymbol(Node root) {
964
                FSymbol polygon=new FSymbol(FShape.POLYGON);
965
                NodeList children = root.getChildNodes();
966

    
967
                for (int i = 0; i < children.getLength(); i++) {
968
                        Node child = children.item(i);
969

    
970
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
971
                                continue;
972
                        }
973
                        String childName = child.getLocalName();
974
                        if (childName == null) {
975
                                childName = child.getNodeName();
976
                        }
977
                        if (childName.equalsIgnoreCase(SLDTags.GEOMETRY)) {
978
                                parseGeometryName(child,polygon);
979
                        }
980

    
981
                        if (childName.equalsIgnoreCase(SLDTags.STROKE)) {
982
                                parseStroke(child,polygon);
983
                        }
984

    
985
                        if (childName.equalsIgnoreCase(SLDTags.FILL)) {
986
                                parseFill(child,polygon);
987
                        }
988
                }
989

    
990
                return polygon;
991
        }
992

    
993
        private void parseFill(Node root,FSymbol symbol) {
994
                NodeList list = findElements(((Element) root), SLDTags.GRAPHICFILL);
995

    
996
                if (list.getLength() > 0) {
997

    
998
                        NodeList kids = list.item(0).getChildNodes();
999

    
1000
                        for (int i = 0; i < kids.getLength(); i++) {
1001
                                Node child = kids.item(i);
1002

    
1003
                                if ((child == null)
1004
                                                || (child.getNodeType() != Node.ELEMENT_NODE)) {
1005
                                        continue;
1006
                                }
1007
                                String childName = child.getLocalName();
1008
                                if (childName == null) {
1009
                                        childName = child.getNodeName();
1010
                                }
1011
                                if (childName.equalsIgnoreCase(SLDTags.GRAPHIC)) {
1012
                                        parseGraphic(child,symbol);
1013
                                }
1014
                        }
1015
                }
1016

    
1017
                list = findElements(((Element) root), SLDTags.CSSPARAMETER);
1018

    
1019
                for (int i = 0; i < list.getLength(); i++) {
1020
                        Node child = list.item(i);
1021

    
1022
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
1023
                                continue;
1024
                        }
1025

    
1026
                        Element param = (Element) child;
1027
                        org.w3c.dom.NamedNodeMap map = param.getAttributes();
1028

    
1029
                        for (int k = 0; k < map.getLength(); k++) {
1030
                                String res = map.item(k).getNodeValue();
1031
                                if (res.equalsIgnoreCase(SLDTags.FILL)) {
1032
                                        symbol.setColor(getColor(child));
1033
                                }
1034

    
1035
                                if (res.equalsIgnoreCase(SLDTags.OPACITY)
1036
                                                || res.equalsIgnoreCase(SLDTags.FILLOPACITY_ATTR)) {
1037

    
1038
                                        Color color=symbol.getColor();
1039
                                        double opacity=((NumericValue)getValue(child,SLDTags.CSSPARAMETER)).doubleValue();
1040
                                        int opacityInt=(int)(254*opacity);
1041
                                        symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),opacityInt));
1042
                                }
1043
                        }
1044
                }
1045
        }
1046

    
1047
        private void parseGeometryName(Node root, ISymbol symbol) {
1048
                symbol.setDescription(getValue(root,SLDTags.CSSPARAMETER).toString());
1049
        }
1050

    
1051
        private NodeList findElements(final org.w3c.dom.Element element,
1052
                        final String name) {
1053
                NodeList nodes = element.getElementsByTagNameNS("*", name);
1054

    
1055
                if (nodes.getLength() == 0) {
1056
                        nodes = element.getElementsByTagName(name);
1057
                }
1058

    
1059
                return nodes;
1060
        }
1061
        private void parseGraphic(Node root,FSymbol symbol) {
1062
                NodeList children = root.getChildNodes();
1063

    
1064
                for (int i = 0; i < children.getLength(); i++) {
1065
                        Node child = children.item(i);
1066

    
1067
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
1068
                                continue;
1069
                        }
1070
                        String childName = child.getLocalName();
1071
                        if (childName == null) {
1072
                                childName = child.getNodeName();
1073
                        }
1074
                        if (childName.equalsIgnoreCase(SLDTags.GEOMETRY)) {
1075
//                                TODO unsuported
1076
                                ///graphic.setGeometryPropertyName(parseGeometryName(child));
1077
                        }
1078

    
1079
                        if (childName.equalsIgnoreCase(SLDTags.EXTERNALGRAPHIC)) {
1080
//                                TODO unsuported
1081
                                ///graphic.addExternalGraphic(parseExternalGraphic(child));
1082
                        }
1083

    
1084
                        if (childName.equalsIgnoreCase(SLDTags.MARK)) {
1085
//                                TODO unsuported
1086
                                ///graphic.addMark(parseMark(child));
1087
                        }
1088

    
1089
                        if (childName.equalsIgnoreCase(SLDTags.OPACITY)) {
1090
                                double opacity=((NumericValue)getValue(child,SLDTags.CSSPARAMETER)).doubleValue();
1091
                                int opacityInt=(int)(254*opacity);
1092
                                Color color=symbol.getColor();
1093
                                symbol.setColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),opacityInt));
1094
                        }
1095

    
1096
                        if (childName.equalsIgnoreCase(SLDTags.SIZE)) {
1097
                                symbol.setSizeInPixels(true);
1098
                                symbol.setSize(((IntValue)getValue(child,SLDTags.CSSPARAMETER)).intValue());
1099
                        }
1100

    
1101
                        if (childName.equalsIgnoreCase(SLDTags.DISPLACEMENT_ATTR)) {
1102
//                                TODO unsuported
1103
                                ///graphic.setDisplacement(parseDisplacement(child));
1104
                        }
1105

    
1106
                        if (childName.equalsIgnoreCase(SLDTags.ROTATION_ATTR)) {
1107
//                                TODO unsuported
1108
                                ///graphic.setRotation(parseCssParameter(child));
1109
                        }
1110
                }
1111
        }
1112

    
1113
        private void parseStroke(Node root,FSymbol symbol) {
1114
                NodeList list = findElements(((Element) root), SLDTags.GRAPHICFILL);
1115

    
1116
                if (list.getLength() > 0) {
1117
                        NodeList kids = list.item(0).getChildNodes();
1118

    
1119
                        for (int i = 0; i < kids.getLength(); i++) {
1120
                                Node child = kids.item(i);
1121

    
1122
                                if ((child == null)
1123
                                                || (child.getNodeType() != Node.ELEMENT_NODE)) {
1124
                                        continue;
1125
                                }
1126
                                String childName = child.getLocalName();
1127
                                if (childName == null) {
1128
                                        childName = child.getNodeName();
1129
                                }
1130
                                if (childName.equalsIgnoreCase(SLDTags.GRAPHIC)) {
1131
                                        parseGraphic(child,symbol);
1132
                                }
1133
                        }
1134
                }
1135

    
1136
                list = findElements(((Element) root), SLDTags.GRAPHICSTROKE);
1137

    
1138
                if (list.getLength() > 0) {
1139

    
1140
                        NodeList kids = list.item(0).getChildNodes();
1141

    
1142
                        for (int i = 0; i < kids.getLength(); i++) {
1143
                                Node child = kids.item(i);
1144

    
1145
                                if ((child == null)
1146
                                                || (child.getNodeType() != Node.ELEMENT_NODE)) {
1147
                                        continue;
1148
                                }
1149
                                String childName = child.getLocalName();
1150
                                if (childName == null) {
1151
                                        childName = child.getNodeName();
1152
                                }
1153
                                if (childName.equalsIgnoreCase(SLDTags.GRAPHIC)) {
1154
                                        parseGraphic(child,symbol);
1155
                                }
1156
                        }
1157
                }
1158

    
1159
                list = findElements(((Element) root), SLDTags.CSSPARAMETER);
1160

    
1161
                for (int i = 0; i < list.getLength(); i++) {
1162
                        Node child = list.item(i);
1163

    
1164
                        if ((child == null) || (child.getNodeType() != Node.ELEMENT_NODE)) {
1165
                                continue;
1166
                        }
1167
                        Element param = (Element) child;
1168
                        org.w3c.dom.NamedNodeMap map = param.getAttributes();
1169

    
1170
                        for (int k = 0; k < map.getLength(); k++) {
1171
                                String res = map.item(k).getNodeValue();
1172

    
1173
                                if (res.equalsIgnoreCase(SLDTags.STROKE_ATTR)) {
1174
                                        symbol.setOutlined(true);
1175
                                        symbol.setOutlineColor(getColor(child));
1176
                                        if (symbol.getSymbolType()==FShape.LINE) {
1177
                                                symbol.setColor(getColor(child));
1178
                                        }
1179
                                }
1180

    
1181
                                if (res.equalsIgnoreCase(SLDTags.WIDTH_ATTR)
1182
                                                || res.equalsIgnoreCase(SLDTags.STROKE_WIDTH_ATTR)) {
1183
                                        symbol.setStroke(new BasicStroke(((NumericValue)getValue(child,SLDTags.CSSPARAMETER)).floatValue()));
1184
                                }
1185

    
1186
                                if (res.equalsIgnoreCase(SLDTags.OPACITY)
1187
                                                || res.equalsIgnoreCase(SLDTags.STROKE_OPACITY_ATTR)) {
1188
                                        Color color=symbol.getOutlineColor();
1189
                                        double opacity=((NumericValue)getValue(child,SLDTags.CSSPARAMETER)).doubleValue();
1190
                                        int opacityInt=(int)(254*opacity);
1191
                                        symbol.setOutlineColor(new Color(color.getRed(),color.getGreen(),color.getBlue(),opacityInt));
1192

    
1193
                                }
1194

    
1195
                                if (res.equalsIgnoreCase(SLDTags.LINECAP_ATTR)
1196
                                                || res.equalsIgnoreCase(SLDTags.STROKE_LINECAP_ATTR)) {
1197
//                                        TODO unsuported
1198
                                        // since these are system-dependent just pass them through
1199
                                        // and hope.
1200
//                                        stroke.setLineCap(parseCssParameter(child));
1201
                                }
1202

    
1203
                                if (res.equalsIgnoreCase(SLDTags.LINEJOIN_ATTR)
1204
                                                || res.equalsIgnoreCase(SLDTags.STROKE_LINEJOIN_ATTR)) {
1205
//                                        TODO unsuported
1206
                                        // since these are system-dependent just pass them through
1207
                                        // and hope.
1208
//                                        stroke.setLineJoin(parseCssParameter(child));
1209
                                }
1210

    
1211
                                if (res.equalsIgnoreCase(SLDTags.DASHARRAY_ATTR)
1212
                                                || res.equalsIgnoreCase(SLDTags.STROKE_DASHARRAY_ATTR)) {
1213
                                        String dashString = child.getFirstChild().getNodeValue();
1214
                                        StringTokenizer stok = new StringTokenizer(dashString, " ");
1215
                                        float[] dashes = new float[stok.countTokens()];
1216

    
1217
                                        for (int l = 0; l < dashes.length; l++) {
1218
                                                dashes[l] = Float.parseFloat(stok.nextToken());
1219
                                        }
1220
//                                        TODO unsuported
1221
//                                        stroke.setDashArray(dashes);
1222
                                }
1223

    
1224
                                if (res.equalsIgnoreCase(SLDTags.DASHOFFSET_ATTR)
1225
                                                || res.equalsIgnoreCase(SLDTags.STROKE_DASHOFFSET_ATTR)) {
1226
//                                        TODO unsuported
1227
//                                        stroke.setDashOffset(parseCssParameter(child));
1228
                                }
1229
                        }
1230
                }
1231
        }
1232

    
1233
        private Color getColor(Node root) {
1234
                if ((root == null) || (root.getNodeType() != Node.ELEMENT_NODE)) {
1235
                        return null;
1236
                }
1237
                Node child = root;
1238

    
1239
                String childName = (child.getLocalName() != null) ? child
1240
                                .getLocalName() : child.getNodeName();
1241

    
1242
                if (childName.indexOf(':') != -1) {
1243
                        // the DOM parser wasnt properly set to handle namespaces...
1244
                        childName = childName.substring(childName.indexOf(':') + 1);
1245
                }
1246

    
1247
                if (childName.equalsIgnoreCase(SLDTags.CSSPARAMETER)) {
1248

    
1249
                        NodeList kidList = child.getChildNodes();
1250

    
1251
                        for (int i = 0; i < kidList.getLength(); i++) {
1252
                                Node kid = kidList.item(i);
1253

    
1254
                                if (kid == null) {
1255
                                        continue;
1256
                                }
1257
                                if (kid.getNodeValue().trim().length() == 0) {
1258
                                        continue;
1259
                                }
1260

    
1261
                                String nodeValue = kid.getNodeValue();
1262
                                System.out.println("Node value is: " + nodeValue);
1263
                                // see if it's an int
1264
                                return SLDUtils.convertHexStringToColor(nodeValue);
1265
                        }
1266
                }
1267

    
1268
                return null;
1269
        }
1270
}