/** * */ package pt.ist.renderers.extensions; import org.apache.commons.beanutils.BeanUtils; import pt.ist.renderers.OutputRenderer; import pt.ist.renderers.components.HtmlComponent; import pt.ist.renderers.components.HtmlInlineContainer; import pt.ist.renderers.components.HtmlLink; import pt.ist.renderers.components.HtmlText; import pt.ist.renderers.layouts.Layout; /** * @author Goncalo Luiz
Created on May 8, 2006, 4:13:15 * PM * */ public class EmailIdentityRenderer extends OutputRenderer { private boolean collapsed = true; private String text; private String address; @Override protected Layout getLayout(Object object, Class type) { return new Layout() { @Override public HtmlComponent createComponent(Object object, Class type) { if (object == null) { return new HtmlText(); } String email = null; String name = null; try { email = BeanUtils.getProperty(object, getAddress()); name = BeanUtils.getProperty(object, getText()); } catch (Exception e) { throw new RuntimeException(e); } HtmlText nameHtml = new HtmlText(name); HtmlLink emailHtml = new HtmlLink(); emailHtml.setContextRelative(false); emailHtml.setUrl("mailto:" + email); if (!isCollapsed()) { emailHtml.setText(email); HtmlInlineContainer container = new HtmlInlineContainer(); container.addChild(nameHtml); container.addChild(new HtmlText(" <", true)); container.addChild(emailHtml); container.addChild(new HtmlText(">", true)); container.setIndented(false); return container; } else { emailHtml.setText(name); return emailHtml; } } }; } public boolean isCollapsed() { return this.collapsed; } /** * * @property */ public void setCollapsed(boolean collapsed) { this.collapsed = collapsed; } /** * @return the address */ public String getAddress() { return this.address; } /** * @param address * the address to set */ public void setAddress(String address) { this.address = address; } /** * @return the text */ public String getText() { return this.text; } /** * @param text * the text to set */ public void setText(String text) { this.text = text; } }