本文整理匯總了Java中org.apache.oro.text.regex.Perl5Matcher.contains方法的典型用法代碼示例。如果您正苦於以下問題:Java Perl5Matcher.contains方法的具體用法?Java Perl5Matcher.contains怎麽用?Java Perl5Matcher.contains使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.oro.text.regex.Perl5Matcher
的用法示例。
在下文中一共展示了Perl5Matcher.contains方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: indexOf
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
/**
* return index of the first occurence of the pattern in input text
* @param strPattern pattern to search
* @param strInput text to search pattern
* @param offset
* @param caseSensitive
* @return position of the first occurence
* @throws MalformedPatternException
*/
public static int indexOf(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
//Perl5Compiler compiler = new Perl5Compiler();
PatternMatcherInput input = new PatternMatcherInput(strInput);
Perl5Matcher matcher = new Perl5Matcher();
int compileOptions=caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
compileOptions+=Perl5Compiler.SINGLELINE_MASK;
if(offset < 1) offset = 1;
Pattern pattern = getPattern(strPattern,compileOptions);
//Pattern pattern = compiler.compile(strPattern,compileOptions);
if(offset <= strInput.length()) input.setCurrentOffset(offset - 1);
if(offset <= strInput.length() && matcher.contains(input, pattern)) {
return matcher.getMatch().beginOffset(0) + 1;
}
return 0;
}
示例2: validateField
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
/**
* Validates an value for a field and returns ErrorData in case of validation error
* @param value
* @return
*/
@Override
public ErrorData validateField(Object value) {
ErrorData errorData = super.validateField(value);
if (errorData!=null) {
return errorData;
}
String textValue = (String)value;
if (textValue==null || textValue.length()==0){
return null;
}
Perl5Matcher pm = new Perl5Matcher();
if (pattern!=null) {
if (!pm.contains(textValue, pattern)) {
LOGGER.warn("The email:'" + textValue +"' is not accepted by the pattern: "+pattern.getPattern());
errorData = new ErrorData("admin.user.profile.err.emailAddress.format");
return errorData;
}
}
return null;
}
示例3: validateRegEx
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的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);
}
}
}
示例4: getBoundaryStringFromContentType
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
private String getBoundaryStringFromContentType(String requestHeaders) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
String regularExpression = "^" + HTTPConstants.HEADER_CONTENT_TYPE + ": multipart/form-data; boundary=(.+)$";
Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
if(localMatcher.contains(requestHeaders, pattern)) {
MatchResult match = localMatcher.getMatch();
String matchString = match.group(1);
// Header may contain ;charset= , regexp extracts it so computed boundary is wrong
int indexOf = matchString.indexOf(';');
if(indexOf>=0) {
return matchString.substring(0, indexOf);
} else {
return matchString;
}
}
else {
return null;
}
}
示例5: matchStrings
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
private int matchStrings(int matchNumber, Perl5Matcher matcher,
Pattern pattern, List<MatchResult> matches, int found,
String inputString) {
PatternMatcherInput input = new PatternMatcherInput(inputString);
while (matchNumber <=0 || found != matchNumber) {
if (matcher.contains(input, pattern)) {
log.debug("RegexExtractor: Match found!");
matches.add(matcher.getMatch());
found++;
} else {
break;
}
}
return found;
}
示例6: getRequestHeaderValue
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
private static String getRequestHeaderValue(String requestHeaders, String headerName) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
// We use multi-line mask so can prefix the line with ^
String expression = "^" + headerName + ":\\s+([^\\r\\n]+)"; // $NON-NLS-1$ $NON-NLS-2$
Pattern pattern = JMeterUtils.getPattern(expression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
if(localMatcher.contains(requestHeaders, pattern)) {
// The value is in the first group, group 0 is the whole match
// System.out.println("Found:'"+localMatcher.getMatch().group(1)+"'");
// System.out.println("in: '"+localMatcher.getMatch().group(0)+"'");
return localMatcher.getMatch().group(1);
}
else {
return null;
}
}
示例7: getPositionOfBody
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
private static int getPositionOfBody(String stringToCheck) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
// The headers and body are divided by a blank line (the \r is to allow for the CR before LF)
String regularExpression = "^\\r$"; // $NON-NLS-1$
Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
PatternMatcherInput input = new PatternMatcherInput(stringToCheck);
if(localMatcher.contains(input, pattern)) {
MatchResult match = localMatcher.getMatch();
return match.beginOffset(0);
}
// No divider was found
return -1;
}
示例8: getHeaderValue
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
private String getHeaderValue(String headerName, String multiPart) {
String regularExpression = headerName + "\\s*:\\s*(.*)$"; //$NON-NLS-1$
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
if(localMatcher.contains(multiPart, pattern)) {
return localMatcher.getMatch().group(1).trim();
}
else {
return null;
}
}
示例9: getIpAddress
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
protected String getIpAddress(String logLine) {
Pattern incIp = JMeterUtils.getPatternCache().getPattern("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}",
Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.SINGLELINE_MASK);
Perl5Matcher matcher = JMeterUtils.getMatcher();
matcher.contains(logLine, incIp);
return matcher.getMatch().group(0);
}
示例10: match
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
public static Array match(String strPattern, String strInput, int offset, boolean caseSensitive) throws MalformedPatternException {
Perl5Matcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(strInput);
int compileOptions=caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
compileOptions+=Perl5Compiler.SINGLELINE_MASK;
if(offset < 1) offset = 1;
Pattern pattern = getPattern(strPattern,compileOptions);
Array rtn = new ArrayImpl();
MatchResult result;
while(matcher.contains(input, pattern)) {
result = matcher.getMatch();
rtn.appendEL(result.toString());
/*
System.out.println("Match: " + result.toString());
System.out.println("Length: " + result.length());
groups = result.groups();
System.out.println("Groups: " + groups);
System.out.println("Begin offset: " + result.beginOffset(0));
System.out.println("End offset: " + result.endOffset(0));
System.out.println("Saved Groups: ");
// Start at 1 because we just printed out group 0
for(int group = 1; group < groups; group++) {
System.out.println(group + ": " + result.group(group));
System.out.println("Begin: " + result.begin(group));
System.out.println("End: " + result.end(group));
}*/
}
return rtn;
}
示例11: verifyNewUser
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
/**
* Verify a new user
* @param resourceName
* @param username
* @param firstName
* @param lastName
* @param email
* @return
*/
public static List<ErrorData> verifyNewUser(String resourceName, String username, String firstName, String lastName, String email) {
List<ErrorData> errorData = new ArrayList<ErrorData>();
if (username==null || username.length()==0) {
errorData.add(new ErrorData("registration.error.loginName.required"));
}
if ((email==null) || (email.length()== 0)) {
errorData.add(new ErrorData("registration.error.emailAddress.required"));
} else {
int atSign = email.indexOf("@");
if ((atSign < 1) || (atSign >= (email.length() - 1))
|| (email.length() > 60)) {
errorData.add(new ErrorData("registration.error.emailAddress.format"));
}
Perl5Matcher pm = new Perl5Matcher();
TSiteBean siteBean= ApplicationBean.getInstance().getSiteBean();
Perl5Pattern allowedEmailPattern = SiteConfigBL.getSiteAllowedEmailPattern(siteBean);
if (!pm.contains(email.trim(),allowedEmailPattern)) {
errorData.add(new ErrorData("registration.error.emailAddress.domain"));
}
}
TPersonBean existingPersonBean = PersonBL.loadByLoginName(username);
if (existingPersonBean!=null) {
errorData.add(new ErrorData("registration.error.loginName.unique", username));
}
if (PersonBL.nameAndEmailExist(lastName, firstName, email, null)) {
errorData.add(new ErrorData("registration.error.nameAndEmail.unique",
lastName + ", " + firstName + ", " + email));
}
return errorData;
}
示例12: validateNewPassword
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的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);
}
}
}
示例13: process
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
private String process(String textToParse) {
Perl5Matcher matcher = new Perl5Matcher();
PatternMatcherInput input = new PatternMatcherInput(textToParse);
PatternCacheLRU pcLRU = new PatternCacheLRU();
Pattern pattern;
try {
pattern = pcLRU.getPattern(regexpField.getText(), Perl5Compiler.READ_ONLY_MASK);
} catch (MalformedCachePatternException e) {
return e.toString();
}
List<MatchResult> matches = new LinkedList<MatchResult>();
while (matcher.contains(input, pattern)) {
matches.add(matcher.getMatch());
}
// Construct a multi-line string with all matches
StringBuilder sb = new StringBuilder();
final int size = matches.size();
sb.append("Match count: ").append(size).append("\n");
for (int j = 0; j < size; j++) {
MatchResult mr = matches.get(j);
final int groups = mr.groups();
for (int i = 0; i < groups; i++) {
sb.append("Match[").append(j+1).append("][").append(i).append("]=").append(mr.group(i)).append("\n");
}
}
return sb.toString();
}
示例14: getPositionOfBody
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
private int getPositionOfBody(String stringToCheck) {
Perl5Matcher localMatcher = JMeterUtils.getMatcher();
// The headers and body are divided by a blank line
String regularExpression = "^.$";
Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK);
PatternMatcherInput input = new PatternMatcherInput(stringToCheck);
while(localMatcher.contains(input, pattern)) {
MatchResult match = localMatcher.getMatch();
return match.beginOffset(0);
}
// No divider was found
return -1;
}
示例15: isAnchorMatched
import org.apache.oro.text.regex.Perl5Matcher; //導入方法依賴的package包/類
/**
* Check if anchor matches by checking against:
* - protocol
* - domain
* - path
* - parameter names
*
* @param newLink target to match
* @param config pattern to match against
*
* @return true if target URL matches pattern URL
*/
public static boolean isAnchorMatched(HTTPSamplerBase newLink, HTTPSamplerBase config)
{
String query = null;
try {
query = URLDecoder.decode(newLink.getQueryString(), "UTF-8"); // $NON-NLS-1$
} catch (UnsupportedEncodingException e) {
// UTF-8 unsupported? You must be joking!
log.error("UTF-8 encoding not supported!");
throw new Error("Should not happen: " + e.toString(), e);
}
final Arguments arguments = config.getArguments();
final Perl5Matcher matcher = JMeterUtils.getMatcher();
final PatternCacheLRU patternCache = JMeterUtils.getPatternCache();
if (!isEqualOrMatches(newLink.getProtocol(), config.getProtocol(), matcher, patternCache)){
return false;
}
final String domain = config.getDomain();
if (domain != null && domain.length() > 0) {
if (!isEqualOrMatches(newLink.getDomain(), domain, matcher, patternCache)){
return false;
}
}
final String path = config.getPath();
if (!newLink.getPath().equals(path)
&& !matcher.matches(newLink.getPath(), patternCache.getPattern("[/]*" + path, // $NON-NLS-1$
Perl5Compiler.READ_ONLY_MASK))) {
return false;
}
for (JMeterProperty argument : arguments) {
Argument item = (Argument) argument.getObjectValue();
final String name = item.getName();
if (!query.contains(name + "=")) { // $NON-NLS-1$
if (!(matcher.contains(query, patternCache.getPattern(name, Perl5Compiler.READ_ONLY_MASK)))) {
return false;
}
}
}
return true;
}