use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.
the class OMEXMLWriter method setId.
// -- FormatWriter API methods --
/* @see loci.formats.FormatWriter#setId(String) */
@Override
public void setId(String id) throws FormatException, IOException {
if (id.equals(currentId)) {
return;
}
super.setId(id);
MetadataRetrieve retrieve = getMetadataRetrieve();
String xml;
try {
ServiceFactory factory = new ServiceFactory();
service = factory.getInstance(OMEXMLService.class);
xml = service.getOMEXML(retrieve);
OMEXMLMetadata noBin = service.createOMEXMLMetadata(xml);
service.removeBinData(noBin);
OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) noBin.getRoot();
root.setCreator(FormatTools.CREATOR);
xml = service.getOMEXML(noBin);
} catch (DependencyException de) {
throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de);
} catch (ServiceException se) {
throw new FormatException(se);
}
xmlFragments = new ArrayList<String>();
currentFragment = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
XMLTools.parseXML(xml, new OMEHandler());
xmlFragments.add(currentFragment);
}
use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.
the class OMETiffWriter method getBinaryOnlyOMEXML.
private String getBinaryOnlyOMEXML(String file, String companion, String companionUUID) throws FormatException, IOException, DependencyException, ServiceException {
ServiceFactory factory = new ServiceFactory();
OMEXMLService service = factory.getInstance(OMEXMLService.class);
OMEXMLMetadata meta = service.createOMEXMLMetadata();
String uuid = "urn:uuid:" + getUUID(new Location(file).getName());
meta.setUUID(uuid);
meta.setBinaryOnlyMetadataFile(new Location(companion).getName());
meta.setBinaryOnlyUUID(companionUUID);
OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) meta.getRoot();
root.setCreator(FormatTools.CREATOR);
return service.getOMEXML(meta);
}
use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.
the class OMETiffWriter method setupServiceAndMetadata.
private void setupServiceAndMetadata() throws DependencyException, ServiceException {
// extract OME-XML string from metadata object
MetadataRetrieve retrieve = getMetadataRetrieve();
ServiceFactory factory = new ServiceFactory();
service = factory.getInstance(OMEXMLService.class);
OMEXMLMetadata originalOMEMeta = service.getOMEMetadata(retrieve);
originalOMEMeta.resolveReferences();
String omexml = service.getOMEXML(originalOMEMeta);
omeMeta = service.createOMEXMLMetadata(omexml);
}
use of loci.formats.ome.OMEXMLMetadata in project bioformats by openmicroscopy.
the class FormatReaderTest method testEqualOMEXML.
@Test(groups = { "all", "xml", "automated" })
public void testEqualOMEXML() {
if (config == null)
throw new SkipException("No config tree");
String testName = "testEqualOMEXML";
if (!initFile())
result(testName, false, "initFile");
boolean success = true;
String msg = null;
try {
MetadataStore store = reader.getMetadataStore();
success = omexmlService.isOMEXMLMetadata(store);
if (!success)
msg = TestTools.shortClassName(store);
String file = reader.getCurrentFile() + ".ome.xml";
if (success) {
if (!new File(file).exists() && omexmlDir != null && new File(omexmlDir).exists()) {
String dir = System.getProperty("testng.directory");
if (dir != null) {
file = reader.getCurrentFile().replace(dir, omexmlDir) + ".ome.xml";
if (!new File(file).exists()) {
file = reader.getCurrentFile().replace(dir, omexmlDir);
file = file.substring(0, file.lastIndexOf(".")) + ".ome.xml";
}
}
}
if (new File(file).exists()) {
String xml = DataTools.readFile(file);
OMEXMLMetadata base = omexmlService.createOMEXMLMetadata(xml);
success = omexmlService.isEqual(base, (OMEXMLMetadata) store);
}
}
} catch (Throwable t) {
LOGGER.info("", t);
msg = t.getMessage();
}
result(testName, success, msg);
}
Aggregations