1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.util;
18
19 import org.apache.jetspeed.om.profile.Portlets;
20 import org.apache.jetspeed.om.profile.Entry;
21 import org.apache.jetspeed.om.profile.Reference;
22 import org.apache.jetspeed.services.idgenerator.JetspeedIdGenerator;
23
24
25 import org.apache.jetspeed.om.profile.Profile;
26 import org.apache.jetspeed.services.security.PortalResource;
27 import org.apache.jetspeed.om.security.JetspeedUser;
28 import org.apache.jetspeed.services.JetspeedSecurity;
29
30
31 import org.apache.turbine.util.RunData;
32
33 /***
34 * This class provides static util methods for portlet manipulation that
35 * aren't part of the default services.
36 *
37 * @author <a href="mailto:morciuch@apache.org">Mark Orciuch</a>
38 * @version $Id: PortletUtils.java,v 1.4 2004/02/23 03:23:42 jford Exp $
39 */
40 public class PortletUtils
41 {
42 /***
43 * Regenerates jspeid for all portlets, entries and references
44 *
45 * @param profile Profile to process
46 * @return Profile with portlet ids regenerated
47 */
48 public static void regenerateIds(Portlets topPortlets)
49 throws Exception
50 {
51
52 Portlets[] portlets = topPortlets.getPortletsArray();
53 for (int i = 0; i < portlets.length; i++)
54 {
55 portlets[i].setId(JetspeedIdGenerator.getNextPeid());
56
57 Entry[] entries = portlets[i].getEntriesArray();
58 for (int j = 0; j < entries.length; j++)
59 {
60 entries[j].setId(JetspeedIdGenerator.getNextPeid());
61 }
62
63 Reference[] refs = portlets[i].getReferenceArray();
64 for (int k = 0; k < refs.length; k++)
65 {
66 refs[k].setId(JetspeedIdGenerator.getNextPeid());
67 }
68
69 regenerateIds(portlets[i]);
70 }
71 }
72
73 /***
74 * Returns true if specific profile is accessible by the current user
75 *
76 * @param data
77 * @param profile
78 * @return
79 */
80 public static boolean canAccessProfile(RunData rundata, Profile profile)
81 {
82 boolean result = true;
83
84 if (profile != null && profile.getRootSet() != null)
85 {
86 PortalResource portalResource = new PortalResource(profile.getRootSet());
87 String owner = null;
88 if (profile.getUserName() != null)
89 {
90 owner = profile.getUserName();
91 }
92 portalResource.setOwner(owner);
93
94 result = JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(),
95 portalResource,
96 JetspeedSecurity.PERMISSION_CUSTOMIZE);
97 }
98
99 return result;
100
101 }
102
103 }