Interface RenderingContext
-
- All Known Implementing Classes:
RenderingContextImpl
,ThreadSafeRenderingContext
public interface RenderingContext
A context used to deliver parameter to marshallers during a marshalling request.Use
RenderingContext.CtxBuilder
to create your context.When a
RenderingContext
is automatically provided from an HttpServletRequest, it contains request parameters, headers and request attribute.To get/set parameter values, use:
getParameter(String)
getParameters(String)
getBooleanParameter(String)
getAllParameters()
addParameterValues(String, Object...)
addParameterListValues(String, List)
setParameterValues(String, Object...)
setParameterListValues(String, List)
To manage document properties, entity enrichers or properties fetching, use:
To manage infinite loop when calling a marshaller from another marshaller, use:
Example:// This will control infinite loop in this marshaller try (Closeable resource = ctx.wrap().controlDepth().open()) { // call another marshaller to fetch the desired property here } catch (MaxDepthReachedException mdre) { // do not call the other marshaller }
- Since:
- 7.2.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
RenderingContext.CtxBuilder
RenderingContext
builder.static class
RenderingContext.SessionWrapper
Session wrapper.
-
Field Summary
Fields Modifier and Type Field Description static Locale
DEFAULT_LOCALE
static String
DEFAULT_URL
static String
REPOSITORY_NAME_REQUEST_HEADER
static String
REPOSITORY_NAME_REQUEST_PARAMETER
static String
RESPONSE_HEADER_ENTITY_TYPE_KEY
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addParameterListValues(String name, List<?> values)
Add values in the context with a given name.void
addParameterValues(String name, Object... values)
Map<String,List<Object>>
getAllParameters()
Get all parameter in this context except wrapped parameters.String
getBaseUrl()
Gets the current base url.boolean
getBooleanParameter(String name)
Set<String>
getEnrichers(String entity)
Get all enrichers to activate on the given entity type.Set<String>
getFetched(String entity)
Get all properties to fetch for a given entity type.Locale
getLocale()
Gets the requestedLocale
.<T> T
getParameter(String name)
Get the casted parameter value for a given name.<T> List<T>
getParameters(String name)
Get the casted parameter values for a given name.Set<String>
getProperties()
Get all document properties.RenderingContext.SessionWrapper
getSession(DocumentModel document)
Gets the currentCoreSession
or try to create one.Set<String>
getTranslated(String entity)
Get all properties to translate for a given entity type.void
setExistingSession(CoreSession session)
Provides aCoreSession
to marshallers.void
setParameterListValues(String name, List<Object> values)
Push values in the context with a given name.void
setParameterValues(String name, Object... values)
WrappedContext
wrap()
seeWrappedContext
-
-
-
Field Detail
-
DEFAULT_LOCALE
static final Locale DEFAULT_LOCALE
-
DEFAULT_URL
static final String DEFAULT_URL
- See Also:
- Constant Field Values
-
RESPONSE_HEADER_ENTITY_TYPE_KEY
static final String RESPONSE_HEADER_ENTITY_TYPE_KEY
- See Also:
- Constant Field Values
-
REPOSITORY_NAME_REQUEST_HEADER
static final String REPOSITORY_NAME_REQUEST_HEADER
- Since:
- 10.2
- See Also:
- Constant Field Values
-
REPOSITORY_NAME_REQUEST_PARAMETER
static final String REPOSITORY_NAME_REQUEST_PARAMETER
- Since:
- 10.2
- See Also:
- Constant Field Values
-
-
Method Detail
-
getBaseUrl
String getBaseUrl()
Gets the current base url.- Since:
- 7.2
-
getSession
RenderingContext.SessionWrapper getSession(DocumentModel document) throws MarshallingException
Gets the currentCoreSession
or try to create one.- Parameters:
document
- may be null, if present, this method search for a session in the document.- Returns:
- The current
CoreSession
if it exists. null otherwise. - Throws:
MarshallingException
- if no session could be created or found.- Since:
- 7.2
-
setExistingSession
void setExistingSession(CoreSession session)
Provides aCoreSession
to marshallers.For example: a
CoreSession
from the request context.- Parameters:
session
- The existingCoreSession
which lifecycle is managed outside the marshalling context.- Since:
- 7.2
-
getProperties
Set<String> getProperties()
Get all document properties. This will aggregate all values from parameters "properties", "X-NXproperties" and "X-NXDocumentProperties". This supports value separated by comma.- Returns:
- All document properties.
- Since:
- 7.2
-
getFetched
Set<String> getFetched(String entity)
Get all properties to fetch for a given entity type. This will aggregate all values from parameters "fetch.entity" and "X-NXfetch.entity". This supports value separated by comma.- Parameters:
entity
- The type of the entity on which you want to fetch properties.- Returns:
- All properties to fetch.
- Since:
- 7.2
-
getTranslated
Set<String> getTranslated(String entity)
Get all properties to translate for a given entity type. This will aggregate all values from parameters "translate.entity" and "X-NXtranslate.entity". This supports value separated by comma.- Parameters:
entity
- The type of the entity on which you want to fetch properties.- Returns:
- All properties to fetch.
- Since:
- 7.2
-
getEnrichers
Set<String> getEnrichers(String entity)
Get all enrichers to activate on the given entity type. This will aggregate all values from parameters "enrichers.entity", "X-NXenrichers.entity" and "X-NXContext-Category". This supports value separated by comma.- Parameters:
entity
- The type of the entity on which you want to activate enrichers.- Returns:
- All enrichers to activate.
- Since:
- 7.2
-
wrap
WrappedContext wrap()
seeWrappedContext
- Returns:
- A new
WrappedContext
- Since:
- 7.2
-
getParameter
<T> T getParameter(String name)
Get the casted parameter value for a given name. If multiple are available, the first found is returned.- Parameters:
name
- The parameter name.- Returns:
- The first parameter value, null if no parameter are availble.
- Since:
- 7.2
-
getBooleanParameter
boolean getBooleanParameter(String name)
- Returns:
- true is the parameter exists and if it's Boolean.TRUE or "true", false otherwise.
-
getParameters
<T> List<T> getParameters(String name)
Get the casted parameter values for a given name.- Parameters:
name
- The parameter name.- Returns:
- The parameter values.
- Since:
- 7.2
-
getAllParameters
Map<String,List<Object>> getAllParameters()
Get all parameter in this context except wrapped parameters.- Returns:
- All parameter's names and their values.
- Since:
- 7.2
-
setParameterValues
void setParameterValues(String name, Object... values)
- Since:
- 7.2
- See Also:
setParameterListValues(String, List)
-
setParameterListValues
void setParameterListValues(String name, List<Object> values)
Push values in the context with a given name. Please note that this method remove any value for the given name.- Parameters:
name
- The parameter name.values
- The parameter values.- Since:
- 7.2
-
addParameterValues
void addParameterValues(String name, Object... values)
- Since:
- 7.2
- See Also:
addParameterListValues(String, List)
-
-