Interface RewriteContextResolver
-
public interface RewriteContextResolver
Expert feature : Note that if you implement a custom
RewriteContextResolver
, that you make sure thatresolve(Node, Mount, HstRequestContext, boolean, boolean)
is very fast! Namely,resolve(Node, Mount, HstRequestContext, boolean, boolean)
will be invoked for every link creation of aNode
orHippoBean
A use case where this
RewriteContextResolver
can be used is for example when you have comment documents which have a link to the news article they are a comment about. The comment documents themselves do *not* have a URL. They are only visible in the context of the news article they are a comment about. In this case, when there is a link to a comment document or when a comment document is found via search, you want to actually have link creation for the node path of the news document. This can be achieved with a customRewriteContextResolver
. Remember however that the implementation must be fast. Whenever the methodresolve(Node, Mount, HstRequestContext, boolean, boolean)
takes more than a couple (say 2 to 3) milliseconds, you'll run into performance issues when a lot of links have to be created. Custom implementation can best always log at debug level how long parts of the method takes to execute (default hst logs the total time as well). Target time should be around 1/10 to 1 millisecond max.Note that the
node
argument inresolve(Node, Mount, HstRequestContext, boolean, boolean)
is not necessarily theNode
of the backingHippoBean
for which a link is required. TheNode
typically might be the parent (HippoNodeType.NT_HANDLE
) in case theNode
represents a document.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description RewriteContext
resolve(Node node, Mount mount, HstRequestContext context, boolean canonical, boolean navigationStateful)
In general, the returnedRewriteContext.getPath()
with which the link creation is tried is justItem.getPath()
and the returnedRewriteContext.getMount()
just the mount for the currentHstRequestContext
, however, if required differently by an end project, it can be done by implementing a customRewriteContextResolver
and set this onHstLinkCreator
implementation
-
-
-
Method Detail
-
resolve
RewriteContext resolve(Node node, Mount mount, HstRequestContext context, boolean canonical, boolean navigationStateful) throws RewriteContextException, RuntimeException
In general, the returned
RewriteContext.getPath()
with which the link creation is tried is justItem.getPath()
and the returnedRewriteContext.getMount()
just the mount for the currentHstRequestContext
, however, if required differently by an end project, it can be done by implementing a customRewriteContextResolver
and set this onHstLinkCreator
implementation- Parameters:
node
- the jcr node for which aHstLink
is needed. In case of documents, the handle node.context
- theHstRequestContext
for the current requestcanonical
- whether the link to be created was marked to be canonical or not.navigationStateful
- whether the link to be created was marked to be navigationStateful or not. Ifcanonical=true
then typically this parameter its value is ignored. Canonical normally has precedence over navigationStateful- Returns:
RewriteContext
rewrite context containing the node path with which the HstLinkCreator will try to create aHstLink
and for whichMount
it should try to do this. It is not allowed to returnnull
andRewriteContext.getPath()
must start with a '/' and is not allowed to end with a '/'. If theNode
for which a link is required is aHippoNodeType.NT_DOCUMENT
below aHippoNodeType.NT_HANDLE
make sure to return the path of the handle node!- Throws:
RewriteContextException
- in case not a proper RewriteContext can be returned. TheHstLinkCreator
will in case of this exception return ahstLink#isNotFound() == true
.RuntimeException
- in case if an unexpected runtime exception that cannot be handled withRewriteContextException
-
-