/** Parses a DOM from the given XML file on disk. */ public static Document parseDOM(File file) throws ParserConfigurationException, SAXException, IOException { InputStream is = new FileInputStream(file); try { Document doc = parseDOM(is); return doc; } finally { is.close(); } }
public Document createNewDocument() { if (builder == null) { builder = XMLTools.createBuilder(); } return builder.newDocument(); }
/** * Dumps the given OME-XML DOM tree to a string. * @param schemaLocation if null, no xmlns attribute will be added. * @param doc the {@link Document} representing the XML to be written * @param r the {@link Element} to use for adding the schema location * @return OME-XML as a string. */ public static String dumpXML(String schemaLocation, Document doc, Element r) { return dumpXML(schemaLocation, doc, r, true); }
/** Transforms the given XML string using the specified XSLT stylesheet. */ public static String transformXML(String xml, Templates xslt) throws IOException { xml = avoidUndeclaredNamespaces(xml); return transformXML(new StreamSource(new StringReader(xml)), xslt); }
/** Ensures that an xmlns:ome element exists. */ private String verifyOMENamespace(String xml) { try { Document doc = XMLTools.parseDOM(xml); Element e = doc.getDocumentElement(); String omeNamespace = e.getAttribute("xmlns:ome"); if (omeNamespace == null || omeNamespace.equals("")) { e.setAttribute("xmlns:ome", e.getAttribute("xmlns")); } return XMLTools.getXML(doc); } catch (ParserConfigurationException pce) { } catch (TransformerConfigurationException tce) { } catch (TransformerException te) { } catch (SAXException se) { } catch (IOException ioe) { } return null; }
/** Parse metadata values from the Acqusition.xml file. */ private void parseXMLFile() throws IOException { Position p = positions.get(getSeries()); String xmlData = DataTools.readFile(p.xmlFile); xmlData = XMLTools.sanitizeXML(xmlData); DefaultHandler handler = new MicromanagerHandler(); XMLTools.parseXML(xmlData, handler); }
XMLTools.sanitizeXML(new String(buf, Constants.ENCODING)); return XMLTools.parseDOM(xml);
Exception exception = null; try { doc = XMLTools.parseDOM(xml); xml = XMLTools.getXML(doc); Document annotationRoot = XMLTools.parseDOM(annotationXML); NodeList nodes = annotationRoot.getElementsByTagName("ModuloAlongZ"); return XMLTools.validateXML(xml, "OME-XML", SCHEMA_CLASSPATH_READER);
/** * Indents XML to be more readable. * Uses 3 spaces to indent, and may indent CDATA. * * @param xml the XML string to format * @return the formatted XML string * @see #indentXML(String, int, boolean) */ public static String indentXML(String xml) { return indentXML(xml, 3, false); }
/** * Parses the XML contained in the given input stream into * using the specified XML handler. * Be very careful, as 'stream' <b>will</b> be closed by the SAX parser. */ public static void parseXML(RandomAccessInputStream stream, DefaultHandler handler) throws IOException { parseXML((InputStream) stream, handler); }
super.initFile(id); parser = XMLTools.createBuilder(); segment.fillInData(); String xml = ((Metadata) segment).xml; xml = XMLTools.sanitizeXML(xml); if (firstXML == null && canSkipXML) { firstXML = xml; segment.fillInData(); String xml = ((Metadata) segment).xml; xml = XMLTools.sanitizeXML(xml); if (firstXML == null && canSkipXML) { firstXML = xml;
/** * Set the value of this annotation using the given Modulo object * @param meta the associated OMEXMLMetadata * @param m the Modulo object from which to retrieve dimension information */ public void setModulo(OMEXMLMetadata meta, Modulo m) { modulo = m; setNamespace(MODULO_NS); Document doc = XMLTools.createDocument(); Element r = makeModuloElement(doc); setValue(XMLTools.dumpXML(null, doc, r, false)); }
/** * Writes the specified DOM to the given output stream. * * @param os the {@link OutputStream} to which XML should be written * @param doc the {@link Document} representing the XML to write * @throws TransformerException if there is an error during writing */ public static void writeXML(OutputStream os, Document doc) throws TransformerException { writeXML(os, doc, true); }
/** * Attempts to validate the given XML string using * Java's XML validation facility. * @param xml The XML string to validate. * @return whether or not validation was successful. */ public static boolean validateXML(String xml) { return validateXML(xml, null, null); }
if (update2003FC == null) { update2003FC = XMLTools.getStylesheet(XSLT_2003FC, OMEXMLServiceImpl.class); transformed = XMLTools.transformXML(xml, update2003FC); if (update200706 == null) { update200706 = XMLTools.getStylesheet(XSLT_200706, OMEXMLServiceImpl.class); transformed = XMLTools.transformXML(xml, update200706); if (update200802 == null) { update200802 = XMLTools.getStylesheet(XSLT_200802, OMEXMLServiceImpl.class); transformed = XMLTools.transformXML(xml, update200802); if (update200809 == null) { update200809 = XMLTools.getStylesheet(XSLT_200809, OMEXMLServiceImpl.class); transformed = XMLTools.transformXML(transformed, update200809); if (update200909 == null) { update200909 = XMLTools.getStylesheet(XSLT_200909, OMEXMLServiceImpl.class); transformed = XMLTools.transformXML(transformed, update200909);
@BeforeClass public void setUp() throws Exception { InputStream source = this.getClass().getResourceAsStream(RESOURCE); ServiceFactory sf = new ServiceFactory(); OMEXMLService service = sf.getInstance(OMEXMLService.class); String xml = XMLTools.transformXML( new StreamSource(source), UPDATE_201106); ome = (OME) service.createOMEXMLRoot(xml); }
/** * @see OMEXMLService#createOMEXMLMetadata(java.lang.String, java.lang.String) */ @Override public OMEXMLMetadata createOMEXMLMetadata(String xml, String version) throws ServiceException { if (xml != null) { xml = XMLTools.sanitizeXML(xml); } OMEXMLMetadataRoot ome = xml == null ? null : createRoot(transformToLatestVersion(xml)); OMEXMLMetadata meta = new OMEPyramidStore(); if (ome != null) meta.setRoot(ome); return meta; }
/** Parse metadata values from the Acqusition.xml file. */ private void parseXMLFile() throws IOException { Position p = positions.get(getSeries()); String xmlData = DataTools.readFile(p.xmlFile); xmlData = XMLTools.sanitizeXML(xmlData); DefaultHandler handler = new MicromanagerHandler(); XMLTools.parseXML(xmlData, handler); }
XMLTools.sanitizeXML(new String(buf, Constants.ENCODING)); return XMLTools.parseDOM(xml);
Exception exception = null; try { doc = XMLTools.parseDOM(xml); xml = XMLTools.getXML(doc); Document annotationRoot = XMLTools.parseDOM(annotationXML); NodeList nodes = annotationRoot.getElementsByTagName("ModuloAlongZ"); return XMLTools.validateXML(xml, "OME-XML", SCHEMA_CLASSPATH_READER);