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.portal.util.WebKeys;
32 import com.liferay.portlet.PortletPreferencesFactoryUtil;
33 import com.liferay.portlet.journal.NoSuchContentSearchException;
34 import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
35
36 import javax.portlet.PortletPreferences;
37
38 import org.apache.commons.logging.Log;
39 import org.apache.commons.logging.LogFactory;
40
41 import org.springframework.mock.web.MockHttpServletRequest;
42
43
50 public class JournalContentPortletLayoutListener
51 implements PortletLayoutListener {
52
53 public void onAddToLayout(String portletId, long plid)
54 throws PortletLayoutListenerException {
55
56 if (_log.isDebugEnabled()) {
57 _log.debug("Add " + portletId + " to layout " + plid);
58 }
59 }
60
61 public void onMoveInLayout(String portletId, long plid)
62 throws PortletLayoutListenerException {
63
64 if (_log.isDebugEnabled()) {
65 _log.debug("Move " + portletId + " from in " + plid);
66 }
67 }
68
69 public void onRemoveFromLayout(String portletId, long plid)
70 throws PortletLayoutListenerException {
71
72 if (_log.isDebugEnabled()) {
73 _log.debug("Remove " + portletId + " from layout " + plid);
74 }
75
76 try {
77 deleteContentSearch(portletId, plid);
78 }
79 catch (Exception e) {
80 throw new PortletLayoutListenerException(e);
81 }
82 }
83
84 protected void deleteContentSearch(String portletId, long plid)
85 throws Exception {
86
87 MockHttpServletRequest request = new MockHttpServletRequest();
88
89 Layout layout = LayoutLocalServiceUtil.getLayout(plid);
90
91 request.setAttribute(WebKeys.LAYOUT, layout);
92
93 PortletPreferences prefs =
94 PortletPreferencesFactoryUtil.getPortletSetup(
95 request, portletId, StringPool.BLANK);
96
97 String articleId = prefs.getValue("article-id", null);
98
99 if (Validator.isNull(articleId)) {
100 return;
101 }
102
103 try {
104 JournalContentSearchLocalServiceUtil.deleteArticleContentSearch(
105 layout.getGroupId(), layout.isPrivateLayout(),
106 layout.getLayoutId(), portletId, articleId);
107 }
108 catch (NoSuchContentSearchException nscse) {
109 }
110 }
111
112 private static Log _log =
113 LogFactory.getLog(JournalContentPortletLayoutListener.class);
114
115 }