Search in sources :

Example 1 with MyfacesConfig

use of org.apache.myfaces.config.MyfacesConfig in project myfaces by apache.

the class DefaultELResolverBuilder method build.

@Override
public void build(FacesContext facesContext, CompositeELResolver compositeElResolver) {
    MyfacesConfig config = MyfacesConfig.getCurrentInstance(FacesContext.getCurrentInstance());
    // add the ELResolvers to a List first to be able to sort them
    List<ELResolver> list = new ArrayList<>();
    // Add CDI ELResolver for JSF 2.3
    if (isReplaceImplicitObjectResolverWithCDIResolver(facesContext)) {
        list.add(ImplicitObjectResolver.makeResolverForCDI());
        list.add(getCDIELResolver());
    } else {
        list.add(ImplicitObjectResolver.makeResolver());
    }
    list.add(new CompositeComponentELResolver(config));
    addFromRuntimeConfig(list);
    if ("true".equalsIgnoreCase(facesContext.getExternalContext().getInitParameter(UIInput.EMPTY_STRING_AS_NULL_PARAM_NAME))) {
        list.add(new EmptyStringToNullELResolver());
    }
    // Flash object is instanceof Map, so it is necessary to resolve
    // before MapELResolver. Better to put this one before
    list.add(new FlashELResolver());
    list.add(new ResourceResolver());
    list.add(new ResourceBundleELResolver());
    list.add(new ResourceBundleResolver());
    list.add(new ImportConstantsELResolver());
    if (STATIC_FIELD_EL_RESOLVER_CLASS != null && GET_STREAM_EL_RESOLVER_METHOD != null) {
        try {
            ELResolver streamElResolver = (ELResolver) GET_STREAM_EL_RESOLVER_METHOD.invoke(runtimeConfig.getExpressionFactory());
            if (streamElResolver != null) {
                // By default return null, but in a EL 3 implementation it should be there,
                // this is just to avoid exceptions in junit testing
                list.add(streamElResolver);
            }
            list.add((ELResolver) STATIC_FIELD_EL_RESOLVER_CLASS.newInstance());
        } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException ex) {
        }
    }
    list.add(new MapELResolver());
    list.add(new ListELResolver());
    list.add(new ArrayELResolver());
    if (PropertyDescriptorUtils.isUseLambdaMetafactory(facesContext.getExternalContext())) {
        list.add(new LambdaBeanELResolver());
    } else {
        list.add(new BeanELResolver());
    }
    // give the user a chance to sort the resolvers
    sortELResolvers(list);
    list = wrapELResolvers(list);
    // give the user a chance to filter the resolvers
    Iterable<ELResolver> filteredELResolvers = filterELResolvers(list);
    // add the resolvers from the list to the CompositeELResolver
    for (ELResolver resolver : filteredELResolvers) {
        compositeElResolver.add(resolver);
    }
    // Only add this resolver if the user wants to use the EL ImportHandler
    if (config.isSupportEL3ImportHandler()) {
        compositeElResolver.add(new ImportHandlerResolver());
    }
    // the ScopedAttributeResolver has to be the last one in every
    // case, because it always sets propertyResolved to true (per the spec)
    compositeElResolver.add(new ScopedAttributeResolver());
}
Also used : ArrayList(java.util.ArrayList) ListELResolver(jakarta.el.ListELResolver) ScopedAttributeResolver(org.apache.myfaces.el.resolver.ScopedAttributeResolver) LambdaBeanELResolver(org.apache.myfaces.el.resolver.LambdaBeanELResolver) CompositeComponentELResolver(org.apache.myfaces.el.resolver.CompositeComponentELResolver) MapELResolver(jakarta.el.MapELResolver) InvocationTargetException(java.lang.reflect.InvocationTargetException) BeanELResolver(jakarta.el.BeanELResolver) LambdaBeanELResolver(org.apache.myfaces.el.resolver.LambdaBeanELResolver) ELResolver(jakarta.el.ELResolver) MapELResolver(jakarta.el.MapELResolver) BeanELResolver(jakarta.el.BeanELResolver) ImportConstantsELResolver(org.apache.myfaces.el.resolver.ImportConstantsELResolver) EmptyStringToNullELResolver(org.apache.myfaces.el.resolver.EmptyStringToNullELResolver) CompositeELResolver(jakarta.el.CompositeELResolver) FlashELResolver(org.apache.myfaces.el.resolver.FlashELResolver) ListELResolver(jakarta.el.ListELResolver) CompositeComponentELResolver(org.apache.myfaces.el.resolver.CompositeComponentELResolver) ArrayELResolver(jakarta.el.ArrayELResolver) LambdaBeanELResolver(org.apache.myfaces.el.resolver.LambdaBeanELResolver) ResourceBundleELResolver(jakarta.el.ResourceBundleELResolver) ResourceBundleResolver(org.apache.myfaces.el.resolver.ResourceBundleResolver) FlashELResolver(org.apache.myfaces.el.resolver.FlashELResolver) ResourceResolver(org.apache.myfaces.el.resolver.ResourceResolver) ResourceBundleELResolver(jakarta.el.ResourceBundleELResolver) ImportHandlerResolver(org.apache.myfaces.el.resolver.ImportHandlerResolver) MyfacesConfig(org.apache.myfaces.config.MyfacesConfig) EmptyStringToNullELResolver(org.apache.myfaces.el.resolver.EmptyStringToNullELResolver) ImportConstantsELResolver(org.apache.myfaces.el.resolver.ImportConstantsELResolver) ArrayELResolver(jakarta.el.ArrayELResolver)

Example 2 with MyfacesConfig

use of org.apache.myfaces.config.MyfacesConfig in project myfaces by apache.

the class HtmlButtonRendererTest method testAllowedHtmlPropertyPassTru.

public void testAllowedHtmlPropertyPassTru() throws Exception {
    HtmlRenderedAttr[] attrs = { // _AccesskeyProperty
    new HtmlRenderedAttr("accesskey"), // _UniversalProperties
    new HtmlRenderedAttr("dir"), new HtmlRenderedAttr("lang"), new HtmlRenderedAttr("title"), new HtmlRenderedAttr("role"), // _FocusBlurProperties
    new HtmlRenderedAttr("onfocus"), new HtmlRenderedAttr("onblur"), // _ChangeSelectProperties
    new HtmlRenderedAttr("onchange"), new HtmlRenderedAttr("onselect"), // onclick is not allowed in this test case
    new HtmlRenderedAttr("onclick", "onclick", "onclick=\""), new HtmlRenderedAttr("ondblclick"), new HtmlRenderedAttr("onkeydown"), new HtmlRenderedAttr("onkeypress"), new HtmlRenderedAttr("onkeyup"), new HtmlRenderedAttr("onmousedown"), new HtmlRenderedAttr("onmousemove"), new HtmlRenderedAttr("onmouseout"), new HtmlRenderedAttr("onmouseover"), new HtmlRenderedAttr("onmouseup"), // _StyleProperties
    new HtmlRenderedAttr("style"), new HtmlRenderedAttr("styleClass", "styleClass", "class=\"styleClass\""), // _TabindexProperty
    new HtmlRenderedAttr("tabindex") };
    MockServletContext servletContext = new MockServletContext();
    MockExternalContext mockExtCtx = new MockExternalContext(servletContext, new MockHttpServletRequest(), new MockHttpServletResponse());
    MyfacesConfig config = MyfacesConfig.getCurrentInstance(mockExtCtx);
    facesContext.setExternalContext(mockExtCtx);
    HtmlCheckAttributesUtil.checkRenderedAttributes(commandButton, facesContext, writer, attrs);
    if (HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
        Assert.fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
    }
}
Also used : MockExternalContext(org.apache.myfaces.test.mock.MockExternalContext) MockHttpServletRequest(org.apache.myfaces.test.mock.MockHttpServletRequest) HtmlRenderedAttr(org.apache.myfaces.test.utils.HtmlRenderedAttr) MyfacesConfig(org.apache.myfaces.config.MyfacesConfig) MockServletContext(org.apache.myfaces.test.mock.MockServletContext) MockHttpServletResponse(org.apache.myfaces.test.mock.MockHttpServletResponse)

Example 3 with MyfacesConfig

use of org.apache.myfaces.config.MyfacesConfig in project myfaces by apache.

the class HtmlButtonRendererTest method testJSNotAllowedHtmlPropertyPassTru.

public void testJSNotAllowedHtmlPropertyPassTru() throws Exception {
    HtmlRenderedAttr[] attrs = { // _AccesskeyProperty
    new HtmlRenderedAttr("accesskey"), // _UniversalProperties
    new HtmlRenderedAttr("dir"), new HtmlRenderedAttr("lang"), new HtmlRenderedAttr("title"), new HtmlRenderedAttr("role"), // _StyleProperties
    new HtmlRenderedAttr("style"), new HtmlRenderedAttr("styleClass", "styleClass", "class=\"styleClass\""), // _TabindexProperty
    new HtmlRenderedAttr("tabindex") };
    MockServletContext servletContext = new MockServletContext();
    MockExternalContext mockExtCtx = new MockExternalContext(servletContext, new MockHttpServletRequest(), new MockHttpServletResponse());
    MyfacesConfig config = MyfacesConfig.getCurrentInstance(mockExtCtx);
    facesContext.setExternalContext(mockExtCtx);
    HtmlCheckAttributesUtil.checkRenderedAttributes(commandButton, facesContext, writer, attrs);
    if (HtmlCheckAttributesUtil.hasFailedAttrRender(attrs)) {
        Assert.fail(HtmlCheckAttributesUtil.constructErrorMessage(attrs, writer.getWriter().toString()));
    }
}
Also used : MockExternalContext(org.apache.myfaces.test.mock.MockExternalContext) MockHttpServletRequest(org.apache.myfaces.test.mock.MockHttpServletRequest) HtmlRenderedAttr(org.apache.myfaces.test.utils.HtmlRenderedAttr) MyfacesConfig(org.apache.myfaces.config.MyfacesConfig) MockServletContext(org.apache.myfaces.test.mock.MockServletContext) MockHttpServletResponse(org.apache.myfaces.test.mock.MockHttpServletResponse)

Example 4 with MyfacesConfig

use of org.apache.myfaces.config.MyfacesConfig in project myfaces by apache.

the class HtmlRenderKitImplTest method testCreateResponseWriterContentType2.

@Test
public void testCreateResponseWriterContentType2() {
    servletContext.setInitParameter(MyfacesConfig.DEFAULT_RESPONSE_WRITER_CONTENT_TYPE_MODE, ContentTypeUtils.XHTML_CONTENT_TYPE);
    MyfacesConfig config = MyfacesConfig.getCurrentInstance(facesContext);
    facesContext.getExternalContext().getApplicationMap().put(MyfacesConfig.class.getName(), config);
    HtmlRenderKitImpl renderKit = new HtmlRenderKitImpl();
    StringWriter writer = new StringWriter();
    HtmlResponseWriterImpl responseWriter = (HtmlResponseWriterImpl) renderKit.createResponseWriter(writer, null, null);
    Assert.assertEquals(ContentTypeUtils.XHTML_CONTENT_TYPE, responseWriter.getContentType());
    Assert.assertEquals(ContentTypeUtils.XHTML_CONTENT_TYPE, responseWriter.getWriterContentTypeMode());
}
Also used : StringWriter(java.io.StringWriter) HtmlResponseWriterImpl(org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl) MyfacesConfig(org.apache.myfaces.config.MyfacesConfig) HtmlRenderKitImpl(org.apache.myfaces.renderkit.html.HtmlRenderKitImpl) Test(org.junit.Test)

Example 5 with MyfacesConfig

use of org.apache.myfaces.config.MyfacesConfig in project myfaces by apache.

the class HtmlRenderKitImplTest method testCreateResponseWriterContentType8.

@Test
public void testCreateResponseWriterContentType8() {
    MyfacesConfig config = new MyfacesConfig();
    facesContext.getExternalContext().getApplicationMap().put(MyfacesConfig.class.getName(), config);
    request.addHeader("Accept", "text/html, application/xml;q=0.9, application/xhtml+xml;q=0.9, image/png, " + // Opera
    "image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1");
    HtmlRenderKitImpl renderKit = new HtmlRenderKitImpl();
    StringWriter writer = new StringWriter();
    HtmlResponseWriterImpl responseWriter = (HtmlResponseWriterImpl) renderKit.createResponseWriter(writer, null, null);
    Assert.assertEquals(ContentTypeUtils.HTML_CONTENT_TYPE, responseWriter.getContentType());
    Assert.assertEquals(ContentTypeUtils.HTML_CONTENT_TYPE, responseWriter.getWriterContentTypeMode());
}
Also used : StringWriter(java.io.StringWriter) HtmlResponseWriterImpl(org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl) MyfacesConfig(org.apache.myfaces.config.MyfacesConfig) HtmlRenderKitImpl(org.apache.myfaces.renderkit.html.HtmlRenderKitImpl) Test(org.junit.Test)

Aggregations

MyfacesConfig (org.apache.myfaces.config.MyfacesConfig)21 StringWriter (java.io.StringWriter)9 HtmlRenderKitImpl (org.apache.myfaces.renderkit.html.HtmlRenderKitImpl)9 HtmlResponseWriterImpl (org.apache.myfaces.renderkit.html.HtmlResponseWriterImpl)9 Test (org.junit.Test)9 ExternalContext (jakarta.faces.context.ExternalContext)3 ArrayList (java.util.ArrayList)3 FacesContext (jakarta.faces.context.FacesContext)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MockExternalContext (org.apache.myfaces.test.mock.MockExternalContext)2 MockHttpServletRequest (org.apache.myfaces.test.mock.MockHttpServletRequest)2 MockHttpServletResponse (org.apache.myfaces.test.mock.MockHttpServletResponse)2 MockServletContext (org.apache.myfaces.test.mock.MockServletContext)2 HtmlRenderedAttr (org.apache.myfaces.test.utils.HtmlRenderedAttr)2 ArrayELResolver (jakarta.el.ArrayELResolver)1 BeanELResolver (jakarta.el.BeanELResolver)1 CompositeELResolver (jakarta.el.CompositeELResolver)1 ELResolver (jakarta.el.ELResolver)1 ListELResolver (jakarta.el.ListELResolver)1 MapELResolver (jakarta.el.MapELResolver)1