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 / expression / FunctionElement.java @ 46
History | View | Annotate | Download (3.47 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.expression; |
27 |
|
28 |
import java.io.IOException; |
29 |
import java.util.HashMap; |
30 |
import java.util.Map; |
31 |
|
32 |
import org.xmlpull.v1.XmlPullParser; |
33 |
import org.xmlpull.v1.XmlPullParserException; |
34 |
|
35 |
import org.gvsig.sldsupport.exception.InvalidSLDObjectException; |
36 |
import org.gvsig.sldsupport.exception.SLDReadException; |
37 |
import org.gvsig.sldsupport.exception.UnsupportedSLDObjectException; |
38 |
import org.gvsig.sldsupport.impl.util.SLDUtils; |
39 |
import org.gvsig.sldsupport.impl.util.XmlBuilder; |
40 |
import org.gvsig.sldsupport.sld.SLDTags; |
41 |
import org.gvsig.sldsupport.sld.filter.FilterTags; |
42 |
import org.gvsig.sldsupport.sld.filter.expression.SLDExpression; |
43 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDFunction; |
44 |
|
45 |
public class FunctionElement { |
46 |
|
47 |
public static void append(SLDFunction obj, XmlBuilder xb, String version) |
48 |
throws InvalidSLDObjectException, UnsupportedSLDObjectException {
|
49 |
|
50 |
Map<String, String> atts = new HashMap<String, String>(); |
51 |
atts.put(SLDTags.NAME_ATTR, obj.getFunctionName()); |
52 |
|
53 |
xb.openTag(FilterTags.FUNCTION, atts); |
54 |
for (int i = 0; i < obj.getArguments().size(); i++) { |
55 |
ExpressionElement.append(obj.getArguments().get(i), xb, version); |
56 |
} |
57 |
xb.closeTag(); |
58 |
} |
59 |
|
60 |
public static SLDFunction parse(XmlPullParser parser, String version) |
61 |
throws XmlPullParserException, IOException, SLDReadException { |
62 |
|
63 |
parser.require(XmlPullParser.START_TAG, null, FilterTags.FUNCTION);
|
64 |
String fname = parser.getAttributeValue(null, SLDTags.NAME_ATTR); |
65 |
if (fname == null) { |
66 |
throw new SLDReadException( |
67 |
"Attribute 'name' not found in SLD function");
|
68 |
} |
69 |
SLDFunction resp = new SLDFunction();
|
70 |
resp.setFunctionName(fname); |
71 |
|
72 |
int tag = parser.nextTag();
|
73 |
String name = parser.getName();
|
74 |
SLDExpression expre = null;
|
75 |
|
76 |
while (!(SLDUtils.isStr(name, SLDTags.FUNCTION) && (tag == XmlPullParser.END_TAG))) {
|
77 |
expre = ExpressionElement.parse(parser, version); |
78 |
resp.getArguments().add(expre); |
79 |
// =========== Get current values
|
80 |
tag = parser.getEventType(); |
81 |
name = parser.getName(); |
82 |
} |
83 |
parser.nextTag(); |
84 |
return resp;
|
85 |
} |
86 |
} |