Example usage for org.springframework.web.util UriTemplate matches

List of usage examples for org.springframework.web.util UriTemplate matches

Introduction

In this page you can find the example usage for org.springframework.web.util UriTemplate matches.

Prototype

public boolean matches(@Nullable String uri) 

Source Link

Document

Indicate whether the given URI matches this template.

Usage

From source file:com.ge.predix.acs.commons.web.UriTemplateUtils.java

public static boolean isCanonicalMatch(final String uriTemplateDef, final String resourceUri) {
    String canonicalResourceURI = URI.create(resourceUri).normalize().toString();
    UriTemplate uriTemplate = new UriTemplate(appendTrailingSlash(uriTemplateDef));
    return uriTemplate.matches(appendTrailingSlash(canonicalResourceURI));
}

From source file:com.ge.predix.acs.service.policy.matcher.PolicyMatcherImplTest.java

private void doTestForURITemplateMatch(final String uriTemplate, final String uri,
        final Boolean uriTemplateExpectedMatch, final String[] varNames, final String[] varValues) {
    UriTemplate template = new UriTemplate(uriTemplate);
    Assert.assertEquals(template.matches(uri), uriTemplateExpectedMatch.booleanValue());

    Map<String, String> matchedVariables = template.match(uri);
    for (int i = 0; i < varNames.length; i++) {
        // skip variable match if name is "n/a"
        if (varNames[i].equals("n/a")) {
            continue;
        }//from   w  w  w.  j av a2  s  .c  o m

        Assert.assertEquals(matchedVariables.get(varNames[i]), varValues[i]);
        Assert.assertEquals(matchedVariables.get(varNames[i]), varValues[i]);
    }
}

From source file:org.craftercms.engine.controller.rest.RestScriptsController.java

protected String parseScriptUrlForVariables(SiteContext siteContext, String scriptUrl,
        Map<String, Object> variables) {
    ContentStoreService storeService = siteContext.getStoreService();
    if (!storeService.exists(siteContext.getContext(), scriptUrl) && urlTemplateScanner != null) {
        List<UriTemplate> urlTemplates = urlTemplateScanner.scan(siteContext);
        if (CollectionUtils.isNotEmpty(urlTemplates)) {
            for (UriTemplate template : urlTemplates) {
                if (template.matches(scriptUrl)) {
                    Map<String, String> pathVars = template.match(scriptUrl);
                    String actualScriptUrl = template.toString();

                    variables.put(GroovyScriptUtils.VARIABLE_PATH_VARS, pathVars);

                    return actualScriptUrl;
                }//w  w  w  .  ja v a 2 s .c o  m
            }
        }
    }

    return scriptUrl;
}