public GravatarPanel(final String idParam, final String emailParam) { super(idParam); if (emailParam == null) { LOGGER.debug(new StringResourceModel("nullEmailParamLogMessage", this, null).getString()); addDefaultGravatarImage(); } else { try { final byte[] hash = MessageDigest.getInstance(MD5).digest(emailParam.getBytes()); final StringBuilder hashString = new StringBuilder(); for (final byte elementLocal : hash) { final String hex = Integer.toHexString(elementLocal); if (hex.length() == 1) { hashString.append(ZERO); hashString.append(hex.charAt(hex.length() - 1)); } else { hashString.append(hex.substring(hex.length() - 2)); } } final Image imgLocal = new Image(WICKET_ID_GRAVATAR_IMG, (IResource) null); imgLocal.add( AttributeModifierFactory.newAttributeAppenderForSrc( "http://www.gravatar.com/avatar/" + hashString.toString() + DOT_JPG)); imgLocal.add( AttributeModifierFactory.newAttributeAppenderForAlt( new StringResourceModel("gravatarAlt", this, null) + emailParam + DOT)); add(imgLocal); } catch (final NoSuchAlgorithmException ex) { LOGGER.info( new StringResourceModel("md5HashAlgoNotFoundLogMessage", this, null).getString(), ex); addDefaultGravatarImage(); } } }
private void addDefaultGravatarImage() { final Image imgLocal = new Image(WICKET_ID_GRAVATAR_IMG, (IResource) null); imgLocal.add( AttributeModifierFactory.newAttributeAppenderForSrc( new StringResourceModel("defaultGravatarImageHref", this, null).getString())); imgLocal.add( AttributeModifierFactory.newAttributeAppenderForAlt( new StringResourceModel("defaultGravatarImageAlt", this, null).getString())); add(imgLocal); }