Content Application Developer Manual / Version 2412.0
Table Of Contents
The link scheme's method signature might contain several parameters (such as
bean, view, HttpServletRequest, ...) that will be
automatically bound by the CAE framework on invocation. Furthermore, several classes are
supported for the scheme's return type, for example
org.springframework.web.util.UriComponents or even a
Map<String,Object> that holds the URI variables only. See the Javadoc of
the annotation com.coremedia.objectserver.web.links.Link for more details.
As a consequence, a link scheme can be implemented in several ways, for instance:
@Link(type = ContentBean.class, uri="/content/{id}")
public UriComponents buildLink(UriComponentsBuilder uriTemplate,
ContentBean bean) {
Integer id = IdHelper.parseContentId(bean.getContent().getId());
return uriTemplate.buildAndExpand(id);
}or
@Link(type = ContentBean.class, uri="/content/{id}")
public Map<String, Object> buildLink(ContentBean bean) {
Integer id = IdHelper.parseContentId(bean.getContent().getId());
return Collections.singletonMap("id", id);
}or
@Link(type = ContentBean.class)
public UriComponentsBuilder buildLink(ContentBean bean) {
Integer id = IdHelper.parseContentId(bean.getContent().getId());
return UriComponentsBuilder.newInstance()
.pathSegment("content")
.pathSegment(id.toString());
}
CoreMedia suggests using org.springframework.web.util.UriComponentsBuilder for
building links since this utility provides convenience functions for manipulating URI parts as
well as functions for substituting URI variables (such as {id}) by concrete
values. In addition, an URI will be encoded (for example /öffnungszeiten to
/%C3%B6ffnungszeiten) properly by using the
UriComponents#encode() function. Moreover, CoreMedia suggests to return
the resulting link as an UriComponents, UriComponentsBuilder or
Map<String,Object> object. Post-processing (see below) of such values is
much more efficient than for objects of type String or URI. As a
side effect, it is not necessary to perform the encoding manually, because this is done by the
framework.


