Search in sources :

Example 1 with WrappingListener

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);
}
Also used : InlineFilterListener(org.xwiki.rendering.listener.InlineFilterListener) HashMap(java.util.HashMap) WrappingListener(org.xwiki.rendering.listener.WrappingListener) StringReader(java.io.StringReader) ResourceType(org.xwiki.rendering.listener.reference.ResourceType) ParseException(org.xwiki.rendering.parser.ParseException)

Aggregations

StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 InlineFilterListener (org.xwiki.rendering.listener.InlineFilterListener)1 WrappingListener (org.xwiki.rendering.listener.WrappingListener)1 ResourceType (org.xwiki.rendering.listener.reference.ResourceType)1 ParseException (org.xwiki.rendering.parser.ParseException)1