@Override
 public String restart() {
   Map<String, Resettable> resettables = BeanUtils.getBeansOfClass(Resettable.class);
   for (String name : resettables.keySet()) {
     if (logger.isDebugEnabled()) {
       logger.debug("trying to reset bean [" + name + "]...");
     }
     Resettable bean = resettables.get(name);
     if (bean == null) {
       throw new ConfigException(
           "bean [" + name + "] is null, " + "application can not be restarted.");
     }
     bean.reset();
     if (logger.isDebugEnabled()) {
       logger.debug("bean [" + name + "] was reset.");
     }
   }
   if (!isPortletMode()) {
     // it is always this case !
     ExceptionUtils.unmarkExceptionCaught();
     ((HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false))
         .invalidate();
   }
   return "applicationRestarted";
 }
 /** @return the current user's locale. */
 @Override
 public Locale getCurrentUserLocale() {
   if (logger.isDebugEnabled()) {
     logger.debug(this.getClass().getName() + ".getCurrentUserLocale()");
   }
   User currentUser = null;
   try {
     currentUser = getCurrentUser();
   } catch (Exception e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   if (currentUser == null) {
     if (logger.isDebugEnabled()) {
       logger.debug("no current user, return null");
     }
     return null;
   }
   String lang = currentUser.getLanguage();
   if (lang == null) {
     if (logger.isDebugEnabled()) {
       logger.debug("language not set for user '" + currentUser.getLogin() + "', return null");
     }
     return null;
   }
   Locale locale = new Locale(lang);
   if (logger.isDebugEnabled()) {
     logger.debug("language for user '" + currentUser.getLogin() + "' is '" + locale + "'");
   }
   return locale;
 }
 /** @return true if portlet mode. */
 private boolean isPortletMode() {
   if (logger.isDebugEnabled()) {
     logger.debug("Mode detected in Application");
   }
   FacesContext fc = FacesContext.getCurrentInstance();
   portletMode = ExternalContextUtils.isPortlet(fc.getExternalContext());
   if (logger.isDebugEnabled()) {
     if (portletMode) {
       logger.debug("Portlet mode detected");
     } else {
       logger.debug("Servlet mode detected");
     }
   }
   return portletMode;
 }
 /**
  * Store the authentication information to the session.
  *
  * @param authInfo
  * @param user
  */
 protected void storeToSession(final AuthInfo authInfo, final User user) {
   if (logger.isDebugEnabled()) {
     logger.debug("storing to session: " + authInfo);
   }
   ContextUtils.setSessionAttribute(AUTH_INFO_ATTRIBUTE, authInfo);
   ContextUtils.setSessionAttribute(USER_ATTRIBUTE, user);
 }
 /**
  * @see org.esupportail.commons.web.component.UIAbstractPaginatorStyle#makeDivPages(
  *     javax.faces.application.Application)
  */
 @SuppressWarnings("unchecked")
 @Override
 protected Div makeDivPages(final Application a) {
   if (logger.isDebugEnabled()) {
     logger.debug("entering makeDivPagination(" + a + ")");
   }
   Div divPages = (Div) a.createComponent(Div.COMPONENT_TYPE);
   divPages.setParent(this);
   divPages.setStyleClass(NAVIGATION_BLOCK);
   // if there are more than one page on display pagination
   if (getPaginator().getFirstPageNumber() != getPaginator().getLastPageNumber()) {
     HtmlTag ul1 = (HtmlTag) a.createComponent(HtmlTag.COMPONENT_TYPE);
     ul1.setValue(HTML.UL_ELEM);
     ul1.setParent(divPages);
     // PREVIOUS BUTTON
     if (getPaginator().getCurrentPage() != getPaginator().getFirstPageNumber()) {
       ul1.getChildren()
           .add(
               makeLiGroup(
                   a,
                   getStringsVar() + "['" + PREVIOUS_BUTTON_I18N_KEY + "']",
                   null,
                   true,
                   PaginatorUtils.GOTO_PREVIOUS,
                   null,
                   null));
     }
     // BODY of Paginator
     divPages = makePages(divPages, getPaginator(), ul1, a);
   }
   return divPages;
 }
 /**
  * @param targetService
  * @return a proxy ticket.
  * @throws CasException
  */
 private String retrieveProxyTicket(final String targetService) throws CasException {
   if (logger.isDebugEnabled()) {
     logger.debug("retrieving a proxy ticket for service [" + targetService + "]...");
     logger.debug("pgtIou=[" + validator.getPgtIou() + "]");
   }
   int tryNumber = 0;
   Exception exception = null;
   while (tryNumber < (1 + retries)) {
     tryNumber++;
     if (logger.isDebugEnabled()) {
       logger.debug("try #" + tryNumber);
     }
     try {
       String url = URLEncoder.encode(targetService, "UTF-8");
       return ProxyTicketReceptor.getProxyTicket(validator.getPgtIou(), url);
     } catch (IOException e) {
       if (logger.isDebugEnabled()) {
         logger.debug(
             "could not retrieve a proxy ticket for service ["
                 + targetService
                 + "] (try #"
                 + tryNumber
                 + ")",
             e);
       }
       if (tryNumber == retries) {
         try {
           Thread.sleep(sleep * THOUSAND);
         } catch (InterruptedException ie) {
           exception = ie;
         }
       } else {
         exception = e;
       }
     }
   }
   CasException ce =
       new CasException(
           "could not get a proxy ticket for service [" + targetService + "]", exception);
   if (logger.isDebugEnabled()) {
     logger.debug(ce);
   }
   throw ce;
 }
 /** @see org.esupportail.pstage.services.authentication.Authenticator#getUser() */
 public User getUser() {
   AuthInfo authInfo = (AuthInfo) ContextUtils.getSessionAttribute(AUTH_INFO_ATTRIBUTE);
   if (authInfo != null) {
     User user = (User) ContextUtils.getSessionAttribute(USER_ATTRIBUTE);
     if (logger.isDebugEnabled()) {
       logger.debug("found auth info in session: " + user);
     }
     return user;
   }
   if (logger.isDebugEnabled()) {
     logger.debug("no auth info found in session");
   }
   authInfo = authenticationService.getAuthInfo();
   if (authInfo == null) {
     return null;
   }
   if (AuthUtils.CAS.equals(authInfo.getType())) {
     User user = getDomainService().getUser(authInfo.getId());
     storeToSession(authInfo, user);
     return user;
   }
   return null;
 }
  public String getAsString(
      @SuppressWarnings("unused") final FacesContext context,
      @SuppressWarnings("unused") final UIComponent component,
      final Object value) {

    String text = value.toString();
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(text);
    while (m.find())
      text =
          text.replace(
              m.group(1),
              account.getAttribute(m.group(2)) != null ? account.getAttribute(m.group(2)) : none);

    logger.debug("Converted string : " + text);

    return text;
  }
 /** @see org.esupportail.commons.services.cas.CasService#validate() */
 public void validate() throws CasException {
   String serviceTicket = getServiceTicket();
   validator = new ProxyTicketValidator();
   validator.setCasValidateUrl(casValidateUrl);
   validator.setService(service);
   validator.setServiceTicket(serviceTicket);
   validator.setProxyCallbackUrl(proxyCallbackUrl);
   if (logger.isDebugEnabled()) {
     logger.debug("validating ticket [" + serviceTicket + "]...");
     logger.debug("casValidateUrl=[" + validator.getCasValidateUrl() + "]");
     logger.debug("service=[" + service + "]");
     logger.debug("proxyCallbackUrl=[" + validator.getProxyCallbackUrl() + "]");
   }
   int tryNumber = 0;
   Exception validateException = null;
   while (tryNumber < (1 + retries)) {
     tryNumber++;
     if (logger.isDebugEnabled()) {
       logger.debug("try #" + tryNumber);
     }
     try {
       validator.validate();
       if (logger.isDebugEnabled()) {
         logger.debug("response = [" + validator.getResponse() + "]");
         logger.debug("errorCode = [" + validator.getErrorCode() + "]");
         logger.debug("errorMessage = [" + validator.getErrorMessage() + "]");
       }
       if (validator.isAuthenticationSuccesful()) {
         return;
       }
       // no error, but authentication failed
       throw new CasException(
           "authentication failed for ticket ["
               + serviceTicket
               + "] ("
               + validator.getErrorCode()
               + ": "
               + validator.getErrorMessage()
               + ")");
     } catch (IOException e) {
       if (logger.isDebugEnabled()) {
         logger.debug(
             "could not validate ticket [" + serviceTicket + "] (try #" + tryNumber + ")", e);
       }
       if (tryNumber == retries) {
         try {
           Thread.sleep(sleep * THOUSAND);
         } catch (InterruptedException ie) {
           validateException = ie;
         }
       } else {
         validateException = e;
       }
     } catch (SAXException e) {
       validateException = e;
     } catch (ParserConfigurationException e) {
       validateException = e;
     }
   }
   CasException ce =
       new CasException("could not validate ticket [" + serviceTicket + "]", validateException);
   if (logger.isDebugEnabled()) {
     logger.debug(ce);
   }
   throw ce;
 }