Example usage for android.net Uri getEncodedQuery

List of usage examples for android.net Uri getEncodedQuery

Introduction

In this page you can find the example usage for android.net Uri getEncodedQuery.

Prototype

@Nullable
public abstract String getEncodedQuery();

Source Link

Document

Gets the encoded query component from this URI.

Usage

From source file:net.wequick.small.Bundle.java

protected static Bundle getLaunchableBundle(Uri uri) {
    if (sPreloadBundles != null) {
        for (Bundle bundle : sPreloadBundles) {
            if (bundle.matchesRule(uri)) {
                if (!bundle.enabled)
                    return null; // Illegal bundle (invalid signature, etc.)
                return bundle;
            }/*from  w ww . jav a 2 s  .  c o  m*/
        }
    }

    // Downgrade to show webView
    if (uri.getScheme() != null) {
        Bundle bundle = new Bundle();
        try {
            bundle.url = new URL(uri.toString());
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        bundle.prepareForLaunch();
        bundle.setQuery(uri.getEncodedQuery()); // Fix issue #6 from Spring-Xu.
        bundle.mApplicableLauncher = new WebBundleLauncher();
        bundle.mApplicableLauncher.prelaunchBundle(bundle);
        return bundle;
    }
    return null;
}

From source file:com.remobile.file.ContentFilesystem.java

@Override
public LocalFilesystemURL toLocalUri(Uri inputURL) {
    if (!"content".equals(inputURL.getScheme())) {
        return null;
    }/*from  ww  w  .  j  a  v a 2  s  . com*/
    String subPath = inputURL.getEncodedPath();
    if (subPath.length() > 0) {
        subPath = subPath.substring(1);
    }
    Uri.Builder b = new Uri.Builder().scheme(LocalFilesystemURL.FILESYSTEM_PROTOCOL).authority("localhost")
            .path(name).appendPath(inputURL.getAuthority());
    if (subPath.length() > 0) {
        b.appendEncodedPath(subPath);
    }
    Uri localUri = b.encodedQuery(inputURL.getEncodedQuery()).encodedFragment(inputURL.getEncodedFragment())
            .build();
    return LocalFilesystemURL.parse(localUri);
}

From source file:uk.bowdlerize.service.CensorCensusService.java

private CensorPayload checkURL(String checkURL) throws IllegalArgumentException, URISyntaxException {
    if (!checkURL.startsWith("http"))
        checkURL = "http://" + checkURL;

    CensorPayload censorPayload = new CensorPayload(checkURL);

    Uri mUri = Uri.parse(checkURL);

    if (null == mUri.getEncodedQuery()) {
        checkURL = mUri.getScheme() + "://" + mUri.getHost() + mUri.getPath();
    } else {/*www. ja v a2 s . co m*/
        checkURL = mUri.getScheme() + "://" + mUri.getHost() + mUri.getPath() + "?"
                + URLEncoder.encode(mUri.getEncodedQuery());
    }

    Log.e("Checking url", checkURL);

    client = new DefaultHttpClient();

    /*headRequest = new HttpHead(checkURL);
    headRequest.setHeader("User-Agent", "OONI Android Probe");*/

    httpGet = new HttpGet(checkURL);
    httpGet.setHeader("User-Agent", "OONI Android Probe");

    try {
        //response = client.execute(headRequest);
        client.addResponseInterceptor(new HttpResponseInterceptor() {
            @Override
            public void process(HttpResponse httpResponse, HttpContext httpContext)
                    throws HttpException, IOException {
                if (httpResponse.getStatusLine().getStatusCode() == 302
                        || httpResponse.getStatusLine().getStatusCode() == 301) {
                    for (Header hdr : httpResponse.getAllHeaders()) {
                        if (hdr.getName().equals("Location")) {
                            /*if (hdr.getValue().equals("http://ee-outage.s3.amazonaws.com/content-blocked/content-blocked-v1.html") ||
                            hdr.getValue().contains("http://ee-outage.s3.amazonaws.com"))
                            {
                            Log.e("Blocked", "Blocked by EE");
                            throw new CensoredException("Blocked by EE", "EE", 100);
                            }
                            else if (hdr.getValue().contains("http://www.t-mobile.co.uk/service/wnw-mig/entry/") ||
                                 hdr.getValue().contains("http://tmobile.ee.co.uk/common/system_error_pages/outage_wnw.html"))
                            {
                            Log.e("Blocked", "Blocked by TMobile");
                            throw new CensoredException("Blocked by TMobile", "TMobile", 100);
                            }
                            else if (hdr.getValue().contains("http://online.vodafone.co.uk/dispatch/Portal/ContentControlServlet?type=restricted"))
                            {
                            Log.e("Blocked", "Blocked by Vodafone");
                            throw new CensoredException("Blocked by Vodafone", "Vodafone", 100);
                            }
                            else if (hdr.getValue().contains("http://blockpage.bt.com/pcstaticpage/blocked.html"))
                            {
                            Log.e("Blocked", "Blocked by BT");
                            throw new CensoredException("Blocked by BT", "BT", 100);
                            }
                            else if (hdr.getValue().contains("http://www.talktalk.co.uk/notice/parental-controls?accessurl"))
                            {
                            Log.e("Blocked", "Blocked by TalkTalk");
                            throw new CensoredException("Blocked by TalkTalk", "TalkTalk", 100);
                            }
                            else if (hdr.getValue().contains("http://www.plus.net/support/security/abuse/blocked.shtml"))
                            {
                            Log.e("Blocked", "Blocked by PlusNet");
                            throw new CensoredException("Blocked by PlusNet", "PlusNet", 100);
                            }
                            else if (hdr.getValue().contains("http://mobile.three.co.uk/pc/Live/pcreator/live/100004/pin/blocked?"))
                            {
                            Log.e("Blocked", "Blocked by Three");
                            throw new CensoredException("Blocked by Three", "Three", 100);
                            }
                            else if (hdr.getValue().contains("http://m.virginmedia.com/MiscPages/AdultWarning.aspx"))
                            {
                            Log.e("Blocked", "Blocked by VirginMobile");
                            throw new CensoredException("Blocked by VirginMobile", "VirginMobile", 100);
                            }
                            else if (hdr.getValue().contains("http://assets.o2.co.uk/18plusaccess/"))
                            {
                            Log.e("Blocked", "Blocked by O2");
                            throw new CensoredException("Blocked by O2", "O2", 100);
                            }*/
                            api.checkHeader(hdr);
                        }
                    }
                }

                /*Log.e("intercepted return code",httpResponse.getStatusLine().toString());
                        
                for(Header hdr : httpResponse.getAllHeaders())
                {
                Log.e("intercepted header",hdr.getName().toString() + " / " + hdr.getValue().toString());
                }
                Log.e("intercepted header","------------------\r\n------------------\r\n------------------\r\n------------------\r\n------------------\r\n");*/

            }
        });
        response = client.execute(httpGet);
    }
    //This is the best case scenario!
    catch (CensoredException CE) {
        censorPayload.consumeCensoredException(CE);
        return censorPayload;
    } catch (UnknownHostException uhe) {
        uhe.printStackTrace();
        censorPayload.consumeError(uhe.getMessage());
        return censorPayload;
    } catch (ConnectTimeoutException CTE) {
        CTE.printStackTrace();
        censorPayload.consumeError(CTE.getMessage());
        return censorPayload;
    } catch (NoHttpResponseException NHRE) {
        NHRE.printStackTrace();
        censorPayload.consumeError(NHRE.getMessage());
        return censorPayload;
    } catch (IOException ioe) {
        ioe.printStackTrace();
        censorPayload.consumeError(ioe.getMessage());
        return censorPayload;
    } catch (IllegalStateException ise) {
        ise.printStackTrace();
        censorPayload.setCensored(false);
        censorPayload.setConfidence(0);
        return censorPayload;
    } catch (Exception e) {
        e.printStackTrace();
        censorPayload.setCensored(false);
        censorPayload.setConfidence(0);
        return censorPayload;
    }

    int statusCode = response.getStatusLine().getStatusCode();

    censorPayload.setReturnCode(statusCode);

    Log.e("checkURL code", Integer.toString(statusCode));
    if (statusCode == 403 || statusCode == 404) {
        censorPayload.setCensored(true);
        censorPayload.setConfidence(25);
        return censorPayload;
    } else if (statusCode == 504 || statusCode == 503 || statusCode == 500) {
        censorPayload.consumeError("Server Issue " + Integer.toString(statusCode));
        return censorPayload;
    }

    String phrase = response.getStatusLine().getReasonPhrase();

    Log.e("checkURL phrase", phrase);

    if (phrase.contains("orbidden")) {
        censorPayload.setCensored(true);
        censorPayload.setConfidence(50);
        return censorPayload;
    }

    if (phrase.contains("blocked")) {
        censorPayload.setCensored(true);
        censorPayload.setConfidence(100);
        return censorPayload;
    }

    for (Header hdr : response.getAllHeaders()) {
        Log.e("checkURL header", hdr.getName() + " / " + hdr.getValue());
    }

    censorPayload.setCensored(false);
    censorPayload.setConfidence(1);
    return censorPayload;
}

From source file:net.openid.appauthdemo.Configuration.java

@NonNull
Uri getRequiredConfigUri(String propName) throws InvalidConfigurationException {
    String uriStr = getRequiredConfigString(propName);
    Uri uri;
    try {//from  w ww. j a v  a 2  s.  co  m
        uri = Uri.parse(uriStr);
    } catch (Throwable ex) {
        throw new InvalidConfigurationException(propName + " could not be parsed", ex);
    }

    if (!uri.isHierarchical() || !uri.isAbsolute()) {
        throw new InvalidConfigurationException(propName + " must be hierarchical and absolute");
    }

    if (!TextUtils.isEmpty(uri.getEncodedUserInfo())) {
        throw new InvalidConfigurationException(propName + " must not have user info");
    }

    if (!TextUtils.isEmpty(uri.getEncodedQuery())) {
        throw new InvalidConfigurationException(propName + " must not have query parameters");
    }

    if (!TextUtils.isEmpty(uri.getEncodedFragment())) {
        throw new InvalidConfigurationException(propName + " must not have a fragment");
    }

    return uri;
}

From source file:org.mozilla.gecko.GeckoAppShell.java

static boolean openUriExternal(String aUriSpec, String aMimeType, String aPackageName, String aClassName,
        String aAction, String aTitle) {
    Intent intent = getIntentForActionString(aAction);
    if (aAction.equalsIgnoreCase(Intent.ACTION_SEND)) {
        Intent shareIntent = getIntentForActionString(aAction);
        shareIntent.putExtra(Intent.EXTRA_TEXT, aUriSpec);
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, aTitle);
        if (aMimeType != null && aMimeType.length() > 0)
            shareIntent.setType(aMimeType);
        intent = Intent.createChooser(shareIntent,
                GeckoApp.mAppContext.getResources().getString(R.string.share_title));
    } else if (aMimeType.length() > 0) {
        intent.setDataAndType(Uri.parse(aUriSpec), aMimeType);
    } else {/*from   www  .  ja va 2s .  com*/
        Uri uri = Uri.parse(aUriSpec);
        if ("sms".equals(uri.getScheme())) {
            // Have a apecial handling for the SMS, as the message body
            // is not extracted from the URI automatically
            final String query = uri.getEncodedQuery();
            if (query != null && query.length() > 0) {
                final String[] fields = query.split("&");
                boolean foundBody = false;
                String resultQuery = "";
                for (int i = 0; i < fields.length; i++) {
                    final String field = fields[i];
                    if (field.length() > 5 && "body=".equals(field.substring(0, 5))) {
                        final String body = Uri.decode(field.substring(5));
                        intent.putExtra("sms_body", body);
                        foundBody = true;
                    } else {
                        resultQuery = resultQuery.concat(resultQuery.length() > 0 ? "&" + field : field);
                    }
                }
                if (foundBody) {
                    // Put the query without the body field back into the URI
                    final String prefix = aUriSpec.substring(0, aUriSpec.indexOf('?'));
                    uri = Uri.parse(resultQuery.length() > 0 ? prefix + "?" + resultQuery : prefix);
                }
            }
        }
        intent.setData(uri);
    }
    if (aPackageName.length() > 0 && aClassName.length() > 0)
        intent.setClassName(aPackageName, aClassName);

    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    try {
        GeckoApp.mAppContext.startActivity(intent);
        return true;
    } catch (ActivityNotFoundException e) {
        return false;
    }
}