Skip to content

Commit

Permalink
getResource(entity) now calls convert(entity, String.class) to give d…
Browse files Browse the repository at this point in the history
…eveloper change to customize resource location based on entity's properties
  • Loading branch information
Paul Warren committed Jun 26, 2018
1 parent fb3fafe commit 5e0cb31
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,25 @@ public Resource getResource(SID id) {

@Override
public Resource getResource(S entity) {
Object contentId = BeanUtils.getFieldWithAnnotation(entity, ContentId.class);
Resource r = getResourceInternal(entity);
if (r != null) {
return r;
}

SID contentId = (SID) BeanUtils.getFieldWithAnnotation(entity, ContentId.class);
if (contentId == null) {
return null;
}
return getResourceInternal(contentId);
}

protected Resource getResourceInternal(Object id) {
protected Resource getResourceInternal(S entity) {
String location = conversion.convert(entity, String.class);
Resource resource = loader.getResource(location);
return resource;
}

protected Resource getResourceInternal(SID id) {
String location = conversion.convert(id, String.class);
Resource resource = loader.getResource(location);
return resource;
Expand Down Expand Up @@ -141,7 +152,7 @@ public void setContent(S property, InputStream content) {
public InputStream getContent(S property) {
if (property == null)
return null;
Object contentId = BeanUtils.getFieldWithAnnotation(property, ContentId.class);
SID contentId = (SID) BeanUtils.getFieldWithAnnotation(property, ContentId.class);
if (contentId == null)
return null;

Expand All @@ -165,7 +176,7 @@ public void unsetContent(S property) {
if (property == null)
return;

Object contentId = BeanUtils.getFieldWithAnnotation(property, ContentId.class);
SID contentId = (SID) BeanUtils.getFieldWithAnnotation(property, ContentId.class);
if (contentId == null)
return;

Expand Down

0 comments on commit 5e0cb31

Please sign in to comment.