Hi @v1101
We have Replicator Service methods to activate the provided page path. please find below code for the same.
Javascript
Pass the page path(ex: with attribute name "pagePath") which author has selected to Servlet in AJAX request.
Servlet:
Create new servlet & service user with required permission.
public class ReplicationServlet extends SlingAllMethodsServlet {
@Reference
private Replicator replicator;
@Reference
private ResourceResolverFactory resourceResolverFactory;
private static final String PAGE_PATH = "pagePath";
private static final String SERVICE_USER = "replication-user"; //create new service user with required permission
private static final Map<String, Object> SERVICE_USER_DETAILS = ImmutableMap
.of(ResourceResolverFactory.SUBSERVICE, (Object) SERVICE_USER);
private static final Logger LOGGER = LoggerFactory.getLogger(ReplicationServlet.class);
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
String pagePath = request.getParameter(PAGE_PATH); //page path without .html extension
if(StringUtils.isNotEmpty(pagePath)) {
try (ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(SERVICE_USER_DETAILS)) {
if (resourceResolver != null) {
Session session = request.getResourceResolver().adaptTo(Session.class);
if (session != null && replicator != null) {
replicator.replicate(session, ReplicationActionType.ACTIVATE, pagePath);
}
}
} catch (LoginException e) {
LOGGER.error("LoginException occurred", e);
} catch (ReplicationException e) {
LOGGER.error("ReplicationException occurred", e);
}
}
}
}
- Manjunath