@Test public void newDocumentWebHomeFromURLTemplateProviderSpecifiedWithSaveAndEdit() throws Exception { DocumentReference documentReference = new DocumentReference("xwiki", "X", "Y"); XWikiDocument document = mock(XWikiDocument.class); when(document.getDocumentReference()).thenReturn(documentReference); when(document.getDocumentReferenceWithLocale()).thenReturn(documentReference); when(document.isNew()).thenReturn(true); when(document.getLocalReferenceMaxLength()).thenReturn(255); when(document.getDefaultEditMode(this.context)).thenReturn("edit"); when(document.getDefaultLocale()).thenReturn(Locale.ROOT); when(document.clone()).thenReturn(document); when(this.context.getWiki().getLocalePreference(this.context)).thenReturn(Locale.FRENCH); when(this.context.getWiki().getDocument(documentReference, this.context)).thenReturn(document); this.context.setDoc(document); DocumentReference userReference = new DocumentReference("xwiki", "Users", "Alice"); this.context.setUserReference(userReference); when(mockRequest.getParameter("spaceReference")).thenReturn("X"); when(mockRequest.getParameter("name")).thenReturn("Y"); when(mockRequest.getParameter("title")).thenReturn("Yippee"); String templateProviderFullName = "XWiki.MyTemplateProvider"; when(mockRequest.getParameter("templateprovider")).thenReturn(templateProviderFullName); mockExistingTemplateProviders(templateProviderFullName, new DocumentReference("xwiki", Arrays.asList("XWiki"), "MyTemplateProvider"), Collections.emptyList(), null, "page", "saveandedit"); assertNull(this.action.render(this.context)); verify(document).setLocale(Locale.ROOT); verify(document).setDefaultLocale(Locale.FRENCH); verify(document).readFromTemplate(new DocumentReference("xwiki", "XWiki", "MyTemplate"), this.context); verify(document).setTitle("Yippee"); verify(document).setCreatorReference(userReference); verify(document).setAuthorReference(userReference); verify(this.context.getWiki()).saveDocument(document, this.context); }
@Override public String render(XWikiContext context) throws XWikiException { CreateActionRequestHandler handler = new CreateActionRequestHandler(context); handler.processRequest(); ScriptContext scontext = getCurrentScriptContext(); scontext.setAttribute(SPACE_REFERENCE, handler.getSpaceReference(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(NAME, handler.getName(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(IS_SPACE, handler.isSpace(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("availableTemplateProviders", handler.getAvailableTemplateProviders(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("recommendedTemplateProviders", handler.getRecommendedTemplateProviders(), ScriptContext.ENGINE_SCOPE); DocumentReference newDocumentReference = handler.getNewDocumentReference(); if (newDocumentReference == null) { return CREATE_TEMPLATE; } if (!handler.isTemplateProviderAllowedToCreateInCurrentSpace()) { return CREATE_TEMPLATE; } checkRights(newDocumentReference.getLastSpaceReference(), context); XWikiDocument newDocument = context.getWiki().getDocument(newDocumentReference, context); if (handler.isDocumentAlreadyExisting(newDocument) || handler.isDocumentPathTooLong(newDocumentReference) || !this.isEntityReferenceNameValid(newDocumentReference)) { return CREATE_TEMPLATE; } if (StringUtils.isBlank(handler.getType()) && !handler.hasTemplate()) { return CREATE_TEMPLATE; } doCreate(context, newDocument, handler.isSpace(), handler.getTemplateProvider()); return null; }
CreateAction extends XWikiAction { @Override public String render(XWikiContext context) throws XWikiException { CreateActionRequestHandler handler = new CreateActionRequestHandler(context); handler.processRequest(); ScriptContext scontext = getCurrentScriptContext(); scontext.setAttribute(SPACE_REFERENCE, handler.getSpaceReference(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(NAME, handler.getName(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(IS_SPACE, handler.isSpace(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("availableTemplateProviders", handler.getAvailableTemplateProviders(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("recommendedTemplateProviders", handler.getRecommendedTemplateProviders(), ScriptContext.ENGINE_SCOPE); DocumentReference newDocumentReference = handler.getNewDocumentReference(); if (newDocumentReference == null) { return CREATE_TEMPLATE; } if (!handler.isTemplateProviderAllowedToCreateInCurrentSpace()) { return CREATE_TEMPLATE; } checkRights(newDocumentReference.getLastSpaceReference(), context); XWikiDocument newDocument = context.getWiki().getDocument(newDocumentReference, context); if (handler.isDocumentAlreadyExisting(newDocument) || handler.isDocumentPathTooLong(newDocumentReference) || !this.isEntityReferenceNameValid(newDocumentReference)) { return CREATE_TEMPLATE; } if (StringUtils.isBlank(handler.getType()) && !handler.hasTemplate()) { return CREATE_TEMPLATE; } doCreate(context, newDocument, handler.isSpace(), handler.getTemplateProvider()); return null; } }
CreateAction extends XWikiAction { @Override public String render(XWikiContext context) throws XWikiException { CreateActionRequestHandler handler = new CreateActionRequestHandler(context); handler.processRequest(); ScriptContext scontext = getCurrentScriptContext(); scontext.setAttribute(SPACE_REFERENCE, handler.getSpaceReference(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(NAME, handler.getName(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(IS_SPACE, handler.isSpace(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("availableTemplateProviders", handler.getAvailableTemplateProviders(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("recommendedTemplateProviders", handler.getRecommendedTemplateProviders(), ScriptContext.ENGINE_SCOPE); DocumentReference newDocumentReference = handler.getNewDocumentReference(); if (newDocumentReference == null) { return CREATE_TEMPLATE; } if (!handler.isTemplateProviderAllowedToCreateInCurrentSpace()) { return CREATE_TEMPLATE; } checkRights(newDocumentReference.getLastSpaceReference(), context); XWikiDocument newDocument = context.getWiki().getDocument(newDocumentReference, context); if (handler.isDocumentAlreadyExisting(newDocument) || handler.isDocumentPathTooLong(newDocumentReference) || !this.isEntityReferenceNameValid(newDocumentReference)) { return CREATE_TEMPLATE; } if (StringUtils.isBlank(handler.getType()) && !handler.hasTemplate()) { return CREATE_TEMPLATE; } doCreate(context, newDocument, handler.isSpace(), handler.getTemplateProvider()); return null; } CreateAction(); }
CreateAction extends XWikiAction { @Override public String render(XWikiContext context) throws XWikiException { CreateActionRequestHandler handler = new CreateActionRequestHandler(context); handler.processRequest(); ScriptContext scontext = getCurrentScriptContext(); scontext.setAttribute(SPACE_REFERENCE, handler.getSpaceReference(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(NAME, handler.getName(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(IS_SPACE, handler.isSpace(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("availableTemplateProviders", handler.getAvailableTemplateProviders(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("recommendedTemplateProviders", handler.getRecommendedTemplateProviders(), ScriptContext.ENGINE_SCOPE); DocumentReference newDocumentReference = handler.getNewDocumentReference(); if (newDocumentReference == null) { return CREATE_TEMPLATE; } if (!handler.isTemplateProviderAllowedToCreateInCurrentSpace()) { return CREATE_TEMPLATE; } checkRights(newDocumentReference.getLastSpaceReference(), context); XWikiDocument newDocument = context.getWiki().getDocument(newDocumentReference, context); if (handler.isDocumentAlreadyExisting(newDocument) || handler.isDocumentPathTooLong(newDocumentReference) || !this.isEntityReferenceNameValid(newDocumentReference)) { return CREATE_TEMPLATE; } if (StringUtils.isBlank(handler.getType()) && !handler.hasTemplate()) { return CREATE_TEMPLATE; } doCreate(context, newDocument, handler.isSpace(), handler.getTemplateProvider()); return null; } CreateAction(); @Override String render(XWikiContext context); }
CreateAction extends XWikiAction { @Override public String render(XWikiContext context) throws XWikiException { CreateActionRequestHandler handler = new CreateActionRequestHandler(context); handler.processRequest(); ScriptContext scontext = getCurrentScriptContext(); scontext.setAttribute(SPACE_REFERENCE, handler.getSpaceReference(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(NAME, handler.getName(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute(IS_SPACE, handler.isSpace(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("availableTemplateProviders", handler.getAvailableTemplateProviders(), ScriptContext.ENGINE_SCOPE); scontext.setAttribute("recommendedTemplateProviders", handler.getRecommendedTemplateProviders(), ScriptContext.ENGINE_SCOPE); DocumentReference newDocumentReference = handler.getNewDocumentReference(); if (newDocumentReference == null) { return CREATE_TEMPLATE; } if (!handler.isTemplateProviderAllowedToCreateInCurrentSpace()) { return CREATE_TEMPLATE; } checkRights(newDocumentReference.getLastSpaceReference(), context); XWikiDocument newDocument = context.getWiki().getDocument(newDocumentReference, context); if (handler.isDocumentAlreadyExisting(newDocument) || handler.isDocumentPathTooLong(newDocumentReference) || !this.isEntityReferenceNameValid(newDocumentReference)) { return CREATE_TEMPLATE; } if (StringUtils.isBlank(handler.getType()) && !handler.hasTemplate()) { return CREATE_TEMPLATE; } doCreate(context, newDocument, handler.isSpace(), handler.getTemplateProvider()); return null; } CreateAction(); @Override String render(XWikiContext context);  }