KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > modules > parameters > MyPagesListBox


1 package org.apache.jetspeed.modules.parameters;
2
3 /*
4  * Copyright 2000-2001,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 // Java stuff
20
import java.util.Hashtable JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 // Jetspeed
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 // Turbine stuff
35
import org.apache.turbine.util.RunData;
36
37 // Velocity stuff
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 JavaDoc name, String JavaDoc value, Map JavaDoc parms, Context context)
64     {
65         Map JavaDoc entries = null;
66
67         try
68         {
69             entries = (Map JavaDoc) rundata.getUser().getTemp(PsmlManagerAction.CACHED_PSML);
70             if (entries == null)
71             {
72                 // Initialize the query locator
73
QueryLocator ql = new QueryLocator(QueryLocator.QUERY_USER);
74
75                 JetspeedRunData jdata = (JetspeedRunData) rundata;
76                 ql.setUser(jdata.getJetspeedUser());
77                 //ql.setMediaType(jdata.getCapability().getPreferredMediaType());
78
entries = new Hashtable JavaDoc();
79                 Iterator JavaDoc i = Profiler.query(ql);
80                 while (i.hasNext())
81                 {
82                     Profile profile = (Profile) i.next();
83
84                     String JavaDoc 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 JavaDoc 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 JavaDoc e)
109         {
110             logger.error("Exception", e);
111         }
112
113     }
114
115 }
Popular Tags