use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class SpamFilter method checkPageName.
private void checkPageName(final Context context, final String content, final Change change) throws RedirectException {
final Page page = context.getPage();
final String pageName = page.getName();
final int maxlength = Integer.parseInt(m_pageNameMaxLength);
if (pageName.length() > maxlength) {
//
// Spam filter has a match.
//
final String uid = log(context, REJECT, REASON_PAGENAME_TOO_LONG + "(" + m_pageNameMaxLength + ")", pageName);
log.info("SPAM:PageNameTooLong (" + uid + "). The length of the page name is too large (" + pageName.length() + " , limit is " + m_pageNameMaxLength + ")");
checkStrategy(context, REASON_PAGENAME_TOO_LONG, "Herb says '" + pageName + "' is a bad pageName and I trust Herb! (Incident code " + uid + ")");
}
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class DiffLinkTag method doWikiStartTag.
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
String pageName = m_pageName;
if (m_pageName == null) {
if (m_wikiContext.getPage() != null) {
pageName = m_wikiContext.getPage().getName();
} else {
return SKIP_BODY;
}
}
final JspWriter out = pageContext.getOut();
int r1;
int r2;
// In case the page does not exist, we fail silently.
if (!engine.getManager(PageManager.class).wikiPageExists(pageName)) {
return SKIP_BODY;
}
if (VER_LATEST.equals(getVersion())) {
final Page latest = engine.getManager(PageManager.class).getPage(pageName, WikiProvider.LATEST_VERSION);
if (latest == null) {
// This may occur if matchEnglishPlurals is on, and we access the wrong page name
return SKIP_BODY;
}
r1 = latest.getVersion();
} else if (VER_PREVIOUS.equals(getVersion())) {
r1 = m_wikiContext.getPage().getVersion() - 1;
r1 = Math.max(r1, 1);
} else if (VER_CURRENT.equals(getVersion())) {
r1 = m_wikiContext.getPage().getVersion();
} else {
r1 = Integer.parseInt(getVersion());
}
if (VER_LATEST.equals(getNewVersion())) {
final Page latest = engine.getManager(PageManager.class).getPage(pageName, WikiProvider.LATEST_VERSION);
r2 = latest.getVersion();
} else if (VER_PREVIOUS.equals(getNewVersion())) {
r2 = m_wikiContext.getPage().getVersion() - 1;
r2 = Math.max(r2, 1);
} else if (VER_CURRENT.equals(getNewVersion())) {
r2 = m_wikiContext.getPage().getVersion();
} else {
r2 = Integer.parseInt(getNewVersion());
}
final String url = m_wikiContext.getURL(ContextEnum.PAGE_DIFF.getRequestContext(), pageName, "r1=" + r1 + "&r2=" + r2);
switch(m_format) {
case ANCHOR:
out.print("<a href=\"" + url + "\">");
break;
case URL:
out.print(url);
break;
}
return EVAL_BODY_INCLUDE;
}
use of org.apache.wiki.api.core.Page 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.Page in project jspwiki by apache.
the class IteratorTag method buildContext.
/**
* Arg, I hate globals.
*/
private void buildContext() {
final Context context = m_wikiContext.clone();
final Object o = m_iterator.next();
if (o instanceof Page) {
context.setPage((Page) o);
}
pageContext.setAttribute(Context.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
pageContext.setAttribute(getId(), o);
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class NoSuchPageTag method doWikiStartTag.
@Override
public int doWikiStartTag() throws IOException, ProviderException {
final Engine engine = m_wikiContext.getEngine();
final Page page;
if (m_pageName == null) {
page = m_wikiContext.getPage();
} else {
page = engine.getManager(PageManager.class).getPage(m_pageName);
}
if (page != null && engine.getManager(PageManager.class).wikiPageExists(page.getName(), page.getVersion())) {
return SKIP_BODY;
}
return EVAL_BODY_INCLUDE;
}
Aggregations