Search in sources :

Example 16 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class UserLocaleHelper method getCurrentUserLocale.

/**
     * Return the current user's locale.
     *
     * @param request
     * @return
     */
public Locale getCurrentUserLocale(PortletRequest request) {
    final HttpServletRequest originalPortalRequest = this.portalRequestUtils.getPortletHttpRequest(request);
    IUserInstance ui = userInstanceManager.getUserInstance(originalPortalRequest);
    IUserPreferencesManager upm = ui.getPreferencesManager();
    final IUserProfile userProfile = upm.getUserProfile();
    LocaleManager localeManager = userProfile.getLocaleManager();
    // first check the session locales
    Locale[] sessionLocales = localeManager.getSessionLocales();
    if (sessionLocales != null && sessionLocales.length > 0) {
        return sessionLocales[0];
    }
    // if no session locales were found, check the user locales
    Locale[] userLocales = localeManager.getUserLocales();
    if (userLocales != null && userLocales.length > 0) {
        return userLocales[0];
    }
    // just return null
    return null;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IUserInstance(org.apereo.portal.user.IUserInstance) Locale(java.util.Locale) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager) LocaleManager(org.apereo.portal.i18n.LocaleManager)

Example 17 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class UrlNodeSyntaxHelperRegistryImpl method getCurrentUrlNodeSyntaxHelper.

@Override
public IUrlNodeSyntaxHelper getCurrentUrlNodeSyntaxHelper(HttpServletRequest request) {
    final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
    final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
    final IUserProfile userProfile = preferencesManager.getUserProfile();
    final int themeStylesheetId = userProfile.getThemeStylesheetId();
    final IUrlNodeSyntaxHelper themeUrlSyntaxHelper = getUrlNodeSyntaxHelperForStylesheet(themeStylesheetId);
    if (themeUrlSyntaxHelper != null) {
        return themeUrlSyntaxHelper;
    }
    final int structureStylesheetId = userProfile.getStructureStylesheetId();
    final IUrlNodeSyntaxHelper structureUrlSyntaxHelper = getUrlNodeSyntaxHelperForStylesheet(structureStylesheetId);
    if (structureUrlSyntaxHelper != null) {
        return structureUrlSyntaxHelper;
    }
    throw new IllegalStateException("No IUrlNodeSyntaxHelper could be found for the current request. Review the IStylesheetDescriptor configuration.");
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Example 18 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class FragmentActivator method loadLayout.

private void loadLayout(UserView view, FragmentDefinition fragment, IPerson owner, Locale locale) {
    // if fragment not bound to user can't return any layouts.
    if (view.getUserId() == -1)
        return;
    // this area is hacked right now. Time won't permit how to handle
    // matching up multiple profiles for a fragment with an appropriate
    // one for incorporating into a user's layout based on their profile
    // when they log in with a certain user agent. The challenge is
    // being able to match up profiles for a user with those of a
    // fragment. Until this is resolved only one profile will be supported
    // and will have a hard coded id of 1 which is the default for profiles.
    // If anyone changes this user all heck could break loose for dlm. :-(
    Document layout = null;
    try {
        // fix hard coded 1 later for multiple profiles
        IUserProfile profile = userLayoutStore.getUserProfileByFname(owner, "default");
        profile.setLocaleManager(new LocaleManager(owner, new Locale[] { locale }));
        // If not then fall back on system's selected stylesheets.
        if (profile.getStructureStylesheetId() == 0 || profile.getThemeStylesheetId() == 0)
            profile = userLayoutStore.getSystemProfileByFname(profile.getProfileFname());
        view.setProfileId(profile.getProfileId());
        view.setLayoutId(profile.getLayoutId());
        layout = userLayoutStore.getFragmentLayout(owner, profile);
        Element root = layout.getDocumentElement();
        root.setAttribute(Constants.ATT_ID, Constants.FRAGMENT_ID_USER_PREFIX + view.getUserId() + Constants.FRAGMENT_ID_LAYOUT_PREFIX + view.getLayoutId());
        view.setLayout(layout);
    } catch (Exception e) {
        LOG.error("Anomaly occurred while loading layout for fragment '" + fragment.getName() + "'. The fragment will not be " + "available for inclusion into user layouts.", e);
    }
}
Also used : Locale(java.util.Locale) IUserProfile(org.apereo.portal.IUserProfile) Element(org.w3c.dom.Element) LocaleManager(org.apereo.portal.i18n.LocaleManager) Document(org.w3c.dom.Document) AuthorizationException(org.apereo.portal.AuthorizationException)

Example 19 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class FragmentActivator method saveLayout.

/**
     * Saves the loaded layout in the database for the user and profile.
     *
     * @param view
     * @param owner
     * @throws Exception
     */
private void saveLayout(UserView view, IPerson owner) throws Exception {
    IUserProfile profile = new UserProfile();
    profile.setProfileId(view.getProfileId());
    userLayoutStore.setUserLayout(owner, profile, view.getLayout(), true, false);
}
Also used : IUserProfile(org.apereo.portal.IUserProfile) UserProfile(org.apereo.portal.UserProfile) IUserProfile(org.apereo.portal.IUserProfile)

Example 20 with IUserProfile

use of org.apereo.portal.IUserProfile in project uPortal by Jasig.

the class StylesheetUserPreferencesServiceImpl method getStylesheetDescriptor.

@Override
public IStylesheetDescriptor getStylesheetDescriptor(HttpServletRequest request, PreferencesScope prefScope) {
    String stylesheetName = this.getStyleSheetName(request, prefScope);
    if (!StringUtils.isBlank(stylesheetName)) {
        return this.stylesheetDescriptorDao.getStylesheetDescriptorByName(stylesheetName);
    } else {
        final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
        final IUserPreferencesManager preferencesManager = userInstance.getPreferencesManager();
        final IUserProfile userProfile = preferencesManager.getUserProfile();
        final int stylesheetId = prefScope.getStylesheetId(userProfile);
        return this.stylesheetDescriptorDao.getStylesheetDescriptor(stylesheetId);
    }
}
Also used : IUserInstance(org.apereo.portal.user.IUserInstance) IUserProfile(org.apereo.portal.IUserProfile) IUserPreferencesManager(org.apereo.portal.IUserPreferencesManager)

Aggregations

IUserProfile (org.apereo.portal.IUserProfile)23 IUserInstance (org.apereo.portal.user.IUserInstance)10 IUserPreferencesManager (org.apereo.portal.IUserPreferencesManager)9 IPerson (org.apereo.portal.security.IPerson)7 LocaleManager (org.apereo.portal.i18n.LocaleManager)4 IStylesheetDescriptor (org.apereo.portal.layout.om.IStylesheetDescriptor)4 Locale (java.util.Locale)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 PortalException (org.apereo.portal.PortalException)3 BrokenSecurityContext (org.apereo.portal.security.provider.BrokenSecurityContext)3 PersonImpl (org.apereo.portal.security.provider.PersonImpl)3 Document (org.w3c.dom.Document)3 ArrayList (java.util.ArrayList)2 AuthorizationException (org.apereo.portal.AuthorizationException)2 UserProfile (org.apereo.portal.UserProfile)2 IStylesheetUserPreferences (org.apereo.portal.layout.om.IStylesheetUserPreferences)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 Test (org.junit.Test)2 Node (org.w3c.dom.Node)2 Connection (java.sql.Connection)1