Example usage for org.w3c.dom NamedNodeMap getLength

List of usage examples for org.w3c.dom NamedNodeMap getLength

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap getLength.

Prototype

public int getLength();

Source Link

Document

The number of nodes in this map.

Usage

From source file:de.micromata.genome.gwiki.page.impl.wiki.rte.els.RteTableDomElementListener.java

protected void copyAttributes(MacroAttributes target, DomElementEvent event) {
    NamedNodeMap attrs = event.element.getAttributes();
    for (int i = 0; i < attrs.getLength(); ++i) {
        String k = attrs.item(i).getLocalName();
        String v = attrs.item(i).getNodeValue();
        target.getArgs().setStringValue(k, v);
    }//from  w  w w .  j  a va 2  s . c om
}

From source file:com.krawler.esp.utils.mime.MimeTypesReader.java

/** Read Element named magic. */
private void readMagic(Element element, MimeType mimeType) {
    // element.getValue();
    String offset = null;//from  ww w.j  a  va  2s .com
    String content = null;
    String type = null;
    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        if (attr.getName().equals("offset")) {
            offset = attr.getValue();
        } else if (attr.getName().equals("type")) {
            type = attr.getValue();
        } else if (attr.getName().equals("value")) {
            content = attr.getValue();
        }
    }
    if ((offset != null) && (content != null)) {
        mimeType.addMagic(Integer.parseInt(offset), type, content);
    }
}

From source file:TreeDumper2.java

private void dumpDocumentType(DocumentType node, String indent) {
    System.out.println(indent + "DOCUMENT_TYPE: " + node.getName());
    if (node.getPublicId() != null)
        System.out.println(indent + " Public ID: " + node.getPublicId());
    if (node.getSystemId() != null)
        System.out.println(indent + " System ID: " + node.getSystemId());
    NamedNodeMap entities = node.getEntities();
    if (entities.getLength() > 0) {
        for (int i = 0; i < entities.getLength(); i++) {
            dumpLoop(entities.item(i), indent + "  ");
        }/*from  w  w  w.  ja v  a  2 s  .  c  o  m*/
    }
    NamedNodeMap notations = node.getNotations();
    if (notations.getLength() > 0) {
        for (int i = 0; i < notations.getLength(); i++)
            dumpLoop(notations.item(i), indent + "  ");
    }
}

From source file:TreeDumper2.java

private void dumpElement(Element node, String indent) {
    System.out.println(indent + "ELEMENT: " + node.getTagName());
    NamedNodeMap nm = node.getAttributes();
    for (int i = 0; i < nm.getLength(); i++)
        dumpLoop(nm.item(i), indent + "  ");
}

From source file:com.qwazr.extractor.parser.ImageParser.java

private void browseNodes(String path, final Node root, final ParserFieldsBuilder result) {
    if (root == null)
        return;/*from  w ww  . j  av a  2  s . c om*/
    switch (root.getNodeType()) {
    case Node.TEXT_NODE:
        result.add(ParserField.newString(path, null), root.getNodeValue());
        break;
    case Node.ELEMENT_NODE:
        final NamedNodeMap nnm = root.getAttributes();
        if (nnm != null)
            for (int i = 0; i < nnm.getLength(); i++)
                browseNodes(path, nnm.item(i), result);
        Node child = root.getFirstChild();
        while (child != null) {
            browseNodes(path + "/" + child.getNodeName(), child, result);
            child = child.getNextSibling();
        }
        break;
    case Node.ATTRIBUTE_NODE:
        path = path + "#" + root.getNodeName();
        result.add(ParserField.newString(path, null), root.getNodeValue());
        break;
    default:
        throw new NotImplementedException("Unknown attribute: " + root.getNodeType());
    }
}

From source file:com.diversityarrays.dalclient.DalUtil.java

public static DalResponseRecord createFrom(String requestUrl, Node node) {
    DalResponseRecord result = new DalResponseRecord(requestUrl, node.getNodeName());
    NamedNodeMap attributes = node.getAttributes();
    if (attributes != null) {
        int nAttributes = attributes.getLength();
        for (int ai = 0; ai < nAttributes; ++ai) {
            Node attr = attributes.item(ai);
            result.rowdata.put(attr.getNodeName(), attr.getNodeValue());
        }//from   w ww .  jav  a  2 s.com
    }

    NodeList childNodes = node.getChildNodes();
    int nChildNodes = childNodes.getLength();
    if (nChildNodes > 0) {
        for (int ci = 0; ci < nChildNodes; ++ci) {
            Node child = childNodes.item(ci);
            if (Node.ELEMENT_NODE == child.getNodeType()) {
                String childName = child.getNodeName();
                Map<String, String> childMap = asRowdata(child);
                if (childMap != null) {
                    result.addNestedData(childName, childMap);
                }
            }
        }
    }

    return result;
}

From source file:edu.wustl.xipHost.hostLogin.STSLogin.java

void parseSamlAssertion(String xmlSamlAssertion)
        throws ParserConfigurationException, SAXException, IOException {
    InputStream is = new ByteArrayInputStream(xmlSamlAssertion.getBytes());
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(is);
    samlAssertionElement = doc.getDocumentElement(); //docELement to be returned to XUA to build XUAAssertion
    NodeList childNodes = samlAssertionElement.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.item(i);
        if (childNode.getNodeName().equals("saml:AttributeStatement")) {
            NodeList attStatementNodes = childNode.getChildNodes();
            for (int j = 0; j < attStatementNodes.getLength(); j++) {
                Node node = attStatementNodes.item(j);
                NamedNodeMap atts = node.getAttributes();
                for (int k = 0; k < atts.getLength(); k++) {
                    Node att = atts.item(k);
                    if (att.getNodeValue().endsWith("GlobusCredential")) {
                        NodeList globusCredNodes = node.getChildNodes();
                        String saml = globusCredNodes.item(0).getTextContent();
                        try {
                            byte[] bytes = Base64.decode(saml);
                            ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
                            globusCred = new GlobusCredential(stream);
                        } catch (GlobusCredentialException e) {
                            globusCred = null;
                            logger.error(e, e);
                        }//w  ww  .ja  va 2 s .c om
                    }
                }

            }
        }
    }
    is.close();
}

From source file:com.krawler.esp.utils.mime.MimeTypesReader.java

/** Read Element named mime-type. */
private MimeType readMimeType(Element element) {
    String name = null;/*  ww w. j  a  v  a2 s.  c  o  m*/
    String description = null;
    MimeType type = null;
    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        if (attr.getName().equals("name")) {
            name = attr.getValue();
        } else if (attr.getName().equals("description")) {
            description = attr.getValue();
        }
    }
    if ((name == null) || (name.trim().equals(""))) {
        return null;
    }

    try {
        type = new MimeType(name);
    } catch (MimeTypeException mte) {
        // Mime Type not valid... just ignore it
        if (logger.isInfoEnabled()) {
            logger.info(mte.toString() + " ... Ignoring!");
        }
        return null;
    }
    type.setDescription(description);

    NodeList nodes = element.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element nodeElement = (Element) node;
            if (nodeElement.getTagName().equals("ext")) {
                readExt(nodeElement, type);
            } else if (nodeElement.getTagName().equals("magic")) {
                readMagic(nodeElement, type);
            }
        }
    }
    return type;
}

From source file:com.apricot.eating.xml.XMLParser.java

public HashMap getAttributes(Node node) {
    NamedNodeMap map = node.getAttributes();
    HashMap attrs = new HashMap();
    for (int i = 0; i < map.getLength(); i++) {
        Node n = map.item(i);/*from w  w w  .  j  a v a2  s  .c  om*/
        attrs.put(n.getNodeName(), n.getNodeValue());
        n = null;
    }
    return attrs;
}

From source file:com.cellngine.util.FXMLValidator.java

private void checkNode(final Node node) throws InvalidFXMLException {
    final String nodeName = node.getNodeName();
    final short nodeType = node.getNodeType();

    if (nodeType == Node.ELEMENT_NODE) {
        if (!ALLOWED_ELEMENTS.isElementAllowed(nodeName)) {
            throw new InvalidFXMLException("Element type \"" + nodeName + "\" not allowed");
        }//from  w w w.java  2 s .  co  m

        final NamedNodeMap nodeAttributes = node.getAttributes();
        for (int i = 0; i < nodeAttributes.getLength(); i++) {
            checkAttributeNode(nodeAttributes.item(i), nodeName);
        }
    } else if (nodeType == Node.TEXT_NODE || nodeType == Node.DOCUMENT_NODE) {
    } else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE && node.getNodeName().equals("import")) {
        if (!ALLOWED_IMPORTS.contains(node.getNodeValue())) {
            throw new InvalidFXMLException("Import \"" + node.getNodeValue() + "\" not allowed.");
        }
    } else if (nodeType != Node.COMMENT_NODE) {
        throw new InvalidFXMLException("Unrecognized node: type: \"" + nodeType + "\", name: \""
                + node.getNodeName() + "\", value: \"" + node.getNodeValue() + "\"");
    }

    final NodeList nodeChildren = node.getChildNodes();
    for (int i = 0; i < nodeChildren.getLength(); i++) {
        checkNode(nodeChildren.item(i));
    }
}