org.w3c.dom.NodeList

Here are the examples of the java api class org.w3c.dom.NodeList taken from open source projects.

1. SamlModel#hasDestinationIndication()

Project: OWASP-WebScarab
Source File: SamlModel.java
View license
public boolean hasDestinationIndication(ConversationID id) {
    Document document = getSAMLDocument(id);
    if (null == document) {
        return false;
    }
    NodeList saml2ResponseNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "Response");
    if (0 != saml2ResponseNodeList.getLength()) {
        return hasDestinationIndicationSaml2Response((Element) saml2ResponseNodeList.item(0));
    }
    NodeList saml2AuthnRequestNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest");
    if (0 != saml2AuthnRequestNodeList.getLength()) {
        return hasDestinationIndicationSaml2AuthnRequest((Element) saml2AuthnRequestNodeList.item(0));
    }
    NodeList saml1ResponseNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:protocol", "Response");
    if (0 != saml1ResponseNodeList.getLength()) {
        return hasDestinationIndicationSaml1Response((Element) saml1ResponseNodeList.item(0));
    }
    return false;
}

2. SamlTest#testEncryptedXML()

Project: OWASP-WebScarab
Source File: SamlTest.java
View license
@Test
public void testEncryptedXML() throws Exception {
    // setup
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    builderFactory.setNamespaceAware(true);
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Document document = builder.parse(SamlTest.class.getResourceAsStream("/test-saml-response-encrypted-attribute.xml"));
    NodeList nodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "EncryptedAttribute");
    assertEquals(1, nodeList.getLength());
    Element encryptedAttributeElement = (Element) nodeList.item(0);
    NodeList encryptedDataNodeList = encryptedAttributeElement.getElementsByTagNameNS("http://www.w3.org/2001/04/xmlenc#", "EncryptedData");
    assertEquals(1, encryptedDataNodeList.getLength());
    Element encryptedDataElement = (Element) encryptedDataNodeList.item(0);
    Init.init();
    XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.AES_128);
    String aes128HexStr = "2a1e3d83f475ec3c007f487c5150a5f2";
    byte[] aes128Bytes = Hex.decode(aes128HexStr);
    SecretKeySpec secretKeySpec = new SecretKeySpec(aes128Bytes, "AES");
    xmlCipher.init(XMLCipher.DECRYPT_MODE, secretKeySpec);
    xmlCipher.doFinal(document, encryptedDataElement);
    LOG.debug("decrypted attribute: " + toString(encryptedAttributeElement));
    NodeList attributeNodeList = encryptedAttributeElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute");
    assertEquals(1, attributeNodeList.getLength());
}

3. SamlModel#getSAMLVersion()

Project: OWASP-WebScarab
Source File: SamlModel.java
View license
public int getSAMLVersion(ConversationID id) {
    Document document = getSAMLDocument(id);
    if (null == document) {
        return 0;
    }
    NodeList saml1ResponseNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:protocol", "Response");
    if (0 != saml1ResponseNodeList.getLength()) {
        return SAML_VERSION_1_1;
    }
    NodeList saml2AuthnRequestNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest");
    if (0 != saml2AuthnRequestNodeList.getLength()) {
        return SAML_VERSION_2;
    }
    NodeList saml2ResponseNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "Response");
    if (0 != saml2ResponseNodeList.getLength()) {
        return SAML_VERSION_2;
    }
    return 0;
}

4. XmlAgentConfigurationBuilder#getForbiddenPaths()

View license
private void getForbiddenPaths(Element parent, AgentConfigurationDefaultImpl agentConfiguration) {
    NodeList nodes = parent.getElementsByTagName(EXCLUDED_PREFIXES_TAG);
    Element forbiddenElement = getFirst(nodes);
    if (forbiddenElement == null) {
        return;
    }
    HashSet<String> excludedPrefixes = new HashSet<String>();
    NodeList addClasses = forbiddenElement.getElementsByTagName(FORBIDDEN_PREFIX_TAG);
    if (addClasses == null) {
        return;
    }
    for (int index = 0; index < addClasses.getLength(); ++index) {
        Element classElement = getClassDataElement(addClasses.item(index));
        if (classElement == null) {
            continue;
        }
        excludedPrefixes.add(classElement.getFirstChild().getTextContent());
    }
    agentConfiguration.setExcludedPrefixes(excludedPrefixes);
}

5. SamlModel#hasDestinationIndicationSaml1Response()

Project: OWASP-WebScarab
Source File: SamlModel.java
View license
private boolean hasDestinationIndicationSaml1Response(Element responseElement) {
    if (null != responseElement.getAttributeNode("Recipient")) {
        return true;
    }
    NodeList assertionNodeList = responseElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Assertion");
    if (0 == assertionNodeList.getLength()) {
        return false;
    }
    Element assertionElement = (Element) assertionNodeList.item(0);
    NodeList audienceNodeList = assertionElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Audience");
    if (0 != audienceNodeList.getLength()) {
        return true;
    }
    return false;
}

6. XMLModelsParser#getModels()

Project: spaceracer3d
Source File: XMLModelsParser.java
View license
public ArrayList<String> getModels(final String objectName) throws Exception {
    if (filename == null) {
        throw new Exception("No XML file to parse is specified!");
    }
    final ArrayList<String> models = new ArrayList<String>();
    final String expression = "/models/" + objectName;
    final InputSource inputSource = new InputSource(filename);
    final NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
    NodeList modelNodes;
    String model = null;
    for (int i = 0; i < nodes.getLength(); i++) {
        modelNodes = nodes.item(i).getChildNodes();
        for (int j = 1; j < modelNodes.getLength(); j += 2) {
            model = modelNodes.item(j).getTextContent();
            if (model != null && model.length() > 0) {
                models.add(model);
            }
        }
    }
    return models;
}

7. EntityChildTest#test()

Project: openjdk
Source File: EntityChildTest.java
View license
@Test
public void test() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(true);
    DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    Document document = docBuilder.parse(new File(XML_DIR + "entitychild.xml"));
    Element root = document.getDocumentElement();
    NodeList n = root.getElementsByTagName("table");
    NodeList nl = n.item(0).getChildNodes();
    assertEquals(n.getLength(), 1);
    assertEquals(nl.getLength(), 3);
}

8. NodeListTest#lastItemTest()

Project: openjdk
Source File: NodeListTest.java
View license
@Test(dataProvider = "xml")
public void lastItemTest(String xmlFileName, String nodeName) throws Exception {
    Document document = createDOM(xmlFileName);
    NodeList nl = document.getElementsByTagName(nodeName);
    int n = nl.getLength();
    Element elem1 = (Element) nl.item(n - 1);
    nl.item(n);
    Element elem3 = (Element) nl.item(n - 1);
    assertEquals(elem3, elem1);
}

9. JaxpIssue43Test#getSchemaSources()

Project: openjdk
Source File: JaxpIssue43Test.java
View license
private Source[] getSchemaSources() throws Exception {
    List<Source> list = new ArrayList<Source>();
    String file = getClass().getResource("hello_literal.wsdl").getFile();
    Source source = new StreamSource(new FileInputStream(file), file);
    Transformer trans = TransformerFactory.newInstance().newTransformer();
    DOMResult result = new DOMResult();
    trans.transform(source, result);
    // Look for <xsd:schema> element in wsdl
    Element e = ((Document) result.getNode()).getDocumentElement();
    NodeList typesList = e.getElementsByTagNameNS("http://schemas.xmlsoap.org/wsdl/", "types");
    NodeList schemaList = ((Element) typesList.item(0)).getElementsByTagNameNS("http://www.w3.org/2001/XMLSchema", "schema");
    Element elem = (Element) schemaList.item(0);
    list.add(new DOMSource(elem, file + "#schema0"));
    return list.toArray(new Source[list.size()]);
}

10. XPathPropertyArrayItemGetter#get()

View license
public Object get(EventBean eventBean) throws PropertyAccessException {
    Object result = getter.get(eventBean);
    if (!(result instanceof NodeList)) {
        return null;
    }
    NodeList nodeList = (NodeList) result;
    if (nodeList.getLength() <= index) {
        return null;
    }
    return nodeList.item(index);
}

11. TestMixinXml#textExceptions()

Project: etch
Source File: TestMixinXml.java
View license
/** @throws Exception */
@org.junit.Test
public void textExceptions() throws Exception {
    // verify exceptions
    NodeList exceptionsNodeList = document.getElementsByTagName("exceptions");
    assertEquals(exceptionsNodeList.getLength(), 1);
    Node exceptionsNode = exceptionsNodeList.item(0);
    ArrayList<Node> list = new ArrayList<Node>();
    NodeList exceptionsNodeChildren = exceptionsNode.getChildNodes();
    for (int i = 0; i < exceptionsNodeChildren.getLength(); i++) {
        if (exceptionsNodeChildren.item(i).getNodeName() == "exception") {
            list.add(exceptionsNodeChildren.item(i));
        }
    }
    assertEquals(list.size(), 0);
}

12. ExecutionReportTest#shouldHandleMissingRunTimesGraceFully()

Project: fitnesse
Source File: ExecutionReportTest.java
View license
@Test
public void shouldHandleMissingRunTimesGraceFully() throws Exception {
    TestExecutionReport report = new TestExecutionReport(new FitNesseVersion("version"), "rootPath");
    Element element = mock(Element.class);
    NodeList emptyNodeList = mock(NodeList.class);
    when(element.getElementsByTagName("totalRunTimeInMillis")).thenReturn(emptyNodeList);
    when(emptyNodeList.getLength()).thenReturn(0);
    assertThat(report.getTotalRunTimeInMillisOrMinusOneIfNotPresent(element), is(-1L));
    element = mock(Element.class);
    NodeList matchingNodeList = mock(NodeList.class);
    Node elementWithText = mock(Element.class);
    when(element.getElementsByTagName("totalRunTimeInMillis")).thenReturn(matchingNodeList);
    when(matchingNodeList.getLength()).thenReturn(1);
    when(matchingNodeList.item(0)).thenReturn(elementWithText);
    when(elementWithText.getTextContent()).thenReturn("255");
    assertThat(report.getTotalRunTimeInMillisOrMinusOneIfNotPresent(element), is(255L));
}

13. SuiteExecutionReportTest#shouldHandleMissingRunTimesGraceFully()

View license
@Test
public void shouldHandleMissingRunTimesGraceFully() throws Exception {
    Element element = mock(Element.class);
    NodeList emptyNodeList = mock(NodeList.class);
    when(element.getElementsByTagName("runTimeInMillis")).thenReturn(emptyNodeList);
    when(emptyNodeList.getLength()).thenReturn(0);
    assertThat(report1.getRunTimeInMillisOrZeroIfNotPresent(element), is(0L));
    element = mock(Element.class);
    NodeList matchingNodeList = mock(NodeList.class);
    Node elementWithText = mock(Element.class);
    when(element.getElementsByTagName("runTimeInMillis")).thenReturn(matchingNodeList);
    when(matchingNodeList.getLength()).thenReturn(1);
    when(matchingNodeList.item(0)).thenReturn(elementWithText);
    when(elementWithText.getTextContent()).thenReturn("255");
    assertThat(report1.getRunTimeInMillisOrZeroIfNotPresent(element), is(255L));
}

14. XformsQueueProcessor#getPatientIdentifier()

Project: buendia
Source File: XformsQueueProcessor.java
View license
private String getPatientIdentifier(Document doc) {
    NodeList elemList = doc.getDocumentElement().getElementsByTagName("patient");
    if (!(elemList != null && elemList.getLength() > 0))
        return null;
    Element patientNode = (Element) elemList.item(0);
    NodeList children = patientNode.getChildNodes();
    int len = patientNode.getChildNodes().getLength();
    for (int index = 0; index < len; index++) {
        Node child = children.item(index);
        if (child.getNodeType() != Node.ELEMENT_NODE)
            continue;
        if ("patient_identifier".equalsIgnoreCase(((Element) child).getAttribute("openmrs_table")) && "identifier".equalsIgnoreCase(((Element) child).getAttribute("openmrs_attribute")))
            return child.getTextContent();
    }
    return null;
}

15. DMLConfig#updateYarnMemorySettings()

Project: incubator-systemml
Source File: DMLConfig.java
View license
/**
	 * 
	 * @param amMem
	 * @param mrMem
	 */
public void updateYarnMemorySettings(String amMem, String mrMem) {
    //app master memory
    NodeList list1 = _xmlRoot.getElementsByTagName(YARN_APPMASTERMEM);
    if (list1 != null && list1.getLength() > 0) {
        Element elem = (Element) list1.item(0);
        elem.getFirstChild().setNodeValue(String.valueOf(amMem));
    }
    //mapreduce memory
    NodeList list2 = _xmlRoot.getElementsByTagName(YARN_MAPREDUCEMEM);
    if (list2 != null && list2.getLength() > 0) {
        Element elem = (Element) list2.item(0);
        elem.getFirstChild().setNodeValue(String.valueOf(mrMem));
    }
}

16. XMLDocumentHelper#createElementMappingForNodes()

View license
/**
     * Creates the element mapping for the specified nodes and all their child
     * nodes.
     *
     * @param n1 node 1
     * @param n2 node 2
     * @param mapping the mapping to be filled
     */
private static void createElementMappingForNodes(Node n1, Node n2, Map<Node, Node> mapping) {
    mapping.put(n1, n2);
    NodeList childNodes1 = n1.getChildNodes();
    NodeList childNodes2 = n2.getChildNodes();
    int count = Math.min(childNodes1.getLength(), childNodes2.getLength());
    for (int i = 0; i < count; i++) {
        createElementMappingForNodes(childNodes1.item(i), childNodes2.item(i), mapping);
    }
}

17. RCSBDescriptionFactory#makeMolecule()

Project: biojava
Source File: RCSBDescriptionFactory.java
View license
private static RCSBMacromolecule makeMolecule(Element moleculeE) {
    RCSBMacromolecule molecule = new RCSBMacromolecule();
    molecule.setName(moleculeE.getAttribute("name"));
    Element element = null;
    NodeList data = moleculeE.getChildNodes();
    for (int i = 0; i < data.getLength(); i++) {
        if (data.item(i).getNodeType() != 1)
            continue;
        element = (Element) data.item(i);
        if (element.getNodeName().equals("accession")) {
            molecule.addAccession(element.getAttribute("id"));
        }
    }
    return molecule;
}

18. NativeBroker#dropIndex()

Project: exist
Source File: NativeBroker.java
View license
private void dropIndex(final Txn transaction, final DocumentImpl document) throws ReadOnlyException {
    final StreamListener listener = indexController.getStreamListener(document, ReindexMode.REMOVE_ALL_NODES);
    final NodeList nodes = document.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        final IStoredNode<?> node = (IStoredNode<?>) nodes.item(i);
        try (final INodeIterator iterator = getNodeIterator(node)) {
            iterator.next();
            scanNodes(transaction, iterator, node, new NodePath(), IndexMode.REMOVE, listener);
        } catch (final IOException ioe) {
            LOG.warn("Unable to close node iterator", ioe);
        }
    }
    notifyDropIndex(document);
    indexController.flush();
}

19. RCSBLigandsFactory#makeLigand()

Project: biojava
Source File: RCSBLigandsFactory.java
View license
private static RCSBLigand makeLigand(Element ligandE) {
    RCSBLigand ligand = new RCSBLigand();
    ligand.setId(ligandE.getAttribute("chemicalID"));
    ligand.setType(ligandE.getAttribute("type"));
    ligand.setWeight(ReadUtils.toDouble(ligandE.getAttribute("molecularWeight")));
    Element element = null;
    NodeList data = ligandE.getChildNodes();
    for (int i = 0; i < data.getLength(); i++) {
        if (data.item(i).getNodeType() != 1)
            continue;
        element = (Element) data.item(i);
        if (element.getNodeName().equals("chemicalName")) {
            ligand.setName(element.getTextContent());
        } else if (element.getNodeName().equals("formula")) {
            ligand.setFormula(element.getTextContent());
        } else if (element.getNodeName().equals("InChIKey")) {
            ligand.setInChIKey(element.getTextContent());
        } else if (element.getNodeName().equals("InChI")) {
            ligand.setInChI(element.getTextContent());
        } else if (element.getNodeName().equals("smiles")) {
            ligand.setSmiles(element.getTextContent());
        }
    }
    return ligand;
}

20. BNDAnnotationTest#print()

Project: bnd
Source File: BNDAnnotationTest.java
View license
private static void print(Node doc, String indent) {
    System.err.println(indent + doc);
    NamedNodeMap attributes = doc.getAttributes();
    if (attributes != null)
        for (int i = 0; i < attributes.getLength(); i++) {
            print(attributes.item(i), indent + "  ");
        }
    NodeList nl = doc.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        print(nl.item(i), indent + "  ");
    }
}

21. POM#index()

Project: bnd
Source File: POM.java
View license
private void index(Element node, String prefix, String... names) throws XPathExpressionException {
    String expr = "./*";
    if (names.length > 0) {
        StringBuilder sb = new StringBuilder("./*[");
        String del = "name()=";
        for (String name : names) {
            sb.append(del).append('"').append(name).append('"');
            del = " or name()=";
        }
        sb.append("]");
        expr = sb.toString();
    }
    NodeList childNodes = (NodeList) xp.evaluate(expr, node, XPathConstants.NODESET);
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        String key = child.getNodeName();
        String value = child.getTextContent().trim();
        properties.put(prefix + key, value);
    }
}

22. ResultDocModifier#getElementById()

Project: clerezza
Source File: ResultDocModifier.java
View license
private Element getElementById(Element element, String id) {
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element) {
            Element subElement = (Element) node;
            NamedNodeMap attrs = subElement.getAttributes();
            if (attrs != null) {
                Node idNode = attrs.getNamedItem("id");
                if ((idNode != null) && (id.equals(idNode.getTextContent()))) {
                    return subElement;
                }
            }
            Element subResult = getElementById(subElement, id);
            if (subResult != null) {
                return subResult;
            }
        }
    }
    return null;
}

23. XfaForm#fillXfaForm()

Project: clj-pdf
Source File: XfaForm.java
View license
/**
     * Replaces the data under datasets/data.
     * @since	iText 5.0.0
     */
public void fillXfaForm(Node node) {
    Node data = datasetsNode.getFirstChild();
    NodeList list = data.getChildNodes();
    if (list.getLength() == 0) {
        data.appendChild(domDocument.importNode(node, true));
    } else {
        data.replaceChild(domDocument.importNode(node, true), data.getFirstChild());
    }
    extractNodes();
    setChanged(true);
}

24. XmpReader#add()

Project: clj-pdf
Source File: XmpReader.java
View license
/**
	 * Adds a tag.
	 * @param	namespaceURI	the URI of the namespace
	 * @param	parent			the tag name of the parent
	 * @param	localName		the name of the tag to add
	 * @param	value			the new content for the tag
	 * @return	true if the content was successfully added
	 * @since	2.1.6
	 */
public boolean add(String parent, String namespaceURI, String localName, String value) {
    NodeList nodes = domDocument.getElementsByTagName(parent);
    if (nodes.getLength() == 0)
        return false;
    Node pNode;
    Node node;
    for (int i = 0; i < nodes.getLength(); i++) {
        pNode = nodes.item(i);
        NamedNodeMap attrs = pNode.getAttributes();
        for (int j = 0; j < attrs.getLength(); j++) {
            node = attrs.item(j);
            if (namespaceURI.equals(node.getNodeValue())) {
                node = domDocument.createElement(localName);
                node.appendChild(domDocument.createTextNode(value));
                pNode.appendChild(node);
                return true;
            }
        }
    }
    return false;
}

25. XmpReader#serializeDoc()

Project: clj-pdf
Source File: XmpReader.java
View license
/**
     * Writes the document to a byte array.
     */
public byte[] serializeDoc() throws IOException {
    XmlDomWriter xw = new XmlDomWriter();
    ByteArrayOutputStream fout = new ByteArrayOutputStream();
    xw.setOutput(fout, null);
    fout.write(XmpWriter.XPACKET_PI_BEGIN.getBytes("UTF-8"));
    fout.flush();
    NodeList xmpmeta = domDocument.getElementsByTagName("x:xmpmeta");
    xw.write(xmpmeta.item(0));
    fout.flush();
    for (int i = 0; i < 20; i++) {
        fout.write(XmpWriter.EXTRASPACE.getBytes());
    }
    fout.write(XmpWriter.XPACKET_PI_END_W.getBytes());
    fout.close();
    return fout.toByteArray();
}

26. XmlUtil#getChildNodes()

Project: cmb
Source File: XmlUtil.java
View license
public static List<Element> getChildNodes(Element ele, String tagName) {
    List<Element> elements = new ArrayList<Element>();
    if (ele == null) {
        return elements;
    }
    NodeList nl = ele.getChildNodes();
    if (nl != null && nl.getLength() > 0) {
        for (Integer i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element && ((Element) node).getNodeName().equals(tagName)) {
                elements.add((Element) node);
            }
        }
    }
    return elements;
}

27. XmlUtil#getChildNodes()

Project: cmb
Source File: XmlUtil.java
View license
public static List<Element> getChildNodes(Element ele) {
    List<Element> elements = new ArrayList<Element>();
    if (ele == null) {
        return elements;
    }
    NodeList nl = ele.getChildNodes();
    if (nl != null && nl.getLength() > 0) {
        for (Integer i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element) {
                elements.add((Element) node);
            }
        }
    }
    return elements;
}

28. XmlUtil#getCurrentLevelChildNodes()

Project: cmb
Source File: XmlUtil.java
View license
public static List<Element> getCurrentLevelChildNodes(Element ele, String tagName) {
    List<Element> elements = new ArrayList<Element>();
    if (ele == null) {
        return elements;
    }
    NodeList nl = ele.getChildNodes();
    if (nl != null && nl.getLength() > 0) {
        for (Integer i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element && ((Element) node).getNodeName().equals(tagName)) {
                elements.add((Element) node);
            }
        }
    }
    return elements;
}

29. XMLRuleLoader#loadTableRules()

Project: cobar
Source File: XMLRuleLoader.java
View license
private void loadTableRules(Element root) throws SQLSyntaxErrorException {
    NodeList list = root.getElementsByTagName("tableRule");
    for (int i = 0, n = list.getLength(); i < n; ++i) {
        Node node = list.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            String name = e.getAttribute("name");
            if (tableRules.containsKey(name)) {
                throw new ConfigException("table rule " + name + " duplicated!");
            }
            NodeList ruleNodes = e.getElementsByTagName("rule");
            int length = ruleNodes.getLength();
            List<RuleConfig> ruleList = new ArrayList<RuleConfig>(length);
            for (int j = 0; j < length; ++j) {
                RuleConfig rule = loadRule((Element) ruleNodes.item(j));
                ruleList.add(rule);
                rules.add(rule);
            }
            tableRules.put(name, new TableRuleConfig(name, ruleList));
        }
    }
}

30. XMLRuleLoader#loadFunctions()

Project: cobar
Source File: XMLRuleLoader.java
View license
private void loadFunctions(Element root) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
    NodeList list = root.getElementsByTagName("function");
    for (int i = 0, n = list.getLength(); i < n; ++i) {
        Node node = list.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            String name = e.getAttribute("name");
            if (functions.containsKey(name)) {
                throw new ConfigException("rule function " + name + " duplicated!");
            }
            String clazz = e.getAttribute("class");
            RuleAlgorithm function = createFunction(name, clazz);
            ParameterMapping.mapping(function, ConfigUtil.loadElements(e));
            functions.put(name, function);
        }
    }
}

31. XMLSchemaLoader#findPropertyByName()

Project: cobar
Source File: XMLSchemaLoader.java
View license
private static Element findPropertyByName(Element bean, String name) {
    NodeList propertyList = bean.getElementsByTagName("property");
    for (int j = 0, m = propertyList.getLength(); j < m; ++j) {
        Node node = propertyList.item(j);
        if (node instanceof Element) {
            Element p = (Element) node;
            if (name.equals(p.getAttribute("name"))) {
                return p;
            }
        }
    }
    return null;
}

32. XMLServerLoader#loadUsers()

Project: cobar
Source File: XMLServerLoader.java
View license
private void loadUsers(Element root) {
    NodeList list = root.getElementsByTagName("user");
    for (int i = 0, n = list.getLength(); i < n; i++) {
        Node node = list.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            String name = e.getAttribute("name");
            UserConfig user = new UserConfig();
            user.setName(name);
            Map<String, Object> props = ConfigUtil.loadElements(e);
            user.setPassword((String) props.get("password"));
            String schemas = (String) props.get("schemas");
            if (schemas != null) {
                String[] strArray = SplitUtil.split(schemas, ',', true);
                user.setSchemas(new HashSet<String>(Arrays.asList(strArray)));
            }
            if (users.containsKey(name)) {
                throw new ConfigException("user " + name + " duplicated!");
            }
            users.put(name, user);
        }
    }
}

33. ConfigUtil#loadElements()

Project: cobar
Source File: ConfigUtil.java
View license
public static Map<String, Object> loadElements(Element parent) {
    Map<String, Object> map = new HashMap<String, Object>();
    NodeList children = parent.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.item(i);
        if (node instanceof Element) {
            Element e = (Element) node;
            String name = e.getNodeName();
            if ("property".equals(name)) {
                String key = e.getAttribute("name");
                NodeList nl = e.getElementsByTagName("bean");
                if (nl.getLength() == 0) {
                    String value = e.getTextContent();
                    map.put(key, StringUtil.isEmpty(value) ? null : value.trim());
                } else {
                    map.put(key, loadBean((Element) nl.item(0)));
                }
            }
        }
    }
    return map;
}

34. DomHelper#getChildElements()

Project: cocoon
Source File: DomHelper.java
View license
/**
     * Returns all Element children of an Element that belong to the given
     * namespace and have the given local name.
     */
public static Element[] getChildElements(Element element, String namespace, String localName) {
    ArrayList elements = new ArrayList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName())) {
            elements.add(node);
        }
    }
    return (Element[]) elements.toArray(new Element[elements.size()]);
}

35. DomHelper#getChildElement()

Project: cocoon
Source File: DomHelper.java
View license
/**
     * Returns the first child element with the given namespace and localName,
     * or null if there is no such element and required flag is unset or
     * throws an Exception if the "required" flag is set.
     */
public static Element getChildElement(Element element, String namespace, String localName, boolean required) throws FormsException {
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName())) {
            return (Element) node;
        }
    }
    if (required) {
        throw new FormsException("Required element '" + localName + "' is missing.", DomHelper.getLocationObject(element));
    }
    return null;
}

36. DomHelper#compileElementContent()

Project: cocoon
Source File: DomHelper.java
View license
/**
     * Returns the content of the given Element as an object implementing the
     * XMLizable interface. Practically speaking, the implementation uses the
     * {@link SaxBuffer} class. The XMLizable object will be a standalone blurb
     * of SAX events, not producing start/endDocument calls and containing all
     * necessary namespace declarations.
     */
public static XMLizable compileElementContent(Element element) {
    // Remove location information
    LocationAttributes.remove(element, true);
    SaxBuffer saxBuffer = new SaxBuffer();
    DOMStreamer domStreamer = new DOMStreamer();
    domStreamer.setContentHandler(saxBuffer);
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        try {
            domStreamer.stream(childNodes.item(i));
        } catch (SAXException e) {
            throw new RuntimeException("Error in DomHelper.compileElementContent: " + e.toString());
        }
    }
    return saxBuffer;
}

37. SourceProperty#getValueAsString()

Project: cocoon
Source File: SourceProperty.java
View license
/**
     * Returns the value of the property
     *
     * @return Value of the property
     */
public String getValueAsString() {
    NodeList nodeslist = this.value.getChildNodes();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < nodeslist.getLength(); i++) {
        if ((nodeslist.item(i).getNodeType() == Node.TEXT_NODE) || (nodeslist.item(i).getNodeType() == Node.CDATA_SECTION_NODE)) {
            buffer.append(nodeslist.item(i).getNodeValue());
        }
    }
    return buffer.toString();
}

38. RequestSessionContext#getNodeList()

Project: cocoon
Source File: RequestSessionContext.java
View license
/**
     * Get a copy all the nodes specified by the path.
     */
public NodeList getNodeList(String path) throws ProcessingException {
    path = this.createPath(path);
    NodeList list = null;
    try {
        list = DOMUtil.selectNodeList(this.contextData, path, this.xpathProcessor);
    } catch (javax.xml.transform.TransformerException localException) {
        throw new ProcessingException("Exception: " + localException, localException);
    }
    return list;
}

39. SimpleSessionContext#removeXML()

Project: cocoon
Source File: SimpleSessionContext.java
View license
/**
     * Remove nodes
     */
public synchronized void removeXML(String path) throws ProcessingException {
    NodeList list;
    path = this.createPath(path);
    String[] pathComponents = DOMUtil.buildPathArray(path);
    if (pathComponents == null) {
        list = this.xpathProcessor.selectNodeList(this.data, path);
    } else {
        list = DOMUtil.getNodeListFromPath(data, pathComponents);
    }
    if (list != null && list.getLength() > 0) {
        int len = list.getLength();
        Node child;
        for (int i = 0; i < len; i++) {
            child = list.item(len - 1 - i);
            child.getParentNode().removeChild(child);
        }
    }
}

40. SimpleSessionContext#getNodeList()

Project: cocoon
Source File: SimpleSessionContext.java
View license
/**
     * Get a copy all the nodes specified by the path.
     */
public synchronized NodeList getNodeList(String path) throws ProcessingException {
    NodeList result = null;
    path = this.createPath(path);
    String[] pathComponents = DOMUtil.buildPathArray(path);
    if (pathComponents == null) {
        result = this.xpathProcessor.selectNodeList(this.data, path);
    } else {
        result = DOMUtil.getNodeListFromPath(data, pathComponents);
    }
    // clone list
    if (result != null) {
        result = new NodeListImpl(result);
    }
    return result;
}

41. Comment#execute()

Project: cocoon
Source File: Comment.java
View license
public Event execute(final XMLConsumer consumer, ExpressionContext expressionContext, ExecutionContext executionContext, MacroContext macroContext, Event startEvent, Event endEvent) throws SAXException {
    // Parse the body of the comment
    NodeList nodeList = Invoker.toDOMNodeList("comment", this, expressionContext, executionContext, macroContext);
    // JXPath doesn't handle NodeList, so convert it to an array
    int len = nodeList.getLength();
    final StringBuffer buf = new StringBuffer();
    Properties omit = XMLUtils.createPropertiesForXML(true);
    for (int i = 0; i < len; i++) {
        try {
            buf.append(XMLUtils.serializeNode(nodeList.item(i), omit));
        } catch (ProcessingException e) {
            throw new SAXParseException(e.getMessage(), getLocation(), e);
        }
    }
    char[] chars = new char[buf.length()];
    buf.getChars(0, chars.length, chars, 0);
    consumer.comment(chars, 0, chars.length);
    return getEndInstruction().getNext();
}

42. DomHelper#getChildElements()

Project: cocoon
Source File: DomHelper.java
View license
/**
     * Returns all Element children of an Element that belong to the given
     * namespace.
     */
public static Element[] getChildElements(Element element, String namespace) {
    ArrayList elements = new ArrayList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI()))
            elements.add(node);
    }
    return (Element[]) elements.toArray(new Element[0]);
}

43. DomHelper#getChildElements()

Project: cocoon
Source File: DomHelper.java
View license
/**
     * Returns all Element children of an Element that belong to the given
     * namespace and have the given local name.
     */
public static Element[] getChildElements(Element element, String namespace, String localName) {
    ArrayList elements = new ArrayList();
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName())) {
            elements.add(node);
        }
    }
    return (Element[]) elements.toArray(new Element[0]);
}

44. DomHelper#getChildElement()

Project: cocoon
Source File: DomHelper.java
View license
/**
     * Returns the first child element with the given namespace and localName,
     * or null if there is no such element and required flag is unset or
     * throws an Exception if the "required" flag is set.
     */
public static Element getChildElement(Element element, String namespace, String localName, boolean required) throws Exception {
    NodeList nodeList = element.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node instanceof Element && namespace.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName())) {
            return (Element) node;
        }
    }
    if (required) {
        throw new Exception("Missing element \"" + localName + "\" as child of element \"" + element.getTagName() + "\" at " + DomHelper.getLocation(element));
    } else {
        return null;
    }
}

45. DomHelper#compileElementContent()

Project: cocoon
Source File: DomHelper.java
View license
/**
     * Returns the content of the given Element as an object implementing the
     * XMLizable interface. Practically speaking, the implementation uses the
     * {@link SaxBuffer} class. The XMLizable object will be a standalone blurb
     * of SAX events, not producing start/endDocument calls and containing all
     * necessary namespace declarations.
     */
public static XMLizable compileElementContent(Element element) {
    SaxBuffer saxBuffer = new SaxBuffer();
    DOMStreamer domStreamer = new DOMStreamer();
    domStreamer.setContentHandler(saxBuffer);
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        try {
            domStreamer.stream(childNodes.item(i));
        } catch (SAXException e) {
            throw new RuntimeException("Error in DomHelper.compileElementContent: " + e.toString());
        }
    }
    return saxBuffer;
}

46. BeanConfigurator#parseLoggingNode()

Project: cocoon
Source File: BeanConfigurator.java
View license
private static void parseLoggingNode(CocoonBean cocoon, Node node) throws IllegalArgumentException {
    if (hasAttribute(node, ATTR_LOG_KIT)) {
        cocoon.setLogKit(getAttributeValue(node, ATTR_LOG_KIT));
    }
    if (hasAttribute(node, ATTR_LOGGER)) {
        cocoon.setLogger(getAttributeValue(node, ATTR_LOGGER));
    }
    if (hasAttribute(node, ATTR_LOG_LEVEL)) {
        cocoon.setLogLevel(getAttributeValue(node, ATTR_LOG_LEVEL));
    }
    NodeList nodes = node.getChildNodes();
    if (nodes.getLength() != 0) {
        throw new IllegalArgumentException("Unexpected children of <" + NODE_LOGGING + "> node");
    }
}

47. BeanConfigurator#parseBrokenLinkNode()

Project: cocoon
Source File: BeanConfigurator.java
View license
private static void parseBrokenLinkNode(CocoonBean cocoon, Node node, OutputStreamListener listener) throws IllegalArgumentException {
    if (hasAttribute(node, ATTR_BROKEN_LINK_REPORT_FILE)) {
        listener.setReportFile(getAttributeValue(node, ATTR_BROKEN_LINK_REPORT_FILE));
    }
    if (hasAttribute(node, ATTR_BROKEN_LINK_REPORT_TYPE)) {
        listener.setReportType(getAttributeValue(node, ATTR_BROKEN_LINK_REPORT_TYPE));
    }
    if (hasAttribute(node, ATTR_BROKEN_LINK_GENERATE)) {
        cocoon.setBrokenLinkGenerate(getBooleanAttributeValue(node, ATTR_BROKEN_LINK_GENERATE));
    }
    if (hasAttribute(node, ATTR_BROKEN_LINK_EXTENSION)) {
        cocoon.setBrokenLinkExtension(getAttributeValue(node, ATTR_BROKEN_LINK_EXTENSION));
    }
    NodeList nodes = node.getChildNodes();
    if (nodes.getLength() != 0) {
        throw new IllegalArgumentException("Unexpected children of <" + NODE_BROKEN_LINKS + "> node");
    }
}

48. BeanConfigurator#parseIncludeExcludeNode()

Project: cocoon
Source File: BeanConfigurator.java
View license
private static String parseIncludeExcludeNode(CocoonBean cocoon, Node node, final String NODE_TYPE) throws IllegalArgumentException {
    NodeList nodes = node.getChildNodes();
    if (nodes.getLength() != 0) {
        throw new IllegalArgumentException("Unexpected children of <" + NODE_INCLUDE + "> node");
    }
    if (hasAttribute(node, ATTR_INCLUDE_EXCLUDE_PATTERN)) {
        return getAttributeValue(node, ATTR_INCLUDE_EXCLUDE_PATTERN);
    } else {
        throw new IllegalArgumentException("Expected a " + ATTR_INCLUDE_EXCLUDE_PATTERN + " attribute for <" + NODE_TYPE + "> node");
    }
}

49. BeanConfigurator#getNodeValue()

Project: cocoon
Source File: BeanConfigurator.java
View license
private static String getNodeValue(Node root, String name) throws IllegalArgumentException {
    NodeList nodes = root.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            String nodeName = node.getNodeName();
            if (nodeName.equals(name)) {
                return getNodeValue(node);
            }
        }
    }
    return null;
}

50. BeanConfigurator#getNodeValue()

Project: cocoon
Source File: BeanConfigurator.java
View license
private static String getNodeValue(Node node) throws IllegalArgumentException {
    StringBuffer s = new StringBuffer();
    NodeList children = node.getChildNodes();
    boolean found = false;
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.TEXT_NODE) {
            s.append(child.getNodeValue());
            found = true;
        } else {
            throw new IllegalArgumentException("Unexpected node:" + child.getLocalName());
        }
    }
    if (!found) {
        throw new IllegalArgumentException("Expected value for " + node.getLocalName() + " node");
    }
    return s.toString();
}

51. TimelineEditor#getDisposalMethod()

Project: CodenameOne
Source File: TimelineEditor.java
View license
static String getDisposalMethod(ImageReader reader, int num) throws IOException {
    IIOMetadata meta = reader.getImageMetadata(num);
    Node parent = meta.getAsTree("javax_imageio_gif_image_1.0");
    //printNodeTree(parent);
    NodeList root = parent.getChildNodes();
    for (int iter = 0; iter < root.getLength(); iter++) {
        Node n = root.item(iter);
        if (n.getNodeName().equals("GraphicControlExtension")) {
            return n.getAttributes().getNamedItem("disposalMethod").getNodeValue();
        }
    }
    return null;
}

52. AnimationImpl#getFrameTime()

Project: CodenameOne
Source File: AnimationImpl.java
View license
public static int getFrameTime(ImageReader reader, int num) throws IOException {
    IIOMetadata meta = reader.getImageMetadata(num);
    Node parent = meta.getAsTree("javax_imageio_gif_image_1.0");
    //printNodeTree(parent);
    NodeList root = parent.getChildNodes();
    for (int iter = 0; iter < root.getLength(); iter++) {
        Node n = root.item(iter);
        if (n.getNodeName().equals("GraphicControlExtension")) {
            return Integer.parseInt(n.getAttributes().getNamedItem("delayTime").getNodeValue()) * 10;
        }
    }
    return 1000;
}

53. AnimationImpl#isRestoreToBackgroundColor()

Project: CodenameOne
Source File: AnimationImpl.java
View license
static boolean isRestoreToBackgroundColor(ImageReader reader, int num) throws IOException {
    IIOMetadata meta = reader.getImageMetadata(num);
    Node parent = meta.getAsTree("javax_imageio_gif_image_1.0");
    //printNodeTree(parent);
    NodeList root = parent.getChildNodes();
    for (int iter = 0; iter < root.getLength(); iter++) {
        Node n = root.item(iter);
        if (n.getNodeName().equals("GraphicControlExtension")) {
            return n.getAttributes().getNamedItem("disposalMethod").getNodeValue().equalsIgnoreCase("restoreToBackgroundColor");
        }
    }
    return false;
}

54. NodeListIteratorTest#makeEmptyIterator()

View license
@Override
public Iterator<Node> makeEmptyIterator() {
    final NodeList emptyNodeList = new NodeList() {

        @Override
        public Node item(final int index) {
            throw new IndexOutOfBoundsException();
        }

        @Override
        public int getLength() {
            return 0;
        }
    };
    if (createIteratorWithStandardConstr) {
        return new NodeListIterator(emptyNodeList);
    } else {
        final Node parentNode = createMock(Node.class);
        expect(parentNode.getChildNodes()).andStubReturn(emptyNodeList);
        replay(parentNode);
        return new NodeListIterator(parentNode);
    }
}

55. NodeListIteratorTest#makeObject()

View license
@Override
public Iterator<Node> makeObject() {
    final NodeList nodeList = new NodeList() {

        @Override
        public Node item(final int index) {
            return nodes[index];
        }

        @Override
        public int getLength() {
            return nodes.length;
        }
    };
    return new NodeListIterator(nodeList);
}

56. IteratorUtilsTest#testNodeListIterator()

View license
/**
     * Tests method nodeListIterator(NodeList)
     */
@Test
public void testNodeListIterator() {
    final Node[] nodes = createNodes();
    final NodeList nodeList = createNodeList(nodes);
    final Iterator<Node> iterator = IteratorUtils.nodeListIterator(nodeList);
    int expectedNodeIndex = 0;
    for (final Node actual : IteratorUtils.asIterable(iterator)) {
        assertEquals(nodes[expectedNodeIndex], actual);
        ++expectedNodeIndex;
    }
    // insure iteration occurred
    assertTrue(expectedNodeIndex > 0);
    // single use iterator
    assertFalse("should not be able to iterate twice", IteratorUtils.asIterable(iterator).iterator().hasNext());
}

57. IteratorUtilsTest#testNodeIterator()

View license
/**
     * Tests method nodeListIterator(Node)
     */
@Test
public void testNodeIterator() {
    final Node[] nodes = createNodes();
    final NodeList nodeList = createNodeList(nodes);
    final Node parentNode = createMock(Node.class);
    expect(parentNode.getChildNodes()).andStubReturn(nodeList);
    replay(parentNode);
    final Iterator<Node> iterator = IteratorUtils.nodeListIterator(parentNode);
    int expectedNodeIndex = 0;
    for (final Node actual : IteratorUtils.asIterable(iterator)) {
        assertEquals(nodes[expectedNodeIndex], actual);
        ++expectedNodeIndex;
    }
    // insure iteration occurred
    assertTrue(expectedNodeIndex > 0);
    // single use iterator
    assertFalse("should not be able to iterate twice", IteratorUtils.asIterable(iterator).iterator().hasNext());
}

58. XMLConfiguration#initRootElementText()

View license
/**
     * Sets the text of the root element of a newly created XML Document.
     *
     * @param doc the document
     * @param value the new text to be set
     */
private void initRootElementText(Document doc, Object value) {
    Element elem = doc.getDocumentElement();
    NodeList children = elem.getChildNodes();
    // Remove all existing text nodes
    for (int i = 0; i < children.getLength(); i++) {
        org.w3c.dom.Node nd = children.item(i);
        if (nd.getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
            elem.removeChild(nd);
        }
    }
    if (value != null) {
        // Add a new text node
        elem.appendChild(doc.createTextNode(String.valueOf(value)));
    }
}

59. TestXMLDocumentHelper#testInitForNewDocument()

View license
/**
     * Tests whether an instance can be created wrapping a new document.
     */
@Test
public void testInitForNewDocument() throws ConfigurationException {
    XMLDocumentHelper helper = XMLDocumentHelper.forNewDocument(ELEMENT);
    Document doc = helper.getDocument();
    Element rootElement = doc.getDocumentElement();
    assertEquals("Wrong root element name", ELEMENT, rootElement.getNodeName());
    NodeList childNodes = rootElement.getChildNodes();
    assertEquals("Got child nodes", 0, childNodes.getLength());
    assertNull("Got a public ID", helper.getSourcePublicID());
    assertNull("Got a system ID", helper.getSourceSystemID());
}

60. TestXMLDocumentHelper#findTextElementsForNode()

View license
/**
     * Recursively obtains all text elements for the given node.
     *
     * @param node the node
     * @param texts the collection with text elements
     */
private static void findTextElementsForNode(Node node, Collection<Node> texts) {
    if (node instanceof Text) {
        texts.add(node);
    }
    NodeList childNodes = node.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        findTextElementsForNode(childNodes.item(i), texts);
    }
}

61. DOMNodePointer#stringValue()

Project: commons-jxpath
Source File: DOMNodePointer.java
View license
/**
     * Get the string value of the specified node.
     * @param node Node to check
     * @return String
     */
private String stringValue(Node node) {
    int nodeType = node.getNodeType();
    if (nodeType == Node.COMMENT_NODE) {
        return "";
    }
    boolean trim = !"preserve".equals(findEnclosingAttribute(node, "xml:space"));
    if (nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) {
        String text = node.getNodeValue();
        return text == null ? "" : trim ? text.trim() : text;
    }
    if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
        String text = ((ProcessingInstruction) node).getData();
        return text == null ? "" : trim ? text.trim() : text;
    }
    NodeList list = node.getChildNodes();
    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < list.getLength(); i++) {
        Node child = list.item(i);
        buf.append(stringValue(child));
    }
    return buf.toString();
}

62. StandardFileSystemManager#getRequiredClasses()

View license
/**
     * Extracts the required classes from a provider definition.
     */
private String[] getRequiredClasses(final Element providerDef) {
    final ArrayList<String> classes = new ArrayList<>();
    final NodeList deps = providerDef.getElementsByTagName("if-available");
    final int count = deps.getLength();
    for (int i = 0; i < count; i++) {
        final Element dep = (Element) deps.item(i);
        final String className = dep.getAttribute("class-name");
        if (className != null && className.length() > 0) {
            classes.add(className);
        }
    }
    return classes.toArray(new String[classes.size()]);
}

63. StandardFileSystemManager#getRequiredSchemes()

View license
/**
     * Extracts the required schemes from a provider definition.
     */
private String[] getRequiredSchemes(final Element providerDef) {
    final ArrayList<String> schemes = new ArrayList<>();
    final NodeList deps = providerDef.getElementsByTagName("if-available");
    final int count = deps.getLength();
    for (int i = 0; i < count; i++) {
        final Element dep = (Element) deps.item(i);
        final String scheme = dep.getAttribute("scheme");
        if (scheme != null && scheme.length() > 0) {
            schemes.add(scheme);
        }
    }
    return schemes.toArray(new String[schemes.size()]);
}

64. StandardFileSystemManager#getSchemas()

View license
/**
     * Extracts the schema names from a provider definition.
     */
private String[] getSchemas(final Element provider) {
    final ArrayList<String> schemas = new ArrayList<>();
    final NodeList schemaElements = provider.getElementsByTagName("scheme");
    final int count = schemaElements.getLength();
    for (int i = 0; i < count; i++) {
        final Element scheme = (Element) schemaElements.item(i);
        schemas.add(scheme.getAttribute("name"));
    }
    return schemas.toArray(new String[schemas.size()]);
}

65. CustomModelImportTest#testValidUpload_ModelAndExtModule()

View license
public void testValidUpload_ModelAndExtModule() throws Exception {
    File zipFile = getResourceFile("validModelAndExtModule.zip");
    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    AuthenticationUtil.setFullyAuthenticatedUser(NON_ADMIN_USER);
    Response response = sendRequest(postRequest, 403);
    AuthenticationUtil.setFullyAuthenticatedUser(CUSTOM_MODEL_ADMIN);
    response = sendRequest(postRequest, 200);
    JSONObject json = new JSONObject(new JSONTokener(response.getContentAsString()));
    String importedModelName = json.getString("modelName");
    importedModels.add(importedModelName);
    String extModule = json.getString("shareExtModule");
    Document document = XMLUtil.parse(extModule);
    NodeList nodes = document.getElementsByTagName("id");
    assertEquals(1, nodes.getLength());
    assertNotNull(nodes.item(0).getTextContent());
}

66. CustomModelImportTest#testValidUpload_ExtModuleOnly()

View license
public void testValidUpload_ExtModuleOnly() throws Exception {
    File zipFile = getResourceFile("validExtModule.zip");
    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    AuthenticationUtil.setFullyAuthenticatedUser(NON_ADMIN_USER);
    Response response = sendRequest(postRequest, 403);
    AuthenticationUtil.setFullyAuthenticatedUser(CUSTOM_MODEL_ADMIN);
    response = sendRequest(postRequest, 200);
    JSONObject json = new JSONObject(new JSONTokener(response.getContentAsString()));
    assertFalse(json.has("modelName"));
    String extModule = json.getString("shareExtModule");
    Document document = XMLUtil.parse(extModule);
    NodeList nodes = document.getElementsByTagName("id");
    assertEquals(1, nodes.getLength());
    assertNotNull(nodes.item(0).getTextContent());
}

67. mxGraphMlKeyManager#initialise()

Project: consulo
Source File: mxGraphMlKeyManager.java
View license
/**
   * Load the map with the key elements in the document.<br/>
   * The keys are wrapped for instances of mxGmlKey.
   *
   * @param doc Document with the keys.
   */
public void initialise(Document doc) {
    NodeList gmlKeys = doc.getElementsByTagName(mxGraphMlConstants.KEY);
    int keyLength = gmlKeys.getLength();
    for (int i = 0; i < keyLength; i++) {
        Element key = (Element) gmlKeys.item(i);
        String keyId = key.getAttribute(mxGraphMlConstants.ID);
        mxGraphMlKey keyElement = new mxGraphMlKey(key);
        keyMap.put(keyId, keyElement);
    }
}

68. mxGraphMlUtils#childsHasTag()

Project: consulo
Source File: mxGraphMlUtils.java
View license
/**
   * Checks if the childrens of element has a Node with name = tag.
   *
   * @param element Element
   * @param tag     Name of the node.
   * @return Returns <code>true</code> if the childrens of element has a Node with name = tag.
   */
public static boolean childsHasTag(Element element, String tag) {
    NodeList nl = element.getChildNodes();
    boolean has = false;
    if (nl != null) {
        int length = nl.getLength();
        for (int i = 0; (i < length) && !has; i++) {
            has = (nl.item(i)).getNodeName().equals(tag);
        }
    }
    return has;
}

69. mxGraphMlUtils#childsTag()

Project: consulo
Source File: mxGraphMlUtils.java
View license
/**
   * Returns the first Element that has name = tag in the childrens of element.
   *
   * @param element Element
   * @param tag     Name of the Element
   * @return Element with name = 'tag'.
   */
public static Element childsTag(Element element, String tag) {
    NodeList nl = element.getChildNodes();
    if (nl != null) {
        int length = nl.getLength();
        boolean has = false;
        for (int i = 0; (i < length) && !has; i++) {
            has = (nl.item(i)).getNodeName().equals(tag);
            if (has) {
                return (Element) nl.item(i);
            }
        }
    }
    return null;
}

70. mxGraphMlUtils#childsTags()

Project: consulo
Source File: mxGraphMlUtils.java
View license
/**
   * Returns a list with the elements included in the childrens of element
   * that have name = tag.
   *
   * @param element Element
   * @param tag     name of the Element.
   * @return List with the indicated elements.
   */
public static List<Element> childsTags(Element element, String tag) {
    NodeList nl = element.getChildNodes();
    ArrayList<Element> ret = new ArrayList<Element>();
    if (nl != null) {
        int length = nl.getLength();
        for (int i = 0; i < length; i++) {
            if (tag.equals((nl.item(i)).getNodeName())) {
                ret.add((Element) nl.item(i));
            }
        }
    }
    return ret;
}

71. mxGraphMlCodec#decode()

Project: consulo
Source File: mxGraphMlCodec.java
View license
/**
   * Receives a GraphMl document and parses it generating a new graph that is inserted in graph.
   *
   * @param document XML to be parsed
   * @param graph    Graph where the parsed graph is included.
   */
public static void decode(Document document, mxGraph graph) {
    Object parent = graph.getDefaultParent();
    graph.getModel().beginUpdate();
    // Initialise the key properties.
    mxGraphMlKeyManager.getInstance().initialise(document);
    NodeList graphs = document.getElementsByTagName(mxGraphMlConstants.GRAPH);
    if (graphs.getLength() > 0) {
        Element graphElement = (Element) graphs.item(0);
        //Create the graph model.
        mxGraphMlGraph gmlGraph = new mxGraphMlGraph(graphElement);
        gmlGraph.addGraph(graph, parent);
    }
    graph.getModel().endUpdate();
    cleanMaps();
}

72. DocumentedException#parseErrorInfo()

Project: controller
Source File: DocumentedException.java
View license
private static Map<String, String> parseErrorInfo(Node node) {
    Map<String, String> infoMap = new HashMap<>();
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            infoMap.put(child.getNodeName(), child.getTextContent());
        }
    }
    return infoMap;
}

73. XmlElement#getChildElementsInternal()

Project: controller
Source File: XmlElement.java
View license
/**
     * Non recursive
     */
private List<XmlElement> getChildElementsInternal(ElementFilteringStrategy strat) {
    NodeList childNodes = element.getChildNodes();
    final List<XmlElement> result = new ArrayList<>();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node item = childNodes.item(i);
        if (!(item instanceof Element)) {
            continue;
        }
        if (strat.accept((Element) item)) {
            result.add(new XmlElement((Element) item));
        }
    }
    return result;
}

74. XmlElement#getTextContent()

Project: controller
Source File: XmlElement.java
View license
public String getTextContent() throws DocumentedException {
    NodeList childNodes = element.getChildNodes();
    if (childNodes.getLength() == 0) {
        return DEFAULT_NAMESPACE_PREFIX;
    }
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node textChild = childNodes.item(i);
        if (textChild instanceof Text) {
            String content = textChild.getTextContent();
            return content.trim();
        }
    }
    throw new DocumentedException(getName() + " should contain text.", DocumentedException.ErrorType.application, DocumentedException.ErrorTag.invalid_value, DocumentedException.ErrorSeverity.error);
}

75. DomReader#getChildByName()

Project: CoreNLP
Source File: DomReader.java
View license
/**
	 * Searches (recursively) for the first child that has the given name
	 */
protected static Node getChildByName(Node node, String name) {
    NodeList children = node.getChildNodes();
    // this node matches
    if (node.getNodeName().equals(name))
        return node;
    // search children
    for (int i = 0; i < children.getLength(); i++) {
        Node found = getChildByName(children.item(i), name);
        if (found != null)
            return found;
    }
    // failed
    return null;
}

76. DomReader#getChildrenByName()

Project: CoreNLP
Source File: DomReader.java
View license
/**
	 * Searches for all immediate children with the given name
	 */
protected static List<Node> getChildrenByName(Node node, String name) {
    List<Node> matches = new ArrayList<>();
    NodeList children = node.getChildNodes();
    // search children
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child.getNodeName().equals(name)) {
            matches.add(child);
        }
    }
    return matches;
}

77. DomReader#getChildByAttribute()

Project: CoreNLP
Source File: DomReader.java
View license
/**
	 * Searches for children that have the given attribute
	 */
protected static Node getChildByAttribute(Node node, String attributeName, String attributeValue) {
    NodeList children = node.getChildNodes();
    NamedNodeMap attribs = node.getAttributes();
    Node attribute = null;
    // this node matches
    if (attribs != null && (attribute = attribs.getNamedItem(attributeName)) != null && attribute.getNodeValue().equals(attributeValue))
        return node;
    // search children
    for (int i = 0; i < children.getLength(); i++) {
        Node found = getChildByAttribute(children.item(i), attributeName, attributeValue);
        if (found != null)
            return found;
    }
    // failed
    return null;
}

78. DomReader#getChildByNameAndAttribute()

Project: CoreNLP
Source File: DomReader.java
View license
/**
	 * Searches for children that have the given name and attribute
	 */
protected static Node getChildByNameAndAttribute(Node node, String name, String attributeName, String attributeValue) {
    NodeList children = node.getChildNodes();
    NamedNodeMap attribs = node.getAttributes();
    Node attribute = null;
    // this node matches
    if (node.getNodeName().equals(name) && attribs != null && (attribute = attribs.getNamedItem(attributeName)) != null && attribute.getNodeValue().equals(attributeValue))
        return node;
    // search children
    for (int i = 0; i < children.getLength(); i++) {
        Node found = getChildByAttribute(children.item(i), attributeName, attributeValue);
        if (found != null)
            return found;
    }
    // failed
    return null;
}

79. DomUtils#removeTags()

Project: crawljax
Source File: DomUtils.java
View license
/**
	 * Removes all the given tags from the document.
	 * 
	 * @param dom
	 *            the document object.
	 * @param tagName
	 *            the tag name, examples: script, style, meta
	 * @return the changed dom.
	 */
public static Document removeTags(Document dom, String tagName) {
    NodeList list;
    try {
        list = XPathHelper.evaluateXpathExpression(dom, "//" + tagName.toUpperCase());
        while (list.getLength() > 0) {
            Node sc = list.item(0);
            if (sc != null) {
                sc.getParentNode().removeChild(sc);
            }
            list = XPathHelper.evaluateXpathExpression(dom, "//" + tagName.toUpperCase());
        }
    } catch (XPathExpressionException e) {
        LOGGER.error("Error while removing tag " + tagName, e);
    }
    return dom;
}

80. XPathHelper#getSiblings()

Project: crawljax
Source File: XPathHelper.java
View license
/**
	 * Get siblings of the same type as element from parent.
	 * 
	 * @param parent
	 *            parent node.
	 * @param element
	 *            element.
	 * @return List of sibling (from element) under parent
	 */
public static List<Node> getSiblings(Node parent, Node element) {
    List<Node> result = new ArrayList<Node>();
    NodeList list = parent.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        Node el = list.item(i);
        if (el.getNodeName().equals(element.getNodeName())) {
            result.add(el);
        }
    }
    return result;
}

81. XPathHelper#getXpathForXPathExpressions()

Project: crawljax
Source File: XPathHelper.java
View license
/**
	 * Returns the XPaths of all nodes retrieved by xpathExpression. Example: //DIV[@id='foo']
	 * returns /HTM[1]/BODY[1]/DIV[2]
	 * 
	 * @param dom
	 *            The dom.
	 * @param xpathExpression
	 *            The expression to find the element.
	 * @return list of XPaths retrieved by xpathExpression.
	 * @throws XPathExpressionException
	 */
public static ImmutableList<String> getXpathForXPathExpressions(Document dom, String xpathExpression) throws XPathExpressionException {
    NodeList nodeList = XPathHelper.evaluateXpathExpression(dom, xpathExpression);
    Builder<String> result = ImmutableList.builder();
    if (nodeList.getLength() > 0) {
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node n = nodeList.item(i);
            result.add(getXPathExpression(n));
        }
    }
    return result.build();
}

82. WebDriverBackedEmbeddedBrowserTest#testGetDocument()

View license
@Test
public void testGetDocument() throws Exception {
    // TODO Stefan; refactor out the direct use of the FirefoxDriver
    WebDriverBackedEmbeddedBrowser browser = WebDriverBackedEmbeddedBrowser.withDriver(provider.newBrowser(), ImmutableSortedSet.<String>of(), 100, 100);
    Document doc;
    browser.goToUrl(SERVER.getSiteUrl());
    doc = DomUtils.asDocument(browser.getStrippedDom());
    NodeList frameNodes = doc.getElementsByTagName("IFRAME");
    assertEquals(2, frameNodes.getLength());
    doc = DomUtils.asDocument(browser.getStrippedDomWithoutIframeContent());
    frameNodes = doc.getElementsByTagName("IFRAME");
    assertEquals(2, frameNodes.getLength());
}

83. ImagingTaskStateManager#getPartsHeadUrl()

View license
private List<String> getPartsHeadUrl(final String manifest) throws Exception {
    final XPath xpath = XPathFactory.newInstance().newXPath();
    final DocumentBuilder builder = XMLParser.getDocBuilder();
    final Document inputSource = builder.parse(new ByteArrayInputStream(manifest.getBytes()));
    final List<String> parts = Lists.newArrayList();
    final NodeList nodes = (NodeList) xpath.evaluate(ImportImageManifest.INSTANCE.getPartsPath() + "/head-url", inputSource, XPathConstants.NODESET);
    for (int i = 0; i < nodes.getLength(); i++) {
        parts.add(nodes.item(i).getTextContent());
    }
    return parts;
}

84. TestMixinXml#testService()

Project: etch
Source File: TestMixinXml.java
View license
/** @throws Exception */
@org.junit.Test
public void testService() throws Exception {
    NodeList list = document.getElementsByTagName("service");
    assertEquals(list.getLength(), 1);
    String serviceName = list.item(0).getAttributes().getNamedItem("name").getNodeValue();
    assertEquals(serviceName, "Foo");
    // verify that no unknown attr exist
    assertTrue(onlyAttrsOfName(list.item(0), new String[] { "name" }));
    // verify that no unknown child nodes exist
    assertTrue(onlyChildNodesOfName(list.item(0), new String[] { "description", "consts", "externs", "enums", "structs", "exceptions", "methods" }));
    Node child = getDescriptionElement(list.item(0));
    assertNull(child);
}

85. TestMixinXml#testExterns()

Project: etch
Source File: TestMixinXml.java
View license
/** @throws Exception */
@org.junit.Test
public void testExterns() throws Exception {
    // verify consts
    NodeList list = document.getElementsByTagName("extern");
    assertEquals(list.getLength(), 3);
    int nodeCount = 0;
    Node externNode = list.item(nodeCount++);
    checkExternProperties(externNode, "FooTable", "-1404806234", "org.apache.etch.tests.Foo.FooTable");
    checkExternMapProperties(externNode, "java", "org.apache.etch.bindings.java.util.StrStrHashMap", "", "org.apache.etch.bindings.java.util.StrStrHashMapSerializer", "");
    externNode = list.item(nodeCount++);
    checkExternProperties(externNode, "BazTable", "729647100", "org.apache.etch.tests.Baz.BazTable");
    checkExternMapProperties(externNode, "java", "org.apache.etch.bindings.java.util.StrStrHashMap", "", "org.apache.etch.bindings.java.util.StrStrHashMapSerializer", "");
    externNode = list.item(nodeCount++);
    checkExternProperties(externNode, "BarTable", "-278631412", "org.apache.etch.tests.Bar.BarTable");
    checkExternMapProperties(externNode, "java", "org.apache.etch.bindings.java.util.StrStrHashMap", "", "org.apache.etch.bindings.java.util.StrStrHashMapSerializer", "");
}

86. TestMixinXml#getDescriptionElement()

Project: etch
Source File: TestMixinXml.java
View license
private Node getDescriptionElement(Node node) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        short nodeType = children.item(i).getNodeType();
        String nodeName = children.item(i).getNodeName();
        if (nodeType == Node.ELEMENT_NODE && nodeName == "description") {
            return children.item(i);
        }
    }
    return null;
}

87. TestMixinXml#getAuthorizeElement()

Project: etch
Source File: TestMixinXml.java
View license
private Node getAuthorizeElement(Node node) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        short nodeType = children.item(i).getNodeType();
        String nodeName = children.item(i).getNodeName();
        if (nodeType == Node.ELEMENT_NODE && nodeName == "authorize") {
            return children.item(i);
        }
    }
    return null;
}

88. TestMixinXml#getResultElement()

Project: etch
Source File: TestMixinXml.java
View license
private Node getResultElement(Node node) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        short nodeType = children.item(i).getNodeType();
        String nodeName = children.item(i).getNodeName();
        if (nodeType == Node.ELEMENT_NODE && nodeName == "result") {
            return children.item(i);
        }
    }
    return null;
}

89. TestMixinXml#getChildElementCount()

Project: etch
Source File: TestMixinXml.java
View license
private int getChildElementCount(Node node) {
    int count = 0;
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
            count++;
        }
    }
    return count;
}

90. TestXml#testModule()

Project: etch
Source File: TestXml.java
View license
/** @throws Exception */
@org.junit.Test
public void testModule() throws Exception {
    NodeList list = document.getElementsByTagName("module");
    assertEquals(list.getLength(), 1);
    String moduleName = list.item(0).getAttributes().getNamedItem("name").getNodeValue();
    assertEquals(moduleName, "org.apache.etch.tests");
    // verify that no unknown attr exist
    assertTrue(onlyAttrsOfName(list.item(0), new String[] { "name" }));
    // verify that no unknown child nodes exist
    assertTrue(onlyChildNodesOfName(list.item(0), new String[] { "description", "service" }));
}

91. TestXml#testService()

Project: etch
Source File: TestXml.java
View license
/** @throws Exception */
@org.junit.Test
public void testService() throws Exception {
    NodeList list = document.getElementsByTagName("service");
    assertEquals(list.getLength(), 1);
    String serviceName = list.item(0).getAttributes().getNamedItem("name").getNodeValue();
    assertEquals(serviceName, "Test1");
    // verify that no unknown attr exist
    assertTrue(onlyAttrsOfName(list.item(0), new String[] { "name" }));
    // verify that no unknown child nodes exist
    assertTrue(onlyChildNodesOfName(list.item(0), new String[] { "consts", "externs", "enums", "structs", "exceptions", "methods" }));
}

92. TestXml#testExterns()

Project: etch
Source File: TestXml.java
View license
/** @throws Exception */
@org.junit.Test
public void testExterns() throws Exception {
    // verify consts
    NodeList list = document.getElementsByTagName("extern");
    assertEquals(list.getLength(), 1);
    int nodeCount = 0;
    Node externNode = list.item(nodeCount++);
    checkExternProperties(externNode, "Blob", "-1308039838", "org.apache.etch.tests.Test1.Blob");
    checkExternMapProperties(externNode, "java", "StrIntHashMap", "org.apache.etch.bindings.java.util.StrIntHashMap", "StrIntHashMapSerializer", "org.apache.etch.bindings.java.util.StrIntHashMapSerializer");
    checkExternMapProperties(externNode, "csharp", "StrIntHashMap", "Org.Apache.Etch.Bindings.Csharp.Util", "StrIntHashMapSerializer", "Org.Apache.Etch.Bindings.Csharp.Util");
}

93. TestXml#testEnums()

Project: etch
Source File: TestXml.java
View license
/** @throws Exception */
@org.junit.Test
public void testEnums() throws Exception {
    // verify enums
    NodeList list = document.getElementsByTagName("enum");
    assertEquals(list.getLength(), 1);
    int nodeCount = 0;
    Node enumNode = list.item(nodeCount++);
    checkEnumProperties(enumNode, "E1", "874541489", "org.apache.etch.tests.Test1.E1", "blah");
    checkEnumValueProperties(enumNode, "A", "352988284");
    checkEnumValueProperties(enumNode, "B", "352988285");
    checkEnumValueProperties(enumNode, "C", "352988286");
}

94. TestXml#testStructs()

Project: etch
Source File: TestXml.java
View license
/** @throws Exception */
@org.junit.Test
public void testStructs() throws Exception {
    // verify structs
    NodeList list = document.getElementsByTagName("struct");
    assertEquals(list.getLength(), 4);
    int nodeCount = 0;
    Node structNode = list.item(nodeCount++);
    checkStructProperties(structNode, "S1", "875459875", "org.apache.etch.tests.Test1.S1", "null", "blah");
    checkStructValueProperties(structNode, "x", "352988339", "x", "int", "true", "false", null, "value");
    checkStructValueProperties(structNode, "y", "352988340", "y", "int", "true", "false", null, "value");
    checkStructValueProperties(structNode, "z", "352988341", "z", "int", "true", "false", null, "value");
}

95. TestXml#getDescriptionElement()

Project: etch
Source File: TestXml.java
View license
private Node getDescriptionElement(Node node) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        short nodeType = children.item(i).getNodeType();
        String nodeName = children.item(i).getNodeName();
        if (nodeType == Node.ELEMENT_NODE && nodeName == "description") {
            return children.item(i);
        }
    }
    return null;
}

96. TestXml#getAuthorizeElement()

Project: etch
Source File: TestXml.java
View license
private Node getAuthorizeElement(Node node) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        short nodeType = children.item(i).getNodeType();
        String nodeName = children.item(i).getNodeName();
        if (nodeType == Node.ELEMENT_NODE && nodeName == "authorize") {
            return children.item(i);
        }
    }
    return null;
}

97. TestXml#getResultElement()

Project: etch
Source File: TestXml.java
View license
private Node getResultElement(Node node) {
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        short nodeType = children.item(i).getNodeType();
        String nodeName = children.item(i).getNodeName();
        if (nodeType == Node.ELEMENT_NODE && nodeName == "result") {
            return children.item(i);
        }
    }
    return null;
}

98. TestXml#getChildElementCount()

Project: etch
Source File: TestXml.java
View license
private int getChildElementCount(Node node) {
    int count = 0;
    NodeList children = node.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        if (children.item(i).getNodeType() == Node.ELEMENT_NODE) {
            count++;
        }
    }
    return count;
}

99. testJaxp#dump()

Project: etch
Source File: testJaxp.java
View license
private static void dump(String prefix, Element e) {
    System.out.println(prefix + "start of element name=" + e.getTagName());
    NamedNodeMap attrs = e.getAttributes();
    int n = attrs.getLength();
    for (int i = 0; i < n; i++) {
        Node a = attrs.item(i);
        System.out.println(prefix + "  attr name '" + a.getNodeName() + "' value '" + a.getNodeValue() + "'");
    }
    NodeList nl = e.getChildNodes();
    n = nl.getLength();
    for (int i = 0; i < n; i++) {
        Node sn = nl.item(i);
        if (sn instanceof Element)
            dump(prefix + "  ", (Element) sn);
        else
            dump(prefix + "  ", (CharacterData) sn);
    }
    System.out.println(prefix + "end of element name=" + e.getTagName());
}

100. MessageListFunctions#parseChildSearchTerm()

Project: exist
Source File: MessageListFunctions.java
View license
private SearchTerm parseChildSearchTerm(Node terms) throws XPathException {
    // Parent only allows a single child search term
    SearchTerm st = null;
    NodeList children = terms.getChildNodes();
    if (children.getLength() == 1) {
        Node child = children.item(0);
        st = parseSearchTerms(child);
    } else {
        throw (new XPathException(this, "Only one child term is allowed for term with type: " + ((Element) terms).getAttribute("type")));
    }
    return (st);
}