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;
}
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;
}
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;
}
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 "";
}
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;
}
Aggregations