Revision 34132 branches/v2_0_0_prep/libraries/libRemoteServices/src/org/gvsig/remoteclient/wfs/filters/filterencoding/FilterEncoding.java
FilterEncoding.java | ||
---|---|---|
48 | 48 |
import org.gvsig.compat.CompatLocator; |
49 | 49 |
import org.gvsig.compat.lang.StringUtils; |
50 | 50 |
import org.gvsig.remoteclient.wfs.WFSStatus; |
51 |
import org.gvsig.remoteclient.wfs.edition.WFSTTags; |
|
51 | 52 |
import org.gvsig.remoteclient.wfs.filters.AbstractFilter; |
52 | 53 |
import org.gvsig.remoteclient.wfs.filters.BinaryTree; |
53 | 54 |
import org.gvsig.remoteclient.wfs.filters.BinaryTree.Node; |
... | ... | |
71 | 72 |
* @author Jorge Piera Llodra (piera_jor@gva.es) |
72 | 73 |
*/ |
73 | 74 |
public class FilterEncoding extends AbstractFilter { |
74 |
public static final int RELATIONSHIP_PROPERTY = 0;
|
|
75 |
public static final int RELATIONSHIP_VAUES = 1;
|
|
75 |
public static final int RELATIONSHIP_PROPERTY = 0;
|
|
76 |
public static final int RELATIONSHIP_VAUES = 1;
|
|
76 | 77 |
|
77 |
private StringBuffer currentQuery = null; |
|
78 |
//Operation types |
|
79 |
private static final int OPERATION_PROPERTYNAME = 0; |
|
80 |
private static final int OPERATION_LITERAL = 1; |
|
81 |
//Filter namespace. (typically "ogc") |
|
82 |
private String namepacePrefix = null; |
|
83 |
//If the Filter can have blanckSpaces |
|
84 |
private boolean hasBlankSpaces = true; |
|
85 |
private String defaultBlankSpace = "%20"; |
|
86 |
//This character must be replaced by any set of characters (typically "*") |
|
87 |
private String wildCardChar = null; |
|
88 |
//This character must be replaced by one character (typically "?") |
|
89 |
private String singleChar = null; |
|
90 |
//Escape character (typically "\") |
|
91 |
private String escapeChar = null; |
|
92 |
//Default values |
|
93 |
public static final String DEFAULT_NAMESPACE_PREFIX = "ogc"; |
|
94 |
public static final String DEFAULT_WILDCARD = "*"; |
|
95 |
public static final String DEFAULT_SINGLECHAR = "?"; |
|
96 |
public static final String DEFAULT_ESCAPE = "\\"; |
|
97 |
public static final String DEFAULT_NAMESPACE = "xmlns:ogc=\"http://www.opengis.net/ogc\""; |
|
78 |
private StringBuffer currentQuery = null; |
|
79 |
//Operation types |
|
80 |
private static final int OPERATION_PROPERTYNAME = 0; |
|
81 |
private static final int OPERATION_LITERAL = 1; |
|
82 |
|
|
83 |
//Filter namespace. |
|
84 |
private String nameSpacePrefix = null; |
|
85 |
private String nameSpaceLocation = null; |
|
98 | 86 |
|
99 |
private Hashtable filterAttributes = new Hashtable(); |
|
87 |
//If the Filter can have blanckSpaces |
|
88 |
private boolean hasBlankSpaces = true; |
|
89 |
private String defaultBlankSpace = "%20"; |
|
90 |
//This character must be replaced by any set of characters (typically "*") |
|
91 |
private String wildCardChar = null; |
|
92 |
//This character must be replaced by one character (typically "?") |
|
93 |
private String singleChar = null; |
|
94 |
//Escape character (typically "\") |
|
95 |
private String escapeChar = null; |
|
96 |
//Default values |
|
97 |
public static final String DEFAULT_NAMESPACE_PREFIX = "ogc"; |
|
98 |
public static final String DEFAULT_WILDCARD = "*"; |
|
99 |
public static final String DEFAULT_SINGLECHAR = "?"; |
|
100 |
public static final String DEFAULT_ESCAPE = "\\"; |
|
101 |
public static final String DEFAULT_NAMESPACE = "xmlns:ogc=\"http://www.opengis.net/ogc\""; |
|
100 | 102 |
|
101 |
/** |
|
102 |
* If the namespace XML is qualified |
|
103 |
*/ |
|
104 |
private boolean isQualified = false; |
|
103 |
private Hashtable filterAttributes = new Hashtable(); |
|
105 | 104 |
|
106 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
|
107 |
|
|
108 |
/** |
|
109 |
* Create a new Filter Encoding Parser |
|
110 |
* |
|
111 |
* |
|
112 |
* @param namepacePrefix |
|
113 |
* Filter namespace. (typically "ogc") |
|
114 |
* @param wildCardChar |
|
115 |
* This character must be replaced by any set of characters (typically "*") |
|
116 |
* @param singleChar |
|
117 |
* This character must be replaced by one character (typically "?") |
|
118 |
* @param escape |
|
119 |
* Escape character |
|
120 |
* @param filterAttribute Sometimes, "Field" label needs an attribute. |
|
121 |
*/ |
|
122 |
public FilterEncoding(ISQLExpressionFormat formatter,String namesPacePrefix, String wildCard, String singleChar, String escape, Hashtable filterAttributes) { |
|
123 |
super(formatter); |
|
124 |
if (namesPacePrefix == null){ |
|
125 |
setQualified(false); |
|
126 |
}else{ |
|
127 |
setQualified(true); |
|
128 |
} |
|
129 |
this.wildCardChar = wildCard; |
|
130 |
this.singleChar = singleChar; |
|
131 |
this.escapeChar = escape; |
|
132 |
this.filterAttributes = filterAttributes; |
|
133 |
} |
|
105 |
/** |
|
106 |
* If the namespace XML is qualified |
|
107 |
*/ |
|
108 |
private boolean isQualified = false; |
|
134 | 109 |
|
110 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
|
135 | 111 |
|
136 |
/** |
|
137 |
* Create a new Filter Encoding Parser |
|
138 |
* @param formatter |
|
139 |
*/ |
|
140 |
public FilterEncoding(ISQLExpressionFormat formatter) { |
|
141 |
this(formatter,null,DEFAULT_WILDCARD,DEFAULT_SINGLECHAR, |
|
142 |
DEFAULT_ESCAPE,new Hashtable()); |
|
143 |
} |
|
112 |
/** |
|
113 |
* Create a new Filter Encoding Parser |
|
114 |
* |
|
115 |
* |
|
116 |
* @param nameSpacePrefix |
|
117 |
* Filter namespace. (typically "ogc") |
|
118 |
* @param wildCardChar |
|
119 |
* This character must be replaced by any set of characters (typically "*") |
|
120 |
* @param singleChar |
|
121 |
* This character must be replaced by one character (typically "?") |
|
122 |
* @param escape |
|
123 |
* Escape character |
|
124 |
* @param filterAttribute Sometimes, "Field" label needs an attribute. |
|
125 |
*/ |
|
126 |
public FilterEncoding(ISQLExpressionFormat formatter,String namesPacePrefix, String wildCard, String singleChar, String escape, Hashtable filterAttributes) { |
|
127 |
super(formatter); |
|
128 |
if (namesPacePrefix == null){ |
|
129 |
setQualified(false); |
|
130 |
}else{ |
|
131 |
setQualified(true); |
|
132 |
} |
|
133 |
this.wildCardChar = wildCard; |
|
134 |
this.singleChar = singleChar; |
|
135 |
this.escapeChar = escape; |
|
136 |
this.filterAttributes = filterAttributes; |
|
137 |
} |
|
144 | 138 |
|
145 |
/** |
|
146 |
* Create a new Filter Encoding Parser |
|
147 |
*/ |
|
148 |
public FilterEncoding() { |
|
149 |
this(new DefaultSQLExpressionFormat()); |
|
150 |
} |
|
151 | 139 |
|
152 |
/** |
|
153 |
* Create a new Filter Encoding Parser |
|
154 |
*/ |
|
155 |
public FilterEncoding(WFSStatus status) { |
|
156 |
this(); |
|
157 |
setQueryByAttribute(status.getFilterByAttribute()); |
|
158 |
clearSpatialFilters(); |
|
159 |
addSpatialFilter(status.getFilterByArea()); |
|
160 |
} |
|
140 |
/** |
|
141 |
* Create a new Filter Encoding Parser |
|
142 |
* @param formatter |
|
143 |
*/ |
|
144 |
public FilterEncoding(ISQLExpressionFormat formatter) { |
|
145 |
this(formatter,null,DEFAULT_WILDCARD,DEFAULT_SINGLECHAR, |
|
146 |
DEFAULT_ESCAPE,new Hashtable()); |
|
147 |
} |
|
161 | 148 |
|
162 |
/* |
|
163 |
* (non-Javadoc) |
|
164 |
* @see org.gvsig.remoteClient.filterEncoding.QueryLanguage#toString(org.gvsig.remoteClient.filterEncoding.BinaryTree) |
|
165 |
*/ |
|
166 |
public String toString(BinaryTree tree, String version) { |
|
167 |
//If is a filter by ids... |
|
168 |
StringBuffer idQuery = null; |
|
169 |
if (getIds() != null){ |
|
170 |
idQuery = new StringBuffer(); |
|
171 |
ArrayList ids = getIds(); |
|
172 |
for (int i=0 ; i<ids.size() ; i++){ |
|
173 |
if (ids.get(i) != null){ |
|
174 |
Hashtable attributes = new Hashtable(); |
|
175 |
attributes.put("fid","\"" + ids.get(i).toString() + "\""); |
|
176 |
idQuery.append(setTag("FeatureId", attributes, null)); |
|
177 |
} |
|
178 |
} |
|
179 |
return enclosesWithFilterTag(idQuery.toString()); |
|
180 |
} |
|
181 |
//If is a filter by attributes... |
|
182 |
String filterQuery = null; |
|
183 |
if ((tree.getRoot() == null) && (getSpatialFiltersCount() == 0)){ |
|
184 |
return null; |
|
185 |
} |
|
186 |
if (tree.getRoot() != null){ |
|
187 |
currentQuery = new StringBuffer(); |
|
188 |
filterQuery = getFilterNode(tree.getRoot()); |
|
189 |
if (getSpatialFiltersCount() == 0){ |
|
190 |
return enclosesWithFilterTag(filterQuery); |
|
191 |
} |
|
192 |
} |
|
193 |
//If is a filter by area |
|
194 |
String bboxQuery = null; |
|
195 |
if (getSpatialFiltersCount() > 0){ |
|
196 |
for (int i=0 ; i<getSpatialFiltersCount() ; i++){ |
|
197 |
WFSSpatialFilterOperation spatialFilter = getSpatialFilterAt(i); |
|
198 |
SpatialFEQuery feQuery = null; |
|
199 |
if (spatialFilter instanceof WFSGeometryFilterOperation){ |
|
200 |
feQuery = new GeometryFEQuery((WFSGeometryFilterOperation)spatialFilter); |
|
201 |
}else if (spatialFilter instanceof WFSEnvelopeFilterOperation){ |
|
202 |
//TODO add this for a manager |
|
203 |
if (version.equals("1.0.0")){ |
|
204 |
feQuery = new EnvelopeFEQuery1_0_0((WFSEnvelopeFilterOperation)spatialFilter); |
|
205 |
}else{ |
|
206 |
feQuery = new EnvelopeFEQuery1_1_0((WFSEnvelopeFilterOperation)spatialFilter); |
|
207 |
} |
|
208 |
} |
|
209 |
//If there is a spatial query |
|
210 |
if (feQuery != null){ |
|
211 |
bboxQuery = feQuery.getFilterEncoding(); |
|
212 |
if (tree.getRoot() == null){ |
|
213 |
return bboxQuery; |
|
214 |
} |
|
215 |
} |
|
216 |
} |
|
217 |
} |
|
218 |
return enclosesWithFilterTag(filterQuery + bboxQuery); |
|
219 |
} |
|
149 |
/** |
|
150 |
* Create a new Filter Encoding Parser |
|
151 |
*/ |
|
152 |
FilterEncoding() { |
|
153 |
this(new DefaultSQLExpressionFormat()); |
|
154 |
} |
|
220 | 155 |
|
221 |
/** |
|
222 |
* Gets the filter code from a node |
|
223 |
* @param node |
|
224 |
*/ |
|
225 |
private String getFilterNode(Node node){ |
|
226 |
if (node.isField()){ |
|
227 |
return getExpression(node.getValue()); |
|
228 |
}else{ |
|
229 |
String left = ""; |
|
230 |
String rigth = ""; |
|
231 |
if (node.getLeftNode() != null){ |
|
232 |
left = getFilterNode(node.getLeftNode()); |
|
233 |
} |
|
234 |
if (node.getRigthNode() != null){ |
|
235 |
rigth = getFilterNode(node.getRigthNode()); |
|
236 |
} |
|
237 |
int operationCode = getLogicalOperator(node.getValue()); |
|
238 |
String operation = getLogicalOperator(operationCode); |
|
239 |
return enterLabel(left+rigth, operation); |
|
240 |
} |
|
241 |
} |
|
156 |
/** |
|
157 |
* Create a new Filter Encoding Parser |
|
158 |
*/ |
|
159 |
public FilterEncoding(WFSStatus status) { |
|
160 |
this(); |
|
161 |
this.nameSpacePrefix = status.getNamespacePrefix(); |
|
162 |
this.nameSpaceLocation = status.getNamespaceLocation(); |
|
163 |
setQueryByAttribute(status.getFilterByAttribute()); |
|
164 |
clearSpatialFilters(); |
|
165 |
addSpatialFilter(status.getFilterByArea()); |
|
166 |
} |
|
242 | 167 |
|
243 |
/** |
|
244 |
* Parses a expresion like 'A op B' and returns the |
|
245 |
* expresion using the filter encoding language |
|
246 |
* @param expression |
|
247 |
* @return |
|
248 |
*/ |
|
249 |
private String getExpression(String expression){ |
|
250 |
String[] words = stringUtils.split(expression, " "); |
|
251 |
//Param |
|
252 |
String param = words[0]; |
|
253 |
if (param.charAt(0) == '"'){ |
|
254 |
param = param.substring(1,param.length()); |
|
255 |
} |
|
256 |
if (param.charAt(param.length()-1) == '"'){ |
|
257 |
param = param.substring(0,param.length()-1); |
|
258 |
} |
|
259 |
//Operator |
|
260 |
String operator = words[1]; |
|
261 |
//Value |
|
262 |
String value = words[2]; |
|
263 |
for (int i=3 ; i<words.length ; i++){ |
|
264 |
value = value + " " + words[i]; |
|
265 |
} |
|
266 |
if (value.charAt(0) == '\''){ |
|
267 |
value = value.substring(1,value.length()); |
|
268 |
} |
|
269 |
if (value.charAt(value.length()-1) == '\''){ |
|
270 |
value = value.substring(0,value.length()-1); |
|
271 |
} |
|
272 |
int operatorCode = getRelationalOperator(operator); |
|
273 |
operator = getRelationalOperator(operatorCode); |
|
274 |
return createExpression(operator,param,value); |
|
275 |
} |
|
168 |
/* |
|
169 |
* (non-Javadoc) |
|
170 |
* @see org.gvsig.remoteClient.filterEncoding.QueryLanguage#toString(org.gvsig.remoteClient.filterEncoding.BinaryTree) |
|
171 |
*/ |
|
172 |
public String toString(BinaryTree tree, String version) { |
|
173 |
//If is a filter by ids... |
|
174 |
StringBuffer idQuery = null; |
|
175 |
if (getIds() != null){ |
|
176 |
idQuery = new StringBuffer(); |
|
177 |
ArrayList ids = getIds(); |
|
178 |
for (int i=0 ; i<ids.size() ; i++){ |
|
179 |
if (ids.get(i) != null){ |
|
180 |
Hashtable attributes = new Hashtable(); |
|
181 |
attributes.put("fid","\"" + ids.get(i).toString() + "\""); |
|
182 |
idQuery.append(setTag("FeatureId", attributes, null)); |
|
183 |
} |
|
184 |
} |
|
185 |
return enclosesWithFilterTag(idQuery.toString()); |
|
186 |
} |
|
187 |
//If is a filter by attributes... |
|
188 |
String filterQuery = null; |
|
189 |
if ((tree.getRoot() == null) && (getSpatialFiltersCount() == 0)){ |
|
190 |
return null; |
|
191 |
} |
|
192 |
if (tree.getRoot() != null){ |
|
193 |
currentQuery = new StringBuffer(); |
|
194 |
filterQuery = getFilterNode(tree.getRoot()); |
|
195 |
if (getSpatialFiltersCount() == 0){ |
|
196 |
return enclosesWithFilterTag(filterQuery); |
|
197 |
} |
|
198 |
} |
|
199 |
//If is a filter by area |
|
200 |
String bboxQuery = null; |
|
201 |
if (getSpatialFiltersCount() > 0){ |
|
202 |
for (int i=0 ; i<getSpatialFiltersCount() ; i++){ |
|
203 |
WFSSpatialFilterOperation spatialFilter = getSpatialFilterAt(i); |
|
204 |
SpatialFEQuery feQuery = null; |
|
205 |
if (spatialFilter instanceof WFSGeometryFilterOperation){ |
|
206 |
feQuery = new GeometryFEQuery((WFSGeometryFilterOperation)spatialFilter); |
|
207 |
}else if (spatialFilter instanceof WFSEnvelopeFilterOperation){ |
|
208 |
//TODO add this for a manager |
|
209 |
if (version.equals("1.0.0")){ |
|
210 |
feQuery = new EnvelopeFEQuery1_0_0((WFSEnvelopeFilterOperation)spatialFilter); |
|
211 |
}else{ |
|
212 |
feQuery = new EnvelopeFEQuery1_1_0((WFSEnvelopeFilterOperation)spatialFilter); |
|
213 |
} |
|
214 |
} |
|
215 |
//If there is a spatial query |
|
216 |
if (feQuery != null){ |
|
217 |
bboxQuery = feQuery.getFilterEncoding(); |
|
218 |
if (tree.getRoot() == null){ |
|
219 |
return bboxQuery; |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
} |
|
224 |
return enclosesWithFilterTag(filterQuery + bboxQuery); |
|
225 |
} |
|
276 | 226 |
|
277 |
/** |
|
278 |
* It writes a "PropertyIsXXX" part of a filtyer encoding query |
|
279 |
* |
|
280 |
* |
|
281 |
* @return The part of the query |
|
282 |
* @param property Possible Values: PropertIsLike, PropertyIsLess, PropertyIsGreater,... See |
|
283 |
* the Filter Encoding documentation |
|
284 |
* @param parameter Parameter name |
|
285 |
* @param value Parameter value |
|
286 |
* @param type Values: "P" (to comparate two propertyes) or "L" (to comparate one property |
|
287 |
* and one literal value) |
|
288 |
*/ |
|
289 |
private String createExpression(String property, String parameter, String value) { |
|
290 |
String cadena = ""; |
|
291 |
cadena = "<" + namepacePrefix + property; |
|
292 |
if (property.equals("PropertyIsLike")) { |
|
293 |
if (wildCardChar != null) { |
|
294 |
cadena = cadena + " wildCard=\"" + this.wildCardChar + "\""; |
|
295 |
} |
|
296 |
if (singleChar != null) { |
|
297 |
cadena = cadena + " singleChar=\"" + this.singleChar + "\""; |
|
298 |
} |
|
299 |
if (escapeChar != null) { |
|
300 |
cadena = cadena + " escape=\"" + this.escapeChar + "\""; |
|
301 |
} |
|
302 |
} |
|
303 |
cadena = cadena + ">" + enterLabel(parameter, "PropertyName"); |
|
304 |
cadena = cadena + enterLabel(value, "Literal"); |
|
305 |
return cadena + "</" + namepacePrefix + property + ">"; |
|
306 |
} |
|
227 |
/** |
|
228 |
* Gets the filter code from a node |
|
229 |
* @param node |
|
230 |
*/ |
|
231 |
private String getFilterNode(Node node){ |
|
232 |
if (node.isField()){ |
|
233 |
return getExpression(node.getValue()); |
|
234 |
}else{ |
|
235 |
String left = ""; |
|
236 |
String rigth = ""; |
|
237 |
if (node.getLeftNode() != null){ |
|
238 |
left = getFilterNode(node.getLeftNode()); |
|
239 |
} |
|
240 |
if (node.getRigthNode() != null){ |
|
241 |
rigth = getFilterNode(node.getRigthNode()); |
|
242 |
} |
|
243 |
int operationCode = getLogicalOperator(node.getValue()); |
|
244 |
String operation = getLogicalOperator(operationCode); |
|
245 |
return enterLabel(left+rigth, operation); |
|
246 |
} |
|
247 |
} |
|
307 | 248 |
|
308 |
/** |
|
309 |
* Envuelve a una pregunta con una etiqueta |
|
310 |
* |
|
311 |
* |
|
312 |
* @return String : parte de la query en el lenguaje soportado |
|
313 |
* @param pregunta Pregunta a envolver |
|
314 |
* @param etiqueta Nombre de la etiqueta |
|
315 |
*/ |
|
316 |
private String enterLabel(String value, String tagName) { |
|
317 |
if (tagName.equals("Filter") && (!(filterAttributes.isEmpty()))) { |
|
318 |
return setTag(tagName,filterAttributes,value); |
|
319 |
} else { |
|
320 |
return setTag(tagName,null,value); |
|
321 |
} |
|
322 |
} |
|
249 |
/** |
|
250 |
* Parses a expresion like 'A op B' and returns the |
|
251 |
* expresion using the filter encoding language |
|
252 |
* @param expression |
|
253 |
* @return |
|
254 |
*/ |
|
255 |
private String getExpression(String expression){ |
|
256 |
String[] words = stringUtils.split(expression, " "); |
|
257 |
//Param |
|
258 |
String param = words[0]; |
|
259 |
if (param.charAt(0) == '"'){ |
|
260 |
param = param.substring(1,param.length()); |
|
261 |
} |
|
262 |
if (param.charAt(param.length()-1) == '"'){ |
|
263 |
param = param.substring(0,param.length()-1); |
|
264 |
} |
|
265 |
//Operator |
|
266 |
String operator = words[1]; |
|
267 |
//Value |
|
268 |
String value = words[2]; |
|
269 |
for (int i=3 ; i<words.length ; i++){ |
|
270 |
value = value + " " + words[i]; |
|
271 |
} |
|
272 |
if (value.charAt(0) == '\''){ |
|
273 |
value = value.substring(1,value.length()); |
|
274 |
} |
|
275 |
if (value.charAt(value.length()-1) == '\''){ |
|
276 |
value = value.substring(0,value.length()-1); |
|
277 |
} |
|
278 |
int operatorCode = getRelationalOperator(operator); |
|
279 |
operator = getRelationalOperator(operatorCode); |
|
280 |
return createExpression(operator,param,value); |
|
281 |
} |
|
323 | 282 |
|
324 |
/** |
|
325 |
* Envolves a value with an XML tag |
|
326 |
* |
|
327 |
* @return String |
|
328 |
* XML tag with its value |
|
329 |
* @param tagName |
|
330 |
* XML tag name |
|
331 |
* @param attributes |
|
332 |
* XML tag attributes |
|
333 |
* @param value |
|
334 |
* Tag value |
|
335 |
*/ |
|
336 |
public String setTag(String tagName, Hashtable attributes, String value) { |
|
337 |
StringBuffer tag = new StringBuffer(); |
|
283 |
/** |
|
284 |
* It writes a "PropertyIsXXX" part of a filtyer encoding query |
|
285 |
* |
|
286 |
* |
|
287 |
* @return The part of the query |
|
288 |
* @param property Possible Values: PropertIsLike, PropertyIsLess, PropertyIsGreater,... See |
|
289 |
* the Filter Encoding documentation |
|
290 |
* @param parameter Parameter name |
|
291 |
* @param value Parameter value |
|
292 |
* @param type Values: "P" (to comparate two propertyes) or "L" (to comparate one property |
|
293 |
* and one literal value) |
|
294 |
*/ |
|
295 |
private String createExpression(String property, String parameter, String value) { |
|
296 |
String cadena = ""; |
|
297 |
cadena = "<" + WFSTTags.OGC_NAMESPACE_PREFIX + ":" + property; |
|
298 |
if (property.equals("PropertyIsLike")) { |
|
299 |
if (wildCardChar != null) { |
|
300 |
cadena = cadena + " wildCard=\"" + this.wildCardChar + "\""; |
|
301 |
} |
|
302 |
if (singleChar != null) { |
|
303 |
cadena = cadena + " singleChar=\"" + this.singleChar + "\""; |
|
304 |
} |
|
305 |
if (escapeChar != null) { |
|
306 |
cadena = cadena + " escape=\"" + this.escapeChar + "\""; |
|
307 |
} |
|
308 |
} |
|
309 |
cadena = cadena + ">" + enterLabel(nameSpacePrefix + ":" + parameter, "PropertyName"); |
|
310 |
cadena = cadena + enterLabel(value, "Literal"); |
|
311 |
return cadena + "</" + WFSTTags.OGC_NAMESPACE_PREFIX + ":" + property + ">"; |
|
312 |
} |
|
338 | 313 |
|
339 |
tag.append("<");
|
|
340 |
tag.append(namepacePrefix);
|
|
341 |
tag.append(tagName);
|
|
342 |
if (attributes != null){
|
|
343 |
Set keys = attributes.keySet();
|
|
344 |
if (attributes.size() > 0){
|
|
345 |
Iterator it = keys.iterator();
|
|
346 |
while (it.hasNext()){
|
|
347 |
String key = (String)it.next();
|
|
348 |
if (hasBlankSpaces){
|
|
349 |
tag.append(" ");
|
|
350 |
}else{
|
|
351 |
tag.append(defaultBlankSpace);
|
|
352 |
}
|
|
353 |
tag.append(key + "=" + (String)attributes.get(key));
|
|
314 |
/**
|
|
315 |
* Envuelve a una pregunta con una etiqueta
|
|
316 |
*
|
|
317 |
*
|
|
318 |
* @return String : parte de la query en el lenguaje soportado
|
|
319 |
* @param pregunta Pregunta a envolver
|
|
320 |
* @param etiqueta Nombre de la etiqueta
|
|
321 |
*/
|
|
322 |
private String enterLabel(String value, String tagName) {
|
|
323 |
if (tagName.equals("Filter") && (!(filterAttributes.isEmpty()))) {
|
|
324 |
return setTag(tagName,filterAttributes,value);
|
|
325 |
} else {
|
|
326 |
return setTag(tagName,null,value);
|
|
327 |
}
|
|
328 |
}
|
|
354 | 329 |
|
355 |
}
|
|
356 |
}
|
|
357 |
}
|
|
358 |
if (value == null){
|
|
359 |
tag.append("/>");
|
|
360 |
}else{
|
|
361 |
tag.append(">" + value);
|
|
362 |
tag.append("</");
|
|
363 |
tag.append(namepacePrefix);
|
|
364 |
tag.append(tagName);
|
|
365 |
tag.append(">");
|
|
366 |
}
|
|
367 |
return tag.toString();
|
|
368 |
}
|
|
330 |
/**
|
|
331 |
* Envolves a value with an XML tag
|
|
332 |
*
|
|
333 |
* @return String
|
|
334 |
* XML tag with its value
|
|
335 |
* @param tagName
|
|
336 |
* XML tag name
|
|
337 |
* @param attributes
|
|
338 |
* XML tag attributes
|
|
339 |
* @param value
|
|
340 |
* Tag value
|
|
341 |
*/
|
|
342 |
public String setTag(String tagName, Hashtable attributes, String value) {
|
|
343 |
StringBuffer tag = new StringBuffer();
|
|
369 | 344 |
|
345 |
tag.append("<"); |
|
346 |
tag.append(WFSTTags.OGC_NAMESPACE_PREFIX + ":"); |
|
347 |
tag.append(tagName); |
|
348 |
if (attributes != null){ |
|
349 |
Set keys = attributes.keySet(); |
|
350 |
if (attributes.size() > 0){ |
|
351 |
Iterator it = keys.iterator(); |
|
352 |
while (it.hasNext()){ |
|
353 |
String key = (String)it.next(); |
|
354 |
if (hasBlankSpaces){ |
|
355 |
tag.append(" "); |
|
356 |
}else{ |
|
357 |
tag.append(defaultBlankSpace); |
|
358 |
} |
|
359 |
tag.append(key + "=" + (String)attributes.get(key)); |
|
370 | 360 |
|
371 |
/** |
|
372 |
* Encloses a query with the filter tag |
|
373 |
* @param query |
|
374 |
* @return |
|
375 |
*/ |
|
376 |
private String enclosesWithFilterTag(String query){ |
|
377 |
StringBuffer filter = new StringBuffer(); |
|
378 |
filter.append("<" + namepacePrefix + "Filter"); |
|
379 |
if (!isQualified){ |
|
380 |
filter.append("%20"); |
|
381 |
filter.append("xmlns:ogc=\"http://www.opengis.net/ogc\"%20"); |
|
382 |
filter.append("xmlns:gml=\"http://www.opengis.net/gml\"%20"); |
|
383 |
filter.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"%20"); |
|
384 |
filter.append("xsi:schemaLocation=\"http://www.opengis.net/ogc%20../filter/1.0.0/filter.xsd%20http://www.opengis.net/gml%20../gml/2.1.2/geometry.xsd\""); |
|
385 |
} |
|
386 |
filter.append(">"); |
|
387 |
filter.append(query); |
|
388 |
filter.append("</" + namepacePrefix + "Filter>"); |
|
389 |
return filter.toString(); |
|
390 |
} |
|
361 |
} |
|
362 |
} |
|
363 |
} |
|
364 |
if (value == null){ |
|
365 |
tag.append("/>"); |
|
366 |
}else{ |
|
367 |
tag.append(">" + value); |
|
368 |
tag.append("</"); |
|
369 |
tag.append(WFSTTags.OGC_NAMESPACE_PREFIX + ":"); |
|
370 |
tag.append(tagName); |
|
371 |
tag.append(">"); |
|
372 |
} |
|
373 |
return tag.toString(); |
|
374 |
} |
|
391 | 375 |
|
392 |
/* |
|
393 |
* (non-Javadoc) |
|
394 |
* @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getLogicOperator(int) |
|
395 |
*/ |
|
396 |
public String getLogicalOperator(int operator) { |
|
397 |
switch (operator){ |
|
398 |
case LOGICAL_OPERATOR_AND: |
|
399 |
return "And"; |
|
400 |
case LOGICAL_OPERATOR_OR: |
|
401 |
return "Or"; |
|
402 |
case LOGICAL_OPERATOR_NOT: |
|
403 |
return "Not"; |
|
404 |
default: |
|
405 |
return "And"; |
|
406 |
} |
|
407 |
} |
|
408 | 376 |
|
409 |
/* |
|
410 |
* (non-Javadoc) |
|
411 |
* @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getRelationalOperator(int) |
|
412 |
*/ |
|
413 |
public String getRelationalOperator(int operator) { |
|
414 |
switch (operator){ |
|
415 |
case RELATIONAL_OPERATOR_IS_EQUALS_TO: |
|
416 |
return "PropertyIsEqualTo"; |
|
417 |
case RELATIONAL_OPERATOR_IS_NOT_EQUALS_TO: |
|
418 |
return "PropertyIsNotEqualTo"; |
|
419 |
case RELATIONAL_OPERATOR_IS_LESS_THAN: |
|
420 |
return "PropertyIsLessThan"; |
|
421 |
case RELATIONAL_OPERATOR_IS_GREATER_THAN: |
|
422 |
return "PropertyIsGreaterThan"; |
|
423 |
case RELATIONAL_OPERATOR_IS_LESS_THAN_OR_EQUAL_TO: |
|
424 |
return "PropertyIsLessThanOrEqualTo"; |
|
425 |
case RELATIONAL_OPERATOR_IS_GREATER_THAN_OR_EQUAL_TO: |
|
426 |
return "PropertyIsGreaterThanOrEqualTo"; |
|
427 |
case RELATIONAL_OPERATOR_IS_LIKE: |
|
428 |
return "PropertyIsLike"; |
|
429 |
case RELATIONAL_OPERATOR_IS_NULL: |
|
430 |
return "PropertyIsNull"; |
|
431 |
case RELATIONAL_OPERATOR_IS_BETWEEN: |
|
432 |
return "PropertyIsBetween"; |
|
433 |
default: |
|
434 |
return "PropertyIsLike"; |
|
435 |
} |
|
436 |
} |
|
377 |
/** |
|
378 |
* Encloses a query with the filter tag |
|
379 |
* @param query |
|
380 |
* @return |
|
381 |
*/ |
|
382 |
private String enclosesWithFilterTag(String query){ |
|
383 |
StringBuffer filter = new StringBuffer(); |
|
384 |
filter.append("<ogc:Filter"); |
|
385 |
if (!isQualified){ |
|
386 |
filter.append(" "); |
|
387 |
addNamespace(filter, WFSTTags.OGC_NAMESPACE_PREFIX, WFSTTags.OGC_NAMESPACE); |
|
388 |
addNamespace(filter, WFSTTags.GML_NAMESPACE_PREFIX, WFSTTags.GML_NAMESPACE); |
|
389 |
if (nameSpacePrefix != null){ |
|
390 |
addNamespace(filter, nameSpacePrefix, nameSpaceLocation); |
|
391 |
} |
|
392 |
filter.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "); |
|
393 |
filter.append("xsi:schemaLocation=\"http://www.opengis.net/ogc ../filter/1.0.0/filter.xsd http://www.opengis.net/gml ../gml/2.1.2/geometry.xsd\""); |
|
394 |
} |
|
395 |
filter.append(">"); |
|
396 |
filter.append(query); |
|
397 |
filter.append("</ogc:Filter>"); |
|
398 |
return filter.toString(); |
|
399 |
} |
|
400 |
|
|
401 |
private void addNamespace(StringBuffer buffer, String nameSpacePrefix, String nameSpaceLocation){ |
|
402 |
buffer.append(WFSTTags.XMLNS + ":" + nameSpacePrefix + "=\"" + nameSpaceLocation + "\" "); |
|
403 |
} |
|
437 | 404 |
|
438 |
/* |
|
439 |
* (non-Javadoc) |
|
440 |
* @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getGeometricOperator(int) |
|
441 |
*/ |
|
442 |
public String getGeometricOperator(int operator) { |
|
443 |
switch (operator){ |
|
444 |
case GEOMETRIC_OPERATOR_EQUALS: |
|
445 |
return "Equals"; |
|
446 |
case GEOMETRIC_OPERATOR_DISJOINT: |
|
447 |
return "Disjoint"; |
|
448 |
case GEOMETRIC_OPERATOR_TOUCHES: |
|
449 |
return "Touches"; |
|
450 |
case GEOMETRIC_OPERATOR_WITHIN: |
|
451 |
return "Within"; |
|
452 |
case GEOMETRIC_OPERATOR_OVERLAPS: |
|
453 |
return "Overlaps"; |
|
454 |
case GEOMETRIC_OPERATOR_CROSSES: |
|
455 |
return "Crosses"; |
|
456 |
case GEOMETRIC_OPERATOR_INTERSECT: |
|
457 |
return "Intersect"; |
|
458 |
case GEOMETRIC_OPERATOR_CONTAINS: |
|
459 |
return "Contains"; |
|
460 |
case GEOMETRIC_OPERATOR_DWITHIN: |
|
461 |
return "Dwithin"; |
|
462 |
case GEOMETRIC_OPERATOR_BEYOND: |
|
463 |
return "Beyond"; |
|
464 |
case GEOMETRIC_OPERATOR_BBOX: |
|
465 |
return "BBOX"; |
|
466 |
default: |
|
467 |
return "Equals"; |
|
468 |
} |
|
405 |
/* |
|
406 |
* (non-Javadoc) |
|
407 |
* @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getLogicOperator(int) |
|
408 |
*/ |
|
409 |
public String getLogicalOperator(int operator) { |
|
410 |
switch (operator){ |
|
411 |
case LOGICAL_OPERATOR_AND: |
|
412 |
return "And"; |
|
413 |
case LOGICAL_OPERATOR_OR: |
|
414 |
return "Or"; |
|
415 |
case LOGICAL_OPERATOR_NOT: |
|
416 |
return "Not"; |
|
417 |
default: |
|
418 |
return "And"; |
|
419 |
} |
|
420 |
} |
|
469 | 421 |
|
470 |
} |
|
422 |
/* |
|
423 |
* (non-Javadoc) |
|
424 |
* @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getRelationalOperator(int) |
|
425 |
*/ |
|
426 |
public String getRelationalOperator(int operator) { |
|
427 |
switch (operator){ |
|
428 |
case RELATIONAL_OPERATOR_IS_EQUALS_TO: |
|
429 |
return "PropertyIsEqualTo"; |
|
430 |
case RELATIONAL_OPERATOR_IS_NOT_EQUALS_TO: |
|
431 |
return "PropertyIsNotEqualTo"; |
|
432 |
case RELATIONAL_OPERATOR_IS_LESS_THAN: |
|
433 |
return "PropertyIsLessThan"; |
|
434 |
case RELATIONAL_OPERATOR_IS_GREATER_THAN: |
|
435 |
return "PropertyIsGreaterThan"; |
|
436 |
case RELATIONAL_OPERATOR_IS_LESS_THAN_OR_EQUAL_TO: |
|
437 |
return "PropertyIsLessThanOrEqualTo"; |
|
438 |
case RELATIONAL_OPERATOR_IS_GREATER_THAN_OR_EQUAL_TO: |
|
439 |
return "PropertyIsGreaterThanOrEqualTo"; |
|
440 |
case RELATIONAL_OPERATOR_IS_LIKE: |
|
441 |
return "PropertyIsLike"; |
|
442 |
case RELATIONAL_OPERATOR_IS_NULL: |
|
443 |
return "PropertyIsNull"; |
|
444 |
case RELATIONAL_OPERATOR_IS_BETWEEN: |
|
445 |
return "PropertyIsBetween"; |
|
446 |
default: |
|
447 |
return "PropertyIsLike"; |
|
448 |
} |
|
449 |
} |
|
471 | 450 |
|
472 |
public String getSeparator(int separator) { |
|
473 |
return null; |
|
474 |
} |
|
451 |
/* |
|
452 |
* (non-Javadoc) |
|
453 |
* @see org.gvsig.remoteClient.filterEncoding.AQueryLanguage#getGeometricOperator(int) |
|
454 |
*/ |
|
455 |
public String getGeometricOperator(int operator) { |
|
456 |
switch (operator){ |
|
457 |
case GEOMETRIC_OPERATOR_EQUALS: |
|
458 |
return "Equals"; |
|
459 |
case GEOMETRIC_OPERATOR_DISJOINT: |
|
460 |
return "Disjoint"; |
|
461 |
case GEOMETRIC_OPERATOR_TOUCHES: |
|
462 |
return "Touches"; |
|
463 |
case GEOMETRIC_OPERATOR_WITHIN: |
|
464 |
return "Within"; |
|
465 |
case GEOMETRIC_OPERATOR_OVERLAPS: |
|
466 |
return "Overlaps"; |
|
467 |
case GEOMETRIC_OPERATOR_CROSSES: |
|
468 |
return "Crosses"; |
|
469 |
case GEOMETRIC_OPERATOR_INTERSECT: |
|
470 |
return "Intersect"; |
|
471 |
case GEOMETRIC_OPERATOR_CONTAINS: |
|
472 |
return "Contains"; |
|
473 |
case GEOMETRIC_OPERATOR_DWITHIN: |
|
474 |
return "Dwithin"; |
|
475 |
case GEOMETRIC_OPERATOR_BEYOND: |
|
476 |
return "Beyond"; |
|
477 |
case GEOMETRIC_OPERATOR_BBOX: |
|
478 |
return "BBOX"; |
|
479 |
default: |
|
480 |
return "Equals"; |
|
481 |
} |
|
475 | 482 |
|
476 |
/** |
|
477 |
* @param isQualified the isQualified to set |
|
478 |
*/ |
|
479 |
public void setQualified(boolean isQualified) { |
|
480 |
this.isQualified = isQualified; |
|
481 |
if (isQualified){ |
|
482 |
namepacePrefix = DEFAULT_NAMESPACE_PREFIX + ":"; |
|
483 |
}else{ |
|
484 |
namepacePrefix = ""; |
|
485 |
} |
|
486 |
} |
|
483 |
} |
|
487 | 484 |
|
485 |
public String getSeparator(int separator) { |
|
486 |
return null; |
|
487 |
} |
|
488 | 488 |
|
489 |
/** |
|
490 |
* @param namepacePrefix the namepacePrefix to set |
|
491 |
*/ |
|
492 |
public void setNamepacePrefix(String namepacePrefix) { |
|
493 |
if ((namepacePrefix == null) || (namepacePrefix.equals(""))){ |
|
494 |
this.namepacePrefix = ""; |
|
495 |
}else{ |
|
496 |
this.namepacePrefix = namepacePrefix + ":"; |
|
497 |
} |
|
498 |
} |
|
489 |
/** |
|
490 |
* @param isQualified the isQualified to set |
|
491 |
*/ |
|
492 |
public void setQualified(boolean isQualified) { |
|
493 |
this.isQualified = isQualified; |
|
494 |
if (isQualified){ |
|
495 |
nameSpacePrefix = DEFAULT_NAMESPACE_PREFIX + ":"; |
|
496 |
}else{ |
|
497 |
nameSpacePrefix = ""; |
|
498 |
} |
|
499 |
} |
|
499 | 500 |
|
500 | 501 |
|
501 |
/** |
|
502 |
* @param hasBlankSpaces the hasBlankSpaces to set |
|
503 |
*/ |
|
504 |
public void setHasBlankSpaces(boolean hasBlankSpaces) { |
|
505 |
this.hasBlankSpaces = hasBlankSpaces; |
|
506 |
} |
|
502 |
/** |
|
503 |
* @param namepacePrefix the namepacePrefix to set |
|
504 |
*/ |
|
505 |
public void setNamepacePrefix(String namepacePrefix) { |
|
506 |
if ((namepacePrefix == null) || (namepacePrefix.equals(""))){ |
|
507 |
this.nameSpacePrefix = ""; |
|
508 |
}else{ |
|
509 |
this.nameSpacePrefix = namepacePrefix + ":"; |
|
510 |
} |
|
511 |
} |
|
512 |
|
|
513 |
|
|
514 |
/** |
|
515 |
* @param hasBlankSpaces the hasBlankSpaces to set |
|
516 |
*/ |
|
517 |
public void setHasBlankSpaces(boolean hasBlankSpaces) { |
|
518 |
this.hasBlankSpaces = hasBlankSpaces; |
|
519 |
} |
|
507 | 520 |
} |
Also available in: Unified diff