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