Example usage for com.liferay.portal.kernel.diff CompareVersionsException getVersion

List of usage examples for com.liferay.portal.kernel.diff CompareVersionsException getVersion

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.diff CompareVersionsException getVersion.

Prototype

public double getVersion() 

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());
    }/*from w w  w  .j  a  v  a  2  s .c om*/

    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 w  w.j  a  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);
    }
}