Search in sources :

Example 1 with Span

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

the class WatchListEvent method getObjectsHTMLDiff.

/**
 * @param objectDiffs List of object diff
 * @param isXWikiClass is the diff to compute the diff for a xwiki class, the other possibility being a plain xwiki
 *            object
 * @param documentFullName full name of the document the diff is computed for
 * @param diff the diff plugin API
 * @return The HTML diff
 */
private String getObjectsHTMLDiff(List<List<ObjectDiff>> objectDiffs, boolean isXWikiClass, String documentFullName, DiffPluginApi diff) {
    StringBuffer result = new StringBuffer();
    String propSeparator = ": ";
    String prefix = (isXWikiClass) ? "class" : "object";
    try {
        for (List<ObjectDiff> oList : objectDiffs) {
            if (oList.size() > 0) {
                Div mainDiv = createDiffDiv(prefix + "Diff");
                Span objectName = createDiffSpan(prefix + "ClassName");
                if (isXWikiClass) {
                    objectName.addElement(getFullName());
                } else {
                    objectName.addElement(oList.get(0).getClassName());
                }
                mainDiv.addElement(prefix + HTML_IMG_PLACEHOLDER_SUFFIX);
                mainDiv.addElement(objectName);
                for (ObjectDiff oDiff : oList) {
                    String propDiff = getPropertyHTMLDiff(oDiff, diff);
                    if (!StringUtils.isBlank(oDiff.getPropName()) && !StringUtils.isBlank(propDiff)) {
                        Div propDiv = createDiffDiv("propDiffContainer");
                        Span propNameSpan = createDiffSpan("propName");
                        propNameSpan.addElement(oDiff.getPropName() + propSeparator);
                        String shortPropType = StringUtils.removeEnd(oDiff.getPropType(), "Class").toLowerCase();
                        if (StringUtils.isBlank(shortPropType)) {
                            // When the diff shows a property that has been deleted, its type is not available.
                            shortPropType = HTML_IMG_METADATA_PREFIX;
                        }
                        propDiv.addElement(shortPropType + HTML_IMG_PLACEHOLDER_SUFFIX);
                        propDiv.addElement(propNameSpan);
                        Div propDiffDiv = createDiffDiv("propDiff");
                        propDiffDiv.addElement(propDiff);
                        propDiv.addElement(propDiffDiv);
                        mainDiv.addElement(propDiv);
                    }
                }
                result.append(mainDiv);
            }
        }
    } catch (XWikiException e) {
        // Catch the exception to be sure we won't send emails containing stacktraces to users.
        e.printStackTrace();
    }
    return result.toString();
}
Also used : Div(org.apache.ecs.html.Div) ObjectDiff(com.xpn.xwiki.objects.ObjectDiff) Span(org.apache.ecs.html.Span) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with Span

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

the class WatchListEvent method createDiffSpan.

/**
 * @param classAttr The class of the span to create
 * @return an opening span markup
 */
private Span createDiffSpan(String classAttr) {
    Span span = new Span();
    span.setClass(classAttr);
    span.setStyle(HTML_STYLE_PLACEHOLDER_PREFIX + classAttr);
    return span;
}
Also used : Span(org.apache.ecs.html.Span)

Example 3 with Span

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

the class DefaultWatchListEventHTMLDiffExtractor method createDiffSpan.

/**
 * @param classAttr The class of the span to create
 * @return an opening span markup
 */
private static Span createDiffSpan(String classAttr) {
    Span span = new Span();
    span.setClass(classAttr);
    span.setStyle(HTML_STYLE_PLACEHOLDER_PREFIX + classAttr);
    return span;
}
Also used : Span(org.apache.ecs.html.Span)

Example 4 with Span

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

the class DefaultWatchListEventHTMLDiffExtractor method getObjectsHTMLDiff.

/**
 * @param objectDiffs the list of object diff
 * @param isXWikiClass true if the diff to compute is for an XWiki class, false if it's a plain XWiki object
 * @param documentFullName full name of the document the diff is computed for
 * @param diff the diff plugin API
 * @return the HTML string displaying the specified list of diffs
 */
private String getObjectsHTMLDiff(List<List<ObjectDiff>> objectDiffs, boolean isXWikiClass, String documentFullName, DiffPluginApi diff) {
    StringBuffer result = new StringBuffer();
    String propSeparator = ": ";
    String prefix = (isXWikiClass) ? "class" : "object";
    try {
        for (List<ObjectDiff> oList : objectDiffs) {
            if (oList.isEmpty()) {
                continue;
            }
            // The main container
            Div mainDiv = createDiffDiv(prefix + "Diff");
            // Class name
            Span objectName = createDiffSpan(prefix + "ClassName");
            if (isXWikiClass) {
                objectName.addElement(documentFullName);
            } else {
                objectName.addElement(oList.get(0).getClassName());
            }
            mainDiv.addElement(prefix + HTML_IMG_PLACEHOLDER_SUFFIX);
            mainDiv.addElement(objectName);
            // Diffs for each property
            for (ObjectDiff oDiff : oList) {
                String propDiff = getPropertyHTMLDiff(oDiff, diff);
                if (StringUtils.isBlank(oDiff.getPropName()) || StringUtils.isBlank(propDiff)) {
                    // Skip invalid properties or the ones that have no changed.
                    continue;
                }
                Div propDiv = createDiffDiv("propDiffContainer");
                // Property name
                Span propNameSpan = createDiffSpan("propName");
                propNameSpan.addElement(oDiff.getPropName() + propSeparator);
                String shortPropType = StringUtils.removeEnd(oDiff.getPropType(), "Class").toLowerCase();
                if (StringUtils.isBlank(shortPropType)) {
                    // When the diff shows a property that has been deleted, its type is not available.
                    shortPropType = HTML_IMG_METADATA_PREFIX;
                }
                propDiv.addElement(shortPropType + HTML_IMG_PLACEHOLDER_SUFFIX);
                propDiv.addElement(propNameSpan);
                // Property diff
                Div propDiffDiv = createDiffDiv("propDiff");
                propDiffDiv.addElement(propDiff);
                propDiv.addElement(propDiffDiv);
                // Add it to the main div
                mainDiv.addElement(propDiv);
            }
            result.append(mainDiv);
        }
    } catch (XWikiException e) {
        // Catch the exception to be sure we won't send emails containing stacktraces to users.
        logger.error("Failed to compute HTML objects or class diff", e);
    }
    return result.toString();
}
Also used : Div(org.apache.ecs.html.Div) ObjectDiff(com.xpn.xwiki.objects.ObjectDiff) Span(org.apache.ecs.html.Span) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

Span (org.apache.ecs.html.Span)4 XWikiException (com.xpn.xwiki.XWikiException)2 ObjectDiff (com.xpn.xwiki.objects.ObjectDiff)2 Div (org.apache.ecs.html.Div)2