001/* 002 * Copyright 2018-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2018-2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.tasks; 022 023 024 025import com.unboundid.util.StaticUtils; 026import com.unboundid.util.ThreadSafety; 027import com.unboundid.util.ThreadSafetyLevel; 028 029 030 031/** 032 * This enum defines the set of allowed timestamp formats for use in conjunction 033 * with the file retention task. 034 * <BR> 035 * <BLOCKQUOTE> 036 * <B>NOTE:</B> This class, and other classes within the 037 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 038 * supported for use against Ping Identity, UnboundID, and 039 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 040 * for proprietary functionality or for external specifications that are not 041 * considered stable or mature enough to be guaranteed to work in an 042 * interoperable way with other types of LDAP servers. 043 * </BLOCKQUOTE> 044 */ 045@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 046public enum FileRetentionTaskTimestampFormat 047{ 048 /** 049 * The timestamp format that uses the generalized time format in the UTC time 050 * zone (with the 'Z' time zone indicator) with millisecond-level precision 051 * (e.g., "20180102123456.789Z"). 052 */ 053 GENERALIZED_TIME_UTC_WITH_MILLISECONDS(true, "yyyyMMddHHmmss.SSS'Z'", 054 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP + 055 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR + 056 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH + 057 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY + 058 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR + 059 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE + 060 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_SECOND + 061 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MILLISECOND + 062 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_LITERAL_Z + 063 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP), 064 065 066 067 /** 068 * The timestamp format that uses the generalized time format in the UTC time 069 * zone (with the 'Z' time zone indicator) with second-level precision (e.g., 070 * "20180102123456Z"). 071 */ 072 GENERALIZED_TIME_UTC_WITH_SECONDS(true, "yyyyMMddHHmmss'Z'", 073 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP + 074 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR + 075 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH + 076 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY + 077 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR + 078 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE + 079 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_SECOND + 080 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_LITERAL_Z + 081 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP), 082 083 084 085 /** 086 * The timestamp format that uses the generalized time format in the UTC time 087 * zone (with the 'Z' time zone indicator) with minute-level precision (e.g., 088 * "201801021234Z"). 089 */ 090 GENERALIZED_TIME_UTC_WITH_MINUTES(true, "yyyyMMddHHmm'Z'", 091 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP + 092 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR + 093 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH + 094 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY + 095 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR + 096 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE + 097 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_LITERAL_Z + 098 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP), 099 100 101 102 /** 103 * The timestamp format that uses a numeric form at in the local time zone 104 * (with no time zone indicator) with millisecond-level precision (e.g., 105 * "20180102123456.789"). 106 */ 107 LOCAL_TIME_WITH_MILLISECONDS(false, "yyyyMMddHHmmss.SSS", 108 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP + 109 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR + 110 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH + 111 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY + 112 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR + 113 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE + 114 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_SECOND + 115 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MILLISECOND + 116 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP), 117 118 119 120 /** 121 * The timestamp format that uses a numeric form at in the local time zone 122 * (with no time zone indicator) with second-level precision (e.g., 123 * "20180102123456"). 124 */ 125 LOCAL_TIME_WITH_SECONDS(false, "yyyyMMddHHmmss", 126 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP + 127 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR + 128 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH + 129 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY + 130 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR + 131 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE + 132 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_SECOND + 133 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP), 134 135 136 137 /** 138 * The timestamp format that uses a numeric form at in the local time zone 139 * (with no time zone indicator) with minute-level precision (e.g., 140 * "201801021234"). 141 */ 142 LOCAL_TIME_WITH_MINUTES(false, "yyyyMMddHHmm", 143 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP + 144 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR + 145 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH + 146 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY + 147 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR + 148 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE + 149 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP), 150 151 152 153 /** 154 * The timestamp format that uses a numeric form at in the local time zone 155 * (with no time zone indicator) with day-level precision (e.g., "20180102"). 156 */ 157 LOCAL_DATE(false, "yyyyMMdd", 158 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP + 159 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR + 160 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH + 161 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY + 162 FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP); 163 164 165 166 /** 167 * A regular expression fragment that begins a capture group. 168 */ 169 private static final String REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP = "("; 170 171 172 173 /** 174 * A regular expression fragment that matches a year between 1900 and 2199. 175 */ 176 private static final String REGEX_FRAGMENT_YEAR = "(19|20|21)[0-9][0-9]"; 177 178 179 180 /** 181 * A regular expression fragment that matches a month between 01 and 12. 182 */ 183 private static final String REGEX_FRAGMENT_MONTH = "(0[1-9]|1[0-2])"; 184 185 186 187 /** 188 * A regular expression fragment that matches a day between 01 and 31. 189 */ 190 private static final String REGEX_FRAGMENT_DAY = "(0[1-9]|[1-2][0-9]|3[0-1])"; 191 192 193 194 /** 195 * A regular expression fragment that matches an hour between 00 and 23. 196 */ 197 private static final String REGEX_FRAGMENT_HOUR = "([0-1][0-9]|2[0-3])"; 198 199 200 201 /** 202 * A regular expression fragment that matches a minute between 00 and 59. 203 */ 204 private static final String REGEX_FRAGMENT_MINUTE = "[0-5][0-9]"; 205 206 207 208 /** 209 * A regular expression fragment that matches a second between 00 and 59. 210 */ 211 private static final String REGEX_FRAGMENT_SECOND = "[0-5][0-9]"; 212 213 214 215 /** 216 * A regular expression fragment that matches a millisecond between 000 and 217 * 999, preceded by a literal period character. 218 */ 219 private static final String REGEX_FRAGMENT_MILLISECOND = "\\.[0-9][0-9][0-9]"; 220 221 222 223 /** 224 * A regular expression fragment that matches a literal 'Z' character (to 225 * serve as a time zone indicator). 226 */ 227 private static final String REGEX_FRAGMENT_LITERAL_Z = "Z"; 228 229 230 231 /** 232 * A regular expression fragment that ends a capture group. 233 */ 234 private static final String REGEX_FRAGMENT_END_CAPTURE_GROUP = ")"; 235 236 237 238 // Indicates whether this timestamp format should use the UTC time zone rather 239 // than the JVM's default time zone. 240 private final boolean isInUTCTimeZone; 241 242 // A format string that can be used to create a SimpleDateFormat object 243 // capable of parsing timestamps in this format. 244 private final String simpleDateFormatString; 245 246 // A regular expression string that can be used to match timestamps in this 247 // format. 248 private final String regexString; 249 250 251 252 /** 253 * Creates a new timestamp format value with the provided information. 254 * 255 * @param isInUTCTimeZone Indicates whether the timestamp format 256 * should use the UTC time zone rather than 257 * the JVM's default time zone. 258 * @param simpleDateFormatString A format string that can be used to create 259 * a {@code SimpleDateFormat] object capable 260 * of parsing timestamps in this format. It 261 * must not be {@code null}. 262 * @param regexString A regular expression string that can be 263 * used to match timestamps in this format. 264 * It must not be {@code null}. 265 */ 266 FileRetentionTaskTimestampFormat(final boolean isInUTCTimeZone, 267 final String simpleDateFormatString, 268 final String regexString) 269 { 270 this.isInUTCTimeZone = isInUTCTimeZone; 271 this.simpleDateFormatString = simpleDateFormatString; 272 this.regexString = regexString; 273 } 274 275 276 277 /** 278 * Indicates whether the timestamp format should use the UTC time zone rather 279 * than the JVM's default time zone. 280 * 281 * @return {@code true} if the timestamp format should use the UTC time zone, 282 * or {@code false} if it should use the JVM's default time zone 283 * (which itself may or may not be the UTC time zone). 284 */ 285 public boolean isInUTCTimeZone() 286 { 287 return isInUTCTimeZone; 288 } 289 290 291 292 /** 293 * Retrieves a format string that can be used to create a 294 * {@code SimpleDateFormat} object capable of parsing timestamps in this 295 * format. 296 * 297 * @return A format string that can be used to create a 298 * {@code SimpleDateFormat} object capable of parsing timestamps in 299 * this format. 300 */ 301 public String getSimpleDateFormatString() 302 { 303 return simpleDateFormatString; 304 } 305 306 307 308 /** 309 * Retrieves a regular expression string that can be used to match timestamps 310 * in this format. The returned string will be surrounded by parentheses so 311 * that it can act as a capture group. 312 * 313 * @return A regular expression string that can be used to match timestamps 314 * in this format. 315 */ 316 public String getRegexString() 317 { 318 return regexString; 319 } 320 321 322 323 /** 324 * Retrieves the timestamp format value with the specified name. 325 * 326 * @param name The name of the timestamp format value to retrieve. 327 * 328 * @return The timestamp format value with the specified name, or 329 * {@code null} if there is no value with that name. 330 */ 331 public static FileRetentionTaskTimestampFormat forName(final String name) 332 { 333 final String upperName = StaticUtils.toUpperCase(name).replace('-', '_'); 334 for (final FileRetentionTaskTimestampFormat f : values()) 335 { 336 if (f.name().equals(upperName)) 337 { 338 return f; 339 } 340 } 341 342 return null; 343 } 344}