package com.xpn.xwiki.web;

import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.doc.XWikiLock;

public class LockAction extends XWikiAction {
	public boolean action(XWikiContext context) throws XWikiException {
        XWiki xwiki = context.getWiki();
        XWikiRequest request = context.getRequest();
        XWikiResponse response = context.getResponse();
        XWikiDocument doc = context.getDoc();
        XWikiForm form = context.getForm();

        String language = ((EditForm)form).getLanguage();
        String defaultLanguage = ((EditForm)form).getDefaultLanguage();
        XWikiDocument tdoc;

        if ((language==null)||(language.equals(""))||(language.equals("default"))||(language.equals(doc.getDefaultLanguage()))) {
            // Need to save parent and defaultLanguage if they have changed
            tdoc = doc;
        } else {
            tdoc = doc.getTranslatedDocument(language, context);
            if (tdoc == doc) {
                tdoc = new XWikiDocument(doc.getSpace(), doc.getName());
                tdoc.setLanguage(language);
                tdoc.setStore(doc.getStore());
            }
            tdoc.setTranslation(1);
        }

        String username = context.getUser();
        XWikiLock lock = tdoc.getLock(context);
        if ((lock==null)||(username.equals(lock.getUserName()))) {
            if ("inline".equals(request.get("action")))
                doc.setLock(username, context);
            else
                tdoc.setLock(username, context);
        }

        // forward to view
        String ajax = request.getParameter("ajax");
        if(ajax == null || !ajax.equals("1")){
        	String redirect = Utils.getRedirect("view", context);
        	sendRedirect(response, redirect);
        }
        return false;
	}
}

@@ -245,12 +245,15 @@
 tion
- %7B%0A%09
+%0A%7B%0A    
 publ
@@ -313,16 +313,20 @@
 xception
+%0A   
  %7B%0A     
@@ -590,32 +590,33 @@
 ge = ((EditForm)
+ 
 form).getLanguag
@@ -664,16 +664,17 @@
 ditForm)
+ 
 form).ge
@@ -743,25 +743,29 @@
 language
+ 
 ==
+ 
 null)
+ 
 %7C%7C
+ 
 (languag
@@ -777,18 +777,20 @@
 als(%22%22))
+ 
 %7C%7C
+ 
 (languag
@@ -809,18 +809,32 @@
 fault%22))
+%0A            
 %7C%7C
+ 
 (languag
@@ -1424,17 +1424,21 @@
 lock
+ 
 ==
+ 
 null)
+ 
 %7C%7C
+ 
 (use
@@ -1744,16 +1744,17 @@
       if
+ 
 (ajax ==
@@ -1780,16 +1780,17 @@
 ls(%221%22))
+ 
 %7B%0A      
@@ -1791,17 +1791,20 @@
         
-%09
+    
 String r
@@ -1857,17 +1857,20 @@
         
-%09
+    
 sendRedi
@@ -1931,9 +1931,12 @@
 se;%0A
-%09
+    
 %7D%0A%7D%0A

Apply codestyle