1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.administration;
18
19 import java.util.ArrayList;
20
21 import javax.servlet.jsp.JspException;
22
23 import org.apache.jetspeed.om.folder.Folder;
24 import org.apache.taglibs.random.RandomStrg;
25
26 /***
27 * Helper for admininstration
28 *
29 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
30 * @author <a href="mailto:chris@bluesunrise.com">Chris Schaefer</a>
31 * @version $Id: $
32 */
33 public class AdminUtil
34 {
35 /*** the list of characters from which a password can be generatored. */
36 protected static final char[] PASS_CHARS = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
37 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
38 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
39 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
40 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
41
42
43
44
45
46 public String generatePassword()
47 {
48 RandomStrg rs = new RandomStrg();
49
50
51
52
53 try
54 {
55 rs.generateRandomObject();
56 } catch (JspException e)
57 {
58
59
60 e.printStackTrace();
61 }
62 rs.setLength(new Integer(12));
63 rs.setSingle(PASS_CHARS,PASS_CHARS.length);
64 ArrayList upper = new ArrayList();
65 ArrayList lower = new ArrayList();
66
67
68 rs.setRanges(upper,lower);
69 String retval = rs.getRandom();
70
71 return retval;
72 }
73
74 protected String concatenatePaths(String base, String path)
75 {
76 String result = "";
77 if (base == null)
78 {
79 if (path == null)
80 {
81 return result;
82 }
83 return path;
84 }
85 else
86 {
87 if (path == null)
88 {
89 return base;
90 }
91 }
92 if (base.endsWith(Folder.PATH_SEPARATOR))
93 {
94 if (path.startsWith(Folder.PATH_SEPARATOR))
95 {
96 result = base.concat(path.substring(1));
97 return result;
98 }
99
100 }
101 else
102 {
103 if (!path.startsWith(Folder.PATH_SEPARATOR))
104 {
105 result = base.concat(Folder.PATH_SEPARATOR).concat(path);
106 return result;
107 }
108 }
109 return base.concat(path);
110 }
111
112 }