Search in sources :

Example 1 with HtmlInline

use of com.vladsch.flexmark.ast.HtmlInline in project jspwiki by apache.

the class LocalLinkNodePostProcessorState method process.

/**
 * {@inheritDoc}
 *
 * @see NodePostProcessorState#process(NodeTracker, JSPWikiLink)
 */
@Override
public void process(final NodeTracker state, final JSPWikiLink link) {
    final int hashMark = link.getUrl().toString().indexOf('#');
    final String attachment = wikiContext.getEngine().getAttachmentManager().getAttachmentInfoName(wikiContext, link.getUrl().toString());
    if (attachment != null) {
        if (!linkOperations.isImageLink(link.getUrl().toString())) {
            final String attlink = wikiContext.getURL(WikiContext.ATTACH, link.getUrl().toString());
            link.setUrl(CharSubSequence.of(attlink));
            link.removeChildren();
            final HtmlInline content = new HtmlInline(CharSubSequence.of(link.getText().toString()));
            link.appendChild(content);
            state.nodeAddedWithChildren(content);
            addAttachmentLink(state, link);
        } else {
            new ImageLinkNodePostProcessorState(wikiContext, attachment, link.hasRef()).process(state, link);
        }
    } else if (hashMark != -1) {
        // It's an internal Wiki link, but to a named section
        final String namedSection = link.getUrl().toString().substring(hashMark + 1);
        link.setUrl(CharSubSequence.of(link.getUrl().toString().substring(0, hashMark)));
        final String matchedLink = linkOperations.linkIfExists(link.getUrl().toString());
        if (matchedLink != null) {
            String sectref = "#section-" + wikiContext.getEngine().encodeName(matchedLink + "-" + MarkupParser.wikifyLink(namedSection));
            sectref = sectref.replace('%', '_');
            link.setUrl(CharSubSequence.of(wikiContext.getURL(WikiContext.VIEW, link.getUrl().toString() + sectref)));
        } else {
            link.setUrl(CharSubSequence.of(wikiContext.getURL(WikiContext.EDIT, link.getUrl().toString())));
        }
    } else {
        if (linkOperations.linkExists(link.getUrl().toString())) {
            link.setUrl(CharSubSequence.of(wikiContext.getURL(WikiContext.VIEW, link.getUrl().toString())));
        } else {
            link.setUrl(CharSubSequence.of(wikiContext.getURL(WikiContext.EDIT, link.getUrl().toString())));
        }
    }
}
Also used : HtmlInline(com.vladsch.flexmark.ast.HtmlInline)

Example 2 with HtmlInline

use of com.vladsch.flexmark.ast.HtmlInline in project jspwiki by apache.

the class NodePostProcessorStateCommonOperations method addOutlinkImage.

static void addOutlinkImage(final NodeTracker state, final Node node, final WikiContext wikiContext, final boolean useOutlinkImage) {
    final Boolean wysiwygVariable = (Boolean) wikiContext.getVariable(RenderingManager.WYSIWYG_EDITOR_MODE);
    boolean wysiwygEditorMode = wysiwygVariable != null ? wysiwygVariable.booleanValue() : false;
    if (useOutlinkImage && !wysiwygEditorMode) {
        final String m_outlinkImageURL = wikiContext.getURL(WikiContext.NONE, MarkupParser.OUTLINK_IMAGE);
        final HtmlInline img = new HtmlInline(CharSubSequence.of("<img class=\"" + MarkupParser.OUTLINK + "\" " + "alt=\"\" src=\"" + m_outlinkImageURL + "\" />"));
        node.insertAfter(img);
        state.nodeAdded(img);
    }
}
Also used : HtmlInline(com.vladsch.flexmark.ast.HtmlInline)

Example 3 with HtmlInline

use of com.vladsch.flexmark.ast.HtmlInline in project jspwiki by apache.

the class PluginLinkNodePostProcessorState method process.

/**
 * {@inheritDoc}
 *
 * @see NodePostProcessorState#process(NodeTracker, JSPWikiLink)
 */
@Override
public void process(final NodeTracker state, final JSPWikiLink link) {
    if (link.getText().toString().startsWith("{TableOfContents")) {
        handleTableOfContentsPlugin(state, link);
        return;
    }
    PluginContent pluginContent = null;
    try {
        // -1 == do not generate _bounds parameter
        pluginContent = PluginContent.parsePluginLine(wikiContext, link.getUrl().toString(), -1);
        // 
        if (pluginContent != null) {
            final String pluginInvocation = pluginInvocation(link.getText().toString(), pluginContent);
            final HtmlInline content = new HtmlInline(CharSubSequence.of(pluginInvocation));
            pluginContent.executeParse(wikiContext);
            NodePostProcessorStateCommonOperations.addContent(state, link, content);
        }
    } catch (final PluginException e) {
        LOG.info(wikiContext.getRealPage().getWiki() + " : " + wikiContext.getRealPage().getName() + " - Failed to insert plugin: " + e.getMessage());
        if (!m_wysiwygEditorMode) {
            final ResourceBundle rbPlugin = Preferences.getBundle(wikiContext, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
            NodePostProcessorStateCommonOperations.makeError(state, link, MessageFormat.format(rbPlugin.getString("plugin.error.insertionfailed"), wikiContext.getRealPage().getWiki(), wikiContext.getRealPage().getName(), e.getMessage()));
        }
    } finally {
        if (pluginContent != null) {
            removeLink(state, link);
        }
    }
}
Also used : PluginException(org.apache.wiki.api.exceptions.PluginException) HtmlInline(com.vladsch.flexmark.ast.HtmlInline) ResourceBundle(java.util.ResourceBundle) PluginContent(org.apache.wiki.parser.PluginContent)

Example 4 with HtmlInline

use of com.vladsch.flexmark.ast.HtmlInline in project jspwiki by apache.

the class VariableLinkNodePostProcessorState method process.

/**
 * {@inheritDoc}
 *
 * @see NodePostProcessorState#process(NodeTracker, JSPWikiLink)
 */
@Override
public void process(final NodeTracker state, final JSPWikiLink link) {
    final String variable = NodePostProcessorStateCommonOperations.inlineLinkTextOnWysiwyg(state, link, m_wysiwygEditorMode);
    if (!m_wysiwygEditorMode) {
        try {
            final String parsedVariable = wikiContext.getEngine().getVariableManager().parseAndGetValue(wikiContext, variable);
            final HtmlInline content = new HtmlInline(CharSubSequence.of(StringEscapeUtils.escapeXml(parsedVariable)));
            NodePostProcessorStateCommonOperations.addContent(state, link, content);
        } catch (final NoSuchVariableException e) {
            NodePostProcessorStateCommonOperations.makeError(state, link, "No such variable: " + variable + " (" + e.getMessage() + ")");
        }
    }
}
Also used : NoSuchVariableException(org.apache.wiki.api.exceptions.NoSuchVariableException) HtmlInline(com.vladsch.flexmark.ast.HtmlInline)

Example 5 with HtmlInline

use of com.vladsch.flexmark.ast.HtmlInline in project jspwiki by apache.

the class LocalLinkNodePostProcessorState method addAttachmentLink.

void addAttachmentLink(final NodeTracker state, final JSPWikiLink link) {
    final String infolink = wikiContext.getURL(WikiContext.INFO, link.getWikiLink());
    final String imglink = wikiContext.getURL(WikiContext.NONE, "images/attachment_small.png");
    final HtmlInline aimg = new HtmlInline(CharSubSequence.of("<a href=\"" + infolink + "\" class=\"infolink\">" + "<img src=\"" + imglink + "\" border=\"0\" alt=\"(info)\" />" + "</a>"));
    link.insertAfter(aimg);
    state.nodeAdded(aimg);
}
Also used : HtmlInline(com.vladsch.flexmark.ast.HtmlInline)

Aggregations

HtmlInline (com.vladsch.flexmark.ast.HtmlInline)9 ResourceBundle (java.util.ResourceBundle)2 TocBlock (com.vladsch.flexmark.ext.toc.TocBlock)1 NoSuchVariableException (org.apache.wiki.api.exceptions.NoSuchVariableException)1 PluginException (org.apache.wiki.api.exceptions.PluginException)1 PluginContent (org.apache.wiki.parser.PluginContent)1