Package org.opencms.i18n.tools
Class CmsContainerPageCopier
- java.lang.Object
-
- org.opencms.i18n.tools.CmsContainerPageCopier
-
public class CmsContainerPageCopier extends java.lang.Object
Helper class for copying container pages including some of their elements.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsContainerPageCopier.CopyMode
Enum representing the element copy mode.static class
CmsContainerPageCopier.NoCustomReplacementException
Exception indicating that no custom replacement element was found for a type which requires replacement.
-
Constructor Summary
Constructors Constructor Description CmsContainerPageCopier(CmsObject cms)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
adjustLocalesForElement(CmsResource elementResource, CmsResource originalResource)
Converts locales for the copied container element.void
copyPageOnly(CmsResource originalPage, java.lang.String targetPageRootPath)
Copies the given container page to the provided root path.CmsResource
getCopiedFolderOrPage()
Gets the copied folder or page.CmsResource
getTargetFolder()
Returns the target folder.CmsContainerElementBean
replaceContainerElement(CmsResource targetPage, CmsContainerElementBean originalElement)
Produces the replacement for a container page element to use in a copy of an existing container page.void
replaceElements(CmsResource containerPage)
Replaces the elements in the copied container page with copies, if appropriate based on the current copy mode.void
run(CmsResource source, CmsResource target)
Starts the page copying process.void
run(CmsResource source, CmsResource target, java.lang.String targetName)
Starts the page copying process.void
setCopyMode(CmsContainerPageCopier.CopyMode copyMode)
Sets the copy mode.
-
-
-
Constructor Detail
-
CmsContainerPageCopier
public CmsContainerPageCopier(CmsObject cms)
Creates a new instance.- Parameters:
cms
- the CMS context to use
-
-
Method Detail
-
adjustLocalesForElement
public void adjustLocalesForElement(CmsResource elementResource, CmsResource originalResource) throws CmsException
Converts locales for the copied container element.- Parameters:
elementResource
- the copied container element resourceoriginalResource
- the original container element resource- Throws:
CmsException
- if something goes wrong
-
copyPageOnly
public void copyPageOnly(CmsResource originalPage, java.lang.String targetPageRootPath) throws CmsException, CmsContainerPageCopier.NoCustomReplacementException
Copies the given container page to the provided root path.- Parameters:
originalPage
- the page to copytargetPageRootPath
- the root path of the copy target.- Throws:
CmsException
- thrown if something goes wrong.CmsContainerPageCopier.NoCustomReplacementException
- if a custom replacement is not found for a type which requires it.
-
getCopiedFolderOrPage
public CmsResource getCopiedFolderOrPage()
Gets the copied folder or page.- Returns:
- the copied folder or page
-
getTargetFolder
public CmsResource getTargetFolder()
Returns the target folder.- Returns:
- the target folder
-
replaceContainerElement
public CmsContainerElementBean replaceContainerElement(CmsResource targetPage, CmsContainerElementBean originalElement) throws CmsException, CmsContainerPageCopier.NoCustomReplacementException
Produces the replacement for a container page element to use in a copy of an existing container page.- Parameters:
targetPage
- the target container pageoriginalElement
- the original element- Returns:
- the replacement element for the copied page
- Throws:
CmsException
- if something goes wrongCmsContainerPageCopier.NoCustomReplacementException
- if a custom replacement is not found for a type which requires it
-
replaceElements
public void replaceElements(CmsResource containerPage) throws CmsException, CmsContainerPageCopier.NoCustomReplacementException
Replaces the elements in the copied container page with copies, if appropriate based on the current copy mode.- Parameters:
containerPage
- the container page copy whose elements should be replaced with copies- Throws:
CmsException
- if something goes wrongCmsContainerPageCopier.NoCustomReplacementException
- if a custom replacement element was not found for a type which requires it
-
run
public void run(CmsResource source, CmsResource target) throws CmsException, CmsContainerPageCopier.NoCustomReplacementException
Starts the page copying process.- Parameters:
source
- the source (can be either a container page, or a folder whose default file is a container page)target
- the target folder- Throws:
CmsException
- if soemthing goes wrongCmsContainerPageCopier.NoCustomReplacementException
- if a custom replacement element was not found
-
run
public void run(CmsResource source, CmsResource target, java.lang.String targetName) throws CmsException, CmsContainerPageCopier.NoCustomReplacementException
Starts the page copying process.- Parameters:
source
- the source (can be either a container page, or a folder whose default file is a container page)target
- the target foldertargetName
- the name to give the new folder- Throws:
CmsException
- if something goes wrongCmsContainerPageCopier.NoCustomReplacementException
- if a custom replacement element was not found
-
setCopyMode
public void setCopyMode(CmsContainerPageCopier.CopyMode copyMode)
Sets the copy mode.- Parameters:
copyMode
- the copy mode
-
-