use of eu.esdihumboldt.hale.common.core.io.project.ProjectReader in project hale by halestudio.
the class ProjectServiceImpl method loadTemplate.
@Override
public void loadTemplate(Project project) {
// no change check as this is done by clean before a new project is
// loaded
ProjectReader reader = new DummyProjectReader(project);
ProjectResourcesUtil.executeProvider(reader, openProjectAdvisor, null);
}
use of eu.esdihumboldt.hale.common.core.io.project.ProjectReader in project hale by halestudio.
the class ArchiveProjectReader method execute.
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
// copy resources to a temporary directory
tempDir = Files.createTempDir();
IOUtils.extract(tempDir, getSource().getInput());
// create the project file via XMLProjectReader
File baseFile = new File(tempDir, "project.halex");
ProjectReader reader;
if (!baseFile.exists()) {
// look for project file
log.debug("Default project file not found, looking for other candidates.");
String candidate = ProjectIO.findProjectFile(tempDir);
if (candidate != null) {
log.info(MessageFormat.format("Loading {0} as project file from archive", candidate));
baseFile = new File(tempDir, candidate);
}
reader = HaleIO.findIOProvider(ProjectReader.class, new FileIOSupplier(baseFile), candidate);
if (reader == null) {
reporter.error(new IOMessageImpl("Could not find reader for project file " + candidate, null));
reporter.setSuccess(false);
return reporter;
}
} else {
// default project file
reader = new XMLProjectReader();
}
LocatableInputSupplier<InputStream> tempSource = new FileIOSupplier(baseFile);
// save old save configuration
LocatableInputSupplier<? extends InputStream> oldSource = getSource();
setSource(tempSource);
reader.setSource(tempSource);
reader.setProjectFiles(getProjectFiles());
IOReport report = reader.execute(progress);
Project readProject = reader.getProject();
if (readProject != null) {
/*
* Because the original source is only available here, update the
* project's resource paths here.
*
* The only drawback is that the UILocationUpdater cannot be used.
*/
LocationUpdater updater = new LocationUpdater(readProject, tempSource.getLocation());
// update resources
// resources are made absolute (else they can't be found afterwards)
updater.updateProject(false);
}
// set the real source
setSource(oldSource);
// set the read project
setProjectChecked(readProject, reporter);
return report;
}
use of eu.esdihumboldt.hale.common.core.io.project.ProjectReader in project hale by halestudio.
the class ProjectReference method loadProjectInfo.
/**
* Load project information.
*
* @param projectFile the project file
* @param reportHandler the report handler
* @return the project info or <code>null</code> if the project file could
* not be loaded
*/
protected Project loadProjectInfo(File projectFile, ReportHandler reportHandler) {
FileIOSupplier in = new FileIOSupplier(projectFile);
ProjectReader reader = HaleIO.findIOProvider(ProjectReader.class, in, projectFile.getName());
reader.setSource(in);
try {
IOReport report = reader.execute(null);
reportHandler.publishReport(report);
} catch (Exception e) {
log.error("Failed to load project information for project at " + projectFile.getAbsolutePath(), e);
return null;
}
return reader.getProject();
}
use of eu.esdihumboldt.hale.common.core.io.project.ProjectReader 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.project.ProjectReader 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