Java Code Examples for org.apache.oro.text.regex.MalformedPatternException#getMessage()

The following examples show how to use org.apache.oro.text.regex.MalformedPatternException#getMessage() . 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: 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 2
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 3
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 4
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 5
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 6
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);
    }
}