Search in sources :

Example 11 with PathUpdate

use of eu.esdihumboldt.hale.common.core.io.PathUpdate in project hale by halestudio.

the class PathUpdateTest method testReuse.

/**
 * Test reusing the FilePathUpdate object
 */
@Test
public void testReuse() {
    String orgPath = "C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/t1t2.hale";
    String path = "C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/t1t2.hale";
    PathUpdate update = new PathUpdate(URI.create("file:/" + orgPath), URI.create("file:/" + path));
    URI file = URI.create("file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/t1.xsd");
    String correct = "file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/t1.xsd";
    String newpath = update.changePath(file).toString();
    assertEquals(correct, newpath);
    // reuse PathUpdate with the same settings
    file = URI.create("file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/schemas/t1.xsd");
    correct = "file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/schemas/t1.xsd";
    newpath = update.changePath(file).toString();
    assertEquals(correct, newpath);
}
Also used : PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) URI(java.net.URI) Test(org.junit.Test)

Example 12 with PathUpdate

use of eu.esdihumboldt.hale.common.core.io.PathUpdate in project hale by halestudio.

the class PathUpdateTest method testSubfolder2.

/**
 * Extended real world example - file in a subfolder, project file renamed
 */
@Test
public void testSubfolder2() {
    String orgPath = "C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/t1t2.hale";
    String path = "C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/t1t2_alt.hale";
    PathUpdate update = new PathUpdate(URI.create("file:/" + orgPath), URI.create("file:/" + path));
    URI file = URI.create("file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/unification/schemas/t1.xsd");
    String correct = "file:/C:/Users/sitemple/Entwicklung/hale/cst/plugins/eu.esdihumboldt.cst.test/src/testdata/propmerge/schemas/t1.xsd";
    String newpath = update.changePath(file).toString();
    assertEquals(correct, newpath);
}
Also used : PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) URI(java.net.URI) Test(org.junit.Test)

Example 13 with PathUpdate

use of eu.esdihumboldt.hale.common.core.io.PathUpdate in project hale by halestudio.

the class CastorAlignmentWriter method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save hale alignment", ProgressIndicator.UNKNOWN);
    PathUpdate pathUpdate = new PathUpdate(getProjectLocation(), getTarget().getLocation());
    OutputStream out = getTarget().getOutput();
    try {
        CastorAlignmentIO.save(getAlignment(), out, pathUpdate);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
        return reporter;
    } finally {
        out.close();
    }
    progress.end();
    reporter.setSuccess(true);
    return reporter;
}
Also used : OutputStream(java.io.OutputStream) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Example 14 with PathUpdate

use of eu.esdihumboldt.hale.common.core.io.PathUpdate in project hale by halestudio.

the class JaxbAlignmentIO method printCell.

/**
 * Print a cell to an output stream (intended for tests/debugging).
 *
 * @param cell the cell to print
 * @param out the output stream
 * @throws Exception if an error occurs trying to print the cell
 */
public static void printCell(MutableCell cell, OutputStream out) throws Exception {
    DefaultAlignment alignment = new DefaultAlignment();
    alignment.addCell(cell);
    IOReporter reporter = new DefaultIOReporter(new Locatable() {

        @Override
        public URI getLocation() {
            return null;
        }
    }, "Print cell", null, false);
    PathUpdate pathUpdate = new PathUpdate(null, null);
    AlignmentType at = convert(alignment, reporter, pathUpdate);
    CellType ct = (CellType) at.getCellOrModifier().get(0);
    JAXBContext jc = JAXBContext.newInstance(ALIGNMENT_CONTEXT, ObjectFactory.class.getClassLoader());
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    ObjectFactory of = new ObjectFactory();
    try {
        m.marshal(of.createCell(ct), out);
    } finally {
        out.flush();
        out.close();
    }
}
Also used : AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) Marshaller(javax.xml.bind.Marshaller) DefaultIOReporter(eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter) ObjectFactory(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.ObjectFactory) CellType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.CellType) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) DefaultAlignment(eu.esdihumboldt.hale.common.align.model.impl.DefaultAlignment) JAXBContext(javax.xml.bind.JAXBContext) URI(java.net.URI) Locatable(eu.esdihumboldt.hale.common.core.io.supplier.Locatable)

Example 15 with PathUpdate

use of eu.esdihumboldt.hale.common.core.io.PathUpdate in project hale by halestudio.

the class JaxbAlignmentWriter method execute.

/**
 * @see AbstractIOProvider#execute(ProgressIndicator, IOReporter)
 */
@Override
protected IOReport execute(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
    progress.begin("Save hale alignment", ProgressIndicator.UNKNOWN);
    PathUpdate pathUpdate = new PathUpdate(getProjectLocation(), getTarget().getLocation());
    AlignmentType alignment;
    try {
        alignment = JaxbAlignmentIO.convert(getAlignment(), reporter, pathUpdate);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl("Error converting alignment to XML model", e));
        reporter.setSuccess(false);
        return reporter;
    }
    OutputStream out = getTarget().getOutput();
    try {
        JaxbAlignmentIO.save(alignment, reporter, out);
    } catch (Exception e) {
        reporter.error(new IOMessageImpl(e.getMessage(), e));
        reporter.setSuccess(false);
        return reporter;
    } finally {
        out.close();
    }
    progress.end();
    reporter.setSuccess(true);
    return reporter;
}
Also used : AlignmentType(eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType) OutputStream(java.io.OutputStream) PathUpdate(eu.esdihumboldt.hale.common.core.io.PathUpdate) IOMessageImpl(eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl) IOProviderConfigurationException(eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException) IOException(java.io.IOException)

Aggregations

PathUpdate (eu.esdihumboldt.hale.common.core.io.PathUpdate)15 URI (java.net.URI)10 Test (org.junit.Test)7 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)5 IOException (java.io.IOException)5 DefaultInputSupplier (eu.esdihumboldt.hale.common.core.io.supplier.DefaultInputSupplier)4 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 AlignmentType (eu.esdihumboldt.hale.common.align.io.impl.internal.generated.AlignmentType)2 LogProgressIndicator (eu.esdihumboldt.hale.common.core.io.impl.LogProgressIndicator)2 ProjectFileInfo (eu.esdihumboldt.hale.common.core.io.project.model.ProjectFileInfo)2 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)2 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)2 DefaultIOReporter (eu.esdihumboldt.hale.common.core.io.report.impl.DefaultIOReporter)2 Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)2 OutputStream (java.io.OutputStream)2 AlignmentReader (eu.esdihumboldt.hale.common.align.io.AlignmentReader)1 JaxbAlignmentReader (eu.esdihumboldt.hale.common.align.io.impl.JaxbAlignmentReader)1 AlignmentBean (eu.esdihumboldt.hale.common.align.io.impl.internal.AlignmentBean)1 CellBean (eu.esdihumboldt.hale.common.align.io.impl.internal.CellBean)1 NamedEntityBean (eu.esdihumboldt.hale.common.align.io.impl.internal.NamedEntityBean)1