Example usage for org.jsoup.nodes Document text

List of usage examples for org.jsoup.nodes Document text

Introduction

In this page you can find the example usage for org.jsoup.nodes Document text.

Prototype

public String text() 

Source Link

Document

Gets the combined text of this element and all its children.

Usage

From source file:de.geeksfactory.opacclient.apis.TouchPoint.java

protected SearchRequestResult parse_search(String html, int page) throws OpacErrorException, IOException {
    Document doc = Jsoup.parse(html);

    if (doc.select("#RefineHitListForm").size() > 0) {
        // the results are located on a different page loaded via AJAX
        html = httpGet(opac_url + "/speedHitList.do?_=" + String.valueOf(System.currentTimeMillis() / 1000)
                + "&hitlistindex=0&exclusionList=", ENCODING);
        doc = Jsoup.parse(html);/*w  w  w  .ja  v a2  s .com*/
    }

    if (doc.select(".nodata").size() > 0) {
        return new SearchRequestResult(new ArrayList<SearchResult>(), 0, 1, 1);
    }

    doc.setBaseUri(opac_url + "/searchfoo");

    int results_total = -1;

    String resultnumstr = doc.select(".box-header h2").first().text();
    if (resultnumstr.contains("(1/1)") || resultnumstr.contains(" 1/1")) {
        reusehtml = html;
        throw new OpacErrorException("is_a_redirect");
    } else if (resultnumstr.contains("(")) {
        results_total = Integer.parseInt(resultnumstr.replaceAll(".*\\(([0-9]+)\\).*", "$1"));
    } else if (resultnumstr.contains(": ")) {
        results_total = Integer.parseInt(resultnumstr.replaceAll(".*: ([0-9]+)$", "$1"));
    }

    Elements table = doc.select("table.data > tbody > tr");
    identifier = null;

    Elements links = doc.select("table.data a");
    boolean haslink = false;
    for (Element node : links) {
        if (node.hasAttr("href") & node.attr("href").contains("singleHit.do") && !haslink) {
            haslink = true;
            try {
                List<NameValuePair> anyurl = URLEncodedUtils
                        .parse(new URI(node.attr("href").replace(" ", "%20").replace("&amp;", "&")), ENCODING);
                for (NameValuePair nv : anyurl) {
                    if (nv.getName().equals("identifier")) {
                        identifier = nv.getValue();
                        break;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    }

    List<SearchResult> results = new ArrayList<>();
    for (int i = 0; i < table.size(); i++) {
        Element tr = table.get(i);
        SearchResult sr = new SearchResult();
        if (tr.select(".icn, img[width=32]").size() > 0) {
            String[] fparts = tr.select(".icn, img[width=32]").first().attr("src").split("/");
            String fname = fparts[fparts.length - 1];
            String changedFname = fname.toLowerCase(Locale.GERMAN).replace(".jpg", "").replace(".gif", "")
                    .replace(".png", "");

            // File names can look like this: "20_DVD_Video.gif"
            Pattern pattern = Pattern.compile("(\\d+)_.*");
            Matcher matcher = pattern.matcher(changedFname);
            if (matcher.find()) {
                changedFname = matcher.group(1);
            }

            MediaType defaulttype = defaulttypes.get(changedFname);
            if (data.has("mediatypes")) {
                try {
                    sr.setType(MediaType.valueOf(data.getJSONObject("mediatypes").getString(fname)));
                } catch (JSONException | IllegalArgumentException e) {
                    sr.setType(defaulttype);
                }
            } else {
                sr.setType(defaulttype);
            }
        }
        String title;
        String text;
        if (tr.select(".results table").size() > 0) { // e.g. RWTH Aachen
            title = tr.select(".title a").text();
            text = tr.select(".title div").text();
        } else { // e.g. Schaffhausen, BSB Mnchen
            title = tr.select(".title, .hitlistTitle").text();
            text = tr.select(".results, .hitlistMetadata").first().ownText();
        }

        // we need to do some evil javascript parsing here to get the cover
        // and loan status of the item

        // get cover
        if (tr.select(".cover script").size() > 0) {
            String js = tr.select(".cover script").first().html();
            String isbn = matchJSVariable(js, "isbn");
            String ajaxUrl = matchJSVariable(js, "ajaxUrl");
            if (!"".equals(isbn) && !"".equals(ajaxUrl)) {
                String url = new URL(new URL(opac_url + "/"), ajaxUrl).toString();
                String coverUrl = httpGet(url + "?isbn=" + isbn + "&size=small", ENCODING);
                if (!"".equals(coverUrl)) {
                    sr.setCover(coverUrl.replace("\r\n", "").trim());
                }
            }
        }
        // get loan status and media ID
        if (tr.select("div[id^=loanstatus] + script").size() > 0) {
            String js = tr.select("div[id^=loanstatus] + script").first().html();
            String[] variables = new String[] { "loanstateDBId", "itemIdentifier", "hitlistIdentifier",
                    "hitlistPosition", "duplicateHitlistIdentifier", "itemType", "titleStatus", "typeofHit",
                    "context" };
            String ajaxUrl = matchJSVariable(js, "ajaxUrl");
            if (!"".equals(ajaxUrl)) {
                JSONObject id = new JSONObject();
                List<NameValuePair> map = new ArrayList<>();
                for (String variable : variables) {
                    String value = matchJSVariable(js, variable);
                    if (!"".equals(value)) {
                        map.add(new BasicNameValuePair(variable, value));
                    }
                    try {
                        if (variable.equals("itemIdentifier")) {
                            id.put("id", value);
                        } else if (variable.equals("loanstateDBId")) {
                            id.put("db", value);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                sr.setId(id.toString());
                String url = new URL(new URL(opac_url + "/"), ajaxUrl).toString();
                String loanStatusHtml = httpGet(url + "?" + URLEncodedUtils.format(map, "UTF-8"), ENCODING)
                        .replace("\r\n", "").trim();
                Document loanStatusDoc = Jsoup.parse(loanStatusHtml);
                String loanstatus = loanStatusDoc.text().replace("\u00bb", "").trim();

                if ((loanstatus.startsWith("entliehen") && loanstatus.contains("keine Vormerkung mglich")
                        || loanstatus.contains("Keine Exemplare verfgbar"))) {
                    sr.setStatus(SearchResult.Status.RED);
                } else if (loanstatus.startsWith("entliehen") || loanstatus.contains("andere Zweigstelle")) {
                    sr.setStatus(SearchResult.Status.YELLOW);
                } else if ((loanstatus.startsWith("bestellbar") && !loanstatus.contains("nicht bestellbar"))
                        || (loanstatus.startsWith("vorbestellbar")
                                && !loanstatus.contains("nicht vorbestellbar"))
                        || (loanstatus.startsWith("vorbestellbar")
                                && !loanstatus.contains("nicht vorbestellbar"))
                        || (loanstatus.startsWith("vormerkbar") && !loanstatus.contains("nicht vormerkbar"))
                        || (loanstatus.contains("heute zurckgebucht"))
                        || (loanstatus.contains("ausleihbar") && !loanstatus.contains("nicht ausleihbar"))) {
                    sr.setStatus(SearchResult.Status.GREEN);
                }
                if (sr.getType() != null) {
                    if (sr.getType().equals(MediaType.EBOOK) || sr.getType().equals(MediaType.EVIDEO)
                            || sr.getType().equals(MediaType.MP3))
                    // Especially Onleihe.de ebooks are often marked
                    // green though they are not available.
                    {
                        sr.setStatus(SearchResult.Status.UNKNOWN);
                    }
                }
            }
        }

        sr.setInnerhtml(("<b>" + title + "</b><br/>") + text);

        sr.setNr(10 * (page - 1) + i + 1);
        results.add(sr);
    }
    resultcount = results.size();
    return new SearchRequestResult(results, results_total, page);
}

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

private void loadScheduleFromUrl(SubstitutionSchedule v, String url, List<String> usedUrls)
        throws IOException, JSONException, CredentialInvalidException, IncompatibleScheduleException {
    usedUrls.add(url);//from w  w  w.  j  a  v  a  2s .  c o m
    String html = httpGet(url, data.has(PARAM_ENCODING) ? data.optString(PARAM_ENCODING, null) : "UTF-8");
    Document doc = Jsoup.parse(html);

    if (doc.title().toLowerCase().contains("untis") || doc.html().toLowerCase().contains("untis")
            || data.optString(PARAM_TYPE, "").equals("untis")) {
        parseMultipleMonitorDays(v, doc, data);
    } else if (doc.html().toLowerCase().contains("created by davinci")
            || data.optString(PARAM_TYPE, "").equals("davinci")) {
        Elements titles = doc.select("h2");
        Elements tables = doc.select("h2 + p + table");
        if (titles.size() != tables.size())
            throw new IOException("Anzahl berschriften != Anzahl Tabellen");
        for (int i = 0; i < titles.size(); i++) {
            SubstitutionScheduleDay day = new SubstitutionScheduleDay();
            String date = titles.get(i).text();
            day.setDateString(date);
            day.setDate(ParserUtils.parseDate(date));
            DaVinciParser.parseDaVinciTable(tables.get(i), v, day, colorProvider);
            v.addDay(day);
        }
    } else if (doc.select(".tdaktionen").size() > 0 || data.optString(PARAM_TYPE, "").equals("indiware")) {
        new IndiwareParser(scheduleData, cookieProvider).parseIndiwarePage(v, doc.html());
    } else if (doc.text().matches(".*Fr diesen Bereich.*wurde kein Inhalt bereitgestellt\\.")) {
        return;
    } else {
        throw new IncompatibleScheduleException();
    }

    if (doc.select("meta[http-equiv=refresh]").size() > 0) {
        Element meta = doc.select("meta[http-equiv=refresh]").first();
        String attr = meta.attr("content").toLowerCase();
        String redirectUrl = url.substring(0, url.lastIndexOf("/") + 1)
                + attr.substring(attr.indexOf("url=") + 4);
        if (!usedUrls.contains(redirectUrl)) {
            loadScheduleFromUrl(v, redirectUrl, usedUrls);
        }
    }
}

From source file:de.geeksfactory.opacclient.apis.SISIS.java

@Override
public ReservationResult reservation(DetailledItem item, Account acc, int useraction, String selection)
        throws IOException {
    String reservation_info = item.getReservation_info();
    final String branch_inputfield = "issuepoint";

    Document doc = null;/*w w w .j a v a 2 s . c o m*/

    String action = "reservation";
    if (reservation_info.contains("doBestellung")) {
        action = "order";
    }

    if (useraction == MultiStepResult.ACTION_CONFIRMATION) {
        List<NameValuePair> nameValuePairs = new ArrayList<>(2);
        nameValuePairs.add(new BasicNameValuePair("methodToCall", action));
        nameValuePairs.add(new BasicNameValuePair("CSId", CSId));
        String html = httpPost(opac_url + "/" + action + ".do", new UrlEncodedFormEntity(nameValuePairs),
                ENCODING);
        doc = Jsoup.parse(html);
    } else if (selection == null || useraction == 0) {
        String html = httpGet(opac_url + "/availability.do?" + reservation_info, ENCODING);
        doc = Jsoup.parse(html);

        if (doc.select("input[name=username]").size() > 0) {
            // Login vonnten
            List<NameValuePair> nameValuePairs = new ArrayList<>(2);
            nameValuePairs.add(new BasicNameValuePair("username", acc.getName()));
            nameValuePairs.add(new BasicNameValuePair("password", acc.getPassword()));
            nameValuePairs.add(new BasicNameValuePair("methodToCall", "submit"));
            nameValuePairs.add(new BasicNameValuePair("CSId", CSId));
            nameValuePairs.add(new BasicNameValuePair("login_action", "Login"));

            html = handleLoginMessage(
                    httpPost(opac_url + "/login.do", new UrlEncodedFormEntity(nameValuePairs), ENCODING));
            doc = Jsoup.parse(html);

            if (doc.getElementsByClass("error").size() == 0) {
                logged_in = System.currentTimeMillis();
                logged_in_as = acc;
            }
        }
        if (doc.select("input[name=expressorder]").size() > 0) {
            List<NameValuePair> nameValuePairs = new ArrayList<>(2);
            nameValuePairs.add(new BasicNameValuePair(branch_inputfield, selection));
            nameValuePairs.add(new BasicNameValuePair("methodToCall", action));
            nameValuePairs.add(new BasicNameValuePair("CSId", CSId));
            nameValuePairs.add(new BasicNameValuePair("expressorder", " "));
            html = httpPost(opac_url + "/" + action + ".do", new UrlEncodedFormEntity(nameValuePairs),
                    ENCODING);
            doc = Jsoup.parse(html);
        }
        if (doc.select("input[name=" + branch_inputfield + "]").size() > 0) {
            List<Map<String, String>> branches = new ArrayList<>();
            for (Element option : doc.select("input[name=" + branch_inputfield + "]").first().parent().parent()
                    .parent().select("td")) {
                if (option.select("input").size() != 1) {
                    continue;
                }
                String value = option.text().trim();
                String key = option.select("input").val();
                Map<String, String> selopt = new HashMap<>();
                selopt.put("key", key);
                selopt.put("value", value);
                branches.add(selopt);
            }
            ReservationResult result = new ReservationResult(MultiStepResult.Status.SELECTION_NEEDED);
            result.setActionIdentifier(ReservationResult.ACTION_BRANCH);
            result.setSelection(branches);
            return result;
        }
    } else if (useraction == ReservationResult.ACTION_BRANCH) {
        List<NameValuePair> nameValuePairs = new ArrayList<>(2);
        nameValuePairs.add(new BasicNameValuePair(branch_inputfield, selection));
        nameValuePairs.add(new BasicNameValuePair("methodToCall", action));
        nameValuePairs.add(new BasicNameValuePair("CSId", CSId));

        String html = httpPost(opac_url + "/" + action + ".do", new UrlEncodedFormEntity(nameValuePairs),
                ENCODING);
        doc = Jsoup.parse(html);
    }

    if (doc == null) {
        return new ReservationResult(MultiStepResult.Status.ERROR);
    }

    if (doc.getElementsByClass("error").size() >= 1) {
        return new ReservationResult(MultiStepResult.Status.ERROR,
                doc.getElementsByClass("error").get(0).text());
    }

    if (doc.select("#CirculationForm p").size() > 0 && doc.select("input[type=button]").size() >= 2) {
        List<String[]> details = new ArrayList<>();
        for (String row : doc.select("#CirculationForm p").first().html().split("<br>")) {
            Document frag = Jsoup.parseBodyFragment(row);
            if (frag.text().contains(":")) {
                String[] split = frag.text().split(":");
                if (split.length >= 2) {
                    details.add(new String[] { split[0].trim() + ":", split[1].trim() });
                }
            } else {
                details.add(new String[] { "", frag.text().trim() });
            }
        }
        ReservationResult result = new ReservationResult(Status.CONFIRMATION_NEEDED);
        result.setDetails(details);
        return result;
    }

    if (doc.select("#CirculationForm .textrot").size() >= 1) {
        String errmsg = doc.select("#CirculationForm .textrot").get(0).text();
        if (errmsg.contains("Dieses oder andere Exemplare in anderer Zweigstelle ausleihbar")) {
            Copy best = null;
            for (Copy copy : item.getCopies()) {
                if (copy.getResInfo() == null) {
                    continue;
                }
                if (best == null) {
                    best = copy;
                    continue;
                }
                try {
                    if (Integer.parseInt(copy.getReservations()) < Long.parseLong(best.getReservations())) {
                        best = copy;
                    } else if (Integer.parseInt(copy.getReservations()) == Long
                            .parseLong(best.getReservations())) {
                        if (copy.getReturnDate().isBefore(best.getReturnDate())) {
                            best = copy;
                        }
                    }
                } catch (NumberFormatException e) {

                }
            }
            if (best != null) {
                item.setReservation_info(best.getResInfo());
                return reservation(item, acc, 0, null);
            }
        }
        return new ReservationResult(MultiStepResult.Status.ERROR, errmsg);
    }

    if (doc.select("#CirculationForm td[colspan=2] strong").size() >= 1) {
        return new ReservationResult(MultiStepResult.Status.OK,
                doc.select("#CirculationForm td[colspan=2] strong").get(0).text());
    }
    return new ReservationResult(Status.OK);
}

From source file:com.ewcms.plugin.crawler.generate.EwcmsContentCrawler.java

/**
 * ?page??//from w ww . j  av a  2s  .  co  m
 */
@Override
public void visit(Page page) {
    try {
        String url = page.getWebURL().getURL();

        page.setContentType("text/html; charset=" + gather.getEncoding());
        Document doc = Jsoup.connect(url).timeout(gather.getTimeOutWait().intValue() * 1000).get();

        String title = doc.title();
        if (gather.getTitleExternal() && gather.getTitleRegex() != null
                && gather.getTitleRegex().length() > 0) {
            Elements titleEles = doc.select(gather.getTitleRegex());
            if (!titleEles.isEmpty()) {
                String tempTitle = titleEles.text();
                if (tempTitle != null && tempTitle.length() > 0) {
                    title = tempTitle;
                }
            }
        }

        if (title != null && title.trim().length() > 0) {
            Elements elements = doc.select(matchRegex);
            if (filterRegex != null && filterRegex.trim().length() > 0) {
                elements = elements.not(filterRegex);
            }
            if (!elements.isEmpty()) {
                String subHtml = elements.html();
                Document blockDoc = Jsoup.parse(subHtml);
                String contentText = blockDoc.html();

                if (gather.getRemoveHref()) {
                    Document moveDoc = Jsoup.parse(contentText);
                    Elements moveEles = moveDoc.select("*").not("a");
                    contentText = moveEles.html();
                }
                if (gather.getRemoveHtmlTag())
                    contentText = doc.text();

                if (isLocal) {
                    contentText = doc.text();

                    Boolean isMatcher = true;
                    for (int i = 0; i < keys.length; i++) {
                        Boolean result = Pattern.compile(keys[i].trim()).matcher(contentText).find();
                        if (!result) {
                            isMatcher = false;
                            break;
                        }
                    }

                    if (isMatcher) {
                        Storage storage = new Storage();
                        storage.setGatherId(gather.getId());
                        storage.setGatherName(gather.getName());
                        storage.setTitle(title);
                        storage.setUrl(url);
                        try {
                            gatherService.addStorage(storage);
                        } catch (Exception e) {
                            logger.error("save storage error : {}", e.getLocalizedMessage());
                        } finally {
                            storage = null;
                        }
                    }
                } else {
                    Content content = new Content();
                    content.setDetail(contentText);
                    content.setPage(1);
                    List<Content> contents = new ArrayList<Content>();
                    contents.add(content);

                    Article article = new Article();
                    article.setTitle(title);
                    article.setContents(contents);

                    articleMainService.addArticleMainByCrawler(article, gather.getChannelId(),
                            CrawlerUtil.USER_NAME);
                }
            }
        }
    } catch (IOException e) {
        logger.warn(e.getLocalizedMessage());
    }
}

From source file:de.geeksfactory.opacclient.apis.BiBer1992.java

private Document accountHttpPost(Account account, String func) throws IOException, OpacErrorException {
    // get media list via http POST
    List<NameValuePair> nameValuePairs = new ArrayList<>(2);
    nameValuePairs.add(new BasicNameValuePair("FUNC", func));
    nameValuePairs.add(new BasicNameValuePair("LANG", "de"));
    nameValuePairs.add(new BasicNameValuePair("BENUTZER", account.getName()));
    nameValuePairs.add(new BasicNameValuePair("PASSWORD", account.getPassword()));

    String html = httpPost(opacUrl + "/" + opacDir + "/user.C", new UrlEncodedFormEntity(nameValuePairs),
            getDefaultEncoding());//w w w .j a va 2 s . c o  m

    Document doc = Jsoup.parse(html);

    // Error recognition
    // <title>OPAC Fehler</title>
    if (doc.title().contains("Fehler")
            || (doc.select("h2").size() > 0 && doc.select("h2").text().contains("Fehler"))) {
        String errText = "unknown error";
        Elements elTable = doc.select("table");
        if (elTable.size() > 0) {
            errText = elTable.get(0).text();
        }
        throw new OpacErrorException(errText);
    }
    if (doc.select("tr td font[color=red]").size() == 1) {
        throw new OpacErrorException(doc.select("font[color=red]").text());
    }
    if (doc.text().contains("No html file set")
            || doc.text().contains("Der BIBDIA Server konnte den Auftrag nicht")) {
        throw new OpacErrorException(stringProvider.getString(StringProvider.WRONG_LOGIN_DATA));
    }

    return doc;
}

From source file:com.gelakinetic.mtgfam.fragments.CardViewFragment.java

/**
 * Converts some html to plain text, replacing images with their textual counterparts
 *
 * @param html html to be converted//from   w ww  . j  ava 2s. c o m
 * @return plain text representation of the input
 */
public String convertHtmlToPlainText(String html) {
    Document document = Jsoup.parse(html);
    Elements images = document.select("img");
    for (Element image : images) {
        image.html("{" + image.attr("src") + "}");
    }
    return document.text();
}

From source file:de.geeksfactory.opacclient.apis.IOpac.java

@Override
public ReservationResult reservation(DetailledItem item, Account account, int useraction, String selection)
        throws IOException {
    String reservation_info = item.getReservation_info();
    // STEP 1: Login page
    String html = httpGet(opac_url + "/" + reservation_info, getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    if (doc.select("table").first().text().contains("kann nicht")) {
        return new ReservationResult(MultiStepResult.Status.ERROR, doc.select("table").first().text().trim());
    }/*ww  w. j a  v  a  2 s . c o  m*/

    if (doc.select("form[name=form1]").size() == 0) {
        return new ReservationResult(MultiStepResult.Status.ERROR);
    }

    Element form = doc.select("form[name=form1]").first();
    List<BasicNameValuePair> params = new ArrayList<>();
    params.add(new BasicNameValuePair("sleKndNr", account.getName()));
    params.add(new BasicNameValuePair("slePw", account.getPassword()));
    params.add(new BasicNameValuePair("pshLogin", "Reservieren"));
    for (Element input : form.select("input[type=hidden]")) {
        params.add(new BasicNameValuePair(input.attr("name"), input.attr("value")));
    }

    // STEP 2: Confirmation page
    html = httpPost(opac_url + "/cgi-bin/di.exe", new UrlEncodedFormEntity(params), getDefaultEncoding());
    doc = Jsoup.parse(html);

    if (doc.select("form[name=form1]").size() > 0) {
        // STEP 3: There is another confirmation needed
        form = doc.select("form[name=form1]").first();
        html = httpGet(opac_url + "/" + generateQuery(form), getDefaultEncoding());
        doc = Jsoup.parse(html);
    }

    if (doc.text().contains("fehlgeschlagen") || doc.text().contains("Achtung")
            || doc.text().contains("nicht m")) {
        return new ReservationResult(MultiStepResult.Status.ERROR, doc.select("table").first().text().trim());
    } else {
        return new ReservationResult(MultiStepResult.Status.OK);
    }

}

From source file:com.lloydtorres.stately.issues.IssueDecisionActivity.java

/**
 * Process the received page into the Issue and its IssueOptions
 * @param v Activity view//from   w  w w  . java2  s .co  m
 * @param d Document received from NationStates
 */
private void processIssueInfo(View v, Document d) {
    // First check if the issue is still available
    if (d.text().contains(NOT_AVAILABLE)) {
        mSwipeRefreshLayout.setRefreshing(false);
        SparkleHelper.makeSnackbar(v,
                String.format(Locale.US, getString(R.string.issue_unavailable), mNation.name));
        return;
    }

    Element issueInfoContainer = d.select("div#dilemma").first();

    if (issueInfoContainer == null) {
        // safety check
        mSwipeRefreshLayout.setRefreshing(false);
        SparkleHelper.makeSnackbar(v, getString(R.string.login_error_parsing));
        return;
    }

    Elements issueInfoRaw = issueInfoContainer.children();

    String issueText = issueInfoRaw.select("p").first().text();
    // If this is an issue chain, grab the second paragraph instead
    if (d.select("div.dilemmachain").first() != null) {
        issueText = issueInfoRaw.select("p").get(1).text();
        if (d.text().contains(STORY_SO_FAR)) {
            issueText = issueText + "<br><br>" + issueInfoRaw.select("p").get(2).text();
        }
    }
    issue.content = issueText;

    issue.options = new ArrayList<IssueOption>();

    Element optionHolderMain = issueInfoRaw.select("ol.diloptions").first();
    if (optionHolderMain != null) {
        Elements optionsHolder = optionHolderMain.select("li");

        int i = 0;
        for (Element option : optionsHolder) {
            IssueOption issueOption = new IssueOption();
            issueOption.index = i++;

            Element button = option.select("button").first();
            if (button != null) {
                issueOption.header = button.attr("name");
            } else {
                issueOption.header = IssueOption.SELECTED_HEADER;
            }

            Element optionContentHolder = option.select("p").first();
            if (optionContentHolder == null) {
                // safety check
                mSwipeRefreshLayout.setRefreshing(false);
                SparkleHelper.makeSnackbar(v, getString(R.string.login_error_parsing));
                return;
            }

            issueOption.content = optionContentHolder.text();
            issue.options.add(issueOption);
        }
    }

    IssueOption dismissOption = new IssueOption();
    dismissOption.index = -1;
    dismissOption.header = IssueOption.DISMISS_HEADER;
    dismissOption.content = "";
    issue.options.add(dismissOption);

    setRecyclerAdapter(issue);
    mSwipeRefreshLayout.setRefreshing(false);
    mSwipeRefreshLayout.setEnabled(false);
}

From source file:org.b3log.symphony.service.ActivityMgmtService.java

/**
 * Collects 1A0001.//www . j  a  va 2s .  c o  m
 *
 * @param userId the specified user id
 * @return result
 */
public synchronized JSONObject collect1A0001(final String userId) {
    final JSONObject ret = Results.falseResult();

    if (!activityQueryService.is1A0001Today(userId)) {
        ret.put(Keys.MSG, langPropsService.get("activityNotParticipatedLabel"));

        return ret;
    }

    if (activityQueryService.isCollected1A0001Today(userId)) {
        ret.put(Keys.MSG, langPropsService.get("activityParticipatedLabel"));

        return ret;
    }

    final List<JSONObject> records = pointtransferQueryService.getLatestPointtransfers(userId,
            Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_1A0001, 1);
    final JSONObject pointtransfer = records.get(0);
    final String data = pointtransfer.optString(Pointtransfer.DATA_ID);
    final String smallOrLarge = data.split("-")[1];
    final int sum = pointtransfer.optInt(Pointtransfer.SUM);

    String smallOrLargeResult = null;
    try {
        final Document doc = Jsoup.parse(new URL("http://stockpage.10jqka.com.cn/1A0001/quote/header/"), 5000);
        final JSONObject result = new JSONObject(doc.text());
        final String price = result.optJSONObject("data").optJSONObject("1A0001").optString("10");

        if (!price.contains(".")) {
            smallOrLargeResult = "0";
        } else {
            int endInt = 0;
            if (price.split("\\.")[1].length() > 1) {
                final String end = price.substring(price.length() - 1);
                endInt = Integer.valueOf(end);
            }

            if (0 <= endInt && endInt <= 4) {
                smallOrLargeResult = "0";
            } else if (5 <= endInt && endInt <= 9) {
                smallOrLargeResult = "1";
            } else {
                LOGGER.error("Activity 1A0001 collect result [" + endInt + "]");
            }
        }
    } catch (final Exception e) {
        LOGGER.log(Level.ERROR, "Collect 1A0001 failed", e);

        ret.put(Keys.MSG, langPropsService.get("activity1A0001CollectFailLabel"));

        return ret;
    }

    if (Strings.isEmptyOrNull(smallOrLarge)) {
        ret.put(Keys.MSG, langPropsService.get("activity1A0001CollectFailLabel"));

        return ret;
    }

    ret.put(Keys.STATUS_CODE, true);
    if (StringUtils.equals(smallOrLarge, smallOrLargeResult)) {
        final int amount = sum * 2;

        final boolean succ = null != pointtransferMgmtService.transfer(Pointtransfer.ID_C_SYS, userId,
                Pointtransfer.TRANSFER_TYPE_C_ACTIVITY_1A0001_COLLECT, amount,
                DateFormatUtils.format(new Date(), "yyyyMMdd") + "-" + smallOrLargeResult);

        if (succ) {
            String msg = langPropsService.get("activity1A0001CollectSucc1Label");
            msg = msg.replace("{point}", String.valueOf(amount));

            ret.put(Keys.MSG, msg);
        } else {
            ret.put(Keys.MSG, langPropsService.get("activity1A0001CollectFailLabel"));
        }
    } else {
        ret.put(Keys.MSG, langPropsService.get("activity1A0001CollectSucc0Label"));
    }

    return ret;
}

From source file:org.spdx.licenseTemplate.SpdxLicenseTemplateHelper.java

/**
 * Converts an HTML string to text preserving line breaks for <br/> tags
 * @param html/*  w  w w. jav  a2 s.  com*/
 * @return
 */
public static String htmlToText(String html) {
    String newlineString = "NewLineGoesHere";
    String replaceBrs = html.replaceAll("(?i)<br[^>]*>", newlineString);
    String replaceBrsAndPs = replaceBrs.replaceAll("(?i)<p[^>]*>", newlineString);
    Document doc = Jsoup.parse(replaceBrsAndPs);
    String retval = doc.text();
    retval = retval.replace(newlineString, "\n");
    return retval;
}