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.main;
029
030import org.opencms.i18n.CmsMessageContainer;
031
032/**
033 * This exeption is thrown by a class which implements org.opencms.main.I_CmsResourceInit.
034 * When this exeption is thrown,
035 * all other implementations of I_CmsResourceInit will not be executed.<p>
036 *
037 * @since 6.0.0
038 */
039public class CmsResourceInitException extends CmsException {
040
041    /** Serial version UID required for safe serialization. */
042    private static final long serialVersionUID = 4896514314866157082L;
043
044    /** The 'clear errors' flag. */
045    private boolean m_clearErrors;
046
047    /**
048     * Creates a resource init exception for a given resource init handler class.<p>
049     *
050     * @param cls the resource init handler class
051     */
052    public CmsResourceInitException(Class<? extends I_CmsResourceInit> cls) {
053
054        this(Messages.get().container(Messages.ERR_RESOURCE_INIT_ABORTED_1, cls.getName()));
055    }
056
057    /**
058     * Creates a new localized Exception.<p>
059     *
060     * @param container the localized message container to use
061     */
062    public CmsResourceInitException(CmsMessageContainer container) {
063
064        super(container);
065    }
066
067    /**
068     * Creates a new localized Exception that also containes a root cause.<p>
069     *
070     * @param container the localized message container to use
071     * @param cause the Exception root cause
072     */
073    public CmsResourceInitException(CmsMessageContainer container, Throwable cause) {
074
075        super(container, cause);
076    }
077
078    /**
079     * @see org.opencms.main.CmsException#createException(org.opencms.i18n.CmsMessageContainer, java.lang.Throwable)
080     */
081    @Override
082    public CmsException createException(CmsMessageContainer container, Throwable cause) {
083
084        return new CmsResourceInitException(container, cause);
085    }
086
087    /**
088     * If this method returns true, the {@link OpenCmsCore#initResource(org.opencms.file.CmsObject, String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)}
089     * method should just return null instead of throwing an exception.<p>
090     *
091     * @return the 'clear errors' flag
092     */
093    public boolean isClearErrors() {
094
095        return m_clearErrors;
096    }
097
098    /**
099     * Sets the 'clear errors' flag, which causes the resource init method catching this exception to return null of throwing an exception.
100     * This can be useful if you want to redirect inside a resource init handler.<p>
101     *
102     * @param clearErrors the new value of the 'clear errors' flag
103     */
104    public void setClearErrors(boolean clearErrors) {
105
106        m_clearErrors = clearErrors;
107    }
108
109}