android.net.UrlQuerySanitizer Java Examples

The following examples show how to use android.net.UrlQuerySanitizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UriHelper.java    From clevertap-android-sdk with MIT License 6 votes vote down vote up
static Bundle getAllKeyValuePairs(String url, boolean encodeValues) {
    if (url == null) return new Bundle();
    Bundle customPairs = new Bundle();
    try {
        UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
        sanitizer.setAllowUnregisteredParamaters(true);
        sanitizer.setUnregisteredParameterValueSanitizer(UrlQuerySanitizer.getAllButNulLegal());
        sanitizer.parseUrl(url);
        Set<String> queryParams = sanitizer.getParameterSet();
        for (String key : queryParams) {
            String value = getValueForKey(key, sanitizer, false);
            if (value != null) {
                // Don't encode wzrk_c2a - as the URL must be preserved
                if (encodeValues || key.equals("wzrk_c2a")) {
                    // Already encoded
                    customPairs.putString(key, value);
                } else {
                    customPairs.putString(key, URLDecoder.decode(value, "UTF-8"));
                }
            }
        }
    } catch (Throwable ignore) {
        // Won't happen
    }
    return customPairs;
}
 
Example #2
Source File: XulGIFAnimationDrawable.java    From starcor.xul with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static XulDrawable buildAnimation(InputStream stream, String url, String imageKey) {
	if (stream == null) {
		return null;
	}

	UrlQuerySanitizer s = new UrlQuerySanitizer(url);
	boolean noLoop = s.hasParameter("NoLoop");
	boolean noTransparent = s.hasParameter("noTransparent");
	float speed = XulUtils.tryParseFloat(s.getValue("Speed"), 1.0f);
	if (speed <= 0) {
		speed = 0.01f;
	}

	XulGIFDecoder.GIFFrame[] frames = XulGIFDecoder.decode(stream, noLoop, noTransparent);
	if (frames == null) {
		Log.e(TAG, "GIF decode failed! " + stream + " URL:" + url);
		return null;
	}

	if (frames.length == 1) {
		XulGIFDecoder.GIFStaticRender staticRenderer = XulGIFDecoder.createStaticRenderer(frames, noTransparent);
		return staticRenderer.extractDrawable(url, imageKey);
	} else {

		XulGIFAnimationDrawable drawable = new XulGIFAnimationDrawable();
		drawable._gifRender = XulGIFDecoder.createAnimationRenderer(frames, noLoop, noTransparent);
		drawable._url = url;
		drawable._key = imageKey;
		drawable._speed = speed;
		return drawable;
	}
}
 
Example #3
Source File: UnionsActivity.java    From talk-android with MIT License 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
private void initWebView() {
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.startsWith(ApiConfig.REDIRECT_URI)) {
                List<UrlQuerySanitizer.ParameterValuePair> pvpList = new UrlQuerySanitizer(url)
                        .getParameterList();
                for (UrlQuerySanitizer.ParameterValuePair pvp : pvpList) {
                    if ("code".equals(pvp.mParameter)) {
                        Intent data = new Intent();
                        data.putExtra(CODE, pvp.mValue);
                        setResult(RESULT_OK, data);
                        finish();
                        break;
                    }
                }
            } else {
                webView.loadUrl(url);
            }
            return true;
        }
    });

    webView.loadUrl(url);
}
 
Example #4
Source File: UriHelper.java    From clevertap-android-sdk with MIT License 5 votes vote down vote up
static JSONObject getUrchinFromUri(Uri uri) {
    JSONObject referrer = new JSONObject();
    try {

        UrlQuerySanitizer sanitizer = new UrlQuerySanitizer();
        sanitizer.setAllowUnregisteredParamaters(true);
        sanitizer.parseUrl(uri.toString());

        // Don't care for null values - they won't be added anyway
        String source = getUtmOrWzrkValue("source", sanitizer);
        String medium = getUtmOrWzrkValue("medium", sanitizer);
        String campaign = getUtmOrWzrkValue("campaign", sanitizer);

        referrer.put("us", source);
        referrer.put("um", medium);
        referrer.put("uc", campaign);

        String wm = getWzrkValueForKey("medium", sanitizer);
        if (wm != null && wm.matches("^email$|^social$|^search$"))
            referrer.put("wm", wm);

        Logger.d("Referrer data: " + referrer.toString(4));
    } catch (Throwable ignore) {
        // Won't happen
    }
    return referrer;
}
 
Example #5
Source File: UriHelper.java    From clevertap-android-sdk with MIT License 5 votes vote down vote up
private static String getUtmOrWzrkValue(String utmKey, UrlQuerySanitizer sanitizer) {
    // Give preference to utm_*, else, try to look for wzrk_*
    String value;
    if ((value = getUtmValueForKey(utmKey, sanitizer)) != null
            || (value = getWzrkValueForKey(utmKey, sanitizer)) != null)
        return value;
    else
        return null;
}
 
Example #6
Source File: UriHelper.java    From clevertap-android-sdk with MIT License 5 votes vote down vote up
private static String getValueForKey(String key, UrlQuerySanitizer sanitizer, boolean truncate) {
    if (key == null || sanitizer == null) return null;
    try {
        String value = sanitizer.getValue(key);

        if (value == null) return null;
        if (truncate && value.length() > Constants.MAX_KEY_LENGTH)
            return value.substring(0, Constants.MAX_KEY_LENGTH);
        else
            return value;
    } catch (Throwable t) {
        Logger.v("Couldn't parse the URI", t);
        return null;
    }
}
 
Example #7
Source File: UriUtilTest.java    From AppAuth-Android with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() {
    mSanitizer = new UrlQuerySanitizer();
    mSanitizer.setAllowUnregisteredParamaters(true);
    mSanitizer.setUnregisteredParameterValueSanitizer(UrlQuerySanitizer.getUrlAndSpaceLegal());
}
 
Example #8
Source File: GhostAuth.java    From quill with MIT License 4 votes vote down vote up
@Nullable
public static String extractAuthCodeFromUrl(@NonNull String url) {
    return new UrlQuerySanitizer(url).getValue("code");
}
 
Example #9
Source File: UriHelper.java    From clevertap-android-sdk with MIT License 4 votes vote down vote up
private static String getWzrkValueForKey(String key, UrlQuerySanitizer sanitizer) {
    key = "wzrk_" + key;
    return getValueForKey(key, sanitizer, true);
}
 
Example #10
Source File: UriHelper.java    From clevertap-android-sdk with MIT License 4 votes vote down vote up
private static String getUtmValueForKey(String key, UrlQuerySanitizer sanitizer) {
    key = "utm_" + key;
    return getValueForKey(key, sanitizer, true);
}