View Javadoc

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;
21  import java.util.Iterator;
22  import java.util.Map;
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 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                  // 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();
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 }