List of usage examples for com.liferay.portal.util PropsValues BLOGS_PINGBACK_ENABLED
boolean BLOGS_PINGBACK_ENABLED
To view the source code for com.liferay.portal.util PropsValues BLOGS_PINGBACK_ENABLED.
Click Source Link
From source file:com.liferay.blogs.internal.util.PingbackMethodImpl.java
License:Open Source License
protected long addPingback(long companyId) throws Exception { if (!PropsValues.BLOGS_PINGBACK_ENABLED) { throw new DisabledPingbackException("Pingbacks are disabled"); }//w w w .j av a2 s. c om validateSource(); BlogsEntry entry = getBlogsEntry(companyId); if (!entry.isAllowPingbacks() || Validator.isNull(entry.getUrlTitle())) { throw new DisabledPingbackException("Pingbacks are disabled"); } long userId = _userLocalService.getDefaultUserId(companyId); long groupId = entry.getGroupId(); String className = BlogsEntry.class.getName(); long classPK = entry.getEntryId(); String body = "[...] " + getExcerpt() + " [...] [url=" + _sourceURI + "]" + LanguageUtil.get(LocaleUtil.getSiteDefault(), "read-more") + "[/url]"; ServiceContext serviceContext = buildServiceContext(companyId, groupId, entry.getUrlTitle()); return _commentManager.addComment(userId, groupId, className, classPK, body, new IdentityServiceContextFunction(serviceContext)); }
From source file:com.liferay.blogs.internal.util.PingbackMethodImplTest.java
License:Open Source License
@Test public void testAddPingbackWhenPortalPropertyDisablesPingbacks() throws Exception { boolean previous = PropsValues.BLOGS_PINGBACK_ENABLED; Whitebox.setInternalState(PropsValues.class, "BLOGS_PINGBACK_ENABLED", false); try {/*from ww w . ja v a 2s .c o m*/ execute(); verifyFault(XmlRpcConstants.REQUESTED_METHOD_NOT_FOUND, "Pingbacks are disabled"); } finally { Whitebox.setInternalState(PropsValues.class, "BLOGS_PINGBACK_ENABLED", previous); } }
From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected void pingPingback(BlogsEntry entry, ServiceContext serviceContext) throws PortalException { if (!PropsValues.BLOGS_PINGBACK_ENABLED || !entry.isAllowPingbacks() || !entry.isApproved()) { return;//from w ww .j a v a 2s .c o m } HttpServletRequest request = serviceContext.getRequest(); if (request == null) { return; } ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String layoutFullURL = PortalUtil.getLayoutFullURL(themeDisplay); if (Validator.isNull(layoutFullURL)) { return; } String sourceUri = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/" + entry.getUrlTitle(); Source source = new Source(entry.getContent()); List<StartTag> tags = source.getAllStartTags("a"); for (StartTag tag : tags) { String targetUri = tag.getAttributeValue("href"); if (Validator.isNotNull(targetUri)) { try { LinkbackProducerUtil.sendPingback(sourceUri, targetUri); } catch (Exception e) { _log.error("Error while sending pingback " + targetUri, e); } } } }
From source file:com.liferay.blogs.web.internal.portlet.action.ViewEntryMVCRenderCommand.java
License:Open Source License
@Override public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException { long assetCategoryId = ParamUtil.getLong(renderRequest, "categoryId"); String assetCategoryName = ParamUtil.getString(renderRequest, "tag"); if ((assetCategoryId > 0) || Validator.isNotNull(assetCategoryName)) { return "/blogs/view.jsp"; }//from ww w . j a v a 2s.co m try { ActionUtil.getEntry(renderRequest); if (PropsValues.BLOGS_PINGBACK_ENABLED) { BlogsEntry entry = (BlogsEntry) renderRequest.getAttribute(WebKeys.BLOGS_ENTRY); if ((entry != null) && entry.isAllowPingbacks()) { HttpServletResponse response = PortalUtil.getHttpServletResponse(renderResponse); response.addHeader("X-Pingback", PortalUtil.getPortalURL(renderRequest) + "/xmlrpc/pingback"); } } } catch (Exception e) { if (e instanceof NoSuchEntryException || e instanceof PrincipalException) { SessionErrors.add(renderRequest, e.getClass()); return "/blogs/error.jsp"; } else { throw new PortletException(e); } } return "/blogs/view_entry.jsp"; }
From source file:com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
protected void pingPingback(BlogsEntry entry, ServiceContext serviceContext) { if (!PropsValues.BLOGS_PINGBACK_ENABLED || !entry.isAllowPingbacks() || !entry.isApproved()) { return;//ww w. ja v a 2 s .co m } String layoutFullURL = serviceContext.getLayoutFullURL(); if (Validator.isNull(layoutFullURL)) { return; } String sourceUri = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "blogs/" + entry.getUrlTitle(); Source source = new Source(entry.getContent()); List<StartTag> tags = source.getAllStartTags("a"); for (StartTag tag : tags) { String targetUri = tag.getAttributeValue("href"); if (Validator.isNotNull(targetUri)) { try { LinkbackProducerUtil.sendPingback(sourceUri, targetUri); } catch (Exception e) { _log.error("Error while sending pingback " + targetUri, e); } } } }
From source file:com.liferay.portlet.blogs.util.PingbackMethodImpl.java
License:Open Source License
public Response execute(long companyId) { if (!PropsValues.BLOGS_PINGBACK_ENABLED) { return XmlRpcUtil.createFault(XmlRpcConstants.REQUESTED_METHOD_NOT_FOUND, "Pingbacks are disabled"); }//from w w w . j a v a2s.c o m Response response = validateSource(); if (response != null) { return response; } try { BlogsEntry entry = getBlogsEntry(companyId); if (!entry.isAllowPingbacks()) { return XmlRpcUtil.createFault(XmlRpcConstants.REQUESTED_METHOD_NOT_FOUND, "Pingbacks are disabled"); } long userId = UserLocalServiceUtil.getDefaultUserId(companyId); long groupId = entry.getGroupId(); String className = BlogsEntry.class.getName(); long classPK = entry.getEntryId(); MBMessageDisplay messageDisplay = MBMessageLocalServiceUtil.getDiscussionMessageDisplay(userId, groupId, className, classPK, WorkflowConstants.STATUS_APPROVED); MBThread thread = messageDisplay.getThread(); long threadId = thread.getThreadId(); long parentMessageId = thread.getRootMessageId(); String body = "[...] " + getExcerpt() + " [...] [url=" + _sourceUri + "]" + LanguageUtil.get(LocaleUtil.getDefault(), "read-more") + "[/url]"; List<MBMessage> messages = MBMessageLocalServiceUtil.getThreadMessages(threadId, WorkflowConstants.STATUS_APPROVED); for (MBMessage message : messages) { if (message.getBody().equals(body)) { return XmlRpcUtil.createFault(PINGBACK_ALREADY_REGISTERED, "Pingback previously registered"); } } ServiceContext serviceContext = new ServiceContext(); String pingbackUserName = LanguageUtil.get(LocaleUtil.getDefault(), "pingback"); serviceContext.setAttribute("pingbackUserName", pingbackUserName); StringBundler sb = new StringBundler(5); String layoutFullURL = PortalUtil.getLayoutFullURL(groupId, PortletKeys.BLOGS); sb.append(layoutFullURL); sb.append(Portal.FRIENDLY_URL_SEPARATOR); Portlet portlet = PortletLocalServiceUtil.getPortletById(companyId, PortletKeys.BLOGS); sb.append(portlet.getFriendlyURLMapping()); sb.append(StringPool.SLASH); sb.append(entry.getUrlTitle()); serviceContext.setAttribute("redirect", sb.toString()); serviceContext.setLayoutFullURL(layoutFullURL); MBMessageLocalServiceUtil.addDiscussionMessage(userId, StringPool.BLANK, groupId, className, classPK, threadId, parentMessageId, StringPool.BLANK, body, serviceContext); return XmlRpcUtil.createSuccess("Pingback accepted"); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } return XmlRpcUtil.createFault(TARGET_URI_INVALID, "Error parsing target URI"); } }
From source file:com.liferay.portlet.messageboards.service.impl.MBMessageLocalServiceImpl.java
License:Open Source License
protected void pingPingback(MBMessage message, ServiceContext serviceContext) { if (!PropsValues.BLOGS_PINGBACK_ENABLED || !message.isAllowPingbacks() || !message.isApproved()) { return;//from w w w .j a v a 2s . c o m } String layoutFullURL = serviceContext.getLayoutFullURL(); if (Validator.isNull(layoutFullURL)) { return; } String sourceUri = layoutFullURL + Portal.FRIENDLY_URL_SEPARATOR + "message_boards/view_message/" + message.getMessageId(); Source source = new Source(message.getBody(true)); List<StartTag> startTags = source.getAllStartTags("a"); for (StartTag startTag : startTags) { String targetUri = startTag.getAttributeValue("href"); if (Validator.isNotNull(targetUri)) { try { LinkbackProducerUtil.sendPingback(sourceUri, targetUri); } catch (Exception e) { _log.error("Error while sending pingback " + targetUri, e); } } } }