use of org.apache.wiki.api.exceptions.PluginException 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);
}
}
}
use of org.apache.wiki.api.exceptions.PluginException 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);
}
}
}
use of org.apache.wiki.api.exceptions.PluginException in project jspwiki by apache.
the class AbstractReferralPlugin method initialize.
/**
* @param context the wiki context
* @param params parameters for initializing the plugin
* @throws PluginException if any of the plugin parameters are malformed
*/
// FIXME: The compiled pattern strings should really be cached somehow.
public void initialize(WikiContext context, Map<String, String> params) throws PluginException {
m_dateFormat = Preferences.getDateFormat(context, TimeFormat.DATETIME);
m_engine = context.getEngine();
m_maxwidth = TextUtil.parseIntParameter(params.get(PARAM_MAXWIDTH), Integer.MAX_VALUE);
if (m_maxwidth < 0)
m_maxwidth = 0;
String s = params.get(PARAM_SEPARATOR);
if (s != null) {
m_separator = s;
// pre-2.1.145 there was a separator at the end of the list
// if they set the parameters, we use the new format of
// before Item1 after separator before Item2 after separator before Item3 after
m_after = "";
}
s = params.get(PARAM_BEFORE);
if (s != null) {
m_before = s;
}
s = params.get(PARAM_AFTER);
if (s != null) {
m_after = s;
}
s = params.get(PARAM_EXCLUDE);
if (s != null) {
try {
PatternCompiler pc = new GlobCompiler();
String[] ptrns = StringUtils.split(s, ",");
m_exclude = new Pattern[ptrns.length];
for (int i = 0; i < ptrns.length; i++) {
m_exclude[i] = pc.compile(ptrns[i]);
}
} catch (MalformedPatternException e) {
throw new PluginException("Exclude-parameter has a malformed pattern: " + e.getMessage());
}
}
// TODO: Cut-n-paste, refactor
s = params.get(PARAM_INCLUDE);
if (s != null) {
try {
PatternCompiler pc = new GlobCompiler();
String[] ptrns = StringUtils.split(s, ",");
m_include = new Pattern[ptrns.length];
for (int i = 0; i < ptrns.length; i++) {
m_include[i] = pc.compile(ptrns[i]);
}
} catch (MalformedPatternException e) {
throw new PluginException("Include-parameter has a malformed pattern: " + e.getMessage());
}
}
// log.debug( "Requested maximum width is "+m_maxwidth );
s = params.get(PARAM_SHOW);
if (s != null) {
if (s.equalsIgnoreCase("count")) {
m_show = "count";
}
}
s = params.get(PARAM_LASTMODIFIED);
if (s != null) {
if (s.equalsIgnoreCase("true")) {
if (m_show.equals("count")) {
m_lastModified = true;
} else {
throw new PluginException("showLastModified=true is only valid if show=count is also specified");
}
}
}
initSorter(context, params);
}
use of org.apache.wiki.api.exceptions.PluginException in project jspwiki by apache.
the class BugReportHandler method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
String title;
String description;
String version;
String submitter = null;
SimpleDateFormat format = new SimpleDateFormat(DEFAULT_DATEFORMAT);
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
title = params.get(PARAM_TITLE);
description = params.get(PARAM_DESCRIPTION);
version = params.get(PARAM_VERSION);
Principal wup = context.getCurrentUser();
if (wup != null) {
submitter = wup.getName();
}
if (title == null)
throw new PluginException(rb.getString("bugreporthandler.titlerequired"));
if (title.length() == 0)
return "";
if (description == null)
description = "";
if (version == null)
version = "unknown";
Properties mappings = parseMappings(params.get(PARAM_MAPPINGS));
try {
StringWriter str = new StringWriter();
PrintWriter out = new PrintWriter(str);
Date d = new Date();
//
// Outputting of basic data
//
out.println("|" + mappings.getProperty(PARAM_TITLE, "Title") + "|" + title);
out.println("|" + mappings.getProperty("date", "Date") + "|" + format.format(d));
out.println("|" + mappings.getProperty(PARAM_VERSION, "Version") + "|" + version);
if (submitter != null) {
out.println("|" + mappings.getProperty("submitter", "Submitter") + "|" + submitter);
}
//
for (Iterator<Map.Entry<String, String>> i = params.entrySet().iterator(); i.hasNext(); ) {
Map.Entry<String, String> entry = i.next();
if (entry.getKey().equals(PARAM_TITLE) || entry.getKey().equals(PARAM_DESCRIPTION) || entry.getKey().equals(PARAM_VERSION) || entry.getKey().equals(PARAM_MAPPINGS) || entry.getKey().equals(PARAM_PAGE) || entry.getKey().startsWith("_")) {
// Ignore this
} else {
//
// If no mapping has been defined, just ignore
// it.
//
String head = mappings.getProperty(entry.getKey(), entry.getKey());
if (head.length() > 0) {
out.println("|" + head + "|" + entry.getValue());
}
}
}
out.println();
out.println(description);
out.close();
//
// Now create a new page for this bug report
//
String pageName = findNextPage(context, title, params.get(PARAM_PAGE));
WikiPage newPage = new WikiPage(context.getEngine(), pageName);
WikiContext newContext = (WikiContext) context.clone();
newContext.setPage(newPage);
context.getEngine().saveText(newContext, str.toString());
MessageFormat formatter = new MessageFormat("");
formatter.applyPattern(rb.getString("bugreporthandler.new"));
String[] args = { "<a href=\"" + context.getViewURL(pageName) + "\">" + pageName + "</a>" };
return formatter.format(args);
} catch (RedirectException e) {
log.info("Saving not allowed, reason: '" + e.getMessage() + "', can't redirect to " + e.getRedirect());
throw new PluginException("Saving not allowed, reason: " + e.getMessage());
} catch (WikiException e) {
log.error("Unable to save page!", e);
return rb.getString("bugreporthandler.unable");
}
}
use of org.apache.wiki.api.exceptions.PluginException in project jspwiki by apache.
the class ReferredPagesPlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
m_engine = context.getEngine();
WikiPage page = context.getPage();
if (page == null)
return "";
// parse parameters
String rootname = params.get(PARAM_ROOT);
if (rootname == null)
rootname = page.getName();
String format = params.get(PARAM_FORMAT);
if (format == null)
format = "";
if (format.indexOf("full") >= 0)
m_formatCompact = false;
if (format.indexOf("sort") >= 0)
m_formatSort = true;
m_depth = TextUtil.parseIntParameter(params.get(PARAM_DEPTH), MIN_DEPTH);
if (m_depth > MAX_DEPTH)
m_depth = MAX_DEPTH;
String includePattern = params.get(PARAM_INCLUDE);
if (includePattern == null)
includePattern = ".*";
String excludePattern = params.get(PARAM_EXCLUDE);
if (excludePattern == null)
excludePattern = "^$";
log.debug("Fetching referred pages for " + rootname + " with a depth of " + m_depth + " with include pattern of " + includePattern + " with exclude pattern of " + excludePattern);
//
// do the actual work
//
String href = context.getViewURL(rootname);
String title = "ReferredPagesPlugin: depth[" + m_depth + "] include[" + includePattern + "] exclude[" + excludePattern + "] format[" + (m_formatCompact ? "compact" : "full") + (m_formatSort ? " sort" : "") + "]";
m_result.append("<div class=\"ReferredPagesPlugin\">\n");
m_result.append("<a class=\"wikipage\" href=\"" + href + "\" title=\"" + title + "\">" + rootname + "</a>\n");
m_exists.add(rootname);
// pre compile all needed patterns
// glob compiler : * is 0..n instance of any char -- more convenient as input
// perl5 compiler : .* is 0..n instances of any char -- more powerful
// PatternCompiler g_compiler = new GlobCompiler();
PatternCompiler compiler = new Perl5Compiler();
try {
m_includePattern = compiler.compile(includePattern);
m_excludePattern = compiler.compile(excludePattern);
} catch (MalformedPatternException e) {
if (m_includePattern == null) {
throw new PluginException("Illegal include pattern detected.");
} else if (m_excludePattern == null) {
throw new PluginException("Illegal exclude pattern detected.");
} else {
throw new PluginException("Illegal internal pattern detected.");
}
}
// go get all referred links
getReferredPages(context, rootname, 0);
// close and finish
m_result.append("</div>\n");
return m_result.toString();
}
Aggregations