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