/**
  * This method is invoked when an attribute is replaced in the ServletContext object
  *
  * @param event Description of the Parameter
  */
 public void attributeReplaced(HttpSessionBindingEvent event) {
   // This event has a handle to the old User object
   ServletContext context = event.getSession().getServletContext();
   // The user has logged in
   if ("User".equals(event.getName())) {
     UserBean thisUser = (UserBean) event.getValue();
     thisUser.setSessionId(event.getSession().getId());
     Tracker tracker =
         ((SystemStatus)
                 ((Hashtable) context.getAttribute("SystemStatus"))
                     .get(thisUser.getConnectionElement().getUrl()))
             .getTracker();
     tracker.remove(event.getSession().getId());
     tracker.add(thisUser.getSessionId(), thisUser);
   }
 }
 /**
  * This method is invoked when an attribute is removed from the ServletContext object
  *
  * @param se Description of the Parameter
  */
 public void attributeRemoved(HttpSessionBindingEvent se) {
   ServletContext context = se.getSession().getServletContext();
   try {
     if (se.getName().equals("User")) {
       UserBean thisUser = (UserBean) se.getValue();
       if (thisUser != null) {
         // Internal SessionManager
         int userId = thisUser.getActualUserId();
         if (userId > -2) {
           // If context reloaded, then SystemStatus is null, but user is valid
           Hashtable systems = (Hashtable) context.getAttribute("SystemStatus");
           if (systems != null) {
             SystemStatus systemStatus =
                 (SystemStatus) systems.get(thisUser.getConnectionElement().getUrl());
             if (systemStatus != null) {
               // Remove the user from the session if it already is there
               SessionManager thisManager = systemStatus.getSessionManager();
               if (thisManager != null) {
                 UserSession thisSession = thisManager.getUserSession(userId);
                 if (thisSession != null && thisSession.getId().equals(thisUser.getSessionId())) {
                   if (System.getProperty("DEBUG") != null) {
                     System.out.println(
                         "ContextSessionListener-> Session for user " + userId + " ended");
                   }
                   thisManager.removeUser(userId);
                   if (System.getProperty("DEBUG") != null) {
                     System.out.println(
                         "ContextSessionListener-> User removed from valid user list");
                   }
                 }
               }
               // Website Tracker
               Tracker tracker = systemStatus.getTracker();
               tracker.remove(thisUser.getSessionId());
             }
           }
         }
       }
     }
   } catch (Exception e) {
     e.printStackTrace(System.out);
     System.out.println("ContextSessionListener-> attributeRemoved Error: " + e.toString());
   }
 }
 /**
  * This method is invoked when an attribute is added to the ServletContext object
  *
  * @param event Description of the Parameter
  */
 public void attributeAdded(HttpSessionBindingEvent event) {
   ServletContext context = event.getSession().getServletContext();
   if ("User".equals(event.getName())) {
     // A user session has been created, can be a portal user or system user
     UserBean thisUser = (UserBean) event.getValue();
     thisUser.setSessionId(event.getSession().getId());
     // Track website users
     Hashtable systems = (Hashtable) context.getAttribute("SystemStatus");
     if (systems != null && thisUser.getConnectionElement() != null) {
       SystemStatus systemStatus =
           (SystemStatus) systems.get(thisUser.getConnectionElement().getUrl());
       if (systemStatus != null) {
         Tracker tracker =
             ((SystemStatus)
                     ((Hashtable) context.getAttribute("SystemStatus"))
                         .get(thisUser.getConnectionElement().getUrl()))
                 .getTracker();
         tracker.add(thisUser.getSessionId(), thisUser);
       }
     }
   }
 }
  /**
   * Description of the Method
   *
   * @return Description of the Return Value
   * @throws JspException Description of the Exception
   */
  public int doStartTag() throws JspException {
    String dateString = "";
    String language = "en";
    String country = "US";
    try {
      Locale locale = null;
      // Retrieve the user's timezone from their session
      UserBean thisUser = (UserBean) pageContext.getSession().getAttribute("User");
      if (thisUser != null && thisUser.getUserId() != -1 && thisUser.getUserRecord() != null) {
        if (timeZone == null) {
          timeZone = thisUser.getUserRecord().getTimeZone();
        }
        locale = thisUser.getUserRecord().getLocale();
      }
      if (locale == null) {
        locale = Locale.getDefault();
      }
      language = locale.getLanguage();
      country = locale.getCountry();
      if (timestamp != null) {
        // Format the specified value with the retrieved timezone
        SimpleDateFormat formatter =
            (SimpleDateFormat) SimpleDateFormat.getDateInstance(dateFormat, locale);
        formatter.applyPattern(DateUtils.get4DigitYearDateFormat(formatter.toPattern()));

        // set the timezone
        if (timeZone != null) {
          java.util.TimeZone tz = java.util.TimeZone.getTimeZone(timeZone);
          formatter.setTimeZone(tz);
        }
        dateString = formatter.format(timestamp);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    // Output the result based on the retrieved info (if any)
    try {
      if (pageContext.getRequest().getAttribute(field + "Error") != null) {
        dateString = pageContext.getRequest().getParameter(field);
      }
      if (dateString == null) {
        dateString = "";
      }
      if (!hidden) {
        // TODO: Add onChange="checkDate(this.value)"
        String toWriteOut =
            "<input type=\"text\" name=\""
                + field
                + "\" size=\"10\" value=\""
                + dateString
                + "\" />"
                + (required ? " <font color='red'>*</font>" : "")
                + "&nbsp;<a href=\"javascript:popCalendar('"
                + form
                + "','"
                + field
                + "','"
                + language
                + "','"
                + country
                + "','"
                + timeZone
                + "');\">"
                + "<img src=\"images/icons/stock_form-date-field-16.gif\" border=\"0\" align=\"absmiddle\"></a>";
        if (showTimeZone) {
          toWriteOut =
              toWriteOut
                  + "&nbsp;"
                  + HtmlSelectTimeZone.getSelect(field + "TimeZone", timeZone).getHtml();
        }
        this.pageContext.getOut().write(toWriteOut);
      } else {
        this.pageContext
            .getOut()
            .write("<input type=\"hidden\" name=\"" + field + "\" value=\"" + dateString + "\" />");
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return SKIP_BODY;
  }