use of org.apache.wiki.pages.PageLock in project jspwiki by apache.
the class ListLocksPlugin method execute.
/**
* {@inheritDoc}
*/
@Override
public String execute(final Context context, final Map<String, String> params) throws PluginException {
final StringBuilder result = new StringBuilder();
final PageManager mgr = context.getEngine().getManager(PageManager.class);
final List<PageLock> locks = mgr.getActiveLocks();
final ResourceBundle rb = Preferences.getBundle(context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE);
result.append("<table class=\"wikitable\">\n");
result.append("<tr>\n");
result.append("<th>").append(rb.getString("plugin.listlocks.page")).append("</th><th>").append(rb.getString("plugin.listlocks.locked.by")).append("</th><th>").append(rb.getString("plugin.listlocks.acquired")).append("</th><th>").append(rb.getString("plugin.listlocks.expires")).append("</th>\n");
result.append("</tr>");
if (locks.size() == 0) {
result.append("<tr><td colspan=\"4\" class=\"odd\">").append(rb.getString("plugin.listlocks.no.locks.exist")).append("</td></tr>\n");
} else {
int rowNum = 1;
for (final PageLock lock : locks) {
result.append(rowNum % 2 != 0 ? "<tr class=\"odd\">" : "<tr>");
result.append("<td>").append(lock.getPage()).append("</td>");
result.append("<td>").append(lock.getLocker()).append("</td>");
result.append("<td>").append(Preferences.renderDate(context, lock.getAcquisitionTime(), Preferences.TimeFormat.DATETIME)).append("</td>");
result.append("<td>").append(Preferences.renderDate(context, lock.getExpiryTime(), Preferences.TimeFormat.DATETIME)).append("</td>");
result.append("</tr>\n");
rowNum++;
}
}
result.append("</table>");
return result.toString();
}
use of org.apache.wiki.pages.PageLock in project jspwiki by apache.
the class CheckLockTag method doWikiStartTag.
/**
* {@inheritDoc}
*/
@Override
public final int doWikiStartTag() throws IOException, ProviderException {
final Engine engine = m_wikiContext.getEngine();
final Page page = m_wikiContext.getPage();
if (page != null) {
final PageManager mgr = engine.getManager(PageManager.class);
final PageLock lock = mgr.getCurrentLock(page);
final HttpSession session = pageContext.getSession();
final 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)) {
final String tid = getId();
if (tid != null && lock != null) {
pageContext.setAttribute(tid, lock);
}
return EVAL_BODY_INCLUDE;
}
}
return SKIP_BODY;
}
use of org.apache.wiki.pages.PageLock in project jspwiki by apache.
the class DefaultAclManager method setPermissions.
/**
* {@inheritDoc}
*/
@Override
public void setPermissions(final Page page, final Acl acl) throws WikiSecurityException {
final PageManager pageManager = m_engine.getManager(PageManager.class);
// Forcibly expire any page locks
final PageLock lock = pageManager.getCurrentLock(page);
if (lock != null) {
pageManager.unlockPage(lock);
}
// Remove all of the existing ACLs.
final String pageText = m_engine.getManager(PageManager.class).getPureText(page);
final Matcher matcher = DefaultAclManager.ACL_PATTERN.matcher(pageText);
final String cleansedText = matcher.replaceAll("");
final String newText = DefaultAclManager.printAcl(page.getAcl()) + cleansedText;
try {
pageManager.putPageText(page, newText);
} catch (final ProviderException e) {
throw new WikiSecurityException("Could not set Acl. Reason: ProviderExcpetion " + e.getMessage(), e);
}
}
use of org.apache.wiki.pages.PageLock in project jspwiki by apache.
the class WeblogEntryPlugin method findFreeEntry.
private int findFreeEntry(final Engine engine, final String baseName, final String date) throws ProviderException {
final Collection<Page> everyone = engine.getManager(PageManager.class).getAllPages();
final String startString = WeblogPlugin.makeEntryPage(baseName, date, "");
int max = 0;
for (final Page p : everyone) {
if (p.getName().startsWith(startString)) {
try {
final String probableId = p.getName().substring(startString.length());
final int id = Integer.parseInt(probableId);
if (id > max) {
max = id;
}
} catch (final NumberFormatException e) {
log.debug("Was not a log entry: " + p.getName());
}
}
}
// Find the first page that has no page lock.
int idx = max + 1;
while (idx < MAX_BLOG_ENTRIES) {
final Page page = Wiki.contents().page(engine, WeblogPlugin.makeEntryPage(baseName, date, Integer.toString(idx)));
final PageLock lock = engine.getManager(PageManager.class).getCurrentLock(page);
if (lock == null) {
break;
}
idx++;
}
return idx;
}
Aggregations