Search in sources :

Example 1 with PageLock

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();
}
Also used : PageManager(org.apache.wiki.pages.PageManager) ResourceBundle(java.util.ResourceBundle) PageLock(org.apache.wiki.pages.PageLock)

Example 2 with PageLock

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;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) HttpSession(javax.servlet.http.HttpSession) Page(org.apache.wiki.api.core.Page) PageLock(org.apache.wiki.pages.PageLock) Engine(org.apache.wiki.api.core.Engine)

Example 3 with PageLock

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);
    }
}
Also used : WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) PageManager(org.apache.wiki.pages.PageManager) Matcher(java.util.regex.Matcher) ProviderException(org.apache.wiki.api.exceptions.ProviderException) PageLock(org.apache.wiki.pages.PageLock)

Example 4 with PageLock

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;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) PageLock(org.apache.wiki.pages.PageLock)

Aggregations

PageLock (org.apache.wiki.pages.PageLock)4 PageManager (org.apache.wiki.pages.PageManager)4 Page (org.apache.wiki.api.core.Page)2 ResourceBundle (java.util.ResourceBundle)1 Matcher (java.util.regex.Matcher)1 HttpSession (javax.servlet.http.HttpSession)1 Engine (org.apache.wiki.api.core.Engine)1 ProviderException (org.apache.wiki.api.exceptions.ProviderException)1 WikiSecurityException (org.apache.wiki.auth.WikiSecurityException)1