Example usage for org.w3c.dom NamedNodeMap getNamedItem

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

Introduction

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

Prototype

public Node getNamedItem(String name);

Source Link

Document

Retrieves a node specified by name.

Usage

From source file:com.axelor.csv.script.PrepareCsv.java

/**
 * Get namecolumn field of entity/*from w  ww.  j  a  va2s  . c  o m*/
 * @param fileName
 * @return
 * @throws SAXException
 * @throws IOException
 * @throws ParserConfigurationException
 */
private String getNameColumn(String fileName) throws SAXException, IOException, ParserConfigurationException {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    File domainFile = new File(fileName);
    if (!domainFile.exists())
        return null;
    Document doc = dBuilder.parse(domainFile);
    NodeList nList = doc.getElementsByTagName("entity");
    if (nList != null) {
        NodeList fields = nList.item(0).getChildNodes();
        Integer count = 0;
        while (count < fields.getLength()) {
            NamedNodeMap attrs = fields.item(count).getAttributes();
            count++;
            if (attrs != null && attrs.getNamedItem("name") != null) {
                String name = attrs.getNamedItem("name").getNodeValue();
                if (name.equals("importId"))
                    return "importId";
                else if (name.equals("code"))
                    return "code";
                else if (name.equals("name"))
                    return "name";
                else
                    continue;
            }

        }
    }
    return null;
}

From source file:at.sti2.spark.handler.ImpactoriumHandler.java

public String extractInfoObjectIdentifier(String infoObjectResponse) {

    String reportId = null;//  w  w w  . j  a v  a  2  s .  c o  m

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    //dbf.setNamespaceAware(true);
    try {
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(new ByteArrayInputStream(infoObjectResponse.getBytes("UTF-8")));

        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        XPathExpression expr = xpath.compile("//info-object");
        Object result = expr.evaluate(doc, XPathConstants.NODESET);

        NodeList nodes = (NodeList) result;
        Node item = nodes.item(0);
        if (item != null) {
            NamedNodeMap attributesMap = item.getAttributes();
            Node idAttribute = attributesMap.getNamedItem("id");
            reportId = idAttribute.getNodeValue();
        }

    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }

    return reportId;
}

From source file:it.jnrpe.plugin.tomcat.TomcatDataProvider.java

private void parseMemoryPools() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    InputSource is = new InputSource(new StringReader(tomcatXML));

    Document doc = builder.parse(is);
    XPathFactory xPathfactory = XPathFactory.newInstance();
    XPath xpath = xPathfactory.newXPath();

    NodeList memoryPoolList = (NodeList) xpath.compile("//status/jvm/memorypool")
            .evaluate(doc.getDocumentElement(), XPathConstants.NODESET);

    for (int i = 0; i < memoryPoolList.getLength(); i++) {
        Node poolNode = memoryPoolList.item(i);
        NamedNodeMap atts = poolNode.getAttributes();
        final String poolName = atts.getNamedItem("name").getNodeValue();
        long usageInit = Long.parseLong(atts.getNamedItem("usageInit").getNodeValue());
        long usageCommitted = Long.parseLong(atts.getNamedItem("usageCommitted").getNodeValue());
        long usageMax = Long.parseLong(atts.getNamedItem("usageMax").getNodeValue());
        long usageUsed = Long.parseLong(atts.getNamedItem("usageUsed").getNodeValue());

        memoryPoolData.put(poolName,//from w w  w.j a v a 2s.c o m
                new MemoryPoolData(poolName, usageInit, usageCommitted, usageMax, usageUsed));
    }
}

From source file:io.personium.engine.source.FsServiceResourceSourceManager.java

/**
 * ??????./*from ww  w  .ja v a  2 s  . c  o m*/
 * @param xml XML
 * @param svcName ??
 * @return 
 */
private void parseServiceTag() {
    DocumentBuilder builder = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
    Document doc = null;
    InputStream is = new ByteArrayInputStream(this.serviceCollectionInfo.getBytes());
    try {
        doc = builder.parse(is);
        Element el = doc.getDocumentElement();
        this.serviceSubject = el.getAttribute("subject");
        NodeList nl = doc.getElementsByTagNameNS("*", "path");
        for (int i = 0; i < nl.getLength(); i++) {
            NamedNodeMap nnm = nl.item(i).getAttributes();
            pathMap.put(nnm.getNamedItem("name").getNodeValue(), nnm.getNamedItem("src").getNodeValue());
        }
    } catch (SAXException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.SignatureFakingOracle.java

private boolean isSignatureMethodSupported(Node signatureMethodElement) {
    NamedNodeMap nl = signatureMethodElement.getAttributes();
    Node n = nl.getNamedItem("Algorithm");
    if (n != null) {
        String algorithm = n.getTextContent();
        if (algorithm.contains("rsa-sha")) {
            return true;
        }//w  ww. j  a v a2  s. c o  m
    }
    return false;
}

From source file:org.hdiv.config.xml.EditableValidationsBeanDefinitionParser.java

/**
 * Initialize Map with url and ValidationRule data.
 * // w ww  .j  a  va 2 s .c om
 * @param node
 *            processing xml node
 * @param bean
 *            bean configuration
 * @param map
 *            Map with url and ValidationRule data
 */
private void processValidationRule(Node node, BeanDefinitionBuilder bean, Map map) {

    String value = node.getTextContent();
    List ids = this.convertToList(value);

    NamedNodeMap attributes = node.getAttributes();
    String url = attributes.getNamedItem("url").getTextContent();

    boolean enableDefaults = false;
    String enableDefaultsVal = attributes.getNamedItem("enableDefaults").getTextContent();
    if (enableDefaultsVal != null) {
        enableDefaults = Boolean.TRUE.toString().equalsIgnoreCase(enableDefaultsVal);
    }
    if (enableDefaults) {
        // Add defaults
        ids.addAll(this.defaultValidationIds);
    }

    map.put(url, ids);

}

From source file:dk.statsbiblioteket.doms.iprolemapper.webservice.IPRangesConfigReader.java

/**
 * This method produces an <code>IPRangeRoles</code> instance from the
 * information stored in the <code>Node</code> specified by
 * <code>ipRangeNode</code>.
 * //w ww  .  jav a  2s.c om
 * @param ipRangeNode
 *            a <code>Document Node</code> containing information about an
 *            IP range and its associated roles.
 * @return an <code>IPRangeRoles</code> instance created from the
 *         information contained in <code>ipRangeNode</code>.
 * @throws XPathExpressionException
 *             if any errors are encountered while reading range roles from
 *             <code>ipRangeNode</code>.
 * @throws UnknownHostException
 *             if the begin or end address of <code>ipRangeNode</code> is
 *             either an unknown host name or an illegal IP address.
 * @throws IllegalArgumentException
 *             if the begin address and end address of the range is not of
 *             the same type. I.e. if they are not both IPv4 or IPv6
 *             addresses, or if <code>beginAddress</code> is higher/after
 *             <code>endAddress</code>.
 */
private IPRangeRoles produceIPRangeInstance(Node ipRangeNode)
        throws XPathExpressionException, IllegalArgumentException, UnknownHostException {

    if (log.isTraceEnabled()) {

        String ipRangeNodeXMLString = "Malformed XML";
        try {
            ipRangeNodeXMLString = DOM.domToString(ipRangeNode);
        } catch (TransformerException transformerException) {
            // Just ignore for now and log. The code will break later...
        }

        log.trace("produceIPRangeInstance(): Called with XML node: " + ipRangeNodeXMLString);
    }

    final NamedNodeMap attributes = ipRangeNode.getAttributes();
    final String beginAddress = attributes.getNamedItem("begin").getNodeValue();
    final String endAddress = attributes.getNamedItem("end").getNodeValue();

    final XPathFactory xPathFactory = XPathFactory.newInstance();
    final XPath xPath = xPathFactory.newXPath();

    final NodeList ipRangeRoleNodes = (NodeList) xPath.evaluate("role", ipRangeNode, XPathConstants.NODESET);

    final List<String> ipRangeRoles = new LinkedList<String>();
    for (int nodeIdx = 0; nodeIdx < ipRangeRoleNodes.getLength(); nodeIdx++) {
        ipRangeRoles.add(ipRangeRoleNodes.item(nodeIdx).getTextContent().trim());
    }

    final IPRangeRoles rangeRoles = new IPRangeRoles(InetAddress.getByName(beginAddress),
            InetAddress.getByName(endAddress), ipRangeRoles);

    if (log.isTraceEnabled()) {
        log.trace("produceIPRangeInstance(): Returning IPRangeRoles " + "instance: " + rangeRoles);
    }
    return rangeRoles;
}

From source file:com.amalto.core.history.accessor.AttributeAccessor.java

public void markUnmodified() {
    Node parentNode = parent.getNode();
    NamedNodeMap attributes = parentNode.getAttributes();
    if (attributes.getNamedItem(MODIFIED_MARKER_ATTRIBUTE) != null) {
        attributes.removeNamedItem(MODIFIED_MARKER_ATTRIBUTE);
    }/*from   w ww.  j  ava  2s.c  o  m*/
}

From source file:org.ala.harvester.IdentifyLifeHarvester.java

/**
 * Harvest a document and update the repository.
 * //from   w  w w.  j  a v  a2s.c  o m
 * @param infosourceId
 * @param url
 * @throws Exception
 */
private void harvestDoc(int infosourceId, String url) throws Exception {
    byte[] content = null;

    System.out.println("******** request: " + url);
    Object[] resp = restfulClient.restGet(url);
    if ((Integer) resp[0] == HttpStatus.SC_OK) {
        content = resp[1].toString().getBytes("UTF-8");
    }

    if (content != null) {
        List<String> ids = new ArrayList<String>();
        String keyUrl = connectionParams.get(KEY_END_POINT_ATTR_NAME);

        // Instantiates a DOM builder to create a DOM of the response.
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();

        // return a parsed Document
        Document doc = builder.parse(new ByteArrayInputStream(content));

        XPathFactory xfactory = XPathFactory.newInstance();
        XPath xpath = xfactory.newXPath();

        XPathExpression xe = xpath.compile("//keys/key[@id]");
        NodeList nodeSet = (NodeList) xe.evaluate(doc, XPathConstants.NODESET);
        for (int i = 0; i < nodeSet.getLength(); i++) {
            NamedNodeMap map = nodeSet.item(i).getAttributes();
            ids.add(map.getNamedItem("id").getNodeValue());
        }

        for (int i = 0; i < ids.size(); i++) {
            Object[] res = restfulClient.restGet(keyUrl + "/" + ids.get(i));
            if ((Integer) res[0] == HttpStatus.SC_OK) {
                //map the document 
                List<ParsedDocument> pds = documentMapper.map(keyUrl + ids.get(i),
                        res[1].toString().getBytes());

                //store the results
                for (ParsedDocument pd : pds) {
                    //debugParsedDoc(pd);
                    repository.storeDocument(infosourceId, pd);
                    logger.debug("Parent guid for stored doc: " + pd.getParentGuid());
                }
            }
        }
    } else {
        logger.warn("Unable to process url: " + url);
    }
}

From source file:it.jnrpe.plugin.tomcat.TomcatDataProvider.java

private void parseConnectorsThreadData() throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    InputSource is = new InputSource(new StringReader(tomcatXML));

    Document doc = builder.parse(is);
    XPathFactory xPathfactory = XPathFactory.newInstance();
    XPath xpath = xPathfactory.newXPath();

    NodeList connectorsNodeList = (NodeList) xpath.compile("//status/connector")
            .evaluate(doc.getDocumentElement(), XPathConstants.NODESET);

    for (int i = 0; i < connectorsNodeList.getLength(); i++) {
        Node connector = connectorsNodeList.item(i);
        NodeList connectorChildren = connector.getChildNodes();

        final String connectorName = connector.getAttributes().getNamedItem("name").getNodeValue();
        for (int j = 0; j < connectorChildren.getLength(); j++) {
            Node node = connectorChildren.item(j);
            if (node.getNodeName().equalsIgnoreCase("threadInfo")) {

                NamedNodeMap atts = node.getAttributes();

                long maxThreads = Long.parseLong(atts.getNamedItem("maxThreads").getNodeValue());
                long currentThreadsBusy = Long
                        .parseLong(atts.getNamedItem("currentThreadsBusy").getNodeValue());
                long currentThreadCount = Long
                        .parseLong(atts.getNamedItem("currentThreadCount").getNodeValue());

                connectorThreadData.put(connectorName,
                        new ThreadData(connectorName, currentThreadCount, currentThreadsBusy, maxThreads));
            }//from  www.ja v a  2s.  c  o  m
        }
    }
}