Search in sources :

Example 21 with OMEXMLMetadata

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);
}
Also used : ServiceException(loci.common.services.ServiceException) ServiceFactory(loci.common.services.ServiceFactory) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) OMEXMLMetadataRoot(ome.xml.meta.OMEXMLMetadataRoot) MissingLibraryException(loci.formats.MissingLibraryException) DependencyException(loci.common.services.DependencyException) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) OMEXMLService(loci.formats.services.OMEXMLService) FormatException(loci.formats.FormatException)

Example 22 with OMEXMLMetadata

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);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) OMEXMLMetadataRoot(ome.xml.meta.OMEXMLMetadataRoot) OMEXMLService(loci.formats.services.OMEXMLService) Location(loci.common.Location)

Example 23 with OMEXMLMetadata

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);
}
Also used : ServiceFactory(loci.common.services.ServiceFactory) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) MetadataRetrieve(loci.formats.meta.MetadataRetrieve) OMEXMLService(loci.formats.services.OMEXMLService)

Example 24 with OMEXMLMetadata

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);
}
Also used : MetadataStore(loci.formats.meta.MetadataStore) OMEXMLMetadata(loci.formats.ome.OMEXMLMetadata) SkipException(org.testng.SkipException) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

OMEXMLMetadata (loci.formats.ome.OMEXMLMetadata)24 ServiceException (loci.common.services.ServiceException)12 ServiceFactory (loci.common.services.ServiceFactory)10 OMEXMLService (loci.formats.services.OMEXMLService)10 DependencyException (loci.common.services.DependencyException)9 IOException (java.io.IOException)8 FormatException (loci.formats.FormatException)8 MetadataStore (loci.formats.meta.MetadataStore)7 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)7 Location (loci.common.Location)6 PositiveInteger (ome.xml.model.primitives.PositiveInteger)6 CoreMetadata (loci.formats.CoreMetadata)5 Length (ome.units.quantity.Length)5 NonNegativeInteger (ome.xml.model.primitives.NonNegativeInteger)5 Test (org.testng.annotations.Test)5 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 TransformerException (javax.xml.transform.TransformerException)3 MissingLibraryException (loci.formats.MissingLibraryException)3 Image (ome.xml.model.Image)3 EnumerationException (ome.xml.model.enums.EnumerationException)3