1

我有一个问题对应CQ5。激活页面时,会为该页面创建版本。现在,如果我修改页面并将其与早期版本进行比较,那么它将以绿色显示内容为 diffrence 。

现在我想通过代码和 API 来做到这一点,并让修改后的内容通过邮件发送。

有什么解决办法吗?

4

2 回答 2

3

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).

于 2013-06-26T21:02:11.467 回答
2

可以按如下方式以编程方式访问节点版本历史记录。

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

VersionHistory 使您可以访问节点的特定 javax.jcr.version.Version(版本扩展节点)。

要创建特定组件的差异,com.day.cq.commons.DiffInfo您可能会感兴趣。有关详细信息,请参阅http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/commons/DiffInfo.html

于 2013-06-26T08:09:16.793 回答