Search in sources :

Example 16 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class SpatiaLiteSchemaReader method loadConfiguration.

@Override
public void loadConfiguration(Map<String, Value> configuration) {
    super.loadConfiguration(configuration);
    Value source = configuration.get(PARAM_SOURCE);
    if (source != null && !source.isEmpty()) {
        setSource(new DefaultInputSupplier(URI.create(source.as(String.class))));
    }
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Value(eu.esdihumboldt.hale.common.core.io.Value)

Example 17 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class AbstractHandlerTest method loadXMLInstances.

/**
 * Load an instance collection from a GML file.
 *
 * @param schemaLocation the GML application schema location
 * @param xmlLocation the GML file location
 * @param interpolConfig the interpolation configuration
 * @return the instance collection
 * @throws IOException if reading schema or instances failed
 * @throws IOProviderConfigurationException if the I/O providers were not
 *             configured correctly
 */
public static InstanceCollection loadXMLInstances(URI schemaLocation, URI xmlLocation, @Nullable ReaderConfiguration interpolConfig) throws IOException, IOProviderConfigurationException {
    SchemaReader reader = new XmlSchemaReader();
    reader.setSharedTypes(null);
    reader.setSource(new DefaultInputSupplier(schemaLocation));
    IOReport schemaReport = reader.execute(null);
    assertTrue(schemaReport.isSuccess());
    Schema sourceSchema = reader.getSchema();
    InstanceReader instanceReader = new GmlInstanceReader();
    instanceReader.setSource(new DefaultInputSupplier(xmlLocation));
    instanceReader.setSourceSchema(sourceSchema);
    if (interpolConfig != null) {
        interpolConfig.apply(instanceReader);
    }
    IOReport instanceReport = instanceReader.execute(null);
    assertTrue(instanceReport.isSuccess());
    return instanceReader.getInstances();
}
Also used : InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) SchemaReader(eu.esdihumboldt.hale.common.schema.io.SchemaReader) XmlSchemaReader(eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) Schema(eu.esdihumboldt.hale.common.schema.model.Schema) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) GmlInstanceReader(eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)

Example 18 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class AppSchemaIsolatedWorkspacesMappingTest method loadSchema.

private static Schema loadSchema(SchemaReader schemaReader, String resource) throws Exception {
    DefaultInputSupplier input = new DefaultInputSupplier(AppSchemaIsolatedWorkspacesMappingTest.class.getResource(resource).toURI());
    schemaReader.setSharedTypes(new DefaultTypeIndex());
    schemaReader.setSource(input);
    schemaReader.validate();
    IOReport report = schemaReader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return schemaReader.getSchema();
}
Also used : DefaultTypeIndex(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeIndex) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 19 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class AppSchemaMappingTest method loadSchema.

private static Schema loadSchema(SchemaReader schemaReader, String resource) throws Exception {
    DefaultInputSupplier input = new DefaultInputSupplier(AppSchemaMappingTest.class.getResource(resource).toURI());
    schemaReader.setSharedTypes(new DefaultTypeIndex());
    schemaReader.setSource(input);
    schemaReader.validate();
    IOReport report = schemaReader.execute(null);
    assertTrue(report.isSuccess());
    assertTrue("Errors are contained in the report", report.getErrors().isEmpty());
    return schemaReader.getSchema();
}
Also used : DefaultTypeIndex(eu.esdihumboldt.hale.common.schema.model.impl.DefaultTypeIndex) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport)

Example 20 with DefaultInputSupplier

use of eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier in project hale by halestudio.

the class AbstractAppSchemaConfigurator method updateTargetSchemaResources.

// TODO: code adapted from ArchiveProjectWriter: how to avoid duplication?
private Map<URI, String> updateTargetSchemaResources(File targetDirectory, ProgressIndicator progress, IOReporter reporter) throws IOException {
    progress.begin("Copy resources", ProgressIndicator.UNKNOWN);
    Project project = (Project) getProjectInfo();
    // resource locations mapped to new resource path
    Map<URI, String> handledResources = new HashMap<>();
    try {
        List<IOConfiguration> resources = project.getResources();
        // every resource needs his own directory
        int count = 0;
        Iterator<IOConfiguration> iter = resources.iterator();
        while (iter.hasNext()) {
            IOConfiguration resource = iter.next();
            if (resource.getActionId().equals(SchemaIO.ACTION_LOAD_TARGET_SCHEMA)) {
                // get resource path
                Map<String, Value> providerConfig = resource.getProviderConfiguration();
                String path = providerConfig.get(ImportProvider.PARAM_SOURCE).toString();
                URI pathUri;
                try {
                    pathUri = new URI(path);
                } catch (URISyntaxException e1) {
                    reporter.error(new IOMessageImpl("Skipped resource because of invalid URI: " + path, e1));
                    continue;
                }
                // check if path was already handled
                if (handledResources.containsKey(pathUri)) {
                    // skip copying the resource
                    continue;
                }
                String scheme = pathUri.getScheme();
                LocatableInputSupplier<? extends InputStream> input = null;
                if (scheme != null) {
                    if (scheme.equals("http") || scheme.equals("https") || scheme.equals("file") || scheme.equals("platform") || scheme.equals("bundle") || scheme.equals("jar")) {
                        input = new DefaultInputSupplier(pathUri);
                    } else {
                        continue;
                    }
                } else {
                    // now can't open that, can we?
                    reporter.error(new IOMessageImpl("Skipped resource because it cannot be loaded from " + pathUri.toString(), null));
                    continue;
                }
                progress.setCurrentTask("Copying resource at " + path);
                // every resource file is copied into an own resource
                // directory in the target directory
                String resourceFolder = "_schemas";
                if (count > 0) {
                    resourceFolder += count;
                }
                File newDirectory = new File(targetDirectory, resourceFolder);
                try {
                    newDirectory.mkdir();
                } catch (SecurityException e) {
                    throw new IOException("Can not create directory " + newDirectory.toString(), e);
                }
                // the filename
                String name = path.toString().substring(path.lastIndexOf("/") + 1, path.length());
                // remove any query string from the filename
                int queryIndex = name.indexOf('?');
                if (queryIndex >= 0) {
                    name = name.substring(0, queryIndex);
                }
                if (name.isEmpty()) {
                    name = "file";
                }
                File newFile = new File(newDirectory, name);
                Path target = newFile.toPath();
                // retrieve the resource advisor
                Value ct = providerConfig.get(ImportProvider.PARAM_CONTENT_TYPE);
                IContentType contentType = null;
                if (ct != null) {
                    contentType = HalePlatform.getContentTypeManager().getContentType(ct.as(String.class));
                }
                ResourceAdvisor ra = ResourceAdvisorExtension.getInstance().getAdvisor(contentType);
                // copy the resource
                progress.setCurrentTask("Copying resource at " + path);
                ra.copyResource(input, target, contentType, true, reporter);
                // store new path for resource
                String newPath = resourceFolder + "/" + name;
                handledResources.put(pathUri, newPath);
                count++;
            }
        }
    } finally {
        progress.end();
    }
    return handledResources;
}
Also used : Path(java.nio.file.Path) DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) HashMap(java.util.HashMap) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IContentType(org.eclipse.core.runtime.content.IContentType) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) ResourceAdvisor(eu.esdihumboldt.hale.common.core.io.ResourceAdvisor) Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) Value(eu.esdihumboldt.hale.common.core.io.Value) File(java.io.File)

Aggregations

DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)73 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)34 URI (java.net.URI)30 Test (org.junit.Test)21 Schema (eu.esdihumboldt.hale.common.schema.model.Schema)15 XmlIndex (eu.esdihumboldt.hale.io.xsd.model.XmlIndex)15 IOException (java.io.IOException)13 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)11 XmlElement (eu.esdihumboldt.hale.io.xsd.model.XmlElement)11 SchemaReader (eu.esdihumboldt.hale.common.schema.io.SchemaReader)10 TypeDefinition (eu.esdihumboldt.hale.common.schema.model.TypeDefinition)10 XmlSchemaReader (eu.esdihumboldt.hale.io.xsd.reader.XmlSchemaReader)10 QName (javax.xml.namespace.QName)10 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)9 InstanceReader (eu.esdihumboldt.hale.common.instance.io.InstanceReader)7 CSVSchemaReader (eu.esdihumboldt.hale.io.csv.reader.internal.CSVSchemaReader)7 GmlInstanceReader (eu.esdihumboldt.hale.io.gml.reader.internal.GmlInstanceReader)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)6 GroupPropertyDefinition (eu.esdihumboldt.hale.common.schema.model.GroupPropertyDefinition)6 File (java.io.File)6