/** * 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); }
/** * 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. * * @param stream the {@link RandomAccessInputStream} representing the XML * @param handler the {@link DefaultHandler} to use for parsing * @throws IOException if there is an error during parsing */ public static void parseXML(RandomAccessInputStream stream, DefaultHandler handler) throws IOException { parseXML((InputStream) stream, handler); }
/** * Parses the XML contained in the given byte array into * using the specified XML handler. */ public static void parseXML(byte[] xml, DefaultHandler handler) throws IOException { parseXML(new ByteArrayInputStream(xml), handler); }
/** * Parses the given XML string using the specified XML handler. * * @param xml the string representing the XML * @param handler the {@link DefaultHandler} to use for parsing * @throws IOException if there is an error during parsing */ public static void parseXML(String xml, DefaultHandler handler) throws IOException { parseXML(xml.getBytes(Constants.ENCODING), handler); }
/** * Parses the given XML string using the specified XML handler. */ public static void parseXML(String xml, DefaultHandler handler) throws IOException { parseXML(xml.getBytes(Constants.ENCODING), handler); }
/** * Parses the XML contained in the given byte array into * using the specified XML handler. * * @param xml the byte array representing the XML * @param handler the {@link DefaultHandler} to use for parsing * @throws IOException if there is an error during parsing */ public static void parseXML(byte[] xml, DefaultHandler handler) throws IOException { parseXML(new ByteArrayInputStream(xml), handler); }
private void parseResFile(String id) throws IOException { ResHandler handler = new ResHandler(); String resXML = DataTools.readFile(id); XMLTools.parseXML(resXML, handler); }
/** Parses the given XML string into a list of key/value pairs. */ public static Hashtable<String, String> parseXML(String xml) throws IOException { MetadataHandler handler = new MetadataHandler(); parseXML(xml, handler); return handler.getMetadata(); }
private void parseResFile(String id) throws IOException { ResHandler handler = new ResHandler(); String resXML = DataTools.readFile(id); XMLTools.parseXML(resXML, handler); }
/** * Parses the given XML string into a list of key/value pairs. * * @param xml the {@link InputStream} representing the XML * @return a hashtable of key/value pairs representing the XML * @throws IOException if there is an error during parsing * @see MetadataHandler */ public static Hashtable<String, String> parseXML(String xml) throws IOException { MetadataHandler handler = new MetadataHandler(); parseXML(xml, handler); return handler.getMetadata(); }
/** 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); }
/** 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); }
@Override protected void initStandardMetadata() throws FormatException, IOException { super.initStandardMetadata(); String xml = ifds.get(0).getIFDTextValue(NIKON_XML_TAG).trim(); if (xml.length() == 0) { xml = ifds.get(0).getIFDTextValue(NIKON_XML_TAG_2).trim(); } int open = xml.indexOf('<'); if (open >= 0) { xml = xml.substring(open); } xml = "<NIKON>" + xml + "</NIKON>"; xml = XMLTools.sanitizeXML(xml); handler = new ND2Handler(core, false, getImageCount()); try { XMLTools.parseXML(xml, handler); final Map<String, Object> globalMetadata = handler.getMetadata(); for (final Map.Entry<String, Object> entry : globalMetadata.entrySet()) { addGlobalMeta(entry.getKey(), entry.getValue()); } } catch (IOException e) { } }
@Override protected void initStandardMetadata() throws FormatException, IOException { super.initStandardMetadata(); String xml = ifds.get(0).getIFDTextValue(NIKON_XML_TAG).trim(); if (xml.length() == 0) { xml = ifds.get(0).getIFDTextValue(NIKON_XML_TAG_2).trim(); } int open = xml.indexOf('<'); if (open >= 0) { xml = xml.substring(open); } xml = "<NIKON>" + xml + "</NIKON>"; xml = XMLTools.sanitizeXML(xml); handler = new ND2Handler(core, false, getImageCount()); try { XMLTools.parseXML(xml, handler); final Map<String, Object> globalMetadata = handler.getMetadata(); for (final Map.Entry<String, Object> entry : globalMetadata.entrySet()) { addGlobalMeta(entry.getKey(), entry.getValue()); } } catch (IOException e) { } }
private void parseFile(String tiff, MetamorphHandler handler) throws IOException { try (RandomAccessInputStream s = new RandomAccessInputStream(tiff)) { TiffParser parser = new TiffParser(s); IFD firstIFD = parser.getFirstIFD(); String xml = XMLTools.sanitizeXML(firstIFD.getComment()); XMLTools.parseXML(xml, handler); } }
private void parseFile(String tiff, MetamorphHandler handler) throws IOException { try (RandomAccessInputStream s = new RandomAccessInputStream(tiff)) { TiffParser parser = new TiffParser(s); IFD firstIFD = parser.getFirstIFD(); String xml = XMLTools.sanitizeXML(firstIFD.getComment()); XMLTools.parseXML(xml, handler); } }
@Override public boolean isThisType(String name, boolean open) { if (super.isThisType(name, open) && open) { try (RandomAccessInputStream stream = new RandomAccessInputStream(name)) { TiffParser tiffParser = new TiffParser(stream); if (!tiffParser.isValidHeader()) { return false; } String imageDescription = tiffParser.getComment(); if (imageDescription != null) { try { // Test if XML is valid SCN metadata LeicaSCNHandler handler = new LeicaSCNHandler(); XMLTools.parseXML(imageDescription, handler); return true; } catch (Exception se) { LOGGER.debug("XML parsing failed", se); } } } catch (IOException e) { LOGGER.debug("I/O exception during isThisType() evaluation.", e); } } return false; }
@Override public boolean isThisType(String name, boolean open) { if (super.isThisType(name, open) && open) { try (RandomAccessInputStream stream = new RandomAccessInputStream(name)) { TiffParser tiffParser = new TiffParser(stream); if (!tiffParser.isValidHeader()) { return false; } String imageDescription = tiffParser.getComment(); if (imageDescription != null) { try { // Test if XML is valid SCN metadata LeicaSCNHandler handler = new LeicaSCNHandler(); XMLTools.parseXML(imageDescription, handler); return true; } catch (Exception se) { LOGGER.debug("XML parsing failed", se); } } } catch (IOException e) { LOGGER.debug("I/O exception during isThisType() evaluation.", e); } } return false; }
@Override public void setId(String id) throws FormatException, IOException { if (id.equals(currentId)) { return; } super.setId(id); MetadataRetrieve retrieve = getMetadataRetrieve(); String xml; try { ServiceFactory factory = new ServiceFactory(); service = factory.getInstance(OMEXMLService.class); xml = service.getOMEXML(retrieve); OMEXMLMetadata noBin = service.createOMEXMLMetadata(xml); service.removeBinData(noBin); OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) noBin.getRoot(); root.setCreator(FormatTools.CREATOR); xml = service.getOMEXML(noBin); } catch (DependencyException de) { throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de); } catch (ServiceException se) { throw new FormatException(se); } xmlFragments = new ArrayList<String>(); currentFragment = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; XMLTools.parseXML(xml, new OMEHandler()); xmlFragments.add(currentFragment); }
@Override public void setId(String id) throws FormatException, IOException { if (id.equals(currentId)) { return; } super.setId(id); MetadataRetrieve retrieve = getMetadataRetrieve(); String xml; try { ServiceFactory factory = new ServiceFactory(); service = factory.getInstance(OMEXMLService.class); xml = service.getOMEXML(retrieve); OMEXMLMetadata noBin = service.createOMEXMLMetadata(xml); service.removeBinData(noBin); OMEXMLMetadataRoot root = (OMEXMLMetadataRoot) noBin.getRoot(); root.setCreator(FormatTools.CREATOR); xml = service.getOMEXML(noBin); } catch (DependencyException de) { throw new MissingLibraryException(OMEXMLServiceImpl.NO_OME_XML_MSG, de); } catch (ServiceException se) { throw new FormatException(se); } xmlFragments = new ArrayList<String>(); currentFragment = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; XMLTools.parseXML(xml, new OMEHandler()); xmlFragments.add(currentFragment); }