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);
}
}
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;
}
Aggregations