001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.model;
016    
017    import com.liferay.portal.service.LayoutLocalServiceUtil;
018    import com.liferay.portal.servlet.filters.cache.CacheUtil;
019    
020    /**
021     * @author Alexander Chow
022     * @author Raymond Augé
023     */
024    public class PortletPreferencesListener
025            extends BaseModelListener<PortletPreferences> {
026    
027            public void onAfterRemove(PortletPreferences portletPreferences) {
028                    clearCache(portletPreferences);
029            }
030    
031            public void onAfterUpdate(PortletPreferences portletPreferences) {
032                    clearCache(portletPreferences);
033            }
034    
035            protected void clearCache(PortletPreferences portletPreferences) {
036                    try {
037                            Layout layout = LayoutLocalServiceUtil.getLayout(
038                                    portletPreferences.getPlid());
039    
040                            if (!layout.isPrivateLayout()) {
041                                    CacheUtil.clearCache(layout.getCompanyId());
042                            }
043                    }
044                    catch (Exception e) {
045                            CacheUtil.clearCache();
046                    }
047            }
048    
049    }