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

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

Introduction

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

Prototype

public UriTemplate(String uriTemplate) 

Source Link

Document

Construct a new UriTemplate with the given URI String.

Usage

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

/**
 * 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//  w  w  w  . j a  v a  2s. co  m
 *            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);
}

From source file:org.zalando.github.spring.GithubApiUriUtil.java

public UriTemplate buildUriTemplate(String path) {
    return new UriTemplate(buildUriString(path));
}

From source file:org.zalando.github.spring.GithubApiUriUtil.java

public URI buildUri(String path, Map<String, Object> uriVariables) {
    return new UriTemplate(buildUriString(path)).expand(uriVariables);
}

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:net.eusashead.hateoas.hal.response.impl.OrderRepresentationWriter.java

@Override
public Representation write(Order t, RepresentationFactory factory) {
    return factory.newRepresentation(new UriTemplate("/order/{id}").expand(t.getId()))
            .withProperty("id", t.getId()).withProperty("total", t.getTotal())
            .withProperty("date", t.getDate());
}

From source file:net.eusashead.hateoas.response.impl.CustomerRepresentationWriter.java

@Override
public Representation write(Customer t, RepresentationFactory factory) {

    return factory.newRepresentation(new UriTemplate("/customer/{id}").expand(t.getId()))
            .withProperty("id", t.getId()).withProperty("total", t.getTotal())
            .withProperty("date", t.getDate());

}

From source file:org.zalando.github.spring.UriTemplateTest.java

@Test
public void checkParameters() {
    Map<String, Object> uriVariables = new HashMap<>();
    uriVariables.put("first", "eins");
    uriVariables.put("second", "zwei");
    uriVariables.put("bar", "baz");
    uriVariables.put("thing", "something");
    URI uri = new UriTemplate("http://example.org/{first}/path/{second}?foo={bar}&bar={thing}")
            .expand(uriVariables);//w  w w . j  a v  a  2  s  .  c o  m

    String uriString = uri.toString();
    Assertions.assertThat(uriString).contains("foo=baz");
    Assertions.assertThat(uriString).contains("bar=something");
    Assertions.assertThat(uriString).contains("eins/path/zwei");
    System.out.println(uri.toString());
}

From source file:com.bennavetta.appsite.processing.RewriteRule.java

@OnLoad
private void loadTemplates() {
    inputTemplate = new UriTemplate(inputPattern);
    outputTemplate = new UriTemplate(outputPattern);
}

From source file:com.springsource.greenhouse.account.WelcomeMailTransformerTest.java

@Test
public void welcomeMail() {
    WelcomeMailTransformer transformer = new WelcomeMailTransformer();

    Account account = new Account(1L, "Roy", "Clarkson", "rclarkson@vmware.com", "rclarkson",
            "http://foo.com/bar.jpg", new UriTemplate("http://greenhouse.springsource.org/members/{id}"));
    SimpleMailMessage welcomeMail = (SimpleMailMessage) transformer.welcomeMail(account);

    assertEquals("rclarkson@vmware.com", welcomeMail.getTo()[0]);
    assertEquals("Greenhouse <noreply@springsource.com>", welcomeMail.getFrom());
    assertEquals("Welcome to the Greenhouse!", welcomeMail.getSubject());
    String mailText = welcomeMail.getText();
    assertTrue(mailText.contains(/*from www. j a  va  2s .c om*/
            "View your member profile at:" + NEWLINE + "http://greenhouse.springsource.org/members/rclarkson"));
}

From source file:com.ge.predix.acs.rest.RestModelIdExtractor.java

/**
 * Constructor given URI template./*www  .j  a  v a 2  s  . com*/
 *
 * @param uriTemplateValue
 *            URI template used by the model
 */
public RestModelIdExtractor(final String uriTemplateValue) {
    this.uriTemplate = new UriTemplate(uriTemplateValue);
}