Java Code Examples for org.apache.oro.text.perl.Perl5Util#match()

The following examples show how to use org.apache.oro.text.perl.Perl5Util#match() . 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: ADMValidator.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Check if the authority contains a valid hostname without "."
 * characters and an optional port number
 * 
 * @param authority
 * @return <code>true</code> if the authority is valid
 */
private boolean isValidAuthorityHostNoDot(String authority) {
    Perl5Util authorityMatcher = new Perl5Util();
    if (authority != null
            && authorityMatcher.match(
                    "/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) {
        String hostIP = authorityMatcher.group(1);
        if (hostIP.indexOf('.') < 0) {
            // the hostname contains no dot, add domain validation to check invalid hostname like "g08fnstd110825-"
            DomainValidator domainValidator = DomainValidator.getInstance(true);
            if(!domainValidator.isValid(hostIP)) {
                return false;
            }
            String port = authorityMatcher.group(2);
            if (!isValidPort(port)) {
                return false;
            }
            String extra = authorityMatcher.group(3);
            return GenericValidator.isBlankOrNull(extra);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
Example 2
Source File: SpagoURLValidator.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
* Controls if the input string represents a valid path.
* 
* @param path The input string path
* @return True if the string represents a valid path, else false
* 
*/
protected boolean isValidPath(String path) {
      if (path == null) {
          return false;
      }

      Perl5Util pathMatcher = new Perl5Util();

      if (!pathMatcher.match(PATH_PATTERN, path)) {
          return false;
      }

      //if (path.endsWith("/")) {
      //    return false;
      //}

      int slash2Count = countToken("//", path);
      //if (this.options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) {
      //    return false;
      //}

      int slashCount = countToken("/", path);
      int dot2Count = countToken("..", path);
      if (dot2Count > 0) {
          if ((slashCount - slash2Count - 1) <= dot2Count) {
              return false;
          }
      }

      return true;
  }
 
Example 3
Source File: SpagoURLValidator.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
* Controls if the input string represents a valid path.
* 
* @param path The input string path
* @return True if the string represents a valid path, else false
* 
*/
protected boolean isValidPath(String path) {
      if (path == null) {
          return false;
      }

      Perl5Util pathMatcher = new Perl5Util();

      if (!pathMatcher.match(PATH_PATTERN, path)) {
          return false;
      }

      //if (path.endsWith("/")) {
      //    return false;
      //}

      int slash2Count = countToken("//", path);
      //if (this.options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) {
      //    return false;
      //}

      int slashCount = countToken("/", path);
      int dot2Count = countToken("..", path);
      if (dot2Count > 0) {
          if ((slashCount - slash2Count - 1) <= dot2Count) {
              return false;
          }
      }

      return true;
  }
 
Example 4
Source File: ADMValidator.java    From development with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the authority contains a hostname without top level domain
 * and an optional port number
 * 
 * @param authority
 * @return <code>true</code> if the authority is valid
 */
private boolean isValidAuthorityHostNoTld(String authority) {
    Perl5Util authorityMatcher = new Perl5Util();
    if (authority != null
            && authorityMatcher.match(
                    "/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) {
        String host = authorityMatcher.group(1);
        if (host.indexOf('.') > 0) {
            DomainValidator domainValidator = DomainValidator.getInstance();
            // Make the host have a valid TLD, so that the "no TLD" host can pass the domain validation.
            String patchedHost = host + ".com";
            if(!domainValidator.isValid(patchedHost)) {
                return false;
            }
            String port = authorityMatcher.group(2);
            if (!isValidPort(port)) {
                return false;
            }
            String extra = authorityMatcher.group(3);
            return GenericValidator.isBlankOrNull(extra);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
Example 5
Source File: ADMValidator.java    From development with Apache License 2.0 5 votes vote down vote up
private boolean isValidPort(String port) {
    if (port != null) {
        Perl5Util portMatcher = new Perl5Util();
        if (!portMatcher.match("/^:(\\d{1,5})$/", port))
            return false;
    }
    return true;
}
 
Example 6
Source File: SpagoURLValidator.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
    * Controls if a String at imput is a valid URL.
    * 
    * @param value The input string
    * 
    * @return True if the string is a valid URL, else false.
    */
public boolean isValid(String value) {
	if (value == null) {
           return false;
       }

       Perl5Util matchUrlPat = new Perl5Util();
       Perl5Util matchAsciiPat = new Perl5Util();

       if (!matchAsciiPat.match(LEGAL_ASCII_PATTERN, value)) {
           return false;
       }

       // Check the whole url address structure
       if (!matchUrlPat.match(URL_PATTERN, value)) {
           return false;
       }

       if (!isValidScheme(matchUrlPat.group(PARSE_URL_SCHEME))) {
           return false;
       }
       
       /*
       if (!isValidAuthority(matchUrlPat.group(PARSE_URL_AUTHORITY))) {
           return false;
       }
       */

       if (!isValidPath(matchUrlPat.group(PARSE_URL_PATH))) {
           return false;
       }

       if (!isValidQuery(matchUrlPat.group(PARSE_URL_QUERY))) {
           return false;
       }

       if (!isValidFragment(matchUrlPat.group(PARSE_URL_FRAGMENT))) {
           return false;
       }

       return true;
}
 
Example 7
Source File: SpagoURLValidator.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
    * Controls if a String at imput is a valid URL.
    * 
    * @param value The input string
    * 
    * @return True if the string is a valid URL, else false.
    */
public boolean isValid(String value) {
	if (value == null) {
           return false;
       }

       Perl5Util matchUrlPat = new Perl5Util();
       Perl5Util matchAsciiPat = new Perl5Util();

       if (!matchAsciiPat.match(LEGAL_ASCII_PATTERN, value)) {
           return false;
       }

       // Check the whole url address structure
       if (!matchUrlPat.match(URL_PATTERN, value)) {
           return false;
       }

       if (!isValidScheme(matchUrlPat.group(PARSE_URL_SCHEME))) {
           return false;
       }
       
       /*
       if (!isValidAuthority(matchUrlPat.group(PARSE_URL_AUTHORITY))) {
           return false;
       }
       */

       if (!isValidPath(matchUrlPat.group(PARSE_URL_PATH))) {
           return false;
       }

       if (!isValidQuery(matchUrlPat.group(PARSE_URL_QUERY))) {
           return false;
       }

       if (!isValidFragment(matchUrlPat.group(PARSE_URL_FRAGMENT))) {
           return false;
       }

       return true;
}