KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > editors > directedit > CmsDirectEditMode


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/editors/directedit/CmsDirectEditMode.java,v $
3  * Date : $Date: 2006/10/26 12:25:34 $
4  * Version: $Revision: 1.2 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (C) 2002 - 2005 Alkacon Software (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, 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.editors.directedit;
33
34 import org.opencms.util.CmsStringUtil;
35
36 /**
37  * Constants to indicate which mode to use for placement of the HTML that generates
38  * the direct edit buttons.<p>
39  *
40  * There are 3 basic options for the direct edit mode:
41  * <ul>
42  * <li>{@link #FALSE}: Direct edit is disabled.
43  * <li>{@link #AUTO}: Direct edit button HTML is inserted automatically.
44  * <li>{@link #MANUAL}: Direct edit button HTML is inserted manually by using &ltcms: editable mode="manual" /&gt tags.
45  * </ul>
46  *
47  * There is one global option set for the page / template.
48  * The default is {@link #AUTO}.<p>
49  *
50  * There is an additional constant {@link #TRUE} that means "use the default mode of the page / template".<p>
51  *
52  * It is possible to switch modes for an individual content loop.
53  * This is intended to use with XmlContents that require special placement of the direct edit HTML
54  * because the default placement does not give good results.<p>
55  *
56  * @author Alexander Kandzior
57  *
58  * @version $Revision: 1.2 $
59  *
60  * @since 6.2.3
61  */

62 public final class CmsDirectEditMode {
63
64     /** Indicates automatic placement of direct edit HTML. */
65     public static final CmsDirectEditMode AUTO = new CmsDirectEditMode(2);
66
67     /** Indicates direct edit is disabled. */
68     public static final CmsDirectEditMode FALSE = new CmsDirectEditMode(0);
69
70     /** Indicates manual placement of direct edit HTML. */
71     public static final CmsDirectEditMode MANUAL = new CmsDirectEditMode(3);
72
73     /** Indicates direct edit HTML is to be generated according to the default setting of the current page. */
74     public static final CmsDirectEditMode TRUE = new CmsDirectEditMode(1);
75
76     /** Array of mode constants. */
77     private static final CmsDirectEditMode[] MODES = {FALSE, TRUE, AUTO, MANUAL};
78
79     /** Constant to indicate editable mode is "auto", which is equivalent to "true". */
80     private static final String JavaDoc VALUE_AUTO = "auto";
81
82     /** Constant to indicate editable mode is "false", which means direct edit is turned off. */
83     private static final String JavaDoc VALUE_FALSE = CmsStringUtil.FALSE;
84
85     /** Constant to indicate editable mode is "manual". */
86     private static final String JavaDoc VALUE_MANUAL = "manual";
87
88     /** Constant to indicate editable mode is "true", which means use the default from the page. */
89     private static final String JavaDoc VALUE_TRUE = CmsStringUtil.TRUE;
90
91     /** The direct edit mode to use. */
92     private int m_mode;
93
94     /**
95      * Hides the public constructor.<p>
96      *
97      * @param mode the mode to initialize
98      */

99     private CmsDirectEditMode(int mode) {
100
101         m_mode = mode;
102     }
103
104     /**
105      * Returns {@link #TRUE} in case the given value is <code>true</code>, {@link #FALSE} otherwise.<p>
106      *
107      * @param value the direct edit mode to get the constant for
108      *
109      * @return {@link #TRUE} in case the given value is <code>true</code>, {@link #FALSE} otherwise
110      */

111     public static CmsDirectEditMode valueOf(boolean value) {
112
113         return value ? TRUE : FALSE;
114     }
115
116     /**
117      * Returns the mode constant for the selected direct edit int mode.<p>
118      *
119      * The possible value are:
120      * <ul>
121      * <li>0: Mode is {@link #FALSE}.
122      * <li>1: Mode is {@link #TRUE}.
123      * <li>2: Mode is {@link #AUTO}.
124      * <li>3: Mode is {@link #MANUAL}.
125      * </ul>
126      *
127      * @param mode the direct edit int mode to get the constant for
128      *
129      * @return the mode constant for the selected direct edit int mode
130      */

131     public static CmsDirectEditMode valueOf(int mode) {
132
133         if ((mode > 0) && (mode < MODES.length)) {
134             return MODES[mode];
135         }
136         return FALSE;
137     }
138
139     /**
140      * Returns the mode constant for the selected direct edit String mode description.<p>
141      *
142      * For a mode instance <code>A</code>, {@link #toString()} returns the String mode description.<p>
143      *
144      * @param value the direct edit String mode description to get the constant for
145      *
146      * @return the mode constant for the selected direct edit String mode description
147      */

148     public static CmsDirectEditMode valueOf(String JavaDoc value) {
149
150         CmsDirectEditMode result = FALSE;
151         if (CmsStringUtil.isNotEmpty(value)) {
152             value = value.trim().toLowerCase();
153             if (Boolean.valueOf(value).booleanValue()) {
154                 result = TRUE;
155             } else if (VALUE_AUTO.equals(value)) {
156                 result = AUTO;
157             } else if (VALUE_MANUAL.equals(value)) {
158                 result = MANUAL;
159             }
160         }
161         return result;
162     }
163
164     /**
165      * Returns this modes int value.<p>
166      *
167      * @return this modes int value
168      *
169      * @see #valueOf(int)
170      */

171     public int getMode() {
172
173         return m_mode;
174     }
175
176     /**
177      * Returns <code>true</code> in case this mode indicates direct edit is enabled.<p>
178      *
179      * Direct edit is enabled if this mode is not {@link #FALSE}, which is
180      * identical to <code>{@link #getMode()} > 0</code>.
181      *
182      * @return <code>true</code> in case this mode indicates direct edit is enabled
183      */

184     public boolean isEnabled() {
185
186         return m_mode > 0;
187     }
188
189     /**
190      * @see java.lang.Object#toString()
191      * @see #valueOf(String)
192      */

193     public String JavaDoc toString() {
194
195         switch (m_mode) {
196             case 1:
197                 return VALUE_TRUE;
198             case 2:
199                 return VALUE_AUTO;
200             case 3:
201                 return VALUE_MANUAL;
202             default:
203                 return VALUE_FALSE;
204         }
205     }
206 }
Popular Tags