/** * Parses a XML property list from an input stream. * This method does not close the specified input stream. * * @param is The input stream pointing to the property list's data. * @return The root object of the property list. This is usually a {@link NSDictionary} but can also be a {@link NSArray}. * @see javax.xml.parsers.DocumentBuilder#parse(java.io.InputStream) * @throws javax.xml.parsers.ParserConfigurationException If a document builder for parsing a XML property list * could not be created. This should not occur. * @throws java.io.IOException If any I/O error occurs while reading the file. * @throws org.xml.sax.SAXException If any parse error occurs. * @throws com.dd.plist.PropertyListFormatException If the given property list has an invalid format. * @throws java.text.ParseException If a date string could not be parsed. */ public static NSObject parse(InputStream is) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException, ParseException { return parse(getDocBuilder().parse(is)); }
if (type.equals("dict")) { NSDictionary dict = new NSDictionary(); List<Node> children = filterElementNodes(n.getChildNodes()); for (int i = 0; i < children.size(); i += 2) { Node key = children.get(i); Node val = children.get(i + 1); String keyString = getNodeTextContents(key); dict.put(keyString, parseObject(val)); List<Node> children = filterElementNodes(n.getChildNodes()); NSArray array = new NSArray(children.size()); for (int i = 0; i < children.size(); i++) { array.setValue(i, parseObject(children.get(i))); return new NSNumber(false); } else if (type.equals("integer")) { return new NSNumber(getNodeTextContents(n)); } else if (type.equals("real")) { return new NSNumber(getNodeTextContents(n)); } else if (type.equals("string")) { return new NSString(getNodeTextContents(n)); } else if (type.equals("data")) { return new NSData(getNodeTextContents(n)); } else if (type.equals("date")) { return new NSDate(getNodeTextContents(n));
/** * Parses a XML property list from a byte array. * * @param bytes The byte array containing the property list's data. * @return The root object of the property list. This is usually a {@link NSDictionary} but can also be a {@link NSArray}. * @throws javax.xml.parsers.ParserConfigurationException If a document builder for parsing a XML property list * could not be created. This should not occur. * @throws java.io.IOException If any I/O error occurs while reading the file. * @throws org.xml.sax.SAXException If any parse error occurs. * @throws com.dd.plist.PropertyListFormatException If the given property list has an invalid format. * @throws java.text.ParseException If a date string could not be parsed. */ public static NSObject parse(final byte[] bytes) throws ParserConfigurationException, ParseException, SAXException, PropertyListFormatException, IOException { return parse(new ByteArrayInputStream(bytes)); }
List<Node> rootNodes = filterElementNodes(doc.getDocumentElement().getChildNodes()); if (rootNodes.isEmpty()) { throw new PropertyListFormatException("The given XML property list has no root element!"); return parseObject(rootNode);
private NSObject parse(final InputStream in) throws AccessDeniedException { try { return XMLPropertyListParser.parse(in); } catch(ParserConfigurationException | IOException | SAXException | ParseException | PropertyListFormatException e) { throw new AccessDeniedException("Failure parsing XML property list", e); } }
/** * Parses a XML property list file. * * @param f The XML property list file. * @return The root object of the property list. This is usually a {@link NSDictionary} but can also be a {@link NSArray}. * @see javax.xml.parsers.DocumentBuilder#parse(java.io.File) * @throws javax.xml.parsers.ParserConfigurationException If a document builder for parsing a XML property list * could not be created. This should not occur. * @throws java.io.IOException If any I/O error occurs while reading the file. * @throws org.xml.sax.SAXException If any parse error occurs. * @throws com.dd.plist.PropertyListFormatException If the given property list has an invalid format. * @throws java.text.ParseException If a date string could not be parsed. */ public static NSObject parse(File f) throws ParserConfigurationException, IOException, SAXException, PropertyListFormatException, ParseException { InputStream fileInputStream = new FileInputStream(f); try { return parse(getDocBuilder().parse(fileInputStream)); } finally { try { fileInputStream.close(); } catch (IOException e) { // ignore } } }
private NSDictionary read(final Local file) { try { return (NSDictionary) XMLPropertyListParser.parse(file.getInputStream()); } catch(ParserConfigurationException | IOException | SAXException | PropertyListFormatException | ParseException | AccessDeniedException e) { log.warn(String.format("Failure %s reading dictionary from %s", e.getMessage(), file)); } return null; }
/** * Parses a property list from an InputStream. * This method does not close the specified input stream. * * @param is The InputStream delivering the property list data. * @return The root object of the property list. This is usually a {@link NSDictionary} but can also be a {@link NSArray}. * @throws javax.xml.parsers.ParserConfigurationException If a document builder for parsing a XML property list could not be created. * @throws java.io.IOException If any I/O error occurs while reading the input stream. * @throws org.xml.sax.SAXException If any parse error occurs. * @throws com.dd.plist.PropertyListFormatException If the given property list has an invalid format. * @throws java.text.ParseException If the given property list has an invalid format. */ public static NSObject parse(InputStream is) throws IOException, PropertyListFormatException, ParseException, ParserConfigurationException, SAXException { if (!is.markSupported()) { is = new BufferedInputStream(is); } switch(determineType(is, 0)) { case TYPE_BINARY: return BinaryPropertyListParser.parse(is); case TYPE_XML: return XMLPropertyListParser.parse(is); case TYPE_ASCII: return ASCIIPropertyListParser.parse(is); case TYPE_ERROR_BLANK: return null; default: throw new PropertyListFormatException("The given data is not a property list of a supported format."); } }