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 java.io.IOException;
031
032import javax.servlet.http.HttpServletResponse;
033import javax.servlet.http.HttpServletResponseWrapper;
034
035/**
036 * Response wrapper for static export requests, required to access the status code of the response.<p>
037 *
038 * The <code>{@link org.opencms.loader.I_CmsResourceLoader#export(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, HttpServletResponse)}</code>
039 * method is called by the static export manager. Many implementations set the http status codes for the response.
040 * This wrapper enables the export manager to return the status code set on the response
041 * in <code>{@link org.opencms.staticexport.CmsStaticExportManager#export(javax.servlet.http.HttpServletRequest, HttpServletResponse, org.opencms.file.CmsObject, CmsStaticExportData)}</code>.<p>
042 *
043 * @since 6.0.0
044 */
045public class CmsStaticExportResponseWrapper extends HttpServletResponseWrapper {
046
047    /** The status code. */
048    protected int m_status;
049
050    /**
051     * Creates a new export response wrapper.<p>
052     *
053     * @param res the original response to wrap
054     */
055    public CmsStaticExportResponseWrapper(HttpServletResponse res) {
056
057        super(res);
058        m_status = -1;
059    }
060
061    /**
062     * Returns the status code of this export response, if no status code was set so far,
063     * <code>-1</code> is returned.<p>
064     *
065     * @return the status code of this export response
066     */
067    @Override
068    public int getStatus() {
069
070        return m_status;
071    }
072
073    /**
074     * @see javax.servlet.http.HttpServletResponse#sendError(int)
075     */
076    @Override
077    public void sendError(int status) throws IOException {
078
079        m_status = status;
080        super.sendError(status);
081    }
082
083    /**
084     * @see javax.servlet.http.HttpServletResponse#sendError(int, java.lang.String)
085     */
086    @Override
087    public void sendError(int status, String message) throws IOException {
088
089        m_status = status;
090        super.sendError(status, message);
091    }
092
093    /**
094     * @see javax.servlet.http.HttpServletResponseWrapper#setStatus(int)
095     */
096    @Override
097    public void setStatus(int status) {
098
099        m_status = status;
100        super.setStatus(status);
101    }
102
103    /**
104     * @see javax.servlet.http.HttpServletResponseWrapper#setStatus(int, java.lang.String)
105     */
106    @Override
107    public void setStatus(int status, String message) {
108
109        m_status = status;
110        super.setStatus(status, message);
111    }
112}