public class AvatarTag extends TagSupport {
public int doEndTag() throws JspException {
try {
IAvatarManager avatarManager = (IAvatarManager) ApsWebApplicationUtils.getBean(JpAvatarSystemConstants.AVATAR_MANAGER, pageContext);
HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
boolean isCurrentUserGuest = null == currentUser || currentUser.getUsername().trim().length() == 0 || currentUser.getUsername().equalsIgnoreCase(SystemConstants.GUEST_USER_NAME);
if (StringUtils.isBlank(this.getUsername()) && isCurrentUserGuest) {
this.doOut(this.getNullAvatar(avatarManager));
} else {
String username = this.getUsername();
if (StringUtils.isBlank(username)) {
username = currentUser.getUsername();
}
String avatarName = avatarManager.getAvatarUrl(username);
if (null != avatarName) {
this.doOut(avatarName);
} else {
this.doOut(this.getNullAvatar(avatarManager));
}
}
if (StringUtils.isNotBlank(this.getAvatarStyleVar())) {
this.pageContext.getRequest().setAttribute(this.getAvatarStyleVar(), avatarManager.getConfig().getStyle());
}
} catch (Throwable e) {
ApsSystemUtils.logThrowable(e, this, "doEndTag");
throw new JspException("Error in AvatarTag", e);
}