Search in sources :

Example 1 with ProjectReader

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);
}
Also used : ProjectReader(eu.esdihumboldt.hale.common.core.io.project.ProjectReader)

Example 2 with ProjectReader

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;
}
Also used : Project(eu.esdihumboldt.hale.common.core.io.project.model.Project) LocationUpdater(eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater) InputStream(java.io.InputStream) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) File(java.io.File) ProjectReader(eu.esdihumboldt.hale.common.core.io.project.ProjectReader)

Example 3 with ProjectReader

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();
}
Also used : IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) FileIOSupplier(eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier) ProjectReader(eu.esdihumboldt.hale.common.core.io.project.ProjectReader) IOException(java.io.IOException)

Example 4 with ProjectReader

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.");
    }
}
Also used : DefaultInputSupplier(eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier) ProjectReader(eu.esdihumboldt.hale.common.core.io.project.ProjectReader)

Example 5 with ProjectReader

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

ProjectReader (eu.esdihumboldt.hale.common.core.io.project.ProjectReader)5 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)2 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)2 FileIOSupplier (eu.esdihumboldt.hale.common.core.io.supplier.FileIOSupplier)2 Project (eu.esdihumboldt.hale.common.core.io.project.model.Project)1 LocationUpdater (eu.esdihumboldt.hale.common.core.io.project.util.LocationUpdater)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1