Returns the scheme prefix like "http" from the URL spec, or null if the
spec doesn't start with a scheme. Scheme prefixes match this pattern:
{@code alpha ( alpha | digit | '+' | '-' | '.' )* ':'}
492367
public static String getSchemePrefix(String spec) {
        int colon = spec.indexOf(':');

        if (colon < 1) {
            return null;
        }

        for (int i = 0; i < colon; i++) {
            char c = spec.charAt(i);
            if (!isValidSchemeChar(i, c)) {
                return null;
            }
        }

        return spec.substring(0, colon).toLowerCase(Locale.US);
    }
749351
private String getPrefix() {

        if (m_prefix == null) {
            m_prefix = OpenCms.getSystemInfo().getContextPath()
                + "/"
                + OpenCms.getStaticExportManager().getProtectedExportPath()
                + "/";
        }
        return m_prefix;
    }
1307538
public String urlDecode(String s) {
        if (s == null || s.isEmpty()) {
            return s;
        }
        return URL.decodeQueryString(s);
    }
167882
public String encodeURL(String relativePath, String scheme) {
		StringBuffer urlEncoded = new StringBuffer();
		//Context
		Context context = (Context)sipManager.getContainer();
		//Host
		Host host = (Host)context.getParent();
		//Service
		Service service = ((Engine)host.getParent()).getService();
		String[] aliases = host.findAliases();
		String hostname = null;
		
		// Needed for http://code.google.com/p/sipservlets/issues/detail?id=150
		// to pass TCK test com.bea.sipservlet.tck.agents.api.javax_servlet_sip.ConvergedHttpSessionTest.testEncodeURL002
		if(aliases.length < 1) {
			hostname = host.getName();
		} else {
			// FIXME would be better to try to match the alias by some path or IP but unaware if this is really needed at this point
			// or how it can be effectively done
			hostname = aliases[0];
		}
		
		//retrieving the port corresponding to the specified scheme
		//TODO ask EG what if the scheme is not supported on the server ?
		int port = -1;		
		Connector[] connectors = service.findConnectors();
		int i = 0;
		while (i < connectors.length && port < 0) {
			if(scheme != null && connectors[i].getProtocol().toLowerCase().contains(scheme.toLowerCase())) {
				port = connectors[i].getPort();
			}
			i++;
		}
		urlEncoded = urlEncoded.append(scheme);
		urlEncoded = urlEncoded.append("://");
		urlEncoded = urlEncoded.append(hostname);
		urlEncoded = urlEncoded.append(":");
		urlEncoded = urlEncoded.append(port);
		urlEncoded = urlEncoded.append(((Context)sipManager.getContainer()).getPath());
		urlEncoded = urlEncoded.append(encodeURL(relativePath));
		return urlEncoded.toString();
	}
802664
public boolean containsKeyPrefix(String prefix) {
        if (prefix == null) {
            throw new NullPointerException("Prefix key can not be null");
        }

        // An empty string is a prefix of everything
        if (prefix.equals("")) {
            return true;
        }

        // Find nearest node
        PatriciaNode<V> nearest = findNearestNode(prefix);

        // If no nearest node exist, there isn't any prefix match either
        if (nearest == null) {
            return false;
        }

        // The nearest is the root, so no match
        if (nearest.getKey() == null) {
            return false;
        }

        // Test prefix match
        return nearest.getKey().startsWith(prefix);
    }
462003
public static String getAbsoluteUrl(SlingHttpServletRequest request, String url) {
        if (!isExternalUrl(url) && url.startsWith("/")) {
            String scheme = request.getScheme().toLowerCase();
            url = scheme + "://" + getAuthority(request) + url;
        }
        return url;
    }
638611
private String convertURItoURL(String uri) {
        int indexScheme = uri.indexOf("://");
        if (-1 != indexScheme) {
            int indexQuery = uri.indexOf('?');
            if (-1 == indexQuery || indexScheme < indexQuery) {
                // already a full url
                return uri;
            }
        }
        StringBuilder sb = new StringBuilder();
        String scheme = this.request.getScheme();
        sb.append(scheme).append("://");
        sb.append(this.request.getServerName());
        int port = this.request.getServerPort();
        if ("http".equalsIgnoreCase(scheme) && 80 != port) {
            sb.append(':').append(port);
        } else if ("https".equalsIgnoreCase(scheme) && 443 != port) {
            sb.append(':').append(port);
        }
        String data = this.request.getContextPath();
        if (!"".equals(data)) {
            sb.append(data);
        }
        if (0 == uri.length()) {
            sb.append('/');
        } else if (uri.charAt(0) == '/') {
            // relative to servlet container root...
            sb.append(uri);
        } else {
            // relative to current URI,
            data = this.request.getServletPath();
            if (!"".equals(data)) {
                sb.append(data);
            }
            data = this.request.getPathInfo();
            if (null != data) {
                sb.append(data);
            }
            sb.append('/');
            sb.append(uri);
            // TODO: webcontainer converted "/./" and "/../" info too
        }

        return sb.toString();
    }
1170998
public List<String> prefixMatch(String prefix)
    {
        int curState = 1;
        IntArrayList bytes = new IntArrayList(prefix.length() * 4);
        for (int i = 0; i < prefix.length(); i++)
        {
            int codePoint = prefix.charAt(i);
            if (curState < 1)
            {
                return Collections.emptyList();
            }
            if ((curState != 1) && (isEmpty(curState)))
            {
                return Collections.emptyList();
            }
            int[] ids = this.charMap.toIdList(codePoint);
            if (ids.length == 0)
            {
                return Collections.emptyList();
            }
            for (int j = 0; j < ids.length; j++)
            {
                int c = ids[j];
                if ((getBase(curState) + c < getBaseArraySize())
                    && (getCheck(getBase(curState) + c) == curState))
                {
                    bytes.append(c);
                    curState = getBase(curState) + c;
                }
                else
                {
                    return Collections.emptyList();
                }
            }

        }
        List<String> result = new ArrayList<String>();
        recursiveAddSubTree(curState, result, bytes);

        return result;
    }
1091380
public String getParametersToString(String prefix) {
        final StringBuilder sb = new StringBuilder();
        getParameters().forEach((k, v) -> {
            if (sb.length() > 0) sb.append('&');
            try {
                sb.append(k).append('=').append(URLEncoder.encode(v, "UTF-8"));
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        });
        return (sb.length() > 0 && prefix != null) ? (prefix + sb) : sb.toString();
    }
19620
public UrlBuilder withScheme(String scheme) {
        if (scheme == null || scheme.isEmpty()) {
            this.scheme = null;
        } else {
            with(scheme, UrlTokenizerState.SCHEME);
        }
        return this;
    }
658200
public String getPrefix(String namespaceURI)
   {
      String prefix = null;
      try
      {
         prefix = namespaceRegistry.getPrefix(namespaceURI);
      }
      catch (NamespaceException exc)
      {
         prefix = prefixes.get(namespaceURI);
      }
      catch (RepositoryException exc)
      {
         log.error(exc.getMessage(), exc);
      }
      return prefix;

   }
573937
@Override
    public final String getNamespaceURI(String prefix)
    {
        /* First the known offenders; invalid args, 2 predefined xml namespace
         * prefixes
         */
        if (prefix == null) {
            throw new IllegalArgumentException(ErrorConsts.ERR_NULL_ARG);
        }
        if (prefix.length() > 0) {
            if (prefix.equals(XMLConstants.XML_NS_PREFIX)) {
                return XMLConstants.XML_NS_URI;
            }
            if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
                return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
            }
        }
        return doGetNamespaceURI(prefix);
    }
1159543
String requestName(String url) {
    String s = "."+toString();
    int i = url.indexOf(s);
    if( i== -1 ) return url;    // No, or default, type
    return url.substring(0,i)+url.substring(i+s.length());
  }
404407
public static String getUrlExtension(String url) {
        String extension = MimeTypeMap.getFileExtensionFromUrl(url);
        return TextUtils.isEmpty(extension) ? "" : extension;
    }
153468
static String urlencode(final String s) {
		try {
			return URLEncoder.encode(s, CHARSET_NAME);
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}
	}
911993
public static boolean validateUrl(String url) {
        String[] schemes = {"https"};
        UrlValidator urlValidator = new UrlValidator(schemes);
        return urlValidator.isValid(url);
    }
815331
@Override
    public String getNamespaceURI(String prefix){
        if(prefix==null)
            throw new IllegalArgumentException("prefix is null");

        return get(prefix);
    }