Search in sources :

Example 1 with PageLock

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;
}
Also used : WikiPage(org.apache.wiki.WikiPage) Iterator(java.util.Iterator) Collection(java.util.Collection) PageLock(org.apache.wiki.PageLock)

Example 2 with PageLock

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;
}
Also used : PageManager(org.apache.wiki.PageManager) HttpSession(javax.servlet.http.HttpSession) WikiPage(org.apache.wiki.WikiPage) PageLock(org.apache.wiki.PageLock) WikiEngine(org.apache.wiki.WikiEngine)

Example 3 with PageLock

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

Example 4 with PageLock

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

Aggregations

PageLock (org.apache.wiki.PageLock)4 PageManager (org.apache.wiki.PageManager)3 WikiPage (org.apache.wiki.WikiPage)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 ResourceBundle (java.util.ResourceBundle)1 Matcher (java.util.regex.Matcher)1 HttpSession (javax.servlet.http.HttpSession)1 WikiEngine (org.apache.wiki.WikiEngine)1 ProviderException (org.apache.wiki.api.exceptions.ProviderException)1 WikiSecurityException (org.apache.wiki.auth.WikiSecurityException)1