Java Code Examples for android.net.Uri#isOpaque()

The following examples show how to use android.net.Uri#isOpaque() . 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: CompatUri.java    From droidddle with Apache License 2.0 5 votes vote down vote up
public static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException(NOT_HIERARCHICAL);
    }

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}
 
Example 2
Source File: General.java    From RedReader with GNU General Public License v3.0 5 votes vote down vote up
public static Set<String> getUriQueryParameterNames(final Uri uri) {

		if(uri.isOpaque()) {
			throw new UnsupportedOperationException("This isn't a hierarchical URI.");
		}

		final String query = uri.getEncodedQuery();
		if(query == null) {
			return Collections.emptySet();
		}

		final Set<String> names = new LinkedHashSet<>();
		int pos = 0;
		while(pos < query.length()) {
			int next = query.indexOf('&', pos);
			int end = (next == -1) ? query.length() : next;

			int separator = query.indexOf('=', pos);
			if (separator > end || separator == -1) {
				separator = end;
			}

			String name = query.substring(pos, separator);
			names.add(Uri.decode(name));

			// Move start to end of name.
			pos = end + 1;
		}

		return Collections.unmodifiableSet(names);
	}
 
Example 3
Source File: CompatUri.java    From android-oauth-client with Apache License 2.0 5 votes vote down vote up
static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException(NOT_HIERARCHICAL);
    }

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}
 
Example 4
Source File: UriUtil.java    From android-lite-http with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a set of the unique names of all query parameters. Iterating
 * over the set will return the names in order of their first occurrence.
 *
 * @return a set of decoded names
 * @throws UnsupportedOperationException if this isn't a hierarchical URI
 */
public static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        return Collections.emptySet();
    }

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(name);
        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}
 
Example 5
Source File: UriUtils.java    From arca-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<String> getQueryParameterNames(final Uri uri) {
	if (uri.isOpaque()) {
		throw new UnsupportedOperationException("This isn't a hierarchical URI.");
	}

	final String query = uri.getEncodedQuery();
	if (query == null) {
		return Collections.emptySet();
	}

	final Set<String> names = new LinkedHashSet<String>();
	int start = 0;
	do {
		final int next = query.indexOf('&', start);
		final int end = (next == -1) ? query.length() : next;

		int separator = query.indexOf('=', start);
		if (separator > end || separator == -1) {
			separator = end;
		}

		final String name = query.substring(start, separator);
		names.add(Uri.decode(name));

		// Move start to end of name.
		start = end + 1;
	} while (start < query.length());

	return Collections.unmodifiableSet(names);
}
 
Example 6
Source File: CompatUri.java    From android-java-connect-rest-sample with MIT License 5 votes vote down vote up
/**
 * Returns a set of the unique names of all query parameters. Iterating
 * over the set will return the names in order of their first occurrence.
 * Extracted from Uri#getQueryParameterNames() API 22.
 *
 * @throws UnsupportedOperationException if this isn't a hierarchical URI
 * @see Uri#getQueryParameterNames()
 *
 * @return a set of decoded names
 */
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
public static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException(NOT_HIERARCHICAL);
    }

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}
 
Example 7
Source File: QchatSchemeActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
public static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException("This isn't a hierarchical URI.");
    }

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<String>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = next == -1 ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name.
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}
 
Example 8
Source File: OAuthManagerDialogFragment.java    From react-native-oauth with MIT License 5 votes vote down vote up
static boolean isCallbackUri(String uri, String callbackUrl) {
  Uri u = null;
  Uri r = null;
  try {
    u = Uri.parse(uri);
    r = Uri.parse(callbackUrl);
  } catch (NullPointerException e) {
    return false;
  }

  if (u == null || r == null) return false;

  boolean rOpaque = r.isOpaque();
  boolean uOpaque = u.isOpaque();
  if (uOpaque != rOpaque) return false;

  if (rOpaque) return TextUtils.equals(uri, callbackUrl);
  if (!TextUtils.equals(r.getScheme(), u.getScheme())) return false;
  if (u.getPort() != r.getPort()) return false;
  if (!TextUtils.isEmpty(r.getPath()) && !TextUtils.equals(r.getPath(), u.getPath())) return false;

  Set<String> paramKeys = r.getQueryParameterNames();
  for (String key : paramKeys) {
    if (!TextUtils.equals(r.getQueryParameter(key), u.getQueryParameter(key))) return false;
  }

  String frag = r.getFragment();
  if (!TextUtils.isEmpty(frag) && !TextUtils.equals(frag, u.getFragment())) return false;
  return true;
}
 
Example 9
Source File: DomainRule.java    From Rabbits with Apache License 2.0 5 votes vote down vote up
@Override
public boolean verify(Uri uri) {
    if (uri.isOpaque()) {
        return false;
    }
    return verify(uri.getAuthority());
}
 
Example 10
Source File: QueryRule.java    From Rabbits with Apache License 2.0 5 votes vote down vote up
@Override
public boolean verify(Uri uri) {
    if (uri.isOpaque()) {
        return false;
    }
    String q = uri.getQueryParameter(mKey);
    return super.verify(q);
}
 
Example 11
Source File: PathRule.java    From Rabbits with Apache License 2.0 5 votes vote down vote up
@Override
public boolean verify(Uri uri) {
    if (uri.isOpaque()) {
        return false;
    }
    return verify(uri.getPath());
}
 
Example 12
Source File: CompatUri.java    From mirror with Apache License 2.0 5 votes vote down vote up
static Set<String> getQueryParameterNames(Uri uri) {
    if (uri.isOpaque()) {
        throw new UnsupportedOperationException(NOT_HIERARCHICAL);
    }

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptySet();
    }

    Set<String> names = new LinkedHashSet<>();
    int start = 0;
    do {
        int next = query.indexOf('&', start);
        int end = (next == -1) ? query.length() : next;

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        String name = query.substring(start, separator);
        names.add(Uri.decode(name));

        // Move start to end of name
        start = end + 1;
    } while (start < query.length());

    return Collections.unmodifiableSet(names);
}
 
Example 13
Source File: DribbbleLogin.java    From droidddle with Apache License 2.0 4 votes vote down vote up
static boolean isRedirectUriFound(String uri, String redirectUri) {
    Uri u = null;
    Uri r = null;
    try {
        u = Uri.parse(uri);
        r = Uri.parse(redirectUri);
    } catch (NullPointerException e) {
        return false;
    }
    if (u == null || r == null) {
        return false;
    }
    boolean rOpaque = r.isOpaque();
    boolean uOpaque = u.isOpaque();
    if (rOpaque != uOpaque) {
        return false;
    }
    if (rOpaque) {
        return TextUtils.equals(uri, redirectUri);
    }
    if (!TextUtils.equals(r.getScheme(), u.getScheme())) {
        return false;
    }
    if (!TextUtils.equals(r.getAuthority(), u.getAuthority())) {
        return false;
    }
    if (r.getPort() != u.getPort()) {
        return false;
    }
    if (!TextUtils.isEmpty(r.getPath()) && !TextUtils.equals(r.getPath(), u.getPath())) {
        return false;
    }
    Set<String> paramKeys = CompatUri.getQueryParameterNames(r);
    for (String key : paramKeys) {
        if (!TextUtils.equals(r.getQueryParameter(key), u.getQueryParameter(key))) {
            return false;
        }
    }
    String frag = r.getFragment();
    if (!TextUtils.isEmpty(frag) && !TextUtils.equals(frag, u.getFragment())) {
        return false;
    }
    return true;
}
 
Example 14
Source File: OAuthDialogFragment.java    From mirror with Apache License 2.0 4 votes vote down vote up
static boolean isRedirectUriFound(String uri, String redirectUri) {
    Uri u;
    Uri r;
    try {
        u = Uri.parse(uri);
        r = Uri.parse(redirectUri);
    } catch (NullPointerException e) {
        return false;
    }
    if (u == null || r == null) {
        return false;
    }
    boolean rOpaque = r.isOpaque();
    boolean uOpaque = u.isOpaque();
    if (rOpaque != uOpaque) {
        return false;
    }
    if (rOpaque) {
        return TextUtils.equals(uri, redirectUri);
    }
    if (!TextUtils.equals(r.getScheme(), u.getScheme())) {
        return false;
    }
    if (!TextUtils.equals(r.getAuthority(), u.getAuthority())) {
        return false;
    }
    if (r.getPort() != u.getPort()) {
        return false;
    }
    if (!TextUtils.isEmpty(r.getPath()) && !TextUtils.equals(r.getPath(), u.getPath())) {
        return false;
    }
    Set<String> paramKeys = CompatUri.getQueryParameterNames(r);
    for (String key : paramKeys) {
        if (!TextUtils.equals(r.getQueryParameter(key), u.getQueryParameter(key))) {
            return false;
        }
    }
    String frag = r.getFragment();
    return !(!TextUtils.isEmpty(frag) && !TextUtils.equals(frag, u.getFragment()));
}
 
Example 15
Source File: UriUtil.java    From android-lite-http with Apache License 2.0 4 votes vote down vote up
/**
 * Searches the query string for parameter values with the given key.
 *
 * @param key which will be encoded
 * @return a list of decoded values
 * @throws UnsupportedOperationException if this isn't a hierarchical URI
 * @throws NullPointerException          if key is null
 */
public static List<String> getQueryParameters(Uri uri, String key) {
    if (uri.isOpaque()) {
        return Collections.emptyList();
    }
    if (key == null) {
        throw new NullPointerException("key");
    }

    String query = uri.getEncodedQuery();
    if (query == null) {
        return Collections.emptyList();
    }

    ArrayList<String> values = new ArrayList<String>();

    int start = 0;
    do {
        int nextAmpersand = query.indexOf('&', start);
        int end = nextAmpersand != -1 ? nextAmpersand : query.length();

        int separator = query.indexOf('=', start);
        if (separator > end || separator == -1) {
            separator = end;
        }

        if (separator - start == key.length()
                && query.regionMatches(start, key, 0, key.length())) {
            if (separator == end) {
                values.add("");
            } else {
                values.add(query.substring(separator + 1, end));
            }
        }

        // Move start to end of name.
        if (nextAmpersand != -1) {
            start = nextAmpersand + 1;
        } else {
            break;
        }
    } while (true);

    return Collections.unmodifiableList(values);
}
 
Example 16
Source File: OAuthDialogFragment.java    From android-oauth-client with Apache License 2.0 4 votes vote down vote up
static boolean isRedirectUriFound(String uri, String redirectUri) {
    Uri u = null;
    Uri r = null;
    try {
        u = Uri.parse(uri);
        r = Uri.parse(redirectUri);
    } catch (NullPointerException e) {
        return false;
    }
    if (u == null || r == null) {
        return false;
    }
    boolean rOpaque = r.isOpaque();
    boolean uOpaque = u.isOpaque();
    if (rOpaque != uOpaque) {
        return false;
    }
    if (rOpaque) {
        return TextUtils.equals(uri, redirectUri);
    }
    if (!TextUtils.equals(r.getScheme(), u.getScheme())) {
        return false;
    }
    if (!TextUtils.equals(r.getAuthority(), u.getAuthority())) {
        return false;
    }
    if (r.getPort() != u.getPort()) {
        return false;
    }
    if (!TextUtils.isEmpty(r.getPath()) && !TextUtils.equals(r.getPath(), u.getPath())) {
        return false;
    }
    Set<String> paramKeys = CompatUri.getQueryParameterNames(r);
    for (String key : paramKeys) {
        if (!TextUtils.equals(r.getQueryParameter(key), u.getQueryParameter(key))) {
            return false;
        }
    }
    String frag = r.getFragment();
    if (!TextUtils.isEmpty(frag)
            && !TextUtils.equals(frag, u.getFragment())) {
        return false;
    }
    return true;
}
 
Example 17
Source File: X5WebUtils.java    From YCWebView with Apache License 2.0 4 votes vote down vote up
@Nullable
private static String getKdtUnionUrl(@NonNull Uri uri) {
    return uri.isOpaque() ? null : uri.getQueryParameter("redirect_uri");
}