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());
}
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()));
}
}
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()));
}
}
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());
}
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());
}
Aggregations