@Override public String toString() { return element.getTagName() + ":" + element.getAttribute("name"); } }
private void readPackageConfigFromXml(Node node) throws IOException { NodeList childNodes = node.getChildNodes(); if (childNodes.getLength() > 0) { for (int j = 0, n = childNodes.getLength(); j < n; j++) { Node child = childNodes.item(j); if (child.getNodeType() == Node.ELEMENT_NODE) { Element check = (Element) child; String tagName = check.getTagName(); String value = check.getAttribute(ATTR_VALUE); String name = check.getAttribute(ATTR_NAME); if (tagName.equals(ATTR_CONFIG_FIELD)) { mPackageFields.put(name, value); } else { System.err.println("unknown package config tag " + tagName); } } } } }
protected void setPh(Element t, String ph) { if (!t.getTagName().equals(MaryXML.TOKEN)) throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Only t elements allowed, received " + t.getTagName() + "."); if (t.hasAttribute("ph")) { String prevPh = t.getAttribute("ph"); // In previous sampa, replace star with sampa: String newPh = prevPh.replaceFirst("\\*", ph); t.setAttribute("ph", newPh); } else { t.setAttribute("ph", ph); } }
private StatisticsType[] extractStatistics(Element root, StatisticsTypeFactory statFactory) { Assert.assertTrue(root.getTagName().equals("statistics")); ArrayList types = new ArrayList(); NodeList typeNodes = root.getElementsByTagName("type"); for (int i = 0; i < typeNodes.getLength(); i++) { Element typeNode = (Element) typeNodes.item(i); types.add(extractType(typeNode, statFactory)); } return (StatisticsType[]) types.toArray(new StatisticsType[types.size()]); }
private static XmlDom convert(Node node, String tag, String attr, String value){ if(node.getNodeType() != Node.ELEMENT_NODE){ return null; } Element e = (Element) node; XmlDom result = null; if(tag == null || tag.equals(e.getTagName())){ if(attr == null || e.hasAttribute(attr)){ if(value == null || value.equals(e.getAttribute(attr))){ result = new XmlDom(e); } } } return result; }
/** * Check if the List of Elements contains any TOKENS that have PHONE descendants * * @param tokensAndBoundaries * the List of Elements to check for PHONE elements * @return true once a PHONE has been found within a TOKEN, false if this never happens */ private boolean containsPhoneDescendants(List<Element> tokensAndBoundaries) { for (Element element : tokensAndBoundaries) { if (element.getTagName().equals(MaryXML.TOKEN) && element.getElementsByTagName(MaryXML.PHONE).getLength() > 0) { return true; } } return false; }
/** * Get the next sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if * there is no such element. * * @param e * e * @param name * name * @return null if n is null, true otherwise */ public static Element getNextSiblingElementByTagName(Element e, String name) { Node n = e; if (n == null) return null; while ((n = n.getNextSibling()) != null) { if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name)) return (Element) n; } return null; }
private void readLibPatternsFromXml(Node node) throws IOException { NodeList childNodes = node.getChildNodes(); if (childNodes.getLength() > 0) { for (int j = 0, n = childNodes.getLength(); j < n; j++) { Node child = childNodes.item(j); if (child.getNodeType() == Node.ELEMENT_NODE) { Element check = (Element) child; String tagName = check.getTagName(); String value = check.getAttribute(ATTR_VALUE); if (tagName.equals(ATTR_PATTERN)) { addToPatterns(value, mSoFilePattern); } else { System.err.println("unknown dex tag " + tagName); } } } } }
protected void setPh(Element t, String ph) { if (!t.getTagName().equals(MaryXML.TOKEN)) throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Only t elements allowed, received " + t.getTagName() + "."); if (t.hasAttribute("ph")) { String prevPh = t.getAttribute("ph"); // In previous sampa, replace star with sampa: String newPh = prevPh.replaceFirst("\\*", ph); t.setAttribute("ph", newPh); } else { t.setAttribute("ph", ph); } }
public InstallFileParser(URL installFile) throws IOException, SAXException { Document doc; try { InputStream in = installFile.openStream(); doc = builder.parse(in); in.close(); } catch (Exception e) { throw new IOException("Problem parsing install file " + installFile, e); } Element docElt = doc.getDocumentElement(); if (!docElt.getTagName().equals("marytts-install")) { throw new IllegalArgumentException("Expected <marytts-install> document, but found root node <" + docElt.getTagName() + ">!"); } NodeList languageElements = docElt.getElementsByTagName("language"); for (int i = 0, max = languageElements.getLength(); i < max; i++) { Element languageElement = (Element) languageElements.item(i); languages.add(new LanguageComponentDescription(languageElement)); } NodeList voiceElements = docElt.getElementsByTagName("voice"); for (int i = 0, max = voiceElements.getLength(); i < max; i++) { Element voiceElement = (Element) voiceElements.item(i); voices.add(new VoiceComponentDescription(voiceElement)); } }
public static String getPhoneSymbol(Element segmentOrBoundary) { String phone; if (segmentOrBoundary.getTagName().equals(MaryXML.PHONE)) { phone = segmentOrBoundary.getAttribute("p"); } else { assert segmentOrBoundary.getTagName().equals(MaryXML.BOUNDARY) : "Expected boundary element, but got " + segmentOrBoundary.getTagName(); // TODO: how can we know the silence symbol here? phone = "_"; } return phone; }
/** * Check if the List of Elements contains any TOKENS that have PHONE descendants * * @param tokensAndBoundaries * the List of Elements to check for PHONE elements * @return true once a PHONE has been found within a TOKEN, false if this never happens */ private boolean containsPhoneDescendants(List<Element> tokensAndBoundaries) { for (Element element : tokensAndBoundaries) { if (element.getTagName().equals(MaryXML.TOKEN) && element.getElementsByTagName(MaryXML.PHONE).getLength() > 0) { return true; } } return false; }
/** * Get the previous sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if * there is no such element. * * @param e * e * @param name * name * @return null if n is null */ public static Element getPreviousSiblingElementByTagName(Element e, String name) { Node n = e; if (n == null) return null; while ((n = n.getPreviousSibling()) != null) { if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name)) return (Element) n; } return null; }
private void readDexPatternsFromXml(Node node) throws IOException { NodeList childNodes = node.getChildNodes(); if (childNodes.getLength() > 0) { for (int j = 0, n = childNodes.getLength(); j < n; j++) { Node child = childNodes.item(j); if (child.getNodeType() == Node.ELEMENT_NODE) { Element check = (Element) child; String tagName = check.getTagName(); String value = check.getAttribute(ATTR_VALUE); if (tagName.equals(ATTR_DEX_MODE)) { if (value.equals("raw")) { mDexRaw = true; } } else if (tagName.equals(ATTR_PATTERN)) { addToPatterns(value, mDexFilePattern); } else if (tagName.equals(ATTR_LOADER)) { mDexLoaderPattern.add(value); } else if (tagName.equals(ATTR_IGNORE_CHANGE)) { mDexIgnoreWarningLoaderPattern.add(value); } else { System.err.println("unknown dex tag " + tagName); } } } } }
protected void setPh(Element t, String ph) { if (!t.getTagName().equals(MaryXML.TOKEN)) throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Only t elements allowed, received " + t.getTagName() + "."); if (t.hasAttribute("ph")) { String prevPh = t.getAttribute("ph"); // In previous sampa, replace star with sampa: String newPh = prevPh.replaceFirst("\\*", ph); t.setAttribute("ph", newPh); } else { t.setAttribute("ph", ph); } }
public InstallFileParser(URL installFile) throws IOException, SAXException { Document doc; try { InputStream in = installFile.openStream(); doc = builder.parse(in); in.close(); } catch (Exception e) { throw new IOException("Problem parsing install file " + installFile, e); } Element docElt = doc.getDocumentElement(); if (!docElt.getTagName().equals("marytts-install")) { throw new IllegalArgumentException("Expected <marytts-install> document, but found root node <" + docElt.getTagName() + ">!"); } NodeList languageElements = docElt.getElementsByTagName("language"); for (int i = 0, max = languageElements.getLength(); i < max; i++) { Element languageElement = (Element) languageElements.item(i); languages.add(new LanguageComponentDescription(languageElement)); } NodeList voiceElements = docElt.getElementsByTagName("voice"); for (int i = 0, max = voiceElements.getLength(); i < max; i++) { Element voiceElement = (Element) voiceElements.item(i); voices.add(new VoiceComponentDescription(voiceElement)); } }
@Override public ServiceConfiguration<XAStore.Provider> parseServiceConfiguration(Element fragment, ClassLoader classLoader) { String localName = fragment.getLocalName(); if ("xa-store".equals(localName)) { String uniqueXAResourceId = fragment.getAttribute("unique-XAResource-id"); return new XAStoreConfiguration(uniqueXAResourceId); } else { throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported", fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName()))); } }
/** * Get the next sibling of <code>e</code> which is an element and has tag name <code>name</code>, or <code>null</code> if * there is no such element. * * @param e * e * @param name * name * @return null if n is null, true otherwise */ public static Element getNextSiblingElementByTagName(Element e, String name) { Node n = e; if (n == null) return null; while ((n = n.getNextSibling()) != null) { if (n.getNodeType() == Node.ELEMENT_NODE && ((Element) n).getTagName().equals(name)) return (Element) n; } return null; }
private void readPropertyFromXml(Node node) throws IOException { NodeList childNodes = node.getChildNodes(); if (childNodes.getLength() > 0) { for (int j = 0, n = childNodes.getLength(); j < n; j++) { Node child = childNodes.item(j); if (child.getNodeType() == Node.ELEMENT_NODE) { Element check = (Element) child; String tagName = check.getTagName(); String value = check.getAttribute(ATTR_VALUE); if (value.length() == 0) { throw new IOException(
protected void setPh(Element t, String ph) { if (!t.getTagName().equals(MaryXML.TOKEN)) throw new DOMException(DOMException.INVALID_ACCESS_ERR, "Only t elements allowed, received " + t.getTagName() + "."); if (t.hasAttribute("ph")) { String prevPh = t.getAttribute("ph"); // In previous sampa, replace star with sampa: String newPh = prevPh.replaceFirst("\\*", ph); t.setAttribute("ph", newPh); } else { t.setAttribute("ph", ph); } }