[Schmitzm-commits] r1194 - trunk/src/schmitzm/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Nov 1 19:49:31 CET 2010
Author: alfonx
Date: 2010-11-01 19:49:31 +0100 (Mon, 01 Nov 2010)
New Revision: 1194
Modified:
trunk/src/schmitzm/geotools/FilterUtil.java
Log:
Fixed the creation of unvalidatable SLD code:
# org.xml.sax.SAXParseException: cvc-complex-type.2.4.b: The content of element 'ogc:Or' is not complete. One of '{"http://www.opengis.net/ogc":comparisonOps, "http://www.opengis.net/ogc":spatialOps, "http://www.opengis.net/ogc":logicOps}' is expected.
http://permalink.gmane.org/gmane.comp.gis.geoserver.user/20967
Modified: trunk/src/schmitzm/geotools/FilterUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/FilterUtil.java 2010-11-01 17:20:17 UTC (rev 1193)
+++ trunk/src/schmitzm/geotools/FilterUtil.java 2010-11-01 18:49:31 UTC (rev 1194)
@@ -29,11 +29,14 @@
******************************************************************************/
package schmitzm.geotools;
+import java.util.List;
+
import org.geotools.factory.CommonFactoryFinder;
import org.geotools.filter.FilterFactoryImpl;
import org.opengis.filter.Filter;
import org.opengis.filter.FilterFactory;
import org.opengis.filter.FilterFactory2;
+import org.opengis.filter.Or;
import com.vividsolutions.jts.geom.GeometryFactory;
@@ -60,4 +63,29 @@
public static final Filter ALLWAYS_TRUE_FILTER = FILTER_FAC2.equals(
FILTER_FAC2.literal("1"), FILTER_FAC2.literal("1"));
+ public static final Filter NEVER_TRUE_FILTER = FILTER_FAC2.equals(
+ FILTER_FAC2.literal("NEVER"), FILTER_FAC2.literal("TRUE"));
+
+ /**
+ * Problem: If <or><boolena expression></or> is used, the filter works fine
+ * in Geotools, BUT it is not validated: <br/>
+ * <code>org.xml.sax.SAXParseException: cvc-complex-type.2.4.b: The content of element 'ogc:Or' is not
+ * complete. One of '{"http://www.opengis.net/ogc":comparisonOps,
+ * "http://www.opengis.net/ogc":spatialOps, "http://www.opengis.net/ogc":logicOps}' is expected.</code>
+ * <br/>
+ * Hence, to comply with SLD validity, if there is only one element in the
+ * <code>ors</code> list, we remove the or around it.
+ */
+ public static Filter correctOrForValidation(Or or) {
+
+ List<Filter> ors = or.getChildren();
+
+ if (ors.size() == 0)
+ return NEVER_TRUE_FILTER;
+ if (ors.size() == 1)
+ return ors.get(0);
+
+ return or;
+ }
+
}
More information about the Schmitzm-commits
mailing list