Hello Jody,
I create a little Patch which solve my Problems and also keep the "old"
functionality alive.
Perhaps it is possible that you integrate it to the 2.3.x Branch.
Tim
-----Ursprüngliche Nachricht-----
Von: Jody Garnett [mailto:[EMAIL PROTECTED]
Gesendet: Donnerstag, 26. Juli 2007 09:01
An: Tim Englich
Cc: [email protected]
Betreff: Re: [Geotools-gt2-users] NumberValue Problems Using
FilterFilter and GMLFilterDocument
Tim Englich wrote:
> Hello,
>
> I have got problems with parsing the following Filter in GeoTools 2.3.1
>
> <Filter>
> <PropertyIsEqualTo>
>
> <PropertyName>Flurstueckskennzeichen</PropertyName>
> <Literal>1201011010004500000</Literal>
> </PropertyIsEqualTo>
> </Filter>
>
>
> First of all the attribute I apply the Filter on is an String attribute.
The
> value I got in the Filter-Object after parsing the XML is an double value.
> When I convert the value back to String with the following code
>
> Double d = (Double)value;
> DecimalFormat f = new
>
DecimalFormat("0.############################################################
> ######");
> valueString =f.format(d);
>
> I got back the value 1201011010004499970.
>
> Has anyone an Idea how to solve this Problem?
>
I am afraid that 2.3 does not take the attribute type into account when
parsing,
upgrading to 2.4 will fix the problem (it leaves everything as a String
and the PropertyIsEqualsTo implementation
will convert the values to the same type for comparison).
It is exactly this kind of problem that motivated this work in GeoTools 2.4.
Jody
Index:
D:/WorkspaceGT-2.3/2.3.x/module/main/src/org/geotools/filter/FilterFilter.java
===================================================================
---
D:/WorkspaceGT-2.3/2.3.x/module/main/src/org/geotools/filter/FilterFilter.java
(revision 26228)
+++
D:/WorkspaceGT-2.3/2.3.x/module/main/src/org/geotools/filter/FilterFilter.java
(working copy)
@@ -79,6 +79,8 @@
* to be processed by endElement */
private StringBuffer characters;
+
+ private boolean convertLiteralToNumber = true;
/**
* Constructor with parent, which must implement GMLHandlerJTS.
*
@@ -94,6 +96,18 @@
logicFactory = new LogicSAXParser();
characters = new StringBuffer();
}
+
+ /**
+ * Constructor with parent, which must implement GMLHandlerJTS.
+ *
+ * @param parent The parent of this filter, to recieve the filters created.
+ * @param schema The schema that the filter will be used against.
+ */
+ public FilterFilter(FilterHandler parent, FeatureType schema,boolean
convertLiteralToNumber ) {
+ this(parent,schema);
+ this.convertLiteralToNumber = convertLiteralToNumber;
+
+ }
/**
* Checks the name of the element, and sends to the appropriate filter
@@ -255,7 +269,7 @@
filterFactory.setDistance(message, units);
} else {
LOGGER.finest("sending to expression factory: " +
message);
- expressionFactory.message(message);
+
expressionFactory.message(message,this.convertLiteralToNumber);
}
} catch (IllegalFilterException ife) {
throw new SAXException(ife);
Index:
D:/WorkspaceGT-2.3/2.3.x/module/main/src/org/geotools/filter/ExpressionSAXParser.java
===================================================================
---
D:/WorkspaceGT-2.3/2.3.x/module/main/src/org/geotools/filter/ExpressionSAXParser.java
(revision 26228)
+++
D:/WorkspaceGT-2.3/2.3.x/module/main/src/org/geotools/filter/ExpressionSAXParser.java
(working copy)
@@ -254,7 +254,7 @@
* things working, and may be the best choice in the end, but it
* should be thought through more.
*/
- public void message(String message) throws IllegalFilterException {
+ public void message(String message, boolean convertToNumber) throws
IllegalFilterException {
// TODO 2:
// AT SOME POINT MUST MAKE THIS HANDLE A TYPED FEATURE
// BY PASSING IT A FEATURE AND CHECKING ITS TYPE HERE
@@ -304,26 +304,32 @@
// like filter?)
//HACK: This should also not use exception catching, it's
//expensive and bad code practice.
- try {
- Object temp = new Integer(message);
+ if (convertToNumber){
+ try {
+ Object temp = new Integer(message);
+ ((LiteralExpression) curExprssn).setLiteral(temp);
+ currentState = "complete";
+ } catch (NumberFormatException nfe1) {
+ try {
+ Object temp = new Double(message);
+ ((LiteralExpression)
curExprssn).setLiteral(temp);
+ currentState = "complete";
+ } catch (NumberFormatException nfe2) {
+ Object temp = message;
+ ((LiteralExpression)
curExprssn).setLiteral(temp);
+ currentState = "complete";
+ }
+ }
+ }else{
+ Object temp = message;
((LiteralExpression) curExprssn).setLiteral(temp);
currentState = "complete";
- } catch (NumberFormatException nfe1) {
- try {
- Object temp = new Double(message);
- ((LiteralExpression) curExprssn).setLiteral(temp);
- currentState = "complete";
- } catch (NumberFormatException nfe2) {
- Object temp = message;
- ((LiteralExpression) curExprssn).setLiteral(temp);
- currentState = "complete";
- }
}
} else if (expFactory != null) {
- expFactory.message(message);
+ expFactory.message(message,convertToNumber);
}
} else if (expFactory != null) {
- expFactory.message(message);
+ expFactory.message(message,convertToNumber);
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users