Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fold RenderableResource into ReadableResource #18

Merged
merged 2 commits into from
Apr 19, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.net.URI;

import static com.theoryinpractise.halbuilder.impl.api.Support.WHITESPACE_SPLITTER;
import static java.lang.String.format;
Expand Down Expand Up @@ -51,6 +52,17 @@ public MutableResource withLink(String href, String rel) {
return this;
}

/**
* Add a link to this resource
* @param uri The target URI for the link, possibly relative to the href of
* this resource.
* @param rel
* @return
*/
public MutableResource withLink(URI uri, String rel) {
return withLink(uri.toASCIIString(), rel);
}

/**
* Add a link to this resource
* @param href The target href for the link, relative to the href of this resource.
Expand All @@ -68,11 +80,22 @@ public MutableResource withLink(String href, String rel, Predicate<ReadableResou

/**
* Add a link to this resource
* @param href The target href for the link, relative to the href of this resource.
* @param uri The target URI for the link, possibly relative to the href of
* this resource.
* @param rel
* @return
*/
public MutableResource withLink(String href, String rel, Optional<Predicate<ReadableResource>> predicate, Optional<String> name, Optional<String> title, Optional<String> hreflang) {
public MutableResource withLink(URI uri, String rel, Predicate<ReadableResource> predicate) {
return withLink(uri.toASCIIString(), rel, predicate);
}

/**
* Add a link to this resource
* @param href The target href for the link, relative to the href of this resource.
* @param rel
* @return
*/
public MutableResource withLink(String href, String rel, Optional<Predicate<ReadableResource>> predicate, Optional<String> name, Optional<String> title, Optional<String> hreflang) {
if (predicate.or(Predicates.<ReadableResource>alwaysTrue()).apply(this)) {
String resolvedHref = resolvableUri.matcher(href).matches() ? resolveRelativeHref(href) : href;
for (String reltype : WHITESPACE_SPLITTER.split(rel)) {
Expand All @@ -84,6 +107,17 @@ public MutableResource withLink(String href, String rel, Optional<Predicate<Read
return this;
}

/**
* Add a link to this resource
* @param uri The target URI for the link, possibly relative to the href of
* this resource.
* @param rel
* @return
*/
public MutableResource withLink(URI uri, String rel, Optional<Predicate<ReadableResource>> predicate, Optional<String> name, Optional<String> title, Optional<String> hreflang) {
return withLink(uri.toASCIIString(), rel, predicate, name, title, hreflang);
}

public Resource withProperty(String name, Object value) {
if (properties.containsKey(name)) {
throw new ResourceException(format("Duplicate property '%s' found for resource", name));
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/theoryinpractise/halbuilder/spi/Resource.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package com.theoryinpractise.halbuilder.spi;

import java.net.URI;

import com.google.common.base.Optional;
import com.google.common.base.Predicate;

public interface Resource extends ReadableResource {

Resource withLink(String url, String rel);
Resource withLink(String href, String rel);

Resource withLink(URI uri, String rel);

Resource withLink(String url, String rel, Predicate<ReadableResource> predicate);
Resource withLink(String href, String rel, Predicate<ReadableResource> predicate);

Resource withLink(URI uri, String rel, Predicate<ReadableResource> predicate);

Resource withLink(String href, String rel, Optional<Predicate<ReadableResource>> predicate, Optional<String> name, Optional<String> title, Optional<String> hreflang);

Resource withLink(URI uri, String rel, Optional<Predicate<ReadableResource>> predicate, Optional<String> name, Optional<String> title, Optional<String> hreflang);

Resource withProperty(String name, Object value);

Resource withBean(Object value);
Expand Down