use of org.apache.wiki.PageLock in project jspwiki by apache.
the class WeblogEntryPlugin method findFreeEntry.
private int findFreeEntry(PageManager mgr, String baseName, String date) throws ProviderException {
Collection everyone = mgr.getAllPages();
int max = 0;
String startString = WeblogPlugin.makeEntryPage(baseName, date, "");
for (Iterator i = everyone.iterator(); i.hasNext(); ) {
WikiPage p = (WikiPage) i.next();
if (p.getName().startsWith(startString)) {
try {
String probableId = p.getName().substring(startString.length());
int id = Integer.parseInt(probableId);
if (id > max) {
max = id;
}
} catch (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) {
WikiPage page = new WikiPage(mgr.getEngine(), WeblogPlugin.makeEntryPage(baseName, date, Integer.toString(idx)));
PageLock lock = mgr.getCurrentLock(page);
if (lock == null) {
break;
}
idx++;
}
return idx;
}
use of org.apache.wiki.PageLock 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;
}
use of org.apache.wiki.PageLock in project jspwiki by apache.
the class DefaultAclManager method setPermissions.
/**
* Sets the access control list for the page and persists it by prepending
* it to the wiki page markup and saving the page. When this method is
* called, all other ACL markup in the page is removed. This method will forcibly
* expire locks on the wiki page if they exist. Any ProviderExceptions will be
* re-thrown as WikiSecurityExceptions.
*
* @param page the wiki page
* @param acl the access control list
* @throws WikiSecurityException of the Acl cannot be set
* @since 2.5
*/
public void setPermissions(WikiPage page, Acl acl) throws WikiSecurityException {
PageManager pageManager = m_engine.getPageManager();
// Forcibly expire any page locks
PageLock lock = pageManager.getCurrentLock(page);
if (lock != null) {
pageManager.unlockPage(lock);
}
// Remove all of the existing ACLs.
String pageText = m_engine.getPureText(page);
Matcher matcher = DefaultAclManager.ACL_PATTERN.matcher(pageText);
String cleansedText = matcher.replaceAll("");
String newText = DefaultAclManager.printAcl(page.getAcl()) + cleansedText;
try {
pageManager.putPageText(page, newText);
} catch (ProviderException e) {
throw new WikiSecurityException("Could not set Acl. Reason: ProviderExcpetion " + e.getMessage(), e);
}
}
use of org.apache.wiki.PageLock in project jspwiki by apache.
the class ListLocksPlugin method execute.
/**
* {@inheritDoc}
*/
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
StringBuilder result = new StringBuilder();
PageManager mgr = context.getEngine().getPageManager();
List<PageLock> locks = mgr.getActiveLocks();
ResourceBundle rb = Preferences.getBundle(context, WikiPlugin.CORE_PLUGINS_RESOURCEBUNDLE);
result.append("<table class=\"wikitable\">\n");
result.append("<tr>\n");
result.append("<th>" + rb.getString("plugin.listlocks.page") + "</th><th>" + rb.getString("plugin.listlocks.locked.by") + "</th><th>" + rb.getString("plugin.listlocks.acquired") + "</th><th>" + rb.getString("plugin.listlocks.expires") + "</th>\n");
result.append("</tr>");
if (locks.size() == 0) {
result.append("<tr><td colspan=\"4\" class=\"odd\">" + rb.getString("plugin.listlocks.no.locks.exist") + "</td></tr>\n");
} else {
int rowNum = 1;
for (Iterator<PageLock> i = locks.iterator(); i.hasNext(); ) {
PageLock lock = i.next();
result.append(rowNum % 2 != 0 ? "<tr class=\"odd\">" : "<tr>");
result.append("<td>" + lock.getPage() + "</td>");
result.append("<td>" + lock.getLocker() + "</td>");
result.append("<td>" + Preferences.renderDate(context, lock.getAcquisitionTime(), Preferences.TimeFormat.DATETIME) + "</td>");
result.append("<td>" + Preferences.renderDate(context, lock.getExpiryTime(), Preferences.TimeFormat.DATETIME) + "</td>");
result.append("</tr>\n");
rowNum++;
}
}
result.append("</table>");
return result.toString();
}
Aggregations