use of org.apereo.portal.i18n.LocaleManager in project uPortal by Jasig.
the class RDBMUserLayoutStore method getUserProfileByFname.
public UserProfile getUserProfileByFname(final IPerson person, final String profileFname) {
Tuple<String, String> key = null;
final Cache<Tuple<String, String>, UserProfile> profileCache = getProfileImportExportCache();
if (profileCache != null) {
key = new Tuple<String, String>(person.getUserName(), profileFname);
final UserProfile profile = profileCache.getIfPresent(key);
if (profile != null) {
return profile;
}
}
logger.debug("Getting profile {} for user {}", profileFname, person.getID());
final int userId = person.getID();
final UserProfile userProfile = jdbcOperations.execute(new ConnectionCallback<UserProfile>() {
@Override
public UserProfile doInConnection(Connection con) throws SQLException, DataAccessException {
String query = "SELECT USER_ID, PROFILE_ID, PROFILE_NAME, DESCRIPTION, " + "LAYOUT_ID, STRUCTURE_SS_ID, THEME_SS_ID FROM UP_USER_PROFILE WHERE " + "USER_ID=? AND PROFILE_FNAME=?";
PreparedStatement pstmt = con.prepareStatement(query);
pstmt.setInt(1, userId);
pstmt.setString(2, profileFname);
try {
logger.debug("getUserProfileByFname(): {} userId: {} profileFname: {}", query, userId, profileFname);
ResultSet rs = pstmt.executeQuery();
try {
if (rs.next()) {
int profileId = rs.getInt(2);
String profileName = rs.getString(3);
String profileDesc = rs.getString(4);
int layoutId = rs.getInt(5);
if (rs.wasNull()) {
layoutId = 0;
}
int structSsId = rs.getInt(6);
if (rs.wasNull()) {
// This is probably a data issue and probably an export operation; defer to the system user...
if (!person.equals(getSystemUser())) {
structSsId = getSystemProfileByFname(profileFname).getStructureStylesheetId();
} else {
String msg = "The system user profile has no structure stylesheet Id.";
throw new IllegalStateException(msg);
}
}
int themeSsId = rs.getInt(7);
if (rs.wasNull()) {
// This is probably a data issue and probably an export operation; defer to the system user...
if (!person.equals(getSystemUser())) {
themeSsId = getSystemProfileByFname(profileFname).getThemeStylesheetId();
} else {
String msg = "The system user profile has no theme stylesheet Id.";
throw new IllegalStateException(msg);
}
}
UserProfile userProfile = new UserProfile(profileId, profileFname, profileName, profileDesc, layoutId, structSsId, themeSsId);
final Locale[] userLocales = localeStore.getUserLocales(person);
userProfile.setLocaleManager(new LocaleManager(person, userLocales));
return userProfile;
}
/* Try to copy the template profile. */
logger.debug("Copying template profile {} to user {}", profileFname, person.getID());
rs.close();
pstmt.close();
pstmt = con.prepareStatement("SELECT USER_DFLT_USR_ID FROM UP_USER WHERE USER_ID=?");
pstmt.setInt(1, person.getID());
rs = pstmt.executeQuery();
if (rs.next()) {
int defaultProfileUser = rs.getInt(1);
if (rs.wasNull()) {
throw new RuntimeException("Need to clone the '" + profileFname + "' profile from template user for " + person + " but they have no template user");
}
IPerson defaultProfilePerson = new PersonImpl();
defaultProfilePerson.setID(defaultProfileUser);
if (defaultProfilePerson.getID() != person.getID()) {
UserProfile templateProfile = getUserProfileByFname(defaultProfilePerson, profileFname);
if (templateProfile != null) {
UserProfile newUserProfile = new UserProfile(templateProfile);
final Locale[] userLocales = localeStore.getUserLocales(person);
newUserProfile.setLayoutId(0);
newUserProfile = addUserProfile(person, newUserProfile);
newUserProfile.setLocaleManager(new LocaleManager(person, userLocales));
return newUserProfile;
}
}
}
throw new RuntimeException("Unable to find User Profile for userId " + userId + " and profile " + profileFname);
} finally {
rs.close();
}
} finally {
pstmt.close();
}
}
});
if (profileCache != null && key != null) {
profileCache.put(key, userProfile);
}
return userProfile;
}
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 = new LocaleManager(person, userLocales);
final Locale locale = localeManager.getLocales()[0];
return locale;
}
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 Locale[] locales = localeManager.getLocales();
if (locales != null && locales.length > 0 && locales[0] != null) {
final String locale = locales[0].toString();
final String xslLocale = locale.replace('_', '-');
return CacheKey.build(this.getClass().getName(), xslLocale);
}
return null;
}
use of org.apereo.portal.i18n.LocaleManager in project uPortal by Jasig.
the class ChannelListController method getUserLocale.
/*
* Implementation
*/
private Locale getUserLocale(IPerson user) {
// get user locale
Locale[] locales = localeStore.getUserLocales(user);
LocaleManager localeManager = new LocaleManager(user, locales);
Locale rslt = localeManager.getLocales()[0];
return rslt;
}
use of org.apereo.portal.i18n.LocaleManager 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;
}
Aggregations