View Javadoc

1   package org.gnomekr.potron.web.view;
2   
3   import javax.faces.context.FacesContext;
4   import javax.faces.el.VariableResolver;
5   
6   import org.apache.commons.logging.Log;
7   import org.apache.commons.logging.LogFactory;
8   
9   import net.sf.acegisecurity.Authentication;
10  import net.sf.acegisecurity.context.security.SecureContext;
11  import net.sf.acegisecurity.context.security.SecureContextUtils;
12  import net.sf.acegisecurity.providers.dao.User;
13  
14  /***
15   * AbstractFacesView.java
16   * @author Xavier Cho
17   * @version $Revision 1.1 $ $Date: 2005/07/17 08:08:32 $
18   */
19  public abstract class AbstractFacesView {
20  
21      private static final String TREE_BEAN_NAME = "navigation";
22  
23      private static Log log = LogFactory.getLog(AbstractFacesView.class);
24  
25      protected String getCurrentUserName() {
26          SecureContext context = SecureContextUtils.getSecureContext();
27          Authentication auth = context.getAuthentication();
28  
29          String userName = null;
30          User user = (User) auth.getPrincipal();
31  
32          if (user != null) {
33              userName = user.getUsername();
34          }
35  
36          return userName;
37      }
38  
39      void refreshNavigationTree() {
40          if (log.isDebugEnabled()) {
41              log.debug("Refreshing navigation tree menu.");
42          }
43  
44          FacesContext context = FacesContext.getCurrentInstance();
45          VariableResolver resolver = context.getApplication()
46                  .getVariableResolver();
47          NavigationTreeView tree = (NavigationTreeView) resolver
48                  .resolveVariable(context, TREE_BEAN_NAME);
49          tree.refresh();
50      }
51  }