Search in sources :

Example 6 with Div

use of org.apache.ecs.html.Div in project xwiki-platform by xwiki.

the class DefaultWatchListEventHTMLDiffExtractor method getHTMLDiff.

@Override
public String getHTMLDiff(WatchListEvent event) throws WatchListException {
    XWikiContext context = contextProvider.get();
    StringBuffer result = new StringBuffer();
    try {
        DiffPluginApi diff = (DiffPluginApi) context.getWiki().getPluginApi("diff", context);
        XWikiDocument d2 = context.getWiki().getDocument(event.getDocumentReference(), context);
        if (event.getType().equals(WatchListEventType.CREATE)) {
            d2 = context.getWiki().getDocument(d2, INITIAL_DOCUMENT_VERSION, context);
        }
        XWikiDocument d1 = context.getWiki().getDocument(d2, event.getPreviousVersion(), context);
        List<AttachmentDiff> attachDiffs = d2.getAttachmentDiff(d1, d2, context);
        List<List<ObjectDiff>> objectDiffs = d2.getObjectDiff(d1, d2, context);
        List<List<ObjectDiff>> classDiffs = d2.getClassDiff(d1, d2, context);
        List<MetaDataDiff> metaDiffs = d2.getMetaDataDiff(d1, d2, context);
        if (!d1.getContent().equals(d2.getContent())) {
            Div contentDiv = createDiffDiv("contentDiff");
            String contentDiff = diff.getDifferencesAsHTML(d1.getContent(), d2.getContent(), false);
            contentDiv.addElement(contentDiff);
            result.append(contentDiv);
        }
        for (AttachmentDiff aDiff : attachDiffs) {
            Div attachmentDiv = createDiffDiv("attachmentDiff");
            attachmentDiv.addElement(HTML_IMG_ATTACHMENT_PREFIX + HTML_IMG_PLACEHOLDER_SUFFIX);
            attachmentDiv.addElement(aDiff.toString());
            result.append(attachmentDiv);
        }
        result.append(getObjectsHTMLDiff(objectDiffs, false, event.getFullName(), diff));
        result.append(getObjectsHTMLDiff(classDiffs, true, event.getFullName(), diff));
        for (MetaDataDiff mDiff : metaDiffs) {
            Div metaDiv = createDiffDiv("metaDiff");
            metaDiv.addElement(HTML_IMG_METADATA_PREFIX + HTML_IMG_PLACEHOLDER_SUFFIX);
            metaDiv.addElement(mDiff.toString());
            result.append(metaDiv);
        }
        return result.toString();
    } catch (Exception e) {
        throw new WatchListException(String.format("Failed to compute HTML diff for event type [%s] on [%s]", event.getType(), event.getPrefixedFullName()), e);
    }
}
Also used : MetaDataDiff(com.xpn.xwiki.doc.MetaDataDiff) DiffPluginApi(com.xpn.xwiki.plugin.diff.DiffPluginApi) WatchListException(org.xwiki.watchlist.internal.api.WatchListException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) WatchListException(org.xwiki.watchlist.internal.api.WatchListException) Div(org.apache.ecs.html.Div) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) List(java.util.List) AttachmentDiff(com.xpn.xwiki.doc.AttachmentDiff)

Aggregations

Div (org.apache.ecs.html.Div)6 XWikiException (com.xpn.xwiki.XWikiException)4 AttachmentDiff (com.xpn.xwiki.doc.AttachmentDiff)2 MetaDataDiff (com.xpn.xwiki.doc.MetaDataDiff)2 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)2 ObjectDiff (com.xpn.xwiki.objects.ObjectDiff)2 DiffPluginApi (com.xpn.xwiki.plugin.diff.DiffPluginApi)2 List (java.util.List)2 Span (org.apache.ecs.html.Span)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 ArrayList (java.util.ArrayList)1 WatchListException (org.xwiki.watchlist.internal.api.WatchListException)1