Search in sources :

Example 71 with DefaultInputSupplier

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

the class URLSource method detectContentType.

/**
 * Detect the content type
 *
 * @return the detected content type or <code>null</code>
 */
private IContentType detectContentType() {
    final Display display = PlatformUI.getWorkbench().getDisplay();
    final AtomicReference<String> sourceString = new AtomicReference<String>();
    final AtomicReference<URI> sourceURI = new AtomicReference<URI>();
    display.syncExec(new Runnable() {

        @Override
        public void run() {
            if (sourceURL.isValid() && sourceURL.getURI() != null) {
                sourceString.set(sourceURL.getStringValue());
                try {
                    sourceURI.set(sourceURL.getURI());
                } catch (Throwable e) {
                    getPage().setErrorMessage(e.getLocalizedMessage());
                }
            }
        }
    });
    if (sourceURI.get() != null && sourceString.get() != null) {
        // determine content type
        Collection<IContentType> filteredTypes;
        filteredTypes = HaleIO.findContentTypesFor(supportedTypes, new DefaultInputSupplier(sourceURI.get()), sourceString.get());
        if (!filteredTypes.isEmpty()) {
            return filteredTypes.iterator().next();
        }
    }
    return null;
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) AtomicReference(java.util.concurrent.atomic.AtomicReference) IContentType(org.eclipse.core.runtime.content.IContentType) URI(java.net.URI) Display(org.eclipse.swt.widgets.Display)

Example 72 with DefaultInputSupplier

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

the class ProjectServiceImpl method load.

/**
 * @see ProjectService#load(URI)
 */
@Override
public void load(URI uri) {
    // no change check as this is done by clean before a new project is
    // loaded
    // use I/O provider and content type mechanisms to enable loading of a
    // project file
    ProjectReader reader = HaleIO.findIOProvider(ProjectReader.class, new DefaultInputSupplier(uri), uri.getPath());
    if (reader != null) {
        // configure reader
        reader.setSource(new DefaultInputSupplier(uri));
        ProjectResourcesUtil.executeProvider(reader, openProjectAdvisor, null);
    } else {
        log.userError("The project format is not supported.");
    }
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) ProjectReader(eu.esdihumboldt.hale.common.core.io.project.ProjectReader)

Example 73 with DefaultInputSupplier

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

the class ProjectServiceImpl method update.

@Override
public void update() {
    // no change check as this is done by clean before a new project is
    // loaded
    URI currentLocation = null;
    synchronized (this) {
        currentLocation = projectLocation;
    }
    if (currentLocation != null && Arrays.asList("file", "http", "https").contains(currentLocation.getScheme())) {
        // use I/O provider and content type mechanisms to enable loading of
        // a project file
        ProjectReader reader = HaleIO.findIOProvider(ProjectReader.class, new DefaultInputSupplier(currentLocation), currentLocation.getPath());
        if (reader != null) {
            // configure reader
            reader.setSource(new DefaultInputSupplier(currentLocation));
            ProjectResourcesUtil.executeProvider(reader, updateProjectAdvisor, null);
        } else {
            log.userError("The project format is not supported.");
        }
    } else {
        log.userError("The project needs to be saved to a file before you can reload it.");
    }
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) URI(java.net.URI) ProjectReader(eu.esdihumboldt.hale.common.core.io.project.ProjectReader)

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