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