Java 类org.springframework.util.PathMatcher 实例源码

项目:spring4-understanding    文件:AbstractMessageBrokerConfiguration.java   
@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;
}
项目:spring4-understanding    文件:DestinationPatternsMessageCondition.java   
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;
}
项目:spring4-understanding    文件:PatternsRequestCondition.java   
/**
 * 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);
        }
    }
}
项目:spring4-understanding    文件:InterceptorRegistryTests.java   
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;
}
项目:haven-platform    文件:EventRouter.java   
@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;
    }
}
项目:class-guard    文件:PatternsRequestCondition.java   
/**
 * 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);
        }
    }
}
项目:class-guard    文件:InterceptorRegistryTests.java   
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;
}
项目:artifactory-resource    文件:PathFilter.java   
private boolean hasMatch(PathMatcher pathMatcher, String path,
        List<String> patterns) {
    for (String pattern : patterns) {
        if (pathMatcher.match(pattern, path)) {
            return true;
        }
    }
    return false;
}
项目:spring4-understanding    文件:PathMatchingResourcePatternResolver.java   
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();
}
项目:spring4-understanding    文件:WebMvcConfigurationSupport.java   
@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;
}
项目:spring4-understanding    文件:WebMvcConfigurationSupport.java   
/**
 * 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();
    }
}
项目:spring4-understanding    文件:InterceptorRegistryTests.java   
@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());
}
项目:spring4-understanding    文件:WebMvcConfigurationSupportTests.java   
@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());
}
项目:spring4-understanding    文件:DelegatingWebMvcConfigurationTests.java   
@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());
}
项目:spring    文件:PathMatchingResourcePatternResolver.java   
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();
}
项目:spring-cors-filter    文件:CORSFilter.java   
boolean matchPath(Set<PathMatcher> matchers, HttpServletRequest request) {
    for (PathMatcher matcher : matchers) {
        if (matcher.isPattern(request.getPathInfo())) {
            return true;
        }
    }
    return false;
}
项目:spring-cloud-bus    文件:BusAutoConfiguration.java   
@BusPathMatcher
// There is a @Bean of type PathMatcher coming from Spring MVC
@ConditionalOnMissingBean(name = BusAutoConfiguration.BUS_PATH_MATCHER_NAME)
@Bean(name = BusAutoConfiguration.BUS_PATH_MATCHER_NAME)
public PathMatcher busPathMatcher() {
    return new DefaultBusPathMatcher(new AntPathMatcher(":"));
}
项目:wampspring    文件:DefaultWampConfiguration.java   
/**
 * Returns an instance of a {@link PathMatcher}. Used by the messageHandlers for
 * matching the topicURI to a destination
 */
protected PathMatcher pathMatcher() {
    if (this.internalPathMatcher == null) {
        this.internalPathMatcher = new AntPathMatcher();
    }
    return this.internalPathMatcher;
}
项目:wampspring    文件:WampAnnotationMethodMessageHandler.java   
public WampAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
        MessageChannel clientOutboundChannel, EventMessenger eventMessenger,
        ConversionService conversionService,
        MethodParameterConverter methodParameterConverter, PathMatcher pathMatcher,
        WampMessageSelector wampMessageSelector, MessageConverter messageConverter) {
    this.clientInboundChannel = clientInboundChannel;
    this.clientOutboundChannel = clientOutboundChannel;
    this.eventMessenger = eventMessenger;
    this.conversionService = conversionService;
    this.methodParameterConverter = methodParameterConverter;
    this.pathMatcher = pathMatcher;
    this.wampMessageSelector = wampMessageSelector;
    this.messageConverter = messageConverter;
}
项目:wampspring    文件:DestinationPatternsMessageCondition.java   
private DestinationPatternsMessageCondition(Collection<String> patterns,
        PathMatcher pathMatcher) {
    Assert.notNull(pathMatcher, "pathMatcher is required");

    this.pathMatcher = pathMatcher;
    this.patterns = Collections.unmodifiableSet(new LinkedHashSet<>(patterns));
}
项目:class-guard    文件:PathMatchingResourcePatternResolver.java   
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();
}
项目:spring-cloud-aws    文件:PathMatchingSimpleStorageResourcePatternResolverTest.java   
@Test
public void testWithCustomPathMatcher() throws Exception {
    AmazonS3 amazonS3 = mock(AmazonS3.class);
    PathMatcher pathMatcher = mock(PathMatcher.class);

    PathMatchingSimpleStorageResourcePatternResolver patternResolver = new PathMatchingSimpleStorageResourcePatternResolver(amazonS3,
            new SimpleStorageResourceLoader(amazonS3),
            new PathMatchingResourcePatternResolver());
    patternResolver.setPathMatcher(pathMatcher);

    patternResolver.getResources("s3://foo/bar");

    verify(pathMatcher, times(1)).isPattern("foo/bar");
}
项目:geomajas-project-server    文件:ResourceServlet.java   
private boolean isAllowed(String resourcePath) {
    if (resourcePath.matches(PROTECTED_PATH)) {
        return false;
    }
    PathMatcher pathMatcher = new AntPathMatcher();
    for (String pattern : allowedResourcePaths) {
        if (pathMatcher.match(pattern, resourcePath)) {
            return true;
        }
    }
    return false;
}
项目:geomajas-project-server    文件:ResourceController.java   
private boolean isAllowed(String resourcePath) {
    if (resourcePath.matches(PROTECTED_PATH)) {
        return false;
    }
    PathMatcher pathMatcher = new AntPathMatcher();
    for (String pattern : (allowedResourcePaths == null ? ALLOWED_RESOURCE_PATHS : allowedResourcePaths)) {
        if (pathMatcher.match(pattern, resourcePath)) {
            return true;
        }
    }
    return false;
}
项目:egovframework.rte.root    文件:ExceptionTransfer.java   
/**
 * 발생한 Exception 에 따라 후처리 로직이 실행할 수 있도록 연결하는 역할을 수행한다.
 * 
 * @param clazz Exception 발생 클래스 
 * @param methodName Exception 발생 메소드명 
 * @param exception 발생한 Exception 
 * @param pm 발생한 PathMatcher(default : AntPathMatcher) 
 * @param exceptionHandlerServices[] 등록되어 있는 ExceptionHandlerService 리스트
 */
protected void processHandling(Class clazz, String methodName, Exception exception, PathMatcher pm,
                               ExceptionHandlerService[] exceptionHandlerServices) {
    try {
        for (ExceptionHandlerService ehm : exceptionHandlerServices) {

            if (!ehm.hasReqExpMatcher())
                ehm.setReqExpMatcher(pm);
            ehm.setPackageName(clazz.getCanonicalName()+"."+methodName);
            ehm.run(exception);

        }
    } catch (Exception e) {
    }
}
项目:SpringMango    文件:MyAuthenticationEntryPoint.java   
public PathMatcher getPathMatcher() {
    return pathMatcher;
}
项目:SpringMango    文件:MyAuthenticationEntryPoint.java   
public void setPathMatcher(PathMatcher pathMatcher) {
    this.pathMatcher = pathMatcher;
}
项目:gemini.blueprint    文件:OsgiBundleResourcePatternResolver.java   
/**
 * Searches for the given pattern inside the imported bundle. This translates to pattern matching on the imported
 * packages.
 * 
 * @param importedBundle imported bundle
 * @param path path used for pattern matching
 * @param foundPaths collection of found results
 */
@SuppressWarnings("unchecked")
private void findImportedBundleMatchingResource(final ImportedBundle importedBundle, String rootPath, String path,
        final Collection<String> foundPaths) throws IOException {

    final boolean trace = logger.isTraceEnabled();

    String[] packages = importedBundle.getImportedPackages();

    if (trace)
        logger.trace("Searching path [" + path + "] on imported pkgs " + ObjectUtils.nullSafeToString(packages)
                + "...");

    final boolean startsWithSlash = rootPath.startsWith(FOLDER_SEPARATOR);

    for (int i = 0; i < packages.length; i++) {
        // transform the package name into a path
        String pkg = packages[i].replace(DOT, SLASH) + SLASH;

        if (startsWithSlash) {
            pkg = FOLDER_SEPARATOR + pkg;
        }

        final PathMatcher matcher = getPathMatcher();
        // if the imported package matches the path
        if (matcher.matchStart(path, pkg)) {
            Bundle bundle = importedBundle.getBundle();
            // 1. look at the Bundle jar root
            Enumeration<String> entries = bundle.getEntryPaths(pkg);
            while (entries != null && entries.hasMoreElements()) {
                String entry = entries.nextElement();
                if (startsWithSlash)
                    entry = FOLDER_SEPARATOR + entry;

                if (matcher.match(path, entry)) {
                    if (trace)
                        logger.trace("Found entry [" + entry + "]");
                    foundPaths.add(entry);
                }
            }
            // 2. Do a Bundle-Classpath lookup (since the jar might use a different classpath)
            Collection<String> cpMatchingPaths = findBundleClassPathMatchingPaths(bundle, path);
            foundPaths.addAll(cpMatchingPaths);
        }
    }
}
项目:item-shop-reactive-backend    文件:PathMatcherServerWebExchangeMatcher.java   
public void setPathMatcher(PathMatcher pathMatcher) {
    Assert.notNull(pathMatcher, "pathMatcher cannot be null");
    this.pathMatcher = pathMatcher;
}
项目:minsx-java-example    文件:RegexA.java   
public static  boolean matcherAnt(String reg,String str){
    PathMatcher matcher = new AntPathMatcher();
     return matcher.match(reg, str);
}
项目:FastBootWeixin    文件:WxMappingInfo.java   
public void setPathMatcher(PathMatcher pathMatcher) {
    this.pathMatcher = pathMatcher;
}
项目:FastBootWeixin    文件:WxMappingInfo.java   
public PathMatcher getPathMatcher() {
    return this.pathMatcher;
}
项目:spring4-understanding    文件:SimpAnnotationMethodMessageHandler.java   
/**
 * Set the PathMatcher implementation to use for matching destinations
 * against configured destination patterns.
 * <p>By default, {@link AntPathMatcher} is used.
 */
public void setPathMatcher(PathMatcher pathMatcher) {
    Assert.notNull(pathMatcher, "PathMatcher must not be null");
    this.pathMatcher = pathMatcher;
    this.slashPathSeparator = this.pathMatcher.combine("a", "a").equals("a/a");
}
项目:spring4-understanding    文件:SimpAnnotationMethodMessageHandler.java   
/**
 * Return the PathMatcher implementation to use for matching destinations.
 */
public PathMatcher getPathMatcher() {
    return this.pathMatcher;
}
项目:spring4-understanding    文件:DefaultSubscriptionRegistry.java   
/**
 * Specify the {@link PathMatcher} to use.
 */
public void setPathMatcher(PathMatcher pathMatcher) {
    this.pathMatcher = pathMatcher;
}
项目:spring4-understanding    文件:DefaultSubscriptionRegistry.java   
/**
 * Return the configured {@link PathMatcher}.
 */
public PathMatcher getPathMatcher() {
    return this.pathMatcher;
}
项目:spring4-understanding    文件:SimpleBrokerMessageHandler.java   
/**
 * When configured, the given PathMatcher is passed down to the
 * SubscriptionRegistry to use for matching destination to subscriptions.
 */
public void setPathMatcher(PathMatcher pathMatcher) {
    this.pathMatcher = pathMatcher;
    initPathMatcherToUse();
}
项目:spring4-understanding    文件:MessageBrokerRegistry.java   
protected PathMatcher getPathMatcher() {
    return this.pathMatcher;
}
项目:spring4-understanding    文件:DestinationPatternsMessageCondition.java   
private DestinationPatternsMessageCondition(Collection<String> patterns, PathMatcher pathMatcher) {
    this.pathMatcher = (pathMatcher != null ? pathMatcher : new AntPathMatcher());
    this.patterns = Collections.unmodifiableSet(prependLeadingSlash(patterns, this.pathMatcher));
}
项目:spring4-understanding    文件:PathMatchingResourcePatternResolver.java   
/**
 * Return the PathMatcher that this resource pattern resolver uses.
 */
public PathMatcher getPathMatcher() {
    return this.pathMatcher;
}