Search in sources :

Example 1 with Plugin

use of org.apache.wiki.api.plugin.Plugin in project jspwiki by apache.

the class PluginContent method executeParse.

/**
 *{@inheritDoc}
 */
@Override
public void executeParse(final Context context) throws PluginException {
    final PluginManager pm = context.getEngine().getManager(PluginManager.class);
    if (pm.pluginsEnabled()) {
        final ResourceBundle rb = Preferences.getBundle(context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE);
        final Map<String, String> params = getParameters();
        final Plugin plugin = pm.newWikiPlugin(getPluginName(), rb);
        try {
            if (plugin instanceof ParserStagePlugin) {
                ((ParserStagePlugin) plugin).executeParser(this, context, params);
            }
        } catch (final ClassCastException e) {
            throw new PluginException(MessageFormat.format(rb.getString("plugin.error.notawikiplugin"), getPluginName()), e);
        }
    }
}
Also used : PluginManager(org.apache.wiki.plugin.PluginManager) ParserStagePlugin(org.apache.wiki.api.plugin.ParserStagePlugin) PluginException(org.apache.wiki.api.exceptions.PluginException) ResourceBundle(java.util.ResourceBundle) ParserStagePlugin(org.apache.wiki.api.plugin.ParserStagePlugin) Plugin(org.apache.wiki.api.plugin.Plugin)

Example 2 with Plugin

use of org.apache.wiki.api.plugin.Plugin in project jspwiki by apache.

the class DefaultPluginManager method newWikiPlugin.

/**
 * Creates a {@link Plugin}.
 *
 * @param pluginName plugin's classname
 * @param rb {@link ResourceBundle} with i18ned text for exceptions.
 * @return a {@link Plugin}.
 * @throws PluginException if there is a problem building the {@link Plugin}.
 */
@Override
public Plugin newWikiPlugin(final String pluginName, final ResourceBundle rb) throws PluginException {
    Plugin plugin = null;
    WikiPluginInfo pluginInfo = m_pluginClassMap.get(pluginName);
    try {
        if (pluginInfo == null) {
            pluginInfo = WikiPluginInfo.newInstance(findPluginClass(pluginName));
            registerPlugin(pluginInfo);
        }
        if (!checkCompatibility(pluginInfo)) {
            final String msg = "Plugin '" + pluginInfo.getName() + "' not compatible with this version of JSPWiki";
            log.info(msg);
        } else {
            plugin = pluginInfo.newPluginInstance(m_searchPath, m_externalJars);
        }
    } catch (final ClassNotFoundException e) {
        throw new PluginException(MessageFormat.format(rb.getString("plugin.error.couldnotfind"), pluginName), e);
    } catch (final InstantiationException e) {
        throw new PluginException(MessageFormat.format(rb.getString("plugin.error.cannotinstantiate"), pluginName), e);
    } catch (final IllegalAccessException e) {
        throw new PluginException(MessageFormat.format(rb.getString("plugin.error.notallowed"), pluginName), e);
    } catch (final Exception e) {
        throw new PluginException(MessageFormat.format(rb.getString("plugin.error.instantationfailed"), pluginName), e);
    }
    return plugin;
}
Also used : PluginException(org.apache.wiki.api.exceptions.PluginException) PluginException(org.apache.wiki.api.exceptions.PluginException) NoSuchElementException(java.util.NoSuchElementException) MalformedPatternException(org.apache.oro.text.regex.MalformedPatternException) InternalWikiException(org.apache.wiki.InternalWikiException) IOException(java.io.IOException) Plugin(org.apache.wiki.api.plugin.Plugin) InitializablePlugin(org.apache.wiki.api.plugin.InitializablePlugin)

Example 3 with Plugin

use of org.apache.wiki.api.plugin.Plugin in project jspwiki by apache.

the class DefaultPluginManager method execute.

/**
 * {@inheritDoc}
 */
@Override
public String execute(final Context context, final String classname, final Map<String, String> params) throws PluginException {
    if (!m_pluginsEnabled) {
        return "";
    }
    final ResourceBundle rb = Preferences.getBundle(context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE);
    final boolean debug = TextUtil.isPositive(params.get(PARAM_DEBUG));
    try {
        // Create...
        final Plugin plugin = newWikiPlugin(classname, rb);
        if (plugin == null) {
            return "Plugin '" + classname + "' not compatible with this version of JSPWiki";
        }
        // ...and launch.
        try {
            return plugin.execute(context, params);
        } catch (final PluginException e) {
            if (debug) {
                return stackTrace(params, e);
            }
            // Just pass this exception onward.
            throw (PluginException) e.fillInStackTrace();
        } catch (final Throwable t) {
            // But all others get captured here.
            log.info("Plugin failed while executing:", t);
            if (debug) {
                return stackTrace(params, t);
            }
            throw new PluginException(rb.getString("plugin.error.failed"), t);
        }
    } catch (final ClassCastException e) {
        throw new PluginException(MessageFormat.format(rb.getString("plugin.error.notawikiplugin"), classname), e);
    }
}
Also used : PluginException(org.apache.wiki.api.exceptions.PluginException) ResourceBundle(java.util.ResourceBundle) Plugin(org.apache.wiki.api.plugin.Plugin) InitializablePlugin(org.apache.wiki.api.plugin.InitializablePlugin)

Aggregations

PluginException (org.apache.wiki.api.exceptions.PluginException)3 Plugin (org.apache.wiki.api.plugin.Plugin)3 ResourceBundle (java.util.ResourceBundle)2 InitializablePlugin (org.apache.wiki.api.plugin.InitializablePlugin)2 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)1 InternalWikiException (org.apache.wiki.InternalWikiException)1 ParserStagePlugin (org.apache.wiki.api.plugin.ParserStagePlugin)1 PluginManager (org.apache.wiki.plugin.PluginManager)1