Search in sources :

Example 1 with ProjectFile

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();
    }
}
Also used : HaleProject(eu.esdihumboldt.hale.io.project.jaxb.generated.HaleProject) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(javax.xml.bind.JAXBException) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) JAXBContext(javax.xml.bind.JAXBContext) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) HaleProject(eu.esdihumboldt.hale.io.project.jaxb.generated.HaleProject) Unmarshaller(javax.xml.bind.Unmarshaller) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) File(java.io.File)

Example 2 with ProjectFile

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();
    }
}
Also used : IOProviderDescriptor(eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) ProjectWriter(eu.esdihumboldt.hale.common.core.io.project.ProjectWriter) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) NoStreamOutputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.NoStreamOutputSupplier) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with ProjectFile

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;
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) AdvisorProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.AdvisorProjectFile) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 4 with ProjectFile

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);
    }
}
Also used : ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) URI(java.net.URI)

Example 5 with ProjectFile

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;
}
Also used : ProjectFileFactory(eu.esdihumboldt.hale.common.core.io.project.extension.ProjectFileFactory) HashMap(java.util.HashMap) ProjectFile(eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile) ProjectFileExtension(eu.esdihumboldt.hale.common.core.io.project.extension.ProjectFileExtension)

Aggregations

ProjectFile (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFile)9 File (java.io.File)4 URI (java.net.URI)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 IOException (java.io.IOException)3 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)2 IOConfiguration (eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration)2 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)2 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ZipEntry (java.util.zip.ZipEntry)2 PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)1 IOProviderDescriptor (eu.esdihumboldt.hale.common.core.io.extension.IOProviderDescriptor)1 ProjectWriter (eu.esdihumboldt.hale.common.core.io.project.ProjectWriter)1 ProjectFileExtension (eu.esdihumboldt.hale.common.core.io.project.extension.ProjectFileExtension)1 ProjectFileFactory (eu.esdihumboldt.hale.common.core.io.project.extension.ProjectFileFactory)1 ActionProjectFile (eu.esdihumboldt.hale.common.core.io.project.extension.internal.ActionProjectFile)1 AdvisorProjectFile (eu.esdihumboldt.hale.common.core.io.project.model.AdvisorProjectFile)1