Skip to content

Commit

Permalink
Merge branch 'master' into feature/support-java-9
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianMurphy committed Feb 27, 2018
2 parents 2f947f8 + ed6e488 commit b581402
Show file tree
Hide file tree
Showing 24 changed files with 464 additions and 433 deletions.
12 changes: 3 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ plugins {
id 'build-announcements'
id 'com.github.kt3k.coveralls' version '2.8.2'
id 'com.moowork.node' version '1.2.0'
id 'me.champeau.buildscan-recipes' version '0.2.0'
id 'net.researchgate.release' version '2.6.0'
// Records all tasks in task graph, generates `build/reports/visteg.dot`
// dot file can be converted to an image using graphviz. `dot -Tsvg -O -v visteg.dot`
id 'cz.malohlava' version '1.0.3'

// Sub project plugins
id 'com.github.sherter.google-java-format' version '0.6' apply false
id 'nebula.lint' version '8.3.1' apply false
id 'nebula.lint' version '8.3.2' apply false
//id 'net.ltgt.errorprone' version '0.0.13' apply false
}

Expand All @@ -35,9 +34,6 @@ buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
}
buildScanRecipes {
recipes 'travis-ci', 'git-commit'
}

allprojects {
apply plugin: 'java'
Expand All @@ -60,11 +56,11 @@ allprojects {
}

dependencies {
//errorprone 'com.google.errorprone:error_prone_core:2.1.2'
//errorprone 'com.google.errorprone:error_prone_core:2.2.0'
}

codenarc {
toolVersion = '1.0'
toolVersion = '1.1'
reportFormat = 'console'
}

Expand Down Expand Up @@ -108,8 +104,6 @@ subprojects {
apply plugin: 'maven-publish'
apply plugin: 'maven'
apply plugin: 'signing'
apply plugin: 'maven-publish'


/*======== Dependency Management ========**/
repositories {
Expand Down
1 change: 1 addition & 0 deletions docs/implement/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ users, groups, layouts, *etc.*
5. Content (TBD)
2. [Frontend](frontend/README.md)
3. [Security](security.md)
4. [Internationalization](i18n.md)
31 changes: 31 additions & 0 deletions docs/implement/i18n.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Internationalization

uPortal provides internationalization features. There are three aspects to implementing support for
another language in the portal: the uPortal (Spring) _MessageSource_, _uPortal Data_, and _Content
Modules_.

## uPortal MessageSource

uPortal provides support for internationalizing UI strings through a Spring `MessageSource`.
uPortal comes with several languages available, but you can add your own (or update an existing
one) by adding a `Messages_{code}.properties` file in the classpath at `/properties/i18n/` where
{code} is the two-character country code (e.g. 'fr' for French and 'de' for German).

Use the `org.apereo.portal.i18n.LocaleManager.portal_locales` property to define the languages
available in the portal. Add this property to either `uPortal.properties` or `global.properties`.

### Portal Locales Example

```properties
org.apereo.portal.i18n.LocaleManager.portal_locales=fr_FR
```

This value will limit the portal to _French_.

## uPortal Data

_TBD._

## Content Modules

_TBD._
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ portletApiDependency=org.apache.portals:portlet-api_2.1.0_spec:1.0

# Dependency Versions
activationVersion=1.0.2
antVersion=1.10.1
awsVersion=1.11.255
antVersion=1.10.2
awsVersion=1.11.285
apereoPortletUtilsVersion=1.1.2
aspectjVersion=1.8.13
casClientVersion=3.4.1
Expand Down Expand Up @@ -72,7 +72,7 @@ hibernateJpamodelgenVersion=1.2.0.Final
hsqldbVersion=2.4.0
httpclientVersion=4.5.4
httpcomponentsVersion=4.4.4
jacksonVersion=2.9.3
jacksonVersion=2.9.4
jansiVersion=1.11
javaxMailVersion=1.4.7
javaxmlVersion=1.3.1
Expand All @@ -89,10 +89,10 @@ jspApiVersion=2.2
junitVersion=4.12
lesscssVersion=1.7.0.1.1
logbackVersion=1.2.3
mockitoVersion=2.13.0
mockitoVersion=2.15.0
nodejsVersion=8.9.4
oauthVersion=20100527
orgJsonVersion=20090211
orgJsonVersion=20171018
personDirectoryVersion=1.8.5
plutoVersion=2.1.0-M3
resourceServerVersion=1.0.46
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
Expand All @@ -36,6 +37,7 @@
import org.apereo.portal.groups.IGroupMember;
import org.apereo.portal.i18n.ILocaleStore;
import org.apereo.portal.i18n.LocaleManager;
import org.apereo.portal.i18n.LocaleManagerFactory;
import org.apereo.portal.layout.dlm.remoting.IGroupListHelper;
import org.apereo.portal.layout.dlm.remoting.JsonEntityBean;
import org.apereo.portal.persondir.ILocalAccountDao;
Expand Down Expand Up @@ -65,6 +67,7 @@ public class UserAccountHelper {
private static final String PORTLET_FNAME_LOGIN = "login";

private ILocaleStore localeStore;
private LocaleManagerFactory localeManagerFactory;
private ILocalAccountDao accountDao;
private IPortalPasswordService passwordService;
private List<Preference> accountEditAttributes;
Expand All @@ -80,6 +83,11 @@ public void setLocaleStore(ILocaleStore localeStore) {
this.localeStore = localeStore;
}

@Autowired
public void setLocaleManagerFactory(LocaleManagerFactory localeManagerFactory) {
this.localeManagerFactory = localeManagerFactory;
}

@Autowired
public void setLocalAccountDao(ILocalAccountDao accountDao) {
this.accountDao = accountDao;
Expand Down Expand Up @@ -487,8 +495,9 @@ public void createPassword(PersonForm form, String token) {
protected Locale getCurrentUserLocale(final HttpServletRequest request) {
final IPerson person = personManager.getPerson(request);
final Locale[] userLocales = localeStore.getUserLocales(person);
final LocaleManager localeManager = new LocaleManager(person, userLocales);
final Locale locale = localeManager.getLocales()[0];
final LocaleManager localeManager =
localeManagerFactory.createLocaleManager(person, Arrays.asList(userLocales));
final Locale locale = localeManager.getLocales().get(0);
return locale;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.apereo.portal.portlets.localization;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import javax.portlet.PortletRequest;
Expand All @@ -24,6 +25,7 @@
import org.apereo.portal.PortalException;
import org.apereo.portal.i18n.ILocaleStore;
import org.apereo.portal.i18n.LocaleManager;
import org.apereo.portal.i18n.LocaleManagerFactory;
import org.apereo.portal.layout.dlm.Constants;
import org.apereo.portal.security.IPerson;
import org.apereo.portal.url.IPortalRequestUtils;
Expand All @@ -39,6 +41,7 @@ public class UserLocaleHelper {
private IUserInstanceManager userInstanceManager;
private IPortalRequestUtils portalRequestUtils;
private ILocaleStore localeStore;
private LocaleManagerFactory localeManagerFactory;

@Autowired
public void setLocaleStore(ILocaleStore localeStore) {
Expand All @@ -48,7 +51,7 @@ public void setLocaleStore(ILocaleStore localeStore) {
/**
* Set the UserInstanceManager
*
* @param userInstanceManager
* @param userInstanceManager The {@link IUserInstanceManager}
*/
@Autowired
public void setUserInstanceManager(IUserInstanceManager userInstanceManager) {
Expand All @@ -60,17 +63,22 @@ public void setPortalRequestUtils(IPortalRequestUtils portalRequestUtils) {
this.portalRequestUtils = portalRequestUtils;
}

@Autowired
public void setLocaleManagerFactory(LocaleManagerFactory localeManagerFactory) {
this.localeManagerFactory = localeManagerFactory;
}

/**
* Return a list of LocaleBeans matching the currently available locales for the portal.
*
* @param currentLocale
* @return
*/
public List<LocaleBean> getLocales(Locale currentLocale) {
List<LocaleBean> locales = new ArrayList<LocaleBean>();
List<LocaleBean> locales = new ArrayList<>();

// get the array of locales available from the portal
Locale[] portalLocales = getPortalLocales();
List<Locale> portalLocales = localeManagerFactory.getPortalLocales();
for (Locale locale : portalLocales) {
if (currentLocale != null) {
// if a current locale is available, display language names
Expand All @@ -86,7 +94,7 @@ public List<LocaleBean> getLocales(Locale currentLocale) {
/**
* Return the current user's locale.
*
* @param request
* @param request The current {@link PortletRequest}
* @return
*/
public Locale getCurrentUserLocale(PortletRequest request) {
Expand All @@ -98,15 +106,15 @@ public Locale getCurrentUserLocale(PortletRequest request) {
LocaleManager localeManager = userProfile.getLocaleManager();

// first check the session locales
Locale[] sessionLocales = localeManager.getSessionLocales();
if (sessionLocales != null && sessionLocales.length > 0) {
return sessionLocales[0];
List<Locale> sessionLocales = localeManager.getSessionLocales();
if (sessionLocales != null && sessionLocales.size() > 0) {
return sessionLocales.get(0);
}

// if no session locales were found, check the user locales
Locale[] userLocales = localeManager.getUserLocales();
if (userLocales != null && userLocales.length > 0) {
return userLocales[0];
List<Locale> userLocales = localeManager.getUserLocales();
if (userLocales != null && userLocales.size() > 0) {
return userLocales.get(0);
}

// if no selected locale was found either in the session or user layout,
Expand All @@ -131,9 +139,9 @@ public void updateUserLocale(HttpServletRequest request, String localeString) {

if (localeString != null) {

// build a new Locale[] array from the specified locale
Locale userLocale = parseLocale(localeString);
Locale[] locales = new Locale[] {userLocale};
// build a new List<Locale> from the specified locale
Locale userLocale = localeManagerFactory.parseLocale(localeString);
List<Locale> locales = Collections.singletonList(userLocale);

// set this locale in the session
localeManager.setSessionLocales(locales);
Expand All @@ -143,7 +151,7 @@ public void updateUserLocale(HttpServletRequest request, String localeString) {
final IPerson person = ui.getPerson();
if (!person.isGuest()) {
try {
localeManager.persistUserLocales(new Locale[] {userLocale});
localeManager.setUserLocales(Collections.singletonList(userLocale));
localeStore.updateUserLocales(person, new Locale[] {userLocale});

// remove person layout framgent from session since it contains some of the data
Expand All @@ -158,27 +166,4 @@ public void updateUserLocale(HttpServletRequest request, String localeString) {
}
}
}

/*
* Convenience methods to enhance testability by wrapping static methods
*/

/**
* Get the available portal locales.
*
* @return
*/
protected Locale[] getPortalLocales() {
return LocaleManager.getPortalLocales();
}

/**
* Parse a string representation of a locale and return the matching Locale.
*
* @param localeString
* @return
*/
protected Locale parseLocale(String localeString) {
return LocaleManager.parseLocale(localeString);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.apereo.portal.layout.dlm.remoting;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
Expand All @@ -25,6 +26,7 @@
import org.apereo.portal.EntityIdentifier;
import org.apereo.portal.i18n.ILocaleStore;
import org.apereo.portal.i18n.LocaleManager;
import org.apereo.portal.i18n.LocaleManagerFactory;
import org.apereo.portal.layout.dlm.remoting.registry.ChannelBean;
import org.apereo.portal.layout.dlm.remoting.registry.ChannelCategoryBean;
import org.apereo.portal.layout.dlm.remoting.registry.v43.PortletCategoryBean;
Expand Down Expand Up @@ -76,6 +78,7 @@ public class ChannelListController {
private IPersonManager personManager;
private IPortalSpELService spELService;
private ILocaleStore localeStore;
private LocaleManagerFactory localeManagerFactory;
private MessageSource messageSource;
private IAuthorizationService authorizationService;

Expand Down Expand Up @@ -112,6 +115,11 @@ public void setLocaleStore(ILocaleStore localeStore) {
this.localeStore = localeStore;
}

@Autowired
public void setLocaleManagerFactory(LocaleManagerFactory localeManagerFactory) {
this.localeManagerFactory = localeManagerFactory;
}

@Autowired
public void setMessageSource(MessageSource messageSource) {
this.messageSource = messageSource;
Expand Down Expand Up @@ -465,9 +473,9 @@ private PortletDefinitionBean preparePortletDefinitionBean(
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;
LocaleManager localeManager =
localeManagerFactory.createLocaleManager(user, Arrays.asList(locales));
return localeManager.getLocales().get(0);
}

/**
Expand Down
Loading

0 comments on commit b581402

Please sign in to comment.