use of org.apache.wiki.WikiEngine 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.WikiEngine 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.WikiEngine in project jspwiki by apache.
the class InsertPageTag method doWikiStartTag.
public final int doWikiStartTag() throws IOException, ProviderException {
WikiEngine engine = m_wikiContext.getEngine();
WikiPage insertedPage;
if (m_pageName == null) {
insertedPage = m_wikiContext.getPage();
if (!engine.pageExists(insertedPage))
return SKIP_BODY;
} else {
insertedPage = engine.getPage(m_pageName);
}
if (insertedPage != null) {
// FIXME: Do version setting later.
// page.setVersion( WikiProvider.LATEST_VERSION );
log.debug("Inserting page " + insertedPage);
JspWriter out = pageContext.getOut();
WikiPage oldPage = m_wikiContext.setRealPage(insertedPage);
switch(m_mode) {
case HTML:
out.print(engine.getHTML(m_wikiContext, insertedPage));
break;
case PLAIN:
out.print(engine.getText(m_wikiContext, insertedPage));
break;
}
m_wikiContext.setRealPage(oldPage);
}
return SKIP_BODY;
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class LinkTag method doEndTag.
public int doEndTag() {
try {
if (!m_overrideAbsolute) {
// TODO: see WikiContext.getURL(); this check needs to be specified somewhere.
WikiEngine engine = m_wikiContext.getEngine();
m_absolute = "absolute".equals(engine.getWikiProperties().getProperty(WikiEngine.PROP_REFSTYLE));
}
JspWriter out = pageContext.getOut();
String url = figureOutURL();
StringBuilder sb = new StringBuilder(20);
sb.append((m_cssClass != null) ? "class=\"" + m_cssClass + "\" " : "");
sb.append((m_style != null) ? "style=\"" + m_style + "\" " : "");
sb.append((m_target != null) ? "target=\"" + m_target + "\" " : "");
sb.append((m_title != null) ? "title=\"" + m_title + "\" " : "");
sb.append((m_rel != null) ? "rel=\"" + m_rel + "\" " : "");
sb.append((m_accesskey != null) ? "accesskey=\"" + m_accesskey + "\" " : "");
switch(m_format) {
case URL:
out.print(url);
break;
default:
case ANCHOR:
out.print("<a " + sb.toString() + " href=\"" + url + "\">");
break;
}
// of LinkTag, but happens to be the way it has worked previously.
if (m_bodyContent != null) {
String linktext = m_bodyContent.getString().trim();
out.write(linktext);
}
// Finish off by closing opened anchor
if (m_format == ANCHOR)
out.print("</a>");
} catch (Exception e) {
// Yes, we want to catch all exceptions here, including RuntimeExceptions
log.error("Tag failed", e);
}
return EVAL_PAGE;
}
use of org.apache.wiki.WikiEngine in project jspwiki by apache.
the class CheckLockTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException, ProviderException {
WikiEngine engine = m_wikiContext.getEngine();
WikiPage page = m_wikiContext.getPage();
if (page != null) {
PageManager mgr = engine.getPageManager();
PageLock lock = mgr.getCurrentLock(page);
HttpSession session = pageContext.getSession();
PageLock userLock = (PageLock) session.getAttribute("lock-" + page.getName());
if ((lock != null && m_mode == LockState.LOCKED && lock != userLock) || (lock != null && m_mode == LockState.OWNED && lock == userLock) || (lock == null && m_mode == LockState.NOTLOCKED)) {
String tid = getId();
if (tid != null && lock != null) {
pageContext.setAttribute(tid, lock);
}
return EVAL_BODY_INCLUDE;
}
}
return SKIP_BODY;
}
Aggregations