use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.
the class XmlFeatureTest method testReadSimpleFeatureOldEnc.
@Test
public void testReadSimpleFeatureOldEnc() throws JAXBException, IOException, XMLStreamException {
final XmlFeatureReader readerGml = new JAXPStreamFeatureReader(simpleTypeFull);
readerGml.getProperties().put(JAXPStreamFeatureReader.BINDING_PACKAGE, "GML");
Object obj = readerGml.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc.xml"));
assertTrue(obj instanceof Feature);
Feature result = (Feature) obj;
assertEquals(simpleFeatureFull, result);
obj = readerGml.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc2.xml"));
assertTrue(obj instanceof Feature);
result = (Feature) obj;
assertEquals(simpleFeatureFull, result);
// adding lineString encoding
obj = readerGml.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc3.xml"));
readerGml.dispose();
assertTrue(obj instanceof Feature);
result = (Feature) obj;
assertEquals(simpleFeatureFull, result);
/*
* Not working with JTSWrapper binding mode for JAXP Feature Writer
*
* working for Polygon
* working for LineString
* not for point
*/
final XmlFeatureReader reader = new JAXPStreamFeatureReader(simpleTypeFull);
reader.getProperties().put(JAXPStreamFeatureReader.BINDING_PACKAGE, "JTSWrapper");
obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc.xml"));
assertTrue(obj instanceof Feature);
result = (Feature) obj;
assertEquals(simpleFeatureFull, result);
// adding lineString encoding
obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc2.xml"));
assertTrue(obj instanceof Feature);
result = (Feature) obj;
assertEquals(simpleFeatureFull, result);
// adding lineString encoding
obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureOldEnc3.xml"));
reader.dispose();
assertTrue(obj instanceof Feature);
result = (Feature) obj;
assertFalse(simpleFeatureFull.equals(result));
}
use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.
the class XmlFeatureTest method testReadSimpleCollectionEmbeddedFT.
@Ignore
@Test
public void testReadSimpleCollectionEmbeddedFT() throws JAXBException, IOException, XMLStreamException {
// verify that distant service is working properly
URL url = new URL("http://www.ifremer.fr/services/wfs1?SERVICE=WFS&VERSION=1.1.0&REQUEST=DescribeFeatureType&TYPENAME=quadrige&OUTPUTFORMAT=text/xml;%20subtype=%22gml/3.1.1%22");
final String response = getStringResponse(url.openConnection());
if (response.contains("<!-- ERROR: Failed opening layer (null) -->")) {
Logger.getLogger("org.geotoolkit.feature.xml").warning("Skipping embedded test. external service not responding correctly");
return;
}
JAXPStreamFeatureReader reader = new JAXPStreamFeatureReader();
reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
Object obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/featureCollectionEmbedFT.xml"));
reader.dispose();
assertTrue(obj instanceof FeatureSet);
reader = new JAXPStreamFeatureReader();
reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/featureCollectionEmbedFT2.xml"));
reader.dispose();
assertTrue(obj instanceof FeatureSet);
obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/featureCollectionEmbedFT3.xml"));
reader.dispose();
assertTrue(obj instanceof FeatureSet);
}
use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.
the class XmlFeatureTest method testReadSimpleFeatureWithAtts.
@Test
public void testReadSimpleFeatureWithAtts() throws JAXBException, IOException, XMLStreamException {
final XmlFeatureReader reader = new JAXPStreamFeatureReader(typeWithAtts);
Object obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/SimpleFeatureWithAttribute.xml"));
reader.dispose();
assertTrue(obj instanceof Feature);
Feature result = (Feature) obj;
assertEquals(featureWithAttributes, result);
}
use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.
the class XmlFeatureTest method testReadSimpleCollection.
@Test
public void testReadSimpleCollection() throws JAXBException, IOException, XMLStreamException, DataStoreException {
final XmlFeatureReader reader = new JAXPStreamFeatureReader(simpleTypeBasic);
final Object obj = reader.read(XmlFeatureTest.class.getResourceAsStream("/org/geotoolkit/feature/xml/CollectionSimple.xml"));
reader.dispose();
assertTrue(obj instanceof FeatureSet);
FeatureSet result = (FeatureSet) obj;
assertEquals(FeatureStoreUtilities.getCount(collectionSimple), FeatureStoreUtilities.getCount(result));
assertEquals(collectionSimple.getIdentifier().get().toString(), result.getIdentifier().get().toString());
assertEquals(collectionSimple.getType(), result.getType());
try {
FeatureQuery query = new FeatureQuery();
query.setSortBy(FF.sort(FF.property("attDouble"), SortOrder.ASCENDING));
result = result.subset(query);
} catch (DataStoreException ex) {
Logger.getLogger("org.geotoolkit.feature.xml").log(Level.SEVERE, null, ex);
}
try (Stream<Feature> resultS = result.features(false);
Stream<Feature> expectedS = collectionSimple.features(false)) {
Iterator<Feature> resultIte = resultS.iterator();
Iterator<Feature> expectedIte = expectedS.iterator();
assertEquals(resultIte.next(), expectedIte.next());
assertEquals(resultIte.next(), expectedIte.next());
assertEquals(resultIte.next(), expectedIte.next());
}
}
use of org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader in project geotoolkit by Geomatys.
the class WPSIO method getFeatureReader.
/**
* Get the JAXPStreamFeatureReader to read feature. If there is a schema
* defined, the JAXPStreamFeatureReader will use it. Otherwise it will try
* to read it when reading data.
*
* @param schema location of the feature type definition.
* @return
* @throws MalformedURLException If given schema cannot be translated in a
* propert URL.
*/
public static XmlFeatureReader getFeatureReader(String schema) throws MalformedURLException {
final Collection<FeatureType> schemaTypes;
if (schema == null || (schema = schema.trim()).isEmpty()) {
schemaTypes = Collections.EMPTY_LIST;
} else {
Collection<FeatureType> types = null;
try {
final JAXBFeatureTypeReader xsdReader = new JAXBFeatureTypeReader();
final URL schemaURL = new URL(URLDecoder.decode(schema, StandardCharsets.UTF_8.name()));
types = xsdReader.read(schemaURL).getValues();
} catch (JAXBException | UnsupportedEncodingException ex) {
LOGGER.log(Level.FINE, "Cannot read schema at location " + schema, ex);
}
schemaTypes = types;
}
final JAXPStreamFeatureReader featureReader;
if (schemaTypes == null || schemaTypes.isEmpty()) {
featureReader = new JAXPStreamFeatureReader();
featureReader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
} else {
featureReader = new JAXPStreamFeatureReader(schemaTypes);
}
return featureReader;
}
Aggregations