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.wrightfully.sonar.plugins.dotnet.resharper.CustomSeverities.java

private String getKey(Node node) throws ReSharperException {
    NamedNodeMap attributeMap = node.getAttributes();
    Node keyAttribute = attributeMap.getNamedItem("x:Key");
    String value = keyAttribute.getNodeValue();
    String[] values = value.split("[/=]");
    if (values.length != 8 && values.length != 9) {
        throw new ReSharperException("Invalid key, does not contain 8 or 9 segments seperated by / " + value
                + "\ncontains " + values.length + " elements");
    }//  www. j av  a  2 s .com
    return values[values.length - 2];
}

From source file:com.microsoft.alm.plugin.external.commands.HistoryCommand.java

/**
 * Parses the output of the status command when formatted as xml.
 * SAMPLE//  w ww  . ja va2  s.  c  om
 * <?xml version="1.0" encoding="utf-8"?>
 * <history>
 * <changeset id="4" owner="john" committer="john" date="2016-06-07T11:18:18.790-0400">
 * <comment>add readme</comment>
 * <item change-type="add" server-item="$/tfs01/readme.txt"/>
 * </changeset>
 * <changeset id="3" owner="jeff" committer="jeff" date="2016-06-07T11:13:51.747-0400">
 * <comment>initial checkin</comment>
 * <item change-type="add" server-item="$/tfs01/com.microsoft.core"/>
 * <item change-type="add" server-item="$/tfs01/com.microsoft.core/.classpath"/>
 * </changeset>
 * </history>
 */
@Override
public List<ChangeSet> parseOutput(final String stdout, final String stderr) {
    super.throwIfError(stderr);
    final List<ChangeSet> changeSets = new ArrayList<ChangeSet>(100);
    final NodeList nodes = super.evaluateXPath(stdout, "/history/changeset");

    // Convert all the xpath nodes to changeset models
    if (nodes != null) {
        for (int i = 0; i < nodes.getLength(); i++) {
            final Element changeset = (Element) nodes.item(i);

            // Read comment element
            final NodeList commentNodes = changeset.getElementsByTagName("comment");
            final String comment;
            if (commentNodes.getLength() == 1) {
                comment = commentNodes.item(0).getTextContent();
            } else {
                comment = "";
            }

            // Gather pending changes
            final List<PendingChange> changes = new ArrayList<PendingChange>(100);
            final NodeList childNodes = changeset.getElementsByTagName("item");
            for (int j = 0; j < childNodes.getLength(); j++) {
                final Node child = childNodes.item(j);
                // Assume this is a change
                final NamedNodeMap attributes = child.getAttributes();
                changes.add(new PendingChange(attributes.getNamedItem("server-item").getNodeValue(),
                        attributes.getNamedItem("change-type").getNodeValue()));
            }

            final NamedNodeMap attributes = changeset.getAttributes();
            changeSets.add(new ChangeSet(attributes.getNamedItem("id").getNodeValue(),
                    attributes.getNamedItem("owner").getNodeValue(),
                    attributes.getNamedItem("committer").getNodeValue(),
                    attributes.getNamedItem("date").getNodeValue(), comment, changes));
        }
    }
    return changeSets;
}

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

/**
 * Return the value of the named attribute from the first Node in the NodeList
 * or null if the NodeList is empty or the attribute is not present.
 * @param elements/*from   w w  w.  j a v  a 2 s  .c  om*/
 * @param attributeName
 * @return a String or null
 */
static public String getAttributeValue(NodeList elements, String attributeName) {
    String result = null;
    if (elements != null && elements.getLength() > 0) {
        Node item = elements.item(0);
        NamedNodeMap attributes = item.getAttributes();
        if (attributes != null) {
            Node attr = attributes.getNamedItem(attributeName);
            if (attr != null) {
                result = attr.getNodeValue();
            }
        }
    }
    return result;
}

From source file:com.l2jfree.gameserver.document.DocumentBase.java

final void attachFunc(Node n, Object template, String name) {
    final NamedNodeMap attrs = n.getAttributes();

    final Stats stat = Stats.valueOfXml(attrs.getNamedItem("stat").getNodeValue());
    final int ord = Integer.decode(attrs.getNamedItem("order").getNodeValue());
    final double lambda = getLambda(n, template);

    final Condition applayCond = parseConditionIfExists(n.getFirstChild(), template);

    final FuncTemplate ft = new FuncTemplate(applayCond, name, stat, ord, lambda);

    if (template instanceof L2Equip)
        ((L2Equip) template).attach(ft);

    else if (template instanceof L2Skill)
        ((L2Skill) template).attach(ft);

    else if (template instanceof EffectTemplate)
        ((EffectTemplate) template).attach(ft);

    else//from ww w.j  a va2s.com
        throw new IllegalStateException("Invalid template for a Func");
}

From source file:com.amalto.core.save.context.BeforeSaving.java

public boolean validateFormat(String msg) {
    NodeList nodeList;/*from   w  w w.j av  a2s. c  o  m*/
    try {
        Document document = Util.parse(msg.toLowerCase());
        nodeList = Util.getNodeList(document, "//report/message"); //$NON-NLS-1$
    } catch (Exception e) {
        return false;
    }
    if (nodeList.getLength() != 1) {
        return false;
    }
    Node reportNode = nodeList.item(0);
    if (reportNode.getNodeType() != Node.ELEMENT_NODE) {
        return false;
    }
    NamedNodeMap attrMap = reportNode.getAttributes();
    Node attribute = attrMap.getNamedItem("type"); //$NON-NLS-1$
    if (attribute == null) {
        return false;
    }
    if (!"info".equalsIgnoreCase(attribute.getNodeValue()) //$NON-NLS-1$
            && !"error".equalsIgnoreCase(attribute.getNodeValue())) { //$NON-NLS-1$
        return false;
    }
    NodeList messageNodeList = reportNode.getChildNodes();
    if (messageNodeList.getLength() > 1) {
        return false;
    }
    if (messageNodeList.getLength() == 0) {
        return true;
    }
    Node messageNode = messageNodeList.item(0);
    return messageNode.getNodeType() == Node.TEXT_NODE;
}

From source file:eu.europa.esig.dss.xades.countersignature.XAdESCounterSignatureTest.java

@Test
public void test() throws Exception {
    CertificateService certificateService = new CertificateService();
    MockPrivateKeyEntry entryUserA = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);
    MockPrivateKeyEntry entryUserB = certificateService.generateCertificateChain(SignatureAlgorithm.RSA_SHA256);

    DSSDocument document = new FileDocument(new File("src/test/resources/sample.xml"));

    // Sign/*from  ww  w .  j ava2s . c  o  m*/
    XAdESSignatureParameters signatureParameters = new XAdESSignatureParameters();
    signatureParameters.setSigningCertificate(entryUserA.getCertificate());
    signatureParameters.setCertificateChain(entryUserA.getCertificateChain());
    signatureParameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
    signatureParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);

    CertificateVerifier certificateVerifier = new CommonCertificateVerifier();
    XAdESService service = new XAdESService(certificateVerifier);

    ToBeSigned dataToSign = service.getDataToSign(document, signatureParameters);
    ;
    SignatureValue signatureValue = sign(signatureParameters.getSignatureAlgorithm(), entryUserA, dataToSign);
    DSSDocument signedDocument = service.signDocument(document, signatureParameters, signatureValue);

    // Countersign
    Document documentDom = DSSXMLUtils.buildDOM(signedDocument);
    XPathQueryHolder xPathQueryHolder = new XPathQueryHolder();
    Node node = DSSXMLUtils.getNode(documentDom, xPathQueryHolder.XPATH__SIGNATURE);
    assertNotNull(node);
    NamedNodeMap attributes = node.getAttributes();
    Node attributeId = attributes.getNamedItem("Id");
    assertNotNull(attributeId);

    XAdESSignatureParameters countersigningParameters = new XAdESSignatureParameters();
    countersigningParameters.setSignatureLevel(SignatureLevel.XAdES_BASELINE_B);
    countersigningParameters.setSignaturePackaging(SignaturePackaging.ENVELOPED);
    countersigningParameters.setToCounterSignSignatureId(attributeId.getNodeValue());
    countersigningParameters.setSigningCertificate(entryUserB.getCertificate());
    countersigningParameters.setCertificateChain(entryUserB.getCertificateChain());

    DSSDocument counterSignDocument = service.counterSignDocument(signedDocument, countersigningParameters,
            new MockSignatureTokenConnection(), entryUserB);
    assertNotNull(counterSignDocument);

    try {
        byte[] byteArray = IOUtils.toByteArray(counterSignDocument.openStream());
        LOGGER.info(new String(byteArray));
    } catch (Exception e) {
        LOGGER.error("Cannot display file content", e);
    }

    // Validate
    SignedDocumentValidator validator = SignedDocumentValidator.fromDocument(counterSignDocument);
    validator.setCertificateVerifier(new CommonCertificateVerifier());
    Reports reports = validator.validateDocument();

    reports.print();

    DiagnosticData diagnosticData = reports.getDiagnosticData();

    List<XmlDom> signatures = diagnosticData.getElements("/DiagnosticData/Signature");
    assertEquals(2, signatures.size());

    boolean foundCounterSignature = false;
    for (XmlDom xmlDom : signatures) {
        String type = xmlDom.getAttribute("Type");
        if (AttributeValue.COUNTERSIGNATURE.equals(type)) {
            foundCounterSignature = true;
        }
        assertTrue(diagnosticData.isBLevelTechnicallyValid(xmlDom.getAttribute("Id")));
    }
    assertTrue(foundCounterSignature);
}

From source file:com.axelor.apps.base.test.PrepareCsv.java

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;/*  www . ja  va2s . c  o m*/
        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:com.stevpet.sonar.plugins.dotnet.resharper.customseverities.BaseCustomSeverities.java

private String getKeyAttributeValue(Node node) {
    NamedNodeMap attributeMap = node.getAttributes();
    Node keyAttribute = attributeMap.getNamedItem("x:Key");
    return keyAttribute.getNodeValue();
}

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

@Override
public void markUnmodified() {
    Node parentNode = getElement();
    NamedNodeMap attributes = parentNode.getAttributes();
    if (attributes.getNamedItem(MODIFIED_MARKER_ATTRIBUTE) != null) {
        attributes.removeNamedItem(MODIFIED_MARKER_ATTRIBUTE);
    }/*from w w  w.j a  v a 2  s .  co m*/
}

From source file:com.googlecode.ehcache.annotations.config.EhCacheConfigBeanDefinitionParser.java

/**
 * @param evictExpiredElement/*from ww w.  j  a  va2 s  .com*/
 * @return The list of {@link CacheNameMatcher}s to use for finding caches to evict
 */
protected List<CacheNameMatcher> parseEvictExpiredElement(final Element evictExpiredElement) {
    List<CacheNameMatcher> cacheNameMatchers = new ArrayList<CacheNameMatcher>();
    final NodeList childNodes = evictExpiredElement.getChildNodes();
    final int childNodesLength = childNodes.getLength();
    boolean configContainsExcludes = false;
    boolean configContainsIncludes = false;
    if (0 != childNodesLength) {
        for (int index = 0; index < childNodesLength; index++) {
            final Node childNode = childNodes.item(index);
            if (Node.ELEMENT_NODE == childNode.getNodeType()) {
                final String childName = childNode.getLocalName();
                NamedNodeMap childAttributes = childNode.getAttributes();
                Node nameAttr = childAttributes.getNamedItem(XSD_ATTRIBUTE__NAME);
                CacheNameMatcher matcher = null;
                if (null != nameAttr) {
                    String matcherValue = nameAttr.getTextContent();
                    matcher = new ExactCacheNameMatcherImpl(matcherValue);
                } else {
                    Node patternAttr = childAttributes.getNamedItem(XSD_ATTRIBUTE__PATTERN);
                    if (null != patternAttr) {
                        String matcherValue = patternAttr.getTextContent();
                        matcher = new PatternCacheNameMatcherImpl(matcherValue);
                    }
                }

                if (null != matcher) {
                    if (XSD_ELEMENT__INCLUDE.equals(childName)) {
                        cacheNameMatchers.add(matcher);
                        configContainsIncludes = true;
                    } else if (XSD_ELEMENT__EXCLUDE.equals(childName)) {
                        cacheNameMatchers.add(new NotCacheNameMatcherImpl(matcher));
                        configContainsExcludes = true;
                    }
                }
            }
        }
    }

    if (0 == cacheNameMatchers.size()) {
        // no include/exclude elements found
        cacheNameMatchers = Collections.singletonList(INCLUDE_ALL_CACHE_NAME_MATCHER);
    } else if (!configContainsIncludes && configContainsExcludes) {
        //config contains excludes only
        // create a new list with a Include all matcher at the front
        List<CacheNameMatcher> newList = new ArrayList<CacheNameMatcher>();
        newList.add(INCLUDE_ALL_CACHE_NAME_MATCHER);
        newList.addAll(cacheNameMatchers);
        cacheNameMatchers = newList;
    }

    return Collections.unmodifiableList(cacheNameMatchers);
}