001: /*
002: * $Header$
003: * $Revision: 9637 $
004: * $Date: 2006-09-27 20:08:32 +0000 (Wed, 27 Sep 2006) $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
011: * reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions
015: * are met:
016: *
017: * 1. Redistributions of source code must retain the above copyright
018: * notice, this list of conditions and the following disclaimer.
019: *
020: * 2. Redistributions in binary form must reproduce the above copyright
021: * notice, this list of conditions and the following disclaimer in
022: * the documentation and/or other materials provided with the
023: * distribution.
024: *
025: * 3. The end-user documentation included with the redistribution, if
026: * any, must include the following acknowlegement:
027: * "This product includes software developed by the
028: * Apache Software Foundation (http://www.apache.org/)."
029: * Alternately, this acknowlegement may appear in the software itself,
030: * if and wherever such third-party acknowlegements normally appear.
031: *
032: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
033: * Foundation" must not be used to endorse or promote products derived
034: * from this software without prior written permission. For written
035: * permission, please contact apache@apache.org.
036: *
037: * 5. Products derived from this software may not be called "Apache"
038: * nor may "Apache" appear in their names without prior written
039: * permission of the Apache Group.
040: *
041: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
042: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
043: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
044: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
045: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
046: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
047: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
048: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
049: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
050: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
051: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
052: * SUCH DAMAGE.
053: * ====================================================================
054: *
055: * This software consists of voluntary contributions made by many
056: * individuals on behalf of the Apache Software Foundation. For more
057: * information on the Apache Software Foundation, please see
058: * <http://www.apache.org/>.
059: *
060: */
061:
062: package org.objectweb.jonas.webapp.jonasadmin;
063:
064: import java.util.ArrayList;
065: import java.util.Collection;
066: import java.util.Iterator;
067: import java.util.List;
068: import java.util.StringTokenizer;
069:
070: import org.objectweb.jonas.webapp.taglib.LabelValueBean;
071:
072: /**
073: * General purpose utility methods to create lists of objects that are
074: * commonly required in building the user interface. In all cases, if there
075: * are no matching elements, a zero-length list (rather than <code>null</code>)
076: * is returned.
077: *
078: * @author Craig R. McClanahan
079: * @version $Revision: 9637 $ $Date: 2006-09-27 20:08:32 +0000 (Wed, 27 Sep 2006) $
080: */
081:
082: public class Jlists {
083:
084: // --------------------------------------------------------- Constants
085:
086: public final static String SEPARATOR = ",";
087:
088: // ----------------------------------------------------------- Constructors
089:
090: /**
091: * Protected constructor to prevent instantiation.
092: */
093: protected Jlists() {
094: }
095:
096: // ------------------------------------------------------- Static Variables
097:
098: /**
099: * Precomputed list of debug level labels and values.
100: */
101: private static List debugLevels = new ArrayList();
102:
103: static {
104: debugLevels.add(new LabelValueBean("0", "0"));
105: debugLevels.add(new LabelValueBean("1", "1"));
106: debugLevels.add(new LabelValueBean("2", "2"));
107: debugLevels.add(new LabelValueBean("3", "3"));
108: debugLevels.add(new LabelValueBean("4", "4"));
109: debugLevels.add(new LabelValueBean("5", "5"));
110: debugLevels.add(new LabelValueBean("6", "6"));
111: debugLevels.add(new LabelValueBean("7", "7"));
112: debugLevels.add(new LabelValueBean("8", "8"));
113: debugLevels.add(new LabelValueBean("9", "9"));
114: }
115:
116: /**
117: * Precomputed list of verbosity level labels and values.
118: */
119: private static List verbosityLevels = new ArrayList();
120:
121: static {
122: verbosityLevels.add(new LabelValueBean("0", "0"));
123: verbosityLevels.add(new LabelValueBean("1", "1"));
124: verbosityLevels.add(new LabelValueBean("2", "2"));
125: verbosityLevels.add(new LabelValueBean("3", "3"));
126: verbosityLevels.add(new LabelValueBean("4", "4"));
127: }
128:
129: /**
130: * Precomputed list of Jonas logger level labels and values.
131: */
132: private static List loggerJonasLevels = new ArrayList();
133:
134: static {
135: loggerJonasLevels.add(new LabelValueBean("DEBUG", "DEBUG"));
136: loggerJonasLevels.add(new LabelValueBean("WARN", "WARN"));
137: loggerJonasLevels.add(new LabelValueBean("INFO", "INFO"));
138: loggerJonasLevels.add(new LabelValueBean("ERROR", "ERROR"));
139: loggerJonasLevels.add(new LabelValueBean("INHERIT", "INHERIT"));
140: }
141:
142: /**
143: * Precomputed list of (true,false) labels and values.
144: */
145: private static List booleanValues = new ArrayList();
146:
147: static {
148: booleanValues.add(new LabelValueBean("True", "true"));
149: booleanValues.add(new LabelValueBean("False", "false"));
150: }
151:
152: /**
153: * Precomputed list of JdbcConnectionCheckingLevel labels and values.
154: */
155: private static List jdbcConnectionCheckingLevels = new ArrayList();
156:
157: static {
158: jdbcConnectionCheckingLevels.add(new LabelValueBean("0", "0"));
159: jdbcConnectionCheckingLevels.add(new LabelValueBean("1", "1"));
160: jdbcConnectionCheckingLevels.add(new LabelValueBean("2", "2"));
161: jdbcConnectionCheckingLevels.add(new LabelValueBean("3", "3"));
162: }
163:
164: /**
165: * Precomputed list of SpecVersions labels and values.
166: */
167: private static List specVersion = new ArrayList();
168:
169: static {
170: specVersion.add(new LabelValueBean("1.0", "1.0"));
171: specVersion.add(new LabelValueBean("1.5", "1.5"));
172: }
173:
174: /**
175: * Precomputed list of SecurityAuthenticationLdap labels and values.
176: */
177: private static List securityAuthenticationLdapValues = new ArrayList();
178:
179: static {
180: securityAuthenticationLdapValues.add(new LabelValueBean("none",
181: "none"));
182: securityAuthenticationLdapValues.add(new LabelValueBean(
183: "simple", "simple"));
184: securityAuthenticationLdapValues.add(new LabelValueBean(
185: "strong", "strong"));
186: securityAuthenticationLdapValues.add(new LabelValueBean(
187: "CRAM-MD5", "CRAM-MD5"));
188: securityAuthenticationLdapValues.add(new LabelValueBean(
189: "DIGEST-MD5", "DIGEST-MD5"));
190: }
191:
192: /**
193: * Precomputed list of AuthenticationModeLdapValues labels and values.
194: */
195: private static List authenticationModeLdapValues = new ArrayList();
196:
197: static {
198: authenticationModeLdapValues.add(new LabelValueBean("compare",
199: "compare"));
200: authenticationModeLdapValues.add(new LabelValueBean("bind",
201: "bind"));
202: }
203:
204: /**
205: * Precomputed list of securityAlgorithms labels and values.
206: */
207: private static List securityAlgorithms = new ArrayList();
208:
209: static {
210: securityAlgorithms.add(new LabelValueBean("", ""));
211: securityAlgorithms.add(new LabelValueBean("MD5", "MD5"));
212: securityAlgorithms.add(new LabelValueBean("MD2", "MD2"));
213: securityAlgorithms.add(new LabelValueBean("SHA-1", "SHA-1"));
214: securityAlgorithms.add(new LabelValueBean("SHA", "SHA"));
215: }
216:
217: // --------------------------------------------------------- Public Methods
218:
219: /**
220: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
221: * settings for <code>debug</code> properties.
222: */
223: public static List getDebugLevels() {
224: return (debugLevels);
225: }
226:
227: /**
228: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
229: * settings for <code>verbosity</code> properties.
230: */
231: public static List getVerbosityLevels() {
232: return (verbosityLevels);
233: }
234:
235: /**
236: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
237: * settings for <code>boolean</code> properties.
238: */
239: public static List getBooleanValues() {
240: return (booleanValues);
241: }
242:
243: /**
244: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
245: * settings for <code>Logger Jonas Levels</code> properties.
246: */
247: public static List getLoggerJonasLevels() {
248: return (loggerJonasLevels);
249: }
250:
251: /**
252: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
253: * settings for Jdbc Connection Checking Levels properties.
254: */
255: public static List getJdbcConnectionCheckingLevels() {
256: return (jdbcConnectionCheckingLevels);
257: }
258:
259: /**
260: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
261: * settings for Spec-Version property.
262: * @return a <code>List</code> of legal values.
263: */
264: public static List getSpecVersion() {
265: return (specVersion);
266: }
267:
268: /**
269: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
270: * settings for SecurityAuthenticationLdap properties.
271: */
272: public static List getSecurityAuthenticationLdapValues() {
273: return (securityAuthenticationLdapValues);
274: }
275:
276: /**
277: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
278: * settings for AuthenticationModeLdap properties.
279: */
280: public static List getAuthenticationModeLdapValues() {
281: return (authenticationModeLdapValues);
282: }
283:
284: /**
285: * Return a <code>List</code> of {@link LabelValueBean}s for the legal
286: * settings for SecurityAlgorithms properties.
287: */
288: public static List getSecurityAlgorithms() {
289: return (securityAlgorithms);
290: }
291:
292: /**
293: * Transform the collection like a string, each element are separated by the separator.
294: *
295: * @param p_Collection The collection to transform
296: * @param p_Separator The separator
297: * @return The collection string
298: */
299: public static String getString(Collection p_Collection,
300: String p_Separator) {
301: StringBuffer sb = new StringBuffer();
302: Iterator it = p_Collection.iterator();
303: while (it.hasNext()) {
304: sb.append(it.next());
305: if (it.hasNext()) {
306: sb.append(p_Separator);
307: }
308: }
309: return sb.toString();
310: }
311:
312: /**
313: * Transform the string like a ArrayString, each element are separated by the separator.
314: *
315: * @param p_String
316: * @param p_Separator The separator
317: * @return The list
318: */
319: public static ArrayList getArrayList(String p_String,
320: String p_Separator) {
321: ArrayList al = new ArrayList();
322: StringTokenizer st = new StringTokenizer(p_String, p_Separator);
323: while (st.hasMoreTokens()) {
324: al.add(st.nextToken().trim());
325: }
326: return al;
327: }
328: }
|