From 4027bda168ecef2f0235686e93d399726ec2aced Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 4 Jul 2016 23:30:11 +0200 Subject: [PATCH] Remove Tiles 2 support Issue: SPR-13229 --- .../tiles2/AbstractSpringPreparerFactory.java | 69 --- .../tiles2/SimpleSpringPreparerFactory.java | 76 --- .../tiles2/SpringBeanPreparerFactory.java | 47 -- .../view/tiles2/SpringLocaleResolver.java | 65 --- ...ildcardServletTilesApplicationContext.java | 77 --- .../servlet/view/tiles2/TilesConfigurer.java | 442 ------------------ .../web/servlet/view/tiles2/TilesView.java | 115 ----- .../view/tiles2/TilesViewResolver.java | 86 ---- .../web/servlet/view/tiles2/package-info.java | 10 - .../view/tiles2/TilesConfigurerTests.java | 54 --- .../src/test/resources/log4j.properties | 10 - .../servlet/view/tiles2/tiles-definitions.xml | 10 - 12 files changed, 1061 deletions(-) delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/AbstractSpringPreparerFactory.java delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SimpleSpringPreparerFactory.java delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringBeanPreparerFactory.java delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringLocaleResolver.java delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringWildcardServletTilesApplicationContext.java delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesViewResolver.java delete mode 100644 spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/package-info.java delete mode 100644 spring-webmvc-tiles2/src/test/java/org/springframework/web/servlet/view/tiles2/TilesConfigurerTests.java delete mode 100644 spring-webmvc-tiles2/src/test/resources/log4j.properties delete mode 100644 spring-webmvc-tiles2/src/test/resources/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/AbstractSpringPreparerFactory.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/AbstractSpringPreparerFactory.java deleted file mode 100644 index 0801804d45d2..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/AbstractSpringPreparerFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import org.apache.tiles.TilesException; -import org.apache.tiles.context.TilesRequestContext; -import org.apache.tiles.preparer.PreparerFactory; -import org.apache.tiles.preparer.ViewPreparer; - -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; - -/** - * Abstract implementation of the Tiles {@link org.apache.tiles.preparer.PreparerFactory} - * interface, obtaining the current Spring WebApplicationContext and delegating to - * {@link #getPreparer(String, org.springframework.web.context.WebApplicationContext)}. - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed - * as of Spring Framework 5.0.. - * - * @author Juergen Hoeller - * @since 2.5 - * @see #getPreparer(String, org.springframework.web.context.WebApplicationContext) - * @see SimpleSpringPreparerFactory - * @see SpringBeanPreparerFactory - * @deprecated as of Spring 4.2, in favor of Tiles 3 - */ -@Deprecated -public abstract class AbstractSpringPreparerFactory implements PreparerFactory { - - @Override - public ViewPreparer getPreparer(String name, TilesRequestContext context) throws TilesException { - WebApplicationContext webApplicationContext = (WebApplicationContext) context.getRequestScope().get( - DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE); - if (webApplicationContext == null) { - webApplicationContext = (WebApplicationContext) context.getApplicationContext().getApplicationScope().get( - WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); - if (webApplicationContext == null) { - throw new IllegalStateException("No WebApplicationContext found: no ContextLoaderListener registered?"); - } - } - return getPreparer(name, webApplicationContext); - } - - /** - * Obtain a preparer instance for the given preparer name, - * based on the given Spring WebApplicationContext. - * @param name the name of the preparer - * @param context the current Spring WebApplicationContext - * @return the preparer instance - * @throws TilesException in case of failure - */ - protected abstract ViewPreparer getPreparer(String name, WebApplicationContext context) throws TilesException; - -} diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SimpleSpringPreparerFactory.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SimpleSpringPreparerFactory.java deleted file mode 100644 index 05292d6dfce4..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SimpleSpringPreparerFactory.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2002-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.tiles.TilesException; -import org.apache.tiles.preparer.NoSuchPreparerException; -import org.apache.tiles.preparer.PreparerException; -import org.apache.tiles.preparer.ViewPreparer; - -import org.springframework.web.context.WebApplicationContext; - -/** - * Tiles {@link org.apache.tiles.preparer.PreparerFactory} implementation - * that expects preparer class names and builds preparer instances for those, - * creating them through the Spring ApplicationContext in order to apply - * Spring container callbacks and configured Spring BeanPostProcessors. - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed - * as of Spring Framework 5.0.. - * - * @author Juergen Hoeller - * @since 2.5 - * @see SpringBeanPreparerFactory - * @deprecated as of Spring 4.2, in favor of Tiles 3 - */ -@Deprecated -public class SimpleSpringPreparerFactory extends AbstractSpringPreparerFactory { - - /** Cache of shared ViewPreparer instances: bean name -> bean instance */ - private final Map sharedPreparers = new ConcurrentHashMap(16); - - - @Override - protected ViewPreparer getPreparer(String name, WebApplicationContext context) throws TilesException { - // Quick check on the concurrent map first, with minimal locking. - ViewPreparer preparer = this.sharedPreparers.get(name); - if (preparer == null) { - synchronized (this.sharedPreparers) { - preparer = this.sharedPreparers.get(name); - if (preparer == null) { - try { - Class beanClass = context.getClassLoader().loadClass(name); - if (!ViewPreparer.class.isAssignableFrom(beanClass)) { - throw new PreparerException( - "Invalid preparer class [" + name + "]: does not implement ViewPreparer interface"); - } - preparer = (ViewPreparer) context.getAutowireCapableBeanFactory().createBean(beanClass); - this.sharedPreparers.put(name, preparer); - } - catch (ClassNotFoundException ex) { - throw new NoSuchPreparerException("Preparer class [" + name + "] not found", ex); - } - } - } - } - return preparer; - } - -} diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringBeanPreparerFactory.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringBeanPreparerFactory.java deleted file mode 100644 index fc9ff0a8d467..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringBeanPreparerFactory.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2002-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import org.apache.tiles.TilesException; -import org.apache.tiles.preparer.ViewPreparer; - -import org.springframework.web.context.WebApplicationContext; - -/** - * Tiles {@link org.apache.tiles.preparer.PreparerFactory} implementation - * that expects preparer bean names and obtains preparer beans from the - * Spring ApplicationContext. The full bean creation process will be in - * the control of the Spring application context in this case, allowing - * for the use of scoped beans etc. - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed - * as of Spring Framework 5.0.. - * - * @author Juergen Hoeller - * @since 2.5 - * @see SimpleSpringPreparerFactory - * @deprecated as of Spring 4.2, in favor of Tiles 3 - */ -@Deprecated -public class SpringBeanPreparerFactory extends AbstractSpringPreparerFactory { - - @Override - protected ViewPreparer getPreparer(String name, WebApplicationContext context) throws TilesException { - return context.getBean(name, ViewPreparer.class); - } - -} diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringLocaleResolver.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringLocaleResolver.java deleted file mode 100644 index 39daf47b0123..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringLocaleResolver.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2002-2009 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import java.util.Locale; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.jsp.PageContext; - -import org.apache.tiles.context.TilesRequestContext; -import org.apache.tiles.jsp.context.JspTilesRequestContext; -import org.apache.tiles.locale.impl.DefaultLocaleResolver; -import org.apache.tiles.servlet.context.ServletTilesRequestContext; - -import org.springframework.web.servlet.support.RequestContextUtils; - -/** - * Tiles LocaleResolver adapter that delegates to a Spring - * {@link org.springframework.web.servlet.LocaleResolver}, - * exposing the DispatcherServlet-managed locale. - * - *

This adapter gets automatically registered by {@link TilesConfigurer}. - * If you are using standard Tiles bootstrap, specify the name of this class - * as value for the init-param "org.apache.tiles.locale.LocaleResolver". - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed - * as of Spring Framework 5.0.. - * - * @author Juergen Hoeller - * @since 2.5 - * @see org.apache.tiles.definition.UrlDefinitionsFactory#LOCALE_RESOLVER_IMPL_PROPERTY - * @deprecated as of Spring 4.2, in favor of Tiles 3 - */ -@Deprecated -public class SpringLocaleResolver extends DefaultLocaleResolver { - - @Override - public Locale resolveLocale(TilesRequestContext context) { - if (context instanceof JspTilesRequestContext) { - PageContext pc = ((JspTilesRequestContext) context).getPageContext(); - return RequestContextUtils.getLocale((HttpServletRequest) pc.getRequest()); - } - else if (context instanceof ServletTilesRequestContext) { - HttpServletRequest request = ((ServletTilesRequestContext) context).getRequest(); - if (request != null) { - return RequestContextUtils.getLocale(request); - } - } - return super.resolveLocale(context); - } - -} diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringWildcardServletTilesApplicationContext.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringWildcardServletTilesApplicationContext.java deleted file mode 100644 index 488dde4d6655..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/SpringWildcardServletTilesApplicationContext.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2002-2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import java.io.IOException; -import java.net.URL; -import java.util.LinkedHashSet; -import java.util.Set; -import javax.servlet.ServletContext; - -import org.apache.tiles.servlet.context.ServletTilesApplicationContext; - -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.util.CollectionUtils; -import org.springframework.util.ObjectUtils; -import org.springframework.web.context.support.ServletContextResourcePatternResolver; - -/** - * Spring-specific subclass of the Tiles ServletTilesApplicationContext. - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed - * as of Spring Framework 5.0.. - * - * @author Juergen Hoeller - * @since 4.0.1 - * @deprecated as of Spring 4.2, in favor of Tiles 3 - */ -@Deprecated -public class SpringWildcardServletTilesApplicationContext extends ServletTilesApplicationContext { - - private final ResourcePatternResolver resolver; - - - public SpringWildcardServletTilesApplicationContext(ServletContext servletContext) { - super(servletContext); - this.resolver = new ServletContextResourcePatternResolver(servletContext); - } - - - @Override - public URL getResource(String path) throws IOException { - Set urlSet = getResources(path); - if (!CollectionUtils.isEmpty(urlSet)) { - return urlSet.iterator().next(); - } - return null; - } - - @Override - public Set getResources(String path) throws IOException { - Set urlSet = null; - Resource[] resources = this.resolver.getResources(path); - if (!ObjectUtils.isEmpty(resources)) { - urlSet = new LinkedHashSet(resources.length); - for (Resource resource : resources) { - urlSet.add(resource.getURL()); - } - } - return urlSet; - } - -} diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java deleted file mode 100644 index 719c4510ef9c..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesConfigurer.java +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Copyright 2002-2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import java.io.IOException; -import java.net.URL; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import javax.servlet.ServletContext; -import javax.servlet.jsp.JspFactory; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tiles.TilesApplicationContext; -import org.apache.tiles.TilesException; -import org.apache.tiles.awareness.TilesApplicationContextAware; -import org.apache.tiles.context.TilesRequestContextFactory; -import org.apache.tiles.definition.DefinitionsFactory; -import org.apache.tiles.definition.DefinitionsFactoryException; -import org.apache.tiles.definition.DefinitionsReader; -import org.apache.tiles.definition.Refreshable; -import org.apache.tiles.definition.dao.BaseLocaleUrlDefinitionDAO; -import org.apache.tiles.definition.dao.CachingLocaleUrlDefinitionDAO; -import org.apache.tiles.definition.digester.DigesterDefinitionsReader; -import org.apache.tiles.el.ELAttributeEvaluator; -import org.apache.tiles.evaluator.AttributeEvaluator; -import org.apache.tiles.evaluator.AttributeEvaluatorFactory; -import org.apache.tiles.evaluator.BasicAttributeEvaluatorFactory; -import org.apache.tiles.evaluator.impl.DirectAttributeEvaluator; -import org.apache.tiles.extras.complete.CompleteAutoloadTilesContainerFactory; -import org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer; -import org.apache.tiles.factory.AbstractTilesContainerFactory; -import org.apache.tiles.factory.BasicTilesContainerFactory; -import org.apache.tiles.impl.BasicTilesContainer; -import org.apache.tiles.impl.mgmt.CachingTilesContainer; -import org.apache.tiles.locale.LocaleResolver; -import org.apache.tiles.preparer.PreparerFactory; -import org.apache.tiles.startup.AbstractTilesInitializer; -import org.apache.tiles.startup.TilesInitializer; - -import org.springframework.beans.BeanUtils; -import org.springframework.beans.BeanWrapper; -import org.springframework.beans.PropertyAccessorFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.ClassUtils; -import org.springframework.web.context.ServletContextAware; - -/** - * Helper class to configure Tiles 2.x for the Spring Framework. See - * http://tiles.apache.org - * for more information about Tiles, which basically is a templating mechanism - * for web applications using JSPs and other template engines. - * - * Note: Spring 4.0 requires Tiles 2.2.2. Tiles' EL support will - * be activated by default when the Tiles EL module is present in the classpath. - * - *

The TilesConfigurer simply configures a TilesContainer using a set of files - * containing definitions, to be accessed by {@link TilesView} instances. This is a - * Spring-based alternative (for usage in Spring configuration) to the Tiles-provided - * {@code ServletContextListener} - * (e.g. {@link org.apache.tiles.extras.complete.CompleteAutoloadTilesListener} - * for usage in {@code web.xml}. - * - *

TilesViews can be managed by any {@link org.springframework.web.servlet.ViewResolver}. - * For simple convention-based view resolution, consider using {@link TilesViewResolver}. - * - *

A typical TilesConfigurer bean definition looks as follows: - * - *

- * <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
- *   <property name="definitions">
- *     <list>
- *       <value>/WEB-INF/defs/general.xml</value>
- *       <value>/WEB-INF/defs/widgets.xml</value>
- *       <value>/WEB-INF/defs/administrator.xml</value>
- *       <value>/WEB-INF/defs/customer.xml</value>
- *       <value>/WEB-INF/defs/templates.xml</value>
- *     </list>
- *   </property>
- * </bean>
- * 
- * - * The values in the list are the actual Tiles XML files containing the definitions. - * If the list is not specified, the default is {@code "/WEB-INF/tiles.xml"}. - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed - * as of Spring Framework 5.0.. - * - * @author Juergen Hoeller - * @since 2.5 - * @see TilesView - * @see TilesViewResolver - * @deprecated as of Spring 4.2, in favor of Tiles 3 - */ -@Deprecated -public class TilesConfigurer implements ServletContextAware, InitializingBean, DisposableBean { - - private static final boolean tilesElPresent = - ClassUtils.isPresent("org.apache.tiles.el.ELAttributeEvaluator", TilesConfigurer.class.getClassLoader()); - - - protected final Log logger = LogFactory.getLog(getClass()); - - private TilesInitializer tilesInitializer; - - private String[] definitions; - - private boolean checkRefresh = false; - - private boolean validateDefinitions = true; - - private Class definitionsFactoryClass; - - private Class preparerFactoryClass; - - private boolean useMutableTilesContainer = false; - - private ServletContext servletContext; - - - /** - * Configure Tiles using a custom TilesInitializer, typically specified as an inner bean. - *

Default is a variant of {@link org.apache.tiles.startup.DefaultTilesInitializer}, - * respecting the "definitions", "preparerFactoryClass" etc properties on this configurer. - *

NOTE: Specifying a custom TilesInitializer effectively disables all other bean - * properties on this configurer. The entire initialization procedure is then left - * to the TilesInitializer as specified. - */ - public void setTilesInitializer(TilesInitializer tilesInitializer) { - this.tilesInitializer = tilesInitializer; - } - - /** - * Specify whether to apply Tiles 2.2's "complete-autoload" configuration. - *

See {@link org.apache.tiles.extras.complete.CompleteAutoloadTilesContainerFactory} - * for details on the complete-autoload mode. - *

NOTE: Specifying the complete-autoload mode effectively disables all other bean - * properties on this configurer. The entire initialization procedure is then left - * to {@link org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer}. - * @see org.apache.tiles.extras.complete.CompleteAutoloadTilesContainerFactory - * @see org.apache.tiles.extras.complete.CompleteAutoloadTilesInitializer - */ - public void setCompleteAutoload(boolean completeAutoload) { - if (completeAutoload) { - try { - this.tilesInitializer = new SpringCompleteAutoloadTilesInitializer(); - } - catch (Throwable ex) { - throw new IllegalStateException("Tiles-Extras 2.2 not available", ex); - } - } - else { - this.tilesInitializer = null; - } - } - - /** - * Set the Tiles definitions, i.e. the list of files containing the definitions. - * Default is "/WEB-INF/tiles.xml". - */ - public void setDefinitions(String... definitions) { - this.definitions = definitions; - } - - /** - * Set whether to check Tiles definition files for a refresh at runtime. - * Default is "false". - */ - public void setCheckRefresh(boolean checkRefresh) { - this.checkRefresh = checkRefresh; - } - - /** - * Set whether to validate the Tiles XML definitions. Default is "true". - */ - public void setValidateDefinitions(boolean validateDefinitions) { - this.validateDefinitions = validateDefinitions; - } - - /** - * Set the {@link org.apache.tiles.definition.DefinitionsFactory} implementation to use. - * Default is {@link org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory}, - * operating on definition resource URLs. - *

Specify a custom DefinitionsFactory, e.g. a UrlDefinitionsFactory subclass, - * to customize the creation of Tiles Definition objects. Note that such a - * DefinitionsFactory has to be able to handle {@link java.net.URL} source objects, - * unless you configure a different TilesContainerFactory. - */ - public void setDefinitionsFactoryClass(Class definitionsFactoryClass) { - this.definitionsFactoryClass = definitionsFactoryClass; - } - - /** - * Set the {@link org.apache.tiles.preparer.PreparerFactory} implementation to use. - * Default is {@link org.apache.tiles.preparer.BasicPreparerFactory}, creating - * shared instances for specified preparer classes. - *

Specify {@link SimpleSpringPreparerFactory} to autowire - * {@link org.apache.tiles.preparer.ViewPreparer} instances based on specified - * preparer classes, applying Spring's container callbacks as well as applying - * configured Spring BeanPostProcessors. If Spring's context-wide annotation-config - * has been activated, annotations in ViewPreparer classes will be automatically - * detected and applied. - *

Specify {@link SpringBeanPreparerFactory} to operate on specified preparer - * names instead of classes, obtaining the corresponding Spring bean from - * the DispatcherServlet's application context. The full bean creation process - * will be in the control of the Spring application context in this case, - * allowing for the use of scoped beans etc. Note that you need to define one - * Spring bean definition per preparer name (as used in your Tiles definitions). - * @see SimpleSpringPreparerFactory - * @see SpringBeanPreparerFactory - */ - public void setPreparerFactoryClass(Class preparerFactoryClass) { - this.preparerFactoryClass = preparerFactoryClass; - } - - /** - * Set whether to use a MutableTilesContainer (typically the CachingTilesContainer - * implementation) for this application. Default is "false". - * @see org.apache.tiles.mgmt.MutableTilesContainer - * @see org.apache.tiles.impl.mgmt.CachingTilesContainer - */ - public void setUseMutableTilesContainer(boolean useMutableTilesContainer) { - this.useMutableTilesContainer = useMutableTilesContainer; - } - - @Override - public void setServletContext(ServletContext servletContext) { - this.servletContext = servletContext; - } - - /** - * Creates and exposes a TilesContainer for this web application, - * delegating to the TilesInitializer. - * @throws TilesException in case of setup failure - */ - @Override - public void afterPropertiesSet() throws TilesException { - TilesApplicationContext preliminaryContext = - new SpringWildcardServletTilesApplicationContext(this.servletContext); - if (this.tilesInitializer == null) { - this.tilesInitializer = createTilesInitializer(); - } - this.tilesInitializer.initialize(preliminaryContext); - } - - /** - * Creates a new instance of {@code SpringTilesInitializer}. - *

Override it to use a different initializer. - * @see org.apache.tiles.web.startup.AbstractTilesListener#createTilesInitializer() - */ - protected TilesInitializer createTilesInitializer() { - return new SpringTilesInitializer(); - } - - /** - * Removes the TilesContainer from this web application. - * @throws TilesException in case of cleanup failure - */ - @Override - public void destroy() throws TilesException { - this.tilesInitializer.destroy(); - } - - - private class SpringTilesInitializer extends AbstractTilesInitializer { - - @Override - protected AbstractTilesContainerFactory createContainerFactory(TilesApplicationContext context) { - return new SpringTilesContainerFactory(); - } - } - - - private class SpringTilesContainerFactory extends BasicTilesContainerFactory { - - @Override - protected BasicTilesContainer instantiateContainer(TilesApplicationContext context) { - return (useMutableTilesContainer ? new CachingTilesContainer() : new BasicTilesContainer()); - } - - @Override - protected void registerRequestContextFactory(String className, - List factories, TilesRequestContextFactory parent) { - // Avoid Tiles 2.2 warn logging when default RequestContextFactory impl class not found - if (ClassUtils.isPresent(className, TilesConfigurer.class.getClassLoader())) { - super.registerRequestContextFactory(className, factories, parent); - } - } - - @Override - protected List getSourceURLs(TilesApplicationContext applicationContext, - TilesRequestContextFactory contextFactory) { - if (definitions != null) { - try { - List result = new LinkedList(); - for (String definition : definitions) { - Set resources = applicationContext.getResources(definition); - if (resources != null) { - result.addAll(resources); - } - } - return result; - } - catch (IOException ex) { - throw new DefinitionsFactoryException("Cannot load definition URLs", ex); - } - } - else { - return super.getSourceURLs(applicationContext, contextFactory); - } - } - - @Override - protected BaseLocaleUrlDefinitionDAO instantiateLocaleDefinitionDao(TilesApplicationContext applicationContext, - TilesRequestContextFactory contextFactory, LocaleResolver resolver) { - BaseLocaleUrlDefinitionDAO dao = super.instantiateLocaleDefinitionDao( - applicationContext, contextFactory, resolver); - if (checkRefresh && dao instanceof CachingLocaleUrlDefinitionDAO) { - ((CachingLocaleUrlDefinitionDAO) dao).setCheckRefresh(true); - } - return dao; - } - - @Override - protected DefinitionsReader createDefinitionsReader(TilesApplicationContext applicationContext, - TilesRequestContextFactory contextFactory) { - DigesterDefinitionsReader reader = new DigesterDefinitionsReader(); - if (!validateDefinitions){ - Map map = new HashMap(); - map.put(DigesterDefinitionsReader.PARSER_VALIDATE_PARAMETER_NAME, Boolean.FALSE.toString()); - reader.init(map); - } - return reader; - } - - @Override - protected DefinitionsFactory createDefinitionsFactory(TilesApplicationContext applicationContext, - TilesRequestContextFactory contextFactory, LocaleResolver resolver) { - if (definitionsFactoryClass != null) { - DefinitionsFactory factory = BeanUtils.instantiate(definitionsFactoryClass); - if (factory instanceof TilesApplicationContextAware) { - ((TilesApplicationContextAware) factory).setApplicationContext(applicationContext); - } - BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(factory); - if (bw.isWritableProperty("localeResolver")) { - bw.setPropertyValue("localeResolver", resolver); - } - if (bw.isWritableProperty("definitionDAO")) { - bw.setPropertyValue("definitionDAO", - createLocaleDefinitionDao(applicationContext, contextFactory, resolver)); - } - if (factory instanceof Refreshable) { - ((Refreshable) factory).refresh(); - } - return factory; - } - else { - return super.createDefinitionsFactory(applicationContext, contextFactory, resolver); - } - } - - @Override - protected PreparerFactory createPreparerFactory(TilesApplicationContext applicationContext, - TilesRequestContextFactory contextFactory) { - if (preparerFactoryClass != null) { - return BeanUtils.instantiate(preparerFactoryClass); - } - else { - return super.createPreparerFactory(applicationContext, contextFactory); - } - } - - @Override - protected LocaleResolver createLocaleResolver(TilesApplicationContext applicationContext, - TilesRequestContextFactory contextFactory) { - return new SpringLocaleResolver(); - } - - @Override - protected AttributeEvaluatorFactory createAttributeEvaluatorFactory(TilesApplicationContext applicationContext, - TilesRequestContextFactory contextFactory, LocaleResolver resolver) { - AttributeEvaluator evaluator; - if (tilesElPresent && JspFactory.getDefaultFactory() != null) { - evaluator = TilesElActivator.createEvaluator(applicationContext); - } - else { - evaluator = new DirectAttributeEvaluator(); - } - return new BasicAttributeEvaluatorFactory(evaluator); - } - } - - - private static class SpringCompleteAutoloadTilesInitializer extends CompleteAutoloadTilesInitializer { - - @Override - protected AbstractTilesContainerFactory createContainerFactory(TilesApplicationContext context) { - return new SpringCompleteAutoloadTilesContainerFactory(); - } - } - - - private static class SpringCompleteAutoloadTilesContainerFactory extends CompleteAutoloadTilesContainerFactory { - - @Override - protected LocaleResolver createLocaleResolver(TilesApplicationContext applicationContext, - TilesRequestContextFactory contextFactory) { - return new SpringLocaleResolver(); - } - } - - - private static class TilesElActivator { - - public static AttributeEvaluator createEvaluator(TilesApplicationContext applicationContext) { - ELAttributeEvaluator evaluator = new ELAttributeEvaluator(); - evaluator.setApplicationContext(applicationContext); - evaluator.init(Collections.emptyMap()); - return evaluator; - } - } - -} diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java deleted file mode 100644 index 60a42109d061..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesView.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2002-2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import java.util.Locale; -import java.util.Map; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.tiles.TilesApplicationContext; -import org.apache.tiles.TilesContainer; -import org.apache.tiles.context.TilesRequestContext; -import org.apache.tiles.impl.BasicTilesContainer; -import org.apache.tiles.servlet.context.ServletTilesApplicationContext; -import org.apache.tiles.servlet.context.ServletTilesRequestContext; -import org.apache.tiles.servlet.context.ServletUtil; - -import org.springframework.web.servlet.support.JstlUtils; -import org.springframework.web.servlet.support.RequestContext; -import org.springframework.web.servlet.view.AbstractUrlBasedView; - -/** - * {@link org.springframework.web.servlet.View} implementation that retrieves a - * Tiles definition. The "url" property is interpreted as name of a Tiles definition. - * - *

This class builds on Tiles, which requires JSP 2.0. - * JSTL support is integrated out of the box due to JSTL's inclusion in JSP 2.0. - * Note: Spring 4.0 requires Tiles 2.2.2. - * - *

Depends on a TilesContainer which must be available in - * the ServletContext. This container is typically set up via a - * {@link TilesConfigurer} bean definition in the application context. - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed - * as of Spring Framework 5.0.. - * - * @author Juergen Hoeller - * @author Sebastien Deleuze - * @since 2.5 - * @see #setUrl - * @see TilesConfigurer - * @deprecated as of Spring 4.2, in favor of Tiles 3 - */ -@Deprecated -public class TilesView extends AbstractUrlBasedView { - - private boolean alwaysInclude = false; - - - /** - * Specify whether to always include the view rather than forward to it. - *

Default is "false". Switch this flag on to enforce the use of a - * Servlet include, even if a forward would be possible. - * @since 4.1.2 - * @see TilesViewResolver#setAlwaysInclude - */ - public void setAlwaysInclude(boolean alwaysInclude) { - this.alwaysInclude = alwaysInclude; - } - - - @Override - public boolean checkResource(final Locale locale) throws Exception { - TilesContainer container = ServletUtil.getContainer(getServletContext()); - if (!(container instanceof BasicTilesContainer)) { - // Cannot check properly - let's assume it's there. - return true; - } - BasicTilesContainer basicContainer = (BasicTilesContainer) container; - TilesApplicationContext appContext = new ServletTilesApplicationContext(getServletContext()); - TilesRequestContext requestContext = new ServletTilesRequestContext(appContext, null, null) { - @Override - public Locale getRequestLocale() { - return locale; - } - }; - return (basicContainer.getDefinitionsFactory().getDefinition(getUrl(), requestContext) != null); - } - - @Override - protected void renderMergedOutputModel( - Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { - - ServletContext servletContext = getServletContext(); - TilesContainer container = ServletUtil.getContainer(servletContext); - if (container == null) { - throw new ServletException("Tiles container is not initialized. " + - "Have you added a TilesConfigurer to your web application context?"); - } - - exposeModelAsRequestAttributes(model, request); - JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext)); - if (this.alwaysInclude) { - ServletUtil.setForceInclude(request, true); - } - container.render(getUrl(), request, response); - } - -} diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesViewResolver.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesViewResolver.java deleted file mode 100644 index f5c8fb3a8f7a..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/TilesViewResolver.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2002-2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import org.springframework.web.servlet.view.AbstractUrlBasedView; -import org.springframework.web.servlet.view.UrlBasedViewResolver; - -/** - * Convenience subclass of {@link org.springframework.web.servlet.view.UrlBasedViewResolver} - * that supports {@link TilesView} (i.e. Tiles definitions) and custom subclasses of it. - * - *

The view class for all views generated by this resolver can be specified - * via the "viewClass" property. See UrlBasedViewResolver's javadoc for details. - * - *

Note: When chaining ViewResolvers, a TilesViewResolver will - * check for the existence of the specified template resources and only return - * a non-null View object if the template was actually found. - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 and will be removed - * as of Spring Framework 5.0.. - * - * @author Juergen Hoeller - * @author Sebastien Deleuze - * @since 3.0 - * @see #setViewClass - * @see #setPrefix - * @see #setSuffix - * @see #setRequestContextAttribute - * @see TilesView - * @deprecated as of Spring 4.2, in favor of Tiles 3 - */ -@Deprecated -public class TilesViewResolver extends UrlBasedViewResolver { - - private Boolean alwaysInclude; - - - public TilesViewResolver() { - setViewClass(requiredViewClass()); - } - - - /** - * This resolver requires {@link TilesView}. - */ - @Override - protected Class requiredViewClass() { - return TilesView.class; - } - - /** - * Specify whether to always include the view rather than forward to it. - *

Default is "false". Switch this flag on to enforce the use of a - * Servlet include, even if a forward would be possible. - * @since 4.1.2 - * @see TilesView#setAlwaysInclude - */ - public void setAlwaysInclude(Boolean alwaysInclude) { - this.alwaysInclude = alwaysInclude; - } - - - @Override - protected AbstractUrlBasedView buildView(String viewName) throws Exception { - TilesView view = (TilesView) super.buildView(viewName); - if (this.alwaysInclude != null) { - view.setAlwaysInclude(this.alwaysInclude); - } - return view; - } - -} diff --git a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/package-info.java b/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/package-info.java deleted file mode 100644 index 2bb3140540a3..000000000000 --- a/spring-webmvc-tiles2/src/main/java/org/springframework/web/servlet/view/tiles2/package-info.java +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Support classes for the integration of - * Tiles 2 - * (the standalone version of Tiles) as Spring web view technology. - * Contains a View implementation for Tiles definitions. - * - *

NOTE: Tiles 2 support is deprecated in favor of Tiles 3 - * and will be removed as of Spring Framework 5.0.. - */ -package org.springframework.web.servlet.view.tiles2; diff --git a/spring-webmvc-tiles2/src/test/java/org/springframework/web/servlet/view/tiles2/TilesConfigurerTests.java b/spring-webmvc-tiles2/src/test/java/org/springframework/web/servlet/view/tiles2/TilesConfigurerTests.java deleted file mode 100644 index c9a5a0932731..000000000000 --- a/spring-webmvc-tiles2/src/test/java/org/springframework/web/servlet/view/tiles2/TilesConfigurerTests.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2002-2014 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.servlet.view.tiles2; - -import org.apache.tiles.context.TilesRequestContext; -import org.apache.tiles.impl.BasicTilesContainer; -import org.apache.tiles.servlet.context.ServletTilesRequestContext; -import org.apache.tiles.servlet.context.ServletUtil; -import org.junit.Test; - -import org.springframework.mock.web.test.MockHttpServletRequest; -import org.springframework.mock.web.test.MockHttpServletResponse; -import org.springframework.mock.web.test.MockServletContext; - -import static org.junit.Assert.*; - -/** - * @author Juergen Hoeller - */ -public class TilesConfigurerTests { - - @Test - @SuppressWarnings("deprecation") - public void simpleBootstrap() { - MockServletContext sc = new MockServletContext(); - TilesConfigurer tc = new TilesConfigurer(); - tc.setDefinitions("/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml"); - tc.setCheckRefresh(true); - tc.setServletContext(sc); - tc.afterPropertiesSet(); - - BasicTilesContainer container = (BasicTilesContainer) ServletUtil.getContainer(sc); - TilesRequestContext requestContext = new ServletTilesRequestContext( - container.getApplicationContext(), new MockHttpServletRequest(), new MockHttpServletResponse()); - assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext)); - - tc.destroy(); - } - -} diff --git a/spring-webmvc-tiles2/src/test/resources/log4j.properties b/spring-webmvc-tiles2/src/test/resources/log4j.properties deleted file mode 100644 index 14b26693fa69..000000000000 --- a/spring-webmvc-tiles2/src/test/resources/log4j.properties +++ /dev/null @@ -1,10 +0,0 @@ -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%c] - %m%n - -log4j.rootCategory=WARN, console -log4j.logger.org.springframework.beans=WARN -log4j.logger.org.springframework.convert=DEBUG - -#log4j.logger.org.springframework.web.servlet=TRACE - diff --git a/spring-webmvc-tiles2/src/test/resources/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml b/spring-webmvc-tiles2/src/test/resources/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml deleted file mode 100644 index 8aac5812da31..000000000000 --- a/spring-webmvc-tiles2/src/test/resources/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - -