1
votes

I have a question correspond CQ5. When a page activated, version is created for the page . Now if I modify the page and compare it with the earlier version then it shows the content in green color as diffrence .

Now I want to do that through code and APIs and get the modified content to send through mail.

Is there any solution for it ?

2

2 Answers

3
votes

From what I can see when the page is in "diff mode" it is each components responsibility to render the diff output for the content which it is rendering.

In your own components it seems as though you can roll your own support for diffs using the DiffInfo/DiffService APIs. You then see the diffs for content in your own components

This will give you a diff between the current version and a selected previous version:

ValueMap currentValues = ResourceUtil.getValueMap(resource);
String title = currentValues.get(NameConstants.PN_TITLE, "");

DiffInfo diffInfo = resource.adaptTo(DiffInfo.class);    
ValueMap diffValues = ResourceUtil.getValueMap(diffInfo.getContent());
String diffText = diffValues.get(NameConstants.PN_TITLE, "");

DiffService diffService = sling.getService(DiffService.class);
String diffOutput = diffInfo.getDiffOutput(diffService, title, diffText, false);

When all of your components on page support the diff, then you would need to get the rendered output of the page to include in the email. You could use the SlingRequestProcessor to do this. You might find this difficult though as email clients will not render HTML in the same way a browser might (e.g. issues with external CSS etc).

2
votes

Accessing a nodes version history programmatically can be achiedved as follows.

Workspace workspace = node.getSession().getWorkspace();
VersionManager versionManager = workspace.getVersionManager();
VersionHistory versionHistory = versionManager.getVersionHistory(nde.getPath());

VersionHistory gives you access to a particular javax.jcr.version.Version of a Node (Version extends Node).

To create a diff of a particular component the com.day.cq.commons.DiffInfo may be interesting for you. See http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/commons/DiffInfo.html for more information.