Search in sources :

Example 76 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class StreamGmlWriterTest method testGeometryPrimitive_32_MultiLineString_Curve1.

/**
 * Test writing a {@link MultiLineString} to a GML 3.2 geometry primitive
 * type
 *
 * @throws Exception if an error occurs
 */
@Test
public void testGeometryPrimitive_32_MultiLineString_Curve1() throws Exception {
    // create the geometry
    MultiLineString mls = geomFactory.createMultiLineString(new LineString[] { createLineString(0.0) });
    Map<List<QName>, Object> values = new HashMap<List<QName>, Object>();
    // $NON-NLS-1$
    values.put(GEOMETRY_PROPERTY, mls);
    IOReport report = fillFeatureTest(// $NON-NLS-1$
    "PrimitiveTest", // $NON-NLS-1$
    getClass().getResource("/data/geom_schema/geom-gml32.xsd").toURI(), // $NON-NLS-1$
    values, // $NON-NLS-1$
    "geometryPrimitive_32_MultiLineString", // $NON-NLS-1$
    DEF_SRS_NAME, true, false);
    // $NON-NLS-1$
    assertTrue("Expected GML output to be valid", report.isSuccess());
}
Also used : MultiLineString(com.vividsolutions.jts.geom.MultiLineString) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) List(java.util.List) Test(org.junit.Test)

Example 77 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class StreamGmlWriter method findDefaultContainter.

/**
 * Find the default container element.
 *
 * @param targetIndex the target type index
 * @param reporter the reporter, may be <code>null</code>
 * @return the container XML element or <code>null</code>
 */
protected XmlElement findDefaultContainter(XmlIndex targetIndex, IOReporter reporter) {
    if (useFeatureCollection) {
        // try to find FeatureCollection element
        Iterator<XmlElement> it = targetIndex.getElements().values().iterator();
        Collection<XmlElement> fcElements = new HashSet<XmlElement>();
        while (it.hasNext()) {
            XmlElement el = it.next();
            if (isFeatureCollection(el)) {
                fcElements.add(el);
            }
        }
        if (fcElements.isEmpty() && gmlNs != null && gmlNs.equals(NS_GML)) {
            // include WFS 1.0.0 for the FeatureCollection element
            try {
                URI location = StreamGmlWriter.class.getResource("/schemas/wfs/1.0.0/WFS-basic.xsd").toURI();
                XmlSchemaReader schemaReader = new XmlSchemaReader();
                schemaReader.setSource(new DefaultInputSupplier(location));
                // FIXME to work with the extra schema it must be integrated
                // with the main schema
                // schemaReader.setSharedTypes(sharedTypes);
                IOReport report = schemaReader.execute(null);
                if (report.isSuccess()) {
                    XmlIndex wfsSchema = schemaReader.getSchema();
                    // look for FeatureCollection element
                    for (XmlElement el : wfsSchema.getElements().values()) {
                        if (isFeatureCollection(el)) {
                            fcElements.add(el);
                        }
                    }
                    // add as additional schema, replace location for
                    // verification
                    additionalSchemas.put(wfsSchema.getNamespace(), new SchemaDecorator(wfsSchema) {

                        @Override
                        public URI getLocation() {
                            return URI.create("http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd");
                        }
                    });
                    // add namespace
                    // $NON-NLS-1$
                    GmlWriterUtil.addNamespace(writer, wfsSchema.getNamespace(), "wfs");
                }
            } catch (Exception e) {
                // $NON-NLS-1$
                log.warn("Using WFS schema for the FeatureCollection definition failed", e);
            }
        }
        if (fcElements.isEmpty() && reporter != null) {
            reporter.warn(// $NON-NLS-1$
            new IOMessageImpl("No element describing a FeatureCollection found", null));
        } else {
            // select fc element TODO priorized selection (root element
            // parameters)
            XmlElement fcElement = fcElements.iterator().next();
            log.info(// $NON-NLS-1$ //$NON-NLS-2$
            "Found " + fcElements.size() + " possible FeatureCollection elements" + ", using element " + // $NON-NLS-1$
            fcElement.getName());
            return fcElement;
        }
    }
    return null;
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) XmlIndex(eu.esdihumboldt.hale.io.xsd.model.XmlIndex) URI(java.net.URI) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) URISyntaxException(java.net.URISyntaxException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) XmlElement(eu.esdihumboldt.hale.io.xsd.model.XmlElement) HashSet(java.util.HashSet)

Example 78 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class ExamplesContent method executeProvider.

/**
 * Execute the I/O provider given or specified by the given provider ID.
 *
 * @param advisor the advisor to use for configuration of the provider and
 *            handling the results
 * @param providerId the ID of the provider to execute, may be
 *            <code>null</code> if provider is set
 * @param provider the provider to execute
 * @throws Exception if executing the provider fails or if a provider with
 *             the given ID is not found
 */
@SuppressWarnings("unchecked")
private void executeProvider(@SuppressWarnings("rawtypes") IOAdvisor advisor, String providerId, IOProvider provider) throws Exception {
    if (provider == null) {
        // find and create the provider
        IOProviderDescriptor descriptor = IOProviderExtension.getInstance().getFactory(providerId);
        if (descriptor != null) {
            provider = descriptor.createExtensionObject();
        } else {
            throw new IllegalStateException("I/O provider with ID " + providerId + " not found");
        }
    }
    // use advisor to configure provider
    advisor.prepareProvider(provider);
    advisor.updateConfiguration(provider);
    // execute
    IOReport report = provider.execute(null);
    // handle results
    if (report.isSuccess()) {
        advisor.handleResults(provider);
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 79 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class GenerateDefaults method loadSchema.

private void loadSchema() throws IOProviderConfigurationException, IOException {
    System.out.println("Loading schema...");
    LocatableInputSupplier<? extends InputStream> schemaIn = new DefaultInputSupplier(context.getSchema());
    SchemaReader schemaReader = HaleIO.findIOProvider(SchemaReader.class, schemaIn, context.getSchema().getPath());
    schemaReader.setSource(schemaIn);
    IOReport report = schemaReader.execute(new NullProgressIndicator());
    if (!report.isSuccess() || !report.getErrors().isEmpty()) {
        throw new IllegalStateException("Failed to load schema");
    }
    schema = schemaReader.getSchema();
}
Also used : SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator)

Example 80 with IOReport

use of eu.esdihumboldt.hale.common.core.io.report.IOReport in project hale by halestudio.

the class GenerateDefaults method writeAlignment.

private void writeAlignment() throws Exception {
    System.out.println("Writing alignment to " + context.getOut().getAbsolutePath());
    // create alignment writer
    IContentType contentType = HalePlatform.getContentTypeManager().getContentType(ALIGNMENT_CONTENT_TYPE);
    IOProviderDescriptor factory = HaleIO.findIOProviderFactory(AlignmentWriter.class, contentType, null);
    AlignmentWriter writer = (AlignmentWriter) factory.createExtensionObject();
    // configure alignment writer
    writer.setTargetSchema(new DefaultSchemaSpace().addSchema(schema));
    writer.setTarget(new FileIOSupplier(context.getOut()));
    writer.setAlignment(alignment);
    IOReport report = writer.execute(new NullProgressIndicator());
    if (!report.isSuccess() || !report.getErrors().isEmpty()) {
        throw new IllegalStateException("Errors while writing the alignment.");
    } else {
        System.out.println("Completed successfully.");
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) DefaultSchemaSpace(eu.esdihumboldt.hale.common.schema.model.impl.DefaultSchemaSpace) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) NullProgressIndicator(eu.esdihumboldt.hale.common.core.io.impl.NullProgressIndicator) IContentType(org.eclipse.core.runtime.content.IContentType) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) AlignmentWriter(eu.esdihumboldt.hale.common.align.io.AlignmentWriter)

Aggregations

IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)102 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)34 Test (org.junit.Test)33 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)25 List (java.util.List)23 QName (javax.xml.namespace.QName)23 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)22 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)22 HashMap (java.util.HashMap)22 File (java.io.File)14 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)11 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)8 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)8 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)8 IOException (java.io.IOException)8 Ignore (org.junit.Ignore)8 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)7 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)7