Search in sources :

Example 6 with XWikiLock

use of com.xpn.xwiki.doc.XWikiLock in project xwiki-platform by xwiki.

the class EditAction method maybeLockDocument.

/**
 * Locks the given document unless it is already locked by a different user and the current user didn't request to
 * force the lock.
 *
 * @param document the document to lock
 * @param context the XWiki context
 */
private void maybeLockDocument(XWikiDocument document, XWikiContext context) {
    try {
        XWikiLock lock = document.getLock(context);
        EditForm editForm = (EditForm) context.getForm();
        if (lock == null || lock.getUserName().equals(context.getUser()) || editForm.isLockForce()) {
            document.setLock(context.getUser(), context);
        }
    } catch (Exception e) {
        // Lock should never make XWiki fail, but we should log any related information.
        LOGGER.error("Exception while setting up lock", e);
    }
}
Also used : XWikiLock(com.xpn.xwiki.doc.XWikiLock) XWikiException(com.xpn.xwiki.XWikiException)

Example 7 with XWikiLock

use of com.xpn.xwiki.doc.XWikiLock in project xwiki-platform by xwiki.

the class CancelAction method action.

@Override
public boolean action(XWikiContext context) throws XWikiException {
    XWikiRequest request = context.getRequest();
    XWikiResponse response = context.getResponse();
    XWikiDocument doc = context.getDoc();
    XWikiForm form = context.getForm();
    String language = ((EditForm) form).getLanguage();
    // FIXME Which one should be used: doc.getDefaultLanguage or
    // form.getDefaultLanguage()?
    // String defaultLanguage = ((EditForm)form).getDefaultLanguage();
    XWikiDocument tdoc = getTranslatedDocument(doc, language, context);
    String username = context.getUser();
    try {
        XWikiLock lock = tdoc.getLock(context);
        if (lock != null && lock.getUserName().equals(username)) {
            if ("inline".equals(request.get("action"))) {
                doc.removeLock(context);
            } else {
                tdoc.removeLock(context);
            }
        }
    } catch (Exception ex) {
    // Just ignore this, locks aren't critical.
    }
    // forward to view
    if (Utils.isAjaxRequest(context)) {
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
        response.setContentLength(0);
    } else {
        String redirect = Utils.getRedirect("view", context);
        sendRedirect(response, redirect);
    }
    return false;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiLock(com.xpn.xwiki.doc.XWikiLock) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

XWikiLock (com.xpn.xwiki.doc.XWikiLock)7 XWikiException (com.xpn.xwiki.XWikiException)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)1 SQLException (java.sql.SQLException)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 Query (org.hibernate.Query)1 Session (org.hibernate.Session)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 InitializationException (org.xwiki.component.phase.InitializationException)1 Job (org.xwiki.job.Job)1 QueryException (org.xwiki.query.QueryException)1 UnexpectedException (org.xwiki.store.UnexpectedException)1