use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class NextVersionTag method doWikiStartTag.
public final int doWikiStartTag() throws IOException {
final Page page = m_wikiContext.getPage();
int version = page.getVersion();
if (version != WikiProvider.LATEST_VERSION) {
version++;
}
pageContext.getOut().print(version);
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class PageDateTag method doWikiStartTag.
public final int doWikiStartTag() throws IOException {
final Page page = m_wikiContext.getPage();
if (page != null) {
final Date d = page.getLastModified();
// Date may be null if the page does not exist.
if (d != null) {
final SimpleDateFormat fmt;
if (m_format == null) {
fmt = Preferences.getDateFormat(m_wikiContext, TimeFormat.DATETIME);
} else {
fmt = new SimpleDateFormat(m_format);
}
pageContext.getOut().write(fmt.format(d));
} else {
pageContext.getOut().write("<never>");
}
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class PageInfoLinkTag method doWikiStartTag.
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
String pageName = m_pageName;
if (m_pageName == null) {
final Page p = m_wikiContext.getPage();
if (p != null) {
pageName = p.getName();
} else {
return SKIP_BODY;
}
}
if (engine.getManager(PageManager.class).wikiPageExists(pageName)) {
final JspWriter out = pageContext.getOut();
final String url = m_wikiContext.getURL(ContextEnum.PAGE_INFO.getRequestContext(), pageName);
switch(m_format) {
case ANCHOR:
out.print("<a class=\"pageinfo\" href=\"" + url + "\" accesskey=\"" + m_accesskey + "\" title=\"" + m_title + "\">");
break;
case URL:
out.print(url);
break;
}
return EVAL_BODY_INCLUDE;
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class PageSizeTag method doWikiStartTag.
@Override
public final int doWikiStartTag() throws IOException {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
try {
if (page != null) {
long size = page.getSize();
if (size == -1 && engine.getManager(PageManager.class).wikiPageExists(page)) {
// should never happen with attachments
size = engine.getManager(PageManager.class).getPureText(page.getName(), page.getVersion()).length();
page.setSize(size);
}
pageContext.getOut().write(Long.toString(size));
}
} catch (final ProviderException e) {
log.warn("Providers did not work: ", e);
pageContext.getOut().write("Error determining page size: " + e.getMessage());
}
return SKIP_BODY;
}
use of org.apache.wiki.api.core.Page in project jspwiki by apache.
the class PermissionTag method checkPermission.
/**
* Checks a single permission.
*
* @param permission permission to check for
* @return true if granted, false if not
*/
private boolean checkPermission(final String permission) {
final Session session = m_wikiContext.getWikiSession();
final Page page = m_wikiContext.getPage();
final AuthorizationManager mgr = m_wikiContext.getEngine().getManager(AuthorizationManager.class);
boolean gotPermission = false;
if (CREATE_GROUPS.equals(permission) || CREATE_PAGES.equals(permission) || EDIT_PREFERENCES.equals(permission) || EDIT_PROFILE.equals(permission) || LOGIN.equals(permission)) {
gotPermission = mgr.checkPermission(session, new WikiPermission(page.getWiki(), permission));
} else if (VIEW_GROUP.equals(permission) || EDIT_GROUP.equals(permission) || DELETE_GROUP.equals(permission)) {
final Command command = m_wikiContext.getCommand();
gotPermission = false;
if (command instanceof GroupCommand && command.getTarget() != null) {
final GroupPrincipal group = (GroupPrincipal) command.getTarget();
final String groupName = group.getName();
String action = "view";
if (EDIT_GROUP.equals(permission)) {
action = "edit";
} else if (DELETE_GROUP.equals(permission)) {
action = "delete";
}
gotPermission = mgr.checkPermission(session, new GroupPermission(groupName, action));
}
} else if (ALL_PERMISSION.equals(permission)) {
gotPermission = mgr.checkPermission(session, new AllPermission(m_wikiContext.getEngine().getApplicationName()));
} else if (page != null) {
//
if (EDIT.equals(permission)) {
final Page latest = m_wikiContext.getEngine().getManager(PageManager.class).getPage(page.getName());
if (page.getVersion() != WikiProvider.LATEST_VERSION && latest.getVersion() != page.getVersion()) {
return false;
}
}
final Permission p = PermissionFactory.getPagePermission(page, permission);
gotPermission = mgr.checkPermission(session, p);
}
return gotPermission;
}
Aggregations