Search in sources :

Example 1 with PosixDirectoryFilter

use of org.geotoolkit.nio.PosixDirectoryFilter in project geotoolkit by Geomatys.

the class GMLSparseStore method getType.

@Override
public synchronized FeatureType getType() throws DataStoreException {
    if (featureType == null) {
        final String xsd = parameters.getValue(GMLProvider.XSD);
        final String xsdTypeName = parameters.getValue(GMLProvider.XSD_TYPE_NAME);
        catalog = new GenericNameIndex();
        if (xsd != null) {
            // read types from XSD file
            final JAXBFeatureTypeReader reader = new JAXBFeatureTypeReader();
            try {
                catalog = reader.read(new URL(xsd));
                featureType = catalog.get(xsdTypeName);
            } catch (MalformedURLException | JAXBException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            }
        } else {
            final JAXPStreamFeatureReader reader = new JAXPStreamFeatureReader();
            reader.getProperties().put(JAXPStreamFeatureReader.LONGITUDE_FIRST, longitudeFirst);
            reader.getProperties().put(JAXPStreamFeatureReader.READ_EMBEDDED_FEATURE_TYPE, true);
            try {
                if (Files.isDirectory(file)) {
                    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(file, new PosixDirectoryFilter("*.gml", true))) {
                        final Iterator<Path> gmlPaths = directoryStream.iterator();
                        // get first gml file only
                        if (gmlPaths.hasNext()) {
                            final Path gmlPath = gmlPaths.next();
                            try (FeatureReader ite = reader.readAsStream(gmlPath)) {
                                catalog = reader.getFeatureTypes();
                                featureType = ite.getFeatureType();
                            }
                        }
                    }
                } else {
                    try (FeatureReader ite = reader.readAsStream(file)) {
                        catalog = reader.getFeatureTypes();
                        featureType = ite.getFeatureType();
                    }
                }
            } catch (IOException | XMLStreamException ex) {
                throw new DataStoreException(ex.getMessage(), ex);
            } finally {
                reader.dispose();
            }
        }
    }
    return featureType;
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) DataStoreException(org.apache.sis.storage.DataStoreException) PosixDirectoryFilter(org.geotoolkit.nio.PosixDirectoryFilter) JAXBException(javax.xml.bind.JAXBException) GenericNameIndex(org.geotoolkit.storage.feature.GenericNameIndex) IOException(java.io.IOException) URL(java.net.URL) XMLStreamException(javax.xml.stream.XMLStreamException) JAXBFeatureTypeReader(org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) JAXPStreamFeatureReader(org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader) FeatureReader(org.geotoolkit.storage.feature.FeatureReader)

Aggregations

IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 JAXBException (javax.xml.bind.JAXBException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DataStoreException (org.apache.sis.storage.DataStoreException)1 JAXBFeatureTypeReader (org.geotoolkit.feature.xml.jaxb.JAXBFeatureTypeReader)1 JAXPStreamFeatureReader (org.geotoolkit.feature.xml.jaxp.JAXPStreamFeatureReader)1 PosixDirectoryFilter (org.geotoolkit.nio.PosixDirectoryFilter)1 FeatureReader (org.geotoolkit.storage.feature.FeatureReader)1 GenericNameIndex (org.geotoolkit.storage.feature.GenericNameIndex)1