Let's assume I have list of path like, /content/us/en/a, /content/us/en/b, /content/us/en/c etc. and I want to publish these content from java
What I have ?
List<String> allPaths = allPagesPathWhichNeedToPublish();
and want to publish all pages which is in allPaths list. What java steps I need to follow to publish path/pages one by one.
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Like @aanchal-sikka already described, you should use Replicator java API.
There are two options in your case:
@Reference
private Replicator replicator;
// place for other code
List<String> allPaths = allPagesPathWhichNeedToPublish();
Session session = resourceResolver.adaptTo(Session.class);
for(String path : allPaths) {
try {
replicator.replicate(session, ReplicationActionType.ACTIVATE, path, null);
} catch (ReplicationException e) {
e.printStackTrace();
}
}
@Reference
private Replicator replicator;
// place for other code
List<String> allPaths = allPagesPathWhichNeedToPublish();
// converting to array as this is format accepted by replicator
String [] paths = allPaths.toArray(new String[allPaths.size()])
try {
replicator.replicate(resourceResolver.adaptTo(Session.class), ReplicationActionType.ACTIVATE, paths, null);
} catch (ReplicationException e) {
e.printStackTrace();
}
Make sure that resource resolver object you will be suing has a proper level of permission to replicate pages. You can consider to create proper service user and create resource resolver using this user, to have full control of permission set.
Hello @Shahid_Siddiqui_04
We can use Replicator API to publish pages
@Reference
private Replicator replicator;
ResourceResolver resolver = request.getResourceResolver();
javax.jcr.Session session = resolver.adaptTo(Session.class);
try {
replicator.replicate(session, ReplicationActionType.ACTIVATE, path);
log.info("Page activated: ", path);
} catch (ReplicationException e) {
log.info("Replication failed "+e.getMessage(), path);
}
Thankyou
Like @aanchal-sikka already described, you should use Replicator java API.
There are two options in your case:
@Reference
private Replicator replicator;
// place for other code
List<String> allPaths = allPagesPathWhichNeedToPublish();
Session session = resourceResolver.adaptTo(Session.class);
for(String path : allPaths) {
try {
replicator.replicate(session, ReplicationActionType.ACTIVATE, path, null);
} catch (ReplicationException e) {
e.printStackTrace();
}
}
@Reference
private Replicator replicator;
// place for other code
List<String> allPaths = allPagesPathWhichNeedToPublish();
// converting to array as this is format accepted by replicator
String [] paths = allPaths.toArray(new String[allPaths.size()])
try {
replicator.replicate(resourceResolver.adaptTo(Session.class), ReplicationActionType.ACTIVATE, paths, null);
} catch (ReplicationException e) {
e.printStackTrace();
}
Make sure that resource resolver object you will be suing has a proper level of permission to replicate pages. You can consider to create proper service user and create resource resolver using this user, to have full control of permission set.
Thankyou