/** * Parses XML from a string. * * @param xml String containing valid XML. * @return XML document. * @throws Exception Unspecified exception. */ public static Document parseXMLFromString(String xml) throws Exception { return parseXMLFromStream(IOUtils.toInputStream(xml, StandardCharsets.UTF_8)); }
/** * Parses XML from a file. * * @param filePath Full path to a file containing valid XML. * @return XML document. * @throws Exception Unspecified exception. */ public static Document parseXMLFromLocation(String filePath) throws Exception { return parseXMLFromStream(new FileInputStream(filePath)); }
/** * Parse layout from an input stream. * * @param stream The input stream. * @return The root layout element. */ public static Layout parseStream(InputStream stream) { try (InputStream is = stream) { return parseDocument(XMLUtil.parseXMLFromStream(is)); } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }
/** * Parse a tag library. * * @param stream Input stream referencing the tag library. * @return The parsed tag library. */ public TagLibrary parse(InputStream stream) { try (InputStream is = stream) { Element root = XMLUtil.parseXMLFromStream(is).getDocumentElement(); String uri = getValue(root, "uri"); NodeList nodes = root.getElementsByTagName("function"); int nodeCount = nodes.getLength(); TagLibrary tagLibrary = new TagLibrary(uri); for (int i = 0; i < nodeCount; i++) { Element ele = (Element) nodes.item(i); String name = getValue(ele, "name"); String clazz = getValue(ele, "function-class"); String signature = getValue(ele, "function-signature"); tagLibrary.addFunction(name, clazz, signature); } return tagLibrary; } catch (Exception e) { throw MiscUtil.toUnchecked(e); } }