Java URI Value Check isOnTrustedUriWhiteList(final URI uri)

Here you can find the source of isOnTrustedUriWhiteList(final URI uri)

Description

Evaluates supplied address against a list of supported internet protocols allowed for use on hyperlinks.

License

Open Source License

Parameter

Parameter Description
uri The URL to test.

Return

Returns true for allowed protocols.

Declaration

public static boolean isOnTrustedUriWhiteList(final URI uri) 

Method Source Code


//package com.java2s;
// Licensed under the MIT license. See License.txt in the repository root.

import java.net.URI;

public class Main {
    private static final String[] URI_SCHEME_WHITELIST = new String[] { "http", //$NON-NLS-1$
            "https", //$NON-NLS-1$
            "ftp", //$NON-NLS-1$
            "gopher", //$NON-NLS-1$
            "mailto", //$NON-NLS-1$
            "news", //$NON-NLS-1$
            "telnet", //$NON-NLS-1$
            "wais", //$NON-NLS-1$
            "vstfs", //$NON-NLS-1$
            "tfs", //$NON-NLS-1$
            "alm", //$NON-NLS-1$
            "mtm", //$NON-NLS-1$
            "mtms", //$NON-NLS-1$
            "mfbclient", //$NON-NLS-1$
            "mfbclients", //$NON-NLS-1$
            "x-mvwit" //$NON-NLS-1$
    };//from ww  w  . j a va2  s  . com

    /**
     * Evaluates supplied address against a list of supported internet protocols
     * allowed for use on hyperlinks.
     *
     *
     * @param uri
     *        The URL to test.
     * @return Returns true for allowed protocols.
     */
    public static boolean isOnTrustedUriWhiteList(final URI uri) {
        if (uri == null || uri.getScheme() == null) {
            return false;
        }

        final String protocol = uri.getScheme().toLowerCase();
        for (final String allowedProtocol : URI_SCHEME_WHITELIST) {
            if (protocol.equalsIgnoreCase(allowedProtocol)) {
                return true;
            }
        }

        // Urls operating with an unrecognized protocol are rejected by default.
        return false;
    }
}

Related

  1. isLocalFile(URI uri)
  2. isLocalUri(String uriString)
  3. isLocalURI(URI uri)
  4. isModuleURI(URI uri)
  5. isNormalized(String uriName)
  6. isOriginForm(URI uri)
  7. isPrefix(final URI source, final URI other)
  8. isProjectCacheURI(java.net.URI uri)
  9. isRedirectEndpointUriValid(String redirectUri)