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 / DisplacementElement.java @ 46
History | View | Annotate | Download (3.9 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; |
27 |
|
28 |
import java.io.IOException; |
29 |
|
30 |
import org.xmlpull.v1.XmlPullParser; |
31 |
import org.xmlpull.v1.XmlPullParserException; |
32 |
|
33 |
import org.gvsig.sldsupport.exception.InvalidSLDObjectException; |
34 |
import org.gvsig.sldsupport.exception.SLDReadException; |
35 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
36 |
import org.gvsig.sldsupport.impl.util.SLDUtils; |
37 |
import org.gvsig.sldsupport.impl.util.XmlBuilder; |
38 |
import org.gvsig.sldsupport.sld.SLDTags; |
39 |
import org.gvsig.sldsupport.sld.graphic.SLDDisplacement; |
40 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDParameterValue; |
41 |
|
42 |
public class DisplacementElement { |
43 |
|
44 |
public static void append(SLDDisplacement obj, XmlBuilder xb, String version) |
45 |
throws InvalidSLDObjectException, UnsupportedSLDObjectException {
|
46 |
|
47 |
xb.openTag(SLDTags.DISPLACEMENT); |
48 |
ParameterValueElement.append(SLDTags.DISPLACEMENT_X, |
49 |
obj.getDisplacementX(), xb, version); |
50 |
ParameterValueElement.append(SLDTags.DISPLACEMENT_Y, |
51 |
obj.getDisplacementY(), xb, version); |
52 |
xb.closeTag(); |
53 |
} |
54 |
|
55 |
public static SLDDisplacement parse(XmlPullParser parser, String version) |
56 |
throws XmlPullParserException, IOException, SLDReadException { |
57 |
|
58 |
parser.require(XmlPullParser.START_TAG, null, SLDTags.DISPLACEMENT);
|
59 |
int tag = 0; |
60 |
|
61 |
SLDDisplacement resp = null;
|
62 |
|
63 |
tag = parser.nextTag(); |
64 |
String name = parser.getName();
|
65 |
String txt = null; |
66 |
while (!(SLDUtils.isStr(name, SLDTags.DISPLACEMENT) && (tag == XmlPullParser.END_TAG))) {
|
67 |
|
68 |
switch (tag) {
|
69 |
case XmlPullParser.START_TAG:
|
70 |
if (SLDUtils.isStr(name, SLDTags.DISPLACEMENT_X)) {
|
71 |
SLDParameterValue pv = |
72 |
ParameterValueElement.parse(parser, version); |
73 |
resp.setDisplacementX(pv); |
74 |
break;
|
75 |
} |
76 |
if (SLDUtils.isStr(name, SLDTags.DISPLACEMENT_Y)) {
|
77 |
SLDParameterValue pv = |
78 |
ParameterValueElement.parse(parser, version); |
79 |
resp.setDisplacementY(pv); |
80 |
break;
|
81 |
} |
82 |
/*
|
83 |
* Any other entity causes parsing error
|
84 |
*/
|
85 |
throw new SLDReadException( |
86 |
"Bad SLD file. Unexpected entity in displacement element: "
|
87 |
+ name); |
88 |
case XmlPullParser.END_TAG:
|
89 |
break;
|
90 |
case XmlPullParser.TEXT:
|
91 |
break;
|
92 |
} |
93 |
tag = parser.getEventType(); |
94 |
name = parser.getName(); |
95 |
} |
96 |
|
97 |
parser.nextTag(); |
98 |
return resp;
|
99 |
} |
100 |
} |