//  [java]
    public String render(XWikiContext context) throws XWikiException
    {
        XWikiDocument doc = context.getDoc();

        synchronized (doc) {
            XWikiForm form = context.getForm();

            XWikiDocument cdoc = (XWikiDocument) context.get("cdoc");
            if (cdoc == null) {
                cdoc = doc;
            }

            EditForm peform = (EditForm) form;

            XWikiDocument doc2 = doc.clone();
            context.put("doc", doc2);

            String parent = peform.getParent();
            if (parent != null) {
                doc2.setParent(parent);
            }
            String creator = peform.getCreator();
            if (creator != null) {
                doc2.setCreator(creator);
            }
            String defaultLanguage = peform.getDefaultLanguage();
            if ((defaultLanguage != null) && !defaultLanguage.equals("")) {
                doc2.setDefaultLanguage(defaultLanguage);
            }
            if (doc2.getDefaultLanguage().equals("")) {
                doc2.setDefaultLanguage(context.getWiki().getLanguagePreference(context));
            }
            try {
                readFromTemplate(doc2, peform.getTemplate(), context);
            } catch (XWikiException e) {
                if (e.getCode() == XWikiException.ERROR_XWIKI_APP_DOCUMENT_NOT_EMPTY) {
                    return "docalreadyexists";
                }
            }

            if (doc == cdoc) {
                context.put("cdoc", doc2);
            } else {
                XWikiDocument cdoc2 = cdoc.clone();
                readFromTemplate(cdoc2, peform.getTemplate(), context);
                context.put("cdoc", cdoc2);
            }

            doc2.readFromForm((EditForm) form, context);

            // Set the current user as creator, author and contentAuthor when the edited document is newly created
            // to avoid using XWikiGuest instead (because those fields were not previously initialized).
            // This is needed for the script right, as guest doesn't have it and this would block the execution of
            // scripts in newly created documents even if the user creating the document has the right.
            if (doc2.isNew()) {
                doc2.setCreatorReference(context.getUserReference());
                doc2.setAuthorReference(context.getUserReference());
                doc2.setContentAuthorReference(context.getUserReference());
            }

            /* Setup a lock */
            try {
                XWikiLock lock = doc.getLock(context);
                if ((lock == null) || (lock.getUserName().equals(context.getUser())) || (peform.isLockForce())) {
                    doc.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);
            }
        }

        // Make sure object property fields are displayed in edit mode.
        // See XWikiDocument#display(String, BaseObject, XWikiContext)
        context.put("display", "edit");

        return "inline";
    }