Search in sources :

Example 21 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class IOReferenceContent method getInputStream.

@Override
public InputStream getInputStream(String pluginID, String href, Locale locale) {
    // it is an I/O provider reference
    if (href.startsWith(IO_PROVIDERS_TOPIC_PATH)) {
        String providerId = href.substring(IO_PROVIDERS_TOPIC_PATH.length());
        // strip everything after a ?
        int ind = providerId.indexOf('?');
        if (ind >= 0) {
            providerId = providerId.substring(0, ind);
        }
        // strip the .*htm? ending
        if (providerId.endsWith("html") || providerId.endsWith("htm")) {
            providerId = providerId.substring(0, providerId.lastIndexOf('.'));
        }
        try {
            return getIOProviderContent(providerId);
        } catch (Exception e) {
            log.error("Error creating instance io info page.", e);
            return null;
        }
    } else // should be an I/O provider overview by type
    if (href.startsWith(OVERVIEW_TOPIC_PATH)) {
        // extract provider type name
        String providerType = href.substring(OVERVIEW_TOPIC_PATH.length());
        // strip everything after a ?
        int ind = providerType.indexOf('?');
        if (ind >= 0) {
            providerType = providerType.substring(0, ind);
        }
        // strip the .*htm? ending
        if (providerType.endsWith("html") || providerType.endsWith("htm")) {
            providerType = providerType.substring(0, providerType.lastIndexOf('.'));
        }
        Class<? extends IOProvider> providerClass = null;
        switch(providerType) {
            case "InstanceReader":
                providerClass = InstanceReader.class;
                break;
            case "InstanceWriter":
                providerClass = InstanceWriter.class;
                break;
            case "InstanceValidator":
                providerClass = InstanceValidator.class;
                break;
        }
        if (providerClass != null) {
            final Class<? extends IOProvider> provider = providerClass;
            try {
                return getContentFromTemplate("overview." + providerType, TEMPLATE_OVERVIEW, new Callable<VelocityContext>() {

                    @Override
                    public VelocityContext call() throws Exception {
                        VelocityContext context = new VelocityContext();
                        // getProviderFactorries returns
                        // Collection<IOProviderDescriptor>
                        Collection<IOProviderDescriptor> writer = HaleIO.getProviderFactories(provider);
                        context.put("providers", writer);
                        context.put("providerType", provider.getSimpleName());
                        return context;
                    }
                });
            } catch (Exception e) {
                log.error("Error creating provider overview", e);
                return null;
            }
        }
        return null;
    }
    return null;
}
Also used : InstanceReader(eu.esdihumboldt.hale.common.instance.io.InstanceReader) InstanceValidator(eu.esdihumboldt.hale.common.instance.io.InstanceValidator) InstanceWriter(eu.esdihumboldt.hale.common.instance.io.InstanceWriter) IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) VelocityContext(org.apache.velocity.VelocityContext) IOProvider(eu.esdihumboldt.hale.common.core.io.IOProvider) TransformerException(javax.xml.transform.TransformerException) Callable(java.util.concurrent.Callable)

Example 22 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor 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)

Example 23 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class GenerateDuplicates 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.setSourceSchema(sourceSchema);
    writer.setTargetSchema(targetSchema);
    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) 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)

Example 24 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class CityGMLPropagate 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.setSourceSchema(sourceSchema);
    writer.setTargetSchema(targetSchema);
    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) 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)

Example 25 with IOProviderDescriptor

use of eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor in project hale by halestudio.

the class HaleIO method findIOProviderAndId.

/**
 * Find an I/O provider instance for the given input
 *
 * @param <T> the provider interface type
 *
 * @param providerType the provider type, usually an interface
 * @param in the input supplier to use for testing, may be <code>null</code>
 *            if the file name is not <code>null</code>
 * @param filename the file name, may be <code>null</code> if the input
 *            supplier is not <code>null</code>
 * @return a pair with the I/O provider and the corresponding identifier,
 *         both are <code>null</code> if no matching I/O provider was found
 */
@SuppressWarnings("unchecked")
public static <T extends IOProvider> Pair<T, String> findIOProviderAndId(Class<T> providerType, InputSupplier<? extends InputStream> in, String filename) {
    T reader = null;
    String providerId = null;
    IContentType contentType = HaleIO.findContentType(providerType, in, filename);
    if (contentType != null) {
        IOProviderDescriptor factory = HaleIO.findIOProviderFactory(providerType, contentType, null);
        try {
            reader = (T) factory.createExtensionObject();
            providerId = factory.getIdentifier();
        } catch (Exception e) {
            throw new RuntimeException("Could not create I/O provider", e);
        }
        if (reader != null) {
            reader.setContentType(contentType);
        }
    }
    return new Pair<T, String>(reader, providerId);
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IContentType(org.eclipse.core.runtime.content.IContentType) IOException(java.io.IOException) Pair(eu.esdihumboldt.util.Pair)

Aggregations

IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)40 IContentType (org.eclipse.core.runtime.content.IContentType)17 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)8 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)8 Label (org.eclipse.swt.widgets.Label)7 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 ComboViewer (org.eclipse.jface.viewers.ComboViewer)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)6 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)5 ArrayList (java.util.ArrayList)5 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)5 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)5 GridLayout (org.eclipse.swt.layout.GridLayout)5 IOProvider (eu.esdihumboldt.hale.common.core.io.IOProvider)4 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)4 InstanceWriter (eu.esdihumboldt.hale.common.instance.io.InstanceWriter)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4