List of usage examples for com.liferay.portal.kernel.portlet PortletRequestModel PortletRequestModel
public PortletRequestModel(PortletRequest portletRequest, PortletResponse portletResponse)
From source file:com.liferay.journal.content.web.internal.display.context.JournalContentDisplayContext.java
License:Open Source License
public JournalArticleDisplay getArticleDisplay() { if (_articleDisplay != null) { return _articleDisplay; }//from ww w. ja v a 2 s.c o m _articleDisplay = (JournalArticleDisplay) _portletRequest.getAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY); if (_articleDisplay != null) { return _articleDisplay; } JournalArticle article = getArticle(); if (article == null) { return null; } ThemeDisplay themeDisplay = (ThemeDisplay) _portletRequest.getAttribute(WebKeys.THEME_DISPLAY); if (article.isApproved()) { JournalContent journalContent = (JournalContent) _portletRequest .getAttribute(JournalWebKeys.JOURNAL_CONTENT); _articleDisplay = journalContent.getDisplay(article.getGroupId(), article.getArticleId(), article.getVersion(), null, null, themeDisplay.getLanguageId(), 1, new PortletRequestModel(_portletRequest, _portletResponse), themeDisplay); } else { try { _articleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(article, null, null, themeDisplay.getLanguageId(), 1, new PortletRequestModel(_portletRequest, _portletResponse), themeDisplay); } catch (PortalException pe) { _log.error(pe, pe); } } return _articleDisplay; }
From source file:com.liferay.journal.content.web.internal.portlet.JournalContentPortlet.java
License:Open Source License
@Override public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { PortletPreferences portletPreferences = renderRequest.getPreferences(); ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY); long articleGroupId = PrefsParamUtil.getLong(portletPreferences, renderRequest, "groupId", themeDisplay.getScopeGroupId()); String articleId = PrefsParamUtil.getString(portletPreferences, renderRequest, "articleId"); String ddmTemplateKey = PrefsParamUtil.getString(portletPreferences, renderRequest, "ddmTemplateKey"); JournalArticle article = null;//w w w .j a va 2 s . co m JournalArticleDisplay articleDisplay = null; if ((articleGroupId > 0) && Validator.isNotNull(articleId)) { String viewMode = ParamUtil.getString(renderRequest, "viewMode"); String languageId = LanguageUtil.getLanguageId(renderRequest); int page = ParamUtil.getInteger(renderRequest, "page", 1); article = _journalArticleLocalService.fetchLatestArticle(articleGroupId, articleId, WorkflowConstants.STATUS_APPROVED); try { if (article == null) { article = _journalArticleLocalService.getLatestArticle(articleGroupId, articleId, WorkflowConstants.STATUS_ANY); } if (Validator.isNull(ddmTemplateKey)) { ddmTemplateKey = article.getDDMTemplateKey(); } articleDisplay = _journalContent.getDisplay(article, ddmTemplateKey, viewMode, languageId, page, new PortletRequestModel(renderRequest, renderResponse), themeDisplay); } catch (Exception e) { renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE); } } if (article != null) { renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE, article); } if (articleDisplay != null) { renderRequest.setAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY, articleDisplay); } else { renderRequest.removeAttribute(WebKeys.JOURNAL_ARTICLE_DISPLAY); } super.doView(renderRequest, renderResponse); }
From source file:com.liferay.journal.search.JournalArticleIndexer.java
License:Open Source License
protected String getDDMContentSummary(Document document, Locale snippetLocale, PortletRequest portletRequest, PortletResponse portletResponse) { String content = StringPool.BLANK; if ((portletRequest == null) || (portletResponse == null)) { return content; }//ww w .j av a2s .c o m try { String articleId = document.get(Field.ARTICLE_ID); long groupId = GetterUtil.getLong(document.get(Field.GROUP_ID)); double version = GetterUtil.getDouble(document.get(Field.VERSION)); PortletRequestModel portletRequestModel = new PortletRequestModel(portletRequest, portletResponse); ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); JournalArticleDisplay articleDisplay = _journalContent.getDisplay(groupId, articleId, version, null, Constants.VIEW, LocaleUtil.toLanguageId(snippetLocale), 1, portletRequestModel, themeDisplay); content = articleDisplay.getDescription(); content = HtmlUtil.replaceNewLine(content); if (Validator.isNull(content)) { content = HtmlUtil.extractText(articleDisplay.getContent()); } } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } return content; }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected void notifySubscribers(long userId, JournalArticle article, String action, ServiceContext serviceContext) throws PortalException { String portletId = PortletProviderUtil.getPortletId(JournalArticle.class.getName(), PortletProvider.Action.EDIT); String articleURL = PortalUtil.getControlPanelFullURL(article.getGroupId(), portletId, null); if (!article.isApproved() || Validator.isNull(articleURL)) { return;//from w ww . ja v a 2s .c o m } JournalGroupServiceConfiguration journalGroupServiceConfiguration = getJournalGroupServiceConfiguration( article.getGroupId()); String articleTitle = article.getTitle(serviceContext.getLanguageId()); articleURL = buildArticleURL(articleURL, article.getGroupId(), article.getFolderId(), article.getArticleId()); if (action.equals("add") && journalGroupServiceConfiguration.emailArticleAddedEnabled()) { } else if (action.equals("move_to") && journalGroupServiceConfiguration.emailArticleMovedToFolderEnabled()) { } else if (action.equals("move_from") && journalGroupServiceConfiguration.emailArticleMovedFromFolderEnabled()) { } else if (action.equals("update") && journalGroupServiceConfiguration.emailArticleUpdatedEnabled()) { } else { return; } String fromName = journalGroupServiceConfiguration.emailFromName(); String fromAddress = journalGroupServiceConfiguration.emailFromAddress(); Map<Locale, String> localizedSubjectMap = null; Map<Locale, String> localizedBodyMap = null; int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY; if (action.equals("add")) { localizedSubjectMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleAddedSubject()); localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleAddedBody()); } else if (action.equals("move_to")) { localizedSubjectMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderSubject()); localizedBodyMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleMovedToFolderBody()); notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_TO_FOLDER; } else if (action.equals("move_from")) { localizedSubjectMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderSubject()); localizedBodyMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleMovedFromFolderBody()); notificationType = JournalArticleConstants.NOTIFICATION_TYPE_MOVE_ENTRY_FROM_FOLDER; } else if (action.equals("update")) { localizedSubjectMap = LocalizationUtil .getMap(journalGroupServiceConfiguration.emailArticleUpdatedSubject()); localizedBodyMap = LocalizationUtil.getMap(journalGroupServiceConfiguration.emailArticleUpdatedBody()); notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY; } String articleContent = StringPool.BLANK; String articleDiffs = StringPool.BLANK; JournalArticle previousApprovedArticle = getPreviousApprovedArticle(article); try { PortletRequestModel portletRequestModel = new PortletRequestModel( serviceContext.getLiferayPortletRequest(), serviceContext.getLiferayPortletResponse()); JournalArticleDisplay articleDisplay = getArticleDisplay(article, null, Constants.VIEW, LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), 1, portletRequestModel, serviceContext.getThemeDisplay()); articleContent = articleDisplay.getContent(); articleDiffs = JournalUtil.diffHtml(article.getGroupId(), article.getArticleId(), previousApprovedArticle.getVersion(), article.getVersion(), LocaleUtil.toLanguageId(LocaleUtil.getSiteDefault()), portletRequestModel, serviceContext.getThemeDisplay()); } catch (Exception e) { } SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender( JournalPermission.RESOURCE_NAME); subscriptionSender.setClassName(article.getModelClassName()); subscriptionSender.setClassPK(article.getId()); subscriptionSender.setCompanyId(article.getCompanyId()); subscriptionSender.setContextAttribute("[$ARTICLE_CONTENT$]", articleContent, false); subscriptionSender.setContextAttribute("[$ARTICLE_DIFFS$]", DiffHtmlUtil.replaceStyles(articleDiffs), false); JournalFolder folder = article.getFolder(); subscriptionSender.setContextAttributes("[$ARTICLE_ID$]", article.getArticleId(), "[$ARTICLE_TITLE$]", articleTitle, "[$ARTICLE_URL$]", articleURL, "[$ARTICLE_VERSION$]", article.getVersion(), "[$FOLDER_NAME$]", folder.getName()); subscriptionSender.setContextCreatorUserPrefix("ARTICLE"); subscriptionSender.setCreatorUserId(article.getUserId()); subscriptionSender.setCurrentUserId(userId); subscriptionSender.setEntryTitle(articleTitle); subscriptionSender.setEntryURL(articleURL); subscriptionSender.setFrom(fromAddress, fromName); subscriptionSender.setHtmlFormat(true); subscriptionSender.setLocalizedBodyMap(localizedBodyMap); subscriptionSender.setLocalizedSubjectMap(localizedSubjectMap); subscriptionSender.setMailId("journal_article", article.getId()); subscriptionSender.setNotificationType(notificationType); subscriptionSender.setPortletId(portletId); subscriptionSender.setReplyToAddress(fromAddress); subscriptionSender.setScopeGroupId(article.getGroupId()); subscriptionSender.setServiceContext(serviceContext); subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), article.getGroupId()); if (folder != null) { subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), folder.getFolderId()); for (Long ancestorFolderId : folder.getAncestorFolderIds()) { subscriptionSender.addPersistedSubscribers(JournalFolder.class.getName(), ancestorFolderId); } } DDMStructure ddmStructure = ddmStructureLocalService.getStructure(article.getGroupId(), classNameLocalService.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); subscriptionSender.addPersistedSubscribers(DDMStructure.class.getName(), ddmStructure.getStructureId()); subscriptionSender.addPersistedSubscribers(JournalArticle.class.getName(), article.getResourcePrimKey()); subscriptionSender.flushNotificationsAsync(); }
From source file:com.liferay.journal.taglib.servlet.taglib.JournalArticleTag.java
License:Open Source License
@Override public int doStartTag() throws JspException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletRequest portletRequest = (PortletRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST); PortletResponse portletResponse = (PortletResponse) request .getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE); PortletRequestModel portletRequestModel = new PortletRequestModel(portletRequest, portletResponse); _article = JournalArticleLocalServiceUtil.fetchLatestArticle(_groupId, _articleId, WorkflowConstants.STATUS_APPROVED); try {/*w ww . ja va2s .c om*/ _articleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(_article.getGroupId(), _article.getArticleId(), _article.getVersion(), _ddmTemplateKey, Constants.VIEW, getLanguageId(), 1, portletRequestModel, themeDisplay); } catch (PortalException pe) { if (_log.isDebugEnabled()) { _log.debug("Unable to get journal article display", pe); } return SKIP_BODY; } return super.doStartTag(); }
From source file:com.liferay.journal.web.asset.JournalArticleAssetRenderer.java
License:Open Source License
@Override public String getSummary(PortletRequest portletRequest, PortletResponse portletResponse) { Locale locale = getLocale(portletRequest); String summary = _article.getDescription(locale); if (Validator.isNotNull(summary)) { return summary; }/*from ww w.jav a2 s . c om*/ try { PortletRequestModel portletRequestModel = null; ThemeDisplay themeDisplay = null; if ((portletRequest != null) && (portletResponse != null)) { portletRequestModel = new PortletRequestModel(portletRequest, portletResponse); themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY); } JournalArticleDisplay articleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(_article, null, null, LanguageUtil.getLanguageId(locale), 1, portletRequestModel, themeDisplay); summary = HtmlUtil.stripHtml(articleDisplay.getContent()); } catch (Exception e) { } return summary; }
From source file:com.liferay.journal.web.asset.JournalArticleAssetRenderer.java
License:Open Source License
protected PortletRequestModel getPortletRequestModel(HttpServletRequest request, HttpServletResponse response) { PortletRequest portletRequest = (PortletRequest) request.getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST); PortletResponse portletResponse = (PortletResponse) request .getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE); if ((portletRequest == null) || (portletResponse == null)) { return null; }//www.j a va2s . c o m return new PortletRequestModel(portletRequest, portletResponse); }
From source file:com.liferay.journal.web.internal.display.context.JournalDisplayContext.java
License:Open Source License
public JournalArticleDisplay getArticleDisplay() throws Exception { if (_articleDisplay != null) { return _articleDisplay; }/*w ww .j av a 2 s . co m*/ ThemeDisplay themeDisplay = (ThemeDisplay) _request.getAttribute(WebKeys.THEME_DISPLAY); int page = ParamUtil.getInteger(_liferayPortletRequest, "page"); _articleDisplay = JournalArticleLocalServiceUtil.getArticleDisplay(getArticle(), null, null, themeDisplay.getLanguageId(), page, new PortletRequestModel(_liferayPortletRequest, _liferayPortletResponse), themeDisplay); return _articleDisplay; }
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()); }// w w w .ja va 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 av a 2 s. c om 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); } }