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.report;
029
030import java.util.Map;
031
032import com.google.common.collect.Maps;
033
034/**
035 * Enum representing report entry types.<p>
036 */
037public enum CmsReportFormatType {
038    /** Default format. */
039    fmtDefault("FORMAT_DEFAULT", I_CmsReport.FORMAT_DEFAULT),
040
041    /** Error format. */
042    fmtError("FORMAT_ERROR", I_CmsReport.FORMAT_ERROR),
043
044    /** Exception format. */
045    fmtException("EXCEPTION", -2),
046
047    /** Headline format. */
048    fmtHeadline("FORMAT_HEADLINE", I_CmsReport.FORMAT_HEADLINE),
049
050    /** Newline format. */
051    fmtNewline("NEWLINE", -1),
052
053    /** Note format. */
054    fmtNote("FORMAT_NOTE", I_CmsReport.FORMAT_NOTE),
055
056    /** 'OK' format. */
057    fmtOk("FORMAT_OK", I_CmsReport.FORMAT_OK),
058
059    /** Warning format. */
060    fmtWarning("FORMAT_WARNING", I_CmsReport.FORMAT_WARNING);
061
062    /** Enum values by id. */
063    private static Map<Integer, CmsReportFormatType> m_byId = Maps.newHashMap();
064
065    /** Enum values by format name. */
066    private static Map<String, CmsReportFormatType> m_byName = Maps.newHashMap();
067
068    /** The format id. */
069    private int m_id;
070
071    /** The format name. */
072    private String m_name;
073
074    /**
075     * Creates a new instance.<p>
076     *
077     * @param formatName the format name
078     * @param formatId the format id
079     */
080    private CmsReportFormatType(String formatName, int formatId) {
081        m_name = formatName;
082        m_id = formatId;
083    }
084
085    static {
086        for (CmsReportFormatType type : values()) {
087            m_byId.put(Integer.valueOf(type.getFormatId()), type);
088            m_byName.put(type.getFormatName(), type);
089        }
090    }
091
092    /**
093     * Gets the format enum by its id.<p>
094     *
095     * @param id the format id
096     * @return the format enum
097     */
098    public static CmsReportFormatType byId(int id) {
099
100        return m_byId.get(Integer.valueOf(id));
101    }
102
103    /**
104     * Gets the format enum by its format naem.<p>
105     *
106     * @param name the format name
107     * @return the format enum value
108     */
109    public static CmsReportFormatType byName(String name) {
110
111        return m_byName.get(name);
112    }
113
114    /**
115     * Gets the format id.<p>
116     *
117     * @return the format id
118     */
119    public int getFormatId() {
120
121        return m_id;
122    }
123
124    /**
125     * Gets the format name.<p>
126     *
127     * @return the format name
128     */
129    public String getFormatName() {
130
131        return m_name;
132    }
133
134}