当前位置: 首页>>代码示例>>Java>>正文


Java Perl5Compiler.compile方法代码示例

本文整理汇总了Java中org.apache.oro.text.regex.Perl5Compiler.compile方法的典型用法代码示例。如果您正苦于以下问题:Java Perl5Compiler.compile方法的具体用法?Java Perl5Compiler.compile怎么用?Java Perl5Compiler.compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.oro.text.regex.Perl5Compiler的用法示例。


在下文中一共展示了Perl5Compiler.compile方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convertStringToPattern

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
/**
 * 把字符串转成Pattern和UrlType
 * 
 * @param perl5RegExp
 * @return
 */
private URLPatternHolder convertStringToPattern(String line) {
    URLPatternHolder holder = new URLPatternHolder();
    Pattern compiledPattern;
    Perl5Compiler compiler = new Perl5Compiler();
    String perl5RegExp = line;
    try {
        compiledPattern = compiler.compile(perl5RegExp, Perl5Compiler.READ_ONLY_MASK);
        holder.setCompiledPattern(compiledPattern);
    } catch (MalformedPatternException mpe) {
        throw new IllegalArgumentException("Malformed regular expression: " + perl5RegExp);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Added regular expression: " + compiledPattern.getPattern().toString());
    }
    return holder;
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:24,代码来源:URLProtectedEditor.java

示例2: createOrGetPerl5CompiledPattern

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:26,代码来源:PatternFactory.java

示例3: getTaskPattern

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
@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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:ListChooseByNameModel.java

示例4: isValidSettings

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
@Override
public List<ErrorData> isValidSettings(Map<Integer, Object> settings) {
	List<ErrorData> errorDataList = new ArrayList<ErrorData>();
	TTextBoxSettingsBean textBoxSettingsBean = (TTextBoxSettingsBean)settings.get(mapParameterCode);
	//textBoxSettingsBean can be null when no settings was set (especially by system fields)
	if (textBoxSettingsBean!=null) {
		String patternString = textBoxSettingsBean.getDefaultText();
		Perl5Compiler pc = new Perl5Compiler();
		try {
			/*Perl5Pattern pattern=(Perl5Pattern)*/pc.compile(patternString,Perl5Compiler.CASE_INSENSITIVE_MASK |Perl5Compiler.SINGLELINE_MASK);
		} catch (MalformedPatternException e) {
			LOGGER.error("Malformed Email Domain Pattern " + patternString);
			errorDataList.add(new ErrorData("admin.user.profile.err.emailAddress.format"));
		}
	}
	return errorDataList;
}
 
开发者ID:trackplus,项目名称:Genji,代码行数:18,代码来源:EmaiAddressDT.java

示例5: validateRegEx

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
/**
 * 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);
        }           
    }
}
 
开发者ID:DIA-NZ,项目名称:webcurator,代码行数:28,代码来源:ValidatorUtil.java

示例6: Perl5Regex

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
/**
 * @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());
  }
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:21,代码来源:Perl5Regex.java

示例7: visit

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
@Override
public Object visit(StringBinaryComparison n, Void arg) {
	String first = (String) n.getLeftOperand().accept(this, null);
	String second = (String) n.getRightOperand().accept(this, null);

	Operator op = n.getOperator();
	switch (op) {
	case EQUALSIGNORECASE:
		return first.equalsIgnoreCase(second) ? TRUE_VALUE : FALSE_VALUE;
	case EQUALS:
		return first.equals(second) ? TRUE_VALUE : FALSE_VALUE;
	case ENDSWITH:
		return first.endsWith(second) ? TRUE_VALUE : FALSE_VALUE;
	case CONTAINS:
		return first.contains(second) ? TRUE_VALUE : FALSE_VALUE;
	case PATTERNMATCHES:
		return second.matches(first) ? TRUE_VALUE : FALSE_VALUE;
	case APACHE_ORO_PATTERN_MATCHES: {
		Perl5Matcher matcher = new Perl5Matcher();
		Perl5Compiler compiler = new Perl5Compiler();
		Pattern pattern;
		try {
			pattern = compiler.compile(first);
		} catch (MalformedPatternException e) {
			throw new RuntimeException(e);
		}
		return matcher.matches(second, pattern) ? TRUE_VALUE : FALSE_VALUE;

	}
	default:
		log.warn("StringComparison: unimplemented operator!" + op);
		return null;
	}

}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:36,代码来源:ExpressionExecutor.java

示例8: validateNewPassword

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
/**
 * 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);
        }           
    }
}
 
开发者ID:DIA-NZ,项目名称:webcurator,代码行数:44,代码来源:ValidatorUtil.java

示例9: escapeExpireUrl

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
private static String escapeExpireUrl(String expireURL){
Perl5Compiler 			compiler 	= new Perl5Compiler();
Perl5Matcher				matcher 	= new Perl5Matcher();
Pattern 						pattern 	= null;

try{
	pattern		= compiler.compile( "([+?.])" );
  expireURL = Util.substitute(matcher, pattern, new Perl5Substitution( "\\\\$1" ), expireURL, Util.SUBSTITUTE_ALL );
  return com.nary.util.string.replaceString(expireURL,"*",".*");
}catch(Exception E){
	return null;
}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:14,代码来源:cfCACHE.java

示例10: expireFiles

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
private void expireFiles( File directory, String expireURL, String virtualServer ) throws cfmRunTimeException {
File[] listOfFiles = directory.listFiles(cfCacheFileFilter);

boolean	deleteAll	= (expireURL.equals("*") || expireURL.length() == 0);

//use of this var is the fix for NA bug #3308
 	boolean ignoreHost = (! deleteAll && expireURL.startsWith("*"));

File thisFile;
String firstline;

Perl5Compiler 			compiler 	= new Perl5Compiler();
Perl5Matcher				matcher 	= new Perl5Matcher();
Pattern 						pattern 	= null;

if ( !deleteAll ){
	try {
		if(!ignoreHost)
		{
			/* The string in the cache file is always <servername>/<uri>; we need to add in the servername and adjust the expireURL accordingly */
			if ( expireURL.startsWith("/") )
				expireURL = virtualServer + expireURL;
			else
				expireURL = virtualServer + "/" + expireURL;
		}

		pattern		= compiler.compile( escapeExpireUrl( expireURL ) );
	} catch (MalformedPatternException e) {
		throw new cfmRunTimeException( catchDataFactory.extendedException( "errorCode.runtimeError",
				 "cfcache.expireUrl",
				 new String[]{expireURL},
				 e.getMessage()) );
	}
}

	for ( int x=0; x < listOfFiles.length; x++ ){
		thisFile	= listOfFiles[x];
		if ( deleteAll ) {
			boolean success = false;
			int tries = 0;
			for ( ; (tries < 10) && (!success); tries++ )
			{
				if ( deleteCachedFile( thisFile ) )
					success = true;
		}
	if ( !success ) {
		throw newRunTimeException( "Failed to delete cache file: " + thisFile );
	}
		}
		else{
			firstline	= getURIFromFile( thisFile );
			if ( firstline != null ){

				if( pattern != null && matcher.contains( new PatternMatcherInput( firstline ), pattern ) )
					deleteCachedFile( thisFile );

			}
		}
	}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:61,代码来源:cfCACHE.java

示例11: testPer5PatternMatcher

import org.apache.oro.text.regex.Perl5Compiler; //导入方法依赖的package包/类
@Test
public void testPer5PatternMatcher() throws Exception {


    Perl5Compiler compiler = new Perl5Compiler();
    org.apache.oro.text.regex.Pattern p = compiler.compile(sqlTablePatten);
    org.apache.oro.text.regex.PatternMatcher m = new Perl5Matcher();


    for(String sql : sqls){

        System.out.println(sql);
        PatternMatcherInput input = new PatternMatcherInput(sql);

        MatchResult result = null;
        while(m.contains(input, p)) {
            result = m.getMatch();
            // Perform whatever processing on the result you want.

            System.out.println(result.group(0));
        }
        System.out.println();
    }

}
 
开发者ID:yaohuiwu,项目名称:CAM,代码行数:26,代码来源:SqlFromExtractTest.java


注:本文中的org.apache.oro.text.regex.Perl5Compiler.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。