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, 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.db; 029 030import org.opencms.util.A_CmsModeIntEnumeration; 031 032/** 033 * The read modes to get subscribed resources of a user or group.<p> 034 * 035 * @since 8.0 036 */ 037public final class CmsSubscriptionReadMode extends A_CmsModeIntEnumeration { 038 039 /** String representation of the read mode: all. */ 040 public static final String MODE_NAME_ALL = "all"; 041 042 /** String representation of the read mode: unvisited. */ 043 public static final String MODE_NAME_UNVISITED = "unvisited"; 044 045 /** String representation of the read mode: visited. */ 046 public static final String MODE_NAME_VISITED = "visited"; 047 048 /** Subscription read mode: all. */ 049 public static final CmsSubscriptionReadMode ALL = new CmsSubscriptionReadMode(1); 050 051 /** Subscription read mode: unvisited. */ 052 public static final CmsSubscriptionReadMode UNVISITED = new CmsSubscriptionReadMode(2); 053 054 /** Subscription read mode: visited. */ 055 public static final CmsSubscriptionReadMode VISITED = new CmsSubscriptionReadMode(3); 056 057 /** Serializable version id. */ 058 private static final long serialVersionUID = 7547476104782346902L; 059 060 /** 061 * Private constructor.<p> 062 * 063 * @param mode the subscription read mode integer representation 064 */ 065 private CmsSubscriptionReadMode(int mode) { 066 067 super(mode); 068 } 069 070 /** 071 * Returns the subscription read mode for the given mode name.<p> 072 * 073 * @param modeName the subscription read mode name to get the read mode for 074 * 075 * @return the subscription read mode for the given mode name 076 */ 077 public static CmsSubscriptionReadMode modeForName(String modeName) { 078 079 if (MODE_NAME_ALL.equals(modeName)) { 080 return ALL; 081 } else if (MODE_NAME_VISITED.equals(modeName)) { 082 return VISITED; 083 } 084 return UNVISITED; 085 } 086 087 /** 088 * Returns the subscription read mode for the given mode value.<p> 089 * 090 * This is used only for serialization and should not be accessed for other purposes.<p> 091 * 092 * @param type the subscription read mode value to get the read mode for 093 * 094 * @return the subscription read mode for the given mode value 095 */ 096 public static CmsSubscriptionReadMode valueOf(int type) { 097 098 switch (type) { 099 case 1: 100 return ALL; 101 case 2: 102 return UNVISITED; 103 case 3: 104 return VISITED; 105 default: 106 return UNVISITED; 107 } 108 } 109 110 /** 111 * Returns if the mode is set to {@link #ALL}.<p> 112 * 113 * @return true if the mode is set to {@link #ALL}, otherwise false 114 */ 115 public boolean isAll() { 116 117 return getMode() == ALL.getMode(); 118 } 119 120 /** 121 * Returns if the mode is set to {@link #UNVISITED}.<p> 122 * 123 * @return true if the mode is set to {@link #UNVISITED}, otherwise false 124 */ 125 public boolean isUnVisited() { 126 127 return getMode() == UNVISITED.getMode(); 128 } 129 130 /** 131 * Returns if the mode is set to {@link #VISITED}.<p> 132 * 133 * @return true if the mode is set to {@link #VISITED}, otherwise false 134 */ 135 public boolean isVisited() { 136 137 return getMode() == VISITED.getMode(); 138 } 139 140 /** 141 * 142 * @see org.opencms.util.A_CmsModeIntEnumeration#toString() 143 */ 144 @Override 145 public String toString() { 146 147 switch (getMode()) { 148 case 1: 149 return MODE_NAME_ALL; 150 case 2: 151 return MODE_NAME_UNVISITED; 152 case 3: 153 return MODE_NAME_VISITED; 154 default: 155 return MODE_NAME_UNVISITED; 156 } 157 } 158 159 /** 160 * @see java.lang.Object#clone() 161 */ 162 @Override 163 protected Object clone() { 164 165 return new CmsSubscriptionReadMode(getMode()); 166 } 167 168}