1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.journalcontent;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.portlet.PortletLayoutListener;
20  import com.liferay.portal.kernel.portlet.PortletLayoutListenerException;
21  import com.liferay.portal.kernel.util.StringPool;
22  import com.liferay.portal.kernel.util.Validator;
23  import com.liferay.portal.model.Layout;
24  import com.liferay.portal.service.LayoutLocalServiceUtil;
25  import com.liferay.portlet.PortletPreferencesFactoryUtil;
26  import com.liferay.portlet.journal.NoSuchContentSearchException;
27  import com.liferay.portlet.journal.service.JournalContentSearchLocalServiceUtil;
28  
29  import javax.portlet.PortletPreferences;
30  
31  /**
32   * <a href="JournalContentPortletLayoutListener.java.html"><b><i>View Source</i>
33   * </b></a>
34   *
35   * @author Brian Wing Shun Chan
36   */
37  public class JournalContentPortletLayoutListener
38      implements PortletLayoutListener {
39  
40      public void onAddToLayout(String portletId, long plid)
41          throws PortletLayoutListenerException {
42  
43          if (_log.isDebugEnabled()) {
44              _log.debug("Add " + portletId + " to layout " + plid);
45          }
46      }
47  
48      public void onMoveInLayout(String portletId, long plid)
49          throws PortletLayoutListenerException {
50  
51          if (_log.isDebugEnabled()) {
52              _log.debug("Move " + portletId + " from in " + plid);
53          }
54      }
55  
56      public void onRemoveFromLayout(String portletId, long plid)
57          throws PortletLayoutListenerException {
58  
59          if (_log.isDebugEnabled()) {
60              _log.debug("Remove " + portletId + " from layout " + plid);
61          }
62  
63          try {
64              deleteContentSearch(portletId, plid);
65          }
66          catch (Exception e) {
67              throw new PortletLayoutListenerException(e);
68          }
69      }
70  
71      protected void deleteContentSearch(String portletId, long plid)
72          throws Exception {
73  
74          Layout layout = LayoutLocalServiceUtil.getLayout(plid);
75  
76          PortletPreferences preferences =
77              PortletPreferencesFactoryUtil.getPortletSetup(
78                  layout, portletId, StringPool.BLANK);
79  
80          String articleId = preferences.getValue("article-id", null);
81  
82          if (Validator.isNull(articleId)) {
83              return;
84          }
85  
86          try {
87              JournalContentSearchLocalServiceUtil.deleteArticleContentSearch(
88                  layout.getGroupId(), layout.isPrivateLayout(),
89                  layout.getLayoutId(), portletId, articleId);
90          }
91          catch (NoSuchContentSearchException nscse) {
92          }
93      }
94  
95      private static Log _log = LogFactoryUtil.getLog(
96          JournalContentPortletLayoutListener.class);
97  
98  }