use of ome.specification.XMLWriter in project bioformats by openmicroscopy.
the class SchemaCurrent_TO_2010_06_Test method testDowngradeTo201006ImageNoMetadata.
/**
* Tests the XSLT used to downgrade from current schema to 2010-06.
* An XML file with an image is created and the stylesheet is applied.
* @throws Exception Thrown if an error occurred.
*/
@Test(enabled = false)
public void testDowngradeTo201006ImageNoMetadata() throws Exception {
File inFile = File.createTempFile("testDowngradeTo201006ImageNoMetadata", "." + OME_XML_FORMAT);
files.add(inFile);
File middleFileA = File.createTempFile("testDowngradeTo201006ImageNoMetadataMiddleA", "." + OME_XML_FORMAT);
files.add(middleFileA);
File outputFile = File.createTempFile("testDowngradeTo201006ImageNoMetadataOutput", "." + OME_XML_FORMAT);
files.add(outputFile);
XMLMockObjects xml = new XMLMockObjects();
XMLWriter writer = new XMLWriter();
writer.writeFile(inFile, xml.createImage(), true);
// Dump out file for debuging
// File fCheckIn = new File("/Users/andrew/Desktop/wibble1.xml");
// writer.writeFile(fCheckIn , xml.getRoot(), true);
transformFileWithStream(inFile, middleFileA, STYLESHEET_A);
transformFileWithStream(middleFileA, outputFile, STYLESHEET_B);
Document doc = anOmeValidator.parseFileWithStreamArray(outputFile, schemaArray);
Assert.assertNotNull(doc);
// Should only have one root node i.e. OME node
NodeList list = doc.getChildNodes();
Assert.assertEquals(list.getLength(), 1);
Node root = list.item(0);
Assert.assertEquals(root.getNodeName(), XMLWriter.OME_TAG);
// now analyse the root node
list = root.getChildNodes();
String name;
Node n;
Document docSrc = anOmeValidator.parseFile(inFile, null);
Node rootSrc = docSrc.getChildNodes().item(0);
Node imageNode = null;
NodeList listSrc = rootSrc.getChildNodes();
for (int i = 0; i < listSrc.getLength(); i++) {
n = listSrc.item(i);
name = n.getNodeName();
if (name != null) {
if (name.contains(XMLWriter.IMAGE_TAG))
imageNode = n;
}
}
for (int i = 0; i < list.getLength(); i++) {
n = list.item(i);
name = n.getNodeName();
if (name != null) {
// TODO: add other node
if (name.contains(XMLWriter.IMAGE_TAG) && imageNode != null)
checkImageNode(n, imageNode);
}
}
}
use of ome.specification.XMLWriter in project bioformats by openmicroscopy.
the class SchemaCurrent_TO_2003_FC_Test method testDowngradeTo2003FCImageNoMetadata.
/**
* Tests the XSLT used to downgrade from current schema to 2003-FC.
* An XML file with an image is created and the stylesheet is applied.
* @throws Exception Thrown if an error occurred.
*/
@Test(enabled = false)
public void testDowngradeTo2003FCImageNoMetadata() throws Exception {
File inFile = File.createTempFile("testDowngradeTo2003FCImageNoMetadata", "." + OME_XML_FORMAT);
files.add(inFile);
File middleFileA = File.createTempFile("testDowngradeTo2003FCImageNoMetadataMiddleA", "." + OME_XML_FORMAT);
files.add(middleFileA);
File middleFileB = File.createTempFile("testDowngradeTo2003FCImageNoMetadataMiddleB", "." + OME_XML_FORMAT);
files.add(middleFileB);
File outputFile = File.createTempFile("testDowngradeTo2003FCImageNoMetadataOutput", "." + OME_XML_FORMAT);
files.add(outputFile);
XMLMockObjects xml = new XMLMockObjects();
XMLWriter writer = new XMLWriter();
writer.writeFile(inFile, xml.createImage(), true);
transformFileWithStream(inFile, middleFileA, STYLESHEET_A);
transformFileWithStream(middleFileA, middleFileB, STYLESHEET_B);
transformFileWithStream(middleFileB, outputFile, STYLESHEET_C);
Document doc = anOmeValidator.parseFileWithStreamArray(outputFile, schemaArray);
Assert.assertNotNull(doc);
// Should only have one root node i.e. OME node
NodeList list = doc.getChildNodes();
Assert.assertEquals(list.getLength(), 1);
Node root = list.item(0);
Assert.assertEquals(root.getNodeName(), XMLWriter.OME_TAG);
// now analyse the root node
list = root.getChildNodes();
String name;
Node n;
Document docSrc = anOmeValidator.parseFile(inFile, null);
Node rootSrc = docSrc.getChildNodes().item(0);
Node imageNode = null;
NodeList listSrc = rootSrc.getChildNodes();
for (int i = 0; i < listSrc.getLength(); i++) {
n = listSrc.item(i);
name = n.getNodeName();
if (name != null) {
if (name.contains(XMLWriter.IMAGE_TAG))
imageNode = n;
}
}
for (int i = 0; i < list.getLength(); i++) {
n = list.item(i);
name = n.getNodeName();
if (name != null) {
// TODO: add other node
if (name.contains(XMLWriter.IMAGE_TAG) && imageNode != null)
checkImageNode(n, imageNode);
}
}
}
use of ome.specification.XMLWriter in project bioformats by openmicroscopy.
the class Schema_Transform_Test method createImageFile.
/**
* Generates an <code>OME-XML</code> file.
*
* @param index The type of image to import. One of the constants defined
* by this class.
* @return The image file.
* @throws Exception Thrown if an error occurred.
*/
private File createImageFile(int index) throws Exception {
// First create an image
File f = File.createTempFile("tempFileName", "." + OME_XML);
XMLMockObjects xml = new XMLMockObjects();
XMLWriter writer = new XMLWriter();
if (index == IMAGE_ROI) {
writer.writeFile(f, xml.createImageWithROI(), true);
} else if (index == IMAGE_ANNOTATED_DATA) {
writer.writeFile(f, xml.createImageWithAnnotatedAcquisitionData(), true);
} else {
writer.writeFile(f, xml.createImageWithAcquisitionData(), true);
}
return f;
}
use of ome.specification.XMLWriter in project bioformats by openmicroscopy.
the class SchemaCurrent_TO_2008_02_Test method testDowngradeTo200802ImageNoMetadata.
/**
* Tests the XSLT used to downgrade from current schema to 2008-02.
* An XML file with an image is created and the stylesheet is applied.
* @throws Exception Thrown if an error occurred.
*/
@Test(enabled = false)
public void testDowngradeTo200802ImageNoMetadata() throws Exception {
File inFile = File.createTempFile("testDowngradeTo200802ImageNoMetadata", "." + OME_XML_FORMAT);
files.add(inFile);
File middleFileA = File.createTempFile("testDowngradeTo200802ImageNoMetadataMiddleA", "." + OME_XML_FORMAT);
files.add(middleFileA);
File middleFileB = File.createTempFile("testDowngradeTo200802ImageNoMetadataMiddleB", "." + OME_XML_FORMAT);
files.add(middleFileB);
File outputFile = File.createTempFile("testDowngradeTo200802ImageNoMetadataOutput", "." + OME_XML_FORMAT);
files.add(outputFile);
XMLMockObjects xml = new XMLMockObjects();
XMLWriter writer = new XMLWriter();
writer.writeFile(inFile, xml.createImage(), true);
transformFileWithStream(inFile, middleFileA, STYLESHEET_A);
transformFileWithStream(middleFileA, middleFileB, STYLESHEET_B);
transformFileWithStream(middleFileB, outputFile, STYLESHEET_C);
Document doc = anOmeValidator.parseFileWithStreamArray(outputFile, schemaArray);
Assert.assertNotNull(doc);
// Should only have one root node i.e. OME node
NodeList list = doc.getChildNodes();
Assert.assertEquals(list.getLength(), 1);
Node root = list.item(0);
Assert.assertEquals(root.getNodeName(), XMLWriter.OME_TAG);
// now analyse the root node
list = root.getChildNodes();
String name;
Node n;
Document docSrc = anOmeValidator.parseFile(inFile, null);
Node rootSrc = docSrc.getChildNodes().item(0);
Node imageNode = null;
NodeList listSrc = rootSrc.getChildNodes();
for (int i = 0; i < listSrc.getLength(); i++) {
n = listSrc.item(i);
name = n.getNodeName();
if (name != null) {
if (name.contains(XMLWriter.IMAGE_TAG))
imageNode = n;
}
}
for (int i = 0; i < list.getLength(); i++) {
n = list.item(i);
name = n.getNodeName();
if (name != null) {
// TODO: add other node
if (name.contains(XMLWriter.IMAGE_TAG) && imageNode != null)
checkImageNode(n, imageNode);
}
}
}
Aggregations