UriTemplateUtil { public static String retainVariablesValue(String requestPath,String matchingPatternPath,String[] variableNames){ if (isNotNullOrEmpty(variableNames)){ Map<String, String> opMap = extractUriTemplateVariables(requestPath, matchingPatternPath); return expand(matchingPatternPath, MapUtil.getSubMap(opMap, variableNames)); } return expand(matchingPatternPath, Collections.<String, String> emptyMap()); } private  UriTemplateUtil(); static String getUriTemplateVariableValue(HttpServletRequest request,String pathVarName); static boolean hasPathVarName(HttpServletRequest request,String pathVarName); static Map<String, String> getUriTemplateVariables(HttpServletRequest request); static String getBestMatchingPattern(HttpServletRequest request); static String expandBestMatchingPattern(HttpServletRequest request,String variableName,String value); static String expandWithVariable(String requestPath,String matchingPatternPath,String variableName,String value); static String expandWithVariable(String matchingPatternPath,String variableName,String value); static String clearVariablesValue(String requestPath,String matchingPatternPath,String[] variableNames); static String retainVariablesValue(String requestPath,String matchingPatternPath,String[] variableNames); static String expand(String uriTemplatePath,Map<String, String> map); static List<String> getVariableNames(String uriTemplatePath);  }
@Test public void retainVariablesValue(){ String requestPath = "/s/c500-m60-cred-s-k-s100-o6.htm"; String matchingPatternPath = "/s/c{categoryCode}-m{material}-c{color}-s{size}-k{kind}-s{style}-o{order}.htm"; String[] variableNames = { "color", "style" }; LOGGER.debug(UriTemplateUtil.retainVariablesValue(requestPath, matchingPatternPath, variableNames)); LOGGER.debug(UriTemplateUtil.retainVariablesValue(requestPath, matchingPatternPath, null)); }