use of org.apache.wiki.api.core.Context 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) {
final Context dummyContext = Wiki.context().create(m_engine, m_context.getHttpRequest(), m_context.getPage());
m_cleanTranslator = new JSPWikiMarkupParser(dummyContext, null);
m_cleanTranslator.m_allowHTML = true;
}
return m_cleanTranslator;
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class RPCServlet method doPost.
/**
* Handle HTTP POST. This is an XML-RPC call, and we'll just forward the query to an XmlRpcServer.
*/
@Override
public void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException {
log.debug("Received POST to RPCServlet");
try {
final Context ctx = Wiki.context().create(m_engine, request, ContextEnum.PAGE_NONE.getRequestContext());
final XmlRpcContext xmlrpcContext = new WikiXmlRpcContext(m_xmlrpcServer.getHandlerMapping(), ctx);
final byte[] result = m_xmlrpcServer.execute(request.getInputStream(), xmlrpcContext);
//
// I think it's safe to write the output as UTF-8: The XML-RPC standard never creates other than USASCII
// (which is UTF-8 compatible), and our special UTF-8 hack just creates UTF-8. So in all cases our butt
// should be covered.
//
response.setContentType("text/xml; charset=utf-8");
response.setContentLength(result.length);
final OutputStream out = response.getOutputStream();
out.write(result);
out.flush();
// log.debug("Result = "+new String(result) );
} catch (final IOException e) {
throw new ServletException("Failed to build RPC result", e);
}
}
use of org.apache.wiki.api.core.Context 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.Context in project jspwiki by apache.
the class HistoryIteratorTag method doStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doStartTag() {
m_wikiContext = (Context) pageContext.getAttribute(Context.ATTR_CONTEXT, PageContext.REQUEST_SCOPE);
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
try {
if (page != null && engine.getManager(PageManager.class).wikiPageExists(page)) {
final List<Page> versions = engine.getManager(PageManager.class).getVersionHistory(page.getName());
if (versions == null) {
// There is no history
return SKIP_BODY;
}
m_iterator = versions.iterator();
if (m_iterator.hasNext()) {
final Context context = m_wikiContext.clone();
context.setPage((Page) m_iterator.next());
pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), context.getPage());
} else {
return SKIP_BODY;
}
}
return EVAL_BODY_BUFFERED;
} catch (final ProviderException e) {
LOG.fatal("Provider failed while trying to iterator through history", e);
// FIXME: THrow something.
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Context in project jspwiki by apache.
the class InsertDiffTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
final Context ctx;
if (m_pageName == null) {
ctx = m_wikiContext;
} else {
ctx = m_wikiContext.clone();
ctx.setPage(engine.getManager(PageManager.class).getPage(m_pageName));
}
final Integer vernew = (Integer) pageContext.getAttribute(ATTR_NEWVERSION, PageContext.REQUEST_SCOPE);
final Integer verold = (Integer) pageContext.getAttribute(ATTR_OLDVERSION, PageContext.REQUEST_SCOPE);
log.debug("Request diff between version " + verold + " and " + vernew);
if (ctx.getPage() != null) {
final JspWriter out = pageContext.getOut();
final String diff = engine.getManager(DifferenceManager.class).getDiff(ctx, vernew.intValue(), verold.intValue());
if (diff.isEmpty()) {
return EVAL_BODY_INCLUDE;
}
out.write(diff);
}
return SKIP_BODY;
}
Aggregations