001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (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, 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.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), /** Pass the new path along to the next resource handler. */ 040 passthrough(3), /** A 'moved permanently' status with a link to the aliased resource will be sent to the browser. */ 041 permanentRedirect( 042 2), /** A 'moved temporarily' status with a link to the aliased resource will be sent to the browser. */ 043 redirect(1); 044 045 /** The id used for storing alias modes in the database. */ 046 private final int m_id; 047 048 /** 049 * Creates a new enum constant.<p> 050 * 051 * @param id the id used in the database 052 */ 053 CmsAliasMode(int id) { 054 055 m_id = id; 056 } 057 058 /** 059 * Gets the enum constant for a given integer id.<p> 060 * 061 * @param id the integer id 062 * @return the enum constant matching that id 063 */ 064 public static CmsAliasMode fromInt(int id) { 065 066 switch (id) { 067 case 1: 068 return redirect; 069 case 2: 070 return permanentRedirect; 071 case 3: 072 return passthrough; 073 case 0: 074 default: 075 return page; 076 } 077 } 078 079 /** 080 * Checks whether this is a mode that requires a redirect.<p> 081 * 082 * @return true if this mode requires a redirect 083 */ 084 public boolean isRedirect() { 085 086 return (this == redirect) || (this == permanentRedirect); 087 } 088 089 /** 090 * Converts an enum constant to the id used for storing alias modes in the database.<p> 091 * 092 * @return the enum constant id 093 */ 094 public int toInt() { 095 096 return m_id; 097 } 098 099}