Search in sources :

Example 1 with WikiPlugin

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

the class PluginContent method executeParse.

/**
 * Executes the executeParse() method.
 *
 * @param context The WikiContext
 * @throws PluginException If something goes wrong.
 */
public void executeParse(WikiContext context) throws PluginException {
    PluginManager pm = context.getEngine().getPluginManager();
    if (pm.pluginsEnabled()) {
        ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
        Map<String, String> params = getParameters();
        WikiPlugin plugin = pm.newWikiPlugin(getPluginName(), rb);
        try {
            if (plugin != null && plugin instanceof ParserStagePlugin) {
                ((ParserStagePlugin) plugin).executeParser(this, context, params);
            }
        } catch (ClassCastException e) {
            throw new PluginException(MessageFormat.format(rb.getString("plugin.error.notawikiplugin"), getPluginName()), e);
        }
    }
}
Also used : PluginManager(org.apache.wiki.api.engine.PluginManager) ParserStagePlugin(org.apache.wiki.api.plugin.ParserStagePlugin) PluginException(org.apache.wiki.api.exceptions.PluginException) ResourceBundle(java.util.ResourceBundle) WikiPlugin(org.apache.wiki.api.plugin.WikiPlugin)

Example 2 with WikiPlugin

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

the class DefaultPluginManager method execute.

/**
 *  Executes a plugin class in the given context.
 *  <P>Used to be private, but is public since 1.9.21.
 *
 *  @param context The current WikiContext.
 *  @param classname The name of the class.  Can also be a
 *  shortened version without the package name, since the class name is searched from the
 *  package search path.
 *
 *  @param params A parsed map of key-value pairs.
 *
 *  @return Whatever the plugin returns.
 *
 *  @throws PluginException If the plugin execution failed for
 *  some reason.
 *
 *  @since 2.0
 */
public String execute(WikiContext context, String classname, Map<String, String> params) throws PluginException {
    if (!m_pluginsEnabled) {
        return "";
    }
    ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
    boolean debug = TextUtil.isPositive(params.get(PARAM_DEBUG));
    try {
        // 
        // Create...
        // 
        WikiPlugin plugin = newWikiPlugin(classname, rb);
        if (plugin == null) {
            return "Plugin '" + classname + "' not compatible with this version of JSPWiki";
        }
        // 
        try {
            return plugin.execute(context, params);
        } catch (PluginException e) {
            if (debug) {
                return stackTrace(params, e);
            }
            // Just pass this exception onward.
            throw (PluginException) e.fillInStackTrace();
        } catch (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 (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) WikiPlugin(org.apache.wiki.api.plugin.WikiPlugin)

Example 3 with WikiPlugin

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

the class DefaultPluginManager method newWikiPlugin.

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

Aggregations

PluginException (org.apache.wiki.api.exceptions.PluginException)3 WikiPlugin (org.apache.wiki.api.plugin.WikiPlugin)3 ResourceBundle (java.util.ResourceBundle)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 PluginManager (org.apache.wiki.api.engine.PluginManager)1 ParserStagePlugin (org.apache.wiki.api.plugin.ParserStagePlugin)1