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 / FeatureTypeConstraintElement.java @ 46
History | View | Annotate | Download (4.5 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.constraints.SLDFeatureTypeConstraint; |
40 |
import org.gvsig.sldsupport.sld.extent.SLDExtent; |
41 |
|
42 |
public class FeatureTypeConstraintElement { |
43 |
|
44 |
public static void append(SLDFeatureTypeConstraint obj, XmlBuilder xb, |
45 |
String version) throws InvalidSLDObjectException, |
46 |
UnsupportedSLDObjectException { |
47 |
|
48 |
xb.openTag(SLDTags.FEATURETYPECONSTRAINT); |
49 |
// ========================
|
50 |
if (obj.getFeatureTypeName() != null) { |
51 |
xb.writeTag(SLDTags.FEATURETYPENAME, obj.getFeatureTypeName()); |
52 |
} |
53 |
// =========
|
54 |
if (obj.getFilter() != null) { |
55 |
// 0 or 1 filters
|
56 |
FilterElement.append(obj.getFilter(), xb, version); |
57 |
} |
58 |
// =========
|
59 |
for (int i = 0; i < obj.getExtents().size(); i++) { |
60 |
ExtentElement.append(obj.getExtents().get(i), xb, version); |
61 |
} |
62 |
// ========================
|
63 |
xb.closeTag(); |
64 |
} |
65 |
|
66 |
public static SLDFeatureTypeConstraint parse(XmlPullParser parser, |
67 |
String version) throws XmlPullParserException, IOException, |
68 |
SLDReadException { |
69 |
|
70 |
parser.require(XmlPullParser.START_TAG, null,
|
71 |
SLDTags.FEATURETYPECONSTRAINT); |
72 |
int tag = 0; |
73 |
|
74 |
SLDFeatureTypeConstraint resp = new SLDFeatureTypeConstraint();
|
75 |
|
76 |
tag = parser.nextTag(); |
77 |
String name = parser.getName();
|
78 |
String txt = null; |
79 |
while (!(SLDUtils.isStr(name, SLDTags.FEATURETYPECONSTRAINT) && (tag == XmlPullParser.END_TAG))) {
|
80 |
|
81 |
switch (tag) {
|
82 |
case XmlPullParser.START_TAG:
|
83 |
if (SLDUtils.isStr(name, SLDTags.FEATURETYPENAME)) {
|
84 |
txt = parser.nextText(); |
85 |
resp.setFeatureTypeName(txt); |
86 |
parser.nextTag(); |
87 |
break;
|
88 |
} |
89 |
if (SLDUtils.isStr(name, SLDTags.FILTER)) {
|
90 |
txt = parser.nextText(); |
91 |
resp.setFeatureTypeName(txt); |
92 |
parser.nextTag(); |
93 |
break;
|
94 |
} |
95 |
if (SLDUtils.isStr(name, SLDTags.EXTENT)) {
|
96 |
SLDExtent ext = ExtentElement.parse(parser, version); |
97 |
resp.getExtents().add(ext); |
98 |
break;
|
99 |
} |
100 |
/*
|
101 |
* Any other entity causes parsing error
|
102 |
*/
|
103 |
throw new SLDReadException( |
104 |
"Bad SLD file. Unexpected entity in featuretype constraints: "
|
105 |
+ name); |
106 |
case XmlPullParser.END_TAG:
|
107 |
break;
|
108 |
case XmlPullParser.TEXT:
|
109 |
break;
|
110 |
} |
111 |
tag = parser.getEventType(); |
112 |
name = parser.getName(); |
113 |
} |
114 |
|
115 |
parser.nextTag(); |
116 |
return resp;
|
117 |
} |
118 |
} |