Skip to content
Browse files

Fix and testcase for XML pattern facet parsing problem

  • Loading branch information...
1 parent e6c52a5 commit d8d6401101a5d185bc3d0fc9761a1b8e74d5b921 @sweco-sebhar sweco-sebhar committed Apr 24, 2013
View
49 ...library/sample-data/src/main/resources/org/geotools/test-data/xml/patternfacet/states.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs"
+ xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp"
+ xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.openplans.org/topp states.xsd http://www.opengis.net/wfs ../wfs/WFS-basic.xsd">
+ <gml:boundedBy>
+ <gml:null>unknown</gml:null>
+ </gml:boundedBy>
+ <gml:featureMember>
+ <topp:states fid="states.3">
+ <topp:the_geom>
+ <gml:MultiPolygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
+ <gml:polygonMember>
+ <gml:Polygon>
+ <gml:outerBoundaryIs>
+ <gml:LinearRing>
+ <gml:coordinates xmlns:gml="http://www.opengis.net/gml"
+ decimal="." cs="," ts=" ">-75.70742,38.557476 -75.71106,38.649551 -75.724937,38.83017 -75.752922,39.141548 -75.761658,39.247753 -75.764664,39.295849 -75.772697,39.383007 -75.791435,39.723755 -75.775269,39.724442 -75.745934,39.774818 -75.695114,39.820347 -75.644341,39.838196 -75.583794,39.840008 -75.470345,39.826435 -75.42083,39.79887 -75.412117,39.789658 -75.428009,39.77813 -75.460754,39.763248 -75.475128,39.741718 -75.476334,39.719971 -75.489639,39.714745 -75.610725,39.612793 -75.562996,39.566723 -75.590187,39.463768 -75.515572,39.36694 -75.402481,39.257637 -75.397728,39.073036 -75.324852,39.012386 -75.307899,38.945911 -75.190941,38.80867 -75.083138,38.799812 -75.045998,38.44949 -75.068298,38.449963 -75.093094,38.450451 -75.350204,38.455208 -75.69915,38.463066 -75.70742,38.557476</gml:coordinates>
+ </gml:LinearRing>
+ </gml:outerBoundaryIs>
+ </gml:Polygon>
+ </gml:polygonMember>
+ </gml:MultiPolygon>
+ </topp:the_geom>
+ <topp:STATE_NAME>Delaware</topp:STATE_NAME>
+ <topp:STATE_FIPS>10</topp:STATE_FIPS>
+ <topp:SUB_REGION>S Atl</topp:SUB_REGION>
+ <topp:STATE_ABBR>DE</topp:STATE_ABBR>
+ <topp:LAND_KM>5062.456</topp:LAND_KM>
+ <topp:WATER_KM>1385.022</topp:WATER_KM>
+ <topp:PERSONS>666168.0</topp:PERSONS>
+ <topp:FAMILIES>175867.0</topp:FAMILIES>
+ <topp:HOUSHOLD>247497.0</topp:HOUSHOLD>
+ <topp:MALE>322968.0</topp:MALE>
+ <topp:FEMALE>343200.0</topp:FEMALE>
+ <topp:WORKERS>247566.0</topp:WORKERS>
+ <topp:DRVALONE>258087.0</topp:DRVALONE>
+ <topp:CARPOOL>42968.0</topp:CARPOOL>
+ <topp:PUBTRANS>8069.0</topp:PUBTRANS>
+ <topp:EMPLOYED>335147.0</topp:EMPLOYED>
+ <topp:UNEMPLOY>13945.0</topp:UNEMPLOY>
+ <topp:SERVICE>87973.0</topp:SERVICE>
+ <topp:MANUAL>44140.0</topp:MANUAL>
+ <topp:P_MALE>0.485</topp:P_MALE>
+ <topp:P_FEMALE>0.515</topp:P_FEMALE>
+ <topp:SAMP_POP>102776.0</topp:SAMP_POP>
+ </topp:states>
+ </gml:featureMember>
+</wfs:FeatureCollection>
View
68 ...library/sample-data/src/main/resources/org/geotools/test-data/xml/patternfacet/states.xsd
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:gml="http://www.opengis.net/gml" xmlns:topp="http://www.openplans.org/topp"
+ elementFormDefault="qualified" targetNamespace="http://www.openplans.org/topp">
+ <xsd:import namespace="http://www.opengis.net/gml"
+ schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2/feature.xsd" />
+ <xsd:complexType name="statesType">
+ <xsd:complexContent>
+ <xsd:extension base="gml:AbstractFeatureType">
+ <xsd:sequence>
+ <xsd:element maxOccurs="1" minOccurs="0" name="the_geom"
+ nillable="true" type="gml:MultiPolygonPropertyType" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="STATE_NAME"
+ nillable="true" type="topp:STATE_NAME" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="STATE_FIPS"
+ nillable="true" type="xsd:string" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="SUB_REGION"
+ nillable="true" type="xsd:string" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="STATE_ABBR"
+ nillable="true" type="xsd:string" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="LAND_KM"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="WATER_KM"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="PERSONS"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="FAMILIES"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="HOUSHOLD"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="MALE"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="FEMALE"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="WORKERS"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="DRVALONE"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="CARPOOL"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="PUBTRANS"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="EMPLOYED"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="UNEMPLOY"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="SERVICE"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="MANUAL"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="P_MALE"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="P_FEMALE"
+ nillable="true" type="xsd:double" />
+ <xsd:element maxOccurs="1" minOccurs="0" name="SAMP_POP"
+ nillable="true" type="xsd:double" />
+ </xsd:sequence>
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+ <xsd:simpleType name="STATE_NAME">
+ <xsd:restriction base="xsd:string">
+ <xsd:pattern value="[a-zA-Z]+" />
+ </xsd:restriction>
+ </xsd:simpleType>
+ <xsd:element name="states" substitutionGroup="gml:_Feature"
+ type="topp:statesType" />
+</xsd:schema>
View
2 modules/library/xml/src/main/java/org/geotools/xml/schema/impl/SimpleTypeGT.java
@@ -414,7 +414,7 @@ private Object getRestValue(Element element, ElementValue value,
case Facet.PATTERN:
- if (val.split(constraints[i].getValue()).length != 1) {
+ if (val.split(constraints[i].getValue()).length != 0) {
throw new SAXException("Does not match pattern");
}
View
32 modules/library/xml/src/test/java/org/geotools/xml/GMLParserTest.java
@@ -142,6 +142,38 @@ public void skippedtestMoreFeatures(){
}
}
+ public void testPatternSchema(){
+ try {
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ spf.setNamespaceAware(true);
+ spf.setValidating(false);
+
+ SAXParser parser = spf.newSAXParser();
+
+ String path = "xml/patternfacet/states.xml";
+ File f = TestData.copy(this,path);
+ TestData.copy(this,"xml/patternfacet/states.xsd");
+ URI u = f.toURI();
+
+ XMLSAXHandler xmlContentHandler = new XMLSAXHandler(u,null);
+ XMLSAXHandler.setLogLevel(Level.WARNING);
+ XSISAXHandler.setLogLevel(Level.WARNING);
+ XMLElementHandler.setLogLevel(Level.WARNING);
+ XSIElementHandler.setLogLevel(Level.WARNING);
+
+ parser.parse(f, xmlContentHandler);
+
+ Object doc = xmlContentHandler.getDocument();
+ assertNotNull("Document missing", doc);
+
+ checkFeatureCollection((SimpleFeatureCollection)doc);
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ fail(e.toString());
+ }
+ }
+
public void testFMERoadsFeatures() {
try {
SAXParserFactory spf = SAXParserFactory.newInstance();

0 comments on commit d8d6401

Please sign in to comment.
Something went wrong with that request. Please try again.