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);
}
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);
}
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;
}
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();
}
}
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;
}
Aggregations