1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
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  /**
40   * <a href="JournalContentPortletLayoutListener.java.html"><b><i>View Source</i>
41   * </b></a>
42   *
43   * @author Brian Wing Shun Chan
44   */
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 }