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

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

Introduction

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

Prototype

String DIFF_HTML_RESULTS

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

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

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

License:Open Source License

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

    long nodeId = ParamUtil.getLong(renderRequest, "nodeId");
    String title = ParamUtil.getString(renderRequest, "title");
    double sourceVersion = ParamUtil.getDouble(renderRequest, "sourceVersion");
    double targetVersion = ParamUtil.getDouble(renderRequest, "targetVersion");

    String htmlDiffResult = getHtmlDiffResult(sourceVersion, targetVersion, renderRequest, renderResponse,
            wikiEngineRenderer);/*from   ww w  .  j ava2s. c  om*/

    renderRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, htmlDiffResult);
    renderRequest.setAttribute(WebKeys.SOURCE_VERSION, sourceVersion);
    renderRequest.setAttribute(WebKeys.TARGET_VERSION, targetVersion);
    renderRequest.setAttribute(WebKeys.TITLE, title);
    renderRequest.setAttribute(WikiWebKeys.WIKI_NODE_ID, nodeId);
}

From source file:com.liferay.wiki.web.internal.portlet.action.CompareVersionsMVCResourceCommand.java

License:Open Source License

@Override
protected void doServeResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    double sourceVersion = ParamUtil.getDouble(resourceRequest, "filterSourceVersion");
    double targetVersion = ParamUtil.getDouble(resourceRequest, "filterTargetVersion");

    String htmlDiffResult = ActionUtil.getHtmlDiffResult(sourceVersion, targetVersion, resourceRequest,
            resourceResponse, _wikiEngineRenderer);

    resourceRequest.setAttribute(WebKeys.DIFF_HTML_RESULTS, htmlDiffResult);

    include(resourceRequest, resourceResponse, "/wiki/compare_versions_diff_html.jsp");
}