org.apache.oro.text.regex.MalformedPatternException Java Examples

The following examples show how to use org.apache.oro.text.regex.MalformedPatternException. 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: SSHShell.java    From azure-libraries-for-java with MIT License 7 votes vote down vote up
/**
 * Creates SSHShell.
 *
 * @param host the host name
 * @param port the ssh port
 * @param userName the ssh user name
 * @param password the ssh password
 * @return the shell
 * @throws JSchException
 * @throws IOException
 */
private SSHShell(String host, int port, String userName, String password)
        throws JSchException, IOException {
    Closure expectClosure = getExpectClosure();
    for (String linuxPromptPattern : new String[]{"\\>", "#", "~#", "~\\$"}) {
        try {
            Match match = new RegExpMatch(linuxPromptPattern, expectClosure);
            linuxPromptMatches.add(match);
        } catch (MalformedPatternException malformedEx) {
            throw new RuntimeException(malformedEx);
        }
    }
    JSch jsch = new JSch();
    this.session = jsch.getSession(userName, host, port);
    session.setPassword(password);
    Hashtable<String, String> config = new Hashtable<>();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect(60000);
    this.channel = (ChannelShell) session.openChannel("shell");
    this.expect = new Expect4j(channel.getInputStream(), channel.getOutputStream());
    channel.connect();
}
 
Example #2
Source File: ListChooseByNameModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private Pattern getTaskPattern(String pattern) {
  if (!Comparing.strEqual(pattern, myPattern)) {
    myCompiledPattern = null;
    myPattern = pattern;
  }
  if (myCompiledPattern == null) {
    final String regex = "^.*" + NameUtil.buildRegexp(pattern, 0, true, true);

    final Perl5Compiler compiler = new Perl5Compiler();
    try {
      myCompiledPattern = compiler.compile(regex);
    }
    catch (MalformedPatternException ignored) {
    }
  }
  return myCompiledPattern;
}
 
Example #3
Source File: SshShell.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
/**
 * Creates SSHShell.
 *
 * @param host the host name
 * @param port the ssh port
 * @param userName the ssh user name
 * @param password the ssh password
 * @return the shell
 * @throws JSchException
 * @throws IOException
 */
private SshShell(String host, int port, String userName, String password)
        throws JSchException, IOException {
    Closure expectClosure = getExpectClosure();
    for (String linuxPromptPattern : new String[]{"\\>","#", "~#", "~\\$"}) {
        try {
            Match match = new RegExpMatch(linuxPromptPattern, expectClosure);
            linuxPromptMatches.add(match);
        } catch (MalformedPatternException malformedEx) {
            throw new RuntimeException(malformedEx);
        }
    }
    JSch jsch = new JSch();
    this.session = jsch.getSession(userName, host, port);
    session.setPassword(password);
    Hashtable<String,String> config = new Hashtable<>();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.connect(60000);
    this.channel = (ChannelShell) session.openChannel("shell");
    this.expect = new Expect4j(channel.getInputStream(), channel.getOutputStream());
    channel.connect();
}
 
Example #4
Source File: SSHShell.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
/**
 * Creates SSHShell.
 *
 * @param host the host name
 * @param port the ssh port
 * @param userName the ssh user name
 * @param sshPrivateKey the ssh password
 * @return the shell
 * @throws JSchException
 * @throws IOException
 */
private SSHShell(String host, int port, String userName, byte[] sshPrivateKey)
    throws JSchException, IOException {
    Closure expectClosure = getExpectClosure();
    for (String linuxPromptPattern : new String[]{"\\>", "#", "~#", "~\\$"}) {
        try {
            Match match = new RegExpMatch(linuxPromptPattern, expectClosure);
            linuxPromptMatches.add(match);
        } catch (MalformedPatternException malformedEx) {
            throw new RuntimeException(malformedEx);
        }
    }
    JSch jsch = new JSch();
    jsch.setKnownHosts(System.getProperty("user.home") + "/.ssh/known_hosts");
    jsch.addIdentity(host, sshPrivateKey, (byte[]) null, (byte[]) null);
    this.session = jsch.getSession(userName, host, port);
    this.session.setConfig("StrictHostKeyChecking", "no");
    this.session.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password");
    session.connect(60000);
    this.channel = (ChannelShell) session.openChannel("shell");
    this.expect = new Expect4j(channel.getInputStream(), channel.getOutputStream());
    channel.connect();
}
 
Example #5
Source File: EntityComparisonOperator.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
public static Pattern makeOroPattern(String sqlLike) {
    Perl5Util perl5Util = new Perl5Util();
    try {
        sqlLike = perl5Util.substitute("s/([$^.+*?])/\\\\$1/g", sqlLike);
        sqlLike = perl5Util.substitute("s/%/.*/g", sqlLike);
        sqlLike = perl5Util.substitute("s/_/./g", sqlLike);
    } catch (Throwable t) {
        String errMsg = "Error in ORO pattern substitution for SQL like clause [" + sqlLike + "]: " + t.toString();
        Debug.logError(t, errMsg, module);
        throw new IllegalArgumentException(errMsg);
    }
    try {
        return PatternFactory.createOrGetPerl5CompiledPattern(sqlLike, true);
    } catch (MalformedPatternException e) {
        Debug.logError(e, module);
    }
    return null;
}
 
Example #6
Source File: PatternFactory.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
/**
 * Compiles and caches a Perl5 regexp pattern for the given string pattern.
 * This would be of no benefits (and may bloat memory usage) if stringPattern is never the same.
 * @param stringPattern a Perl5 pattern string
 * @param caseSensitive case sensitive true/false
 * @return a <code>Pattern</code> instance for the given string pattern
 * @throws MalformedPatternException
 */

public static Pattern createOrGetPerl5CompiledPattern(String stringPattern, boolean caseSensitive) throws MalformedPatternException {
    Pattern pattern = compiledPerl5Patterns.get(stringPattern);
    if (pattern == null) {
        Perl5Compiler compiler = new Perl5Compiler();
        if (caseSensitive) {
            pattern = compiler.compile(stringPattern, Perl5Compiler.READ_ONLY_MASK); // READ_ONLY_MASK guarantees immutability
        } else {
            pattern = compiler.compile(stringPattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
        }
        pattern = compiledPerl5Patterns.putIfAbsentAndGet(stringPattern, pattern);
        if (Debug.verboseOn()) {
            Debug.logVerbose("Compiled and cached the pattern: '" + stringPattern, module);
        }
    }
    return pattern;
}
 
Example #7
Source File: ValidatorUtil.java    From webcurator with Apache License 2.0 6 votes vote down vote up
/**
 * Helper method to validate the specified string does not contain anything other than
 * that specified by the regular expression
 * @param aErrors The errors object to populate
 * @param aValue the string to check
 * @param aRegEx the Perl based regular expression to check the value against
 * @param aErrorCode the error code for getting the i8n failure message
 * @param aValues the list of values to replace in the i8n messages
 * @param aFailureMessage the default error message
 */
public static void validateRegEx(Errors aErrors, String aValue, String aRegEx, String aErrorCode, Object[] aValues, String aFailureMessage) {
    if (aValue != null && aRegEx != null && !aRegEx.equals("") && !aValue.trim().equals("")) {
        Perl5Compiler ptrnCompiler = new Perl5Compiler();
        Perl5Matcher matcher = new Perl5Matcher();
        try {
            Perl5Pattern aCharPattern = (Perl5Pattern) ptrnCompiler.compile(aRegEx);
                            
            if (!matcher.contains(aValue, aCharPattern)) {
                aErrors.reject(aErrorCode, aValues, aFailureMessage);               
                return;
            }
        }
        catch (MalformedPatternException e) {
            LogFactory.getLog(ValidatorUtil.class).fatal("Perl pattern malformed: pattern used was "+aRegEx +" : "+ e.getMessage(), e);
        }           
    }
}
 
Example #8
Source File: cfPARAM.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isCreditCard( String _cc ) throws MalformedPatternException{
// firstly check the number only contains numerics and separator chars
if ( !validateRE( "[0-9 \\.-]+", _cc ) ){
	return false;
}

// now create string with just the digits contained
char[] ccChars = _cc.toCharArray();
StringBuilder numerics = new StringBuilder();
for ( int i = 0; i < ccChars.length; i++ ){
	if ( ccChars[i] >= '0' && ccChars[i] <= '9' ){
		numerics.append( ccChars[i] );
	}
}
return checkLuhn( numerics.toString() );

}
 
Example #9
Source File: reReplace.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
protected String doRereplace( String _theString, String _theRE, String _theSubstr, boolean _casesensitive, boolean _replaceAll ) throws cfmRunTimeException{
	int replaceCount = _replaceAll ? Util.SUBSTITUTE_ALL : 1; 
	PatternMatcher matcher = new Perl5Matcher();
	Pattern pattern = null;
	PatternCompiler compiler = new Perl5Compiler();
   
	try {
		if ( _casesensitive ){
			pattern = compiler.compile( _theRE, Perl5Compiler.SINGLELINE_MASK );
		}else{
			pattern = compiler.compile( _theRE, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.SINGLELINE_MASK );
		}
		
	} catch(MalformedPatternException e){ // definitely should happen since regexp is hardcoded
		cfCatchData catchD = new cfCatchData();
		catchD.setType( "Function" );
		catchD.setMessage( "Internal Error" );
		catchD.setDetail( "Invalid regular expression ( " + _theRE + " )" );
		throw new cfmRunTimeException( catchD );
	}

	// Perform substitution and print result.
	return Util.substitute(matcher, pattern, new Perl5Substitution( processSubstr( _theSubstr ) ), _theString, replaceCount );
}
 
Example #10
Source File: cfFormData.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private boolean isTelephone( String field ){
	try{
		return cfPARAM.validateRE( cfPARAM.PHONE_RE, getParameterValue( field ) );
	} catch (MalformedPatternException e) { // shouldn't happen
		return false; 
	}
}
 
Example #11
Source File: cfFormData.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private boolean isUUID( String field ){
	try{
		return cfPARAM.validateRE( cfPARAM.UUID_RE, getParameterValue( field ).toLowerCase() );
	} catch (MalformedPatternException e) { // shouldn't happen
		return false; 
	}
}
 
Example #12
Source File: cfFormData.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private boolean isCreditCard( String field ){
	try{
		return cfPARAM.isCreditCard( getParameterValue( field ) );
	} catch (MalformedPatternException e) { // shouldn't happen
		return false; 
	}
}
 
Example #13
Source File: cfFormData.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private boolean isGUID( String field ){
	try{
		return cfPARAM.validateRE( cfPARAM.GUID_RE, getParameterValue( field ).toLowerCase() );
	} catch (MalformedPatternException e) { // shouldn't happen
		return false; 
	}
}
 
Example #14
Source File: cfFormData.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private boolean isEmail( String field ){
	try{
		return cfPARAM.validateRE( cfPARAM.EMAIL_RE, getParameterValue( field ) );
	} catch (MalformedPatternException e) { // shouldn't happen
		return false; 
	}
}
 
Example #15
Source File: cfPARAM.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isUrl( String _url ) throws MalformedPatternException{
String re = null;
if ( _url.startsWith( "mailto:" ) ){
	re = MAILTO_URL_RE;
}else if ( _url.startsWith( "news:" ) ){
	re = NEWS_URL_RE;
}else if ( _url.startsWith( "file:" ) ){
	re = FILE_URL_RE; 
}else{
	re = URL_RE; 
}
return validateRE( re, _url );
}
 
Example #16
Source File: Perl5RegExpMatching.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * compiles fileNameRegExp into a regular expression and pattern matches on
 * each file's name, and returns those that match.
 * 
 * @param files
 * @param fileNameRegExp
 * 
 * @return String[] of file names that match the expresion.
 */
public String[] matchFileNamesWithPattern(File[] files,
		String fileNameRegExp) throws SshException {
	// set up variables for regexp matching
	Pattern mpattern = null;
	PatternCompiler aPCompiler = new Perl5Compiler();
	PatternMatcher aPerl5Matcher = new Perl5Matcher();
	// Attempt to compile the pattern. If the pattern is not valid,
	// throw exception
	try {
		mpattern = aPCompiler.compile(fileNameRegExp);
	} catch (MalformedPatternException e) {
		throw new SshException("Invalid regular expression:"
				+ e.getMessage(), SshException.BAD_API_USAGE);
	}

	Vector<String> matchedNames = new Vector<String>();

	for (int i = 0; i < files.length; i++) {
		if ((!files[i].getName().equals("."))
				&& (!files[i].getName().equals(".."))
				&& (!files[i].isDirectory())) {
			if (aPerl5Matcher.matches(files[i].getName(), mpattern)) {
				// call get for each match, passing true, so that it doesnt
				// repeat the search
				matchedNames.addElement(files[i].getName());
			}
		}
	}

	// return (String[]) matchedNames.toArray(new String[0]);
	String[] matchedNamesStrings = new String[matchedNames.size()];
	matchedNames.copyInto(matchedNamesStrings);
	return matchedNamesStrings;
}
 
Example #17
Source File: Perl5RegExpMatching.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * compiles fileNameRegExp into a regular expression and pattern matches on
 * each file's name, and returns those that match.
 * 
 * @param files
 * @param fileNameRegExp
 * 
 * @return SftpFile[] of files that match the expresion.
 */
public SftpFile[] matchFilesWithPattern(SftpFile[] files,
		String fileNameRegExp) throws SftpStatusException, SshException {
	// set up variables for regexp matching
	Pattern mpattern = null;
	PatternCompiler aPCompiler = new Perl5Compiler();
	PatternMatcher aPerl5Matcher = new Perl5Matcher();
	// Attempt to compile the pattern. If the pattern is not valid,
	// throw exception
	try {
		mpattern = aPCompiler.compile(fileNameRegExp);
	} catch (MalformedPatternException e) {
		throw new SshException("Invalid regular expression:"
				+ e.getMessage(), SshException.BAD_API_USAGE);
	}

	Vector<SftpFile> matchedNames = new Vector<SftpFile>();

	for (int i = 0; i < files.length; i++) {
		if ((!files[i].getFilename().equals("."))
				&& (!files[i].getFilename().equals(".."))
				&& (!files[i].isDirectory())) {
			if (aPerl5Matcher.matches(files[i].getFilename(), mpattern)) {
				// call get for each match, passing true, so that it doesnt
				// repeat the search
				matchedNames.addElement(files[i]);
			}
		}
	}

	// return (SftpFile[]) matchedNames.toArray(new SftpFile[0]);
	SftpFile[] matchedNamesSftpFiles = new SftpFile[matchedNames.size()];
	matchedNames.copyInto(matchedNamesSftpFiles);
	return matchedNamesSftpFiles;
}
 
Example #18
Source File: GlobRegExpMatching.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * compiles fileNameRegExp into a regular expression and pattern matches on
 * each file's name, and returns those that match.
 * 
 * @param files
 * @param fileNameRegExp
 * 
 * @return String[] of files that match the expresion.
 */
public String[] matchFileNamesWithPattern(File[] files,
		String fileNameRegExp) throws SshException {
	// set up variables for regexp matching
	Pattern mpattern = null;
	PatternCompiler aGCompiler = new GlobCompiler();
	PatternMatcher aPerl5Matcher = new Perl5Matcher();
	// Attempt to compile the pattern. If the pattern is not valid,
	// throw exception
	try {
		mpattern = aGCompiler.compile(fileNameRegExp);
	} catch (MalformedPatternException e) {
		throw new SshException("Invalid regular expression:"
				+ e.getMessage(), SshException.BAD_API_USAGE);
	}

	Vector<String> matchedNames = new Vector<String>();
	for (int i = 0; i < files.length; i++) {
		if ((!files[i].getName().equals("."))
				&& (!files[i].getName().equals(".."))) {
			if (aPerl5Matcher.matches(files[i].getName(), mpattern)) {
				// call get for each match, passing true, so that it doesnt
				// repeat the search
				matchedNames.addElement(files[i].getAbsolutePath());
			}
		}
	}

	// return (String[]) matchedNames.toArray(new String[0]);
	String[] matchedNamesStrings = new String[matchedNames.size()];
	matchedNames.copyInto(matchedNamesStrings);
	return matchedNamesStrings;
}
 
Example #19
Source File: GlobRegExpMatching.java    From j2ssh-maverick with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * compiles fileNameRegExp into a regular expression and pattern matches on
 * each file's name, and returns those that match.
 * 
 * @param files
 * @param fileNameRegExp
 * 
 * @return SftpFile[] of files that match the expresion.
 */
public SftpFile[] matchFilesWithPattern(SftpFile[] files,
		String fileNameRegExp) throws SftpStatusException, SshException {
	// set up variables for regexp matching
	Pattern mpattern = null;
	PatternCompiler aGCompiler = new GlobCompiler();
	PatternMatcher aPerl5Matcher = new Perl5Matcher();
	// Attempt to compile the pattern. If the pattern is not valid,
	// throw exception
	try {
		mpattern = aGCompiler.compile(fileNameRegExp);
	} catch (MalformedPatternException e) {
		throw new SshException("Invalid regular expression:"
				+ e.getMessage(), SshException.BAD_API_USAGE);
	}

	Vector<SftpFile> matchedNames = new Vector<SftpFile>();

	for (int i = 0; i < files.length; i++) {
		if ((!files[i].getFilename().equals("."))
				&& (!files[i].getFilename().equals(".."))
				&& (!files[i].isDirectory())) {
			if (aPerl5Matcher.matches(files[i].getFilename(), mpattern)) {
				// call get for each match, passing true, so that it doesnt
				// repeat the search
				matchedNames.addElement(files[i]);
			}
		}
	}

	// return (SftpFile[]) matchedNames.toArray(new SftpFile[0]);
	SftpFile[] matchedNamesSftpFiles = new SftpFile[matchedNames.size()];
	matchedNames.copyInto(matchedNamesSftpFiles);
	return matchedNamesSftpFiles;
}
 
Example #20
Source File: GlobPatternMatcher.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public GlobMatcher(String expression) throws PatternSyntaxException {
    this.expression = expression;
    try {
        pattern = new GlobCompiler().compile(expression);
    } catch (MalformedPatternException e) {
        throw new PatternSyntaxException(e.getMessage(), expression, 0);
    }
}
 
Example #21
Source File: PatternUtils.java    From canal with Apache License 2.0 5 votes vote down vote up
public Pattern apply(String pattern) {
    try {
        PatternCompiler pc = new Perl5Compiler();
        return pc.compile(pattern,
            Perl5Compiler.CASE_INSENSITIVE_MASK
                    | Perl5Compiler.READ_ONLY_MASK
                    | Perl5Compiler.SINGLELINE_MASK);
    } catch (MalformedPatternException e) {
        throw new RuntimeException(e);
    }
}
 
Example #22
Source File: string.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
public static boolean regexMatches(String str, String re) throws MalformedPatternException {
	PatternMatcher matcher = new Perl5Matcher();
	PatternCompiler compiler = new Perl5Compiler();
	PatternMatcherInput input = new PatternMatcherInput(str);

	Pattern pattern = compiler.compile(re, Perl5Compiler.SINGLELINE_MASK);
	return matcher.matches(input, pattern);
}
 
Example #23
Source File: PatternUtils.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public Pattern apply(String pattern) {
    try {
        PatternCompiler pc = new Perl5Compiler();
        return pc.compile(pattern,
            Perl5Compiler.CASE_INSENSITIVE_MASK
                    | Perl5Compiler.READ_ONLY_MASK
                    | Perl5Compiler.SINGLELINE_MASK);
    } catch (MalformedPatternException e) {
        throw new RuntimeException(e);
    }
}
 
Example #24
Source File: UtilHttp.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * checks, if the current request comes from a searchbot
 *
 * @param request
 * @return whether the request is from a web searchbot
 */
public static boolean checkURLforSpiders(HttpServletRequest request) {
    boolean result = false;

    String spiderRequest = (String) request.getAttribute("_REQUEST_FROM_SPIDER_");
    if (UtilValidate.isNotEmpty(spiderRequest)) {
        if ("Y".equals(spiderRequest)) {
            return true;
        }
        return false;
    }
    String initialUserAgent = request.getHeader("User-Agent") != null ? request.getHeader("User-Agent") : "";
    List<String> spiderList = StringUtil.split(UtilProperties.getPropertyValue("url", "link.remove_lsessionid.user_agent_list"), ",");

    if (UtilValidate.isNotEmpty(spiderList)) {
        for (String spiderNameElement : spiderList) {
            Pattern pattern = null;
            try {
                pattern = PatternFactory.createOrGetPerl5CompiledPattern(spiderNameElement, false);
            } catch (MalformedPatternException e) {
                Debug.logError(e, module);
            }
            PatternMatcher matcher = new Perl5Matcher();
            if (matcher.contains(initialUserAgent, pattern)) {
                request.setAttribute("_REQUEST_FROM_SPIDER_", "Y");
                result = true;
                break;
            }
        }
    }

    if (!result) {
        request.setAttribute("_REQUEST_FROM_SPIDER_", "N");
    }

    return result;
}
 
Example #25
Source File: Regexp.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public Regexp(Element element, SimpleMapProcess simpleMapProcess) {
    super(element, simpleMapProcess);
    expr = element.getAttribute("expr");
    try {
        pattern = PatternFactory.createOrGetPerl5CompiledPattern(expr, true);
    } catch (MalformedPatternException e) {
        Debug.logError(e, module);
    }
}
 
Example #26
Source File: JavaSource.java    From yugong with GNU General Public License v2.0 5 votes vote down vote up
public Pattern apply(String pattern) {
    try {
        PatternCompiler pc = new Perl5Compiler();
        return pc.compile(pattern, Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.READ_ONLY_MASK);
    } catch (MalformedPatternException e) {
        throw new RuntimeException("Regex failed!", e);
    }
}
 
Example #27
Source File: PatternUtils.java    From jlogstash-input-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Pattern apply(String pattern) {
    try {
        PatternCompiler pc = new Perl5Compiler();
        return pc.compile(pattern,
                Perl5Compiler.CASE_INSENSITIVE_MASK
                        | Perl5Compiler.READ_ONLY_MASK
                        | Perl5Compiler.SINGLELINE_MASK);
    } catch (MalformedPatternException e) {
        throw new CanalFilterException(e);
    }
}
 
Example #28
Source File: Perl5Regex.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param regex
 *          the regular expression pattern to compile.
 * @throws PatternInvalidSyntaxException
 *           if the regular expression's syntax is invalid.
 */
public Perl5Regex(String regex) {
  super();

  Perl5Compiler perl5Compiler = new Perl5Compiler();

  try {
    pattern = perl5Compiler.compile(regex);
    regexPattern = regex;

  } catch (MalformedPatternException malformedPatternException) {
    throw new PatternInvalidSyntaxException(malformedPatternException
        .getMessage());
  }
}
 
Example #29
Source File: ValidatorUtil.java    From webcurator with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to validate a new password for a user id.
 * @param aErrors The errors object to populate
 * @param aNewPwd the new password for the user id
 * @param aErrorCode the error code
 * @param aValues the values
 * @param aFailureMessage the default message
 */
public static void validateNewPassword(Errors aErrors, String aNewPwd, String aErrorCode, Object[] aValues, String aFailureMessage) {
    if (aNewPwd != null && !aNewPwd.trim().equals("")) {
        Perl5Compiler ptrnCompiler = new Perl5Compiler();
        Perl5Matcher matcher = new Perl5Matcher();
        try {
            Perl5Pattern lcCharPattern = (Perl5Pattern) ptrnCompiler.compile("[a-z]");
            Perl5Pattern ucCharPattern = (Perl5Pattern) ptrnCompiler.compile("[A-Z]");
            Perl5Pattern numericPattern = (Perl5Pattern) ptrnCompiler.compile("[0-9]");
            
            if (aNewPwd.length() < 6) {
                aErrors.reject(aErrorCode, aValues, aFailureMessage);
                return;
            }
            
            if (!matcher.contains(aNewPwd, lcCharPattern)) {
                aErrors.reject(aErrorCode, aValues, aFailureMessage);               
                return;
            }
            
            if (!matcher.contains(aNewPwd, ucCharPattern)) {
                aErrors.reject(aErrorCode, aValues, aFailureMessage);
                return;
            }
            
            if (!matcher.contains(aNewPwd, numericPattern)) {
                aErrors.reject(aErrorCode, aValues, aFailureMessage);
                return;
            }

        }
        catch (MalformedPatternException e) {
            LogFactory.getLog(ValidatorUtil.class).fatal("Perl patterns malformed: " + e.getMessage(), e);
        }           
    }
}
 
Example #30
Source File: cfFormData.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private boolean isZipCode( String field ){
	try{
		return cfPARAM.validateRE( cfPARAM.ZIPCODE_RE, getParameterValue( field ) );
	} catch (MalformedPatternException e) { // shouldn't happen
		return false; 
	}
}