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;
}
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.");
}
}
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.");
}
}
Aggregations