Browse Source
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@2936 50f2f4bb-b051-0410-bef5-90022cba6387pull/1/head
4 changed files with 157 additions and 36 deletions
@ -0,0 +1,78 @@
@@ -0,0 +1,78 @@
|
||||
/* |
||||
* Copyright 2002-2010 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.Enumeration; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
import javax.servlet.ServletContext; |
||||
|
||||
import org.apache.tiles.Initializable; |
||||
import org.apache.tiles.TilesApplicationContext; |
||||
import org.apache.tiles.context.AbstractTilesApplicationContextFactory; |
||||
import org.apache.tiles.servlet.context.wildcard.WildcardServletTilesApplicationContext; |
||||
|
||||
/** |
||||
* Spring-specific subclass of the standard Tiles AbstractTilesApplicationContextFactory, |
||||
* passing given properties through as Tiles init-param map. |
||||
* |
||||
* @author Juergen Hoeller |
||||
* @since 3.0 |
||||
* @see TilesConfigurer#setTilesProperties |
||||
*/ |
||||
public class SpringTilesApplicationContextFactory extends AbstractTilesApplicationContextFactory |
||||
implements Initializable { |
||||
|
||||
private Map<String, String> params; |
||||
|
||||
public void init(Map<String, String> params) { |
||||
this.params = params; |
||||
} |
||||
|
||||
public TilesApplicationContext createApplicationContext(Object context) { |
||||
return new SpringWildcardServletTilesApplicationContext((ServletContext) context, this.params); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Custom subclass of the standard Tiles WildcardServletTilesApplicationContext, |
||||
* passing given properties through as Tiles init-param map. |
||||
*/ |
||||
private static class SpringWildcardServletTilesApplicationContext extends WildcardServletTilesApplicationContext { |
||||
|
||||
private final Map<String, String> mergedInitParams; |
||||
|
||||
public SpringWildcardServletTilesApplicationContext(ServletContext servletContext, Map<String, String> params) { |
||||
super(servletContext); |
||||
this.mergedInitParams = new LinkedHashMap<String, String>(); |
||||
Enumeration initParamNames = servletContext.getInitParameterNames(); |
||||
while (initParamNames.hasMoreElements()) { |
||||
String initParamName = (String) initParamNames.nextElement(); |
||||
this.mergedInitParams.put(initParamName, servletContext.getInitParameter(initParamName)); |
||||
} |
||||
if (params != null) { |
||||
this.mergedInitParams.putAll(params); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, String> getInitParams() { |
||||
return this.mergedInitParams; |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
/* |
||||
* Copyright 2002-2010 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.Properties; |
||||
|
||||
import org.apache.tiles.TilesApplicationContext; |
||||
import org.apache.tiles.context.TilesRequestContext; |
||||
import org.apache.tiles.evaluator.impl.DirectAttributeEvaluator; |
||||
import org.apache.tiles.factory.TilesContainerFactory; |
||||
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 static org.junit.Assert.*; |
||||
import org.junit.Test; |
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest; |
||||
import org.springframework.mock.web.MockHttpServletResponse; |
||||
import org.springframework.mock.web.MockServletContext; |
||||
|
||||
/** |
||||
* @author Juergen Hoeller |
||||
* */ |
||||
public class TilesConfigurerTests { |
||||
|
||||
@Test |
||||
public void simpleBootstrap() { |
||||
MockServletContext sc = new MockServletContext(); |
||||
TilesConfigurer tc = new TilesConfigurer(); |
||||
tc.setDefinitions(new String[] {"/org/springframework/web/servlet/view/tiles2/tiles-definitions.xml"}); |
||||
Properties props = new Properties(); |
||||
props.setProperty(TilesContainerFactory.ATTRIBUTE_EVALUATOR_INIT_PARAM, DirectAttributeEvaluator.class.getName()); |
||||
tc.setTilesProperties(props); |
||||
tc.setServletContext(sc); |
||||
tc.afterPropertiesSet(); |
||||
|
||||
BasicTilesContainer container = (BasicTilesContainer) ServletUtil.getContainer(sc); |
||||
TilesApplicationContext appContext = new ServletTilesApplicationContext(sc); |
||||
TilesRequestContext requestContext = new ServletTilesRequestContext(appContext, |
||||
new MockHttpServletRequest(), new MockHttpServletResponse()); |
||||
assertNotNull(container.getDefinitionsFactory().getDefinition("test", requestContext)); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,10 @@
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!DOCTYPE tiles-definitions PUBLIC |
||||
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" |
||||
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd"> |
||||
|
||||
<tiles-definitions> |
||||
|
||||
<definition name="test" template="/WEB-INF/tiles/test.jsp"/> |
||||
|
||||
</tiles-definitions> |
||||
Loading…
Reference in new issue