gvsig-sldtools / org.gvsig.sld / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.impl / src / main / java / org / gvsig / sldsupport / impl / sld / parsing / symbol / PointSymbolElement.java @ 46
History | View | Annotate | Download (4.85 KB)
1 |
/*******************************************************************************
|
---|---|
2 |
*
|
3 |
* gvSIG. Desktop Geographic Information System.
|
4 |
*
|
5 |
* Copyright (C) 2007-2013 gvSIG Association.
|
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or
|
8 |
* modify it under the terms of the GNU General Public License
|
9 |
* as published by the Free Software Foundation; either version 3
|
10 |
* of the License, or (at your option) any later version.
|
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License
|
18 |
* along with this program; if not, write to the Free Software
|
19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
20 |
* MA 02110-1301, USA.
|
21 |
*
|
22 |
* For any additional information, do not hesitate to contact us
|
23 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
24 |
*
|
25 |
*******************************************************************************/
|
26 |
package org.gvsig.sldsupport.impl.sld.parsing.symbol; |
27 |
|
28 |
import java.io.IOException; |
29 |
import java.util.Map; |
30 |
|
31 |
import org.xmlpull.v1.XmlPullParser; |
32 |
import org.xmlpull.v1.XmlPullParserException; |
33 |
|
34 |
import org.gvsig.sldsupport.exception.InvalidSLDObjectException; |
35 |
import org.gvsig.sldsupport.exception.SLDReadException; |
36 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
37 |
import org.gvsig.sldsupport.impl.sld.parsing.GeometryElement; |
38 |
import org.gvsig.sldsupport.impl.sld.parsing.GraphicElement; |
39 |
import org.gvsig.sldsupport.impl.util.SLDUtils; |
40 |
import org.gvsig.sldsupport.impl.util.XmlBuilder; |
41 |
import org.gvsig.sldsupport.sld.SLDTags; |
42 |
import org.gvsig.sldsupport.sld.graphic.SLDGraphic; |
43 |
import org.gvsig.sldsupport.sld.symbol.SLDPointSymbol; |
44 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDGeometry; |
45 |
|
46 |
/**
|
47 |
* Used to parse a parameter value inside another entity
|
48 |
*
|
49 |
* @author jldominguez
|
50 |
*
|
51 |
*/
|
52 |
public class PointSymbolElement { |
53 |
|
54 |
public static void append(SLDPointSymbol obj, XmlBuilder xb, |
55 |
Map<String, String> atts) throws InvalidSLDObjectException, |
56 |
UnsupportedSLDObjectException { |
57 |
|
58 |
String v = obj.getVersion();
|
59 |
if ((v == null) && (atts != null)) { |
60 |
v = atts.get(SLDTags.VERSION_ATTR); |
61 |
} |
62 |
if (v == null) { |
63 |
v = SLDUtils.DEFAULT_VERSION; |
64 |
} |
65 |
|
66 |
String ent = ""; |
67 |
if (v.compareToIgnoreCase(SLDUtils.VERSION_1_0_0) == 0) { |
68 |
ent = SLDTags.POINTSYMBOLIZER; |
69 |
} else {
|
70 |
ent = SLDTags.POINTSYMBOL; |
71 |
} |
72 |
|
73 |
if (atts == null) { |
74 |
xb.openTag(ent); |
75 |
} else {
|
76 |
xb.openTag(ent, atts); |
77 |
} |
78 |
// ==================================================
|
79 |
String geoName = obj.getGeometryPropertyName();
|
80 |
if (geoName != null) { |
81 |
GeometryElement.append(new SLDGeometry(geoName), xb, v);
|
82 |
} |
83 |
// =================
|
84 |
SLDGraphic gra = obj.getGraphic(); |
85 |
if (gra != null) { |
86 |
GraphicElement.append(gra, xb, v); |
87 |
} |
88 |
// ==================================================
|
89 |
xb.closeTag(); |
90 |
} |
91 |
|
92 |
public static SLDPointSymbol parse(XmlPullParser parser, String version) |
93 |
throws XmlPullParserException, IOException, SLDReadException { |
94 |
|
95 |
String ent_name = parser.getName();
|
96 |
SLDPointSymbol resp = new SLDPointSymbol();
|
97 |
resp.setVersion(version); |
98 |
int tag = 0; |
99 |
|
100 |
tag = parser.nextTag(); |
101 |
String name = parser.getName();
|
102 |
String txt = null; |
103 |
while (!(SLDUtils.isStr(name, ent_name) && (tag == XmlPullParser.END_TAG))) {
|
104 |
|
105 |
switch (tag) {
|
106 |
case XmlPullParser.START_TAG:
|
107 |
if (SLDUtils.isStr(name, SLDTags.GEOMETRY)) {
|
108 |
SLDGeometry geom = GeometryElement.parse(parser, version); |
109 |
resp.setGeometryPropertyName(geom.getPropertyName()); |
110 |
break;
|
111 |
} |
112 |
if (SLDUtils.isStr(name, SLDTags.GRAPHIC)) {
|
113 |
SLDGraphic gr = GraphicElement.parse(parser, version); |
114 |
resp.setGraphic(gr); |
115 |
break;
|
116 |
} |
117 |
/*
|
118 |
* Any other entity causes parsing error
|
119 |
*/
|
120 |
throw new SLDReadException( |
121 |
"Bad SLD file. Unexpected entity in point symbol: " + name);
|
122 |
case XmlPullParser.END_TAG:
|
123 |
break;
|
124 |
case XmlPullParser.TEXT:
|
125 |
break;
|
126 |
} |
127 |
tag = parser.getEventType(); |
128 |
name = parser.getName(); |
129 |
} |
130 |
|
131 |
parser.nextTag(); |
132 |
return resp;
|
133 |
|
134 |
} |
135 |
} |