1
22
23 package com.liferay.portlet.journalcontent;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27 import com.liferay.portal.kernel.portlet.PortletLayoutListener;
28 import com.liferay.portal.kernel.portlet.PortletLayoutListenerException;
29 import com.liferay.portal.kernel.util.StringPool;
30 import com.liferay.portal.kernel.util.Validator;
31 import com.liferay.portal.model.Layout;
32 import com.liferay.portal.service.LayoutLocalServiceUtil;
33 import com.liferay.portlet.PortletPreferencesFactoryUtil;
34 import com.liferay.portlet.journal.NoSuchContentSearchException;
35 import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
36
37 import javax.portlet.PortletPreferences;
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 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
84
85 PortletPreferences prefs =
86 PortletPreferencesFactoryUtil.getPortletSetup(
87 layout, portletId, StringPool.BLANK);
88
89 String articleId = prefs.getValue("article-id", null);
90
91 if (Validator.isNull(articleId)) {
92 return;
93 }
94
95 try {
96 JournalContentSearchLocalServiceUtil.deleteArticleContentSearch(
97 layout.getGroupId(), layout.isPrivateLayout(),
98 layout.getLayoutId(), portletId, articleId);
99 }
100 catch (NoSuchContentSearchException nscse) {
101 }
102 }
103
104 private static Log _log =
105 LogFactoryUtil.getLog(JournalContentPortletLayoutListener.class);
106
107 }