Search in sources :

Example 1 with WikiEngine

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()));
}
Also used : Locale(java.util.Locale) InternationalizationManager(org.apache.wiki.i18n.InternationalizationManager) TestEngine(org.apache.wiki.TestEngine) Properties(java.util.Properties) WikiEngine(org.apache.wiki.WikiEngine) Test(org.junit.Test)

Example 2 with WikiEngine

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;
}
Also used : WikiContext(org.apache.wiki.WikiContext) WikiPage(org.apache.wiki.WikiPage) WikiEngine(org.apache.wiki.WikiEngine) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 3 with WikiEngine

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Hashtable(java.util.Hashtable) WikiPage(org.apache.wiki.WikiPage) Attachment(org.apache.wiki.attachment.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) WikiEngine(org.apache.wiki.WikiEngine) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 4 with WikiEngine

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();
}
Also used : ResourceBundle(java.util.ResourceBundle) WikiEngine(org.apache.wiki.WikiEngine)

Example 5 with WikiEngine

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;
}
Also used : PluginManager(org.apache.wiki.api.engine.PluginManager) HashMap(java.util.HashMap) ResourceBundle(java.util.ResourceBundle) WikiEngine(org.apache.wiki.WikiEngine) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) InternalWikiException(org.apache.wiki.InternalWikiException) PluginException(org.apache.wiki.api.exceptions.PluginException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

WikiEngine (org.apache.wiki.WikiEngine)67 WikiPage (org.apache.wiki.WikiPage)29 ProviderException (org.apache.wiki.api.exceptions.ProviderException)15 Attachment (org.apache.wiki.attachment.Attachment)10 WikiContext (org.apache.wiki.WikiContext)9 Properties (java.util.Properties)8 JspWriter (javax.servlet.jsp.JspWriter)8 TestEngine (org.apache.wiki.TestEngine)8 Element (org.jdom2.Element)7 IOException (java.io.IOException)5 SimpleDateFormat (java.text.SimpleDateFormat)5 Calendar (java.util.Calendar)5 Date (java.util.Date)5 ResourceBundle (java.util.ResourceBundle)5 PluginException (org.apache.wiki.api.exceptions.PluginException)5 Before (org.junit.Before)5 Principal (java.security.Principal)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 InternalWikiException (org.apache.wiki.InternalWikiException)4 ArrayList (java.util.ArrayList)3