Search in sources :

Example 6 with Annotation

use of ome.xml.model.Annotation in project bioformats by openmicroscopy.

the class InOutCurrentTest method testValidArcAnnotation.

@Test(dependsOnMethods = { "testValidArcNode" }, enabled = false)
public void testValidArcAnnotation() {
    Annotation n = ome.getInstrument(0).getLightSource(2).getLinkedAnnotation(0);
    assertNotNull(n);
    assertEquals(LIGHTSOURCE_ARC_ANNOTATION_ID, n.getID());
    assertEquals(n.getNamespace(), GENERAL_ANNOTATION_NAMESPACE);
    assertTrue(n instanceof CommentAnnotation);
    CommentAnnotation string = (CommentAnnotation) n;
    assertEquals(LIGHTSOURCE_ARC_ANNOTATION_VALUE, string.getValue());
}
Also used : CommentAnnotation(ome.xml.model.CommentAnnotation) ListAnnotation(ome.xml.model.ListAnnotation) CommentAnnotation(ome.xml.model.CommentAnnotation) Annotation(ome.xml.model.Annotation) LongAnnotation(ome.xml.model.LongAnnotation) TimestampAnnotation(ome.xml.model.TimestampAnnotation) XMLAnnotation(ome.xml.model.XMLAnnotation) BooleanAnnotation(ome.xml.model.BooleanAnnotation) Test(org.testng.annotations.Test)

Example 7 with Annotation

use of ome.xml.model.Annotation in project bioformats by openmicroscopy.

the class InOutCurrentTest method testValidLightEmittingDiodeAnnotation.

@Test(dependsOnMethods = { "testValidLightEmittingDiodeNode" }, enabled = false)
public void testValidLightEmittingDiodeAnnotation() {
    LightEmittingDiode led = (LightEmittingDiode) ome.getInstrument(0).getLightSource(4);
    Annotation n = led.getLinkedAnnotation(0);
    assertNotNull(n);
    assertEquals(LIGHTSOURCE_LED_ANNOTATION_ID, n.getID());
    assertEquals(n.getNamespace(), GENERAL_ANNOTATION_NAMESPACE);
    assertTrue(n instanceof CommentAnnotation);
    CommentAnnotation string = (CommentAnnotation) n;
    assertEquals(LIGHTSOURCE_LED_ANNOTATION_VALUE, string.getValue());
}
Also used : LightEmittingDiode(ome.xml.model.LightEmittingDiode) CommentAnnotation(ome.xml.model.CommentAnnotation) ListAnnotation(ome.xml.model.ListAnnotation) CommentAnnotation(ome.xml.model.CommentAnnotation) Annotation(ome.xml.model.Annotation) LongAnnotation(ome.xml.model.LongAnnotation) TimestampAnnotation(ome.xml.model.TimestampAnnotation) XMLAnnotation(ome.xml.model.XMLAnnotation) BooleanAnnotation(ome.xml.model.BooleanAnnotation) Test(org.testng.annotations.Test)

Example 8 with Annotation

use of ome.xml.model.Annotation in project bioformats by openmicroscopy.

the class InOutCurrentTest method testValidDetectorAnnotation.

@Test(dependsOnMethods = { "testValidDetectorNode" })
public void testValidDetectorAnnotation() {
    Annotation n = ome.getInstrument(0).getDetector(0).getLinkedAnnotation(0);
    assertNotNull(n);
    assertEquals(DETECTOR_ANNOTATION_ID, n.getID());
    assertEquals(n.getNamespace(), GENERAL_ANNOTATION_NAMESPACE);
    assertTrue(n instanceof CommentAnnotation);
    CommentAnnotation string = (CommentAnnotation) n;
    assertEquals(DETECTOR_ANNOTATION_VALUE, string.getValue());
}
Also used : CommentAnnotation(ome.xml.model.CommentAnnotation) ListAnnotation(ome.xml.model.ListAnnotation) CommentAnnotation(ome.xml.model.CommentAnnotation) Annotation(ome.xml.model.Annotation) LongAnnotation(ome.xml.model.LongAnnotation) TimestampAnnotation(ome.xml.model.TimestampAnnotation) XMLAnnotation(ome.xml.model.XMLAnnotation) BooleanAnnotation(ome.xml.model.BooleanAnnotation) Test(org.testng.annotations.Test)

Example 9 with Annotation

use of ome.xml.model.Annotation in project bioformats by openmicroscopy.

the class XMLAnnotationTest method testValidXMLAnnotation.

@Test
public void testValidXMLAnnotation() throws EnumerationException {
    assertNotNull(ome);
    assertEquals(1, ome.sizeOfImageList());
    Image image = ome.getImage(0);
    Pixels pixels = image.getPixels();
    assertNotNull(pixels);
    assertEquals(3, pixels.sizeOfChannelList());
    Channel channel = pixels.getChannel(0);
    assertEquals(1, channel.sizeOfLinkedAnnotationList());
    Annotation annotation = channel.getLinkedAnnotation(0);
    assertEquals(XMLAnnotation.class, annotation.getClass());
    String annotationValue = ((XMLAnnotation) annotation).getValue();
    // normalize line endings if the test is run on Windows
    annotationValue = annotationValue.replaceAll("\r\n", "\n");
    assertEquals("<TestData>\n                    <key>foo</key>\n\t\t\t\t\t<value>bar</value>\n                </TestData>", annotationValue);
}
Also used : Channel(ome.xml.model.Channel) XMLAnnotation(ome.xml.model.XMLAnnotation) Image(ome.xml.model.Image) Pixels(ome.xml.model.Pixels) XMLAnnotation(ome.xml.model.XMLAnnotation) Annotation(ome.xml.model.Annotation) Test(org.testng.annotations.Test)

Example 10 with Annotation

use of ome.xml.model.Annotation in project bioformats by openmicroscopy.

the class OMEXMLServiceImpl method getModuloAlong.

/**
 * Create a {@link loci.formats.Modulo} corresponding to the given ModuloAlong* tag.
 * @param omexml the OMEXMLMetadata from which to retrieve the ModuloAlong* tag
 * @param tag the tag name (e.g. "ModuloAlongC")
 * @param image the Image index within the OMEXMLMetadata
 * @return the corresponding Modulo object
 */
private Modulo getModuloAlong(OMEXMLMetadata omexml, String tag, int image) {
    OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) omexml.getRoot();
    Image img = root.getImage(image);
    if (img == null) {
        return null;
    }
    for (int i = 0; i < img.sizeOfLinkedAnnotationList(); i++) {
        Annotation annotation = img.getLinkedAnnotation(i);
        if (!(annotation instanceof XMLAnnotation)) {
            continue;
        }
        String xml = ((XMLAnnotation) annotation).getValue();
        try {
            Document annotationRoot = XMLTools.parseDOM(xml);
            NodeList nodes = annotationRoot.getElementsByTagName(tag);
            if (nodes.getLength() > 0) {
                Element modulo = (Element) nodes.item(0);
                NamedNodeMap attrs = modulo.getAttributes();
                Modulo m = new Modulo(tag.substring(tag.length() - 1));
                Node start = attrs.getNamedItem("Start");
                Node end = attrs.getNamedItem("End");
                Node step = attrs.getNamedItem("Step");
                Node type = attrs.getNamedItem("Type");
                Node typeDescription = attrs.getNamedItem("TypeDescription");
                Node unit = attrs.getNamedItem("Unit");
                if (start != null) {
                    m.start = Double.parseDouble(start.getNodeValue());
                }
                if (end != null) {
                    m.end = Double.parseDouble(end.getNodeValue());
                }
                if (step != null) {
                    m.step = Double.parseDouble(step.getNodeValue());
                }
                if (type != null) {
                    m.type = type.getNodeValue();
                }
                if (typeDescription != null) {
                    m.typeDescription = typeDescription.getNodeValue();
                }
                if (unit != null) {
                    m.unit = unit.getNodeValue();
                }
                NodeList labels = modulo.getElementsByTagName("Label");
                if (labels != null && labels.getLength() > 0) {
                    m.labels = new String[labels.getLength()];
                    for (int q = 0; q < labels.getLength(); q++) {
                        m.labels[q] = labels.item(q).getTextContent();
                    }
                }
                return m;
            }
        } catch (ParserConfigurationException e) {
            LOGGER.debug("Failed to parse ModuloAlong", e);
        } catch (SAXException e) {
            LOGGER.debug("Failed to parse ModuloAlong", e);
        } catch (IOException e) {
            LOGGER.debug("Failed to parse ModuloAlong", e);
        }
    }
    return null;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Modulo(loci.formats.Modulo) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) IOException(java.io.IOException) Image(ome.xml.model.Image) Document(org.w3c.dom.Document) Annotation(ome.xml.model.Annotation) ModuloAnnotation(loci.formats.meta.ModuloAnnotation) OriginalMetadataAnnotation(loci.formats.meta.OriginalMetadataAnnotation) XMLAnnotation(ome.xml.model.XMLAnnotation) SAXException(org.xml.sax.SAXException) OMEXMLMetadataRoot(ome.xml.meta.OMEXMLMetadataRoot) XMLAnnotation(ome.xml.model.XMLAnnotation) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

Annotation (ome.xml.model.Annotation)17 XMLAnnotation (ome.xml.model.XMLAnnotation)17 Test (org.testng.annotations.Test)15 BooleanAnnotation (ome.xml.model.BooleanAnnotation)14 CommentAnnotation (ome.xml.model.CommentAnnotation)14 ListAnnotation (ome.xml.model.ListAnnotation)14 LongAnnotation (ome.xml.model.LongAnnotation)14 TimestampAnnotation (ome.xml.model.TimestampAnnotation)14 Image (ome.xml.model.Image)3 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ModuloAnnotation (loci.formats.meta.ModuloAnnotation)2 OriginalMetadataAnnotation (loci.formats.meta.OriginalMetadataAnnotation)2 OMEXMLMetadataRoot (ome.xml.meta.OMEXMLMetadataRoot)2 Channel (ome.xml.model.Channel)2 Document (org.w3c.dom.Document)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 SAXException (org.xml.sax.SAXException)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)1