Package org.primefaces.component.avatar
Class AvatarRenderer
java.lang.Object
javax.faces.render.Renderer
org.primefaces.renderkit.CoreRenderer
org.primefaces.component.avatar.AvatarRenderer
-
Field Summary
Fields inherited from class javax.faces.render.Renderer
PASSTHROUGH_RENDERER_LOCALNAME_KEY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected String
calculateLabel
(javax.faces.context.FacesContext context, Avatar avatar) Generates a label based on the text if its more than 2 characters.void
encodeChildren
(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component) protected void
encodeDefaultContent
(javax.faces.context.FacesContext context, Avatar avatar, String label) void
encodeEnd
(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component) protected String
generateBackgroundColor
(Avatar avatar) Generates a dynamic color based on the hash of the label.protected String
generateGravatar
(javax.faces.context.FacesContext context, Avatar avatar) Generate a Gravatar URL for an email addressed based on API docs.protected void
generateMailHash
(StringBuilder sb, String email) Converts email address into a hash code for Gravatar API.boolean
Methods inherited from class org.primefaces.renderkit.CoreRenderer
buildAjaxRequest, buildAjaxRequest, buildAjaxRequest, buildDomEvent, buildNonAjaxRequest, buildNonAjaxRequest, decodeBehaviors, encodeClientBehaviors, encodeIndexedId, endsWithLenghtUnit, getEventBehaviors, getHighlighter, getIconOnlyButtonText, getResourceRequestPath, getResourceURL, getStyleBuilder, getStyleClassBuilder, getWidgetBuilder, isGrouped, isValueBlank, logDevelopmentWarning, preConfiguredAjaxRequestBuilder, preConfiguredAjaxRequestBuilder, renderAttribute, renderButtonValue, renderChild, renderChildren, renderDomEvent, renderDomEvents, renderDummyMarkup, renderDynamicPassThruAttributes, renderHiddenInput, renderOnchange, renderOnclick, renderPassThruAttributes, renderPassThruAttributes, renderPassThruAttributes, renderRTLDirection, renderValidationMetadata, shouldRenderAttribute, shouldWriteId
Methods inherited from class javax.faces.render.Renderer
convertClientId, decode, encodeBegin, getConvertedValue
-
Constructor Details
-
AvatarRenderer
public AvatarRenderer()
-
-
Method Details
-
encodeEnd
public void encodeEnd(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component) throws IOException - Overrides:
encodeEnd
in classjavax.faces.render.Renderer
- Throws:
IOException
-
encodeDefaultContent
protected void encodeDefaultContent(javax.faces.context.FacesContext context, Avatar avatar, String label) throws IOException - Throws:
IOException
-
encodeChildren
public void encodeChildren(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component) throws IOException - Overrides:
encodeChildren
in classjavax.faces.render.Renderer
- Throws:
IOException
-
getRendersChildren
public boolean getRendersChildren()- Overrides:
getRendersChildren
in classjavax.faces.render.Renderer
-
calculateLabel
Generates a label based on the text if its more than 2 characters. Example: PrimeFaces Rocks = PR- Parameters:
avatar
- the Avatar component- Returns:
- the calculated label text.
-
generateBackgroundColor
Generates a dynamic color based on the hash of the label.- Parameters:
avatar
- to generate the color for- Returns:
- the new color and background color styles
-
generateGravatar
Generate a Gravatar URL for an email addressed based on API docs.- Parameters:
context
- the Faceavatar
- the Avatar to create a Gravatar for- Returns:
- the URL to retrieve the Gravatar image
- See Also:
-
generateMailHash
Converts email address into a hash code for Gravatar API.- Parameters:
sb
- the Stringbuilder to add the email address toemail
- the email to encode- Throws:
NoSuchAlgorithmException
- if hash can't be encoded
-