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 / LegendGraphicElement.java @ 46
History | View | Annotate | Download (3.69 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.SLDGraphic; |
40 |
import org.gvsig.sldsupport.sld.graphic.SLDLegendGraphic; |
41 |
|
42 |
public class LegendGraphicElement { |
43 |
|
44 |
public static void append(SLDLegendGraphic obj, XmlBuilder xb, |
45 |
String version) throws InvalidSLDObjectException, |
46 |
UnsupportedSLDObjectException { |
47 |
|
48 |
if (obj.getGraphic() == null) { |
49 |
throw new InvalidSLDObjectException(SLDTags.LEGENDGRAPHIC, |
50 |
"No Graphic found");
|
51 |
} |
52 |
xb.openTag(SLDTags.LEGENDGRAPHIC); |
53 |
// ==================================
|
54 |
GraphicElement.append(obj.getGraphic(), xb, version); |
55 |
// ==================================
|
56 |
xb.closeTag(); |
57 |
} |
58 |
|
59 |
public static SLDLegendGraphic parse(XmlPullParser parser, String version) |
60 |
throws XmlPullParserException, IOException, SLDReadException { |
61 |
|
62 |
parser.require(XmlPullParser.START_TAG, null, SLDTags.LEGENDGRAPHIC);
|
63 |
int tag = 0; |
64 |
|
65 |
SLDLegendGraphic resp = new SLDLegendGraphic();
|
66 |
|
67 |
tag = parser.nextTag(); |
68 |
String name = parser.getName();
|
69 |
String txt = null; |
70 |
while (!(SLDUtils.isStr(name, SLDTags.LEGENDGRAPHIC) && (tag == XmlPullParser.END_TAG))) {
|
71 |
|
72 |
switch (tag) {
|
73 |
case XmlPullParser.START_TAG:
|
74 |
if (SLDUtils.isStr(name, SLDTags.GRAPHIC)) {
|
75 |
SLDGraphic gra = GraphicElement.parse(parser, version); |
76 |
resp.setGraphic(gra); |
77 |
break;
|
78 |
} |
79 |
/*
|
80 |
* Any other entity causes parsing error
|
81 |
*/
|
82 |
throw new SLDReadException( |
83 |
"Bad SLD file. Unexpected entity in legend graphic: "
|
84 |
+ name); |
85 |
case XmlPullParser.END_TAG:
|
86 |
break;
|
87 |
case XmlPullParser.TEXT:
|
88 |
break;
|
89 |
} |
90 |
tag = parser.getEventType(); |
91 |
name = parser.getName(); |
92 |
} |
93 |
|
94 |
parser.nextTag(); |
95 |
return resp;
|
96 |
} |
97 |
} |