use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class RSSGenerator method getPageDescription.
private String getPageDescription(WikiPage page) {
StringBuilder buf = new StringBuilder();
String author = getAuthor(page);
WikiContext ctx = new WikiContext(m_engine, page);
if (page.getVersion() > 1) {
String diff = m_engine.getDiff(ctx, // FIXME: Will fail when non-contiguous versions
page.getVersion() - 1, page.getVersion());
buf.append(author + " changed this page on " + page.getLastModified() + ":<br /><hr /><br />");
buf.append(diff);
} else {
buf.append(author + " created this page on " + page.getLastModified() + ":<br /><hr /><br />");
buf.append(m_engine.getHTML(page.getName()));
}
return buf.toString();
}
use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class HistoryIteratorTag method doStartTag.
public final int doStartTag() {
m_wikiContext = (WikiContext) pageContext.getAttribute(WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE);
WikiEngine engine = m_wikiContext.getEngine();
WikiPage page;
page = m_wikiContext.getPage();
try {
if (page != null && engine.pageExists(page)) {
Collection versions = engine.getVersionHistory(page.getName());
if (versions == null) {
// There is no history
return SKIP_BODY;
}
m_iterator = versions.iterator();
if (m_iterator.hasNext()) {
WikiContext context = (WikiContext) m_wikiContext.clone();
context.setPage((WikiPage) m_iterator.next());
pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), context.getPage());
} else {
return SKIP_BODY;
}
}
return EVAL_BODY_BUFFERED;
} catch (ProviderException e) {
log.fatal("Provider failed while trying to iterator through history", e);
// FIXME: THrow something.
}
return SKIP_BODY;
}
use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class InsertDiffTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
public final int doWikiStartTag() throws IOException {
WikiEngine engine = m_wikiContext.getEngine();
WikiContext ctx;
if (m_pageName == null) {
ctx = m_wikiContext;
} else {
ctx = (WikiContext) m_wikiContext.clone();
ctx.setPage(engine.getPage(m_pageName));
}
Integer vernew = (Integer) pageContext.getAttribute(ATTR_NEWVERSION, PageContext.REQUEST_SCOPE);
Integer verold = (Integer) pageContext.getAttribute(ATTR_OLDVERSION, PageContext.REQUEST_SCOPE);
log.debug("Request diff between version " + verold + " and " + vernew);
if (ctx.getPage() != null) {
JspWriter out = pageContext.getOut();
String diff = engine.getDiff(ctx, vernew.intValue(), verold.intValue());
if (diff.length() == 0) {
return EVAL_BODY_INCLUDE;
}
out.write(diff);
}
return SKIP_BODY;
}
use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class IteratorTag method buildContext.
/**
* Arg, I hate globals.
*/
private void buildContext() {
//
// Build a clone of the current context
//
WikiContext context = (WikiContext) m_wikiContext.clone();
Object o = m_iterator.next();
if (o instanceof WikiPage)
context.setPage((WikiPage) o);
//
// Push it to the iterator stack, and set the id.
//
pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), o);
}
use of org.apache.wiki.WikiContext in project jspwiki by apache.
the class AttachmentsIteratorTag method doAfterBody.
/**
* {@inheritDoc}
*/
@Override
public final int doAfterBody() {
if (bodyContent != null) {
try {
JspWriter out = getPreviousOut();
out.print(bodyContent.getString());
bodyContent.clearBody();
} catch (IOException e) {
log.error("Unable to get inner tag text", e);
// FIXME: throw something?
}
}
if (m_iterator != null && m_iterator.hasNext()) {
Attachment att = (Attachment) m_iterator.next();
WikiContext context = (WikiContext) m_wikiContext.clone();
context.setPage(att);
pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), att);
return EVAL_BODY_BUFFERED;
}
return SKIP_BODY;
}
Aggregations