001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (https://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, please see the
018 * company website: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.gwt.shared.alias;
029
030import com.google.gwt.user.client.rpc.IsSerializable;
031
032/**
033 * The values of this enum describe what should happen when a request to an aliased resource
034 * comes in.<p>
035 */
036public enum CmsAliasMode implements IsSerializable {
037
038    /** The request will be forwarded internally to the given resource. */
039    page(0),
040    /** Pass the new path along to the next resource handler. */
041    passthrough(3),
042    /** A 'moved permanently' status with a link to the aliased resource will be sent to the browser. */
043    permanentRedirect(2),
044    /** A 'moved temporarily' status with a link to the aliased resource will be sent to the browser. */
045    redirect(1);
046
047    /** The id used for storing alias modes in the database. */
048    private final int m_id;
049
050    /**
051     * Creates a new enum constant.<p>
052     *
053     * @param id the id used in the database
054     */
055    CmsAliasMode(int id) {
056
057        m_id = id;
058    }
059
060    /**
061     * Gets the enum constant for a given integer id.<p>
062     *
063     * @param id the integer id
064     * @return the enum constant matching that id
065     */
066    public static CmsAliasMode fromInt(int id) {
067
068        switch (id) {
069            case 1:
070                return redirect;
071            case 2:
072                return permanentRedirect;
073            case 3:
074                return passthrough;
075            case 0:
076            default:
077                return page;
078        }
079    }
080
081    /**
082     * Checks whether this is a mode that requires a redirect.<p>
083     *
084     * @return true if this mode requires a redirect
085     */
086    public boolean isRedirect() {
087
088        return (this == redirect) || (this == permanentRedirect);
089    }
090
091    /**
092     * Converts an enum constant to the id used for storing alias modes in the database.<p>
093     *
094     * @return the enum constant id
095     */
096    public int toInt() {
097
098        return m_id;
099    }
100
101}