svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / org.gvsig.sldsupport / org.gvsig.sldsupport.lib / org.gvsig.sldsupport.lib.api / src / main / java / org / gvsig / sldsupport / filterencoding / Filter.java @ 40754
History | View | Annotate | Download (9.12 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Ib��ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* IVER T.I. S.A
|
35 |
* Salamanca 50
|
36 |
* 46005 Valencia
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 963163400
|
40 |
* dac@iver.es
|
41 |
*/
|
42 |
package org.gvsig.sldsupport.filterencoding; |
43 |
|
44 |
|
45 |
import java.io.IOException; |
46 |
import java.util.ArrayList; |
47 |
import java.util.HashSet; |
48 |
import java.util.Set; |
49 |
|
50 |
import org.gvsig.sldsupport.exception.SLDReadException; |
51 |
import org.gvsig.sldsupport.symbolizer.ISLDSymbolizer; |
52 |
import org.xmlpull.v1.XmlPullParser; |
53 |
import org.xmlpull.v1.XmlPullParserException; |
54 |
|
55 |
|
56 |
|
57 |
/**
|
58 |
* Implements the main class expresion where the parsing of a Filter
|
59 |
* Encoding expression starts<br>
|
60 |
*
|
61 |
* A filter is any valid predicate expression that can be formed using the
|
62 |
* elements defined in the Filter Encoding specification. The root element
|
63 |
* <Filter> contains the expression whichis created by combining the elements
|
64 |
* defined in this specification
|
65 |
*
|
66 |
* @see http://www.opengeospatial.org/standards/filter
|
67 |
* @author pepe vidal salvador - jose.vidal.salvador@iver.es
|
68 |
*/
|
69 |
public class Filter { |
70 |
|
71 |
FComparisonOperator compOperator = null;
|
72 |
FLogicOperator logicOperators = null;
|
73 |
FLogicOperatorNot notLogicOperator = null;
|
74 |
FIsBetweenOperator isBetweenOperator = null;
|
75 |
FIsNullOperator isNullOperator = null;
|
76 |
FIsLikeOperator isLikeOperator = null;
|
77 |
// FBinSpatialOperator binSpatialOperator = null;
|
78 |
String expression = ""; |
79 |
|
80 |
Set <String> fieldNames = new HashSet <String>(); |
81 |
ArrayList<ISLDSymbolizer> symbolizers = new ArrayList<ISLDSymbolizer>(); |
82 |
|
83 |
|
84 |
public void parse(XmlPullParser parser) |
85 |
throws XmlPullParserException, IOException, SLDReadException { |
86 |
|
87 |
int currentTag;
|
88 |
boolean end = false; |
89 |
currentTag = parser.next(); |
90 |
|
91 |
expression = "( ";
|
92 |
|
93 |
while (!end)
|
94 |
{ |
95 |
switch(currentTag)
|
96 |
{ |
97 |
// case IXmlStreamReader..START_TAG:
|
98 |
case XmlPullParser.START_TAG:
|
99 |
if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISEQUALTO)) ==0 || |
100 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISNOTEQUALTO)) ==0 ||
|
101 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISLESSTHAN)) ==0 ||
|
102 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISGREATERTHAN)) ==0 ||
|
103 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISLESSOREQUALTHAN)) ==0 ||
|
104 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISGREATEROREQUALTHAN)) ==0) {
|
105 |
|
106 |
if(parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISEQUALTO)) !=0 && |
107 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISNOTEQUALTO)) !=0 ){
|
108 |
|
109 |
} |
110 |
|
111 |
compOperator = new FComparisonOperator();
|
112 |
expression += "( ";
|
113 |
compOperator.parse(parser ,parser.getName()); |
114 |
expression += compOperator.getOpExpressionStr(); |
115 |
|
116 |
expression+= ") ";
|
117 |
|
118 |
fieldNames.addAll(compOperator.getFieldNames()); |
119 |
|
120 |
|
121 |
} |
122 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.AND)) ==0 || |
123 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.OR)) ==0){
|
124 |
logicOperators = new FLogicOperator();
|
125 |
|
126 |
expression += "( ";
|
127 |
logicOperators.parse(parser,parser.getName()); |
128 |
|
129 |
if (logicOperators.getNumOperators() < 2) { |
130 |
throw new SLDReadException(new Exception( |
131 |
"Found " + logicOperators.getNumOperators()
|
132 |
+ " operators, expected 2."));
|
133 |
} |
134 |
|
135 |
expression += logicOperators.getOpExpressionStr(); |
136 |
expression += ") ";
|
137 |
fieldNames.addAll(logicOperators.getFieldNames()); |
138 |
|
139 |
|
140 |
} |
141 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.NOT)) ==0) { |
142 |
notLogicOperator = new FLogicOperatorNot();
|
143 |
|
144 |
expression += "( "+"! "; |
145 |
notLogicOperator.parse(parser,parser.getName()); |
146 |
|
147 |
if (notLogicOperator.getNumOperators() > 1) { |
148 |
throw new SLDReadException(new Exception( |
149 |
"Found " + notLogicOperator.getNumOperators()
|
150 |
+ " operators, expected 1."));
|
151 |
} |
152 |
|
153 |
expression += notLogicOperator.getOpExpressionStr(); |
154 |
expression += ") ";
|
155 |
fieldNames.addAll(notLogicOperator.getFieldNames()); |
156 |
|
157 |
} |
158 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISBETWEEN)) == 0) { |
159 |
isBetweenOperator = new FIsBetweenOperator();
|
160 |
expression += "( Ib ( ";
|
161 |
isBetweenOperator.parse(parser, currentTag, parser.getName()); |
162 |
|
163 |
if(isBetweenOperator.getInsideExpression()==null || isBetweenOperator.getLowerBoundary()==null |
164 |
|| isBetweenOperator.getUpperBoundary()==null) {
|
165 |
throw new SLDReadException(new Exception( |
166 |
"Bad parameters in is-between operator."));
|
167 |
} |
168 |
|
169 |
expression += isBetweenOperator.getInExpressionStr()+","+isBetweenOperator.getLoExpressionStr()+
|
170 |
","+isBetweenOperator.getUpExpressionStr();
|
171 |
expression += ") ) ";
|
172 |
} |
173 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISNULL)) == 0) { |
174 |
isNullOperator = new FIsNullOperator();
|
175 |
expression += "( INull ";
|
176 |
isNullOperator.parse(parser, currentTag, parser.getName()); |
177 |
|
178 |
if(isNullOperator.getPropName()==null) { |
179 |
throw new SLDReadException(new Exception( |
180 |
"Bad or missing name in is-null operator."));
|
181 |
} |
182 |
|
183 |
expression += isNullOperator.getOpExpressionStr(); |
184 |
expression += ") ";
|
185 |
} |
186 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISLIKE)) == 0) { |
187 |
isLikeOperator = new FIsLikeOperator();
|
188 |
expression += "( IL ( ";
|
189 |
String wild =parser.getAttributeValue("", FilterTags.WILDCHAR); |
190 |
String single = parser.getAttributeValue("",FilterTags.SINGLECHAR); |
191 |
String scape = parser.getAttributeValue("", FilterTags.ESCAPECHAR); |
192 |
expression += "( "+wild+" , "+single+" , "+scape+" ) , "; |
193 |
isLikeOperator.parse(parser, currentTag, parser.getName()); |
194 |
|
195 |
if(isLikeOperator.getLiteral()==null || isLikeOperator.getPropName()==null) { |
196 |
throw new SLDReadException(new Exception( |
197 |
"Bad name or literal in is-like operator."));
|
198 |
} |
199 |
|
200 |
expression += "( "+isLikeOperator.getPropName()+" , "+isLikeOperator.getLiteral()+" ) "; |
201 |
expression += ") ) ";
|
202 |
} |
203 |
// else if (parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.EQUALS)) ==0 ||
|
204 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.DISJOINT)) == 0 ||
|
205 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.TOUCHES)) == 0 ||
|
206 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.WITHIN)) == 0 ||
|
207 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.OVERLAPS)) == 0 ||
|
208 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.CROSSES)) == 0 ||
|
209 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.INTERSECTS)) == 0 ||
|
210 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.CONTAINS)) == 0) {
|
211 |
|
212 |
// String func = parser.getName();
|
213 |
|
214 |
// binSpatialOperator = new FBinSpatialOperator();
|
215 |
// expression += "( "+func+" ";
|
216 |
// binSpatialOperator.parse(parser, currentTag, parser.getName());
|
217 |
|
218 |
// if(binSpatialOperator.getPropertyName()==null)
|
219 |
// throw new Error ("binSpatialOperator mal!");
|
220 |
|
221 |
// expression += binSpatialOperator.getOpExpressionStr();
|
222 |
// expression += ") ";
|
223 |
|
224 |
// }
|
225 |
break;
|
226 |
case XmlPullParser.END_TAG:
|
227 |
if (parser.getName().compareTo(
|
228 |
FilterUtils.remNameSpace(FilterTags.FILTER)) == 0)
|
229 |
end = true;
|
230 |
break;
|
231 |
case XmlPullParser.TEXT:
|
232 |
break;
|
233 |
} |
234 |
if (!end)
|
235 |
currentTag = parser.next(); |
236 |
} |
237 |
|
238 |
expression += ") ";
|
239 |
} |
240 |
|
241 |
public Set<String> getFieldNames() { return fieldNames; } |
242 |
public void addSymbolizer2Filter(ISLDSymbolizer symbol) { symbolizers.add(symbol); } |
243 |
public ArrayList<ISLDSymbolizer> getSymbolizers() { return symbolizers; } |
244 |
|
245 |
public FComparisonOperator getCompOperator() {return compOperator;} |
246 |
public FLogicOperator getLogicOperator() {return logicOperators;} |
247 |
public FLogicOperatorNot getNotLogicOperator() {return notLogicOperator;} |
248 |
public String getExpression() {return this.expression;} |
249 |
|
250 |
|
251 |
|
252 |
} |