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 GmbH & Co. KG, 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.log; 029 030import org.opencms.i18n.CmsMessages; 031import org.opencms.main.CmsIllegalArgumentException; 032 033import java.util.Locale; 034 035/** 036 * Wrapper class for the different types of log entries.<p> 037 * 038 * The IDs are organized as following: 039 * <dl> 040 * <dt>1-3</dt> 041 * <dd>user actions (login successful, login failed, resource visited)</dd> 042 * <dt>11-13</dt> 043 * <dd>publish actions (modified, new, deleted)</dd> 044 * <dt>15</dt> 045 * <dd>publish list (hide)</dd> 046 * <dt>21-24</dt> 047 * <dd>resource additional information (relations, permissions, properties)</dd> 048 * <dt>30</dt> 049 * <dd>content changes</dd> 050 * <dt>31-35</dt> 051 * <dd>resource attributes (date expired, released, last modified; type, flags)</dd> 052 * <dt>40-45</dt> 053 * <dd>structure operations (create, copy, delete, move, import)</dd> 054 * <dt>50-54</dt> 055 * <dd>resource recovery (history, restore, undelete, undo changes)</dd> 056 * </dl> 057 * 058 * @since 8.0.0 059 */ 060public enum CmsLogEntryType { 061 062 /** Resource add relation entry. */ 063 RESOURCE_ADD_RELATION(21, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_FROM_TO_2), 064 /** Resource cloned entry. */ 065 RESOURCE_CLONED(42, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_FROM_TO_2), 066 /** Resource content modified entry. */ 067 RESOURCE_CONTENT_MODIFIED(30, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 068 /** Resource copied entry. */ 069 RESOURCE_COPIED(41, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_FROM_TO_2), 070 /** Resource created entry. */ 071 RESOURCE_CREATED(40, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 072 /** Resource set date expired entry. */ 073 RESOURCE_DATE_EXPIRED(31, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 074 /** Resource set date released entry. */ 075 RESOURCE_DATE_RELEASED(32, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 076 /** Resource deleted entry. */ 077 RESOURCE_DELETED(43, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 078 /** Resource set flags entry. */ 079 RESOURCE_FLAGS(35, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 080 /** Resource hidden from publish list entry. */ 081 RESOURCE_HIDDEN(15, LogLevel.WARN, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 082 /** New resource deleted. */ 083 RESOURCE_NEW_DELETED(16, LogLevel.WARN, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 084 /** Resource restored from history entry. */ 085 RESOURCE_HISTORY(50, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 086 /** Resource imported entry. */ 087 RESOURCE_IMPORTED(45, LogLevel.DEBUG, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 088 /** Resource undo changes with mov entry. */ 089 RESOURCE_MOVE_RESTORED(53, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_FROM_TO_2), 090 /** Resource moved entry. */ 091 RESOURCE_MOVED(44, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_FROM_TO_2), 092 /** Resource set permissions entry. */ 093 RESOURCE_PERMISSIONS(23, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 094 /** Resource set properties entry. */ 095 RESOURCE_PROPERTIES(24, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 096 /** Resource published deleted entry. */ 097 RESOURCE_PUBLISHED_DELETED(13, LogLevel.FATAL, false, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 098 /** Resource published modified entry. */ 099 RESOURCE_PUBLISHED_MODIFIED(11, LogLevel.FATAL, false, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 100 /** Resource published new entry. */ 101 RESOURCE_PUBLISHED_NEW(12, LogLevel.FATAL, false, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 102 /** Undo changes entry. */ 103 RESOURCE_CHANGES_UNDONE(14, LogLevel.FATAL, false, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 104 /** Resource remove relation entry. */ 105 RESOURCE_REMOVE_RELATION(22, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_AND_RELATION_FILTER_2), 106 /** Resource restore deleted entry. */ 107 RESOURCE_RESTORE_DELETED(51, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 108 /** Resource undo changes without move entry. */ 109 RESOURCE_RESTORED(54, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 110 /** Resource set date last modified entry. */ 111 RESOURCE_TOUCHED(33, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 112 /** Resource set type entry. */ 113 RESOURCE_TYPE(34, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1), 114 /** Resource undeleted entry. */ 115 RESOURCE_UNDELETED(52, LogLevel.INFO, true, Messages.GUI_LOG_ENTRY_DETAIL_PATH_1); 116 117 /** 118 * Log level.<p> 119 */ 120 private enum LogLevel { 121 122 /** Second Highest level. */ 123 DEBUG, 124 /** Second lowest level. */ 125 ERROR, 126 /** Lowest level. */ 127 FATAL, 128 /** Normal level. */ 129 INFO, 130 /** Highest level. */ 131 TRACE, 132 /** Less than normal level. */ 133 WARN; 134 } 135 136 /** Localization key for detail formatting. */ 137 private String m_detailKey; 138 139 /** Internal representation. */ 140 private final int m_id; 141 142 /** Flag to indicate if this type generates an entry in the user's publish list. */ 143 private boolean m_toPubList; 144 145 /** 146 * Public constructor.<p> 147 * 148 * @param id the id of the log entry type 149 * @param logLevel the activation level 150 * @param toPubList flag to indicate if this type generates an entry in the user's publish list 151 * @param detailKey localization key for detail formatting 152 */ 153 private CmsLogEntryType(int id, LogLevel logLevel, boolean toPubList, String detailKey) { 154 155 m_id = id; 156 m_toPubList = toPubList; 157 m_detailKey = detailKey; 158 } 159 160 /** 161 * Parses an <code>int</code> into a log entry type.<p> 162 * 163 * @param id the internal representation number to parse 164 * 165 * @return the enumeration element 166 * 167 * @throws CmsIllegalArgumentException if the given value could not be matched against a 168 * <code>{@link CmsLogEntryType}</code> object. 169 */ 170 public static CmsLogEntryType valueOf(int id) throws CmsIllegalArgumentException { 171 172 for (CmsLogEntryType type : CmsLogEntryType.values()) { 173 if (id == type.getId()) { 174 return type; 175 } 176 } 177 throw new CmsIllegalArgumentException( 178 org.opencms.db.Messages.get().container( 179 org.opencms.db.Messages.ERR_MODE_ENUM_PARSE_2, 180 Integer.valueOf(id), 181 CmsLogEntryType.class.getName())); 182 } 183 184 /** 185 * Localization key for detail formatting.<p> 186 * 187 * @return localization key for detail formatting 188 */ 189 public String getDetailKey() { 190 191 return m_detailKey; 192 } 193 194 /** 195 * Returns the internal representation of this type.<p> 196 * 197 * @return the internal representation of this type 198 */ 199 public int getId() { 200 201 return m_id; 202 } 203 204 /** 205 * Returns a localized name for the given log entry type.<p> 206 * 207 * @param messages the message bundle to use to resolve the name 208 * 209 * @return a localized name 210 */ 211 public String getLocalizedName(CmsMessages messages) { 212 213 String nameKey = "GUI_LOG_ENTRY_TYPE_" + name() + "_0"; 214 return messages.key(nameKey); 215 } 216 217 /** 218 * Returns a localized name for the given log entry type.<p> 219 * 220 * @param locale the locale 221 * 222 * @return a localized name 223 */ 224 public String getLocalizedName(Locale locale) { 225 226 return getLocalizedName(Messages.get().getBundle(locale)); 227 } 228 229 /** 230 * Checks if this log entry type is active or not.<p> 231 * 232 * @return <code>true</code> if this log entry type is active or not 233 */ 234 public boolean isActive() { 235 236 return true; 237 } 238 239 /** 240 * Check if this type generates an entry in the user's publish list.<p> 241 * 242 * @return <code>true</code> if this type generates an entry in the user's publish list 243 */ 244 public boolean isToPubList() { 245 246 return m_toPubList; 247 } 248}