Search in sources :

Example 16 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class AbstractRPCHandler method getRecentChanges.

public Vector getRecentChanges(final Date since) {
    checkPermission(PagePermission.VIEW);
    final Set<Page> pages = m_engine.getManager(PageManager.class).getRecentChanges();
    final Vector<Hashtable<?, ?>> result = new Vector<>();
    // Transform UTC into local time.
    final Calendar cal = Calendar.getInstance();
    cal.setTime(since);
    cal.add(Calendar.MILLISECOND, cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(since) ? cal.get(Calendar.DST_OFFSET) : 0));
    for (final Page page : pages) {
        if (page.getLastModified().after(cal.getTime())) {
            result.add(encodeWikiPage(page));
        }
    }
    return result;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Hashtable(java.util.Hashtable) Calendar(java.util.Calendar) Page(org.apache.wiki.api.core.Page) Vector(java.util.Vector)

Example 17 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class RPCHandler method getAllPages.

public Vector<String> getAllPages() {
    checkPermission(PagePermission.VIEW);
    final Collection<Page> pages = m_engine.getManager(PageManager.class).getRecentChanges();
    final Vector<String> result = new Vector<>();
    for (final Page p : pages) {
        if (!(p instanceof Attachment)) {
            result.add(toRPCString(p.getName()));
        }
    }
    return result;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) Vector(java.util.Vector)

Example 18 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class SaveWikiPageTask method execute.

/**
 * {@inheritDoc}
 */
@Override
public Outcome execute(final Context context) throws WikiException {
    // Retrieve attributes
    final String proposedText = (String) getWorkflowContext().get(WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT);
    final Page page = context.getPage();
    // Let the rest of the engine handle actual saving.
    context.getEngine().getManager(PageManager.class).putPageText(page, proposedText);
    // Refresh the context for post save filtering.
    context.getEngine().getManager(PageManager.class).getPage(page.getName());
    context.getEngine().getManager(RenderingManager.class).textToHTML(context, proposedText);
    context.getEngine().getManager(FilterManager.class).doPostSaveFiltering(context, proposedText);
    // Reindex saved page
    page.setVersion(PageProvider.LATEST_VERSION);
    context.getEngine().getManager(SearchManager.class).reindexPage(page);
    return Outcome.STEP_COMPLETE;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) RenderingManager(org.apache.wiki.render.RenderingManager) SearchManager(org.apache.wiki.search.SearchManager) Page(org.apache.wiki.api.core.Page) FilterManager(org.apache.wiki.filters.FilterManager)

Example 19 with Page

use of org.apache.wiki.api.core.Page in project jspwiki by apache.

the class MetaWeblogHandler method newPost.

/**
 *  Adds a new post to the blog.
 *
 *  @param blogid The id of the blog.
 *  @param username The username to use
 *  @param password The password
 *  @param content As per Metaweblogapi contract
 *  @param publish This parameter is ignored for JSPWiki.
 *  @return Returns an empty string
 *  @throws XmlRpcException If something goes wrong
 */
public String newPost(final String blogid, final String username, final String password, final Hashtable<String, Object> content, final boolean publish) throws XmlRpcException {
    log.info("metaWeblog.newPost() called");
    final Engine engine = m_context.getEngine();
    final Page page = engine.getManager(PageManager.class).getPage(blogid);
    checkPermissions(page, username, password, "createPages");
    try {
        final WeblogEntryPlugin plugin = new WeblogEntryPlugin();
        final String pageName = plugin.getNewEntryPage(engine, blogid);
        final Page entryPage = Wiki.contents().page(engine, pageName);
        entryPage.setAuthor(username);
        final Context context = Wiki.context().create(engine, entryPage);
        final StringBuilder text = new StringBuilder();
        text.append("!").append(content.get("title"));
        text.append("\n\n");
        text.append(content.get("description"));
        log.debug("Writing entry: " + text);
        engine.getManager(PageManager.class).saveText(context, text.toString());
    } catch (final Exception e) {
        log.error("Failed to create weblog entry", e);
        throw new XmlRpcException(0, "Failed to create weblog entry: " + e.getMessage());
    }
    // FIXME:
    return "";
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) WeblogEntryPlugin(org.apache.wiki.plugin.WeblogEntryPlugin) Engine(org.apache.wiki.api.core.Engine) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 20 with Page

use of org.apache.wiki.api.core.Page 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<String, Object> newMediaObject(final String blogid, final String username, final String password, final Hashtable<String, Object> content) throws XmlRpcException {
    final Engine engine = m_context.getEngine();
    final String url;
    log.info("metaWeblog.newMediaObject() called");
    final Page page = engine.getManager(PageManager.class).getPage(blogid);
    checkPermissions(page, username, password, "upload");
    final String name = (String) content.get("name");
    final byte[] data = (byte[]) content.get("bits");
    final AttachmentManager attmgr = engine.getManager(AttachmentManager.class);
    try {
        final Attachment att = Wiki.contents().attachment(engine, blogid, name);
        att.setAuthor(username);
        attmgr.storeAttachment(att, new ByteArrayInputStream(data));
        url = engine.getURL(ContextEnum.PAGE_ATTACH.getRequestContext(), att.getName(), null);
    } catch (final Exception e) {
        log.error("Failed to upload attachment", e);
        throw new XmlRpcException(0, "Failed to upload media object: " + e.getMessage());
    }
    final Hashtable<String, Object> result = new Hashtable<>();
    result.put("url", url);
    return result;
}
Also used : Hashtable(java.util.Hashtable) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) PageManager(org.apache.wiki.pages.PageManager) ByteArrayInputStream(java.io.ByteArrayInputStream) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) Engine(org.apache.wiki.api.core.Engine) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

Page (org.apache.wiki.api.core.Page)181 PageManager (org.apache.wiki.pages.PageManager)106 Test (org.junit.jupiter.api.Test)71 Context (org.apache.wiki.api.core.Context)46 Engine (org.apache.wiki.api.core.Engine)30 Attachment (org.apache.wiki.api.core.Attachment)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)21 WikiPage (org.apache.wiki.WikiPage)18 ReferenceManager (org.apache.wiki.references.ReferenceManager)16 RenderingManager (org.apache.wiki.render.RenderingManager)15 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)14 File (java.io.File)11 ArrayList (java.util.ArrayList)10 Calendar (java.util.Calendar)10 Hashtable (java.util.Hashtable)10 IOException (java.io.IOException)9 Vector (java.util.Vector)9 TestEngine (org.apache.wiki.TestEngine)9 PagePermission (org.apache.wiki.auth.permissions.PagePermission)8