Example usage for org.jsoup.nodes Element select

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

Introduction

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

Prototype

public Elements select(String cssQuery) 

Source Link

Document

Find elements that match the Selector CSS query, with this element as the starting context.

Usage

From source file:com.itcs.commons.email.EmailAutoconfigClient.java

private static void extractOutgoingServerSettings(Document doc, Map<String, String> settings) {
    for (Element element : doc.select("outgoingServer")) {
        //            System.out.println("element.attr(\"type\"):"+element.attr("type"));
        if (element.attr("type").equals("smtp")) {
            //                System.out.println("element.select(\"hostname\"):" + element.select("hostname").text());
            settings.put(EnumEmailSettingKeys.SMTP_SERVER.getKey(), element.select("hostname").text());
            //                System.out.println("element.select(\"port\"):" + element.select("port").text());
            settings.put(EnumEmailSettingKeys.SMTP_PORT.getKey(), element.select("port").text());
            //                System.out.println("element.select(\"socketType\"):" + element.select("socketType").text());
            settings.put(EnumEmailSettingKeys.SMTP_SSL_ENABLED.getKey(),
                    element.select("socketType").text().equals("SSL") ? "true" : "false");
            settings.put(EnumEmailSettingKeys.TRANSPORT_TLS.getKey(),
                    element.select("socketType").text().equals("STARTTLS") ? "true" : "false");
        }//from ww  w  .j  av  a 2 s .  c  o  m
    }
}

From source file:me.vertretungsplan.parser.UntisCommonParser.java

private static Element getContentElement(Element cell) {
    if (cell.ownText().isEmpty() && cell.select("> span").size() == 1) {
        cell = cell.select("> span").first();
    }//from   w w w  .j av a 2  s. com
    return cell;
}

From source file:me.vertretungsplan.parser.UntisCommonParser.java

static void handleRoom(Substitution subst, Element cell) {
    cell = getContentElement(cell);/*w w w .  j  a va 2s.com*/
    if (cell.select("s").size() > 0) {
        subst.setPreviousRoom(cell.select("s").text());
        if (cell.ownText().length() > 0) {
            subst.setRoom(cell.ownText().replaceFirst("^\\?", "").replaceFirst("", ""));
        }
    } else {
        subst.setRoom(cell.text());
    }
}

From source file:me.vertretungsplan.parser.UntisCommonParser.java

static void handleSubject(Substitution subst, Element cell) {
    cell = getContentElement(cell);//from w w w.  j a  va2 s . c om
    if (cell.select("s").size() > 0) {
        subst.setPreviousSubject(cell.select("s").text());
        if (cell.ownText().length() > 0) {
            subst.setSubject(cell.ownText().replaceFirst("^\\?", "").replaceFirst("", ""));
        }
    } else {
        subst.setSubject(cell.text());
    }
}

From source file:me.vertretungsplan.parser.UntisInfoParser.java

private static List<Substitution> parseTimetableCell(Element cell, String lesson, String klasse,
        JSONArray cellFormat, ColorProvider colorProvider) throws JSONException {
    List<Substitution> substitutions = new ArrayList<>();
    if (cell.text().trim().equals("")) {
        return substitutions;
    }//from  w  w  w  .  j a  v a 2s .  c  o  m

    final Elements rows = cell.select("table").first().select("tr");

    int cols = rows.get(0).select("td").size();
    int courseCount = cols / cellFormat.getJSONArray(0).length();

    for (int course = 0; course < courseCount; course++) {
        Substitution s = new Substitution();
        s.setLesson(lesson);

        final HashSet<String> classes = new HashSet<>();
        classes.add(klasse);
        s.setClasses(classes);

        boolean isChange = false;

        for (int row = 0; row < cellFormat.length() && row < rows.size(); row++) {
            JSONArray rowData = cellFormat.getJSONArray(row);
            Element tr = rows.get(row);
            for (int col = 0; col < rowData.length(); col++) {
                if (rowData.getString(col) == null)
                    continue;
                String type = rowData.getString(col);

                try {
                    Element td = tr.select("td").get(col + course * cellFormat.getJSONArray(0).length());
                    if (td.select("font[color=#FF0000]").size() > 0) {
                        isChange = true;
                    }

                    parseTimetableCellContent(s, type, td);
                } catch (IndexOutOfBoundsException e) {
                    if (course == 0)
                        throw e;
                }
            }
        }

        if (s.getSubject() == null && s.getTeacher() == null && s.getRoom() == null) {
            s.setType("Entfall");
        } else {
            s.setType("Vertretung");
        }
        s.setColor(colorProvider.getColor(s.getType()));

        if (isChange) {
            substitutions.add(s);
        }
    }

    return substitutions;
}

From source file:me.vertretungsplan.parser.UntisCommonParser.java

static void handleTeacher(Substitution subst, Element cell, JSONObject data) {
    cell = getContentElement(cell);//from ww w.  j a va 2 s .co m
    if (cell.select("s").size() > 0) {
        subst.setPreviousTeachers(splitTeachers(cell.select("s").text(), data));
        if (cell.ownText().length() > 0) {
            subst.setTeachers(
                    splitTeachers(cell.ownText().replaceFirst("^\\?", "").replaceFirst("", ""), data));
        }
    } else {
        subst.setTeachers(splitTeachers(cell.text(), data));
    }
}

From source file:com.sastix.cms.server.services.content.impl.GeneralFileHandlerServiceImpl.java

@Override
public String findParentFile(String xml) {
    String ret = null;//from ww  w  . j  a  v  a  2s .  c o m
    Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
    for (Element e : doc.select("resources")) {
        ret = e.select("resource").get(0).attr("href");
    }
    return ret;
}

From source file:de.limod.portals.AutoScout.java

private String getCreated(Element result) {
    Elements t = result.select(AutoScout.SELECTOR_CREATED);
    return t.text();
}

From source file:de.limod.portals.AutoScout.java

private String getPrice(Element result) {
    Elements t = result.select(AutoScout.SELECTOR_PRICE);
    return t.text();
}

From source file:org.cellcore.code.engine.page.extractor.mfrag.MFRAGPageDataExtractor.java

@Override
protected int getStock(Document doc) {
    Elements trs = doc.select("#Tableau").get(0).children().get(0).children();
    float iPrice = Float.MAX_VALUE;
    int iStock = 0;
    for (int i = 1; i < trs.size(); i++) {
        Element tr = trs.get(i);
        String val = tr.select("td").get(3).select("strong").get(0).childNodes().get(0).attr("text");
        String stockV = tr.select("td").get(4).select("option").last().childNodes().get(0).attr("text");
        val = cleanPriceString(val);
        float price = Float.parseFloat(val);

        if (price < iPrice) {
            iPrice = price;//www .j a  va2 s  .  c  o m
            iStock = Integer.parseInt(stockV.replaceAll("\\(", "").replaceAll("\\)", ""));
        }
    }
    return iStock;
}