Example usage for com.liferay.portal.kernel.util WebKeys DIFF_VERSION

List of usage examples for com.liferay.portal.kernel.util WebKeys DIFF_VERSION

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util WebKeys DIFF_VERSION.

Prototype

String DIFF_VERSION

To view the source code for com.liferay.portal.kernel.util WebKeys DIFF_VERSION.

Click Source Link

Usage

From source file:com.liferay.journal.web.internal.portlet.action.ActionUtil.java

License:Open Source License

public static void compareVersions(RenderRequest renderRequest, RenderResponse renderResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(renderRequest, "groupId");
    String articleId = ParamUtil.getString(renderRequest, "articleId");

    String sourceArticleId = ParamUtil.getString(renderRequest, "sourceVersion");

    int index = sourceArticleId.lastIndexOf(JournalPortlet.VERSION_SEPARATOR);

    if (index != -1) {
        sourceArticleId = sourceArticleId.substring(index + JournalPortlet.VERSION_SEPARATOR.length(),
                sourceArticleId.length());
    }/*  ww  w  .j  a  v a2s.co  m*/

    double sourceVersion = GetterUtil.getDouble(sourceArticleId);

    String targetArticleId = ParamUtil.getString(renderRequest, "targetVersion");

    index = targetArticleId.lastIndexOf(JournalPortlet.VERSION_SEPARATOR);

    if (index != -1) {
        targetArticleId = targetArticleId.substring(index + JournalPortlet.VERSION_SEPARATOR.length(),
                targetArticleId.length());
    }

    double targetVersion = GetterUtil.getDouble(targetArticleId);

    if ((sourceVersion == 0) && (targetVersion == 0)) {
        List<JournalArticle> sourceArticles = JournalArticleServiceUtil.getArticlesByArticleId(groupId,
                articleId, 0, 1, new ArticleVersionComparator(false));

        JournalArticle sourceArticle = sourceArticles.get(0);

        sourceVersion = sourceArticle.getVersion();

        List<JournalArticle> targetArticles = JournalArticleServiceUtil.getArticlesByArticleId(groupId,
                articleId, 0, 1, new ArticleVersionComparator(true));

        JournalArticle targetArticle = targetArticles.get(0);

        targetVersion = targetArticle.getVersion();
    }

    if (sourceVersion > targetVersion) {
        double tempVersion = targetVersion;

        targetVersion = sourceVersion;
        sourceVersion = tempVersion;
    }

    String languageId = getLanguageId(renderRequest, groupId, articleId, sourceVersion, targetVersion);

    String diffHtmlResults = null;

    try {
        diffHtmlResults = JournalUtil.diffHtml(groupId, articleId, sourceVersion, targetVersion, languageId,
                new PortletRequestModel(renderRequest, renderResponse), themeDisplay);
    } catch (CompareVersionsException cve) {
        renderRequest.setAttribute(WebKeys.DIFF_VERSION, cve.getVersion());
    }

    renderRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, diffHtmlResults);
    renderRequest.setAttribute(WebKeys.SOURCE_VERSION, sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_VERSION, targetVersion);
}

From source file:com.liferay.journal.web.internal.portlet.JournalPortlet.java

License:Open Source License

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {

    resourceRequest.setAttribute(JournalWebConfiguration.class.getName(), _journalWebConfiguration);

    String resourceID = GetterUtil.getString(resourceRequest.getResourceID());

    HttpServletRequest request = _portal.getHttpServletRequest(resourceRequest);

    HttpServletResponse response = _portal.getHttpServletResponse(resourceResponse);

    if (resourceID.equals("compareVersions")) {
        ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

        long groupId = ParamUtil.getLong(resourceRequest, "groupId");
        String articleId = ParamUtil.getString(resourceRequest, "articleId");
        double sourceVersion = ParamUtil.getDouble(resourceRequest, "filterSourceVersion");
        double targetVersion = ParamUtil.getDouble(resourceRequest, "filterTargetVersion");
        String languageId = ParamUtil.getString(resourceRequest, "languageId");

        String diffHtmlResults = null;

        try {//  w ww. ja v  a  2s  .c o m
            diffHtmlResults = JournalUtil.diffHtml(groupId, articleId, sourceVersion, targetVersion, languageId,
                    new PortletRequestModel(resourceRequest, resourceResponse), themeDisplay);
        } catch (CompareVersionsException cve) {
            resourceRequest.setAttribute(WebKeys.DIFF_VERSION, cve.getVersion());
        } catch (Exception e) {
            try {
                _portal.sendError(e, request, response);
            } catch (ServletException se) {
            }
        }

        resourceRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, diffHtmlResults);

        PortletSession portletSession = resourceRequest.getPortletSession();

        PortletContext portletContext = portletSession.getPortletContext();

        PortletRequestDispatcher portletRequestDispatcher = portletContext
                .getRequestDispatcher("/compare_versions_diff_html.jsp");

        portletRequestDispatcher.include(resourceRequest, resourceResponse);
    } else {
        super.serveResource(resourceRequest, resourceResponse);
    }
}