svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / temp / org.gvsig.sldsupport.lib.impl / src / main / java / org / gvsig / sldsupport / impl / sld1_0_0 / parsing / FillElement.java @ 40799
History | View | Annotate | Download (2.42 KB)
1 |
package org.gvsig.sldsupport.impl.sld1_0_0.parsing; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.sldsupport.exception.SLDReadException; |
6 |
import org.gvsig.sldsupport.impl.util.SLDUtils; |
7 |
import org.gvsig.sldsupport.sld.SLDTags; |
8 |
import org.gvsig.sldsupport.sld.graphic.SLDGraphicFill; |
9 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDFill; |
10 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDSvgCssParameter; |
11 |
import org.kxml2.io.KXmlParser; |
12 |
import org.xmlpull.v1.XmlPullParser; |
13 |
import org.xmlpull.v1.XmlPullParserException; |
14 |
|
15 |
public class FillElement { |
16 |
|
17 |
public static SLDFill parse(XmlPullParser parser , String version) |
18 |
throws XmlPullParserException, IOException, SLDReadException { |
19 |
|
20 |
parser.require(KXmlParser.START_TAG, null, SLDTags.FILL);
|
21 |
int tag = 0; |
22 |
|
23 |
SLDFill resp = new SLDFill();
|
24 |
|
25 |
tag = parser.nextTag(); |
26 |
String name = parser.getName();
|
27 |
String txt = null; |
28 |
String attName = null; |
29 |
while (!(SLDUtils.isStr(name, SLDTags.FILL) && tag == KXmlParser.END_TAG)) {
|
30 |
|
31 |
switch (tag) {
|
32 |
case KXmlParser.START_TAG:
|
33 |
if (SLDUtils.isStr(name, SLDTags.GRAPHICFILL)) {
|
34 |
SLDGraphicFill gf = GraphicFillElement.parse(parser, version); |
35 |
/*
|
36 |
* SLDFill has a 'fillGraphic' field which is a Graphic,
|
37 |
* it does not have a field of FillGraphic type which
|
38 |
* has a graphic (we are collapsing an element)
|
39 |
*/
|
40 |
resp.setFillGraphic(gf.getGraphic()); |
41 |
break;
|
42 |
} |
43 |
if (SLDUtils.isStr(name, SLDTags.CSSPARAMETER)
|
44 |
|| SLDUtils.isStr(name, SLDTags.SVGPARAMETER)) { |
45 |
|
46 |
SLDSvgCssParameter sp = SvgCssParameterElement.parse(parser, version); |
47 |
if (SLDUtils.isStr(sp.getName(), SLDTags.FILL_ATTR)) {
|
48 |
if (sp.getExpressionList().size() > 0) { |
49 |
// Using first item only
|
50 |
resp.setFillColor(sp.getExpressionList().get(0));
|
51 |
} |
52 |
} else {
|
53 |
if (SLDUtils.isStr(sp.getName(), SLDTags.FILLOPACITY_ATTR)) {
|
54 |
if (sp.getExpressionList().size() > 0) { |
55 |
// Using first item only
|
56 |
resp.setOpacity(sp.getExpressionList().get(0));
|
57 |
} |
58 |
} |
59 |
} |
60 |
break;
|
61 |
} |
62 |
/*
|
63 |
* Any other entity causes parsing error
|
64 |
*/
|
65 |
throw new SLDReadException( |
66 |
"Bad SLD file. Unexpected entity in fill element: " + name);
|
67 |
case KXmlParser.END_TAG:
|
68 |
break;
|
69 |
case KXmlParser.TEXT:
|
70 |
break;
|
71 |
} |
72 |
tag = parser.getEventType(); |
73 |
name = parser.getName(); |
74 |
} |
75 |
|
76 |
parser.nextTag(); |
77 |
return resp;
|
78 |
} |
79 |
} |