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 / ParameterValueElement.java @ 46
History | View | Annotate | Download (3.79 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 |
import java.util.List; |
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.expression.ExpressionElement; |
38 |
import org.gvsig.sldsupport.impl.util.SLDUtils; |
39 |
import org.gvsig.sldsupport.impl.util.XmlBuilder; |
40 |
import org.gvsig.sldsupport.sld.filter.expression.SLDExpression; |
41 |
import org.gvsig.sldsupport.sld.filter.expression.operator.SLDLiteral; |
42 |
import org.gvsig.sldsupport.sld.symbol.misc.SLDParameterValue; |
43 |
|
44 |
/**
|
45 |
* Used to parse a parameter value inside another entity
|
46 |
*
|
47 |
* @author jldominguez
|
48 |
*
|
49 |
*/
|
50 |
public class ParameterValueElement { |
51 |
|
52 |
public static void append(String entName, SLDParameterValue obj, |
53 |
XmlBuilder xb, String version) throws InvalidSLDObjectException, |
54 |
UnsupportedSLDObjectException { |
55 |
|
56 |
xb.openTag(entName); |
57 |
// =======================================
|
58 |
List<SLDExpression> list = obj.getExpressionList();
|
59 |
for (int i = 0; i < list.size(); i++) { |
60 |
ExpressionElement.append(list.get(i), xb, version); |
61 |
} |
62 |
// =======================================
|
63 |
xb.closeTag(); |
64 |
} |
65 |
|
66 |
public static SLDParameterValue parse(XmlPullParser parser, String version) |
67 |
throws XmlPullParserException, IOException, SLDReadException { |
68 |
|
69 |
String ent_name = parser.getName();
|
70 |
SLDParameterValue resp = new SLDParameterValue();
|
71 |
|
72 |
String txt = SLDUtils.getTextUntilTag(parser);
|
73 |
int tag = parser.getEventType();
|
74 |
String name = parser.getName();
|
75 |
if (SLDUtils.isStr(name, ent_name) && (tag == XmlPullParser.END_TAG)) {
|
76 |
SLDLiteral lit = new SLDLiteral();
|
77 |
lit.setValue(txt); |
78 |
parser.nextTag(); // move to next entity
|
79 |
resp.getExpressionList().add(lit); |
80 |
return resp;
|
81 |
} |
82 |
|
83 |
/*
|
84 |
* If not raw literal, parse the expression
|
85 |
*/
|
86 |
SLDExpression expre = null;
|
87 |
name = parser.getName(); |
88 |
while (!(SLDUtils.isStr(name, ent_name) && (tag == XmlPullParser.END_TAG))) {
|
89 |
expre = ExpressionElement.parse(parser, version); |
90 |
resp.getExpressionList().add(expre); |
91 |
// =========== Get current values
|
92 |
tag = parser.getEventType(); |
93 |
name = parser.getName(); |
94 |
} |
95 |
parser.nextTag(); |
96 |
return resp;
|
97 |
} |
98 |
} |