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
45 public class JournalContentPortletLayoutListener
46 implements PortletLayoutListener {
47
48 public void onAddToLayout(String portletId, long plid)
49 throws PortletLayoutListenerException {
50
51 if (_log.isDebugEnabled()) {
52 _log.debug("Add " + portletId + " to layout " + plid);
53 }
54 }
55
56 public void onMoveInLayout(String portletId, long plid)
57 throws PortletLayoutListenerException {
58
59 if (_log.isDebugEnabled()) {
60 _log.debug("Move " + portletId + " from in " + plid);
61 }
62 }
63
64 public void onRemoveFromLayout(String portletId, long plid)
65 throws PortletLayoutListenerException {
66
67 if (_log.isDebugEnabled()) {
68 _log.debug("Remove " + portletId + " from layout " + plid);
69 }
70
71 try {
72 deleteContentSearch(portletId, plid);
73 }
74 catch (Exception e) {
75 throw new PortletLayoutListenerException(e);
76 }
77 }
78
79 protected void deleteContentSearch(String portletId, long plid)
80 throws Exception {
81
82 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
83
84 PortletPreferences prefs =
85 PortletPreferencesFactoryUtil.getPortletSetup(
86 layout, portletId, StringPool.BLANK);
87
88 String articleId = prefs.getValue("article-id", null);
89
90 if (Validator.isNull(articleId)) {
91 return;
92 }
93
94 try {
95 JournalContentSearchLocalServiceUtil.deleteArticleContentSearch(
96 layout.getGroupId(), layout.isPrivateLayout(),
97 layout.getLayoutId(), portletId, articleId);
98 }
99 catch (NoSuchContentSearchException nscse) {
100 }
101 }
102
103 private static Log _log =
104 LogFactoryUtil.getLog(JournalContentPortletLayoutListener.class);
105
106 }