use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class LESSExportActionListenerTest method onEventWhenHTMLExport.
@Test
public void onEventWhenHTMLExport() throws Exception {
XWikiContext xcontext = mock(XWikiContext.class);
XWikiRequest request = mock(XWikiRequest.class);
when(xcontext.getRequest()).thenReturn(request);
when(request.get("format")).thenReturn("html");
this.mocker.getComponentUnderTest().onEvent(new ActionExecutingEvent("export"), null, xcontext);
// The test is here: we verify that the cache is disabled!
LESSContext lessContext = mocker.getInstance(LESSContext.class);
verify(lessContext).setHtmlExport(true);
}
use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class LESSExportActionListenerTest method onEventWhenNonHTMLExport.
@Test
public void onEventWhenNonHTMLExport() throws Exception {
XWikiContext xcontext = mock(XWikiContext.class);
XWikiRequest request = mock(XWikiRequest.class);
when(xcontext.getRequest()).thenReturn(request);
when(request.get("format")).thenReturn("xar");
this.mocker.getComponentUnderTest().onEvent(new ActionExecutingEvent("export"), null, xcontext);
// The test is here: we verify that the we do not disable the LESS cache (since the export is not an HTML
// export). Actually that the context object was not called at all...
LESSContext lessContext = mocker.getInstance(LESSContext.class);
verifyZeroInteractions(lessContext);
}
use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class LESSExportActionListener method onEvent.
@Override
public void onEvent(Event event, Object source, Object data) {
// Do not use the the LESS cache if we're doing an HTML export because we need that URLs located in less file be
// recomputed (see ExportURLFactory).
XWikiContext xcontext = (XWikiContext) data;
XWikiRequest request = xcontext.getRequest();
String format = request.get("format");
if ("html".equals(format)) {
lessContext.setHtmlExport(true);
}
}
use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class CurrentColorThemeGetter method getCurrentColorTheme.
/**
* @param checkRights check if the user has the right to see the color theme
* @param fallbackValue value to return if the current color theme is invalid
* @return the full name of the current color theme or fallbackValue if the current color theme is invalid
* @since 7.0-M2
*/
public String getCurrentColorTheme(boolean checkRights, String fallbackValue) {
// Get information about the context
String wikiId = wikiDescriptorManager.getCurrentWikiId();
XWikiContext context = xcontextProvider.get();
XWiki xwiki = context.getWiki();
XWikiRequest request = context.getRequest();
// Get the current color theme
String colorTheme = request.getParameter(COLOR_THEME_FIELD);
if (StringUtils.isEmpty(colorTheme)) {
// Get it from the preferences
colorTheme = xwiki.getUserPreference(COLOR_THEME_FIELD, context);
}
// Getting the full name representation of colorTheme
DocumentReference colorThemeReference = documentReferenceResolver.resolve(colorTheme, new WikiReference(wikiId));
colorTheme = entityReferenceSerializer.serialize(colorThemeReference);
// Also check that the user has the right to see the color theme
if (!xwiki.exists(colorThemeReference, context) || (checkRights && !authorizationManager.hasAccess(Right.VIEW, context.getUserReference(), colorThemeReference))) {
colorTheme = fallbackValue;
}
return colorTheme;
}
use of com.xpn.xwiki.web.XWikiRequest in project xwiki-platform by xwiki.
the class XWikiDocument method validate.
public boolean validate(String[] classNames, XWikiContext context) throws XWikiException {
boolean isValid = true;
if ((classNames == null) || (classNames.length == 0)) {
for (DocumentReference classReference : getXObjects().keySet()) {
BaseClass bclass = context.getWiki().getXClass(classReference, context);
List<BaseObject> objects = getXObjects(classReference);
for (BaseObject obj : objects) {
if (obj != null) {
isValid &= bclass.validateObject(obj, context);
}
}
}
} else {
for (String className : classNames) {
List<BaseObject> objects = getXObjects(getCurrentMixedDocumentReferenceResolver().resolve(className));
if (objects != null) {
for (BaseObject obj : objects) {
if (obj != null) {
BaseClass bclass = obj.getXClass(context);
isValid &= bclass.validateObject(obj, context);
}
}
}
}
}
String validationScript = "";
XWikiRequest req = context.getRequest();
if (req != null) {
validationScript = req.get("xvalidation");
}
if ((validationScript == null) || (validationScript.trim().equals(""))) {
validationScript = getValidationScript();
}
if ((validationScript != null) && (!validationScript.trim().equals(""))) {
isValid &= executeValidationScript(context, validationScript);
}
return isValid;
}
Aggregations