Search in sources :

Example 11 with LocaleManager

use of org.apereo.portal.i18n.LocaleManager in project uPortal by Jasig.

the class UserInstanceManagerImpl method getUserInstance.

/**
 * Returns the UserInstance object that is associated with the given request.
 *
 * @param request Incoming HttpServletRequest
 * @return UserInstance object associated with the given request
 */
@Override
public IUserInstance getUserInstance(HttpServletRequest request) throws PortalException {
    try {
        request = this.portalRequestUtils.getOriginalPortalRequest(request);
    } catch (IllegalArgumentException iae) {
    // ignore, just means that this isn't a wrapped request
    }
    // Use request attributes first for the fastest possible retrieval
    IUserInstance userInstance = (IUserInstance) request.getAttribute(KEY);
    if (userInstance != null) {
        return userInstance;
    }
    final IPerson person;
    try {
        // Retrieve the person object that is associated with the request
        person = this.personManager.getPerson(request);
    } catch (Exception e) {
        logger.error("Exception while retrieving IPerson!", e);
        throw new PortalSecurityException("Could not retrieve IPerson", e);
    }
    if (person == null) {
        throw new PortalSecurityException("PersonManager returned null person for this request.  With no user, there's no UserInstance.  Is PersonManager misconfigured?  RDBMS access misconfigured?");
    }
    final HttpSession session = request.getSession();
    if (session == null) {
        throw new IllegalStateException("HttpServletRequest.getSession() returned a null session for request: " + request);
    }
    // Return the UserInstance object if it's in the session
    UserInstanceHolder userInstanceHolder = getUserInstanceHolder(session);
    if (userInstanceHolder != null) {
        userInstance = userInstanceHolder.getUserInstance();
        if (userInstance != null) {
            return userInstance;
        }
    }
    // Create either a UserInstance or a GuestUserInstance
    final LocaleManager localeManager = this.getLocaleManager(request, person);
    final String userAgent = this.getUserAgent(request);
    final IUserProfile userProfile = this.getUserProfile(request, person, localeManager, userAgent);
    // Create the user layout manager and user instance object
    IUserLayoutManager userLayoutManager = userLayoutManagerFactory.getUserLayoutManager(person, userProfile);
    final UserPreferencesManager userPreferencesManager = new UserPreferencesManager(person, userProfile, userLayoutManager);
    userInstance = new UserInstance(person, userPreferencesManager, localeManager);
    // Ensure the newly created UserInstance is cached in the session
    if (userInstanceHolder == null) {
        userInstanceHolder = new UserInstanceHolder();
    }
    userInstanceHolder.setUserInstance(userInstance);
    session.setAttribute(KEY, userInstanceHolder);
    request.setAttribute(KEY, userInstance);
    // Return the new UserInstance
    return userInstance;
}
Also used : HttpSession(javax.servlet.http.HttpSession) PortalSecurityException(org.apereo.portal.security.PortalSecurityException) PortalSecurityException(org.apereo.portal.security.PortalSecurityException) PortalException(org.apereo.portal.PortalException) UserPreferencesManager(org.apereo.portal.UserPreferencesManager) IPerson(org.apereo.portal.security.IPerson) IUserProfile(org.apereo.portal.IUserProfile) LocaleManager(org.apereo.portal.i18n.LocaleManager) UserInstance(org.apereo.portal.UserInstance) IUserLayoutManager(org.apereo.portal.layout.IUserLayoutManager)

Example 12 with LocaleManager

use of org.apereo.portal.i18n.LocaleManager in project uPortal by Jasig.

the class LocaleTransformerConfigurationSource method getCacheKey.

/* (non-Javadoc)
     * @see org.apereo.portal.rendering.xslt.TransformerConfigurationSource#getCacheKey(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
@Override
public CacheKey getCacheKey(HttpServletRequest request, HttpServletResponse response) {
    final LocaleManager localeManager = this.getLocaleManager(request);
    final List<Locale> locales = localeManager.getLocales();
    if (locales != null && locales.size() > 0 && locales.get(0) != null) {
        final String locale = locales.get(0).toString();
        final String xslLocale = locale.replace('_', '-');
        return CacheKey.build(this.getClass().getName(), xslLocale);
    }
    return null;
}
Also used : Locale(java.util.Locale) LocaleManager(org.apereo.portal.i18n.LocaleManager)

Example 13 with LocaleManager

use of org.apereo.portal.i18n.LocaleManager in project uPortal by Jasig.

the class DefinitionHeaderProvider method getUserLocale.

/*
     * Implementation
     */
private Locale getUserLocale(IPerson user) {
    // get user locale
    Locale[] locales = localeStore.getUserLocales(user);
    LocaleManager localeManager = localeManagerFactory.createLocaleManager(user, Arrays.asList(locales));
    return localeManager.getLocales().get(0);
}
Also used : Locale(java.util.Locale) LocaleManager(org.apereo.portal.i18n.LocaleManager)

Example 14 with LocaleManager

use of org.apereo.portal.i18n.LocaleManager in project uPortal by Jasig.

the class AbstractTenantOperationsListener method getCurrentUserLocale.

/*
     * Implementation
     */
private Locale getCurrentUserLocale() {
    final HttpServletRequest req = this.portalRequestUtils.getCurrentPortalRequest();
    final IPerson person = personManager.getPerson(req);
    final Locale[] userLocales = localeStore.getUserLocales(person);
    final LocaleManager localeManager = localeManagerFactory.createLocaleManager(person, Arrays.asList(userLocales));
    final Locale locale = localeManager.getLocales().get(0);
    return locale;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Locale(java.util.Locale) IPerson(org.apereo.portal.security.IPerson) LocaleManager(org.apereo.portal.i18n.LocaleManager)

Aggregations

LocaleManager (org.apereo.portal.i18n.LocaleManager)14 Locale (java.util.Locale)11 IUserProfile (org.apereo.portal.IUserProfile)5 IPerson (org.apereo.portal.security.IPerson)5 IUserInstance (org.apereo.portal.user.IUserInstance)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)2 PortalException (org.apereo.portal.PortalException)2 IJoinQueryString (org.apereo.portal.jdbc.IJoinQueryString)2 Tuple (org.apereo.portal.utils.Tuple)2 DataAccessException (org.springframework.dao.DataAccessException)2 Document (org.w3c.dom.Document)2 Element (org.w3c.dom.Element)2 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 HttpSession (javax.servlet.http.HttpSession)1