Example usage for org.jsoup.nodes Element val

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

Introduction

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

Prototype

public String val() 

Source Link

Document

Get the value of a form element (input, textarea, etc).

Usage

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

private String parse_option_regex(Element inputTag) {
    String optStr = inputTag.val();
    String html = inputTag.parent().html();
    String result = optStr;/* w w w  .  j a v  a 2s .c o  m*/

    String regex1 = "value=\"" + optStr + "\".*?>([^<]+)";
    String[] regexList = new String[] { regex1 };

    for (String regex : regexList) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(html);
        if (matcher.find()) {
            result = matcher.group(1);
            result = result.replaceAll("&nbsp;", " ").trim();
            break;
        }
    }

    return result;
}

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

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

    HttpGet httpget;/*from  w ww . j  a  va  2  s  .co m*/
    if (opacDir.contains("opax")) {
        httpget = new HttpGet(opacUrl + "/" + opacDir + "/de/qsel.html.S");
    } else {
        httpget = new HttpGet(opacUrl + "/" + opacDir + "/de/qsel_main.S");
    }

    HttpResponse response = http_client.execute(httpget);

    if (response.getStatusLine().getStatusCode() == 500) {
        throw new NotReachableException(response.getStatusLine().getReasonPhrase());
    }
    String html = convertStreamToString(response.getEntity().getContent());
    HttpUtils.consume(response.getEntity());

    Document doc = Jsoup.parse(html);

    // get text fields
    Elements text_opts = doc.select("form select[name=REG1] option");
    for (Element opt : text_opts) {
        TextSearchField field = new TextSearchField();
        field.setId(opt.attr("value"));
        field.setDisplayName(opt.text());
        field.setHint("");
        fields.add(field);
    }

    // get media types
    Elements mt_opts = doc.select("form input[name~=(MT|MS)]");
    if (mt_opts.size() > 0) {
        DropdownSearchField mtDropdown = new DropdownSearchField();
        mtDropdown.setId(mt_opts.get(0).attr("name"));
        mtDropdown.setDisplayName("Medientyp");
        for (Element opt : mt_opts) {
            if (!opt.val().equals("")) {
                String text = opt.text();
                if (text.length() == 0) {
                    // text is empty, check layouts:
                    // Essen: <input name="MT"><img title="mediatype">
                    // Schaffenb: <input name="MT"><img alt="mediatype">
                    Element img = opt.nextElementSibling();
                    if (img != null && img.tagName().equals("img")) {
                        text = img.attr("title");
                        if (text.equals("")) {
                            text = img.attr("alt");
                        }
                    }
                }
                if (text.length() == 0) {
                    // text is still empty, check table layout, Example
                    // Friedrichshafen
                    // <td><input name="MT"></td> <td><img
                    // title="mediatype"></td>
                    Element td1 = opt.parent();
                    Element td2 = td1.nextElementSibling();
                    if (td2 != null) {
                        Elements td2Children = td2.select("img[title]");
                        if (td2Children.size() > 0) {
                            text = td2Children.get(0).attr("title");
                        }
                    }
                }
                if (text.length() == 0) {
                    // text is still empty, check images in label layout, Example
                    // Wiedenst
                    // <input type="radio" name="MT" id="MTYP1" value="MTYP1">
                    // <label for="MTYP1"><img src="http://www.wiedenest.de/bib/image/books
                    // .png" alt="Bcher" title="Bcher"></label>
                    Element label = opt.nextElementSibling();
                    if (label != null) {
                        Elements td2Children = label.select("img[title]");
                        if (td2Children.size() > 0) {
                            text = td2Children.get(0).attr("title");
                        }
                    }
                }
                if (text.length() == 0) {
                    // text is still empty: missing end tag like Offenburg
                    text = parse_option_regex(opt);
                }
                mtDropdown.addDropdownValue(opt.val(), text);
            }
        }
        fields.add(mtDropdown);
    }

    // get branches
    Elements br_opts = doc.select("form select[name=ZW] option");
    if (br_opts.size() > 0) {
        DropdownSearchField brDropdown = new DropdownSearchField();
        brDropdown.setId(br_opts.get(0).parent().attr("name"));
        brDropdown.setDisplayName(br_opts.get(0).parent().parent().previousElementSibling().text()
                .replace("\u00a0", "").replace("?", "").trim());
        for (Element opt : br_opts) {
            brDropdown.addDropdownValue(opt.val(), opt.text());
        }
        fields.add(brDropdown);
    }

    return fields;
}

From source file:me.postar.postarv2.LocalService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    Functions.getParcels(parcels, this);

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Postar");

    if (Functions.isConnectedToInternet(LocalService.this)) {
        Ion.with(this).load("GET", "https://e-racuni.postacg.me/PracenjePosiljaka/").asString().withResponse()
                .setCallback(new FutureCallback<Response<String>>() {
                    @Override//from  w  w  w  .  j  a  v a2  s .c  o  m
                    public void onCompleted(Exception e, Response<String> result) {
                        Document html = Jsoup.parse(result.getResult());
                        Element viewState = html.getElementById("__VIEWSTATE");
                        Element eventValidation = html.getElementById("__EVENTVALIDATION");
                        Element btnPronadji = html.getElementById("btnPronadji");

                        for (final PostParcel parcel : parcels) {
                            if (parcel.isAlarmOn()) {
                                Ion.with(LocalService.this)
                                        .load("POST", "https://e-racuni.postacg.me/PracenjePosiljaka/")
                                        .setBodyParameter("__VIEWSTATE", viewState.val())
                                        .setBodyParameter("__EVENTVALIDATION", eventValidation.val())
                                        .setBodyParameter("btnPronadji", btnPronadji.val())
                                        .setBodyParameter("txtPrijemniBroj", parcel.getParcelNo()).asString()
                                        .withResponse().setCallback(new FutureCallback<Response<String>>() {
                                            @Override
                                            public void onCompleted(Exception e,
                                                    final Response<String> result) {
                                                Document html = Jsoup.parse(result.getResult());
                                                Element table = html.getElementById("dgInfo");

                                                if (table != null) {
                                                    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                                                            LocalService.this)
                                                                    .setSmallIcon(R.drawable.ic_mail_outline)
                                                                    .setLargeIcon(BitmapFactory.decodeResource(
                                                                            getResources(),
                                                                            R.drawable.ic_mail_outline))
                                                                    .setAutoCancel(true);
                                                    mBuilder.setContentTitle(getString(R.string.message_title));
                                                    mBuilder.setContentText(
                                                            getString(R.string.message_content));
                                                    Intent activityIntent = new Intent(LocalService.this,
                                                            StatusActivity.class);
                                                    activityIntent.putExtra("parcel", parcel);
                                                    PendingIntent resultPendingIntent = PendingIntent
                                                            .getActivity(LocalService.this, 0, activityIntent,
                                                                    PendingIntent.FLAG_UPDATE_CURRENT);
                                                    mBuilder.setContentIntent(resultPendingIntent);
                                                    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
                                                            Context.NOTIFICATION_SERVICE);

                                                    mNotificationManager.notify(12, mBuilder.build());

                                                    stopSelf();

                                                    wl.release();
                                                }
                                            }
                                        });
                            }
                        }
                    }
                });
    }

    return START_NOT_STICKY;
}

From source file:org.bigmouth.tfc.v1.PageImpl.java

protected void asynSearch() throws IOException {
    Element asynUrl = document.getElementById("J_ShopAsynSearchURL");
    this.asynSearchUrl = host + asynUrl.val();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("ShopAsycnSearchURL: {}", this.asynSearchUrl);
    }/*from w ww. ja  va 2 s  .  c om*/
    this.asynSearchDoc = JsoupHelper.get(asynSearchUrl);
    String html = JsoupHelper.escape(this.asynSearchDoc.html());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("shopasycnsearch source: {}", html);
    }
    this.asynSearchDoc = Jsoup.parse(html);
}

From source file:org.wso2.appfactory.integration.test.utils.rest.APIMIntegrationClient.java

private void retrieveSAMLToken(String userName, String password) throws Exception {

    String ssoUrl = getBackEndUrl() + "/samlsso";
    String webAppurl = getBackEndUrl() + "/appmgt/site/pages/index.jag";
    String loginHtmlPage;//from w  w w. j a v  a  2 s.  c o  m
    String commonAuthUrl;
    String responceHtml = null;
    HttpHandler httpHandler = new HttpHandler();
    try {
        loginHtmlPage = httpHandler.getHtml(webAppurl);
        Document html = Jsoup.parse(loginHtmlPage);
        Element samlRequestElement = html.select("input[name=SAMLRequest]").first();
        String samlRequest = samlRequestElement.val();
        Element relayStateElement = html.select("input[name=RelayState]").first();
        String relayState = relayStateElement.val();
        Element ssoAuthSessionIDElement = html.select("input[name=SSOAuthSessionID]").first();
        String ssoAuthSessionID = ssoAuthSessionIDElement.val();
        samlRequest = samlRequest.replace("+", "%2B");
        samlRequest = samlRequest.replace("=", "%3D");

        commonAuthUrl = httpHandler.getRedirectionUrl(ssoUrl + "?SAMLRequest=" + samlRequest + "&RelayState="
                + relayState + "&SSOAuthSessionID=" + ssoAuthSessionID);
        responceHtml = httpHandler.doPostHttps(commonAuthUrl, "username=" + userName + "&password=" + password,
                "none", "application/x-www-form-urlencoded");
        Document postHtml = Jsoup.parse(responceHtml);
        Element postHTMLResponse = postHtml.select("input[name=SAMLResponse]").first();
        String samlResponse = postHTMLResponse.val();
        String appmSamlSsoTokenId = httpHandler.doPostHttp(webAppurl,
                "SAMLResponse=" + URLEncoder.encode(samlResponse, "UTF-8"), "appmSamlSsoTokenId",
                "application/x-www-form-urlencoded; charset=UTF-8");
    } catch (Exception e) {
        final String msg = "Error occurred while retrieving SAML token ";
        log.error(msg, e);
        throw new AFIntegrationTestException(msg, e);
    }
}

From source file:socialtrade1.Engine.java

String byId(String s) {
    Element info = null;
    String returnstring = "";
    try {//from ww  w .  j a va  2s  .  c o  m
        doc = Jsoup.parse(response);
        info = doc.getElementById(s);
        returnstring = "" + info.val().replace("=", "%3D");
    } catch (Exception m) {
        //pp(m);
    }
    return returnstring;
}