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
Modifier and TypeInterfaceDescriptionstatic final class
RenderingContext
builder.static class
Session wrapper. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addParameterListValues
(String name, List<?> values) Add values in the context with a given name.void
addParameterValues
(String name, Object... values) Get all parameter in this context except wrapped parameters.Gets the current base url.boolean
getBooleanParameter
(String name) getEnrichers
(String entity) Get all enrichers to activate on the given entity type.getFetched
(String entity) Get all properties to fetch for a given entity type.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.Get all document properties.getSession
(DocumentModel document) Gets the currentCoreSession
or try to create one.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) wrap()
seeWrappedContext
-
Field Details
-
DEFAULT_LOCALE
-
DEFAULT_URL
- See Also:
-
RESPONSE_HEADER_ENTITY_TYPE_KEY
- See Also:
-
REPOSITORY_NAME_REQUEST_HEADER
- Since:
- 10.2
- See Also:
-
REPOSITORY_NAME_REQUEST_PARAMETER
- Since:
- 10.2
- See Also:
-
-
Method Details
-
getLocale
Locale getLocale()Gets the requestedLocale
.- Since:
- 7.2
-
getBaseUrl
String getBaseUrl()Gets the current base url.- Since:
- 7.2
-
getSession
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
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
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
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
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
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
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
- Returns:
- true is the parameter exists and if it's Boolean.TRUE or "true", false otherwise.
-
getParameters
Get the casted parameter values for a given name.- Parameters:
name
- The parameter name.- Returns:
- The parameter values.
- Since:
- 7.2
-
getAllParameters
Get all parameter in this context except wrapped parameters.- Returns:
- All parameter's names and their values.
- Since:
- 7.2
-
setParameterValues
- Since:
- 7.2
- See Also:
-
setParameterListValues
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
- Since:
- 7.2
- See Also:
-
addParameterListValues
Add values in the context with a given name. Please note that this method keep current values for the given name.- Parameters:
name
- The parameter name.values
- The parameter values.- Since:
- 7.2
-