Example usage for org.jsoup.nodes Element hasAttr

List of usage examples for org.jsoup.nodes Element hasAttr

Introduction

In this page you can find the example usage for org.jsoup.nodes Element hasAttr.

Prototype

public boolean hasAttr(String attributeKey) 

Source Link

Document

Test if this element has an attribute.

Usage

From source file:ru.redcraft.pinterest4j.core.api.PinAPI.java

private List<Pin> parsePinsResponse(Document doc) {
    List<Pin> pinList = new ArrayList<Pin>();
    Elements htmlPins = doc.select("div.pin");
    for (Element htmlPin : htmlPins) {
        if (htmlPin.hasAttr(PinAPI.PIN_ID_ATTR)) {
            long pinID = Long.valueOf(htmlPin.attr(PinAPI.PIN_ID_ATTR));
            pinList.add(new LazyPin(pinID, getApiManager()));
        }//from   w w w.  j  a  va2s  .c  o m
    }
    LOG.debug(COLLECTED_PINS + pinList.size());
    return pinList;
}

From source file:uk.co.certait.htmlexporter.css.StyleMap.java

private Style getInlineStyle(Element element) {
    Style style = null;//from   w  w  w . j av a 2s  .  co  m

    if (element.hasAttr("style")) {
        List<Rule> inlineRules;
        try {
            String inlineStyle = element.attr("style").endsWith(";") ? element.attr("style")
                    : element.attr("style") + ";";
            inlineRules = CSSParser.parse("x{" + inlineStyle + "}");
        } catch (Exception e) {
            throw new RuntimeException("Error parsing inline style for element " + element.tagName());
        }

        style = generator.createStyle(inlineRules.get(0), inlineRules.get(0).getSelectors().get(0));
    }

    return style;
}

From source file:uk.co.certait.htmlexporter.writer.AbstractTableCellWriter.java

/**
 * Checks the for the presence of the 'colspan' attribute on the cell and
 * returns the value if this attribute if present, otherwise 1.
 * //from w ww  . j  a va 2s.  co  m
 * @param element
 * 
 * @return True if the this Element spans multiple columns (has the
 *         'colspan' attribute defined, otherwise false.
 */
protected boolean spansMultipleColumns(Element element) {
    boolean spansMultipleColumns = false;

    if (element.hasAttr(COLUMN_SPAN_ATTRIBUTE)) {
        int columnCount = Integer.parseInt(element.attr(COLUMN_SPAN_ATTRIBUTE));

        spansMultipleColumns = columnCount > 1;
    }

    return spansMultipleColumns;
}

From source file:uk.co.certait.htmlexporter.writer.AbstractTableCellWriter.java

protected boolean definesFreezePane(Element element) {
    boolean definesFreezePane = false;

    if (element.hasAttr(DATA_FREEZE_PANE_CELL)) {
        if (Boolean.parseBoolean(element.attr(DATA_FREEZE_PANE_CELL))) {
            definesFreezePane = true;/*from w  w  w .  j  a v a 2s .  c o  m*/
        }
    }

    return definesFreezePane;
}

From source file:uk.co.certait.htmlexporter.writer.AbstractTableCellWriter.java

/**
 * /*from  ww  w .j av a  2  s .  c o m*/
 * @param element
 * 
 * @return
 */
protected boolean isFunctionGroupCell(Element element) {
    return element.hasAttr(DATA_GROUP_ATTRIBUTE);
}

From source file:uk.co.certait.htmlexporter.writer.AbstractTableCellWriter.java

protected boolean isDateCell(Element element) {
    return element.hasAttr(DATE_CELL_ATTRIBUTE);
}

From source file:uk.co.certait.htmlexporter.writer.AbstractTableCellWriter.java

/**
 * /*from w w w.  ja va 2s .  c  o m*/
 * @param element
 * @param attributeName
 * 
 * @return
 */
protected String[] getAttributeValues(Element element, String attributeName) {
    String values[] = null;

    if (element.hasAttr(attributeName)) {
        values = element.attr(attributeName).toLowerCase().split(",");

        for (String value : values) {
            value = value.trim().toLowerCase();
        }
    }

    return values;
}

From source file:uk.co.certait.htmlexporter.writer.AbstractTableCellWriter.java

/**
 * /*from  www . j a  va  2s.c  om*/
 * @param element
 * 
 * @return
 */
public Double getNumericValue(Element element) {
    Double numericValue = null;

    if (!element.hasAttr(DATA_TEXT_CELL))
        try {
            numericValue = NumberFormat.getInstance().parse(element.ownText()).doubleValue();
        } catch (ParseException e) {

        }

    return numericValue;
}

From source file:webserver.WebResource.java

public static String selectDescriptionOpt(Document htmlDoc) {
    String result = "";
    Elements descriptions = htmlDoc.select("meta[name=\"description\"]");
    if (descriptions.size() > 0) {
        Element descr = descriptions.get(0);
        if (descr.hasAttr("content")) {
            result = descr.attr("content");
        }// w  ww  .j  a v a 2 s .co m
    }

    return result;
}

From source file:webserver.WebResource.java

public static String injectValues(String value) {
    // PROCESSING TAG INJ
    Pattern pattern = Pattern.compile("(?i)(<inj.*>(.*?)</inj>)");
    Matcher matcher = pattern.matcher(value);
    while (matcher.find()) {
        Document doc = Jsoup.parse(matcher.group(1));
        Elements inj = doc.select("inj");
        Element element = inj.get(0);

        NameStorageMap nameMap = DBSet.getInstance().getNameStorageMap();
        String name = matcher.group(2);
        String result = "";
        if (nameMap.contains(name)) {

            if (element.hasAttr("key")) {
                String key = element.attr("key");
                String opt = nameMap.getOpt(name, key);
                result = opt != null ? opt : "";

            }/*from   w  w  w  .  ja v  a2s . co m*/
        }
        value = value.replace(matcher.group(), result);

    }
    return value;
}