List of usage examples for org.springframework.hateoas TemplateVariable TemplateVariable
public TemplateVariable(String name, TemplateVariable.VariableType type)
From source file:io.spring.initializr.web.mapper.InitializrMetadataV21JsonMapper.java
public InitializrMetadataV21JsonMapper() { this.dependenciesVariables = new TemplateVariables( new TemplateVariable("bootVersion", TemplateVariable.VariableType.REQUEST_PARAM)); }
From source file:io.spring.initializr.web.mapper.InitializrMetadataV2JsonMapper.java
public InitializrMetadataV2JsonMapper() { this.templateVariables = new TemplateVariables( new TemplateVariable("dependencies", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("packaging", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("javaVersion", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("language", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("bootVersion", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("groupId", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("artifactId", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("version", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("name", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("description", TemplateVariable.VariableType.REQUEST_PARAM), new TemplateVariable("packageName", TemplateVariable.VariableType.REQUEST_PARAM)); }
From source file:de.escalon.hypermedia.spring.PartialUriTemplate.java
/** * Creates a new {@link PartialUriTemplate} using the given template string. * * @param template must not be {@literal null} or empty. *///from www.j av a 2s . c o m public PartialUriTemplate(String template) { Assert.hasText(template, "Template must not be null or empty!"); Matcher matcher = VARIABLE_REGEX.matcher(template); // first group is the variable start without leading {: "", "/", "?", "#", // second group is the comma-separated name list without the trailing } of the variable int endOfPart = 0; while (matcher.find()) { // 0 is the current match, i.e. the entire variable expression int startOfPart = matcher.start(0); // add part before current match if (endOfPart < startOfPart) { final String partWithoutVariables = template.substring(endOfPart, startOfPart); final StringTokenizer stringTokenizer = new StringTokenizer(partWithoutVariables, "?", true); boolean inQuery = false; while (stringTokenizer.hasMoreTokens()) { final String token = stringTokenizer.nextToken(); if ("?".equals(token)) { inQuery = true; } else { if (!inQuery) { urlComponents.add(token); } else { urlComponents.add("?" + token); } variableIndices.add(Collections.<Integer>emptyList()); } } } endOfPart = matcher.end(0); // add current match as part final String variablePart = template.substring(startOfPart, endOfPart); urlComponents.add(variablePart); // collect variablesInPart and track for each part which variables it contains // group(1) is the variable head without the leading { TemplateVariable.VariableType type = TemplateVariable.VariableType.from(matcher.group(1)); // group(2) is the String[] names = matcher.group(2).split(","); List<Integer> variablesInPart = new ArrayList<Integer>(); for (String name : names) { TemplateVariable variable = new TemplateVariable(name, type); variablesInPart.add(variables.size()); variables.add(variable); variableNames.add(name); } variableIndices.add(variablesInPart); } // finish off remaining part if (endOfPart < template.length()) { urlComponents.add(template.substring(endOfPart)); variableIndices.add(Collections.<Integer>emptyList()); } }
From source file:com.github.hateoas.forms.affordance.PartialUriTemplate.java
/** * Creates a new {@link PartialUriTemplate} using the given template string. * * @param template must not be {@literal null} or empty. *//*w w w . j ava 2 s . c o m*/ public PartialUriTemplate(String template) { Assert.hasText(template, "Template must not be null or empty!"); Matcher matcher = VARIABLE_REGEX.matcher(template); // first group is the variable start without leading {: "", "/", "?", "#", // second group is the comma-separated name list without the trailing } of the variable int endOfPart = 0; while (matcher.find()) { // 0 is the current match, i.e. the entire variable expression int startOfPart = matcher.start(0); // add part before current match if (endOfPart < startOfPart) { final String partWithoutVariables = template.substring(endOfPart, startOfPart); final StringTokenizer stringTokenizer = new StringTokenizer(partWithoutVariables, "?", true); boolean inQuery = false; while (stringTokenizer.hasMoreTokens()) { final String token = stringTokenizer.nextToken(); if ("?".equals(token)) { inQuery = true; } else { if (!inQuery) { urlComponents.add(token); } else { urlComponents.add("?" + token); } variableIndices.add(Collections.<Integer>emptyList()); } } } endOfPart = matcher.end(0); // add current match as part final String variablePart = template.substring(startOfPart, endOfPart); urlComponents.add(variablePart); // collect variablesInPart and track for each part which variables it contains // group(1) is the variable head without the leading { TemplateVariable.VariableType type = TemplateVariable.VariableType.from(matcher.group(1)); // group(2) are the variable names String[] names = matcher.group(2).split(","); List<Integer> variablesInPart = new ArrayList<Integer>(); for (String name : names) { TemplateVariable variable = new TemplateVariable(name, type); variablesInPart.add(variables.size()); variables.add(variable); variableNames.add(name); } variableIndices.add(variablesInPart); } // finish off remaining part if (endOfPart < template.length()) { urlComponents.add(template.substring(endOfPart)); variableIndices.add(Collections.<Integer>emptyList()); } }