public static final ILinkRenderer SHARED_INSTANCE = new DefaultLinkRenderer();
public void renderLink(IMarkupWriter writer, IRequestCycle cycle, ILinkComponent linkComponent)
{
IMarkupWriter wrappedWriter = null;
if (cycle.getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME) != null)
throw new ApplicationRuntimeException(Tapestry
.getMessage("AbstractLinkComponent.no-nesting"), linkComponent, null, null);
cycle.setAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME, linkComponent);
boolean hasBody = getHasBody();
boolean disabled = linkComponent.isDisabled();
if (!disabled)
{
ILink l = linkComponent.getLink(cycle);
if (hasBody)
writer.begin(getElement());
else
writer.beginEmpty(getElement());
writer.attribute(getUrlAttribute(), constructURL(l, linkComponent.getAnchor(), cycle));
String target = linkComponent.getTarget();
if (HiveMind.isNonBlank(target))
writer.attribute(getTargetAttribute(), target);
beforeBodyRender(writer, cycle, linkComponent);
// Allow the wrapped components a chance to render.
// Along the way, they may interact with this component
// and cause the name variable to get set.
wrappedWriter = writer.getNestedWriter();
}
else
wrappedWriter = writer;
if (hasBody)
linkComponent.renderBody(wrappedWriter, cycle);
if (!disabled)
{
afterBodyRender(writer, cycle, linkComponent);
linkComponent.renderAdditionalAttributes(writer, cycle);
if (hasBody)
{
wrappedWriter.close();
// Close the <element> tag
writer.end();
}