[Hippo-cms7-user] RESTful API Support - Plain JAX-RS Services

Chandan AGARWAL chandan.agarwal at smile-benelux.com
Tue Sep 25 18:42:04 CEST 2012


Hello everyone, 
I am using spring Rest template to extract the data from hippo using plain JAX-RS Services and displaying this data in the frontend using the rest client, I followed these tutorial s 
http://blog.jeroenreijn.com/2011/02/hippos-restful-jax-rs-component-support.html 
http://www.onehippo.org/7_7/library/concepts/rest/restful-api-support---plain-jax-rs-services.html 

I have a document type called ContentBlock which has one String and a image. 

This is the code which extracts all the documents of ContentBlock and converts it to a list of ContentBlockRepresentation 
@Path("/contentBlocks/") 
public class ContentBlockResource extends AbstractContentResource { 

@GET 
@Path("/") 
@Produces("text/xml") 
public CollectionContentBlockRepresentation getAllContentBlocks(@Context HttpServletRequest servletRequest, 
@Context HttpServletResponse servletResponse) { 

CollectionContentBlockRepresentation contentBlocks = new CollectionContentBlockRepresentation(); 

HstRequestContext requestContext = getRequestContext(servletRequest); 

try { 

String mountContentPath = requestContext.getResolvedMount().getMount().getContentPath(); 
Node mountContentNode = requestContext.getSession().getRootNode().getNode(PathUtils.normalizePath(mountContentPath)); 

HstQueryManager manager = getHstQueryManager(requestContext.getSession(), requestContext); 
HstQuery hstQuery = manager.createQuery(mountContentNode, ContentBlock.class, true); 
HstQueryResult result = hstQuery.execute(); 
HippoBeanIterator iterator = result.getHippoBeans(); 

while (iterator.hasNext()) { 
ContentBlock contentBlock = (ContentBlock) iterator.nextHippoBean(); 

if (contentBlock != null) { 
ContentBlockRepresentation contentBlockRep = new ContentBlockRepresentation(contentBlock.getTitle(), 
contentBlock.getDescription(), getImage(contentBlock.getImage())); 
contentBlocks.getContentBlocks().add(contentBlockRep); 
} 
} 

} catch (Exception e) { 
} 

return contentBlocks; 
} 

private ImageRepresentation getImage(HippoGalleryImageSetBean image) { 
if (image != null) { 
ImageRepresentation imageRepresentation = new ImageRepresentation(); 
imageRepresentation.setPath(image.getOriginal().getPath()); 
imageRepresentation.setFileName(image.getFileName()); 
return imageRepresentation; 
} else 
return null; 

} 

} 

@XmlRootElement(name = "contentBlock") 
public class ContentBlockRepresentation { 

private String title; 
private String description; 
private ImageRepresentation image; 

public ContentBlockRepresentation() { 
} 

public ContentBlockRepresentation(String title, String description, ImageRepresentation image) { 
this.title = title; 
this.description = description; 
this.image = image; 
} 

public String getTitle() { 
return title; 
} 

public void setTitle(String title) { 
this.title = title; 
} 

public String getDescription() { 
return description; 
} 

public void setDescription(String description) { 
this.description = description; 
} 

@XmlElement(name = "image") 
public ImageRepresentation getImage() { 
return image; 
} 

public void setImage(ImageRepresentation image) { 
this.image = image; 
} 

} 

@XmlRootElement(name = "image") 
public class ImageRepresentation { 

private String path; 
private String fileName; 

public String getPath() { 
return path; 
} 

public void setPath(String path) { 
this.path = path; 
} 

public String getFileName() { 
return fileName; 
} 

public void setFileName(String fileName) { 
this.fileName = fileName; 
} 

} 

I am using JAX-B to map the ContentBlock object to ContentBlockRepresentation object. This object is returned by the restClient to the frontend of my site 
In my ImageRepresentation object I have a variable called path in which i want to store the path of the image. The problem is that which path should i store so that i can display it in the jsp. I was able to display the variables like title and description as they are of string type but image is of type HippoGalleryImageSetBean . 

Could you suggest me the mapping for the image type inorder to display it in the Jsp. 




Cdt, 
Chandan AGARWAL 
IED 
Smile Benelux 
Brussels 
Mb - (+32) 0492101358 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onehippo.org/pipermail/hippo-cms7-user/attachments/20120925/fc982133/attachment.htm>


More information about the Hippo-cms7-user mailing list