Class DefaultConversionContext
- java.lang.Object
-
- com.atlassian.confluence.content.render.xhtml.DefaultConversionContext
-
- All Implemented Interfaces:
ConversionContext
public class DefaultConversionContext extends Object implements ConversionContext
A non-thread safe implementation of the ConversionContext suitable for use in the single threaded XHTML output process.Unless explicitly set the
getOutputDeviceType()
will returnConversionContextOutputDeviceType.DESKTOP
.
-
-
Field Summary
-
Fields inherited from interface com.atlassian.confluence.content.render.xhtml.ConversionContext
IS_VALIDATING_COMMENT
-
-
Constructor Summary
Constructors Constructor Description DefaultConversionContext(com.atlassian.renderer.RenderContext renderContext)
DefaultConversionContext(com.atlassian.renderer.RenderContext renderContext, String outputDeviceType)
Create a DefaultConversionContext for the specified output device type.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addMarshallerMetricsConsumer(MarshallerMetricsConsumer consumer)
Adds a consumer ofMarshallerMetrics
that is associated with the current render.void
checkTimeout()
Check the timeout and throw an XhtmlTimeoutException if the timeout is expired.void
disableAsyncRenderSafe()
Mark the content rendered in this context as non-async-render-safeboolean
equals(Object o)
ContentTree
getContentTree()
If multiple items are being converted in this 'context' then the complete tree of ContentNodes will be retrieved via this method.ContentEntityObject
getEntity()
Get the current ContentEntityObject for this context.Map<String,Object>
getImmutableProperties()
The properties returned in this map are guaranteed to be immutable, they are not guaranteed to all be present.Set<MarshallerMetricsConsumer>
getMarshallerMetricsConsumers()
Returns the consumers ofMarshallerMetrics
that are associated with the current render.String
getOutputDeviceType()
Note, that if you want your code to be compatible with versions of Confluence older then 4.3.2 then you can instead callConversionContext.getPropertyAsString(String)
with the parameter "output-device-type".@NonNull String
getOutputType()
PageContext
getPageContext()
Object
getProperty(String name)
Return a property from the context.Object
getProperty(String name, Object defaultValue)
Return a property from the context or the supplied defaultValue if the property does not exist on the context.String
getPropertyAsString(String name)
Returns the property for this key as a String.com.atlassian.renderer.RenderContext
getRenderContext()
String
getSpaceKey()
The spacekey for the current context if applicable or null otherwise.PageTemplate
getTemplate()
com.atlassian.util.concurrent.Timeout
getTimeout()
Deprecated.since 7.0.1.int
hashCode()
boolean
hasProperty(String name)
Returns true if the property with the specified key has been set.com.google.common.collect.ImmutableMap<String,Object>
immutableProperties()
Deprecated.since 7.0.1.boolean
isAsyncRenderSafe()
boolean
isDiffOrEmail()
Check if the current context isConversionContextOutputType.DIFF
orConversionContextOutputType.EMAIL
boolean
removeMarshallerMetricsConsumer(MarshallerMetricsConsumer consumer)
Removes a consumer ofMarshallerMetrics
that is associated with the current render.Object
removeProperty(String name)
Removes the property references by the key from the conversion context and returns it.void
setContentTree(ContentTree contentTree)
void
setProperty(String name, Object value)
Sets the property specified by name in the conversion context.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.atlassian.confluence.content.render.xhtml.ConversionContext
timeout
-
-
-
-
Constructor Detail
-
DefaultConversionContext
public DefaultConversionContext(com.atlassian.renderer.RenderContext renderContext)
-
DefaultConversionContext
public DefaultConversionContext(com.atlassian.renderer.RenderContext renderContext, String outputDeviceType)
Create a DefaultConversionContext for the specified output device type. Note that any output device type on the supplied RenderContext will be overridden by the provided value.- Parameters:
renderContext
-outputDeviceType
-
-
-
Method Detail
-
immutableProperties
@Deprecated public com.google.common.collect.ImmutableMap<String,Object> immutableProperties()
Deprecated.since 7.0.1. UsegetImmutableProperties()
The properties returned in this map are guaranteed to be immutable, they are not guaranteed to all be present.- Returns:
- an immutable map of the immutable properties in the conversion context
-
getImmutableProperties
public Map<String,Object> getImmutableProperties()
The properties returned in this map are guaranteed to be immutable, they are not guaranteed to all be present.- Returns:
- an immutable map of the immutable properties in the conversion context
- Since:
- 7.0.1
-
getPageContext
public PageContext getPageContext()
- Specified by:
getPageContext
in interfaceConversionContext
- Returns:
- the underlying PageContext wrapped by the ConversionContext.
- See Also:
DefaultConversionContext
-
getRenderContext
public com.atlassian.renderer.RenderContext getRenderContext()
- Specified by:
getRenderContext
in interfaceConversionContext
-
removeProperty
public Object removeProperty(String name)
Description copied from interface:ConversionContext
Removes the property references by the key from the conversion context and returns it.- Specified by:
removeProperty
in interfaceConversionContext
- Parameters:
name
- The unique key of the property. SeeConversionContextPropertyName
for common names.- Returns:
- The property from the conversion context.
-
setProperty
public void setProperty(String name, Object value)
Description copied from interface:ConversionContext
Sets the property specified by name in the conversion context.- Specified by:
setProperty
in interfaceConversionContext
- Parameters:
name
- A unique key for this property. SeeConversionContextPropertyName
for common names.value
- The value of the property.
-
getProperty
public Object getProperty(String name)
Description copied from interface:ConversionContext
Return a property from the context.- Specified by:
getProperty
in interfaceConversionContext
- Parameters:
name
- of the property. SeeConversionContextPropertyName
for common names.- Returns:
- a property from the context.
-
getProperty
public Object getProperty(String name, Object defaultValue)
Description copied from interface:ConversionContext
Return a property from the context or the supplied defaultValue if the property does not exist on the context.- Specified by:
getProperty
in interfaceConversionContext
- Parameters:
name
- the name of the propertydefaultValue
- the default value to return if the property is not found.- Returns:
- the value of the found property or the default value if not found.
-
getPropertyAsString
public String getPropertyAsString(String name)
Description copied from interface:ConversionContext
Returns the property for this key as a String.toString() will be called if this is not the java.lang.String class.
null will be returned if this property does not exist.
- Specified by:
getPropertyAsString
in interfaceConversionContext
- Parameters:
name
- The key for the property- Returns:
- The String value of the property or null if the property does not exist.
-
hasProperty
public boolean hasProperty(String name)
Description copied from interface:ConversionContext
Returns true if the property with the specified key has been set.- Specified by:
hasProperty
in interfaceConversionContext
- Parameters:
name
- The name of the property- Returns:
- True if the property exists in this context.
-
getContentTree
public ContentTree getContentTree()
Description copied from interface:ConversionContext
If multiple items are being converted in this 'context' then the complete tree of ContentNodes will be retrieved via this method. If only a single item is being converted in the context then a ContentTree containing a single ContentNode will be returned.- Specified by:
getContentTree
in interfaceConversionContext
- Returns:
- a ContentTree representing all the items being converted in this context. An empty ContentTree may be returned if there is no explicit content being converted in this context.
-
setContentTree
public void setContentTree(ContentTree contentTree)
-
getOutputDeviceType
public String getOutputDeviceType()
Description copied from interface:ConversionContext
Note, that if you want your code to be compatible with versions of Confluence older then 4.3.2 then you can instead callConversionContext.getPropertyAsString(String)
with the parameter "output-device-type". For example, if you are a plugin developer writing a macro that can target different device types such as mobile, you can retain a common code base for your mobile and non-mobile implementations by avoiding this method and callinggetPropertyAsString("output-device-type")
instead.- Specified by:
getOutputDeviceType
in interfaceConversionContext
- Returns:
- the output device type. Typically this would be
ConversionContextOutputDeviceType.DESKTOP
but plugins that have their own renderer could use other types
-
getOutputType
public @NonNull String getOutputType()
- Specified by:
getOutputType
in interfaceConversionContext
- Returns:
- one of the Strings returned by
ConversionContextOutputType.value()
which indicates the target output type for the conversion.
-
isAsyncRenderSafe
public boolean isAsyncRenderSafe()
- Specified by:
isAsyncRenderSafe
in interfaceConversionContext
- Returns:
- true if the content is safe to render in asynchronously, e.g. dynamically on a page without a page refresh.
-
disableAsyncRenderSafe
public void disableAsyncRenderSafe()
Mark the content rendered in this context as non-async-render-safe- Specified by:
disableAsyncRenderSafe
in interfaceConversionContext
-
getTimeout
@Deprecated public com.atlassian.util.concurrent.Timeout getTimeout()
Deprecated.since 7.0.1. UseConversionContext.timeout()
Description copied from interface:ConversionContext
The Timeout object for this Conversion. This can be checked to see if conversion should be terminated usingTimeout.isExpired()
, or how much longer conversion should be allowed to run usingTimeout.getTime()
,Timeout.getUnit()
.- Specified by:
getTimeout
in interfaceConversionContext
- Returns:
- the timeout to perform the conversion.
-
checkTimeout
public void checkTimeout() throws XhtmlTimeoutException
Description copied from interface:ConversionContext
Check the timeout and throw an XhtmlTimeoutException if the timeout is expired. UseConversionContext.timeout()
andTimeout.isExpired()
to check the timeout without throwing an exception.- Specified by:
checkTimeout
in interfaceConversionContext
- Throws:
XhtmlTimeoutException
- if the conversion has exceeded its time limit.
-
isDiffOrEmail
public boolean isDiffOrEmail()
Description copied from interface:ConversionContext
Check if the current context isConversionContextOutputType.DIFF
orConversionContextOutputType.EMAIL
- Specified by:
isDiffOrEmail
in interfaceConversionContext
- Returns:
- true if the context is DIFF or EMAIL
-
addMarshallerMetricsConsumer
public void addMarshallerMetricsConsumer(MarshallerMetricsConsumer consumer)
Description copied from interface:ConversionContext
Adds a consumer ofMarshallerMetrics
that is associated with the current render. These consumers are used instead of event listeners because their scope of interest is limited to a particular thread.- Specified by:
addMarshallerMetricsConsumer
in interfaceConversionContext
-
removeMarshallerMetricsConsumer
public boolean removeMarshallerMetricsConsumer(MarshallerMetricsConsumer consumer)
Description copied from interface:ConversionContext
Removes a consumer ofMarshallerMetrics
that is associated with the current render.- Specified by:
removeMarshallerMetricsConsumer
in interfaceConversionContext
- Returns:
- true if the specified consumer was removed.
-
getMarshallerMetricsConsumers
public Set<MarshallerMetricsConsumer> getMarshallerMetricsConsumers()
Description copied from interface:ConversionContext
Returns the consumers ofMarshallerMetrics
that are associated with the current render. These consumers are used instead of event listeners because their scope of interest is limited to a particular thread.- Specified by:
getMarshallerMetricsConsumers
in interfaceConversionContext
- Returns:
- the list of consumers
-
getEntity
public ContentEntityObject getEntity()
Description copied from interface:ConversionContext
Get the current ContentEntityObject for this context.- Specified by:
getEntity
in interfaceConversionContext
- Returns:
- The ContentEntityObject for this context.
-
getTemplate
public PageTemplate getTemplate()
- Specified by:
getTemplate
in interfaceConversionContext
-
getSpaceKey
public String getSpaceKey()
Description copied from interface:ConversionContext
The spacekey for the current context if applicable or null otherwise.- Specified by:
getSpaceKey
in interfaceConversionContext
- Returns:
- The spacekey or null.
-
-