Example usage for org.w3c.dom Element hasAttribute

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

Introduction

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

Prototype

public boolean hasAttribute(String name);

Source Link

Document

Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.

Usage

From source file:Main.java

private static boolean getElementBooleanValue(Element element, String attribute, boolean defaultValue) {
    if (!element.hasAttribute(attribute))
        return defaultValue;
    return Boolean.valueOf(getElementStringValue(element, attribute)).booleanValue();
}

From source file:org.jdal.beans.BeanDefinitionUtils.java

/**
 * Add property value to {@link BeanDefinitionBuilder} if needed, following the naming {@link Conventions}
 * @param bdb BeanDefintionBuilder to operate on.
 * @param element Element holding the attribute
 * @param attributeName the attribute name
 *///from ww w . ja v  a 2  s  . c  o  m
public static void addPropertyValueIfNeeded(BeanDefinitionBuilder bdb, Element element, String attributeName) {
    if (element.hasAttribute(attributeName))
        bdb.addPropertyValue(Conventions.attributeNameToPropertyName(attributeName),
                element.getAttribute(attributeName));
}

From source file:Main.java

/**
 * Converts XML {@code <property name=""></property>} tags to Properties
 * object.// w  ww.  j av  a 2 s.c o m
 * 
 * @see java.util.XmlUtils.importProperties()
 * 
 * @param entries
 *            List of property nodes in the DOM
 */
public static Properties importProperties(NodeList entries) {
    Properties props = new Properties();
    int numEntries = entries.getLength();
    for (int i = 0; i < numEntries; i++) {
        Element entry = (Element) entries.item(i);
        if (entry.hasAttribute("name")) {
            Node n = entry.getFirstChild();
            String val = (n == null) ? "" : n.getNodeValue();
            props.setProperty(entry.getAttribute("name"), val);
        }
    }
    return props;
}

From source file:Main.java

/**
 * Gets the next sibling to the given element with the given attribute.
 *
 * @return the next sibling, or null if no such sibling
 *//* w  w w . j  a va 2s .c om*/

public static Element getSiblingWithAttribute(Element element, String attributeName) {

    if (element == null) {
        return null;
    }

    Node node = element;

    while (true) {
        node = node.getNextSibling();

        if (node == null) {
            return null;
        }

        if (!(node instanceof Element)) {
            continue;
        }

        Element nextSibling = (Element) node;

        if (nextSibling.hasAttribute(attributeName)) {
            return nextSibling;
        }
    }
}

From source file:org.jdal.beans.BeanDefinitionUtils.java

/**
 * Add property reference to {@link BeanDefinitionBuilder} if needed, following the naming {@link Conventions}
 * @param bdb BeanDefintionBuilder to operate on.
 * @param element Element holding the attribute
 * @param attributeName the attribute name
 *//*from   ww  w  .j a  va  2 s.co m*/
public static void addPropertyReferenceIfNeeded(BeanDefinitionBuilder bdb, Element element,
        String attributeName) {
    if (element.hasAttribute(attributeName))
        bdb.addPropertyReference(Conventions.attributeNameToPropertyName(attributeName),
                element.getAttribute(attributeName));
}

From source file:Main.java

public static Element getFirstChild(Element paramElement, String paramString1, String paramString2,
        String paramString3) {/*from   w w w.j  av a  2  s  .  c  o  m*/
    NodeList localNodeList = paramElement.getChildNodes();
    for (int i = 0; i < localNodeList.getLength(); i++) {
        Node localNode = localNodeList.item(i);
        if ((localNode != null) && (localNode.getNodeType() == 1)
                && (((Element) localNode).getTagName().equals(paramString1))) {
            Element localElement = (Element) localNode;
            if ((localElement.hasAttribute(paramString2))
                    && (paramString3.equals(localElement.getAttribute(paramString2))))
                return localElement;
        }
    }
    return null;
}

From source file:Main.java

/**
 * A convenience method for return a string from an element.  First, this
 * method checks to see if the the specified name exists as an attribute
 * in the element.  If it does, simply returns the attribute value.
 * Then this method checks to see if the specified element has a child
 * element that matches the given name.  If it does, attempts to read
 * the text from the child node.  Otherwise, returns <code>null</code>.
 * @param element//from  ww w. j av  a2  s  . co  m
 * @param name
 * @return String
 */
public static String getAttributeOrChildText(Element element, String name) {
    if (element.hasAttribute(name)) {
        return element.getAttribute(name);
    }
    Element childElem = getChildElement(element, name);
    return childElem == null ? null : getChildText(childElem);
}

From source file:Main.java

public static String getAttribute(Element elem, String att) {
    String res = elem.getAttribute(att);
    return res.length() == 0 && !elem.hasAttribute(att) ? null : res;
}

From source file:ar.com.zauber.commons.conversion.spring.schema.SimplePropertyFieldDefinitionParser.java

/** agrega el constructor del {@link FieldSetSetterStrategy} */
static void configureSetter(final BeanDefinitionBuilder bean, final Element element) {
    if (element.hasAttribute("setter")) {
        final String s = element.getAttribute("setter");
        if (s.equals("setter")) {
            bean.addConstructorArgValue(FieldSetterStrategies.FIELD_SETTER_STRATEGY);
        } else if (s.equals("collection-add")) {
            bean.addConstructorArgValue(FieldSetterStrategies.COLLECTION_ADD_STRATEGY);
        } else {//ww  w.jav a 2s  .c  o m
            throw new IllegalStateException("Unknown setter named " + s);
        }
    }
}

From source file:Main.java

/**
 * Returns an array of strings representing values for provided attribute
 * prefixed by 2 levels of parents, extracted from a provided list of nodes
 * (e.g.: parenetNodeAtrValue.childNodeAtrValue.childNodeAtrValue)
 * @param atrName/*w w  w  .j  av  a  2s .  c o  m*/
 * @param nodes
 * @return
 */
private static ArrayList<String> getValuesWithParentForAttribute(String atrName, NodeList nodes) {
    ArrayList<String> filteredNodesV = new ArrayList<String>();
    for (int j = 0; j < nodes.getLength(); j++) {
        Element childE = (Element) nodes.item(j);
        if (childE.hasAttribute(atrName)) {
            filteredNodesV.add(getXsdParentsAtrValue(childE, atrName) + childE.getAttribute(atrName));
        }
    }
    return filteredNodesV;
}