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.list;
029
030import org.opencms.main.CmsIllegalArgumentException;
031
032import java.util.Arrays;
033import java.util.Collections;
034import java.util.Iterator;
035import java.util.List;
036
037/**
038 * Wrapper class for
039 * the different types of table cell horizontal alignments.<p>
040 *
041 * The possibles values are:<br>
042 * <ul>
043 *   <li>LeftAlign</li>
044 *   <li>CenterAlign</li>
045 *   <li>RightAlign</li>
046 * </ul>
047 * <p>
048 *
049 * @since 6.0.0
050 */
051public final class CmsListColumnAlignEnum {
052
053    /** Constant for center alignment . */
054    public static final CmsListColumnAlignEnum ALIGN_CENTER = new CmsListColumnAlignEnum("center");
055
056    /** Constant for left alignment.  */
057    public static final CmsListColumnAlignEnum ALIGN_LEFT = new CmsListColumnAlignEnum("left");
058
059    /** Constant for right alignment.     */
060    public static final CmsListColumnAlignEnum ALIGN_RIGHT = new CmsListColumnAlignEnum("right");
061
062    /** Array constant for all available align types. */
063    private static final CmsListColumnAlignEnum[] VALUE_ARRAY = {ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT};
064
065    /** List of mode constants. */
066    public static final List<CmsListColumnAlignEnum> VALUES = Collections.unmodifiableList(Arrays.asList(VALUE_ARRAY));
067
068    /** Internal representation. */
069    private final String m_align;
070
071    /**
072     * Private constructor.<p>
073     *
074     * @param align html align value
075     */
076    private CmsListColumnAlignEnum(String align) {
077
078        m_align = align;
079    }
080
081    /**
082     * Parses an string into an element of this enumeration.<p>
083     *
084     * @param value the align to parse
085     *
086     * @return the enumeration element
087     *
088     * @throws CmsIllegalArgumentException if the given value could not be matched against a
089     *         <code>CmsListColumnAlignEnum</code> type.
090     */
091    public static CmsListColumnAlignEnum valueOf(String value) throws CmsIllegalArgumentException {
092
093        Iterator<CmsListColumnAlignEnum> iter = VALUES.iterator();
094        while (iter.hasNext()) {
095            CmsListColumnAlignEnum target = iter.next();
096            if (value.equals(target.getAlign())) {
097                return target;
098            }
099        }
100        throw new CmsIllegalArgumentException(
101            Messages.get().container(
102                Messages.ERR_LIST_ENUM_PARSE_2,
103                Integer.valueOf(value),
104                CmsListColumnAlignEnum.class.getName()));
105    }
106
107    /**
108     * Returns the align string.<p>
109     *
110     * @return the align string
111     */
112    public String getAlign() {
113
114        return m_align;
115    }
116
117    /**
118     * @see java.lang.Object#toString()
119     */
120    @Override
121    public String toString() {
122
123        return m_align;
124    }
125}