/** 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(); } }
/** Parses a DOM from the given XML string. */ public static Document parseDOM(String xml) throws ParserConfigurationException, SAXException, IOException { byte[] bytes = xml.getBytes(Constants.ENCODING); InputStream is = new ByteArrayInputStream(bytes); try { Document doc = parseDOM(is); return doc; } finally { is.close(); } }
/** * Parses a DOM from the given XML file on disk. * * @param file a file on disk that contains XML * @return a {@link Document} reflecting the contents of the file * @throws ParserConfigurationException if the XML parser cannot be created * @throws SAXException if there is an error parsing the XML * @throws IOException if there is an error reading from the file */ 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(); } }
/** * Parses a DOM from the given XML string. * * @param xml XML data * @return a {@link Document} reflecting the XML string * @throws ParserConfigurationException if the XML parser cannot be created * @throws SAXException if there is an error parsing the XML * @throws IOException if there is an error reading from the file */ public static Document parseDOM(String xml) throws ParserConfigurationException, SAXException, IOException { byte[] bytes = xml.getBytes(Constants.ENCODING); InputStream is = new ByteArrayInputStream(bytes); try { Document doc = parseDOM(is); return doc; } finally { is.close(); } }
private String getImageType(int ifdIndex) { String xml = getIFDComment(ifdIndex); try { Element root = XMLTools.parseDOM(xml).getDocumentElement(); NodeList types = root.getElementsByTagName("ImageType"); if (types.getLength() > 0) { return types.item(0).getTextContent(); } } catch (ParserConfigurationException|SAXException|IOException e) { LOGGER.debug("Could not determine image type for IFD #" + ifdIndex, e); } return null; }
private String getImageType(int ifdIndex) { String xml = getIFDComment(ifdIndex); try { Element root = XMLTools.parseDOM(xml).getDocumentElement(); NodeList types = root.getElementsByTagName("ImageType"); if (types.getLength() > 0) { return types.item(0).getTextContent(); } } catch (ParserConfigurationException|SAXException|IOException e) { LOGGER.debug("Could not determine image type for IFD #" + ifdIndex, e); } return null; }
/** 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; }
/** 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; }
/** @see OMEXMLService#getOMEXMLVersion(java.lang.Object) */ @Override public String getOMEXMLVersion(Object o) { if (o == null) return null; if (o instanceof OMEXMLMetadata || o instanceof OMEModelObject) { return LATEST_VERSION; } else if (o instanceof String) { String xml = (String) o; try { Element e = XMLTools.parseDOM(xml).getDocumentElement(); String namespace = e.getAttribute("xmlns"); if (namespace == null || namespace.equals("")) { namespace = e.getAttribute("xmlns:ome"); } if (namespace == null || namespace.equals("")) { namespace = e.getAttribute("xmlns:OME"); } return namespace.endsWith("ome.xsd") ? "2003-FC" : namespace.substring(namespace.lastIndexOf("/") + 1); } catch (ParserConfigurationException pce) { } catch (SAXException se) { } catch (IOException ioe) { } } return null; }
/** @see OMEXMLService#getOMEXMLVersion(java.lang.Object) */ @Override public String getOMEXMLVersion(Object o) { if (o == null) return null; if (o instanceof OMEXMLMetadata || o instanceof OMEModelObject) { return LATEST_VERSION; } else if (o instanceof String) { String xml = (String) o; try { Element e = XMLTools.parseDOM(xml).getDocumentElement(); String namespace = e.getAttribute("xmlns"); if (namespace == null || namespace.equals("")) { namespace = e.getAttribute("xmlns:ome"); } if (namespace == null || namespace.equals("")) { namespace = e.getAttribute("xmlns:OME"); } return namespace.endsWith("ome.xsd") ? "2003-FC" : namespace.substring(namespace.lastIndexOf("/") + 1); } catch (ParserConfigurationException pce) { } catch (SAXException se) { } catch (IOException ioe) { } } return null; }
Exception exception = null; try { doc = XMLTools.parseDOM(xml);
Exception exception = null; try { doc = XMLTools.parseDOM(xml);
/** * Constructs an OME root node. <b>NOTE:</b> This method is mostly here to * ensure type safety of return values as instances of service dependency * classes should not leak out of the interface. * @param xml String of XML to create the root node from. * @return An ome.xml.model.OMEModelObject subclass root node. * @throws IOException If there is an error reading from the string. * @throws SAXException If there is an error parsing the XML. * @throws ParserConfigurationException If there is an error preparing the * parsing infrastructure. */ private OMEXMLMetadataRoot createRoot(String xml) throws ServiceException { try { OMEModel model = new OMEModelImpl(); OMEXMLMetadataRoot ome = new OMEXMLMetadataRoot(XMLTools.parseDOM(xml).getDocumentElement(), model); model.resolveReferences(); return ome; } catch (Exception e) { throw new ServiceException(e); } }
/** * Constructs an OME root node. <b>NOTE:</b> This method is mostly here to * ensure type safety of return values as instances of service dependency * classes should not leak out of the interface. * @param xml String of XML to create the root node from. * @return An ome.xml.model.OMEModelObject subclass root node. * @throws IOException If there is an error reading from the string. * @throws SAXException If there is an error parsing the XML. * @throws ParserConfigurationException If there is an error preparing the * parsing infrastructure. */ private OMEXMLMetadataRoot createRoot(String xml) throws ServiceException { try { OMEModel model = new OMEModelImpl(); OMEXMLMetadataRoot ome = new OMEXMLMetadataRoot(XMLTools.parseDOM(xml).getDocumentElement(), model); model.resolveReferences(); return ome; } catch (Exception e) { throw new ServiceException(e); } }
private void parseXML(RandomAccessInputStream s, String xml, long startFilePointer) throws FormatException, IOException { Element root = null; try { root = XMLTools.parseDOM(xml).getDocumentElement();
private void parseXML(RandomAccessInputStream s, String xml, long startFilePointer) throws FormatException, IOException { Element root = null; try { root = XMLTools.parseDOM(xml).getDocumentElement();
XMLTools.sanitizeXML(new String(buf, Constants.ENCODING)); return XMLTools.parseDOM(xml);
XMLTools.sanitizeXML(new String(buf, Constants.ENCODING)); return XMLTools.parseDOM(xml);
@Test public void testParseOldXML() throws ParserConfigurationException, SAXException, IOException { final Document xml = XMLTools.parseDOM(OLD_XML); final PrairieMetadata meta = new PrairieMetadata(xml, null, null); final Value positionCurrent = meta.getSequence(1).getFrame(1).getValue("positionCurrent"); final Value xAxis = positionCurrent.get("XAxis"); assertEquals("0.95", xAxis.value()); final Value yAxis = positionCurrent.get("YAxis"); assertEquals("-4.45", yAxis.value()); final ValueTable zAxis = (ValueTable) positionCurrent.get("ZAxis"); assertEquals("-9", zAxis.get(0).value()); assertEquals("62.45", zAxis.get(1).value()); }
@Test public void testParseNewXML() throws ParserConfigurationException, SAXException, IOException { final Document xml = XMLTools.parseDOM(NEW_XML); final PrairieMetadata meta = new PrairieMetadata(xml, null, null); final ValueTable positionCurrent = (ValueTable) meta.getSequence(1).getFrame(1).getValue("positionCurrent"); final ValueTable xAxis = (ValueTable) positionCurrent.get("XAxis"); assertEquals("-621.412879412341", xAxis.value()); final ValueTable yAxis = (ValueTable) positionCurrent.get("YAxis"); assertEquals("255.652372573538", yAxis.value()); final ValueTable zAxis = (ValueTable) positionCurrent.get("ZAxis"); assertEquals("28.15", zAxis.get(0).value()); assertEquals("111.23", zAxis.get(1).value()); } }