Search in sources :

Example 6 with LocaleProviderFactory

use of com.opensymphony.xwork2.LocaleProviderFactory in project struts by apache.

the class StrutsTilesLocaleResolver method resolveLocale.

@Override
public Locale resolveLocale(Request request) {
    HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest();
    ActionContext ctx = ServletActionContext.getActionContext(httpRequest);
    if (ctx == null) {
        LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName());
        throw new ConfigurationException("There is no ActionContext for current request!");
    }
    LocaleProviderFactory localeProviderFactory = ctx.getInstance(LocaleProviderFactory.class);
    return localeProviderFactory.createLocaleProvider().getLocale();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ActionContext(com.opensymphony.xwork2.ActionContext) ServletActionContext(org.apache.struts2.ServletActionContext) LocaleProviderFactory(com.opensymphony.xwork2.LocaleProviderFactory)

Example 7 with LocaleProviderFactory

use of com.opensymphony.xwork2.LocaleProviderFactory in project struts by apache.

the class Dispatcher method wrapRequest.

/**
 * <p>
 * Wrap and return the given request or return the original request object.
 * </p>
 *
 * <p>
 * This method transparently handles multipart data as a wrapped class around the given request.
 * Override this method to handle multipart requests in a special way or to handle other types of requests.
 * Note, {@link org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper} is
 * flexible - look first to that object before overriding this method to handle multipart data.
 * </p>
 *
 * @param request the HttpServletRequest object.
 * @return a wrapped request or original request.
 * @throws java.io.IOException on any error.
 * @see org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper
 * @since 2.3.17
 */
public HttpServletRequest wrapRequest(HttpServletRequest request) throws IOException {
    // don't wrap more than once
    if (request instanceof StrutsRequestWrapper) {
        return request;
    }
    if (isMultipartSupportEnabled(request) && isMultipartRequest(request)) {
        MultiPartRequest multiPartRequest = getMultiPartRequest();
        LocaleProviderFactory localeProviderFactory = getContainer().getInstance(LocaleProviderFactory.class);
        request = new MultiPartRequestWrapper(multiPartRequest, request, getSaveDir(), localeProviderFactory.createLocaleProvider(), disableRequestAttributeValueStackLookup);
    } else {
        request = new StrutsRequestWrapper(request, disableRequestAttributeValueStackLookup);
    }
    return request;
}
Also used : MultiPartRequest(org.apache.struts2.dispatcher.multipart.MultiPartRequest) MultiPartRequestWrapper(org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper) LocaleProviderFactory(com.opensymphony.xwork2.LocaleProviderFactory)

Aggregations

LocaleProviderFactory (com.opensymphony.xwork2.LocaleProviderFactory)7 Container (com.opensymphony.xwork2.inject.Container)4 AppConfig (org.gbif.ipt.config.AppConfig)4 DefaultLocaleProviderFactory (com.opensymphony.xwork2.DefaultLocaleProviderFactory)3 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Resource (org.gbif.ipt.model.Resource)3 RegistrationManager (org.gbif.ipt.service.admin.RegistrationManager)3 ResourceManager (org.gbif.ipt.service.manage.ResourceManager)3 SimpleTextProvider (org.gbif.ipt.struts2.SimpleTextProvider)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ActionContext (com.opensymphony.xwork2.ActionContext)2 File (java.io.File)2 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 DataDir (org.gbif.ipt.config.DataDir)2 VersionHistory (org.gbif.ipt.model.VersionHistory)2 VocabulariesManager (org.gbif.ipt.service.admin.VocabulariesManager)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 LocaleProvider (com.opensymphony.xwork2.LocaleProvider)1