Search in sources :

Example 16 with XWikiRequest

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);
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) LESSContext(org.xwiki.lesscss.internal.LESSContext) XWikiContext(com.xpn.xwiki.XWikiContext) ActionExecutingEvent(org.xwiki.bridge.event.ActionExecutingEvent) Test(org.junit.Test)

Example 17 with XWikiRequest

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);
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) LESSContext(org.xwiki.lesscss.internal.LESSContext) XWikiContext(com.xpn.xwiki.XWikiContext) ActionExecutingEvent(org.xwiki.bridge.event.ActionExecutingEvent) Test(org.junit.Test)

Example 18 with XWikiRequest

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);
    }
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) XWikiContext(com.xpn.xwiki.XWikiContext)

Example 19 with XWikiRequest

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;
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 20 with XWikiRequest

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;
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ToString(org.suigeneris.jrcs.util.ToString) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

XWikiRequest (com.xpn.xwiki.web.XWikiRequest)21 XWikiContext (com.xpn.xwiki.XWikiContext)6 XWiki (com.xpn.xwiki.XWiki)4 IOException (java.io.IOException)4 Cookie (javax.servlet.http.Cookie)4 XWikiException (com.xpn.xwiki.XWikiException)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)3 BaseObject (com.xpn.xwiki.objects.BaseObject)3 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)3 Date (java.util.Date)3 Test (org.junit.Test)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 FileNotFoundException (java.io.FileNotFoundException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2 NamingException (javax.naming.NamingException)2 HttpSession (javax.servlet.http.HttpSession)2 URIException (org.apache.commons.httpclient.URIException)2