Remove remaining Portlet references

Issue: SWF-1692
This commit is contained in:
Rossen Stoyanchev
2017-01-06 11:58:05 -05:00
parent 5b0df65be4
commit 3a0857496e
25 changed files with 83 additions and 932 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2004-2012 the original author or authors.
* Copyright 2004-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,17 +18,17 @@ package org.springframework.faces.config;
import java.util.Map;
import org.w3c.dom.Element;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.faces.webflow.JsfRuntimeInformation;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;
import org.w3c.dom.Element;
/**
* Parser for the resources tag.
@@ -39,101 +39,57 @@ import org.w3c.dom.Element;
*/
public class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
static final String SERVLET_RESOURCE_HANDLER_BEAN_NAME = "jsfResourceRequestHandler";
static final String PORTLET_RESOURCE_HANDLER_BEAN_NAME = "jsfPortletResourceRequestHandler";
private static final String SERVLET_RESOURCE_HANDLER_BEAN_NAME = "jsfResourceRequestHandler";
private static final boolean isRichFacesPresent =
ClassUtils.isPresent("org.richfaces.application.CoreConfiguration",
ResourcesBeanDefinitionParser.class.getClassLoader());
public BeanDefinition parse(Element element, ParserContext parserContext) {
new ServletRegistrar(element, parserContext).register();
if (JsfRuntimeInformation.isSpringPortletPresent()) {
new PortletRegistrar(element, parserContext).register();
}
Object source = parserContext.extractSource(element);
registerHandlerAdapterIfNecessary(source, parserContext);
registerResourceHandler(source, parserContext);
registerHandlerMappings(element, source, parserContext);
return null;
}
private static abstract class Registrar {
protected final Element element;
protected final ParserContext parserContext;
protected final Object source;
public Registrar(Element element, ParserContext parserContext) {
this.element = element;
this.parserContext = parserContext;
this.source = parserContext.extractSource(element);
private void registerHandlerAdapterIfNecessary(Object source, ParserContext parserContext) {
String beanName = "org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter";
if (parserContext.getRegistry().containsBeanDefinition(beanName)) {
return;
}
public abstract void register();
RootBeanDefinition beanDefinition = new RootBeanDefinition(HttpRequestHandlerAdapter.class);
beanDefinition.setSource(source);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getReaderContext().registerWithGeneratedName(beanDefinition);
}
private static class ServletRegistrar extends Registrar {
public ServletRegistrar(Element element, ParserContext parserContext) {
super(element, parserContext);
}
@Override
public void register() {
registerHandlerAdapterIfNecessary();
registerResourceHandler();
registerHandlerMappings();
}
private void registerHandlerAdapterIfNecessary() {
if (parserContext.getRegistry().containsBeanDefinition("org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter")) {
return;
}
RootBeanDefinition beanDefinition = new RootBeanDefinition(HttpRequestHandlerAdapter.class);
beanDefinition.setSource(source);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getReaderContext().registerWithGeneratedName(beanDefinition);
}
private void registerResourceHandler() {
RootBeanDefinition beanDefinition = new RootBeanDefinition("org.springframework.faces.webflow.JsfResourceRequestHandler");
beanDefinition.setSource(source);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getRegistry().registerBeanDefinition(SERVLET_RESOURCE_HANDLER_BEAN_NAME, beanDefinition);
}
private void registerHandlerMappings() {
Map<String, String> urlMap = new ManagedMap<String, String>();
urlMap.put("/javax.faces.resource/**", SERVLET_RESOURCE_HANDLER_BEAN_NAME);
if (isRichFacesPresent) {
urlMap.put("/rfRes/**", SERVLET_RESOURCE_HANDLER_BEAN_NAME);
}
RootBeanDefinition beanDefinition = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
beanDefinition.setSource(source);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
beanDefinition.getPropertyValues().add("urlMap", urlMap);
String order = element.getAttribute("order");
beanDefinition.getPropertyValues().add("order", StringUtils.hasText(order) ? order : 0);
parserContext.getReaderContext().registerWithGeneratedName(beanDefinition);
}
private void registerResourceHandler(Object source, ParserContext parserContext) {
String beanName = "org.springframework.faces.webflow.JsfResourceRequestHandler";
RootBeanDefinition beanDefinition = new RootBeanDefinition(beanName);
beanDefinition.setSource(source);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getRegistry().registerBeanDefinition(SERVLET_RESOURCE_HANDLER_BEAN_NAME, beanDefinition);
}
private static class PortletRegistrar extends Registrar {
private void registerHandlerMappings(Element element, Object source, ParserContext parserContext) {
Map<String, String> urlMap = new ManagedMap<String, String>();
urlMap.put("/javax.faces.resource/**", SERVLET_RESOURCE_HANDLER_BEAN_NAME);
public PortletRegistrar(Element element, ParserContext parserContext) {
super(element, parserContext);
if (isRichFacesPresent) {
urlMap.put("/rfRes/**", SERVLET_RESOURCE_HANDLER_BEAN_NAME);
}
@Override
public void register() {
RootBeanDefinition beanDefinition = new RootBeanDefinition("org.springframework.faces.webflow.context.portlet.JsfResourceRequestHandler");
beanDefinition.setSource(source);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
parserContext.getRegistry().registerBeanDefinition(PORTLET_RESOURCE_HANDLER_BEAN_NAME, beanDefinition);
}
RootBeanDefinition beanDefinition = new RootBeanDefinition(SimpleUrlHandlerMapping.class);
beanDefinition.setSource(source);
beanDefinition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
beanDefinition.getPropertyValues().add("urlMap", urlMap);
String order = element.getAttribute("order");
beanDefinition.getPropertyValues().add("order", StringUtils.hasText(order) ? order : 0);
parserContext.getReaderContext().registerWithGeneratedName(beanDefinition);
}
}

View File

@@ -15,10 +15,7 @@
*/
package org.springframework.faces.mvc;
import static org.springframework.faces.webflow.JsfRuntimeInformation.isPortletRequest;
import java.util.Map;
import javax.faces.application.ViewHandler;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
@@ -60,10 +57,7 @@ public class JsfView extends AbstractUrlBasedView {
JsfUtils.notifyBeforeListeners(PhaseId.RESTORE_VIEW, this.facesLifecycle, facesContext);
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
if (!isPortletRequest(facesContext)) {
viewHandler.initView(facesContext);
}
viewHandler.initView(facesContext);
UIViewRoot viewRoot = viewHandler.createView(facesContext, getUrl());
Assert.notNull(viewRoot, "A JSF view could not be created for " + getUrl());

View File

@@ -66,8 +66,7 @@ public class FacesContextHelper {
}
/**
* Factory method that can be used to create a new default {@link FacesContext} instance for the running
* (Portlet/Servlet) environment.
* Factory method that can be used to create a new default {@link FacesContext} instance.
*
* @param context the native context
* @param request the native request

View File

@@ -20,10 +20,8 @@ import javax.faces.FacesWrapper;
import javax.faces.FactoryFinder;
import javax.faces.context.FacesContext;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.webflow.execution.RequestContext;
/**
* Helper class to provide information about the JSF runtime environment such as
@@ -80,12 +78,6 @@ public class JsfRuntimeInformation {
private static boolean myFacesInUse = isMyFacesContextFactoryInUse();
private static boolean portletPresent = ClassUtils.isPresent("javax.portlet.Portlet", CLASSLOADER);
private static boolean springPortletPresent =
ClassUtils.isPresent("org.springframework.web.portlet.DispatcherPortlet", CLASSLOADER);
public static boolean isAtLeastJsf22() {
return jsfVersion >= JSF_22;
@@ -143,46 +135,4 @@ public class JsfRuntimeInformation {
}
}
/**
* Determines if the container has support for portlets and if Spring MVC portlet support is available
*
* @return <tt>true</tt> if a portlet environment is detected
*/
public static boolean isSpringPortletPresent() {
return portletPresent && springPortletPresent;
}
/**
* Determine if the specified {@link FacesContext} is from a portlet request.
* @param context the faces context
* @return <tt>true</tt> if the request is from a portlet
*/
public static boolean isPortletRequest(FacesContext context) {
Assert.notNull(context, "Context must not be null");
return isPortletContext(context.getExternalContext().getContext());
}
/**
* Determine if the specified {@link RequestContext} is from a portlet request.
*
* @param context the request context
* @return <tt>true</tt> if the request is from a portlet
*/
public static boolean isPortletRequest(RequestContext context) {
Assert.notNull(context, "Context must not be null");
return isPortletContext(context.getExternalContext().getNativeContext());
}
/**
* Determine if the specified context object is from portlet.
*
* @param nativeContext the native context
* @return <tt>true</tt> if the context is from a portlet
*/
public static boolean isPortletContext(Object nativeContext) {
Assert.notNull(nativeContext, "Context must not be null");
return ClassUtils.getMethodIfAvailable(nativeContext.getClass(), "getPortletContextName") != null;
}
}

View File

@@ -41,7 +41,6 @@ import org.springframework.webflow.execution.View;
import org.springframework.webflow.execution.ViewFactory;
import static org.springframework.faces.webflow.JsfRuntimeInformation.isMojarraPresent;
import static org.springframework.faces.webflow.JsfRuntimeInformation.isPortletRequest;
/**
* JSF-specific {@link ViewFactory} implementation.
@@ -107,9 +106,7 @@ public class JsfViewFactory implements ViewFactory {
private ViewHandler getViewHandler(FacesContext facesContext) {
ViewHandler viewHandler = facesContext.getApplication().getViewHandler();
if (!isPortletRequest(facesContext)) {
viewHandler.initView(facesContext);
}
viewHandler.initView(facesContext);
return viewHandler;
}

View File

@@ -13,7 +13,6 @@
<factory>
<application-factory>org.springframework.faces.webflow.FlowApplicationFactory</application-factory>
<faces-context-factory>org.springframework.faces.webflow.context.portlet.PortletFacesContextFactory</faces-context-factory>
</factory>
<lifecycle>

View File

@@ -26,7 +26,7 @@ public abstract class AbstractResourcesConfigurationTests extends TestCase {
Map<String, ?> map = this.context.getBeansOfType(HttpRequestHandlerAdapter.class);
assertEquals(1, map.values().size());
Object resourceHandler = this.context.getBean(ResourcesBeanDefinitionParser.SERVLET_RESOURCE_HANDLER_BEAN_NAME);
Object resourceHandler = this.context.getBean("jsfResourceRequestHandler");
assertNotNull(resourceHandler);
assertTrue(resourceHandler instanceof JsfResourceRequestHandler);