@Test public void existingDocumentFromUIDeprecatedCheckEscaping() throws Exception { DocumentReference documentReference = new DocumentReference("xwiki", Arrays.asList("Main"), "WebHome"); XWikiDocument document = mock(XWikiDocument.class); when(document.getDocumentReference()).thenReturn(documentReference); when(document.isNew()).thenReturn(false); when(document.getLocalReferenceMaxLength()).thenReturn(255); context.setDoc(document); when(mockRequest.getParameter("space")).thenReturn("X.Y"); when(mockRequest.getParameter("page")).thenReturn("Z"); String result = action.render(context); assertNull(result); verify(mockURLFactory).createURL("X\\.Y", "Z", "edit", "template=&parent=Main.WebHome&title=Z", null, "xwiki", 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);  }