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.workplace.comparison;
029
030import org.opencms.i18n.CmsMessageContainer;
031import org.opencms.main.CmsIllegalArgumentException;
032
033import java.io.Serializable;
034import java.util.Arrays;
035import java.util.Collections;
036import java.util.Iterator;
037import java.util.List;
038
039/**
040 * Wrapper class for the different types of diff modes.<p>
041 *
042 * The possibles values are:<br>
043 * <ul>
044 * <li>{@link #ALL}</li>
045 * <li>{@link #DIFF_ONLY}</li>
046 * </ul>
047 * <p>
048 *
049 * @since 6.0.0
050 */
051public final class CmsDiffViewMode implements Serializable {
052
053    /** Constant for viewing all lines. */
054    public static final CmsDiffViewMode ALL = new CmsDiffViewMode(
055        "all",
056        Messages.get().container(Messages.GUI_DIFF_MODE_DIFFONLY_NAME_0));
057
058    /** Constant for viewing only the different lines. */
059    public static final CmsDiffViewMode DIFF_ONLY = new CmsDiffViewMode(
060        "diff_only",
061        Messages.get().container(Messages.GUI_DIFF_MODE_ALL_NAME_0));
062
063    /** uid for serialization. */
064    private static final long serialVersionUID = -9107946096096683776L;
065
066    /** Array constant for all available align types. */
067    private static final CmsDiffViewMode[] VALUE_ARRAY = {ALL, DIFF_ONLY};
068
069    /** List of mode constants. */
070    public static final List<CmsDiffViewMode> VALUES = Collections.unmodifiableList(Arrays.asList(VALUE_ARRAY));
071
072    /** Internal representation. */
073    private final String m_mode;
074
075    /** Name to show. */
076    private final CmsMessageContainer m_name;
077
078    /**
079     * Private constructor.
080     * <p>
081     *
082     * @param mode the view mode
083     * @param name the name to show
084     */
085    private CmsDiffViewMode(String mode, CmsMessageContainer name) {
086
087        m_mode = mode;
088        m_name = name;
089    }
090
091    /**
092     * Parses an string into an element of this enumeration.<p>
093     *
094     * @param value the mode to parse
095     *
096     * @return the enumeration element
097     *
098     * @throws CmsIllegalArgumentException if the given value could not be matched against an
099     *             element of this type.
100     */
101    public static CmsDiffViewMode valueOf(String value) throws CmsIllegalArgumentException {
102
103        if (value == null) {
104            return null;
105        }
106        Iterator<CmsDiffViewMode> iter = VALUES.iterator();
107        while (iter.hasNext()) {
108            CmsDiffViewMode target = iter.next();
109            if (value.equals(target.getMode())) {
110                return target;
111            }
112        }
113        throw new CmsIllegalArgumentException(
114            org.opencms.db.Messages.get().container(
115                org.opencms.db.Messages.ERR_MODE_ENUM_PARSE_2,
116                value,
117                CmsDiffViewMode.class.getName()));
118    }
119
120    /**
121     * Returns the mode string.<p>
122     *
123     * @return the mode string
124     */
125    public String getMode() {
126
127        return m_mode;
128    }
129
130    /**
131     * Returns the name to show.<p>
132     *
133     * @return the name to show
134     */
135    public CmsMessageContainer getName() {
136
137        return m_name;
138    }
139
140    /**
141     * @see java.lang.Object#toString()
142     */
143    @Override
144    public String toString() {
145
146        return m_mode;
147    }
148}