001    /**
002     * Copyright (c) 2000-2013 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.portlet.journal.model;
016    
017    import com.liferay.portal.kernel.freemarker.FreeMarkerEngineUtil;
018    import com.liferay.portal.kernel.velocity.VelocityEngineUtil;
019    import com.liferay.portal.model.BaseModelListener;
020    import com.liferay.portal.servlet.filters.cache.CacheUtil;
021    import com.liferay.portlet.journalcontent.util.JournalContentUtil;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     * @author Jon Steer
026     * @author Raymond Aug??
027     * @author Shuyang Zhou
028     */
029    public class JournalTemplateListener
030            extends BaseModelListener<JournalTemplate> {
031    
032            @Override
033            public void onAfterRemove(JournalTemplate template) {
034                    clearCache(template);
035            }
036    
037            @Override
038            public void onAfterUpdate(JournalTemplate template) {
039                    clearCache(template);
040            }
041    
042            protected void clearCache(JournalTemplate template) {
043    
044                    // Freemarker cache
045    
046                    String freeMarkerTemplateId =
047                            template.getCompanyId() + template.getGroupId() +
048                                    template.getTemplateId();
049    
050                    FreeMarkerEngineUtil.flushTemplate(freeMarkerTemplateId);
051    
052                    // Journal content
053    
054                    JournalContentUtil.clearCache();
055    
056                    // Layout cache
057    
058                    CacheUtil.clearCache(template.getCompanyId());
059    
060                    // Velocity cache
061    
062                    VelocityEngineUtil.flushTemplate(freeMarkerTemplateId);
063            }
064    
065    }