本文整理匯總了Java中org.springframework.util.PathMatcher類的典型用法代碼示例。如果您正苦於以下問題:Java PathMatcher類的具體用法?Java PathMatcher怎麽用?Java PathMatcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PathMatcher類屬於org.springframework.util包,在下文中一共展示了PathMatcher類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: simpAnnotationMethodMessageHandler
import org.springframework.util.PathMatcher; //導入依賴的package包/類
@Bean
public SimpAnnotationMethodMessageHandler simpAnnotationMethodMessageHandler() {
SimpAnnotationMethodMessageHandler handler = createAnnotationMethodMessageHandler();
handler.setDestinationPrefixes(getBrokerRegistry().getApplicationDestinationPrefixes());
handler.setMessageConverter(brokerMessageConverter());
handler.setValidator(simpValidator());
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
addArgumentResolvers(argumentResolvers);
handler.setCustomArgumentResolvers(argumentResolvers);
List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
addReturnValueHandlers(returnValueHandlers);
handler.setCustomReturnValueHandlers(returnValueHandlers);
PathMatcher pathMatcher = this.getBrokerRegistry().getPathMatcher();
if (pathMatcher != null) {
handler.setPathMatcher(pathMatcher);
}
return handler;
}
示例2: prependLeadingSlash
import org.springframework.util.PathMatcher; //導入依賴的package包/類
private static Set<String> prependLeadingSlash(Collection<String> patterns, PathMatcher pathMatcher) {
if (patterns == null) {
return Collections.emptySet();
}
boolean slashSeparator = pathMatcher.combine("a", "a").equals("a/a");
Set<String> result = new LinkedHashSet<String>(patterns.size());
for (String pattern : patterns) {
if (slashSeparator) {
if (StringUtils.hasLength(pattern) && !pattern.startsWith("/")) {
pattern = "/" + pattern;
}
}
result.add(pattern);
}
return result;
}
示例3: PatternsRequestCondition
import org.springframework.util.PathMatcher; //導入依賴的package包/類
/**
* Private constructor accepting a collection of patterns.
*/
private PatternsRequestCondition(Collection<String> patterns, UrlPathHelper urlPathHelper,
PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch,
List<String> fileExtensions) {
this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns));
this.pathHelper = (urlPathHelper != null ? urlPathHelper : new UrlPathHelper());
this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher());
this.useSuffixPatternMatch = useSuffixPatternMatch;
this.useTrailingSlashMatch = useTrailingSlashMatch;
if (fileExtensions != null) {
for (String fileExtension : fileExtensions) {
if (fileExtension.charAt(0) != '.') {
fileExtension = "." + fileExtension;
}
this.fileExtensions.add(fileExtension);
}
}
}
示例4: getInterceptorsForPath
import org.springframework.util.PathMatcher; //導入依賴的package包/類
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) {
PathMatcher pathMatcher = new AntPathMatcher();
List<HandlerInterceptor> result = new ArrayList<HandlerInterceptor>();
for (Object interceptor : this.registry.getInterceptors()) {
if (interceptor instanceof MappedInterceptor) {
MappedInterceptor mappedInterceptor = (MappedInterceptor) interceptor;
if (mappedInterceptor.matches(lookupPath, pathMatcher)) {
result.add(mappedInterceptor.getInterceptor());
}
}
else if (interceptor instanceof HandlerInterceptor) {
result.add((HandlerInterceptor) interceptor);
}
else {
fail("Unexpected interceptor type: " + interceptor.getClass().getName());
}
}
return result;
}
示例5: onSimpleBrockedMessageChannel
import org.springframework.util.PathMatcher; //導入依賴的package包/類
@Autowired
@Qualifier("simpleBrokerMessageHandler")
public void onSimpleBrockedMessageChannel(AbstractBrokerMessageHandler handler) {
// here we try to inherit matcher from subscription registry
if (!(handler instanceof SimpleBrokerMessageHandler)) {
return;
}
SubscriptionRegistry registry = ((SimpleBrokerMessageHandler) handler).getSubscriptionRegistry();
if (!(registry instanceof DefaultSubscriptionRegistry)) {
return;
}
PathMatcher pathMatcher = ((DefaultSubscriptionRegistry) registry).getPathMatcher();
if(pathMatcher != null) {
this.pathMatcher = pathMatcher;
}
}
示例6: PatternsRequestCondition
import org.springframework.util.PathMatcher; //導入依賴的package包/類
/**
* Private constructor accepting a collection of patterns.
*/
private PatternsRequestCondition(Collection<String> patterns, UrlPathHelper urlPathHelper,
PathMatcher pathMatcher, boolean useSuffixPatternMatch, boolean useTrailingSlashMatch,
List<String> fileExtensions) {
this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns));
this.pathHelper = urlPathHelper != null ? urlPathHelper : new UrlPathHelper();
this.pathMatcher = pathMatcher != null ? pathMatcher : new AntPathMatcher();
this.useSuffixPatternMatch = useSuffixPatternMatch;
this.useTrailingSlashMatch = useTrailingSlashMatch;
if (fileExtensions != null) {
for (String fileExtension : fileExtensions) {
if (fileExtension.charAt(0) != '.') {
fileExtension = "." + fileExtension;
}
this.fileExtensions.add(fileExtension);
}
}
}
示例7: getInterceptorsForPath
import org.springframework.util.PathMatcher; //導入依賴的package包/類
private List<HandlerInterceptor> getInterceptorsForPath(String lookupPath) {
PathMatcher pathMatcher = new AntPathMatcher();
List<HandlerInterceptor> result = new ArrayList<HandlerInterceptor>();
for (Object i : registry.getInterceptors()) {
if (i instanceof MappedInterceptor) {
MappedInterceptor mappedInterceptor = (MappedInterceptor) i;
if (mappedInterceptor.matches(lookupPath, pathMatcher)) {
result.add(mappedInterceptor.getInterceptor());
}
}
else if (i instanceof HandlerInterceptor){
result.add((HandlerInterceptor) i);
}
else {
fail("Unexpected interceptor type: " + i.getClass().getName());
}
}
return result;
}
示例8: hasMatch
import org.springframework.util.PathMatcher; //導入依賴的package包/類
private boolean hasMatch(PathMatcher pathMatcher, String path,
List<String> patterns) {
for (String pattern : patterns) {
if (pathMatcher.match(pattern, path)) {
return true;
}
}
return false;
}
示例9: findMatchingResources
import org.springframework.util.PathMatcher; //導入依賴的package包/類
public static Set<Resource> findMatchingResources(
Resource rootResource, String locationPattern, PathMatcher pathMatcher) throws IOException {
Object root = VfsPatternUtils.findRoot(rootResource.getURL());
PatternVirtualFileVisitor visitor =
new PatternVirtualFileVisitor(VfsPatternUtils.getPath(root), locationPattern, pathMatcher);
VfsPatternUtils.visit(root, visitor);
return visitor.getResources();
}
示例10: mvcResourceUrlProvider
import org.springframework.util.PathMatcher; //導入依賴的package包/類
@Bean
public ResourceUrlProvider mvcResourceUrlProvider() {
ResourceUrlProvider urlProvider = new ResourceUrlProvider();
UrlPathHelper pathHelper = getPathMatchConfigurer().getUrlPathHelper();
if (pathHelper != null) {
urlProvider.setUrlPathHelper(pathHelper);
}
PathMatcher pathMatcher = getPathMatchConfigurer().getPathMatcher();
if (pathMatcher != null) {
urlProvider.setPathMatcher(pathMatcher);
}
return urlProvider;
}
示例11: mvcPathMatcher
import org.springframework.util.PathMatcher; //導入依賴的package包/類
/**
* Return a global {@link PathMatcher} instance for path matching
* patterns in {@link HandlerMapping}s.
* This instance can be configured using the {@link PathMatchConfigurer}
* in {@link #configurePathMatch(PathMatchConfigurer)}.
* @since 4.1
*/
@Bean
public PathMatcher mvcPathMatcher() {
if (getPathMatchConfigurer().getPathMatcher() != null) {
return getPathMatchConfigurer().getPathMatcher();
}
else {
return new AntPathMatcher();
}
}
示例12: addInterceptorsWithCustomPathMatcher
import org.springframework.util.PathMatcher; //導入依賴的package包/類
@Test
public void addInterceptorsWithCustomPathMatcher() {
PathMatcher pathMatcher = Mockito.mock(PathMatcher.class);
this.registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").pathMatcher(pathMatcher);
MappedInterceptor mappedInterceptor = (MappedInterceptor) this.registry.getInterceptors().get(0);
assertSame(pathMatcher, mappedInterceptor.getPathMatcher());
}
示例13: defaultPathMatchConfiguration
import org.springframework.util.PathMatcher; //導入依賴的package包/類
@Test
public void defaultPathMatchConfiguration() throws Exception {
ApplicationContext context = initContext(WebConfig.class);
UrlPathHelper urlPathHelper = context.getBean(UrlPathHelper.class);
PathMatcher pathMatcher = context.getBean(PathMatcher.class);
assertNotNull(urlPathHelper);
assertNotNull(pathMatcher);
assertEquals(AntPathMatcher.class, pathMatcher.getClass());
}
示例14: configurePathMatch
import org.springframework.util.PathMatcher; //導入依賴的package包/類
@Test
public void configurePathMatch() throws Exception {
final PathMatcher pathMatcher = mock(PathMatcher.class);
final UrlPathHelper pathHelper = mock(UrlPathHelper.class);
List<WebMvcConfigurer> configurers = new ArrayList<WebMvcConfigurer>();
configurers.add(new WebMvcConfigurerAdapter() {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseRegisteredSuffixPatternMatch(true)
.setUseTrailingSlashMatch(false)
.setUrlPathHelper(pathHelper)
.setPathMatcher(pathMatcher);
}
});
delegatingConfig.setConfigurers(configurers);
RequestMappingHandlerMapping handlerMapping = delegatingConfig.requestMappingHandlerMapping();
assertNotNull(handlerMapping);
assertEquals("PathMatchConfigurer should configure RegisteredSuffixPatternMatch",
true, handlerMapping.useRegisteredSuffixPatternMatch());
assertEquals("PathMatchConfigurer should configure SuffixPatternMatch",
true, handlerMapping.useSuffixPatternMatch());
assertEquals("PathMatchConfigurer should configure TrailingSlashMatch",
false, handlerMapping.useTrailingSlashMatch());
assertEquals("PathMatchConfigurer should configure UrlPathHelper",
pathHelper, handlerMapping.getUrlPathHelper());
assertEquals("PathMatchConfigurer should configure PathMatcher",
pathMatcher, handlerMapping.getPathMatcher());
}
示例15: findMatchingResources
import org.springframework.util.PathMatcher; //導入依賴的package包/類
public static Set<Resource> findMatchingResources(
URL rootDirURL, String locationPattern, PathMatcher pathMatcher) throws IOException {
Object root = VfsPatternUtils.findRoot(rootDirURL);
PatternVirtualFileVisitor visitor =
new PatternVirtualFileVisitor(VfsPatternUtils.getPath(root), locationPattern, pathMatcher);
VfsPatternUtils.visit(root, visitor);
return visitor.getResources();
}