public interface RewriteContextResolver
Expert feature : Note that if you implement a custom RewriteContextResolver
, that you make sure
that resolve(Node, Mount, HstRequestContext, boolean, boolean)
is very fast! Namely,
resolve(Node, Mount, HstRequestContext, boolean, boolean)
will be invoked for every
link creation of a Node
or HippoBean
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 custom
RewriteContextResolver
. Remember however that the implementation must be fast. Whenever
the method resolve(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 in resolve(Node, Mount, HstRequestContext, boolean, boolean)
is not necessarily
the Node
of the backing HippoBean
for which a link is
required. The Node
typically might be the parent (HippoNodeType.NT_HANDLE
)
in case the Node
represents a document.
Modifier and Type | Method and Description |
---|---|
RewriteContext |
resolve(javax.jcr.Node node,
Mount mount,
HstRequestContext context,
boolean canonical,
boolean navigationStateful)
In general, the returned
RewriteContext.getPath() with which the link creation is tried is just Item.getPath()
and the returned RewriteContext.getMount() just the mount for the current HstRequestContext , however,
if required differently by an end project, it can be done by implementing a custom RewriteContextResolver
and set this on HstLinkCreator implementation |
RewriteContext resolve(javax.jcr.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 just Item.getPath()
and the returned RewriteContext.getMount()
just the mount for the current HstRequestContext
, however,
if required differently by an end project, it can be done by implementing a custom RewriteContextResolver
and set this on HstLinkCreator
implementation
node
- the jcr node for which a HstLink
is needed. In case of documents, the handle node.context
- the HstRequestContext
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. If
canonical=true
then typically this parameter its value is ignored. Canonical normally has precedence
over navigationStatefulRewriteContext
rewrite context containing the node path with which the HstLinkCreator will try to create a HstLink
and for which Mount
it should try to do this. It is not allowed to return
null
and RewriteContext.getPath()
must start with a '/' and is not allowed to end with a '/'. If the Node
for which a link is required is a HippoNodeType.NT_DOCUMENT
below a
HippoNodeType.NT_HANDLE
make sure to return the path of the handle node!RewriteContextException
- in case not a proper RewriteContext can be returned. The HstLinkCreator
will in case of this exception return a hstLink#isNotFound() == true
.RuntimeException
- in case if an unexpected runtime exception that cannot be handled with
RewriteContextException
Copyright © 2008–2016 Hippo B.V. (http://www.onehippo.com). All rights reserved.