Example usage for org.jdom2 Element getAttribute

List of usage examples for org.jdom2 Element getAttribute

Introduction

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

Prototype

public Attribute getAttribute(final String attname) 

Source Link

Document

This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.

Usage

From source file:com.rometools.rome.io.impl.RSS091NetscapeParser.java

License:Open Source License

@Override
public boolean isMyType(final Document document) {

    final Element rssRoot = document.getRootElement();
    final String name = rssRoot.getName();
    final Attribute version = rssRoot.getAttribute("version");
    final DocType docType = document.getDocType();

    return name.equals(ELEMENT_NAME) && version != null && version.getValue().equals(getRSSVersion())
            && docType != null && ELEMENT_NAME.equals(docType.getElementName())
            && PUBLIC_ID.equals(docType.getPublicID()) && SYSTEM_ID.equals(docType.getSystemID());

}

From source file:com.rometools.rome.io.impl.RSS091UserlandParser.java

License:Open Source License

@Override
public boolean isMyType(final Document document) {
    final Element rssRoot = document.getRootElement();
    final Attribute version = rssRoot.getAttribute("version");
    return rssRoot.getName().equals("rss") && version != null && version.getValue().equals(getRSSVersion());
}

From source file:com.rometools.rome.io.impl.RSS20Parser.java

License:Open Source License

@Override
public boolean isMyType(final Document document) {
    final Element rssRoot = document.getRootElement();
    final Attribute version = rssRoot.getAttribute("version");
    // as far ROME is concerned RSS 2.0, 2.00 and 2.0.X are all the same, so let's use
    // startsWith for leniency.
    return rssRoot.getName().equals("rss") && version != null && version.getValue().startsWith(getRSSVersion());
}

From source file:com.sangupta.jerry.util.DomUtils.java

License:Apache License

/**
 * Returns the value of the attribute from the element.
 * /*from  w  w  w  .ja  va 2  s. c o  m*/
 * @param element
 * @param attributeName
 */
public static String getAttributeValue(Element element, String attributeName) {
    Attribute attribute = element.getAttribute(attributeName);
    if (attribute != null) {
        return attribute.getValue();
    }

    return null;
}

From source file:com.sangupta.jerry.util.DomUtils.java

License:Apache License

/**
 * Returns the integer value of the attribute from the element.
 * /* w w  w . j  ava2 s  .  c  o  m*/
 * @param element
 * @param attributeName
 */
public static int getAttributeValueAsInt(Element element, String attributeName) {
    Attribute attribute = element.getAttribute(attributeName);
    if (attribute != null) {
        try {
            return attribute.getIntValue();
        } catch (DataConversionException e) {
            e.printStackTrace();
        }
    }

    return 0;
}

From source file:com.sangupta.jerry.util.DomUtils.java

License:Apache License

/**
 * Returns the value of a given attribute for the given tagName amongst the
 * supplied foreign markup values.//from w w w. j av a 2 s .  com
 * 
 * @param tagName
 *            the tag name to find
 * 
 * @param attributeName
 *            the attribute name to extract
 * 
 * @param elements
 *            list of elements to search in
 * 
 * @return the value of the attribute if found, <code>null</code> otherwise
 */
public static String getTagAttribute(String tagName, String attributeName, List<Element> elements) {
    for (Element element : elements) {
        if (tagName.equals(element.getName())) {
            Attribute attribute = element.getAttribute(attributeName);
            if (attribute != null) {
                return attribute.getValue();
            }
        }
    }

    return null;
}

From source file:com.sangupta.jerry.util.DomUtils.java

License:Apache License

/**
 * Returns the value of the element with the given tagName, where the
 * supplied attribute matches the supplied attribute value in the supplied
 * foreign markup values.//  w w w .  ja  v a  2 s .c  o  m
 * 
 * @param tagName
 *            the tag to search for
 * 
 * @param attributeName
 *            the attribute name to look for
 * 
 * @param attributeValue
 *            the attribute value to look for
 * 
 * @param elements
 *            the elements to search in
 * 
 * @return all the values of the attributes which have matched
 * 
 */
public static List<String> getTagValues(String tagName, String attributeName, String attributeValue,
        List<Element> elements) {
    List<String> values = new ArrayList<String>();

    for (Element element : elements) {
        if (tagName.equals(element.getName())) {
            String value = element.getAttribute(attributeName).getValue();
            if (attributeValue.equals(value)) {
                values.add(element.getText());
            }
        }
    }

    return values;
}

From source file:com.speedment.codgen.example.uml.TransformDelegator.java

License:Open Source License

default <M> void declareVisibility(M out, Element in) {
    final Attribute visible = in.getAttribute("visibility");

    if (visible != null && visible.isSpecified()) {
        ifType(visible, out, public_.class, public_::public_);
        ifType(visible, out, private_.class, private_::private_);
        ifType(visible, out, protected_.class, protected_::protected_);
    }//from   www  . j a  v a  2 s .  c om
}

From source file:com.sun.syndication.io.impl.RSS091NetscapeParser.java

License:Open Source License

public boolean isMyType(Document document) {
    boolean ok = false;
    Element rssRoot = document.getRootElement();
    ok = rssRoot.getName().equals("rss");
    if (ok) {//  ww w.j  a v  a 2 s .  c o  m
        ok = false;
        Attribute version = rssRoot.getAttribute("version");
        if (version != null) {
            ok = version.getValue().equals(getRSSVersion());
            if (ok) {
                ok = false;
                DocType docType = document.getDocType();

                if (docType != null) {
                    ok = ELEMENT_NAME.equals(docType.getElementName());
                    ok = ok && PUBLIC_ID.equals(docType.getPublicID());
                    ok = ok && SYSTEM_ID.equals(docType.getSystemID());
                }
            }
        }
    }
    return ok;
}

From source file:com.sun.syndication.io.impl.RSS091UserlandParser.java

License:Open Source License

public boolean isMyType(Document document) {
    boolean ok;/*w ww.  j  a va2 s.com*/
    Element rssRoot = document.getRootElement();
    ok = rssRoot.getName().equals("rss");
    if (ok) {
        ok = false;
        Attribute version = rssRoot.getAttribute("version");
        if (version != null) {
            ok = version.getValue().equals(getRSSVersion());
        }
    }
    return ok;
}