本文整理匯總了Java中org.springframework.web.util.UriTemplate.expand方法的典型用法代碼示例。如果您正苦於以下問題:Java UriTemplate.expand方法的具體用法?Java UriTemplate.expand怎麽用?Java UriTemplate.expand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.util.UriTemplate
的用法示例。
在下文中一共展示了UriTemplate.expand方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: expand
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
/**
* Generates an instance of the URI according to the template given by uriTemplate, by expanding the variables
* with the values provided by keyValues.
*
* @param uriTemplate
* The URI template
* @param keyValues
* Dynamic list of string of the form "key:value"
* @return The corresponding URI instance
*/
public static URI expand(final String uriTemplate, final String... keyValues) {
UriTemplate template = new UriTemplate(uriTemplate);
Map<String, String> uriVariables = new HashMap<>();
for (String kv : keyValues) {
String[] keyValue = kv.split(":");
uriVariables.put(keyValue[0], keyValue[1]);
}
return template.expand(uriVariables);
}
示例2: actionPerformed
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
JComponent c = (JComponent) e.getSource();
final Object urlTemplate = c.getClientProperty(PROP_REFERENCE_TEMPLATE_URL);
if (urlTemplate != null && currentBootVersion != null) {
try {
UriTemplate template = new UriTemplate(urlTemplate.toString());
final URI uri = template.expand(currentBootVersion);
HtmlBrowser.URLDisplayer.getDefault().showURL(uri.toURL());
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
}
}
}
示例3: apply
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
public GatewayFilter apply(String template) {
UriTemplate uriTemplate = new UriTemplate(template);
return (exchange, chain) -> {
PathMatchInfo variables = exchange.getAttribute(URI_TEMPLATE_VARIABLES_ATTRIBUTE);
ServerHttpRequest req = exchange.getRequest();
addOriginalRequestUrl(exchange, req.getURI());
Map<String, String> uriVariables;
if (variables != null) {
uriVariables = variables.getUriVariables();
} else {
uriVariables = Collections.emptyMap();
}
URI uri = uriTemplate.expand(uriVariables);
String newPath = uri.getPath();
exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri);
ServerHttpRequest request = req.mutate()
.path(newPath)
.build();
return chain.filter(exchange.mutate().request(request).build());
};
}
示例4: testMatch
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
/**
* Test match.
*/
@Test
public void testMatch(){
// 完全路徑url方式路徑匹配
// String requestPath="http://localhost:8080/pub/login.jsp";//請求路徑
// String patternPath="**/login.jsp";//路徑匹配模式
// 不完整路徑uri方式路徑匹配
// String requestPath="/app/pub/login.do";//請求路徑
// String patternPath="/**/login.do";//路徑匹配模式
// 模糊路徑方式匹配
// String requestPath="/app/pub/login.do";//請求路徑
// String patternPath="/**/*.do";//路徑匹配模式
// 包含模糊單字符路徑匹配
String requestPath = "/2-5-3-13-1.htm";// 請求路徑
String patternPath = "/{c1}-{c2}-{c3}-{c4}.htm";// 路徑匹配模式
requestPath = "/c2-5-3-11-pige-黑-52-chuck taylor all star-vintage.htm";// 請求路徑
patternPath = "/c{categoryCode}-{material}-{color}-{size}-{kind}-{style}.htm";// 路徑匹配模式
requestPath = "/s/c-m-c-s-k-s-o.htm";// 請求路徑
patternPath = "/s/c{categoryCode}-m{material}-c{color}-s{size}-k{kind}-s{style}-o{order}.htm";// 路徑匹配模式
boolean result = PATH_MATCHER.match(patternPath, requestPath);
LOGGER.debug(result + "");
Map<String, String> map = PATH_MATCHER.extractUriTemplateVariables(patternPath, requestPath);
LOGGER.debug("map:{}", JsonUtil.format(map));
map.put("color", "XL");
UriTemplate uriTemplate = new UriTemplate(patternPath);
URI uri = uriTemplate.expand(map);
LOGGER.debug(uri.toString());
// UriComponents uriComponents = UriComponentsBuilder.fromPath(patternPath).buildAndExpand(map);
// LOGGER.debug(uriComponents.toString());
}
示例5: execute
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback,
ResponseExtractor<T> responseExtractor, Object... urlVariables) throws RestClientException {
UriTemplate uriTemplate = new HttpUrlTemplate(url);
URI expanded = uriTemplate.expand(urlVariables);
return doExecute(expanded, method, requestCallback, responseExtractor);
}
示例6: testNonEncodingOfUriTemplate
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
/**
* tests no double encoding of existing query parameter
*/
@Test
public void testNonEncodingOfUriTemplate() throws Exception {
OAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
UriTemplate uriTemplate = new UriTemplate("https://graph.facebook.com/fql?q={q}");
URI expanded = uriTemplate.expand("[q: fql]");
URI appended = restTemplate.appendQueryParameter(expanded, token);
assertEquals("https://graph.facebook.com/fql?q=%5Bq:%20fql%5D&bearer_token=12345", appended.toString());
}
示例7: getBuildResponse
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
@Override
public List<JenkinsBuildResponse> getBuildResponse() {
List<JenkinsBuildResponse> results = new ArrayList<>();
for(String name : names){
UriTemplate buildServerUriTemplate = new UriTemplate(JENKINS_URL);
URI buildServerUri = buildServerUriTemplate.expand(serverUrl, name);
results.add(restTemplate.getForObject(buildServerUri, JenkinsBuildResponse.class));
}
return results;
}
示例8: expand
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
/**
* 擴充模板值.
*
* <h3>示例:</h3>
*
* <blockquote>
*
* <pre class="code">
* String uriTemplatePath = "/s/c{categoryCode}-m{material}-c{color}-s{size}-k{kind}-s{style}-o{order}.htm";
*
* Map{@code <String, String>} map = new HashMap{@code <>}();
* map.put("color", "100");
* map.put("size", "L");
* </pre>
*
* <b>返回:</b>
*
* <pre class="code">
* /s/c-m-c<span style="color:red">100</span>-s<span style="color:red">L</span>-k-s-o.htm
* </pre>
*
* </blockquote>
*
* @param uriTemplatePath
* 模板
* @param map
* 變量-值 map <br>
* 如果 傳入的map 中的key 不在模板中,自動忽略<br>
* 即隻處理 模板中有的key
* @return the string
* @see #getVariableNames(String)
* @see org.springframework.web.util.UriTemplate
* @see org.springframework.web.util.UriTemplate#expand(Map)
*/
public static String expand(String uriTemplatePath,Map<String, String> map){
// 所有的變量
List<String> variableNames = getVariableNames(uriTemplatePath);
Map<String, String> opMap = newLinkedHashMap(variableNames.size());
// 基於變量 生成對應的 值空map
for (String variableName : variableNames){
opMap.put(variableName, null);//如果不設置默認值,那麽會拋出異常 java.lang.IllegalArgumentException: Map has no value for 'categoryCode'
}
MapUtil.putAllIfNotNull(opMap, map);
UriTemplate uriTemplate = new UriTemplate(uriTemplatePath);
URI uri = uriTemplate.expand(opMap);
return uri.toString();
}
示例9: initialize
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
@Override
public Project initialize(Path parentFolder, String identifier, ProjectVariables variables) throws ProjectInitializationException {
SpringBootProjectParams v = (SpringBootProjectParams) variables;
// @formatter:off
String url = springStarterProperties.getUrl()
+ "?name={artifactId}"
+ "&groupId=fr.sii"
+ "&artifactId={artifactId}"
+ "&version={version}"
+ "&description="
+ "&packageName=fr.sii.spring.boot.runtime.testing"
+ "&type={type}"
+ "&packaging=jar"
+ "&javaVersion={javaVersion}"
+ "&language=java"
+ "&bootVersion={springBootVersion}";
// @formatter:on
for (SpringBootDependency dependency : v.getSpringBootDependencies()) {
url += "&dependencies=" + dependency.getModule();
}
UriTemplate template = new UriTemplate(url);
URI expanded = template.expand(identifier,
identifier,
oghamProperties.getOghamVersion(),
v.getBuildTool().getType(),
v.getJavaVersion().getVersion(),
v.getSpringBootVersion());
log.debug("Starter resolved url: {}", expanded);
RequestEntity<Void> request = RequestEntity.get(expanded)
.header(USER_AGENT, "ogham/"+oghamProperties.getOghamVersion())
.build();
ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
if(response.getStatusCode().is2xxSuccessful()) {
try {
return new Project(unzip(response.getBody(), identifier, parentFolder), variables);
} catch(IOException | ZipException | RuntimeException e) {
throw new ProjectInitializationException("Failed to initialize Spring Boot project while trying to unzip Spring starter zip", e);
}
}
throw new ProjectInitializationException("Failed to download Spring starter zip");
}
示例10: childLocation
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
protected URI childLocation(StringBuffer parentUri, Object childId) {
UriTemplate uri = new UriTemplate(parentUri.append("/{childId}").toString());
return uri.expand(childId);
}
示例11: LocationHeaderImpl
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
public LocationHeaderImpl(String uriTemplate, Object... objects) {
UriTemplate uri = new UriTemplate(uriTemplate);
this.value = uri.expand(objects);
}
示例12: getPlanResponse
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
@Override
public BambooPlanResponse getPlanResponse() {
UriTemplate buildServerUriTemplate = new UriTemplate(BAMBOO_PLAN_URL);
URI buildServerUri = buildServerUriTemplate.expand(serverUrl, buildKey, username, password);
return restTemplate.getForObject(buildServerUri, BambooPlanResponse.class);
}
示例13: getResultResponse
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
@Override
public BambooResultResponse getResultResponse() {
UriTemplate buildServerUriTemplate = new UriTemplate(BAMBOO_RESULT_URL);
URI buildServerUri = buildServerUriTemplate.expand(serverUrl, buildKey, username, password);
return restTemplate.getForObject(buildServerUri, BambooResultResponse.class);
}
示例14: linkTo
import org.springframework.web.util.UriTemplate; //導入方法依賴的package包/類
public static ControllerProxyLinkBuilder linkTo(Class<?> controller, Method method, Object... parameters) {
Assert.notNull(controller, "Controller type must not be null!");
Assert.notNull(method, "Method must not be null!");
UriTemplate template = new UriTemplate(DISCOVERER.getMapping(controller, method));
URI uri = template.expand(parameters);
return new ControllerProxyLinkBuilder(getBuilder()).slash(uri);
}