1 package org.apache.jetspeed.modules.parameters;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import java.util.Hashtable;
21 import java.util.Iterator;
22 import java.util.Map;
23
24
25 import org.apache.jetspeed.om.profile.Profile;
26 import org.apache.jetspeed.om.profile.QueryLocator;
27 import org.apache.jetspeed.services.Profiler;
28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
29 import org.apache.jetspeed.services.logging.JetspeedLogger;
30 import org.apache.jetspeed.services.rundata.JetspeedRunData;
31 import org.apache.jetspeed.util.PortletUtils;
32 import org.apache.jetspeed.modules.actions.portlets.PsmlManagerAction;
33
34
35 import org.apache.turbine.util.RunData;
36
37
38 import org.apache.velocity.context.Context;
39
40 /***
41 * Returns list box control populated with pmsl pages for current user for current media type.
42 * @author <a href="morciuch@apache.org">Mark Orciuch</a>
43 * @version $Id: MyPagesListBox.java,v 1.5 2004/02/23 03:01:20 jford Exp $
44 */
45
46 public class MyPagesListBox extends VelocityParameterPresentationStyle
47 {
48
49 /***
50 * Static initialization of the logger for this class
51 */
52 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(MyPagesListBox.class.getName());
53
54 /***
55 * Put custom objects in the velocity context
56 *
57 * @param data
58 * @param name
59 * @param value
60 * @param parms
61 * @param context
62 */
63 public void buildContext(RunData rundata, String name, String value, Map parms, Context context)
64 {
65 Map entries = null;
66
67 try
68 {
69 entries = (Map) rundata.getUser().getTemp(PsmlManagerAction.CACHED_PSML);
70 if (entries == null)
71 {
72
73 QueryLocator ql = new QueryLocator(QueryLocator.QUERY_USER);
74
75 JetspeedRunData jdata = (JetspeedRunData) rundata;
76 ql.setUser(jdata.getJetspeedUser());
77
78 entries = new Hashtable();
79 Iterator i = Profiler.query(ql);
80 while (i.hasNext())
81 {
82 Profile profile = (Profile) i.next();
83
84 String mediaType = profile.getMediaType();
85 if (mediaType != null && mediaType.equals(jdata.getCapability().getPreferredMediaType()))
86 {
87 if (PortletUtils.canAccessProfile(rundata, profile))
88 {
89 if (logger.isDebugEnabled())
90 {
91 logger.debug("MyPagesListBox: refreshing user profile list: " + profile.getPath());
92 }
93 String title = profile.getName();
94 if (profile.getRootSet() != null && profile.getRootSet().getTitle() != null)
95 {
96 title = profile.getRootSet().getTitle();
97 }
98 entries.put(profile, title);
99 }
100 }
101 }
102
103 rundata.getUser().setTemp(PsmlManagerAction.CACHED_PSML, entries);
104 }
105
106 context.put("pages", entries);
107 }
108 catch (Exception e)
109 {
110 logger.error("Exception", e);
111 }
112
113 }
114
115 }