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