Statistics
| Revision:

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

History | View | Annotate | Download (37.9 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.SymbologyFactory;
37
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
38
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
39
import com.iver.cit.gvsig.fmap.rendering.FInterval;
40
import com.iver.cit.gvsig.fmap.rendering.ILegend;
41
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
42
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
43
import com.iver.cit.gvsig.fmap.rendering.IVectorialLegend;
44
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
45
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.BetweenFilter;
46
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.CompareFilter;
47
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.FidFilter;
48
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.Filter;
49
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.GeometryDistanceFilter;
50
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.GeometryFilter;
51
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.LikeFilter;
52
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.LogicFilter;
53
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.filters.NullFilter;
54

    
55

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

    
60
        private InputSource source;
61

    
62
        private Document dom;
63

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

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

    
84
        }
85
        public static IVectorialLegend sld2gvl(File file) {
86

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

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

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

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

    
150
                IVectorialLegend[] legends = new IVectorialLegend[nodes.getLength()];
151

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

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

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

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

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

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

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

    
193
                return legend;
194
        }
195

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

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

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

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

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

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

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

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

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

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

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

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

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

    
284
                                                        CompareFilter cf = (CompareFilter) f;
285
                                                        ((VectorialIntervalLegend) vl).setFieldNames(new String[] {cf
286
                                                                        .getLeftValue().toString()});
287

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
469
                return rule;
470
        }
471

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

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

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

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

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

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

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

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

    
521

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

    
531
                }
532
                return text;
533
        }
534

    
535

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

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

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

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

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

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

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

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

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

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

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

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

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

    
597
                return point;
598
        }
599

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

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

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

    
621
                        Node sibling = fidElement.getNextSibling();
622

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

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

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

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

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

    
657
                        Node value = child.getFirstChild();
658

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
732
                        NamedNodeMap kids = child.getAttributes();
733

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
893
                        NodeList kidList = child.getChildNodes();
894

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

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

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

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

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

    
935
                return null;
936

    
937
        }
938

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

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

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

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

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

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

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

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

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

    
991
                return polygon;
992
        }
993

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1194
                                }
1195

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

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

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

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

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

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

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

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

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

    
1250
                        NodeList kidList = child.getChildNodes();
1251

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

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

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

    
1269
                return null;
1270
        }
1271
}