1
19
20 package com.liferay.portlet.journalcontent;
21
22 import com.liferay.portal.kernel.log.Log;
23 import com.liferay.portal.kernel.log.LogFactoryUtil;
24 import com.liferay.portal.kernel.portlet.PortletLayoutListener;
25 import com.liferay.portal.kernel.portlet.PortletLayoutListenerException;
26 import com.liferay.portal.kernel.util.StringPool;
27 import com.liferay.portal.kernel.util.Validator;
28 import com.liferay.portal.model.Layout;
29 import com.liferay.portal.service.LayoutLocalServiceUtil;
30 import com.liferay.portal.util.WebKeys;
31 import com.liferay.portlet.PortletPreferencesFactoryUtil;
32 import com.liferay.portlet.journal.NoSuchContentSearchException;
33 import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
34
35 import javax.portlet.PortletPreferences;
36
37 import org.springframework.mock.web.MockHttpServletRequest;
38
39
46 public class JournalContentPortletLayoutListener
47 implements PortletLayoutListener {
48
49 public void onAddToLayout(String portletId, long plid)
50 throws PortletLayoutListenerException {
51
52 if (_log.isDebugEnabled()) {
53 _log.debug("Add " + portletId + " to layout " + plid);
54 }
55 }
56
57 public void onMoveInLayout(String portletId, long plid)
58 throws PortletLayoutListenerException {
59
60 if (_log.isDebugEnabled()) {
61 _log.debug("Move " + portletId + " from in " + plid);
62 }
63 }
64
65 public void onRemoveFromLayout(String portletId, long plid)
66 throws PortletLayoutListenerException {
67
68 if (_log.isDebugEnabled()) {
69 _log.debug("Remove " + portletId + " from layout " + plid);
70 }
71
72 try {
73 deleteContentSearch(portletId, plid);
74 }
75 catch (Exception e) {
76 throw new PortletLayoutListenerException(e);
77 }
78 }
79
80 protected void deleteContentSearch(String portletId, long plid)
81 throws Exception {
82
83 MockHttpServletRequest request = new MockHttpServletRequest();
84
85 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
86
87 request.setAttribute(WebKeys.LAYOUT, layout);
88
89 PortletPreferences prefs =
90 PortletPreferencesFactoryUtil.getPortletSetup(
91 request, portletId, StringPool.BLANK);
92
93 String articleId = prefs.getValue("article-id", null);
94
95 if (Validator.isNull(articleId)) {
96 return;
97 }
98
99 try {
100 JournalContentSearchLocalServiceUtil.deleteArticleContentSearch(
101 layout.getGroupId(), layout.isPrivateLayout(),
102 layout.getLayoutId(), portletId, articleId);
103 }
104 catch (NoSuchContentSearchException nscse) {
105 }
106 }
107
108 private static Log _log =
109 LogFactoryUtil.getLog(JournalContentPortletLayoutListener.class);
110
111 }