Class CmsModificationContext
- All Implemented Interfaces:
AutoCloseable
This class is meant to be used with the try-with-resources syntax from Java 7: Use the acquire() method in the try expression (e.g. 'try (CmsModificationContext modContext = CmsModificationContext.acquire(requestContext)) { ... }'. Then use the add() method on the modification context to add any modified resources. Once the close() method is automatically invoked by the try-with-resources statement, *and* we are in the outermost nesting level of such try-with-resources statements, the modified resources are published if they belong to a configured online folder.
-
Method Summary
Modifier and TypeMethodDescriptionprotected static CmsModificationContext
acquire
(CmsRequestContext context) Acquires a modification context.void
add
(CmsResource resource) Checks if the given resource is in the online only folder, and if so, adds it to the set of resources that should be instant-published when the modification context is closed.void
Alternative to add(CmsResource) for methods where the resource is not read.void
close()
Decrements the modification context's level counter by 1, and finally closes it if the counter reaches zero.static <T> T
doWithModificationContext
(CmsRequestContext requestContext, org.apache.commons.lang3.function.FailableSupplier<T, CmsException> runnable) Executes the given action and returns the result, wrapping the execution in a modification context.static CmsOnlineFolderOptions
static void
initialize
(CmsSecurityManager securityManager, CmsObject adminCms, CmsOnlineFolderOptions options) Initializes this class.static boolean
isInOnlineFolder
(String path) Checks if the given path is below the configured online folder.static boolean
Checks if an 'instant publish' operation is currently running.
-
Method Details
-
doWithModificationContext
public static <T> T doWithModificationContext(CmsRequestContext requestContext, org.apache.commons.lang3.function.FailableSupplier<T, CmsException> runnable) throws CmsExceptionExecutes the given action and returns the result, wrapping the execution in a modification context.- Type Parameters:
T
- the result type- Parameters:
requestContext
- the current request contextrunnable
- the action to execute- Returns:
- the result of the action
- Throws:
CmsException
- if something goes wrong
-
getOnlineFolderOptions
-
initialize
public static void initialize(CmsSecurityManager securityManager, CmsObject adminCms, CmsOnlineFolderOptions options) Initializes this class.- Parameters:
securityManager
- the security manager instanceadminCms
- a CmsObject with admin privilegesonlineFolderPath
- the online folder path (nay be null)
-
isInOnlineFolder
Checks if the given path is below the configured online folder.If no online folder is configured, this will return false.
- Parameters:
path
- the path to check- Returns:
- true if the given path is below the configured online folder
-
isInstantPublishing
Checks if an 'instant publish' operation is currently running.- Returns:
- true if an 'instant publish' operation is running
-
acquire
Acquires a modification context.If a modification context was acquired in a higher stack frame, the existing context will be returned, but its level counter will be increased by 1, otherwise a new context will be created with a level counter of 1.
- Parameters:
context
- the request context for which to get a modification context- Returns:
- the modification context
-
add
Checks if the given resource is in the online only folder, and if so, adds it to the set of resources that should be instant-published when the modification context is closed.- Parameters:
resource
- the resource to add
-
addId
Alternative to add(CmsResource) for methods where the resource is not read.Avoid using this if possible, in favor of add(CmsResource)
- Parameters:
structureId
- the structure id of the resource to add
-
close
Decrements the modification context's level counter by 1, and finally closes it if the counter reaches zero.If the counter reaches zero, all resources added with the add() method will be published synchronously, without going through the publish queue.
- Specified by:
close
in interfaceAutoCloseable
- Throws:
CmsException
- See Also:
-