use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class OutcomeTest method testMessage.
@Test
public void testMessage() throws Exception {
Properties props = TestEngine.getTestProperties();
WikiEngine engine = new TestEngine(props);
InternationalizationManager i18n = engine.getInternationalizationManager();
String core = "templates.default";
Locale rootLocale = Locale.ROOT;
Outcome o;
o = Outcome.DECISION_APPROVE;
Assert.assertEquals("Approve", i18n.get(core, rootLocale, o.getMessageKey()));
o = Outcome.DECISION_DENY;
Assert.assertEquals("Deny", i18n.get(core, rootLocale, o.getMessageKey()));
o = Outcome.DECISION_HOLD;
Assert.assertEquals("Hold", i18n.get(core, rootLocale, o.getMessageKey()));
o = Outcome.DECISION_REASSIGN;
Assert.assertEquals("Reassign", i18n.get(core, rootLocale, o.getMessageKey()));
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class MetaWeblogHandler method editPost.
/**
* Allows the user to edit a post. It does not allow general
* editability of wiki pages, because of the limitations of the
* metaWeblog API.
*/
boolean editPost(String postid, String username, String password, Hashtable content, boolean publish) throws XmlRpcException {
WikiEngine engine = m_context.getEngine();
log.info("metaWeblog.editPost(" + postid + ") called");
// FIXME: Is postid correct? Should we determine it from the page name?
WikiPage page = engine.getPage(postid);
checkPermissions(page, username, password, "edit");
try {
WikiPage entryPage = (WikiPage) page.clone();
entryPage.setAuthor(username);
WikiContext context = new WikiContext(engine, entryPage);
StringBuilder text = new StringBuilder();
text.append("!" + content.get("title"));
text.append("\n\n");
text.append(content.get("description"));
log.debug("Updating entry: " + text);
engine.saveText(context, text.toString());
} catch (Exception e) {
log.error("Failed to create weblog entry", e);
throw new XmlRpcException(0, "Failed to update weblog entry: " + e.getMessage());
}
return true;
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class MetaWeblogHandler method newMediaObject.
/**
* Creates an attachment and adds it to the blog. The attachment
* is created into the main blog page, not the actual post page,
* because we do not know it at this point.
*
* @param blogid The id of the blog.
* @param username The username to use
* @param password The password
* @param content As per the MetaweblogAPI contract
* @return As per the MetaweblogAPI contract
* @throws XmlRpcException If something goes wrong
*/
public Hashtable newMediaObject(String blogid, String username, String password, Hashtable content) throws XmlRpcException {
WikiEngine engine = m_context.getEngine();
String url = "";
log.info("metaWeblog.newMediaObject() called");
WikiPage page = engine.getPage(blogid);
checkPermissions(page, username, password, "upload");
String name = (String) content.get("name");
byte[] data = (byte[]) content.get("bits");
AttachmentManager attmgr = engine.getAttachmentManager();
try {
Attachment att = new Attachment(engine, blogid, name);
att.setAuthor(username);
attmgr.storeAttachment(att, new ByteArrayInputStream(data));
url = engine.getURL(WikiContext.ATTACH, att.getName(), null, true);
} catch (Exception e) {
log.error("Failed to upload attachment", e);
throw new XmlRpcException(0, "Failed to upload media object: " + e.getMessage());
}
Hashtable<String, Object> result = new Hashtable<String, Object>();
result.put("url", url);
return result;
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class WeblogEntryPlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
String weblogName = params.get(PARAM_BLOGNAME);
if (weblogName == null) {
weblogName = context.getPage().getName();
}
WikiEngine engine = context.getEngine();
StringBuilder sb = new StringBuilder();
String entryText = params.get(PARAM_ENTRYTEXT);
if (entryText == null) {
entryText = rb.getString("weblogentryplugin.newentry");
}
String url = context.getURL(WikiContext.NONE, "NewBlogEntry.jsp", "page=" + engine.encodeName(weblogName));
sb.append("<a href=\"" + url + "\">" + entryText + "</a>");
return sb.toString();
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class PluginContent method invoke.
/**
* Performs plugin invocation and return its contents.
*
* @param context WikiContext in which the plugin is executed. Must NOT be null.
* @return plugin contents.
*/
public String invoke(WikiContext context) {
String result;
Boolean wysiwygVariable = (Boolean) context.getVariable(RenderingManager.WYSIWYG_EDITOR_MODE);
boolean wysiwygEditorMode = false;
if (wysiwygVariable != null) {
wysiwygEditorMode = wysiwygVariable.booleanValue();
}
try {
// FIXME: The plugin name matching should not be done here, but in a per-editor resource
if (wysiwygEditorMode && !m_pluginName.matches(EMITTABLE_PLUGINS)) {
result = PLUGIN_START + m_pluginName + SPACE;
// convert newlines to <br> in case the plugin has a body.
String cmdLine = (m_params.get(CMDLINE)).replaceAll(LINEBREAK, ELEMENT_BR);
result = result + cmdLine + PLUGIN_END;
} else {
Boolean b = (Boolean) context.getVariable(RenderingManager.VAR_EXECUTE_PLUGINS);
if (b != null && !b.booleanValue()) {
return BLANK;
}
WikiEngine engine = context.getEngine();
Map<String, String> parsedParams = new HashMap<String, String>();
//
for (Map.Entry<String, String> e : m_params.entrySet()) {
String val = e.getValue();
val = engine.getVariableManager().expandVariables(context, val);
parsedParams.put(e.getKey(), val);
}
PluginManager pm = engine.getPluginManager();
result = pm.execute(context, m_pluginName, parsedParams);
}
} catch (Exception e) {
if (wysiwygEditorMode) {
result = "";
} else {
// log.info("Failed to execute plugin",e);
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
result = MarkupParser.makeError(MessageFormat.format(rb.getString("plugin.error.insertionfailed"), context.getRealPage().getWiki(), context.getRealPage().getName(), e.getMessage())).getText();
}
}
return result;
}
Aggregations