1 31 32 package org.opencms.db; 33 34 import org.opencms.main.CmsIllegalArgumentException; 35 import org.opencms.main.CmsRuntimeException; 36 import org.opencms.util.CmsStringUtil; 37 38 import java.util.GregorianCalendar ; 39 40 49 public class CmsLoginMessage { 50 51 52 public static final long DEFAULT_TIME_END = new GregorianCalendar (2039, 11, 31).getTimeInMillis(); 53 54 55 public static final long DEFAULT_TIME_START = new GregorianCalendar (2000, 0, 1).getTimeInMillis(); 56 57 58 private boolean m_enabled; 59 60 61 private boolean m_frozen; 62 63 64 private boolean m_loginForbidden; 65 66 67 private String m_message; 68 69 70 private long m_timeEnd; 71 72 73 private long m_timeStart; 74 75 78 public CmsLoginMessage() { 79 80 m_timeStart = DEFAULT_TIME_START; 81 m_timeEnd = DEFAULT_TIME_END; 82 } 83 84 92 public CmsLoginMessage(long timeStart, long timeEnd, String message, boolean loginForbidden) { 93 94 setTimeStart(timeStart); 95 setTimeEnd(timeEnd); 96 m_enabled = true; 97 setMessage(message); 98 m_loginForbidden = loginForbidden; 99 } 100 101 107 public CmsLoginMessage(String message, boolean loginForbidden) { 108 109 this(DEFAULT_TIME_START, DEFAULT_TIME_END, message, loginForbidden); 110 } 111 112 115 public Object clone() { 116 117 CmsLoginMessage result = new CmsLoginMessage(); 118 result.m_timeStart = m_timeStart; 119 result.m_timeEnd = m_timeEnd; 120 result.m_loginForbidden = m_loginForbidden; 121 result.m_message = m_message; 122 result.m_enabled = m_enabled; 123 124 return result; 125 } 126 127 132 public String getMessage() { 133 134 return m_message; 135 } 136 137 142 public long getTimeEnd() { 143 144 return m_timeEnd; 145 } 146 147 152 public long getTimeStart() { 153 154 return m_timeStart; 155 } 156 157 165 public boolean isActive() { 166 167 if (!m_enabled) { 168 return false; 169 } 170 long currentTime = System.currentTimeMillis(); 171 return ((currentTime > m_timeStart) && (currentTime < m_timeEnd)); 172 } 173 174 179 public boolean isEnabled() { 180 181 return m_enabled; 182 } 183 184 194 public boolean isLoginCurrentlyForbidden() { 195 196 return m_loginForbidden && isActive(); 197 } 198 199 204 public boolean isLoginForbidden() { 205 206 return m_loginForbidden; 207 } 208 209 214 public void setEnabled(boolean enabled) { 215 216 checkFrozen(); 217 m_enabled = enabled; 218 } 219 220 225 public void setLoginForbidden(boolean loginForbidden) { 226 227 checkFrozen(); 228 m_loginForbidden = loginForbidden; 229 } 230 231 236 public void setMessage(String message) { 237 238 checkFrozen(); 239 if (isEnabled() && CmsStringUtil.isEmptyOrWhitespaceOnly(message)) { 240 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_LOGIN_MESSAGE_BAD_MESSAGE_0)); 241 } 242 m_message = message; 243 } 244 245 250 public void setTimeEnd(long timeEnd) { 251 252 checkFrozen(); 253 if (timeEnd < 0) { 254 throw new CmsIllegalArgumentException(Messages.get().container( 255 Messages.ERR_LOGIN_MESSAGE_BAD_TIME_1, 256 new Long (timeEnd))); 257 } 258 if (timeEnd == 0) { 259 timeEnd = DEFAULT_TIME_END; 260 } 261 if ((m_timeStart > 0) && (timeEnd <= m_timeStart)) { 262 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_LOGIN_MESSAGE_BAD_END_TIME_0)); 263 } 264 m_timeEnd = timeEnd; 265 } 266 267 272 public void setTimeStart(long timeStart) { 273 274 checkFrozen(); 275 if (timeStart < 0) { 276 throw new CmsIllegalArgumentException(Messages.get().container( 277 Messages.ERR_LOGIN_MESSAGE_BAD_TIME_1, 278 new Long (timeStart))); 279 } 280 if (timeStart == 0) { 281 timeStart = DEFAULT_TIME_START; 282 } 283 m_timeStart = timeStart; 284 } 285 286 291 protected void checkFrozen() throws CmsRuntimeException { 292 293 if (m_frozen) { 294 throw new CmsRuntimeException(Messages.get().container(Messages.ERR_LOGIN_MESSAGE_FROZEN_0)); 295 } 296 } 297 298 301 protected void setFrozen() { 302 303 m_frozen = true; 304 } 305 } | Popular Tags |