KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > Jlists


1 /*
2  * $Header: /cvsroot/jonas/jonas/src/org/objectweb/jonas/webapp/jonasadmin/Jlists.java,v 1.9 2003/11/12 17:19:34 antonma Exp $
3  * $Revision: 1.9 $
4  * $Date: 2003/11/12 17:19:34 $
5  *
6  * ====================================================================
7  *
8  * The Apache Software License, Version 1.1
9  *
10  * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
11  * reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  *
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  *
20  * 2. Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in
22  * the documentation and/or other materials provided with the
23  * distribution.
24  *
25  * 3. The end-user documentation included with the redistribution, if
26  * any, must include the following acknowlegement:
27  * "This product includes software developed by the
28  * Apache Software Foundation (http://www.apache.org/)."
29  * Alternately, this acknowlegement may appear in the software itself,
30  * if and wherever such third-party acknowlegements normally appear.
31  *
32  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
33  * Foundation" must not be used to endorse or promote products derived
34  * from this software without prior written permission. For written
35  * permission, please contact apache@apache.org.
36  *
37  * 5. Products derived from this software may not be called "Apache"
38  * nor may "Apache" appear in their names without prior written
39  * permission of the Apache Group.
40  *
41  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52  * SUCH DAMAGE.
53  * ====================================================================
54  *
55  * This software consists of voluntary contributions made by many
56  * individuals on behalf of the Apache Software Foundation. For more
57  * information on the Apache Software Foundation, please see
58  * <http://www.apache.org/>.
59  *
60  */

61
62 package org.objectweb.jonas.webapp.jonasadmin;
63
64 import java.util.ArrayList JavaDoc;
65 import java.util.Collection JavaDoc;
66 import java.util.Iterator JavaDoc;
67 import java.util.List JavaDoc;
68 import java.util.StringTokenizer JavaDoc;
69
70 import org.objectweb.jonas.webapp.taglib.LabelValueBean;
71
72 /**
73  * General purpose utility methods to create lists of objects that are
74  * commonly required in building the user interface. In all cases, if there
75  * are no matching elements, a zero-length list (rather than <code>null</code>)
76  * is returned.
77  *
78  * @author Craig R. McClanahan
79  * @version $Revision: 1.9 $ $Date: 2003/11/12 17:19:34 $
80  */

81
82 public class Jlists {
83
84 // --------------------------------------------------------- Constants
85

86     public final static String JavaDoc SEPARATOR = ",";
87
88 // ----------------------------------------------------------- Constructors
89

90     /**
91      * Protected constructor to prevent instantiation.
92      */

93     protected Jlists() {}
94
95 // ------------------------------------------------------- Static Variables
96

97     /**
98      * Precomputed list of debug level labels and values.
99      */

100     private static List JavaDoc debugLevels = new ArrayList JavaDoc();
101
102     static {
103         debugLevels.add(new LabelValueBean("0", "0"));
104         debugLevels.add(new LabelValueBean("1", "1"));
105         debugLevels.add(new LabelValueBean("2", "2"));
106         debugLevels.add(new LabelValueBean("3", "3"));
107         debugLevels.add(new LabelValueBean("4", "4"));
108         debugLevels.add(new LabelValueBean("5", "5"));
109         debugLevels.add(new LabelValueBean("6", "6"));
110         debugLevels.add(new LabelValueBean("7", "7"));
111         debugLevels.add(new LabelValueBean("8", "8"));
112         debugLevels.add(new LabelValueBean("9", "9"));
113     }
114
115     /**
116      * Precomputed list of verbosity level labels and values.
117      */

118     private static List JavaDoc verbosityLevels = new ArrayList JavaDoc();
119
120     static {
121         verbosityLevels.add(new LabelValueBean("0", "0"));
122         verbosityLevels.add(new LabelValueBean("1", "1"));
123         verbosityLevels.add(new LabelValueBean("2", "2"));
124         verbosityLevels.add(new LabelValueBean("3", "3"));
125         verbosityLevels.add(new LabelValueBean("4", "4"));
126     }
127
128     /**
129      * Precomputed list of Jonas logger level labels and values.
130      */

131     private static List JavaDoc loggerJonasLevels = new ArrayList JavaDoc();
132
133     static {
134         loggerJonasLevels.add(new LabelValueBean("DEBUG", "DEBUG"));
135         loggerJonasLevels.add(new LabelValueBean("WARN", "WARN"));
136         loggerJonasLevels.add(new LabelValueBean("INFO", "INFO"));
137         loggerJonasLevels.add(new LabelValueBean("ERROR", "ERROR"));
138         loggerJonasLevels.add(new LabelValueBean("INHERIT", "INHERIT"));
139     }
140
141     /**
142      * Precomputed list of (true,false) labels and values.
143      */

144     private static List JavaDoc booleanValues = new ArrayList JavaDoc();
145
146     static {
147         booleanValues.add(new LabelValueBean("True", "true"));
148         booleanValues.add(new LabelValueBean("False", "false"));
149     }
150
151     /**
152      * Precomputed list of JdbcConnectionCheckingLevel labels and values.
153      */

154     private static List JavaDoc jdbcConnectionCheckingLevels = new ArrayList JavaDoc();
155
156     static {
157         jdbcConnectionCheckingLevels.add(new LabelValueBean("0", "0"));
158         jdbcConnectionCheckingLevels.add(new LabelValueBean("1", "1"));
159         jdbcConnectionCheckingLevels.add(new LabelValueBean("2", "2"));
160     }
161
162     /**
163      * Precomputed list of SecurityAuthenticationLdap labels and values.
164      */

165     private static List JavaDoc securityAuthenticationLdapValues = new ArrayList JavaDoc();
166
167     static {
168         securityAuthenticationLdapValues.add(new LabelValueBean("none", "none"));
169         securityAuthenticationLdapValues.add(new LabelValueBean("simple", "simple"));
170         securityAuthenticationLdapValues.add(new LabelValueBean("strong", "strong"));
171         securityAuthenticationLdapValues.add(new LabelValueBean("CRAM-MD5", "CRAM-MD5"));
172         securityAuthenticationLdapValues.add(new LabelValueBean("DIGEST-MD5", "DIGEST-MD5"));
173     }
174
175     /**
176      * Precomputed list of AuthenticationModeLdapValues labels and values.
177      */

178     private static List JavaDoc authenticationModeLdapValues = new ArrayList JavaDoc();
179
180     static {
181         authenticationModeLdapValues.add(new LabelValueBean("compare", "compare"));
182         authenticationModeLdapValues.add(new LabelValueBean("bind", "bind"));
183     }
184
185     /**
186      * Precomputed list of securityAlgorithms labels and values.
187      */

188     private static List JavaDoc securityAlgorithms = new ArrayList JavaDoc();
189
190     static {
191         securityAlgorithms.add(new LabelValueBean("", ""));
192         securityAlgorithms.add(new LabelValueBean("MD5", "MD5"));
193         securityAlgorithms.add(new LabelValueBean("MD2", "MD2"));
194         securityAlgorithms.add(new LabelValueBean("SHA-1", "SHA-1"));
195         securityAlgorithms.add(new LabelValueBean("SHA", "SHA"));
196     }
197
198 // --------------------------------------------------------- Public Methods
199

200     /**
201      * Return a <code>List</code> of {@link LabelValueBean}s for the legal
202      * settings for <code>debug</code> properties.
203      */

204     public static List JavaDoc getDebugLevels() {
205         return (debugLevels);
206     }
207
208     /**
209      * Return a <code>List</code> of {@link LabelValueBean}s for the legal
210      * settings for <code>verbosity</code> properties.
211      */

212     public static List JavaDoc getVerbosityLevels() {
213         return (verbosityLevels);
214     }
215
216     /**
217      * Return a <code>List</code> of {@link LabelValueBean}s for the legal
218      * settings for <code>boolean</code> properties.
219      */

220     public static List JavaDoc getBooleanValues() {
221         return (booleanValues);
222     }
223
224     /**
225      * Return a <code>List</code> of {@link LabelValueBean}s for the legal
226      * settings for <code>Logger Jonas Levels</code> properties.
227      */

228     public static List JavaDoc getLoggerJonasLevels() {
229         return (loggerJonasLevels);
230     }
231
232     /**
233      * Return a <code>List</code> of {@link LabelValueBean}s for the legal
234      * settings for Jdbc Connection Checking Levels properties.
235      */

236     public static List JavaDoc getJdbcConnectionCheckingLevels() {
237         return (jdbcConnectionCheckingLevels);
238     }
239
240     /**
241      * Return a <code>List</code> of {@link LabelValueBean}s for the legal
242      * settings for SecurityAuthenticationLdap properties.
243      */

244     public static List JavaDoc getSecurityAuthenticationLdapValues() {
245         return (securityAuthenticationLdapValues);
246     }
247
248     /**
249      * Return a <code>List</code> of {@link LabelValueBean}s for the legal
250      * settings for AuthenticationModeLdap properties.
251      */

252     public static List JavaDoc getAuthenticationModeLdapValues() {
253         return (authenticationModeLdapValues);
254     }
255
256     /**
257      * Return a <code>List</code> of {@link LabelValueBean}s for the legal
258      * settings for SecurityAlgorithms properties.
259      */

260     public static List JavaDoc getSecurityAlgorithms() {
261         return (securityAlgorithms);
262     }
263
264     /**
265      * Transform the collection like a string, each element are separated by the separator.
266      *
267      * @param p_Collection The collection to transform
268      * @param p_Separator The separator
269      * @return The collection string
270      */

271     public static String JavaDoc getString(Collection JavaDoc p_Collection, String JavaDoc p_Separator) {
272         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
273         Iterator JavaDoc it = p_Collection.iterator();
274         while (it.hasNext()) {
275             sb.append(it.next());
276             if (it.hasNext()) {
277                 sb.append(p_Separator);
278             }
279         }
280         return sb.toString();
281     }
282
283     /**
284      * Transform the string like a ArrayString, each element are separated by the separator.
285      *
286      * @param p_String
287      * @param p_Separator The separator
288      * @return The list
289      */

290     public static ArrayList JavaDoc getArrayList(String JavaDoc p_String, String JavaDoc p_Separator) {
291         ArrayList JavaDoc al = new ArrayList JavaDoc();
292         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(p_String, p_Separator);
293         while (st.hasMoreTokens()) {
294             al.add(st.nextToken().trim());
295         }
296         return al;
297     }
298 }
299
Popular Tags