Commits

Anonymous committed c5dd50f

- WW-1420
- WebWork doesn't read theme.properties when it is in webapp path

git-svn-id: http://svn.opensymphony.com/svn/webwork/trunk@2821573baa09-0c28-0410-bef9-dab3c582ae83

Comments (0)

Files changed (3)

src/java/com/opensymphony/webwork/components/template/BaseTemplateEngine.java

 package com.opensymphony.webwork.components.template;
 
 import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.webwork.views.JspSupportServlet;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
                 	is = ClassLoaderUtil.getResourceAsStream(propName, getClass());
                 }
                 
+                if (is == null) {
+                	// let's try webapp's context
+                	if (JspSupportServlet.jspSupportServlet != null) {
+                		String _propName = propName.trim();
+                		if (!_propName.startsWith("/")) {
+                			_propName="/"+_propName;
+                		}
+                		is = JspSupportServlet.jspSupportServlet.getServletContext().getResourceAsStream(_propName);
+                	}
+                }
+                
                 props = new Properties();
                 
                 if (is != null) {
                         LOG.error("Could not load " + propName, e);
                     }
                 }
-
+                
                 themeProps.put(template.getTheme(), props);
             }
 

src/test/com/opensymphony/webwork/components/template/BaseTemplateEngineTest.java

  */
 package com.opensymphony.webwork.components.template;
 
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.InputStream;
 import java.net.URL;
 import java.util.Map;
 
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServlet;
+
+import com.mockobjects.servlet.MockServletContext;
+import com.opensymphony.util.ClassLoaderUtil;
 import com.opensymphony.webwork.components.template.BaseTemplateEngine;
 import com.opensymphony.webwork.components.template.Template;
 import com.opensymphony.webwork.components.template.TemplateEngine;
 import com.opensymphony.webwork.components.template.TemplateRenderingContext;
+import com.opensymphony.webwork.views.JspSupportServlet;
 
 import junit.framework.TestCase;
 
 		assertTrue(propertiesMap.size() > 0);
 	}
 	
+	
+	public void testGetPropsThroughWebAppResource() throws Exception {
+		
+		
+		final MockServletContext mockServletContext = new MockServletContext() {
+			public InputStream getResourceAsStream(String resource) {
+				if ("/template/myTheme/theme.properties".equals(resource)) {
+					return ClassLoaderUtil.getResourceAsStream("com/opensymphony/webwork/components/template/dummyWithContents.properties", BaseTemplateEngineTest.class);
+				}
+				return null;
+			}
+		};
+		
+		JspSupportServlet.jspSupportServlet = new JspSupportServlet() {
+			public ServletContext getServletContext() {
+				return mockServletContext;
+			}
+		};
+		
+		
+		Template template = new Template("template", "myTheme", "myComponent");
+		TemplateEngine templateEngine = new InnerBaseTemplateEngine("theme.properties");
+		Map propertiesMap = templateEngine.getThemeProps(template);
+		assertNotNull(propertiesMap);
+		assertEquals(propertiesMap.size(), 3);
+		assertEquals(propertiesMap.get("one"), "one");
+		assertEquals(propertiesMap.get("two"), "two");
+		assertEquals(propertiesMap.get("parent"), "css_xhtml");
+	}
+	
+	
 	public class InnerBaseTemplateEngine extends BaseTemplateEngine {
 		
 		private String themePropertiesFileName;

src/test/com/opensymphony/webwork/components/template/dummyWithContents.properties

+one=one
+two=two
+parent=css_xhtml