Example usage for org.jsoup.nodes Element text

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

Introduction

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

Prototype

public String text() 

Source Link

Document

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

Usage

From source file:com.liato.bankdroid.banking.banks.AbsIkanoPartner.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }/*  ww w .  j a v  a2 s. co  m*/

    urlopen = login();
    Document d = Jsoup.parse(response);
    Element element = d.select("#primary-nav > li:eq(1) > a").first();
    if (element != null && element.attr("href") != null) {
        String myAccountUrl = element.attr("href");
        try {
            response = urlopen.open("https://partner.ikanobank.se/" + myAccountUrl);
            d = Jsoup.parse(response);
            Elements es = d.select("#CustomerAccountInformationSpan > span > span");
            int accId = 0;
            for (Element el : es) {
                Element name = el.select("> span > span:eq(0)").first();
                Element balance = el.select("> span:eq(1)").first();
                Element currency = el.select("> span:eq(2)").first();
                if (name != null && balance != null && currency != null) {
                    Account account = new Account(name.text().trim(), Helpers.parseBalance(balance.text()),
                            Integer.toString(accId));
                    account.setCurrency(Helpers.parseCurrency(currency.text(), "SEK"));
                    if (accId > 0) {
                        account.setAliasfor("0");
                    }
                    accounts.add(account);
                    accId++;
                }
            }
            if (accounts.isEmpty()) {
                throw new BankException(res.getText(R.string.no_accounts_found).toString());
            }
            // Use the amount from "Kvar att handla fr" which should be the
            // last account in the list.
            this.balance = accounts.get(accounts.size() - 1).getBalance();
            ArrayList<Transaction> transactions = new ArrayList<Transaction>();
            es = d.select("#ShowCustomerTransactionPurchasesInformationDiv table tr:has(td)");
            for (Element el : es) {
                if (el.childNodeSize() == 6) {
                    Transaction transaction = new Transaction(el.child(0).text().trim(),
                            el.child(1).text().trim(), Helpers.parseBalance(el.child(2).text()));
                    transaction.setCurrency(Helpers.parseCurrency(el.child(3).text().trim(), "SEK"));
                    transactions.add(transaction);
                }
            }
            accounts.get(0).setTransactions(transactions);
        }

        catch (ClientProtocolException e) {
            throw new BankException(e.getMessage());
        } catch (IOException e) {
            throw new BankException(e.getMessage());
        }
    }
    if (accounts.isEmpty()) {
        throw new BankException(res.getText(R.string.no_accounts_found).toString());
    }
    super.updateComplete();
}

From source file:Leitura.Ecobertura.java

public void escreveTxt() throws IOException { //mtodo para pegar os nomes dos mtodos declarados
    String auxLinha = null;/*from w w w. j a v a  2s.c  o  m*/
    char aux[] = null;
    StringBuffer sbClasse = new StringBuffer();
    StringBuffer sbLinha = new StringBuffer();
    StringBuffer sbMetodo = new StringBuffer();
    String metodoTemp;
    boolean controleClasse = false;

    // Pega somente os elementos com tag "tr"
    Elements elements = document.getElementsByTag("tr");
    for (Element children : elements) {
        if (StringUtils.isBlank(children.text())) {
            continue;
        }
        children.getElementsByClass("comment").remove();
        // System.out.println(children.text());
        //----------------- Dispensa Comentrios -----------------
        //auxLinha = children.getElementsByTag("span").eq(0).text();
        /*if (auxLinha.contains("/*")) {
         comentario = true;
         } else if(auxLinha.contains("//")){
         comentario = true;
         controle = true;            // controla comentrio com //
         }
                
         if (auxLinha.contains("*//*")) {
                                   comentario = false;
                                   }else if(auxLinha.contains("\n") && controle == true){
                                   comentario = false;
                                   controle = false;
                                   }*/

        //------------------ Fim dispensa comentrios --------------

        // if (comentario == false) {
        //--------------------- verifica as linhas do cdigo -------------------
        if (StringUtils.isNotBlank(children.getElementsByClass("numLine").text())) {
            aux = children.getElementsByClass("numLine").text().toCharArray();

            for (int i = 0; i < aux.length; i++) {
                //System.out.println("["+aux[i]+"]");
                if (aux[i] >= 48 && aux[i] <= 57) { // pega o nmero da linha
                    sbLinha.append(aux[i]);
                }
            }
            auxLinha = sbLinha.toString();
            if (StringUtils.isNotBlank(auxLinha)) { // transforma a linha para inteiro
                qtdeLinhas = Integer.parseInt(auxLinha);
            }

            sbLinha.delete(0, sbLinha.length());
        }

        // ------------------- Fim linhas  ---------------------------------
        Elements pre = children.getElementsByTag("pre");
        for (Element element : pre) {
            String tagMetodo = element.getElementsByTag("span").eq(0).text();

            //------------------------- Verifica classe -------------------------
            if (element.getElementsByTag("span").text().contains("class")) {
                element.select("span.keyword").remove();
                if (controleClasse == false) {
                    classe = element.text().trim();
                    aux = classe.toCharArray();

                    for (int j = 0; j < aux.length; j++) {
                        if ((65 <= aux[j]) && (aux[j] <= 90) || (aux[j] >= 97) && (aux[j] <= 122)
                                || (aux[j] == 95)) {
                            sbClasse.append(aux[j]);
                            //System.out.println(j + ", " + sbClasse);
                            if (j < aux.length - 1) {
                                // System.out.println("size: "+aux.length+" j: "+j);
                                if ((aux[j + 1] == ' ') || (aux[j + 1] == '{') || (aux[j + 1] == '<')) {
                                    // System.out.println("entrei");
                                    if ((j + 1) < aux.length - 1) {
                                        for (int k = j++; k < aux.length; k++) {
                                            aux[k] = ' ';
                                        }
                                    }
                                }
                            }
                        }
                    }

                    excluiLinhas.add(qtdeLinhas);
                    classe = sbClasse.toString().replaceAll("\r", "").replaceAll("\t", "").replaceAll("\n", "");

                    controleClasse = true;
                }
                //  System.out.println("Classe: " + classe);
            } //------------------------------- Fim verifica classe------------------------------
              //------------------------------ Verifica mtodo ----------------------------------
              //else if (tagMetodo.equals("privtate") || tagMetodo.equals("public") || tagMetodo.equals("protected")) {
            else if (element.getElementsByTag("span").text().contains("privtate")
                    || element.getElementsByTag("span").text().contains("public")
                    || element.getElementsByTag("span").text().contains("protected")
                    || element.getElementsByTag("span").text().contains("static")
                    || element.getElementsByTag("span").text().contains("final")
                    || element.getElementsByTag("span").text().contains("native")
                    || element.getElementsByTag("span").text().contains("synchronized")
                    || element.getElementsByTag("span").text().contains("abstract")
                    || element.getElementsByTag("span").text().contains("threadsafe")
                    || element.getElementsByTag("span").text().contains("transient")) {
                element.select("span.keyword").remove();
                if (!element.text().contains("=") && !element.text().contains(".")
                        && !element.text().contains("@")) {
                    String[] s = element.text().split(" ");
                    for (int i = 0; i < s.length; i++) {
                        if (s[i].contains("(")) {
                            aux = s[i].toCharArray();
                            for (int j = 0; j < aux.length; j++) {
                                if (aux[j] == '(') {
                                    for (int k = j; k < aux.length; k++) {
                                        aux[k] = ' ';
                                    }
                                    break;
                                }
                                sbMetodo.append(aux[j]);
                            }
                            metodoTemp = sbMetodo.toString();
                            if (!metodoTemp.isEmpty()) {
                                metodo = metodoTemp.replaceAll("\r", "").replaceAll("\t", "").replaceAll("\n",
                                        "");
                                sbMetodo.delete(0, aux.length);
                                informacoes = new Informacoes(classe, metodo, Integer.parseInt(auxLinha));
                                inf.add(informacoes);
                            }
                        }
                    }
                }
            }

            // --------------------------- Fim Verifica Mtodo ------------------------------------
        }

        // }
    }
    /* for(int i=0; i<inf.size(); i++){
     System.out.println("Classe:"+inf.get(i).getClasse()+" Metodo:"+inf.get(i).getMetodo()+" Linha: "+inf.get(i).getLinha());
     }
     //
            
     /* for(Map.Entry<String,Informacoes> entry : inf.entrySet()) {
      String key = entry.getKey();
      int value = entry.getValue().getLinha();
      String metodov = entry.getValue().getMetodo();
      String classev = entry.getValue().getClasse();
            
      System.out.println(key + " => " + classev+ " => " +metodov+ " => " +value);
      }*/
}

From source file:mergedoc.core.APIDocument.java

/**
 * ? Javadoc ????/* w  w w. ja v a  2 s .  c  o m*/
 * @param className ??
 * @param docHtml API 
 */
private void parseMethodComment(String className, Document doc) {
    Elements elements = doc.select("body > div.contentContainer > div.details > ul > li > ul > li > ul > li");
    for (Element element : elements) {
        Element sigElm = element.select("pre").first();
        if (sigElm == null) {
            continue;
        }
        String sigStr = sigElm.html();
        Signature sig = createSignature(className, sigStr);
        Comment comment = new Comment(sig);

        // deprecated 
        String depre = "";
        Elements divs = element.select("div");
        if (divs.size() == 2) {
            depre = divs.get(0).html();
        }
        if (divs.size() > 0) {
            String body = divs.last().html();
            body = formatLinkTag(className, body);
            comment.setDocumentBody(body);
        }

        Elements dtTags = element.select("dl dt");
        for (Element dtTag : dtTags) {
            String dtText = dtTag.text();
            if (dtText.contains(":")) {
                Element dd = dtTag;
                while (true) {
                    dd = dd.nextElementSibling();
                    if (dd == null || dd.tagName().equalsIgnoreCase("dd") == false) {
                        break;
                    }
                    String name = dd.select("code").first().text();
                    if (dtText.contains(":")) {
                        name = "<" + name + ">";
                    }
                    String items = dd.html();
                    Pattern p = PatternCache
                            .getPattern("(?si)<CODE>(.+?)</CODE>\\s*-\\s*(.*?)(<DD>|</DD>|</DL>|<DT>|$)");
                    Matcher m = p.matcher(items);
                    if (m.find()) {
                        String desc = formatLinkTag(className, m.group(2));
                        comment.addParam(name, desc);
                    }
                }
                continue;
            }

            if (dtText.contains(":")) {
                Element dd = dtTag.nextElementSibling();
                String str = dd.html();
                str = formatLinkTag(className, str);
                comment.addReturn(str);
                continue;
            }

            if (dtText.contains(":")) {
                Element dd = dtTag;
                while (true) {
                    dd = dd.nextElementSibling();
                    if (dd == null || dd.tagName().equalsIgnoreCase("dd") == false) {
                        break;
                    }
                    String name = dd.select("code").first().text();
                    String items = dd.html();
                    Pattern p = PatternCache
                            .getPattern("(?si)<CODE>(.+?)</CODE>\\s*-\\s*(.*?)(<DD>|</DD>|</DL>|<DT>|$)");
                    Matcher m = p.matcher(items);
                    if (m.find()) {
                        String desc = formatLinkTag(className, m.group(2));
                        String param = name + " " + desc;
                        comment.addThrows(param);
                    }
                }
                continue;
            }

        }
        // deprecated 
        parseDeprecatedTag(className, depre, comment);

        // 
        parseCommonTag(className, element, comment);

        contextTable.put(sig, comment);
    }
}

From source file:com.liato.bankdroid.banking.banks.coop.Coop.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }// w ww.j  a  v  a2s. c  o  m

    login();

    try {
        for (AccountType at : AccountType.values()) {
            response = urlopen.open(at.getUrl());
            Document d = Jsoup.parse(response);
            Elements historik = d.select("#historik section");
            TransactionParams params = new TransactionParams();
            mTransactionParams.put(at, params);
            if (historik != null && !historik.isEmpty()) {
                String data = historik.first().attr("data-controller");
                Matcher m = rePageGuid.matcher(data);
                if (m.find()) {
                    params.setPageGuid(m.group(1));
                }
            }
            Element date = d.getElementById("dateFrom");
            if (date != null) {
                params.setMinDate(date.hasAttr("min") ? date.attr("min") : null);
                params.setMaxDate(date.hasAttr("max") ? date.attr("max") : null);
            }
            Elements es = d.select(".List:contains(Saldo)");
            if (es != null && !es.isEmpty()) {
                List<String> names = new ArrayList<String>();
                List<String> values = new ArrayList<String>();
                for (Element e : es.first().select("dt")) {
                    names.add(e.text().replaceAll(":", "").trim());
                }
                for (Element e : es.first().select("dd")) {
                    values.add(e.text().trim());
                }
                for (int i = 0; i < Math.min(names.size(), values.size()); i++) {
                    Account a = new Account(names.get(i), Helpers.parseBalance(values.get(i)),
                            String.format("%s%d", at.getPrefix(), i));
                    a.setCurrency(Helpers.parseCurrency(values.get(i), "SEK"));
                    if (a.getName().toLowerCase().contains("disponibelt")) {
                        a.setType(Account.REGULAR);
                        balance = a.getBalance();
                        setCurrency(a.getCurrency());
                    } else {
                        a.setType(Account.OTHER);
                    }

                    if (i > 0) {
                        a.setAliasfor(String.format("%s%d", at.getPrefix(), 0));
                    }
                    accounts.add(a);
                }
            }
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new BankException(e.getMessage());
    }

    try {
        RefundSummaryRequest refsumReq = new RefundSummaryRequest(mUserId, mToken, APPLICATION_ID);
        HttpEntity e = new StringEntity(getObjectmapper().writeValueAsString(refsumReq));
        InputStream is = urlopen
                .openStream("https://www.coop.se/ExternalServices/RefundService.svc/RefundSummary", e, true);
        RefundSummaryResponse refsumResp = readJsonValue(is, RefundSummaryResponse.class);
        if (refsumResp != null && refsumResp.getRefundSummaryResult() != null) {
            Account a = new Account("terbring p ditt kort",
                    BigDecimal.valueOf(refsumResp.getRefundSummaryResult().getAccountBalance()), "refsummary");
            a.setCurrency("SEK");
            if (accounts.isEmpty()) {
                balance = a.getBalance();
                setCurrency(a.getCurrency());
            }
            accounts.add(a);
            a = new Account(
                    String.format("terbring fr %s", refsumResp.getRefundSummaryResult().getMonthName()),
                    BigDecimal.valueOf(refsumResp.getRefundSummaryResult().getTotalRefund()),
                    "refsummary_month");
            accounts.add(a);
        }
    } catch (JsonParseException e) {
        e.printStackTrace();
        throw new BankException(e.getMessage());
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new BankException(e.getMessage());
    }

    if (accounts.isEmpty()) {
        throw new BankException(res.getText(R.string.no_accounts_found).toString());
    }
    super.updateComplete();
}

From source file:edu.harvard.iq.safe.lockss.impl.LOCKSSPlatformStatusHtmlParser.java

/**
 *
 * @param is/*  w w  w . j a  v a2s. c  o m*/
 */
@Override
public void getPlatformStatusData(InputStream is) {

    try {

        Document doc = DataUtil.load(is, "UTF-8", "");
        Element body = doc.body();

        // most of the target items are sandwitched by <b> tag
        // this can be used to reach each target item.
        String tmpCurrentTime = null;
        String tmpUpTime = null;
        String currentTime = null;
        Elements tags = body.getElementsByTag("b");

        for (Element tag : tags) {

            // get the current-time string: for 1.52.3 or older daemons
            // this is the ony place to get it.
            String tagText = tag.text();
            logger.log(Level.FINE, "working on tagText={0}", tagText);

            if (tagText.equals("Daemon Status")) {
                // find current time and up running
                currentTime = tag.parent().parent().text();
                logger.log(Level.INFO, "currentTime text=[{0}]", currentTime);
                // "currentTime =Daemon Status lockss.statelib.lib.in.us (usdocspln group) 01:25:55 03/01/12, up 7d5h21m"
                tmstmpMatcher = currentTimeStampPattern.matcher(currentTime);

                if (tmstmpMatcher.find()) {
                    logger.log(Level.INFO, "group 0={0}", tmstmpMatcher.group(0));
                    tmpCurrentTime = tmstmpMatcher.group(1);
                    logger.log(Level.INFO, "Current Time:group 1={0}", tmpCurrentTime);
                    tmpUpTime = tmstmpMatcher.group(2);
                    logger.log(Level.INFO, "UpTime:group 2={0}", tmpUpTime);
                }
            }

            // get the remaining key-value sets
            if (fieldNameSet.contains(tagText)) {

                Element parent = tag.parent();
                String fieldValue = parent.nextElementSibling().text();
                logger.log(Level.FINE, "{0}={1}", new Object[] { tagText, fieldValue });
                summaryInfoMap.put(tagText, fieldValue);
            }
        }

        // extract the daemon version and platform info that are located
        // at the bottom
        // these data are sandwitched by a <center> tag
        Elements ctags = body.getElementsByTag("center");
        String version = null;
        String platform = null;
        for (Element ctag : ctags) {
            String cText = ctag.text();
            logger.log(Level.FINE, "center tag Text={0}", cText);
            // cText is like this:
            // Daemon 1.53.3 built 28-Jan-12 01:06:36 on build7.lockss.org, Linux RPM 1
            if (StringUtils.isNotBlank(cText) && ctag.child(0).nodeName().equals("font")) {
                String[] versionPlatform = cText.split(", ");
                if (versionPlatform.length == 2) {
                    logger.log(Level.INFO, "daemon version={0};platform={1}", versionPlatform);
                    version = DaemonStatusDataUtil.getDaemonVersion(versionPlatform[0]);
                    platform = versionPlatform[1];
                } else {
                    // the above regex failed
                    logger.log(Level.WARNING, "String-formatting differs; use pattern matching");
                    version = DaemonStatusDataUtil.getDaemonVersion(cText);
                    int platformOffset = cText.lastIndexOf(", ") + 2;
                    platform = cText.substring(platformOffset);
                    logger.log(Level.INFO, "platform={0}", platform);

                }
            }
        }

        if (summaryInfoMap.containsKey("V3 Identity")) {
            String ipAddress = DaemonStatusDataUtil.getPeerIpAddress(summaryInfoMap.get("V3 Identity"));
            logger.log(Level.INFO, "ipAddress={0}", ipAddress);

            if (StringUtils.isNotBlank(ipAddress)) {
                boxInfoMap.put("host", ipAddress);
                if (!ipAddress.equals(summaryInfoMap.get("IP Address"))) {
                    summaryInfoMap.put("IP Address", ipAddress);
                }
            } else {
                logger.log(Level.WARNING, "host token is blank or null: use IP Address instead");
                logger.log(Level.INFO, "IP Address={0}", summaryInfoMap.get("IP Address"));
                boxInfoMap.put("host", summaryInfoMap.get("IP Address"));
            }
        }

        // for pre-1.53.3 versions
        boxInfoMap.put("time", tmpCurrentTime);
        if (!summaryInfoMap.containsKey("Current Time")) {
            summaryInfoMap.put("Current Time", tmpCurrentTime);
        }

        boxInfoMap.put("up", tmpUpTime);
        if (!summaryInfoMap.containsKey("Uptime")) {
            summaryInfoMap.put("Uptime", tmpUpTime);
        }

        boxInfoMap.put("version", version);
        if (!summaryInfoMap.containsKey("Daemon Version")) {
            summaryInfoMap.put("Daemon Version", version);
        }

        boxInfoMap.put("platform", platform);
        if (!summaryInfoMap.containsKey("Platform")) {
            summaryInfoMap.put("Platform", platform);
        }

    } catch (IOException ex) {
        logger.log(Level.SEVERE, "IO error", ex);
    }

    logger.log(Level.INFO, "boxInfoMap={0}", boxInfoMap);
    logger.log(Level.INFO, "summaryInfo={0}", summaryInfoMap);
}

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

protected SearchRequestResult executeSearch(List<SearchQuery> query, int pageIndex)
        throws IOException, OpacErrorException, JSONException {
    final String searchUrl;
    if (!initialised) {
        start();/*w  ww.  ja v  a2 s  .co m*/
    }
    try {
        searchUrl = buildSearchUrl(query, pageIndex);
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }
    final String html = httpGet(searchUrl, getDefaultEncoding());
    final Document doc = Jsoup.parse(html);

    final Element navigation = doc.select(".result_view .navigation").first();
    final int totalResults = navigation != null ? parseTotalResults(navigation.text()) : 0;

    final Element ul = doc.select(".result_view ul.list").first();
    final List<SearchResult> results = new ArrayList<>();
    for (final Element li : ul.children()) {
        if (li.hasClass("zugangsmonat")) {
            continue;
        }
        final SearchResult result = new SearchResult();
        final Element title = li.select(".titelinfo a").first();
        result.setId(getQueryParamsFirst(title.attr("href")).get("id"));
        result.setInnerhtml(title.text() + "<br>" + title.parent().nextElementSibling().text());
        result.setNr(results.size());
        result.setPage(pageIndex);
        result.setType(MEDIA_TYPES.get(li.select(".statusinfo .ma").text()));
        result.setCover(getCover(li));
        final String statusImg = li.select(".status img").attr("src");
        result.setStatus(statusImg.contains("-yes") ? SearchResult.Status.GREEN
                : statusImg.contains("-no") ? SearchResult.Status.RED : null);
        results.add(result);
    }
    return new SearchRequestResult(results, totalResults, pageIndex);
}

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

protected void addSortingSearchFields(List<SearchField> fields) throws IOException, JSONException {
    final String html = httpGet(getApiUrl() + "&mode=a", getDefaultEncoding());
    final Document doc = Jsoup.parse(html);
    for (int i = 0; i < 3; i++) {
        final Element tr = doc.select("#sort_editor tr.sort_" + i).first();
        final DropdownSearchField field = new DropdownSearchField();
        field.setMeaning(SearchField.Meaning.ORDER);
        field.setId("sort_" + i);
        field.setDisplayName(tr.select("td").first().text());
        field.addDropdownValue("", "");
        for (final Element option : tr.select(".crit option")) {
            if (option.hasAttr("selected")) {
                field.addDropdownValue(0, option.attr("value"), option.text());
            } else {
                field.addDropdownValue(option.attr("value"), option.text());
            }/*from w w w  .j  a  va  2 s  .c om*/
        }
        fields.add(field);
    }
}

From source file:company.gonapps.loghut.dao.PostDao.java

public PostDto get(PostDto postObject) throws IOException, InvalidTagNameException {

    PostDto post = getPostObject(postObject.getYear(), postObject.getMonth(), postObject.getDay(),
            postObject.getNumber(), postObject.getSecretEnabled());

    rrwl.readLock().lock();//from   w  ww .  j a va  2  s . c  om
    Document document;
    try {
        document = Jsoup.parse(new File(getPostPathString(post)), "UTF-8");
    } finally {
        rrwl.readLock().unlock();
    }

    post.setTitle(document.select("#loghut-post-title").first().text());
    post.setText(document.select("#loghut-post-text").first().html());
    List<TagDto> tags = new LinkedList<>();

    for (Element tagElement : document.select(".loghut-post-tag")) {
        tags.add(new TagDto().setName(tagElement.text()));
    }

    post.setTags(tags);
    return post;
}

From source file:de.stkl.gbgvertretungsplan.sync.SyncAdapter.java

private Map<String, String> parseGeneralData(Element root, int dataType) {
    Map<String, String> generalData = new HashMap<String, String>();
    // last update time and day
    Element updateTime = root.select("table.mon_head td:eq(2) p").first();
    if (updateTime != null) {
        Pattern pat = Pattern.compile("(Stand: [\\.:0-9 ]+)", Pattern.DOTALL);
        Matcher matcher = pat.matcher(updateTime.text());
        if (matcher.find())
            generalData.put(Sync.GENERAL_DATA_UPDATETIME, matcher.group(1));
    }/*w w  w.ja v a 2  s  . c om*/
    // date the substitution table belongs to
    Element belongingDate = root.select("div.mon_title").first();
    if (belongingDate != null)
        generalData.put(Sync.GENERAL_DATA_DATE, belongingDate.text());

    // daily information
    Elements dailyInfos = root.select("table.info tr");
    int i = 0;
    for (Element info : dailyInfos) {
        Elements e = info.select("td");
        if (e.size() == 0)
            continue;

        String title = "", description = "";
        for (TextNode node : e.first().textNodes())
            title += node.text() + '\n';
        title = title.trim();

        // description only if available
        if (e.size() > 1) {
            for (TextNode node : e.get(1).textNodes())
                description += node.text() + '\n';
            description = title.trim();
        }

        String keyTitle = "", keyDescription = "";
        switch (i) {
        case 0:
            keyTitle = Sync.GENERAL_DATA_DAILYINFO_1_TITLE;
            keyDescription = Sync.GENERAL_DATA_DAILYINFO_1_DESCRIPTION;
            break;
        case 1:
            keyTitle = Sync.GENERAL_DATA_DAILYINFO_2_TITLE;
            keyDescription = Sync.GENERAL_DATA_DAILYINFO_2_DESCRIPTION;
            break;
        case 2:
            keyTitle = Sync.GENERAL_DATA_DAILYINFO_3_TITLE;
            keyDescription = Sync.GENERAL_DATA_DAILYINFO_3_DESCRIPTION;
            break;
        default:
            break;
        }
        if (!keyTitle.equals("")) {
            generalData.put(keyTitle, title);
            generalData.put(keyDescription, description);
        }
        i++;
    }

    generalData.put(Sync.GENERAL_DATA_DATATYPE, String.valueOf(dataType));

    return generalData;
}

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

@Override
public List<SearchField> getSearchFields() throws IOException, JSONException {
    List<SearchField> fields = new ArrayList<>();

    // Text fields
    String html = httpGet(opac_url + "/de/mobile/default.aspx", getDefaultEncoding());
    Document doc = Jsoup.parse(html);
    Elements options = doc.select("#drpOptSearchT option");
    for (Element option : options) {
        TextSearchField field = new TextSearchField();
        field.setDisplayName(option.text());
        field.setId(option.attr("value"));
        field.setData(new JSONObject("{\"filter\":false}"));
        field.setHint("");
        fields.add(field);/*from   www  .ja  v a  2s  .  co  m*/
    }

    // Dropdowns
    String text = httpGet(opac_url + "/de/mobile/GetRestrictions.ashx", getDefaultEncoding());
    JSONArray filters = new JSONObject(text).getJSONArray("restrcontainers");
    for (int i = 0; i < filters.length(); i++) {
        JSONObject filter = filters.getJSONObject(i);
        if (filter.getString("querytyp").equals("EJ")) {
            // Querying by year also works for other years than the ones
            // listed
            // -> Make it a text field instead of a dropdown
            TextSearchField field = new TextSearchField();
            field.setDisplayName(filter.getString("kopf"));
            field.setId(filter.getString("querytyp"));
            field.setData(new JSONObject("{\"filter\":true}"));
            field.setHint("");
            fields.add(field);
        } else {
            DropdownSearchField field = new DropdownSearchField();
            field.setId(filter.getString("querytyp"));
            field.setDisplayName(filter.getString("kopf"));

            JSONArray restrictions = filter.getJSONArray("restrictions");

            field.addDropdownValue("", "Alle");

            for (int j = 0; j < restrictions.length(); j++) {
                JSONObject restriction = restrictions.getJSONObject(j);
                field.addDropdownValue(restriction.getString("id"), restriction.getString("bez"));
            }

            field.setData(new JSONObject("{\"filter\":true}"));
            fields.add(field);
        }
    }

    return fields;
}