Example usage for android.net UrlQuerySanitizer getValue

List of usage examples for android.net UrlQuerySanitizer getValue

Introduction

In this page you can find the example usage for android.net UrlQuerySanitizer getValue.

Prototype

public String getValue(String parameter) 

Source Link

Document

Get the value for a parameter in the current sanitized query.

Usage

From source file:Main.java

static void paramLoader(WebView view, String url) {
    UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
    sanitizer.setAllowUnregisteredParamaters(true);
    sanitizer.parseUrl(url);//  w  w w  .  j  a  v a 2  s.  c  o  m
    String param = sanitizer.getValue("pageload");
    if (param != null) {
        switch (param) {
        case "composer":
            view.loadUrl(
                    "javascript:(function()%7Btry%7Bdocument.querySelector('button%5Bname%3D%22view_overview%22%5D').click()%7Dcatch(_)%7B%7D%7D)()");
            break;
        case "composer_photo":
            view.loadUrl(
                    "javascript:(function()%7Btry%7Bdocument.querySelector('button%5Bname%3D%22view_photo%22%5D').click()%7Dcatch(_)%7B%7D%7D)()");
            break;
        case "composer_checkin":
            view.loadUrl(
                    "javascript:(function()%7Btry%7Bdocument.querySelector('button%5Bname%3D%22view_location%22%5D').click()%7Dcatch(_)%7B%7D%7D)()");
            break;
        case "composer_top":
            view.scrollTo(0, 0);
            break;
        default:
            break;
        }
    }

}

From source file:Main.java

public static CharSequence parseHttpUri(String query, UrlQuerySanitizer sanitizer,
        ValueSanitizer valueSanitizer) {
    sanitizer.registerParameters(geocachingQueryParam, valueSanitizer);
    sanitizer.parseQuery(query);/*  w  w  w  . j  ava 2 s . com*/
    return sanitizer.getValue("q");
}

From source file:com.playhaven.android.data.Purchase.java

public static ArrayList<Purchase> fromJson(String json) {
    if (json == null)
        return new ArrayList<Purchase>(0);

    String url = JsonUtil.getPath(json, "$.url");
    UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(url);
    final String placementTag = sanitizer.getValue("placement_tag");

    ArrayList<Purchase> toReturn = new ArrayList<Purchase>();
    for (String jsonPurchase : JsonUtil.forEach(json, "$.purchases"))
        toReturn.add(new Purchase(jsonPurchase, placementTag));

    return toReturn;
}

From source file:eu.masconsult.bgbanking.banks.sgexpress.SGExpressClient.java

private void checkAuthError(UrlQuerySanitizer sanitizer) throws AuthenticationException {
    String loginReasonId = sanitizer.getValue("strLoginReason");
    if (loginReasonId == null) {
        throw new ParseException("Unknown reason for bad auth");
    }/*from  w  ww .  j a va  2  s. c  o m*/
    throw new AuthenticationException("Bad auth because of " + loginReasonId);
}

From source file:eu.masconsult.bgbanking.banks.dskbank.DskClient.java

@Override
public String authenticate(String username, String password)
        throws IOException, ParseException, CaptchaException {
    final HttpResponse resp;
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, username));
    params.add(new BasicNameValuePair(PARAM_PASSWORD, password));
    final HttpEntity entity;
    try {//  w  w  w. j  a v a 2  s  . c  om
        entity = new UrlEncodedFormEntity(params);
    } catch (final UnsupportedEncodingException e) {
        // this should never happen.
        throw new IllegalStateException(e);
    }
    String uri = BASE_URL + "?"
            + URLEncodedUtils.format(Arrays.asList(new BasicNameValuePair(XML_ID, AUTH_XML_ID)), ENCODING);
    Log.i(TAG, "Authenticating to: " + uri);
    final HttpPost post = new HttpPost(uri);
    post.addHeader(entity.getContentType());
    post.setHeader("Accept", "*/*");
    post.setEntity(entity);
    try {
        resp = getHttpClient().execute(post);

        if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new ParseException("login: unhandled http status " + resp.getStatusLine().getStatusCode()
                    + " " + resp.getStatusLine().getReasonPhrase());
        }

        String response = EntityUtils.toString(resp.getEntity());
        Log.v(TAG, "response = " + response);

        Document doc = Jsoup.parse(response, BASE_URL);
        Element mainForm = doc.getElementById("mainForm");
        if (mainForm == null) {
            throw new ParseException("login: missing mainForm");
        }

        String action = BASE_URL + mainForm.attr("action");
        Log.v(TAG, "action=" + action);
        UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(action);
        String user_id = sanitizer.getValue(PARAM_USER_ID);
        String session_id = sanitizer.getValue(PARAM_SESSION_ID);

        if (user_id == null || "".equals(user_id) || session_id == null || "".equals(session_id)) {
            if (doc.getElementsByClass("redtext").size() > 0) {
                // bad authentication
                return null;
            } else {
                // TODO handle captcha
                Elements captcha = doc.select("input[name=captcha_hkey]");
                if (captcha != null && captcha.size() == 1) {
                    String captchaHash = captcha.first().attr("value");
                    String captchaUri = BASE_URL + "?"
                            + URLEncodedUtils
                                    .format(Arrays.asList(new BasicNameValuePair(XML_ID, CAPTCHA_XML_ID),
                                            new BasicNameValuePair("captcha_key", captchaHash)), ENCODING);
                    throw new CaptchaException(captchaUri);
                }
                throw new ParseException("no user_id or session_id: " + action);
            }
        }

        return URLEncodedUtils.format(Arrays.asList(new BasicNameValuePair(PARAM_USER_ID, user_id),
                new BasicNameValuePair(PARAM_SESSION_ID, session_id)), ENCODING);
    } catch (ClientProtocolException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:eu.masconsult.bgbanking.banks.sgexpress.SGExpressClient.java

private void performAuthentication(DefaultHttpClient httpClient, AuthToken authToken)
        throws IOException, AuthenticationException {
    HttpResponse resp;/* w ww .j a v a2s  . c om*/
    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair(PARAM_USERNAME, authToken.username));
    params.add(new BasicNameValuePair(PARAM_PASSWORD, authToken.password));
    params.add(new BasicNameValuePair(PARAM_USER_TIME, "dummy"));
    final HttpEntity entity;
    try {
        entity = new UrlEncodedFormEntity(params);
    } catch (final UnsupportedEncodingException e) {
        // this should never happen.
        throw new IllegalStateException(e);
    }
    String uri = BASE_URL + "?"
            + URLEncodedUtils.format(Arrays.asList(new BasicNameValuePair(XML_ID, AUTH_XML_ID)), ENCODING);
    Log.i(TAG, "Authenticating to: " + uri);

    final HttpPost post = new HttpPost(uri);
    post.addHeader(entity.getContentType());
    post.setHeader("Accept", "*/*");
    post.setEntity(entity);
    resp = httpClient.execute(post);

    // check for bad status
    if (resp.getStatusLine().getStatusCode() != HttpStatus.SC_MOVED_TEMPORARILY) {
        throw new ParseException("status after auth: " + resp.getStatusLine().getStatusCode() + " "
                + resp.getStatusLine().getReasonPhrase());
    }

    // check header redirect
    Header[] locations = resp.getHeaders(HEADER_LOCATION);
    if (locations.length != 1) {
        throw new ParseException(locations.length + " header locations received!");
    }

    String location = "https://" + DOMAIN + locations[0].getValue();
    Log.v(TAG, "location=" + location);

    UrlQuerySanitizer sanitizer = new UrlQuerySanitizer(location);
    authToken.userId = sanitizer.getValue(PARAM_USER_ID);
    authToken.sessionId = sanitizer.getValue(PARAM_SESSION_ID);
    String redirectedXmlId = sanitizer.getValue(XML_ID);

    if (authToken.userId == null || authToken.userId.length() == 0 || authToken.sessionId == null
            || authToken.sessionId.length() == 0 || AUTH_XML_ID.equalsIgnoreCase(redirectedXmlId)) {
        checkAuthError(sanitizer);
    }
}