001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.staticexport;
029
030import org.opencms.i18n.CmsLocaleManager;
031import org.opencms.main.OpenCms;
032
033import java.io.File;
034import java.util.ArrayList;
035import java.util.Iterator;
036import java.util.List;
037import java.util.Locale;
038
039/**
040 * Extended after publish static export handler, supporting multi-language exports.<p>
041 *
042 * @since 7.0.3
043 *
044 * @see CmsAfterPublishStaticExportHandler
045 * @see I_CmsStaticExportHandler
046 */
047public class CmsAfterPublishMultiLanguageStaticExportHandler extends CmsAfterPublishStaticExportHandler {
048
049    /** Cached locale matching rules. */
050    private static List<CmsStaticExportRfsRule> m_rules;
051
052    /**
053     * @see org.opencms.staticexport.CmsAfterPublishStaticExportHandler#getRelatedFilesToPurge(java.lang.String, java.lang.String)
054     */
055    @Override
056    protected List<File> getRelatedFilesToPurge(String exportFileName, String vfsName) {
057
058        CmsStaticExportManager manager = OpenCms.getStaticExportManager();
059        List<File> result = new ArrayList<File>();
060        if (m_rules == null) {
061            // get the locale matching rules
062            CmsLocaleManager locManager = OpenCms.getLocaleManager();
063            m_rules = new ArrayList<CmsStaticExportRfsRule>();
064            Iterator<CmsStaticExportRfsRule> itRules = manager.getRfsRules().iterator();
065            while (itRules.hasNext()) {
066                CmsStaticExportRfsRule rule = itRules.next();
067                Locale locale = CmsLocaleManager.getLocale(rule.getName());
068                if (locManager.getDefaultLocales().contains(locale)) {
069                    m_rules.add(rule);
070                }
071            }
072        }
073        // add paths for all possible locales
074        Iterator<CmsStaticExportRfsRule> it = m_rules.iterator();
075        while (it.hasNext()) {
076            CmsStaticExportRfsRule rule = it.next();
077            result.add(new File(rule.getLocalizedRfsName(exportFileName, File.separator)));
078        }
079        return result;
080    }
081}