001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }