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.scheduler.jobs;
029
030import org.opencms.file.CmsObject;
031import org.opencms.main.CmsEvent;
032import org.opencms.main.CmsException;
033import org.opencms.main.I_CmsEventListener;
034import org.opencms.main.OpenCms;
035import org.opencms.report.CmsLogReport;
036import org.opencms.report.I_CmsReport;
037import org.opencms.scheduler.I_CmsScheduledJob;
038import org.opencms.staticexport.Messages;
039
040import java.io.IOException;
041import java.util.HashMap;
042import java.util.Map;
043
044import javax.servlet.ServletException;
045
046/**
047 * A schedulable OpenCms job to write a complete static export (e.g. nightly exports).<p>
048 *
049 * This job does not have any parameters.<p>
050 *
051 * @since 6.0.0
052 */
053public class CmsStaticExportJob implements I_CmsScheduledJob {
054
055    /**
056     * @see org.opencms.scheduler.I_CmsScheduledJob#launch(CmsObject, Map)
057     */
058    public String launch(CmsObject cms, Map<String, String> parameters) throws Exception {
059
060        I_CmsReport report = null;
061
062        try {
063            report = new CmsLogReport(cms.getRequestContext().getLocale(), CmsStaticExportJob.class);
064            OpenCms.getStaticExportManager().exportFullStaticRender(true, report);
065            Map<String, Object> eventData = new HashMap<String, Object>();
066            eventData.put("purge", Boolean.TRUE);
067            eventData.put(I_CmsEventListener.KEY_REPORT, report);
068            OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_FULLSTATIC_EXPORT, eventData));
069        } catch (CmsException e) {
070            report.println(e);
071        } catch (IOException e) {
072            report.println(e);
073        } catch (ServletException e) {
074            report.println(e);
075        } finally {
076            // append runtime statistics to the report
077            if (report != null) {
078                report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_STAT_0));
079                report.println(
080                    org.opencms.report.Messages.get().container(
081                        org.opencms.report.Messages.RPT_STAT_DURATION_1,
082                        report.formatRuntime()));
083                report.println(Messages.get().container(Messages.RPT_STATICEXPORT_END_0), I_CmsReport.FORMAT_HEADLINE);
084            }
085        }
086
087        return null;
088    }
089}