svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / temp / org.gvsig.sldsupport.lib.api / src / main / java / org / gvsig / sldsupport / filterencoding / FExpression.java @ 40779
History | View | Annotate | Download (6.57 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.sldsupport.filterencoding; |
42 |
|
43 |
import java.io.IOException; |
44 |
import java.util.HashSet; |
45 |
import java.util.Set; |
46 |
|
47 |
import org.gvsig.sldsupport.exception.SLDReadException; |
48 |
import org.gvsig.sldsupport.util.SLDUtils; |
49 |
import org.xmlpull.v1.XmlPullParser; |
50 |
import org.xmlpull.v1.XmlPullParserException; |
51 |
|
52 |
/**
|
53 |
* Implements the main functionalities to parse an Filter Encoding
|
54 |
* expression<br>
|
55 |
* The expression element is an abstrac element which means that it
|
56 |
* does not really exist and its only purpose is to act as a placeholder
|
57 |
* for the elements and combinations of elements that can be used o form
|
58 |
* expressions.
|
59 |
*
|
60 |
* @see http://www.opengeospatial.org/standards/filter
|
61 |
* @author pepe vidal salvador - jose.vidal.salvador@iver.es
|
62 |
*/
|
63 |
public class FExpression { |
64 |
|
65 |
protected String literal; |
66 |
protected String propertyName; |
67 |
protected String function; |
68 |
protected String expressionType; |
69 |
protected FExpression insideExpression;
|
70 |
protected FExpression insideExpression2;
|
71 |
boolean isPropertyName = false; |
72 |
|
73 |
String expressionStr = ""; |
74 |
|
75 |
Set <String> fieldNames = new HashSet <String>(); |
76 |
|
77 |
double value;
|
78 |
|
79 |
|
80 |
public void parse(XmlPullParser parser, int Tag2, String expressionType) |
81 |
throws XmlPullParserException, IOException, SLDReadException { |
82 |
|
83 |
int currentTag;
|
84 |
boolean end = false; |
85 |
currentTag = Tag2; |
86 |
this.expressionType = expressionType;
|
87 |
|
88 |
while (!end)
|
89 |
{ |
90 |
switch(currentTag)
|
91 |
{ |
92 |
case XmlPullParser.START_TAG:
|
93 |
|
94 |
if (parser.getName().compareTo(
|
95 |
FilterUtils.remNameSpace(FilterTags.PROPERTYNAME))==0) {
|
96 |
this.propertyName = parser.nextText();
|
97 |
fieldNames.add(this.propertyName);
|
98 |
isPropertyName = true;
|
99 |
end = true;
|
100 |
expressionStr +="["+this.propertyName +"] "; |
101 |
} |
102 |
else if (parser.getName().compareTo( |
103 |
FilterUtils.remNameSpace(FilterTags.LITERAL))==0) {
|
104 |
this.literal = parser.nextText();
|
105 |
String myLiteral = this.literal; |
106 |
if (!this.literal.startsWith("#")) |
107 |
if (SLDUtils.isANumber(this.literal)) { |
108 |
setValue(Double.valueOf(this.literal)); |
109 |
} else {
|
110 |
/*
|
111 |
* Parche para leer las leyendas generadas con versiones anteriores que
|
112 |
* no pon?an comillas para identificar los literales
|
113 |
*/
|
114 |
if (!(this.literal.startsWith("\"") && this.literal.endsWith("\""))){ |
115 |
myLiteral = "\""+this.literal +"\""; |
116 |
} |
117 |
/* Fin del parche */
|
118 |
} |
119 |
end = true;
|
120 |
expressionStr += myLiteral +" ";
|
121 |
} |
122 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.FUNCTION))==0) { |
123 |
this.function = parser.nextText();
|
124 |
end = true;
|
125 |
} |
126 |
else if ((parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.ADD))==0) || |
127 |
(parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.DIV))==0) ||
|
128 |
(parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.MULT))==0) ||
|
129 |
(parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.SUB))==0) ){
|
130 |
|
131 |
String operation = parser.getName();
|
132 |
currentTag = parser.nextTag(); |
133 |
this.insideExpression = new FExpression(); |
134 |
expressionStr += "( ";
|
135 |
|
136 |
this.insideExpression.parse(parser,currentTag,parser.getName());
|
137 |
expressionStr += insideExpression.getExpressionStr(); |
138 |
|
139 |
expressionStr += FilterUtils.getSymbol4Expression("ogc:"+operation)+" "; |
140 |
|
141 |
fieldNames.addAll(insideExpression.getFieldNames()); |
142 |
currentTag = parser.nextTag(); |
143 |
this.insideExpression2 = new FExpression(); |
144 |
|
145 |
this.insideExpression2.parse(parser,currentTag,parser.getName());
|
146 |
expressionStr += insideExpression2.getExpressionStr(); |
147 |
|
148 |
expressionStr += ") ";
|
149 |
|
150 |
fieldNames.addAll(insideExpression2.getFieldNames()); |
151 |
parser.nextTag(); |
152 |
/*
|
153 |
if (insideExpression == null && insideExpression2 == null) {
|
154 |
}
|
155 |
*/
|
156 |
end = true;
|
157 |
} |
158 |
|
159 |
break;
|
160 |
case XmlPullParser.END_TAG:
|
161 |
if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYNAME))!=0 && |
162 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.LITERAL))!=0 &&
|
163 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.FUNCTION))!=0 &&
|
164 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.ADD))!=0 &&
|
165 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.DIV))!=0 &&
|
166 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.MULT))!=0 &&
|
167 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.SUB))!=0) {
|
168 |
end = true;
|
169 |
} |
170 |
break;
|
171 |
case XmlPullParser.TEXT:
|
172 |
break;
|
173 |
} |
174 |
if (!end)
|
175 |
currentTag = parser.next(); |
176 |
} |
177 |
|
178 |
} |
179 |
|
180 |
|
181 |
public String getLiteral() { return literal; } |
182 |
public void setLiteral(String literal) { |
183 |
this.literal = literal; }
|
184 |
public String getPropertyName() { return propertyName; } |
185 |
public void setPropertyName(String propertyName) { this.propertyName = propertyName; } |
186 |
public double evaluate() { return this.value; } |
187 |
public void setValue(double value) { this.value = value; } |
188 |
public Set<String> getFieldNames() { return fieldNames; } |
189 |
public boolean isPropertyName() {return isPropertyName;} |
190 |
public String getExpressionType() {return expressionType;} |
191 |
|
192 |
public FExpression getInsideExpression() {return insideExpression;} |
193 |
public FExpression getInsideExpression2() {return insideExpression2;} |
194 |
public String getExpressionStr() {return expressionStr;} |
195 |
|
196 |
} |