use of eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile in project hale by halestudio.
the class ProjectParser method execute.
/**
* @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
*/
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
progress.begin(Messages.ProjectParser_0, ProgressIndicator.UNKNOWN);
try {
File file;
try {
file = new File(getSource().getLocation());
} catch (IllegalArgumentException e) {
file = null;
}
String basePath = (file == null) ? (new File(".").getAbsolutePath()) : (FilenameUtils.getFullPath(file.getAbsolutePath()));
// Unmarshal the project file
JAXBContext jc;
JAXBElement<HaleProject> root;
try {
jc = JAXBContext.newInstance(PROJECT_CONTEXT, ObjectFactory.class.getClassLoader());
Unmarshaller u = jc.createUnmarshaller();
u.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
root = u.unmarshal(new StreamSource(getSource().getInput()), HaleProject.class);
} catch (JAXBException e) {
reporter.error(new IOMessageImpl("Unmarshalling the HaleProject from the given resource failed: {0}", e, -1, -1, getSource().getLocation()));
reporter.setSuccess(false);
return reporter;
}
project = new Project();
projectFiles = new HashMap<String, ProjectFile>();
report = reporter;
HaleProject haleProject = root.getValue();
// populate project and project files
loadProject(haleProject);
loadSchemas(haleProject, basePath);
loadAlignment(haleProject, basePath);
loadStyle(haleProject, basePath);
loadInstances(haleProject, basePath);
loadTasks(haleProject, basePath);
loadConfig(haleProject);
report = null;
reporter.setSuccess(true);
return reporter;
} finally {
progress.end();
}
}
use of eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile in project hale by halestudio.
the class ProjectServiceImpl method save.
/**
* @see ProjectService#save()
*/
@Override
public void save() {
File projectFile;
IOConfiguration saveConfig;
synchronized (this) {
projectFile = this.projectFile;
saveConfig = main.getSaveConfiguration();
}
if (projectFile != null || canSaveTo(projectLocation)) {
Collection<IOProviderDescriptor> providers = HaleIO.getProviderFactories(ProjectWriter.class);
// use configuration from previous save if possible
if (saveConfig != null) {
// get provider ...
ProjectWriter writer = null;
for (IOProviderDescriptor factory : providers) {
if (factory.getIdentifier().equals(saveConfig.getProviderId())) {
/*
* Check if the content type the project was loaded with
* is supported for saving.
*
* Example for a changed content type: A saved project
* archive may have been extracted and the internal XML
* project file loaded.
*/
if (projectLoadContentType != null) {
if (factory.getSupportedTypes() == null || !factory.getSupportedTypes().contains(projectLoadContentType)) {
log.warn("Project cannot be saved with the same settings it was originally saved with, as the content type has changed.");
break;
}
}
try {
writer = (ProjectWriter) factory.createExtensionObject();
} catch (Exception e) {
log.error("Could not create project writer", e);
}
}
}
if (writer != null) {
// configure provider
writer.loadConfiguration(saveConfig.getProviderConfiguration());
// moved externally)
if (projectFile != null) {
writer.setTarget(new FileIOSupplier(projectFile));
} else {
writer.setTarget(new NoStreamOutputSupplier(projectLocation));
}
ListenableFuture<IOReport> result = ProjectResourcesUtil.executeProvider(writer, saveProjectAdvisor, true, null);
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
try {
IOReport report = result.get();
if (!report.isSuccess()) {
log.userError("The project could not be saved. Please check the report for more details.");
}
} catch (InterruptedException | ExecutionException e) {
log.userError("The project could not be saved.", e);
}
}
});
} else {
log.info("The project cannot be saved because the format the project was saved with is not available or has changed.");
// use save as instead
saveAs();
}
} else if (projectFile != null) {
// use I/O provider and content type mechanisms to try saving
// the project file
ProjectWriter writer = HaleIO.findIOProvider(ProjectWriter.class, new FileIOSupplier(projectFile), projectFile.getAbsolutePath());
if (writer != null) {
ProjectResourcesUtil.executeProvider(writer, saveProjectAdvisor, null);
} else {
log.error("The project cannot be saved because the format is not available.");
// use save as instead
saveAs();
}
} else {
saveAs();
}
} else {
saveAs();
}
}
use of eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile in project hale by halestudio.
the class ActionProjectFile method load.
/**
* @see ProjectFile#load(InputStream)
*/
@Override
public void load(InputStream in) throws Exception {
if (applyFile != null && !applyFile.delete()) {
applyFile.deleteOnExit();
}
// direct the stream to a temporary file
File tmpFile = File.createTempFile("project-file", null);
OutputStream out = new BufferedOutputStream(new FileOutputStream(tmpFile));
try {
IOUtils.copy(in, out);
out.flush();
} finally {
out.close();
in.close();
}
applyFile = tmpFile;
}
use of eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile in project hale by halestudio.
the class HaleConnectProjectExportAdvisor method updateConfiguration.
@Override
public void updateConfiguration(HaleConnectProjectWriter provider) {
super.updateConfiguration(provider);
Map<String, ProjectFile> files = ProjectIO.createDefaultProjectFiles(HaleUI.getServiceProvider());
provider.setProjectFiles(files);
URI projectLocation = getService(ProjectService.class).getLoadLocation();
if (projectLocation != null) {
provider.setPreviousTarget(projectLocation);
}
}
use of eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile in project hale by halestudio.
the class ProjectIO method createDefaultProjectFiles.
/**
* Create a set of default project files for use with {@link ProjectReader}
* and {@link ProjectWriter}
*
* @param serviceProvider the service provider to use for eventual I/O
* advisors created
* @return the default project files
*/
public static Map<String, ProjectFile> createDefaultProjectFiles(ServiceProvider serviceProvider) {
Map<String, ProjectFile> result = new HashMap<String, ProjectFile>();
Collection<ProjectFileFactory> elements = new ProjectFileExtension(serviceProvider).getElements();
for (ProjectFileFactory element : elements) {
result.put(element.getId(), element.createProjectFile());
}
return result;
}
Aggregations