use of org.xwiki.rendering.listener.WrappingListener in project xwiki-platform by xwiki.
the class LinkLabelGeneratorChainingListener method endLink.
/**
* {@inheritDoc}
*
* @see org.xwiki.rendering.listener.chaining.AbstractChainingListener#endLink(
* org.xwiki.rendering.listener.reference.ResourceReference , boolean, java.util.Map)
* @since 2.5RC1
*/
@Override
public void endLink(ResourceReference reference, boolean freestanding, Map<String, String> parameters) {
// behaviour
if (getEmptyBlockState().isCurrentContainerBlockEmpty()) {
// get the link label
// FIXME: this should be generated by the link label generator, for all cases, so that the
// link label can be changed with whichever generator, that can handle all cases
String linkLabel = reference.getReference();
ResourceType resourceType = reference.getType();
if (ResourceType.DOCUMENT.equals(resourceType) || ResourceType.SPACE.equals(resourceType)) {
linkLabel = linkLabelGenerator.generate(reference);
}
// create the span around the label signaling that this is a generated label
Map<String, String> formatParams = new HashMap<String, String>();
formatParams.put("class", "wikigeneratedlinkcontent");
// the same as this.format. TODO: decide which one is more semantic.
super.beginFormat(Format.NONE, formatParams);
// parse the linkLabel with a stream parser and an inline filter
WrappingListener inlineFilterListener = new InlineFilterListener();
inlineFilterListener.setWrappedListener(getListenerChain().getNextListener(getClass()));
try {
linkLabelParser.parse(new StringReader(linkLabel), inlineFilterListener);
} catch (ParseException e) {
// couldn't parse it, send it raw (interesting)
super.onRawText(linkLabel, linkLabelParser.getSyntax());
}
super.endFormat(Format.NONE, formatParams);
}
// end the link
super.endLink(reference, freestanding, parameters);
}
Aggregations