Example usage for org.w3c.dom Element getAttribute

List of usage examples for org.w3c.dom Element getAttribute

Introduction

In this page you can find the example usage for org.w3c.dom Element getAttribute.

Prototype

public String getAttribute(String name);

Source Link

Document

Retrieves an attribute value by name.

Usage

From source file:io.cloudslang.schema.WorkerBeanDefinitionParser.java

private static void registerWorkerVersionService(Element element, ParserContext parserContext) {
    String registerWorkerVersionService = element.getAttribute("registerWorkerVersionService");
    if (!registerWorkerVersionService.equals(Boolean.FALSE.toString())) {
        new BeanRegistrator(parserContext).CLASS(WorkerVersionServiceImpl.class).register();
    }/*w ww .  j a  v a  2  s.co  m*/
}

From source file:Main.java

/**
 * Get attribute value, returning <code>null</code> if unset.
 * Some DOM implementations return an empty string for an unset
 * attribute.//from w ww .  j a  v  a  2s .  c  o m
 * @param element The DOM element.
 * @param attributeName The attribute to get.
 * @param namespaceURI Namespace URI of the required attribute, or null
 * to perform a non-namespaced get.
 * @return The attribute value, or &lt;code&gt;null&lt;/code&gt; if unset.
 */
public static String getAttributeValue(Element element, String attributeName, String namespaceURI) {
    String attributeValue;
    if (namespaceURI == null) {
        attributeValue = element.getAttribute(attributeName);
    } else {
        attributeValue = element.getAttributeNS(namespaceURI, attributeName);
    }
    if (attributeValue.length() == 0 && !element.hasAttribute(attributeName)) {
        return null;
    }
    return attributeValue;
}

From source file:Main.java

public static String readAttributeValue(Element e, String attributeName) {
    if (!e.hasAttribute(attributeName)) {
        throw new IllegalStateException("Attribute '" + attributeName + "' is absent");
    }/* ww  w.jav a  2  s . c o m*/

    return e.getAttribute(attributeName);
}

From source file:Main.java

/**
 * Returns true if the given value is an XML node with the node name and if
 * the optional attribute has the specified value.
 * //from w  w w  .j av a 2  s. c  om
 * @param value
 *            Object that should be examined as a node.
 * @param nodeName
 *            String that specifies the node name.
 * @param attributeName
 *            Optional attribute name to check.
 * @param attributeValue
 *            Optional attribute value to check.
 * @return Returns true if the value matches the given conditions.
 */
public static boolean isNode(Object value, String nodeName, String attributeName, String attributeValue) {
    if (value instanceof Element) {
        Element element = (Element) value;

        if (nodeName == null || element.getNodeName().equalsIgnoreCase(nodeName)) {
            String tmp = (attributeName != null) ? element.getAttribute(attributeName) : null;

            return attributeName == null || (tmp != null && tmp.equals(attributeValue));
        }
    }

    return false;
}

From source file:org.drools.container.spring.namespace.EventListenersUtil.java

private static ManagedMap parseEventListenersByType(ParserContext parserContext, List<Element> eventListeners,
        String listenerType) {/*from w  w w  . ja  v a  2 s  . c  o  m*/
    ManagedMap listeners = new ManagedMap();
    for (Element listener : eventListeners) {
        String ref = listener.getAttribute("ref");
        // if this a bean ref
        if (StringUtils.hasText(ref)) {
            if (TYPE_AGENDA_EVENT_LISTENER.equalsIgnoreCase(listenerType)
                    || TYPE_PROCESS_EVENT_LISTENER.equalsIgnoreCase(listenerType)
                    || TYPE_WORKING_MEMORY_EVENT_LISTENER.equalsIgnoreCase(listenerType)) {
                ManagedList subList = (ManagedList) listeners.get(listenerType);
                if (subList == null) {
                    subList = new ManagedList();
                    listeners.put(listenerType, subList);
                }
                subList.add(new RuntimeBeanReference(ref));
            } else {
                throw new IllegalArgumentException(
                        "eventListener must be of type 'agenda-event-listener or 'process-event-listener' or 'working-memory-event-listener'.");
            }
        } else {
            //not a ref check if it is a nested bean
            Element nestedBean = DomUtils.getChildElementByTagName(listener, "bean");
            if (nestedBean == null) {
                //no 'ref' and no nested beans, add the default debug listeners part of the core libs.
                Object obj = null;
                if (TYPE_AGENDA_EVENT_LISTENER.equalsIgnoreCase(listenerType)) {
                    obj = new DebugAgendaEventListener();
                } else if (TYPE_PROCESS_EVENT_LISTENER.equalsIgnoreCase(listenerType)) {
                    obj = new DebugProcessEventListener();
                } else if (TYPE_WORKING_MEMORY_EVENT_LISTENER.equalsIgnoreCase(listenerType)) {
                    obj = new DebugWorkingMemoryEventListener();
                } else {
                    throw new IllegalArgumentException(
                            "eventListener must be of type 'agenda-event-listener or 'process-event-listener' or 'working-memory-event-listener'.");
                }
                ManagedList subList = (ManagedList) listeners.get(listenerType);
                if (subList == null) {
                    subList = new ManagedList();
                    listeners.put(listenerType, subList);
                }
                subList.add(obj);
            } else {
                //String type = StringUtils.hasText(listenerType) ? listenerType: "infer";
                Object obj = parserContext.getDelegate().parsePropertySubElement(nestedBean, null, null);
                ManagedList subList = (ManagedList) listeners.get(listenerType);
                if (subList == null) {
                    subList = new ManagedList();
                    listeners.put(listenerType, subList);
                }
                subList.add(obj);
            }
        }
    }
    return listeners;
}

From source file:com.nominanuda.springmvc.MvcFrontControllerBeanDefinitionParser.java

public static String getAttribute(Element el, String name) {
    String val = el.getAttribute(name);
    if (val == null || "".equals(val)) {
        return null;
    }//from  w  w w .ja va  2 s. com
    return val;
}

From source file:Main.java

private static Properties importProperties(NodeList nodeList) {
    Properties properties = new Properties();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Element entry = (Element) nodeList.item(i);
        if (entry.hasAttribute("name")) {
            String val = (entry == null) ? "" : entry.getFirstChild().getNodeValue();
            String key = entry.getAttribute("name");
            properties.setProperty(key, val);
        }/*w  w  w .  j a  v  a 2s .  com*/
    }
    return properties;
}

From source file:Main.java

static public String getNodeValue(Element parent, String nodeName) {
    NodeList nodes = parent.getElementsByTagName(nodeName);
    if (nodes.getLength() == 0)
        return null;
    Element curElem = (Element) nodes.item(0);
    Node textNode = curElem.getFirstChild();
    if (textNode != null) {
        String encVal = curElem.getAttribute("enc");
        String charSetVal = curElem.getAttribute("charSet");
        String returnVal = textNode.getNodeValue();
        if (encVal != null && encVal.equals("t")) {
            if (charSetVal == null)
                return (URLDecoder.decode(returnVal));
            else/* www. ja  va 2 s.com*/
                try {
                    return (URLDecoder.decode(returnVal, charSetVal));
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
        }
        return (returnVal);
    } else
        return ("");
}

From source file:com.microsoft.tfs.core.clients.build.internal.utils.XamlHelper.java

public static Properties loadPartial(final String xaml) {
    final Properties properties = new Properties();

    try {/*from w  w w .  ja  v a2  s . co m*/
        final Document document = DOMCreateUtils.parseString(xaml);
        final Element root = document.getDocumentElement();

        final NodeList nodes = root.getElementsByTagName("x:String"); //$NON-NLS-1$
        for (int i = 0; i < nodes.getLength(); i++) {
            final Element element = (Element) nodes.item(i);
            final String key = element.getAttribute("x:Key"); //$NON-NLS-1$
            final String value = element.getFirstChild().getNodeValue();
            properties.put(key, value);
        }
    } catch (final XMLException e) {
        log.error(
                MessageFormat.format(Messages.getString("XamlHelper.ExceptionParsingProcessParaemtersFormat"), //$NON-NLS-1$
                        xaml), e);
    }

    return properties;
}

From source file:Main.java

private static void findAllElementsByAttributes(Node node, String tagName, String attrName,
        List<String> attrValues, List<Element> result) {
    if (node == null) {
        return;//from  w ww . ja v a 2s  .c  om
    }
    NodeList nodeList = node.getChildNodes();
    if (nodeList == null) {
        return;
    }
    for (int i = 0; i < nodeList.getLength(); ++i) {
        Node currNode = nodeList.item(i);
        Element element = checkIfElement(currNode, tagName);
        if (element != null) {
            for (String value : attrValues) {
                if (element.getAttribute(attrName).equals(value)) {
                    result.add(element);
                    break;
                }
            }
        }
        findAllElementsByAttributes(currNode, tagName, attrName, attrValues, result);
    }
}