src/main/java/org/owasp/url/UrlValue.java
public static UrlValue from(UrlContext context, String originalUrlText) {
    String urlText = originalUrlText;
    switch (context.urlSource) {
      case HUMAN_READABLE_INPUT:
        if (urlText.indexOf(':') < 0) {
          String prefix = null;
          String suffix = null;
          String hostPortion = null;
          int at = urlText.indexOf('@');
          if (at >= 0) {
            prefix = "mailto:";
            suffix = "";
            hostPortion = urlText.substring(at + 1);
          } else {
            int slash = urlText.indexOf('/');
            prefix = "http://";
            hostPortion = slash >= 0 ? urlText.substring(0, slash) : urlText;
            suffix = slash < 0 ? "/" : "";
          }
          if (hostPortion != null) {
            InternetDomainName dname;
            try {
              dname = InternetDomainName.from(hostPortion);
            } catch (@SuppressWarnings("unused")
                     IllegalArgumentException ex) {
              dname = null;
            }
            if (dname != null && dname.hasPublicSuffix()) {
              urlText = prefix + urlText + suffix;
            }
          }
        }
        break;
      case MACHINE_READABLE_INPUT:
        break;
    }
    return new UrlValue(
        Preconditions.checkNotNull(context),
        Preconditions.checkNotNull(urlText));
  }
/**
   * @param context a context used to flesh out relative URLs.
   * @return a URL value with the given original text and whose
   *     urlText is an absolute URL.
   */
@param context a context used to flesh out relative URLs.
@return a URL value with the given original text and whose
urlText is an absolute URL.
@param context a context used to flesh out relative URLs . @return a URL value with the given original text and whose urlText is an absolute URL .
public static UrlValue from(UrlContext context, String originalUrlText) {
    String urlText = originalUrlText;
    switch (context.urlSource) {
      case HUMAN_READABLE_INPUT:
        if (urlText.indexOf(':') < 0) {
          String prefix = null;
          String suffix = null;
          String hostPortion = null;
          int at = urlText.indexOf('@');
          if (at >= 0) {
            prefix = "mailto:";
            suffix = "";
            hostPortion = urlText.substring(at + 1);
          } else {
            int slash = urlText.indexOf('/');
            prefix = "http://";
            hostPortion = slash >= 0 ? urlText.substring(0, slash) : urlText;
            suffix = slash < 0 ? "/" : "";
          }
          if (hostPortion != null) {
            InternetDomainName dname;
            try {
              dname = InternetDomainName.from(hostPortion);
            } catch (@SuppressWarnings("unused")
                     IllegalArgumentException ex) {
              dname = null;
            }
            if (dname != null && dname.hasPublicSuffix()) {
              urlText = prefix + urlText + suffix;
            }
          }
        }
        break;
      case MACHINE_READABLE_INPUT:
        break;
    }
    return new UrlValue(
        Preconditions.checkNotNull(context),
        Preconditions.checkNotNull(urlText));
  }
public static UrlValue from ( UrlContext context , String originalUrlText ) { String urlText = originalUrlText ; switch ( context . urlSource ) { case HUMAN_READABLE_INPUT : if ( urlText . indexOf ( ':' ) < 0 ) { String prefix = null ; String suffix = null ; String hostPortion = null ; int at = urlText . indexOf ( '@' ) ; if ( at >= 0 ) { prefix = "mailto:" ; suffix = "" ; hostPortion = urlText . substring ( at + 1 ) ; } else { int slash = urlText . indexOf ( '/' ) ; prefix = "http://" ; hostPortion = slash >= 0 ? urlText . substring ( 0 , slash ) : urlText ; suffix = slash < 0 ? "/" : "" ; } if ( hostPortion != null ) { InternetDomainName dname ; try { dname = InternetDomainName . from ( hostPortion ) ; } catch ( @ SuppressWarnings ( "unused" ) IllegalArgumentException ex ) { dname = null ; } if ( dname != null && dname . hasPublicSuffix ( ) ) { urlText = prefix + urlText + suffix ; } } } break ; case MACHINE_READABLE_INPUT : break ; } return new UrlValue ( Preconditions . checkNotNull ( context ) , Preconditions . checkNotNull ( urlText ) ) ; }
@param context a context used to flesh out relative URLs.
@param context a context used to flesh out relative URLs .