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);
}
}
}
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;
}
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);
}
}
Aggregations