use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class CachingProvider method refreshMetadata.
//
// FIXME: Kludge: make sure that the page is also parsed and it gets all the
// necessary variables.
//
private void refreshMetadata(WikiPage page) {
if (page != null && !page.hasMetadata()) {
RenderingManager mgr = m_engine.getRenderingManager();
try {
String data = m_provider.getPageText(page.getName(), page.getVersion());
WikiContext ctx = new WikiContext(m_engine, page);
MarkupParser parser = mgr.getParser(ctx, data);
parser.parse();
} catch (Exception ex) {
log.debug("Failed to retrieve variables for wikipage " + page);
}
}
}
use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class PluginContent method getText.
/**
* The main invocation for the plugin. When the getText() is called, it
* invokes the plugin and returns its contents. If there is no Document
* yet, only returns the plugin name itself.
*
* @return The plugin rendered according to the options set in the WikiContext.
*/
public String getText() {
WikiDocument doc = (WikiDocument) getDocument();
if (doc == null) {
return getPluginName();
}
WikiContext context = doc.getContext();
if (context == null) {
log.info("WikiContext garbage-collected, cannot proceed");
return getPluginName();
}
return invoke(context);
}
use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class VariableContent method getValue.
/**
* Evaluates the variable and returns the contents.
*
* @return The rendered value of the variable.
*/
public String getValue() {
String result = "";
WikiDocument root = (WikiDocument) getDocument();
if (root == null) {
// See similar note in PluginContent
return m_varName;
}
WikiContext context = root.getContext();
if (context == null)
return "No WikiContext available: INTERNAL ERROR";
Boolean wysiwygEditorMode = (Boolean) context.getVariable(RenderingManager.WYSIWYG_EDITOR_MODE);
if (wysiwygEditorMode != null && wysiwygEditorMode.booleanValue()) {
result = "[" + m_varName + "]";
} else {
try {
result = context.getEngine().getVariableManager().parseAndGetValue(context, m_varName);
} catch (NoSuchVariableException e) {
result = MarkupParser.makeError("No such variable: " + e.getMessage()).getText();
}
}
return StringEscapeUtils.escapeXml(result);
}
use of org.apache.wiki.WikiContext 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.WikiContext in project jspwiki by apache.
the class JSPWikiMarkupParser method getCleanTranslator.
/**
* Does a lazy init. Otherwise, we would get into a situation
* where HTMLRenderer would try and boot a TranslatorReader before
* the TranslatorReader it is contained by is up.
*/
private JSPWikiMarkupParser getCleanTranslator() {
if (m_cleanTranslator == null) {
WikiContext dummyContext = new WikiContext(m_engine, m_context.getHttpRequest(), m_context.getPage());
m_cleanTranslator = new JSPWikiMarkupParser(dummyContext, null);
m_cleanTranslator.m_allowHTML = true;
}
return m_cleanTranslator;
}
Aggregations