[java-identity-provider COMMIT] in /trunk/idp-consent/src: main/java/net/shibboleth/idp/consent/logic/AbstractAttribu...
noreply at shibboleth.net
noreply at shibboleth.net
Thu Mar 26 23:24:03 EDT 2015
Author: tzeller
Date: Thu Mar 26 23:24:03 2015
New Revision: 7451
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=7451&view=rev
Log:
Cleanup consent attribute display functions. Guard against improbable NPE.
Modified:
trunk/idp-consent/src/main/java/net/shibboleth/idp/consent/logic/AbstractAttributeDisplayFunction.java
trunk/idp-consent/src/main/java/net/shibboleth/idp/consent/logic/AttributeDisplayDescriptionFunction.java
trunk/idp-consent/src/main/java/net/shibboleth/idp/consent/logic/AttributeDisplayNameFunction.java
trunk/idp-consent/src/test/java/net/shibboleth/idp/consent/logic/AttributeDisplayNameDescriptionFunctionTest.java
Modified: trunk/idp-consent/src/main/java/net/shibboleth/idp/consent/logic/AbstractAttributeDisplayFunction.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-consent/src/main/java/net/shibboleth/idp/consent/logic/AbstractAttributeDisplayFunction.java?rev=7451&r1=7450&r2=7451&view=diff
==============================================================================
--- trunk/idp-consent/src/main/java/net/shibboleth/idp/consent/logic/AbstractAttributeDisplayFunction.java (original)
+++ trunk/idp-consent/src/main/java/net/shibboleth/idp/consent/logic/AbstractAttributeDisplayFunction.java Thu Mar 26 23:24:03 2015
@@ -33,9 +33,9 @@
import com.google.common.base.Function;
/**
- * Abstract Function which returns information about attribute for the defined {@link Locale}. The abstract method
- * {@link #getDisplayInfo(IdPAttribute)} returns the information select from and the default is the attribute id if no
- * information is returned.
+ * Abstract Function which returns {@link Locale}-aware information about an attribute. The abstract method
+ * {@link #getDisplayInfo(IdPAttribute)} returns the information selected from the attribute. This function defaults to
+ * returning the attribute ID if no information is selected from the attribute for the desired locales.
*/
public abstract class AbstractAttributeDisplayFunction implements Function<IdPAttribute, String> {
@@ -45,42 +45,43 @@
/**
* Constructor.
*
- * @param request The {@link HttpServletRequest} this is used to get the languages.
- * @param defaultLanguages the comma delimited list of fallback languages
+ * @param request {@link HttpServletRequest} used to get preferred languages
+ * @param defaultLanguages list of fallback languages in order of decreasing preference
*/
- public AbstractAttributeDisplayFunction(@Nonnull HttpServletRequest request,
- @Nullable List<String> defaultLanguages) {
-
- final Enumeration<Locale> requestLocales = request.getLocales();
+ public AbstractAttributeDisplayFunction(@Nonnull final HttpServletRequest request,
+ @Nullable final List<String> defaultLanguages) {
final List<Locale> newLocales = new ArrayList<>();
+ final Enumeration<Locale> requestLocales = request.getLocales();
while (requestLocales.hasMoreElements()) {
newLocales.add(requestLocales.nextElement());
}
if (null != defaultLanguages) {
for (final String s : defaultLanguages) {
- newLocales.add(new Locale(s));
+ if (null != s) {
+ newLocales.add(new Locale(s));
+ }
}
}
locales = newLocales;
}
/** {@inheritDoc} */
- @Override @Nonnull @NotEmpty public String apply(@Nonnull final IdPAttribute input) {
+ @Override @Nonnull @NotEmpty public String apply(@Nullable final IdPAttribute input) {
if (input == null) {
return "N/A";
}
- final Map<Locale, String> displayNames = getDisplayInfo(input);
- if (null != displayNames && !displayNames.isEmpty()) {
+ final Map<Locale, String> displayInfo = getDisplayInfo(input);
+ if (null != displayInfo && !displayInfo.isEmpty()) {
for (final Locale locale : locales) {
- String displayName = displayNames.get(locale);
- if (displayName != null) {
- return displayName;
+ String toBeDisplayed = displayInfo.get(locale);
+ if (toBeDisplayed != null) {
+ return toBeDisplayed;
}
- displayName = displayNames.get(Locale.forLanguageTag(locale.getLanguage()));
- if (displayName != null) {
- return displayName;
+ toBeDisplayed = displayInfo.get(Locale.forLanguageTag(locale.getLanguage()));
+ if (toBeDisplayed != null) {
+ return toBeDisplayed;
}
}
}
@@ -90,8 +91,8 @@
/**
* Get the information to be displayed from the attribute.
*
- * @param input The attribute to consider
- * @return the map of locale dependant information.
+ * @param input the attribute to consider
+ * @return the map of locale dependent information to be displayed
*/
[... 111 lines stripped ...]
More information about the commits
mailing list