/** * Test if this element has an attribute. * * @param attributeKey The attribute key to check. * @return true if the attribute exists, false if not. */ public boolean hasAttr(String attributeKey) { Validate.notNull(attributeKey); if (attributeKey.toLowerCase().startsWith("abs:")) { String key = attributeKey.substring("abs:".length()); if (attributes.hasKey(key) && !absUrl(key).equals("")) return true; } return attributes.hasKey(attributeKey); }
/** * Get an attribute's value by its key. * * <p>To get an absolute URL from an attribute that may be a relative URL, prefix the key with * <code><b>abs</b></code>, which is a shortcut to the {@link #absUrl} method. E.g.: * * <blockquote> * * <code>String url = a.attr("abs:href");</code> * * </blockquote> * * @param attributeKey The attribute key. * @return The attribute, or empty string if not present (to avoid nulls). * @see #attributes() * @see #hasAttr(String) * @see #absUrl(String) */ public String attr(String attributeKey) { Validate.notNull(attributeKey); if (attributes.hasKey(attributeKey)) return attributes.get(attributeKey); else if (attributeKey.toLowerCase().startsWith("abs:")) return absUrl(attributeKey.substring("abs:".length())); else return ""; }
/** * Check if an element is visible based on whether it has an aria presentation tag. * * @param element * @return true if the element is visible rather than just presentation. * @todo(dallison) check other aria roles for visible intentions */ static boolean isVisible(Element element) { Attributes attributes = element.attributes(); if (attributes.hasKey("role")) { if (attributes.get(ARIA_ROLE).equals(ARIA_PRESENTATION)) { return false; } else { return true; } } else { return true; } }
public String reviseImgForSohuNews(String pcont) { if (pcont == null) return ""; Document doc = Jsoup.parse(pcont); Elements eleimages = doc.select("img"); for (Element img : eleimages) { Attributes attrs = img.attributes(); if (attrs.hasKey("data-src")) { String source = attrs.get("data-src"); img.attr("src", source); } } return doc.html(); }