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 / MarkElement.java @ 40799
History | View | Annotate | Download (3.06 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.SLDMark; |
9 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDFill; |
10 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDStroke; |
11 |
import org.kxml2.io.KXmlParser; |
12 |
import org.xmlpull.v1.XmlPullParser; |
13 |
import org.xmlpull.v1.XmlPullParserException; |
14 |
|
15 |
public class MarkElement { |
16 |
|
17 |
public static SLDMark parse(XmlPullParser parser , String version) |
18 |
throws XmlPullParserException, IOException, SLDReadException { |
19 |
|
20 |
parser.require(KXmlParser.START_TAG, null, SLDTags.MARK);
|
21 |
int tag = 0; |
22 |
|
23 |
SLDMark resp = new SLDMark();
|
24 |
|
25 |
tag = parser.nextTag(); |
26 |
String name = parser.getName();
|
27 |
String txt = null; |
28 |
while (!(SLDUtils.isStr(name, SLDTags.MARK) && tag == KXmlParser.END_TAG)) {
|
29 |
|
30 |
switch (tag) {
|
31 |
case KXmlParser.START_TAG:
|
32 |
if (SLDUtils.isStr(name, SLDTags.WELLKNOWNNAME)) {
|
33 |
txt = parser.nextText(); |
34 |
resp.setMarkType(SLDMark.MARK_TYPE_WELL_KNOWN_NAME); |
35 |
resp.setWellKnownName(txt); |
36 |
parser.nextTag(); |
37 |
break;
|
38 |
} |
39 |
if (SLDUtils.isStr(name, SLDTags.ONLINE_RESOURCE)) {
|
40 |
// xlink:href="http://somesite.com/something.xml"
|
41 |
txt = parser.getAttributeValue(null, SLDTags.XLINK_HREF);
|
42 |
if (txt == null) { |
43 |
throw new SLDReadException("URL not found (xlink:href att is missing) in online resource entity"); |
44 |
} |
45 |
resp.setOnlineResource(txt); |
46 |
resp.setMarkType(SLDMark.MARK_TYPE_ONLINE_RESOURCE); |
47 |
resp.setOnlineResource(txt); |
48 |
parser.nextTag(); |
49 |
parser.nextTag(); |
50 |
break;
|
51 |
} |
52 |
if (SLDUtils.isStr(name, SLDTags.INLINE_CONTENT)) {
|
53 |
/*
|
54 |
* This is unlikely to work if content is binary
|
55 |
*/
|
56 |
txt = parser.nextText(); |
57 |
resp.setMarkType(SLDMark.MARK_TYPE_INLINE_CONTENT); |
58 |
resp.setInlineContent(txt.getBytes()); |
59 |
parser.nextTag(); |
60 |
break;
|
61 |
} |
62 |
if (SLDUtils.isStr(name, SLDTags.FORMAT)) {
|
63 |
txt = parser.nextText(); |
64 |
resp.setFormat(txt); |
65 |
parser.nextTag(); |
66 |
break;
|
67 |
} |
68 |
if (SLDUtils.isStr(name, SLDTags.MARK_INDEX)) {
|
69 |
txt = parser.nextText(); |
70 |
int ind = SLDUtils.parseInteger(txt);
|
71 |
resp.setMarkIndex(ind); |
72 |
parser.nextTag(); |
73 |
break;
|
74 |
} |
75 |
// =============================================
|
76 |
if (SLDUtils.isStr(name, SLDTags.FILL)) {
|
77 |
SLDFill fil = FillElement.parse(parser, version); |
78 |
resp.setFill(fil); |
79 |
break;
|
80 |
} |
81 |
if (SLDUtils.isStr(name, SLDTags.STROKE)) {
|
82 |
SLDStroke stro = StrokeElement.parse(parser, version); |
83 |
resp.setStroke(stro); |
84 |
break;
|
85 |
} |
86 |
/*
|
87 |
* Any other entity causes parsing error
|
88 |
*/
|
89 |
throw new SLDReadException( |
90 |
"Bad SLD file. Unexpected entity in Mark: " + name);
|
91 |
case KXmlParser.END_TAG:
|
92 |
break;
|
93 |
case KXmlParser.TEXT:
|
94 |
break;
|
95 |
} |
96 |
tag = parser.getEventType(); |
97 |
name = parser.getName(); |
98 |
} |
99 |
|
100 |
parser.nextTag(); |
101 |
return resp;
|
102 |
} |
103 |
} |