Hi I want to know the correct way to use deepCopyFunction for coping one page to another page including the attachment
To utilize the deepCopyPage function in Confluence for copying a page, including attachments, follow these steps.
First, obtain a PageManager reference using ComponentLocator. Create a PageCopyOptions object, specifying attachment inclusion, and retrieve references to the original page and destination parent page.
Then, invoke the deepCopyPage function, passing the options, original page, and destination parent page. Ensure the destination parent page exists, and consider handling potential title conflicts, permission issues, and page hierarchy limits.
java
PageManager pageManager = ComponentLocator.getComponent(PageManager.class);
java
PageCopyOptions pageCopyOptions = PageCopyOptions.builder()
.withAttachments(true)
.build();
java
Page originalPage = pageManager.getPage(originalSpaceKey, originalPageTitle);
Page destinationParentPage = pageManager.getPage(destinationSpaceKey, destinationParentPageTitle);
java
pageManager.deepCopyPage(pageCopyOptions, originalPage, destinationParentPage);
java
import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.pages.Page;
import com.atlassian.confluence.pages.persistence.dao.bulk.copy.PageCopyOptions;
import com.atlassian.sal.api.component.ComponentLocator;
// Get PageManager
PageManager pageManager = ComponentLocator.getComponent(PageManager.class);
// Set up copy options
PageCopyOptions pageCopyOptions = PageCopyOptions.builder()
.withAttachments(true)
.build();
// Get original and destination pages
Page originalPage = pageManager.getPage("SOURCESPACE", "Source Page Title");
Page destinationParentPage = pageManager.getPage("DESTSPACE", "Destination Parent Page Title");
// Perform the deep copy
pageManager.deepCopyPage(pageCopyOptions, originalPage, destinationParentPage);
-------------------------------------------------------------------------
The provided code facilitates the duplication of a Confluence page, including attachments, as a child page under a specified destination parent. Key considerations for successful execution include:
The destination parent page must pre-exist.
The duplicated page retains its original title, potentially necessitating conflict resolution if a similarly titled page already exists.
Adequate permissions are required to perform this operation.
The process may fail due to excessive pages in the hierarchy (default limit: 2000), adjustable by administrators.
Robust exception handling is crucial to mitigate issues such as page non-existence or permission conflicts.
Hope this helps - Happy to help further!!
Thank you very much and have a great one!
Warm regards
Instead of PageManager reference using ComponentLocator why we can't use PageManger constructor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We can't use the PageManager constructor directly because PageManager is an interface, not a concrete class.
The Confluence framework provides its implementation at runtime, and ComponentLocator is used to retrieve the properly initialized instance. This ensures that all dependencies are correctly managed within Confluence's service framework.
To learn more - Accessing Confluence Components from Plugin Modules
Hope this helps!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.