root / tags / CatalogYNomenclator_v1_1_1005_Build_0 / applications / appCatalogYNomenclatorClient / src / es / gva / cit / catalogClient / languages / FilterEncoding.java @ 12766
History | View | Annotate | Download (8.38 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 es.gva.cit.catalogClient.languages; |
43 |
import java.util.Iterator; |
44 |
|
45 |
import es.gva.cit.catalogClient.querys.Coordinates; |
46 |
|
47 |
/**
|
48 |
* This class implements the Filter Encoding Language. It is used to
|
49 |
* create querys in this language
|
50 |
*
|
51 |
*
|
52 |
* @author Jorge Piera Llodra (piera_jor@gva.es)
|
53 |
* @see http://portal.opengeospatial.org/files/?artifact_id=8340
|
54 |
*/
|
55 |
public class FilterEncoding extends AbstractGeneralLanguage { |
56 |
|
57 |
/**
|
58 |
*
|
59 |
*
|
60 |
*/
|
61 |
private String prefix = null; |
62 |
|
63 |
/**
|
64 |
*
|
65 |
*
|
66 |
*/
|
67 |
private String wildCard = null; |
68 |
|
69 |
/**
|
70 |
*
|
71 |
*
|
72 |
*/
|
73 |
private String singleChar = null; |
74 |
|
75 |
/**
|
76 |
*
|
77 |
*
|
78 |
*/
|
79 |
private String escape = null; |
80 |
|
81 |
/**
|
82 |
*
|
83 |
*
|
84 |
*/
|
85 |
private String filterAttribute = null; |
86 |
|
87 |
/**
|
88 |
* Create a new Filter Encoding Parser
|
89 |
*
|
90 |
*
|
91 |
* @param prefix Prefix of the labels (if its necessary). Typically "ogc".
|
92 |
* @param wildCard It Depends of the server
|
93 |
* @param singleChar It Depends of the server
|
94 |
* @param escape It Depends of the server
|
95 |
* @param filterAttribute Sometimes, "Field" label needs an attribute.
|
96 |
*/
|
97 |
public FilterEncoding(String prefix, String wildCard, String singleChar, String escape, String filterAttribute) { |
98 |
this.prefix = prefix;
|
99 |
this.wildCard = wildCard;
|
100 |
this.singleChar = singleChar;
|
101 |
this.escape = escape;
|
102 |
this.filterAttribute = filterAttribute;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* It Adds a new clause of the query
|
107 |
*
|
108 |
*
|
109 |
* @param parameter Parameter name
|
110 |
* @param value Parameter value
|
111 |
* @param concordancia "E" (Exact phrase), "A" (All words) or "Y" (anY word).
|
112 |
* @param relationship PropertyIsLike, PropertyIsLess, PropertyIsGreater,... See the File encoding
|
113 |
* Documentation.
|
114 |
* @param type Values: "P" (to comparate two propertyes) or "L" (to comparate one property
|
115 |
* and one literal value)
|
116 |
* @param operator "And" or "Or". Operator between fields
|
117 |
*/
|
118 |
public void addClauses(String parameter, String value, String concordancia, String relationship, String type, String operator) { |
119 |
currentClause = null;
|
120 |
//Seperating the words
|
121 |
Iterator values = parseValues(value, concordancia);
|
122 |
//Filling the words
|
123 |
addClauses(parameter, values, concordancia, relationship, type, operator); |
124 |
} |
125 |
|
126 |
/**
|
127 |
*
|
128 |
*
|
129 |
*
|
130 |
* @param parameter
|
131 |
* @param values
|
132 |
* @param concordancia
|
133 |
* @param relationship
|
134 |
* @param type
|
135 |
* @param operator
|
136 |
*/
|
137 |
public void addClauses(String parameter, Iterator values, String concordancia, String relationship, String type, String operator) { |
138 |
while (values.hasNext())
|
139 |
addTerm(parameter, (String) values.next(), concordancia,
|
140 |
relationship, type); |
141 |
addCurrentClauseQuery(operator); |
142 |
} |
143 |
|
144 |
/**
|
145 |
* It adds a new term to the full query
|
146 |
*
|
147 |
*
|
148 |
* @param parameter Parameter name
|
149 |
* @param value Parameter Value
|
150 |
* @param concordancia "E" (Exact phrase), "A" (All words) or "Y" (anY word).
|
151 |
* @param relationship PropertyIsLike, PropertyIsLess, PropertyIsGreater,... See the File encoding
|
152 |
* Documentation.
|
153 |
* @param type Values: "P" (to comparate two propertyes) or "L" (to comparate one property
|
154 |
* and one literal value)
|
155 |
*/
|
156 |
private void addTerm(String parameter, String value, String concordancia, String relationship, String type) { |
157 |
StringBuffer term = new StringBuffer(); |
158 |
term.append(propertyIsXXX(relationship, parameter, value, type)); |
159 |
if (currentClause == null) { |
160 |
currentClause = term.toString(); |
161 |
} else {
|
162 |
currentClause = currentClause + term.toString(); |
163 |
currentClause = enterLabel(currentClause, getOperator(concordancia)); |
164 |
} |
165 |
} |
166 |
|
167 |
/**
|
168 |
* It adds the "and" label to join different operations
|
169 |
*
|
170 |
*
|
171 |
* @param operator
|
172 |
*/
|
173 |
protected void addCurrentClauseQuery(String operator) { |
174 |
if (currentClause != null) { |
175 |
if (currentQuery == null) { |
176 |
currentQuery = currentClause; |
177 |
} else {
|
178 |
currentQuery = currentQuery + currentClause; |
179 |
currentQuery = enterLabel(currentQuery, operator); |
180 |
} |
181 |
} |
182 |
} |
183 |
|
184 |
/**
|
185 |
* It returns the encoded query
|
186 |
*
|
187 |
*
|
188 |
* @return
|
189 |
*/
|
190 |
public String toString() { |
191 |
return enterLabel(currentQuery, "Filter"); |
192 |
} |
193 |
|
194 |
/**
|
195 |
* Envuelve a una pregunta con una etiqueta
|
196 |
*
|
197 |
*
|
198 |
* @return String : parte de la query en el lenguaje soportado
|
199 |
* @param pregunta Pregunta a envolver
|
200 |
* @param etiqueta Nombre de la etiqueta
|
201 |
*/
|
202 |
public String enterLabel(String pregunta, String etiqueta) { |
203 |
if (etiqueta.equals("Filter") && (this.filterAttribute != null)) { |
204 |
return "<" + prefix + etiqueta + " " + this.filterAttribute + ">" + |
205 |
pregunta + "</" + prefix + etiqueta + ">"; |
206 |
} else {
|
207 |
return "<" + prefix + etiqueta + ">" + pregunta + "</" + prefix + |
208 |
etiqueta + ">";
|
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* It writes a "PropertyIsXXX" part of a filtyer encoding query
|
214 |
*
|
215 |
*
|
216 |
* @return The part of the query
|
217 |
* @param property Possible Values: PropertIsLike, PropertyIsLess, PropertyIsGreater,... See
|
218 |
* the Filter Encoding documentation
|
219 |
* @param parameter Parameter name
|
220 |
* @param value Parameter value
|
221 |
* @param type Values: "P" (to comparate two propertyes) or "L" (to comparate one property
|
222 |
* and one literal value)
|
223 |
*/
|
224 |
public String propertyIsXXX(String property, String parameter, String value, String type) { |
225 |
String cadena = ""; |
226 |
cadena = "<" + prefix + property;
|
227 |
if (property.equals("PropertyIsLike")) { |
228 |
if (this.wildCard != null) { |
229 |
cadena = cadena + " wildCard=\"" + this.wildCard + "\""; |
230 |
} |
231 |
if (this.singleChar != null) { |
232 |
cadena = cadena + " singleChar=\"" + this.singleChar + "\""; |
233 |
} |
234 |
if (this.escape != null) { |
235 |
cadena = cadena + " escape=\"" + this.escape + "\""; |
236 |
} |
237 |
} |
238 |
cadena = cadena + ">" + enterLabel(parameter, "PropertyName"); |
239 |
if (type.equals("P")) { |
240 |
cadena = cadena + enterLabel(value, "PropertyName");
|
241 |
} else {
|
242 |
cadena = cadena + enterLabel(value, "Literal");
|
243 |
} |
244 |
return cadena + "</" + prefix + property + ">"; |
245 |
} |
246 |
|
247 |
/**
|
248 |
* It Adds a Bounding Box query
|
249 |
*
|
250 |
*
|
251 |
* @param coordinates Coordinates to find
|
252 |
* @param propertyName Property that contains the geom field
|
253 |
* @param not If we have to envolve the query with the "NOT" tag.
|
254 |
*/
|
255 |
public void addBoundingBox(Coordinates coordinates, String propertyName, boolean not) { |
256 |
// sNorth -> Uly();
|
257 |
// sWest -> Ulx();
|
258 |
// sSouth -> Bry();
|
259 |
// sEast -> Brx();
|
260 |
String bbox = "<ogc:BBOX>" + "<ogc:PropertyName>" + propertyName + |
261 |
"</ogc:PropertyName>" + "<gml:Box>" + "<gml:coord>" + "<gml:X>" + |
262 |
coordinates.ulx + "</gml:X>" + "<gml:Y>" + coordinates.bry + |
263 |
"</gml:Y>" + "</gml:coord>" + "<gml:coord>" + "<gml:X>" + |
264 |
coordinates.brx + "</gml:X>" + "<gml:Y>" + coordinates.uly + |
265 |
"</gml:Y>" + "</gml:coord>" + "</gml:Box>" + "</ogc:BBOX>"; |
266 |
if (not){
|
267 |
bbox = "<ogc:Not>" + bbox + "</ogc:Not>"; |
268 |
} |
269 |
if (currentQuery == null) { |
270 |
currentQuery = bbox; |
271 |
} else {
|
272 |
currentQuery = currentQuery + bbox; |
273 |
currentQuery = enterLabel(currentQuery, "And");
|
274 |
} |
275 |
} |
276 |
} |