/** * Set the prefix portion of the URL which is to be pre-pended to the URL * pattern. * <p/> * Optional, as the URL pattern may contain everything. However, this is * provided as a convenience so consumers don't have to perform their own * concatenation to pass in the entire URL pattern string to the constructor. * <p/> * For example: 'http://www.example.com:8080' * * @param baseUrl the string that will prefix the URL pattern * @return this LinkBuilder instance to facilitate method chaining. */ public DefaultLinkBuilder baseUrl(String url) { urlBuilder.baseUrl(url); return this; }
/** * Remove the query-string segments from this UrlBuilder. */ public void clearQueries() { urlBuilder.clearQueries(); }
public DefaultLinkBuilder(DefaultLinkBuilder that) { super(); this.urlBuilder = that.urlBuilder.clone(); this.attributes = new HashMap<String, String>(that.attributes); }
/** * Build a Link instance. * * @param tokenResolver a TokenResolver with token bindings. * @return a new Link instance * @throws LinkBuilderException if the LinkBuilder is in a state to build an invalid * LinkDefintion. */ public Link build(Object object, TokenResolver tokenResolver) { return createLink(urlBuilder.build(object, tokenResolver)); }
public DefaultLinkBuilder urlPattern(String pattern) { urlBuilder.urlPattern(pattern); return this; }
/** * Add an optional query-string segment to this LinkBuilder. * <p/> * If all of the tokens in the query-string are bound, the segment is included * in the generated URL string during build(). However, if there are unbound * tokens in the resulting query-string segment, it is not included in the * generated URL string. * <p/> * Do not include any question mark ("?") or ampersand ("&") in the query-string * segment. * * @param query a query-string segment to optionally include. * @return this LinkBuilder instance to facilitate method chaining. */ public DefaultLinkBuilder withQuery(String query) { urlBuilder.withQuery(query); return this; }
public Link build(TokenResolver tokenResolver) { return createLink(urlBuilder.build(tokenResolver)); }
/** * Retrieve the URL pattern associated with this link builder. * * @return the URL pattern or null. */ public String urlPattern() { return urlBuilder.urlPattern(); }
public Blog create(Request request, Response response) { Blog blog = request.getBodyAs(Blog.class, "Blog details not provided"); ValidationEngine.validateAndThrow(blog); Blog saved = blogs.create(blog); // Construct the response for create... response.setResponseCreated(); // Include the Location header... String locationPattern = request.getNamedUrl(HttpMethod.GET, Constants.Routes.BLOG_ENTRY_READ_ROUTE); response.addLocationHeader(LOCATION_BUILDER.build(locationPattern, new DefaultTokenResolver())); // Return the newly-created item... return saved; }
public BlogEntry create(Request request, Response response) { String blogId = request.getHeader(Constants.Url.BLOG_ID_PARAMETER, "No Blog ID provided"); BlogEntry blogEntry = request.getBodyAs(BlogEntry.class, "BlogEntry details not provided"); Blog blog = blogs.read(UUID.parse(blogId)); blogEntry.setBlogId(blog.getUuid()); ValidationEngine.validateAndThrow(blogEntry); BlogEntry saved = blogEntries.create(blogEntry); // Construct the response for create... response.setResponseCreated(); // Include the Location header... String locationPattern = request.getNamedUrl(HttpMethod.GET, Constants.Routes.BLOG_ENTRY_READ_ROUTE); response.addLocationHeader(LOCATION_BUILDER.build(locationPattern, new DefaultTokenResolver())); // Return the newly-created item... return saved; }
public Comment create(Request request, Response response) { Comment comment = request.getBodyAs(Comment.class, "Comment details not provided"); String blogId = request.getHeader(Constants.Url.BLOG_ID_PARAMETER, "Blog ID not provided"); String blogEntryId = request.getHeader(Constants.Url.BLOG_ENTRY_ID_PARAMETER, "Blog Entry ID not provided"); Blog blog = blogs.read(UUID.parse(blogId)); BlogEntry entry = entries.read(UUID.parse(blogEntryId)); comment.setBlogEntryId(entry.getUuid()); ValidationEngine.validateAndThrow(comment); Comment saved = comments.create(comment); // Construct the response for create... response.setResponseCreated(); // Bind the resource with link URL tokens, etc. here... TokenResolver resolver = HyperExpress.bind(Constants.Url.BLOG_ID_PARAMETER, UUID.format(blog.getUuid())); // Include the Location header... String locationPattern = request.getNamedUrl(HttpMethod.GET, Constants.Routes.COMMENT_READ_ROUTE); response.addLocationHeader(LOCATION_BUILDER.build(locationPattern, resolver)); // Return the newly-created item... return saved; }