List of usage examples for org.springframework.web.util UriTemplate match
public Map<String, String> match(String uri)
From source file:com.ge.predix.acs.service.policy.matcher.UriTemplateVariableResolver.java
public String resolve(final String uri, final UriTemplate uriTemplate, final String uriTemplateVariableName) { Map<String, String> variables = uriTemplate.match(uri); return variables.get(uriTemplateVariableName); }
From source file:org.moserp.inventory.rest.BaseWebInventoryTest.java
public String getProductIdFromUri(String productURI) { UriTemplate uriTemplate = new UriTemplate("/products/{productId}"); Map<String, String> variables = uriTemplate.match(productURI); return variables.get("productId"); }
From source file:com.ge.predix.acs.commons.policy.condition.ResourceHandler.java
/** * @param pathVariable//from w w w . j ava 2 s . c o m * name of path parameter in the URL * @return path parameter value */ public String uriVariable(final String pathVariable) { if (StringUtils.isEmpty(this.resourceURITemplate) || StringUtils.isEmpty(this.resourceURI) || StringUtils.isEmpty(pathVariable)) { return ""; } UriTemplate template = new UriTemplate(this.resourceURITemplate); Map<String, String> match = template.match(this.resourceURI); String pathVariableValue = match.get(pathVariable); return pathVariableValue != null ? pathVariableValue : ""; }
From source file:org.moserp.facility.repository.FacilityUtil.java
public String getFacilityIdFromUri(String facilityUri) { UriTemplate uriTemplate = new UriTemplate("/facilities/{facilityId}"); Map<String, String> variables = uriTemplate.match(facilityUri); String facilityId = variables.get("facilityId"); return facilityId; }
From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceAdapter.java
/** * @param clientId//from w w w . ja v a 2 s.com * @param rp * @param uri * @param rm * @param visibility * @return {@link Resource} instance out of mapping, clientID, and resource URI. */ protected Resource prepareResource(String clientId, ResourceParameter rp, String uri, ResourceMapping rm, RESOURCE_VISIBILITY visibility) { Resource r = new Resource(); r.setAccessibleByOthers(rm.isAccessibleByOthers()); r.setApprovalRequired(rm.isApprovalRequired()); r.setAuthority(AUTHORITY.valueOf(rm.getAuthority().value())); r.setClientId(clientId); r.setResourceParameter(rp); UriTemplate template = new UriTemplate(rm.getUri()); Map<String, String> params = template.match(uri); template = new UriTemplate(rm.getDescription()); try { r.setDescription(URLDecoder.decode(template.expand(params).toString(), "utf8")); } catch (UnsupportedEncodingException e) { r.setDescription(rm.getDescription()); } template = new UriTemplate(rm.getName()); try { r.setName(URLDecoder.decode(template.expand(params).toString(), "utf8")); } catch (UnsupportedEncodingException e) { r.setName(rm.getName()); } r.setResourceType(rm.getId()); r.setResourceUri(uri); r.setVisibility(visibility); return r; }
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 www.j a v a 2 s . c om*/ Assert.assertEquals(matchedVariables.get(varNames[i]), varValues[i]); Assert.assertEquals(matchedVariables.get(varNames[i]), varValues[i]); } }
From source file:it.smartcommunitylab.aac.manager.ResourceManager.java
/** * @param clientId/*w ww . j av a 2 s . c o m*/ * @param rp * @param uri * @param rm * @param visibility * @return {@link Resource} instance out of mapping, clientID, and resource URI. */ protected Resource prepareResource(String clientId, ResourceParameter rp, String uri, ResourceMapping rm, RESOURCE_VISIBILITY visibility) { Resource r = new Resource(); r.setAccessibleByOthers(rm.isAccessibleByOthers()); r.setApprovalRequired(rm.isApprovalRequired()); r.setAuthority(AUTHORITY.valueOf(rm.getAuthority().value())); r.setClientId(clientId); r.setResourceParameter(rp); r.setRoles(rm.getRoles()); UriTemplate template = new UriTemplate(rm.getUri()); Map<String, String> params = template.match(uri); template = new UriTemplate(rm.getDescription()); try { r.setDescription(URLDecoder.decode(template.expand(params).toString(), "utf8")); } catch (UnsupportedEncodingException e) { r.setDescription(rm.getDescription()); } template = new UriTemplate(rm.getName()); try { r.setName(URLDecoder.decode(template.expand(params).toString(), "utf8")); } catch (UnsupportedEncodingException e) { r.setName(rm.getName()); } r.setResourceType(rm.getId()); r.setResourceUri(uri); r.setVisibility(visibility); return r; }
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 . java 2s . c o m*/ } } } return scriptUrl; }