KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > comparison > CmsDiffViewMode


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/comparison/CmsDiffViewMode.java,v $
3  * Date : $Date: 2006/03/27 14:52:44 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.comparison;
33
34 import org.opencms.i18n.CmsMessageContainer;
35 import org.opencms.main.CmsIllegalArgumentException;
36
37 import java.io.Serializable JavaDoc;
38 import java.util.Arrays JavaDoc;
39 import java.util.Collections JavaDoc;
40 import java.util.Iterator JavaDoc;
41 import java.util.List JavaDoc;
42
43 /**
44  * Wrapper class for the different types of diff modes.
45  * <p>
46  *
47  * The possibles values are:<br>
48  * <ul>
49  * <li>{@link #ALL}</li>
50  * <li>{@link #DIFF_ONLY}</li>
51  * </ul>
52  * <p>
53  *
54  * @author Michael Moossen
55  *
56  * @version $Revision: 1.2 $
57  *
58  * @since 6.0.0
59  */

60 public final class CmsDiffViewMode implements Serializable JavaDoc {
61
62     /** Constant for viewing all lines. */
63     public static final CmsDiffViewMode ALL = new CmsDiffViewMode("all", Messages.get().container(
64         Messages.GUI_DIFF_MODE_DIFFONLY_NAME_0));
65
66     /** Constant for viewing only the different lines. */
67     public static final CmsDiffViewMode DIFF_ONLY = new CmsDiffViewMode("diff_only", Messages.get().container(
68         Messages.GUI_DIFF_MODE_ALL_NAME_0));
69
70     /** Array constant for all available align types. */
71     private static final CmsDiffViewMode[] VALUE_ARRAY = {ALL, DIFF_ONLY};
72     
73     /** List of mode constants. */
74     public static final List JavaDoc VALUES = Collections.unmodifiableList(Arrays.asList(VALUE_ARRAY));
75
76     /** uid for serialization. */
77     private static final long serialVersionUID = -9107946096096683776L;
78
79     /** Internal representation. */
80     private final String JavaDoc m_mode;
81
82     /** Name to show. */
83     private final CmsMessageContainer m_name;
84
85     /**
86      * Private constructor.
87      * <p>
88      *
89      * @param mode the view mode
90      * @param name the name to show
91      */

92     private CmsDiffViewMode(String JavaDoc mode, CmsMessageContainer name) {
93
94         m_mode = mode;
95         m_name = name;
96     }
97
98     /**
99      * Parses an string into an element of this enumeration.
100      * <p>
101      *
102      * @param value the mode to parse
103      *
104      * @return the enumeration element
105      *
106      * @throws CmsIllegalArgumentException if the given value could not be matched against an
107      * element of this type.
108      */

109     public static CmsDiffViewMode valueOf(String JavaDoc value) throws CmsIllegalArgumentException {
110
111         if (value == null) {
112             return null;
113         }
114         Iterator JavaDoc iter = VALUES.iterator();
115         while (iter.hasNext()) {
116             CmsDiffViewMode target = (CmsDiffViewMode)iter.next();
117             if (value.equals(target.getMode())) {
118                 return target;
119             }
120         }
121         throw new CmsIllegalArgumentException(org.opencms.db.Messages.get().container(
122             org.opencms.db.Messages.ERR_MODE_ENUM_PARSE_2,
123             value,
124             CmsDiffViewMode.class.getName()));
125     }
126
127     /**
128      * Returns the mode string.
129      * <p>
130      *
131      * @return the mode string
132      */

133     public String JavaDoc getMode() {
134
135         return m_mode;
136     }
137
138     /**
139      * Returns the name to show.
140      * <p>
141      *
142      * @return the name to show
143      */

144     public CmsMessageContainer getName() {
145
146         return m_name;
147     }
148
149     /**
150      * @see java.lang.Object#toString()
151      */

152     public String JavaDoc toString() {
153
154         return m_mode;
155     }
156 }
Popular Tags