Example usage for org.w3c.dom Attr getValue

List of usage examples for org.w3c.dom Attr getValue

Introduction

In this page you can find the example usage for org.w3c.dom Attr getValue.

Prototype

public String getValue();

Source Link

Document

On retrieval, the value of the attribute is returned as a string.

Usage

From source file:jp.go.nict.langrid.bpel.ProcessAnalyzer.java

private static void addNamespaceMappings(NamespaceContextImpl nsc, NamedNodeMap attrs) {
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        String[] names = attr.getName().split(":", 2);
        if (names.length == 2) {
            if (names[0].equals("xmlns")) {
                nsc.addMapping(names[1], attr.getValue());
            }//from  w ww .  j ava2s  . c o  m
        }
    }
}

From source file:com.bcmcgroup.flare.client.ClientUtil.java

/**
 * Obtain the STIX version from the Content_Binding urn
 *
 * @param node Content_Binding node/*from   w w w  . jav a 2 s.co m*/
 * @return a String containing the STIX version
 * @throws DOMException DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation
 * is impossible to perform (either for logical reasons, because data is lost, or because the implementation has become unstable).
 * <a href="https://docs.oracle.com/javase/7/docs/api/org/w3c/dom/DOMException.html">Reference to Oracle Documentation.</a>
 *
 */
private static String getStixVersion(Node node) throws DOMException {
    try {
        String urnStr = "";
        if (node.hasAttributes()) {
            Attr attr = (Attr) node.getAttributes().getNamedItem("binding_id");
            if (attr != null) {
                urnStr = attr.getValue();
            }
        }
        if (urnStr.isEmpty()) {
            urnStr = node.getTextContent();
        }
        if (urnStr != null && !urnStr.isEmpty()) {
            int lastIndex = urnStr.lastIndexOf(":");
            String version = "";
            if (lastIndex >= 0) {
                version = urnStr.substring(lastIndex + 1);
            }
            return version;
        }
    } catch (DOMException e) {
        logger.debug("DOMException when attempting to parse binding id from a STIX node. ");
        throw e;
    }
    return "";
}

From source file:DOMUtils.java

public static void compareNodes(Node expected, Node actual) throws Exception {
    if (expected.getNodeType() != actual.getNodeType()) {
        throw new Exception("Different types of nodes: " + expected + " " + actual);
    }/* w  w  w  . jav  a2s .  c  o m*/
    if (expected instanceof Document) {
        Document expectedDoc = (Document) expected;
        Document actualDoc = (Document) actual;
        compareNodes(expectedDoc.getDocumentElement(), actualDoc.getDocumentElement());
    } else if (expected instanceof Element) {
        Element expectedElement = (Element) expected;
        Element actualElement = (Element) actual;

        // compare element names
        if (!expectedElement.getLocalName().equals(actualElement.getLocalName())) {
            throw new Exception("Element names do not match: " + expectedElement.getLocalName() + " "
                    + actualElement.getLocalName());
        }
        // compare element ns
        String expectedNS = expectedElement.getNamespaceURI();
        String actualNS = actualElement.getNamespaceURI();
        if ((expectedNS == null && actualNS != null) || (expectedNS != null && !expectedNS.equals(actualNS))) {
            throw new Exception("Element namespaces names do not match: " + expectedNS + " " + actualNS);
        }

        String elementName = "{" + expectedElement.getNamespaceURI() + "}" + actualElement.getLocalName();

        // compare attributes
        NamedNodeMap expectedAttrs = expectedElement.getAttributes();
        NamedNodeMap actualAttrs = actualElement.getAttributes();
        if (countNonNamespaceAttribures(expectedAttrs) != countNonNamespaceAttribures(actualAttrs)) {
            throw new Exception(elementName + ": Number of attributes do not match up: "
                    + countNonNamespaceAttribures(expectedAttrs) + " "
                    + countNonNamespaceAttribures(actualAttrs));
        }
        for (int i = 0; i < expectedAttrs.getLength(); i++) {
            Attr expectedAttr = (Attr) expectedAttrs.item(i);
            if (expectedAttr.getName().startsWith("xmlns")) {
                continue;
            }
            Attr actualAttr = null;
            if (expectedAttr.getNamespaceURI() == null) {
                actualAttr = (Attr) actualAttrs.getNamedItem(expectedAttr.getName());
            } else {
                actualAttr = (Attr) actualAttrs.getNamedItemNS(expectedAttr.getNamespaceURI(),
                        expectedAttr.getLocalName());
            }
            if (actualAttr == null) {
                throw new Exception(elementName + ": No attribute found:" + expectedAttr);
            }
            if (!expectedAttr.getValue().equals(actualAttr.getValue())) {
                throw new Exception(elementName + ": Attribute values do not match: " + expectedAttr.getValue()
                        + " " + actualAttr.getValue());
            }
        }

        // compare children
        NodeList expectedChildren = expectedElement.getChildNodes();
        NodeList actualChildren = actualElement.getChildNodes();
        if (expectedChildren.getLength() != actualChildren.getLength()) {
            throw new Exception(elementName + ": Number of children do not match up: "
                    + expectedChildren.getLength() + " " + actualChildren.getLength());
        }
        for (int i = 0; i < expectedChildren.getLength(); i++) {
            Node expectedChild = expectedChildren.item(i);
            Node actualChild = actualChildren.item(i);
            compareNodes(expectedChild, actualChild);
        }
    } else if (expected instanceof Text) {
        String expectedData = ((Text) expected).getData().trim();
        String actualData = ((Text) actual).getData().trim();

        if (!expectedData.equals(actualData)) {
            throw new Exception("Text does not match: " + expectedData + " " + actualData);
        }
    }
}

From source file:com.twinsoft.convertigo.engine.localbuild.BuildLocally.java

private static Element cloneNode(Node node, String newNodeName) {

    Element newElement = node.getOwnerDocument().createElement(newNodeName);

    NamedNodeMap attrs = node.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr attr = (Attr) attrs.item(i);
        newElement.setAttribute(attr.getName(), attr.getValue());
    }//from   w  w w  . j  a v  a2s.c  om

    return newElement;

}

From source file:DomUtils.java

/**
 * Rename element.//from www  .j  a  va2s.  com
 * @param element The element to be renamed.
 * @param replacementElement The tag name of the replacement element.
 * @param keepChildContent <code>true</code> if the target element's child content
 * is to be copied to the replacement element, false if not. Default <code>true</code>.
 * @param keepAttributes <code>true</code> if the target element's attributes
 * are to be copied to the replacement element, false if not. Default <code>true</code>.
 * @return The renamed element.
 */
public static Element renameElement(Element element, String replacementElement, boolean keepChildContent,
        boolean keepAttributes) {

    Element replacement = element.getOwnerDocument().createElement(replacementElement);
    if (keepChildContent) {
        DomUtils.copyChildNodes(element, replacement);
    }
    if (keepAttributes) {
        NamedNodeMap attributes = element.getAttributes();
        int attributeCount = attributes.getLength();

        for (int i = 0; i < attributeCount; i++) {
            Attr attribute = (Attr) attributes.item(i);
            replacement.setAttribute(attribute.getName(), attribute.getValue());
        }
    }
    DomUtils.replaceNode(replacement, element);

    return replacement;
}

From source file:org.fishwife.jrugged.spring.config.PerformanceMonitorBeanDefinitionDecorator.java

/**
 * Gets the value of an attribute and returns true if it is set to "true"
 * (case-insensitive), otherwise returns false.
 * /*ww w  . j av a  2  s . c  o  m*/
 * @param source An Attribute node from the spring configuration
 *
 * @return boolean
 */
private boolean getBooleanAttributeValue(Node source) {
    Attr attribute = (Attr) source;
    String value = attribute.getValue();
    return "true".equalsIgnoreCase(value);
}

From source file:be.fedict.eid.dss.document.zip.ZIPResourceResolver.java

private InputStream findZIPEntry(Attr dsReferenceUri) throws IOException {
    String entryName = dsReferenceUri.getValue();
    ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(this.document));
    ZipEntry zipEntry;//from   w w w.  j  a  v a2 s  . com
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (entryName.equals(zipEntry.getName())) {
            return zipInputStream;
        }
    }
    return null;
}

From source file:be.fedict.eid.dss.document.zip.ZIPResourceResolver.java

@Override
public boolean engineCanResolve(Attr uri, String baseUri) {
    LOG.debug("engineCanResolve: " + uri.getValue());
    try {/*from w w  w .j  av a  2  s  .c o  m*/
        if (null != findZIPEntry(uri)) {
            return true;
        }
    } catch (IOException e) {
        LOG.error("IO error: " + e.getMessage(), e);
        return false;
    }
    /*
     * We claim we can resolve em all.
     */
    return true;
}

From source file:net.di2e.ecdr.search.transform.atom.security.impl.XmlMetadataSecurityMarkingHandler.java

@Override
public SecurityData getSecurityData(Metacard metacard) {
    String metadata = metacard.getMetadata();
    if (StringUtils.isNotBlank(metadata)) {
        XPathHelper helper = new XPathHelper(metacard.getMetadata());
        Document document = helper.getDocument();
        NodeList nodeList = document.getElementsByTagNameNS("*", "security");
        if (nodeList != null && nodeList.getLength() > 0) {
            Element element = (Element) nodeList.item(0);
            NamedNodeMap nodeNameMap = element.getAttributes();
            int length = nodeNameMap.getLength();

            Map<String, List<String>> securityProps = new HashMap<String, List<String>>();
            String securityNamespace = null;
            for (int i = 0; i < length; i++) {
                Attr attr = (Attr) nodeNameMap.item(i);
                String value = attr.getValue();
                if (!attr.getName().startsWith(XMLNS_PREFIX) && StringUtils.isNotBlank(value)) {
                    securityProps.put(attr.getLocalName(), SecurityMarkingParser.getValues(value));
                    if (securityNamespace == null) {
                        securityNamespace = attr.getNamespaceURI();
                    }//  ww w. ja  va  2s.  co m
                }
            }
            if (!securityProps.isEmpty()) {
                return new SecurityDataImpl(securityProps, securityNamespace);
            }
        }
    }
    return null;
}

From source file:org.fishwife.jrugged.spring.config.MonitorMethodInterceptorDefinitionDecorator.java

/**
 * Parse the jrugged:methods attribute into a List of strings of method
 * names/*w  w w .  ja  va 2s  . co m*/
 *
 * @param source An Attribute node from the spring configuration
 *
 * @return List<String>
 */
private List<String> buildMethodList(Node source) {
    Attr attribute = (Attr) source;
    String methods = attribute.getValue();
    return parseMethodList(methods);
}