svn-gvsig-desktop / branches / v02_desarrollo / libraries / sld / temp / org.gvsig.sldsupport.lib.api / src / main / java / org / gvsig / sldsupport / filterencoding / Filter.java @ 40779
History | View | Annotate | Download (9.15 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 |
public Filter() { |
84 |
|
85 |
} |
86 |
|
87 |
public void parse(XmlPullParser parser) |
88 |
throws XmlPullParserException, IOException, SLDReadException { |
89 |
|
90 |
int currentTag;
|
91 |
boolean end = false; |
92 |
currentTag = parser.next(); |
93 |
|
94 |
expression = "( ";
|
95 |
|
96 |
while (!end)
|
97 |
{ |
98 |
switch(currentTag)
|
99 |
{ |
100 |
// case IXmlStreamReader..START_TAG:
|
101 |
case XmlPullParser.START_TAG:
|
102 |
if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISEQUALTO)) ==0 || |
103 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISNOTEQUALTO)) ==0 ||
|
104 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISLESSTHAN)) ==0 ||
|
105 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISGREATERTHAN)) ==0 ||
|
106 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISLESSOREQUALTHAN)) ==0 ||
|
107 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISGREATEROREQUALTHAN)) ==0) {
|
108 |
|
109 |
if(parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISEQUALTO)) !=0 && |
110 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISNOTEQUALTO)) !=0 ){
|
111 |
|
112 |
} |
113 |
|
114 |
compOperator = new FComparisonOperator();
|
115 |
expression += "( ";
|
116 |
compOperator.parse(parser ,parser.getName()); |
117 |
expression += compOperator.getOpExpressionStr(); |
118 |
|
119 |
expression+= ") ";
|
120 |
|
121 |
fieldNames.addAll(compOperator.getFieldNames()); |
122 |
|
123 |
|
124 |
} |
125 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.AND)) ==0 || |
126 |
parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.OR)) ==0){
|
127 |
logicOperators = new FLogicOperator();
|
128 |
|
129 |
expression += "( ";
|
130 |
logicOperators.parse(parser,parser.getName()); |
131 |
|
132 |
if (logicOperators.getNumOperators() < 2) { |
133 |
throw new SLDReadException(new Exception( |
134 |
"Found " + logicOperators.getNumOperators()
|
135 |
+ " operators, expected 2."));
|
136 |
} |
137 |
|
138 |
expression += logicOperators.getOpExpressionStr(); |
139 |
expression += ") ";
|
140 |
fieldNames.addAll(logicOperators.getFieldNames()); |
141 |
|
142 |
|
143 |
} |
144 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.NOT)) ==0) { |
145 |
notLogicOperator = new FLogicOperatorNot();
|
146 |
|
147 |
expression += "( "+"! "; |
148 |
notLogicOperator.parse(parser,parser.getName()); |
149 |
|
150 |
if (notLogicOperator.getNumOperators() > 1) { |
151 |
throw new SLDReadException(new Exception( |
152 |
"Found " + notLogicOperator.getNumOperators()
|
153 |
+ " operators, expected 1."));
|
154 |
} |
155 |
|
156 |
expression += notLogicOperator.getOpExpressionStr(); |
157 |
expression += ") ";
|
158 |
fieldNames.addAll(notLogicOperator.getFieldNames()); |
159 |
|
160 |
} |
161 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISBETWEEN)) == 0) { |
162 |
isBetweenOperator = new FIsBetweenOperator();
|
163 |
expression += "( Ib ( ";
|
164 |
isBetweenOperator.parse(parser, currentTag, parser.getName()); |
165 |
|
166 |
if(isBetweenOperator.getInsideExpression()==null || isBetweenOperator.getLowerBoundary()==null |
167 |
|| isBetweenOperator.getUpperBoundary()==null) {
|
168 |
throw new SLDReadException(new Exception( |
169 |
"Bad parameters in is-between operator."));
|
170 |
} |
171 |
|
172 |
expression += isBetweenOperator.getInExpressionStr()+","+isBetweenOperator.getLoExpressionStr()+
|
173 |
","+isBetweenOperator.getUpExpressionStr();
|
174 |
expression += ") ) ";
|
175 |
} |
176 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISNULL)) == 0) { |
177 |
isNullOperator = new FIsNullOperator();
|
178 |
expression += "( INull ";
|
179 |
isNullOperator.parse(parser, currentTag, parser.getName()); |
180 |
|
181 |
if(isNullOperator.getPropName()==null) { |
182 |
throw new SLDReadException(new Exception( |
183 |
"Bad or missing name in is-null operator."));
|
184 |
} |
185 |
|
186 |
expression += isNullOperator.getOpExpressionStr(); |
187 |
expression += ") ";
|
188 |
} |
189 |
else if (parser.getName().compareTo(FilterUtils.remNameSpace(FilterTags.PROPERTYISLIKE)) == 0) { |
190 |
isLikeOperator = new FIsLikeOperator();
|
191 |
expression += "( IL ( ";
|
192 |
String wild =parser.getAttributeValue("", FilterTags.WILDCHAR); |
193 |
String single = parser.getAttributeValue("",FilterTags.SINGLECHAR); |
194 |
String scape = parser.getAttributeValue("", FilterTags.ESCAPECHAR); |
195 |
expression += "( "+wild+" , "+single+" , "+scape+" ) , "; |
196 |
isLikeOperator.parse(parser, currentTag, parser.getName()); |
197 |
|
198 |
if(isLikeOperator.getLiteral()==null || isLikeOperator.getPropName()==null) { |
199 |
throw new SLDReadException(new Exception( |
200 |
"Bad name or literal in is-like operator."));
|
201 |
} |
202 |
|
203 |
expression += "( "+isLikeOperator.getPropName()+" , "+isLikeOperator.getLiteral()+" ) "; |
204 |
expression += ") ) ";
|
205 |
} |
206 |
// else if (parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.EQUALS)) ==0 ||
|
207 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.DISJOINT)) == 0 ||
|
208 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.TOUCHES)) == 0 ||
|
209 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.WITHIN)) == 0 ||
|
210 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.OVERLAPS)) == 0 ||
|
211 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.CROSSES)) == 0 ||
|
212 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.INTERSECTS)) == 0 ||
|
213 |
// parser.getName().compareTo(FilterUtils. remNameSpace(FilterTags.CONTAINS)) == 0) {
|
214 |
|
215 |
// String func = parser.getName();
|
216 |
|
217 |
// binSpatialOperator = new FBinSpatialOperator();
|
218 |
// expression += "( "+func+" ";
|
219 |
// binSpatialOperator.parse(parser, currentTag, parser.getName());
|
220 |
|
221 |
// if(binSpatialOperator.getPropertyName()==null)
|
222 |
// throw new Error ("binSpatialOperator mal!");
|
223 |
|
224 |
// expression += binSpatialOperator.getOpExpressionStr();
|
225 |
// expression += ") ";
|
226 |
|
227 |
// }
|
228 |
break;
|
229 |
case XmlPullParser.END_TAG:
|
230 |
if (parser.getName().compareTo(
|
231 |
FilterUtils.remNameSpace(FilterTags.FILTER)) == 0)
|
232 |
end = true;
|
233 |
break;
|
234 |
case XmlPullParser.TEXT:
|
235 |
break;
|
236 |
} |
237 |
if (!end)
|
238 |
currentTag = parser.next(); |
239 |
} |
240 |
|
241 |
expression += ") ";
|
242 |
} |
243 |
|
244 |
public Set<String> getFieldNames() { return fieldNames; } |
245 |
public void addSymbolizer2Filter(ISLDSymbolizer symbol) { symbolizers.add(symbol); } |
246 |
public ArrayList<ISLDSymbolizer> getSymbolizers() { return symbolizers; } |
247 |
|
248 |
public FComparisonOperator getCompOperator() {return compOperator;} |
249 |
public FLogicOperator getLogicOperator() {return logicOperators;} |
250 |
public FLogicOperatorNot getNotLogicOperator() {return notLogicOperator;} |
251 |
public String getExpression() {return this.expression;} |
252 |
|
253 |
|
254 |
|
255 |
} |