Search in sources :

Example 1 with PluginContent

use of org.apache.wiki.parser.PluginContent 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 2 with PluginContent

use of org.apache.wiki.parser.PluginContent in project jspwiki by apache.

the class CreoleRenderer method renderElement.

/**
 * Renders an element into the StringBuilder given
 * @param ce
 * @param sb
 */
private void renderElement(Element ce, StringBuilder sb) {
    String endEl = EMPTY_STRING;
    for (int i = 0; i < ELEMENTS.length; i += 3) {
        if (ELEMENTS[i].equals(ce.getName())) {
            sb.append(ELEMENTS[i + 1]);
            endEl = ELEMENTS[i + 2];
        }
    }
    if (UL.equals(ce.getName())) {
        m_listCount++;
        m_listChar = '*';
    } else if (OL.equals(ce.getName())) {
        m_listCount++;
        m_listChar = '#';
    } else if (LI.equals(ce.getName())) {
        for (int i = 0; i < m_listCount; i++) sb.append(m_listChar);
        sb.append(ONE_SPACE);
    } else if (A.equals(ce.getName())) {
        String href = ce.getAttributeValue(HREF_ATTRIBUTE);
        String text = ce.getText();
        if (href.equals(text)) {
            sb.append(HREF_START + href + HREF_END);
        } else {
            sb.append(HREF_START + href + HREF_DELIMITER + text + HREF_END);
        }
        // Do not render anything else
        return;
    } else if (PRE.equals(ce.getName())) {
        sb.append(PRE_START);
        sb.append(ce.getText());
        sb.append(PRE_END);
        return;
    }
    // 
    for (Iterator<Content> i = ce.getContent().iterator(); i.hasNext(); ) {
        Content c = i.next();
        if (c instanceof PluginContent) {
            PluginContent pc = (PluginContent) c;
            if (pc.getPluginName().equals(PLUGIN_IMAGE)) {
                sb.append(IMG_START + pc.getParameter(PARAM_SRC) + IMG_END);
            } else {
                m_plugins.add(pc);
                sb.append(PLUGIN_START + pc.getPluginName() + ONE_SPACE + m_plugins.size() + PLUGIN_END);
            }
        } else if (c instanceof Text) {
            sb.append(((Text) c).getText());
        } else if (c instanceof Element) {
            renderElement((Element) c, sb);
        }
    }
    if (UL.equals(ce.getName()) || OL.equals(ce.getName())) {
        m_listCount--;
    } else if (P.equals(ce.getName())) {
        sb.append(LINEBREAK);
    }
    sb.append(endEl);
}
Also used : PluginContent(org.apache.wiki.parser.PluginContent) Content(org.jdom2.Content) Element(org.jdom2.Element) Text(org.jdom2.Text) PluginContent(org.apache.wiki.parser.PluginContent)

Aggregations

PluginContent (org.apache.wiki.parser.PluginContent)2 HtmlInline (com.vladsch.flexmark.ast.HtmlInline)1 ResourceBundle (java.util.ResourceBundle)1 PluginException (org.apache.wiki.api.exceptions.PluginException)1 Content (org.jdom2.Content)1 Element (org.jdom2.Element)1 Text (org.jdom2.Text)1