use of org.olat.user.propertyhandlers.GenderPropertyHandler in project openolat by klemens.
the class DisplayPortraitController method loadPortrait.
private void loadPortrait() {
File image = null;
if (displayPortraitImage) {
GenderPropertyHandler genderHander = (GenderPropertyHandler) UserManager.getInstance().getUserPropertiesConfig().getPropertyHandler(UserConstants.GENDER);
// use as default
String gender = "-";
if (genderHander != null) {
gender = genderHander.getInternalValue(portraitIdent.getUser());
}
if (useLarge) {
image = DisplayPortraitManager.getInstance().getBigPortrait(portraitIdent.getName());
if (image != null && !forceAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_BIG_CSS_CLASS);
} else if (isAnonymous || forceAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.ANONYMOUS_BIG_CSS_CLASS);
} else if (gender.equals("-")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_BIG_CSS_CLASS);
} else if (gender.equals("male")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_MALE_BIG_CSS_CLASS);
} else if (gender.equals("female")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_FEMALE_BIG_CSS_CLASS);
}
} else {
image = DisplayPortraitManager.getInstance().getSmallPortrait(portraitIdent.getName());
if (image != null && !forceAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_SMALL_CSS_CLASS);
} else if (isAnonymous || forceAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.ANONYMOUS_SMALL_CSS_CLASS);
} else if (gender.equals("-")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_SMALL_CSS_CLASS);
} else if (gender.equals("male")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_MALE_SMALL_CSS_CLASS);
} else if (gender.equals("female")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_FEMALE_SMALL_CSS_CLASS);
}
}
if (image != null) {
myContent.contextPut("mapperUrl", mapper.createPathFor(mapperPath, portraitIdent));
} else {
myContent.contextRemove("mapperUrl");
}
} else {
myContent.contextRemove("mapperUrl");
}
myContent.contextPut("hasPortrait", (image != null && !forceAnonymous) ? Boolean.TRUE : Boolean.FALSE);
}
use of org.olat.user.propertyhandlers.GenderPropertyHandler in project openolat by klemens.
the class UserVOFactory method parseGender.
/**
* Allow the value of gender to be in the raw form (male, female key word) or
* to be translated
* @param value
* @param handler
* @param locale
* @return
*/
public static final String parseGender(String value, GenderPropertyHandler handler, Locale locale) {
if (!StringHelper.containsNonWhitespace(value)) {
value = "-";
}
int index = Arrays.binarySearch(UserVOFactory.keys, value);
if (index < 0) {
// try to translate them
boolean found = false;
Translator trans = Util.createPackageTranslator(GenderPropertyHandler.class, locale);
for (String key : keys) {
String translation = trans.translate(handler.i18nFormElementLabelKey() + "." + key);
if (translation.equals(value)) {
value = key;
found = true;
break;
}
}
if (!found && !locale.equals(I18nModule.getDefaultLocale())) {
// very last chance, try with the default locale
trans = Util.createPackageTranslator(GenderPropertyHandler.class, I18nModule.getDefaultLocale());
for (String key : keys) {
String translation = trans.translate(handler.i18nFormElementLabelKey() + "." + key);
if (translation.equals(value)) {
value = key;
found = true;
break;
}
}
}
}
return value;
}
use of org.olat.user.propertyhandlers.GenderPropertyHandler in project OpenOLAT by OpenOLAT.
the class DisplayPortraitController method loadPortrait.
private void loadPortrait() {
File image = null;
if (displayPortraitImage) {
GenderPropertyHandler genderHander = (GenderPropertyHandler) UserManager.getInstance().getUserPropertiesConfig().getPropertyHandler(UserConstants.GENDER);
// use as default
String gender = "-";
if (genderHander != null) {
gender = genderHander.getInternalValue(portraitIdent.getUser());
}
if (useLarge) {
image = DisplayPortraitManager.getInstance().getBigPortrait(portraitIdent.getName());
if (image != null && !forceAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_BIG_CSS_CLASS);
} else if (isAnonymous || forceAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.ANONYMOUS_BIG_CSS_CLASS);
} else if (gender.equals("-")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_BIG_CSS_CLASS);
} else if (gender.equals("male")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_MALE_BIG_CSS_CLASS);
} else if (gender.equals("female")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_FEMALE_BIG_CSS_CLASS);
}
} else {
image = DisplayPortraitManager.getInstance().getSmallPortrait(portraitIdent.getName());
if (image != null && !forceAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.AVATAR_SMALL_CSS_CLASS);
} else if (isAnonymous || forceAnonymous) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.ANONYMOUS_SMALL_CSS_CLASS);
} else if (gender.equals("-")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_SMALL_CSS_CLASS);
} else if (gender.equals("male")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_MALE_SMALL_CSS_CLASS);
} else if (gender.equals("female")) {
myContent.contextPut("portraitCssClass", DisplayPortraitManager.DUMMY_FEMALE_SMALL_CSS_CLASS);
}
}
if (image != null) {
myContent.contextPut("mapperUrl", mapper.createPathFor(mapperPath, portraitIdent));
} else {
myContent.contextRemove("mapperUrl");
}
} else {
myContent.contextRemove("mapperUrl");
}
myContent.contextPut("hasPortrait", (image != null && !forceAnonymous) ? Boolean.TRUE : Boolean.FALSE);
}
use of org.olat.user.propertyhandlers.GenderPropertyHandler in project OpenOLAT by OpenOLAT.
the class UserVOFactory method parseGender.
/**
* Allow the value of gender to be in the raw form (male, female key word) or
* to be translated
* @param value
* @param handler
* @param locale
* @return
*/
public static final String parseGender(String value, GenderPropertyHandler handler, Locale locale) {
if (!StringHelper.containsNonWhitespace(value)) {
value = "-";
}
int index = Arrays.binarySearch(UserVOFactory.keys, value);
if (index < 0) {
// try to translate them
boolean found = false;
Translator trans = Util.createPackageTranslator(GenderPropertyHandler.class, locale);
for (String key : keys) {
String translation = trans.translate(handler.i18nFormElementLabelKey() + "." + key);
if (translation.equals(value)) {
value = key;
found = true;
break;
}
}
if (!found && !locale.equals(I18nModule.getDefaultLocale())) {
// very last chance, try with the default locale
trans = Util.createPackageTranslator(GenderPropertyHandler.class, I18nModule.getDefaultLocale());
for (String key : keys) {
String translation = trans.translate(handler.i18nFormElementLabelKey() + "." + key);
if (translation.equals(value)) {
value = key;
found = true;
break;
}
}
}
}
return value;
}
use of org.olat.user.propertyhandlers.GenderPropertyHandler in project OpenOLAT by OpenOLAT.
the class UserVOFactory method post.
public static void post(User dbUser, UserVO user, Locale locale) {
UserManager um = UserManager.getInstance();
List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
dbUser.setProperty(UserConstants.FIRSTNAME, user.getFirstName());
dbUser.setProperty(UserConstants.LASTNAME, user.getLastName());
dbUser.setProperty(UserConstants.EMAIL, user.getEmail());
for (UserPropertyVO entry : user.getProperties()) {
for (UserPropertyHandler propertyHandler : propertyHandlers) {
if (entry.getName().equals(propertyHandler.getName())) {
String value = parseUserProperty(entry.getValue(), propertyHandler, locale);
String parsedValue;
if (propertyHandler instanceof DatePropertyHandler) {
parsedValue = formatDbDate(value, locale);
} else if (propertyHandler instanceof GenderPropertyHandler) {
parsedValue = parseGender(value, (GenderPropertyHandler) propertyHandler, locale);
} else {
parsedValue = propertyHandler.getStringValue(value, locale);
}
dbUser.setProperty(entry.getName(), parsedValue);
break;
}
}
}
}
Aggregations