Java Code Examples for org.springframework.util.PatternMatchUtils#simpleMatch()

The following examples show how to use org.springframework.util.PatternMatchUtils#simpleMatch() . 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: ProxyWebSocketHandler.java    From spring-cloud-netflix-zuul-websocket with Apache License 2.0 6 votes vote down vote up
private ZuulWebSocketProperties.WsBrokerage getWebSocketBrokarage(URI uri) {
    String path = uri.toString();
    if (path.contains(":")) {
        path = UriComponentsBuilder.fromUriString(path).build().getPath();
    }

    for (Map.Entry<String, ZuulWebSocketProperties.WsBrokerage> entry : zuulWebSocketProperties
            .getBrokerages().entrySet()) {
        ZuulWebSocketProperties.WsBrokerage wsBrokerage = entry.getValue();
        if (wsBrokerage.isEnabled()) {
            for (String endPoint : wsBrokerage.getEndPoints()) {
                if (PatternMatchUtils.simpleMatch(toPattern(endPoint), path + "/")) {
                    return wsBrokerage;
                }
            }
        }
    }

    return null;
}
 
Example 2
Source File: ImagesForUpdate.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Find image by its name, or id
 * @param name
 * @param imageId
 * @return
 */
public Image findImage(String name, String imageId) {
    Image res = null;
    if(imageId != null) {
        res = imagesByName.get(imageId);
    }
    String withoutTag = ImageName.withoutTagOrNull(name);
    if(res == null && withoutTag != null) {
        res = imagesByName.get(withoutTag);
    }
    if(res == null && (imageId != null || withoutTag != null)) {
        for(Image img: imagesWithPattern) {
            String pattern = img.getName();
            if(withoutTag != null && PatternMatchUtils.simpleMatch(pattern, withoutTag) ||
               imageId != null && PatternMatchUtils.simpleMatch(pattern, imageId)) {
                res = img;
                break;
            }
        }
    }
    return res;
}
 
Example 3
Source File: SQLErrorCodesFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Return the {@link SQLErrorCodes} instance for the given database.
 * <p>No need for a database meta-data lookup.
 * @param databaseName the database name (must not be {@code null})
 * @return the {@code SQLErrorCodes} instance for the given database
 * @throws IllegalArgumentException if the supplied database name is {@code null}
 */
public SQLErrorCodes getErrorCodes(String databaseName) {
	Assert.notNull(databaseName, "Database product name must not be null");

	SQLErrorCodes sec = this.errorCodesMap.get(databaseName);
	if (sec == null) {
		for (SQLErrorCodes candidate : this.errorCodesMap.values()) {
			if (PatternMatchUtils.simpleMatch(candidate.getDatabaseProductNames(), databaseName)) {
				sec = candidate;
				break;
			}
		}
	}
	if (sec != null) {
		checkCustomTranslatorRegistry(databaseName, sec);
		if (logger.isDebugEnabled()) {
			logger.debug("SQL error codes for '" + databaseName + "' found");
		}
		return sec;
	}

	// Could not find the database among the defined ones.
	if (logger.isDebugEnabled()) {
		logger.debug("SQL error codes for '" + databaseName + "' not found");
	}
	return new SQLErrorCodes();
}
 
Example 4
Source File: SQLErrorCodesFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Return the {@link SQLErrorCodes} instance for the given database.
 * <p>No need for a database metadata lookup.
 * @param dbName the database name (must not be {@code null})
 * @return the {@code SQLErrorCodes} instance for the given database
 * @throws IllegalArgumentException if the supplied database name is {@code null}
 */
public SQLErrorCodes getErrorCodes(String dbName) {
	Assert.notNull(dbName, "Database product name must not be null");

	SQLErrorCodes sec = this.errorCodesMap.get(dbName);
	if (sec == null) {
		for (SQLErrorCodes candidate : this.errorCodesMap.values()) {
			if (PatternMatchUtils.simpleMatch(candidate.getDatabaseProductNames(), dbName)) {
				sec = candidate;
				break;
			}
		}
	}
	if (sec != null) {
		checkCustomTranslatorRegistry(dbName, sec);
		if (logger.isDebugEnabled()) {
			logger.debug("SQL error codes for '" + dbName + "' found");
		}
		return sec;
	}

	// Could not find the database among the defined ones.
	if (logger.isDebugEnabled()) {
		logger.debug("SQL error codes for '" + dbName + "' not found");
	}
	return new SQLErrorCodes();
}
 
Example 5
Source File: ReadWriteDataSourceProcessor.java    From AsuraFramework with Apache License 2.0 4 votes vote down vote up
protected boolean isMatch(String methodName, String mappedName) {
    return PatternMatchUtils.simpleMatch(mappedName, methodName);
}
 
Example 6
Source File: DataBinder.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Return if the given field is allowed for binding.
 * Invoked for each passed-in property value.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality, in the specified lists of allowed fields and
 * disallowed fields. A field matching a disallowed pattern will not be accepted
 * even if it also happens to match a pattern in the allowed list.
 * <p>Can be overridden in subclasses.
 * @param field the field to check
 * @return if the field is allowed
 * @see #setAllowedFields
 * @see #setDisallowedFields
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isAllowed(String field) {
	String[] allowed = getAllowedFields();
	String[] disallowed = getDisallowedFields();
	return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) &&
			(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field)));
}
 
Example 7
Source File: DataBinder.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return if the given field is allowed for binding.
 * Invoked for each passed-in property value.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality, in the specified lists of allowed fields and
 * disallowed fields. A field matching a disallowed pattern will not be accepted
 * even if it also happens to match a pattern in the allowed list.
 * <p>Can be overridden in subclasses.
 * @param field the field to check
 * @return if the field is allowed
 * @see #setAllowedFields
 * @see #setDisallowedFields
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isAllowed(String field) {
	String[] allowed = getAllowedFields();
	String[] disallowed = getDisallowedFields();
	return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) &&
			(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field)));
}
 
Example 8
Source File: DataBinder.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Return if the given field is allowed for binding.
 * Invoked for each passed-in property value.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality, in the specified lists of allowed fields and
 * disallowed fields. A field matching a disallowed pattern will not be accepted
 * even if it also happens to match a pattern in the allowed list.
 * <p>Can be overridden in subclasses.
 * @param field the field to check
 * @return if the field is allowed
 * @see #setAllowedFields
 * @see #setDisallowedFields
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isAllowed(String field) {
	String[] allowed = getAllowedFields();
	String[] disallowed = getDisallowedFields();
	return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) &&
			(ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field)));
}
 
Example 9
Source File: BeanNameAutoProxyCreator.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Return if the given bean name matches the mapped name.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality. Can be overridden in subclasses.
 * @param beanName the bean name to check
 * @param mappedName the name in the configured list of names
 * @return if the names match
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isMatch(String beanName, String mappedName) {
	return PatternMatchUtils.simpleMatch(mappedName, beanName);
}
 
Example 10
Source File: BeanNameAutoProxyCreator.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Return if the given bean name matches the mapped name.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality. Can be overridden in subclasses.
 * @param beanName the bean name to check
 * @param mappedName the name in the configured list of names
 * @return if the names match
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isMatch(String beanName, String mappedName) {
	return PatternMatchUtils.simpleMatch(mappedName, beanName);
}
 
Example 11
Source File: NameMatchTransactionAttributeSource.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return if the given method name matches the mapped name.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality. Can be overridden in subclasses.
 * @param methodName the method name of the class
 * @param mappedName the name in the descriptor
 * @return if the names match
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isMatch(String methodName, String mappedName) {
	return PatternMatchUtils.simpleMatch(mappedName, methodName);
}
 
Example 12
Source File: ViewNameMethodReturnValueHandler.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Whether the given view name is a redirect view reference.
 * The default implementation checks the configured redirect patterns and
 * also if the view name starts with the "redirect:" prefix.
 * @param viewName the view name to check, never {@code null}
 * @return "true" if the given view name is recognized as a redirect view
 * reference; "false" otherwise.
 */
protected boolean isRedirectViewName(String viewName) {
	return (PatternMatchUtils.simpleMatch(this.redirectPatterns, viewName) || viewName.startsWith("redirect:"));
}
 
Example 13
Source File: UrlBasedViewResolver.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Indicates whether or not this {@link org.springframework.web.servlet.ViewResolver} can
 * handle the supplied view name. If not, {@link #createView(String, java.util.Locale)} will
 * return {@code null}. The default implementation checks against the configured
 * {@link #setViewNames view names}.
 * @param viewName the name of the view to retrieve
 * @param locale the Locale to retrieve the view for
 * @return whether this resolver applies to the specified view
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean canHandle(String viewName, Locale locale) {
	String[] viewNames = getViewNames();
	return (viewNames == null || PatternMatchUtils.simpleMatch(viewNames, viewName));
}
 
Example 14
Source File: ViewNameMethodReturnValueHandler.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Whether the given view name is a redirect view reference.
 * The default implementation checks the configured redirect patterns and
 * also if the view name starts with the "redirect:" prefix.
 * @param viewName the view name to check, never {@code null}
 * @return "true" if the given view name is recognized as a redirect view
 * reference; "false" otherwise.
 */
protected boolean isRedirectViewName(String viewName) {
	return (PatternMatchUtils.simpleMatch(this.redirectPatterns, viewName) || viewName.startsWith("redirect:"));
}
 
Example 15
Source File: MethodMapTransactionAttributeSource.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Return if the given method name matches the mapped name.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*"
 * matches, as well as direct equality.
 * @param methodName the method name of the class
 * @param mappedName the name in the descriptor
 * @return if the names match
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isMatch(String methodName, String mappedName) {
	return PatternMatchUtils.simpleMatch(mappedName, methodName);
}
 
Example 16
Source File: BeanNameAutoProxyCreator.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Return if the given bean name matches the mapped name.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality. Can be overridden in subclasses.
 * @param beanName the bean name to check
 * @param mappedName the name in the configured list of names
 * @return if the names match
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isMatch(String beanName, String mappedName) {
	return PatternMatchUtils.simpleMatch(mappedName, beanName);
}
 
Example 17
Source File: NameMatchMethodPointcut.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Return if the given method name matches the mapped name.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality. Can be overridden in subclasses.
 * @param methodName the method name of the class
 * @param mappedName the name in the descriptor
 * @return if the names match
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isMatch(String methodName, String mappedName) {
	return PatternMatchUtils.simpleMatch(mappedName, methodName);
}
 
Example 18
Source File: NameMatchMethodPointcut.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Return if the given method name matches the mapped name.
 * <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
 * as well as direct equality. Can be overridden in subclasses.
 * @param methodName the method name of the class
 * @param mappedName the name in the descriptor
 * @return if the names match
 * @see org.springframework.util.PatternMatchUtils#simpleMatch(String, String)
 */
protected boolean isMatch(String methodName, String mappedName) {
	return PatternMatchUtils.simpleMatch(mappedName, methodName);
}
 
Example 19
Source File: $.java    From mica with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 字符串是否符合指定的 表达式
 *
 * <p>
 * pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
 * </p>
 *
 * @param pattern 表达式
 * @param str     字符串
 * @return 是否匹配
 */
public static boolean simpleMatch(@Nullable String pattern, @Nullable String str) {
	return PatternMatchUtils.simpleMatch(pattern, str);
}
 
Example 20
Source File: StringUtil.java    From mica with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 字符串是否符合指定的 表达式
 *
 * <p>
 * pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
 * </p>
 *
 * @param patterns 表达式 数组
 * @param str      字符串
 * @return 是否匹配
 */
public static boolean simpleMatch(@Nullable String[] patterns, String str) {
	return PatternMatchUtils.simpleMatch(patterns, str);
}