use of ome.xml.model.XMLAnnotation 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;
}
use of ome.xml.model.XMLAnnotation in project bioformats by openmicroscopy.
the class OMEXMLServiceTest method testOriginalMetadata.
@Test
public void testOriginalMetadata() throws ServiceException {
OMEXMLMetadata metadata = service.createOMEXMLMetadata();
service.populateOriginalMetadata(metadata, "testKey", "testValue");
Hashtable metadataTable = service.getOriginalMetadata(metadata);
assertEquals(metadataTable.size(), 1);
assertTrue("testValue".equals(metadataTable.get("testKey")));
OME root = (OME) metadata.getRoot();
StructuredAnnotations annotations = root.getStructuredAnnotations();
assertEquals(annotations.sizeOfXMLAnnotationList(), 1);
XMLAnnotation xmlAnn = annotations.getXMLAnnotation(0);
String txt = "<OriginalMetadata><Key>testKey</Key><Value>testValue</Value></OriginalMetadata>";
assertEquals(txt, xmlAnn.getValue());
OriginalMetadataAnnotation omAnn = (OriginalMetadataAnnotation) xmlAnn;
assertEquals("testValue", omAnn.getValueForKey());
}
use of ome.xml.model.XMLAnnotation in project bioformats by openmicroscopy.
the class InOutCurrentTest method testValidChannelAnnotation.
@Test(dependsOnMethods = { "testValidChannelNode" })
public void testValidChannelAnnotation() {
Channel c = ome.getImage(0).getPixels().getChannel(0);
Annotation n = c.getLinkedAnnotation(0);
assertNotNull(n);
assertTrue(n instanceof XMLAnnotation);
assertEquals(CHANNEL_ANNOTATION_ID, n.getID());
assertEquals(n.getNamespace(), GENERAL_ANNOTATION_NAMESPACE);
assertEquals(CHANNEL_ANNOTATION_VALUE, ((XMLAnnotation) n).getValue());
}
Aggregations