You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2007/03/05 03:32:52 UTC
svn commit: r514527 - in /tapestry/tapestry4/trunk:
tapestry-examples/TimeTracker/
tapestry-examples/TimeTracker/src/context/WEB-INF/
tapestry-examples/TimeTracker/src/main/resources/
tapestry-framework/src/java/org/apache/tapestry/services/impl/ tapes...
Author: jkuhnert
Date: Sun Mar 4 18:32:50 2007
New Revision: 514527
URL: http://svn.apache.org/viewvc?view=rev&rev=514527
Log:
Fixes TAPESTRY-881. Allow for more flexible resolution of properties bundles by searching / handling classpath versions
of the resources for those instances where the spec resource location only resolves to context relative paths.
Added:
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/main/resources/messages.properties
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/mock/app/impl/classpath.properties
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/override.properties
Removed:
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Home.properties
Modified:
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/pom.xml
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/timetracker.application
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ApplicationSpecificationInitializer.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ClasspathResourceFactoryImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentMessagesSourceImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java
Modified: tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/pom.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/pom.xml?view=diff&rev=514527&r1=514526&r2=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/pom.xml (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/pom.xml Sun Mar 4 18:32:50 2007
@@ -97,7 +97,16 @@
<build>
<sourceDirectory>src/java</sourceDirectory>
<testSourceDirectory>src/test</testSourceDirectory>
-
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <includes>
+ <include>*.sql</include>
+ <include>*.properties</include>
+ </includes>
+ </resource>
+ </resources>
+
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
@@ -111,7 +120,7 @@
<systemProperties>
<systemProperty>
<name>org.apache.tapestry.disable-caching</name>
- <value>false</value>
+ <value>true</value>
</systemProperty>
</systemProperties>
</configuration>
Modified: tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/timetracker.application
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/timetracker.application?view=diff&rev=514527&r1=514526&r2=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/timetracker.application (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/timetracker.application Sun Mar 4 18:32:50 2007
@@ -21,8 +21,8 @@
<application name="Tapestry TimeTracker">
- <meta key="org.apache.tapestry.page-class-packages"
- value="org.apache.tapestry.timetracker.page"/>
+ <meta key="org.apache.tapestry.namespace-properties-name" value="messages" />
+ <meta key="org.apache.tapestry.page-class-packages" value="org.apache.tapestry.timetracker.page"/>
<library id="contrib" specification-path="classpath:/org/apache/tapestry/contrib/Contrib.library"/>
Added: tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/main/resources/messages.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/main/resources/messages.properties?view=auto&rev=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/main/resources/messages.properties (added)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/main/resources/messages.properties Sun Mar 4 18:32:50 2007
@@ -0,0 +1,12 @@
+new.task=Task Entry
+
+choose.project=Project
+button.add=add
+
+task.start.date=Date
+task.start.time=Start
+task.end.time=End
+task.duration=Duration
+task.description=Description
+
+feedback=Feedback
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ApplicationSpecificationInitializer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ApplicationSpecificationInitializer.java?view=diff&rev=514527&r1=514526&r2=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ApplicationSpecificationInitializer.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ApplicationSpecificationInitializer.java Sun Mar 4 18:32:50 2007
@@ -119,8 +119,7 @@
// Pretend the file exists in the most common expected location.
- Resource virtualLocation = new ContextResource(servlet.getServletContext(), "/WEB-INF/"
- + servletName + ".application");
+ Resource virtualLocation = new ContextResource(servlet.getServletContext(), "/WEB-INF/" + servletName + ".application");
result.setSpecificationLocation(virtualLocation);
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ClasspathResourceFactoryImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ClasspathResourceFactoryImpl.java?view=diff&rev=514527&r1=514526&r2=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ClasspathResourceFactoryImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ClasspathResourceFactoryImpl.java Sun Mar 4 18:32:50 2007
@@ -28,6 +28,13 @@
{
private ClassResolver _classResolver;
+ public ClasspathResourceFactoryImpl() {}
+
+ public ClasspathResourceFactoryImpl(ClassResolver resolver)
+ {
+ _classResolver = resolver;
+ }
+
public ClasspathResource newResource(String path)
{
return new ClasspathResource(_classResolver, path);
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentMessagesSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentMessagesSourceImpl.java?view=diff&rev=514527&r1=514526&r2=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentMessagesSourceImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentMessagesSourceImpl.java Sun Mar 4 18:32:50 2007
@@ -37,6 +37,7 @@
import org.apache.tapestry.IComponent;
import org.apache.tapestry.INamespace;
import org.apache.tapestry.event.ResetEventListener;
+import org.apache.tapestry.services.ClasspathResourceFactory;
import org.apache.tapestry.services.ComponentMessagesSource;
import org.apache.tapestry.services.ComponentPropertySource;
import org.apache.tapestry.util.text.LocalizedProperties;
@@ -48,8 +49,7 @@
* @since 2.0.4
*/
-public class ComponentMessagesSourceImpl implements ComponentMessagesSource,
- ResetEventListener
+public class ComponentMessagesSourceImpl implements ComponentMessagesSource, ResetEventListener
{
/**
* The name of the component/application/etc property that will be used to
@@ -80,6 +80,11 @@
private ComponentPropertySource _componentPropertySource;
/**
+ * For locating resources on the classpath as well as context path.
+ */
+ private ClasspathResourceFactory _classpathResourceFactory;
+
+ /**
* Returns an instance of {@link Properties}containing the properly
* localized messages for the component, in the {@link Locale}identified by
* the component's containing page.
@@ -134,8 +139,7 @@
if (result == null)
{
- result = assembleNamespaceProperties(namespace, propertiesMap,
- locale);
+ result = assembleNamespaceProperties(namespace, propertiesMap, locale);
propertiesMap.put(locale, result);
}
@@ -146,8 +150,7 @@
private Properties assembleComponentProperties(IComponent component, Resource baseResourceLocation,
Map propertiesMap, Locale locale)
{
- List localizations =
- findLocalizationsForResource(baseResourceLocation, locale,
+ List localizations = findLocalizationsForResource(baseResourceLocation, locale,
component.getSpecification().getProperty(NAMESPACE_PROPERTIES_NAME));
Properties parent = null;
@@ -163,8 +166,7 @@
// Retrieve namespace properties for current locale (and parent
// locales)
- Properties namespaceProperties = getNamespaceProperties(component,
- l);
+ Properties namespaceProperties = getNamespaceProperties(component, l);
// Use the namespace properties as default for assembled properties
assembledProperties = new Properties(namespaceProperties);
@@ -175,12 +177,15 @@
// Override parent properties with current locale
if (parent != null)
{
- if (properties != null) parent.putAll(properties);
+ if (properties != null)
+ parent.putAll(properties);
}
- else parent = properties;
+ else
+ parent = properties;
// Add to assembled properties
- if (parent != null) assembledProperties.putAll(parent);
+ if (parent != null)
+ assembledProperties.putAll(parent);
// Save result in cache
propertiesMap.put(l, assembledProperties);
@@ -192,8 +197,7 @@
private Properties assembleNamespaceProperties(INamespace namespace,
Map propertiesMap, Locale locale)
{
- List localizations =
- findLocalizationsForResource(namespace.getSpecificationLocation(), locale,
+ List localizations = findLocalizationsForResource(namespace.getSpecificationLocation(), locale,
namespace.getPropertyValue(NAMESPACE_PROPERTIES_NAME));
// Build them back up in reverse order.
@@ -235,7 +239,14 @@
{
List result = new ArrayList();
- String baseName = alternateName == null ? extractBaseName(resource) : alternateName;
+ String baseName = null;
+ if (alternateName != null) {
+
+ baseName = alternateName.replace('.', '/');
+ } else {
+
+ baseName = extractBaseName(resource);
+ }
LocalizedNameGenerator g = new LocalizedNameGenerator(baseName, locale, SUFFIX);
@@ -245,7 +256,12 @@
Locale l = g.getCurrentLocale();
Resource localizedResource = resource.getRelativeResource(localizedName);
-
+
+ if (localizedResource.getResourceURL() == null) {
+
+ localizedResource = _classpathResourceFactory.newResource(baseName + SUFFIX);
+ }
+
result.add(new ResourceLocalization(l, localizedResource));
}
@@ -360,9 +376,13 @@
namespace, locale, MESSAGES_ENCODING_PROPERTY_NAME);
}
- public void setComponentPropertySource(
- ComponentPropertySource componentPropertySource)
+ public void setComponentPropertySource(ComponentPropertySource componentPropertySource)
{
_componentPropertySource = componentPropertySource;
+ }
+
+ public void setClasspathResourceFactory(ClasspathResourceFactory factory)
+ {
+ _classpathResourceFactory = factory;
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java?view=diff&rev=514527&r1=514526&r2=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/TestComponentMessages.java Sun Mar 4 18:32:50 2007
@@ -36,6 +36,7 @@
import org.apache.tapestry.html.BasePage;
import org.apache.tapestry.services.ComponentMessagesSource;
import org.apache.tapestry.services.ComponentPropertySource;
+import org.apache.tapestry.services.impl.ClasspathResourceFactoryImpl;
import org.apache.tapestry.services.impl.ComponentMessagesSourceImpl;
import org.apache.tapestry.spec.ComponentSpecification;
import org.apache.tapestry.spec.IComponentSpecification;
@@ -121,8 +122,7 @@
private ILibrarySpecification newLibrarySpec()
{
- Resource resource = new ClasspathResource(new DefaultClassResolver(),
- "/org/apache/tapestry/junit/Library.library");
+ Resource resource = new ClasspathResource(new DefaultClassResolver(), "/org/apache/tapestry/junit/Library.library");
ILibrarySpecification spec = new LibrarySpecification();
spec.setSpecificationLocation(resource);
@@ -162,6 +162,7 @@
private Messages createMessages(String location, Locale locale)
{
ComponentMessagesSourceImpl source = new ComponentMessagesSourceImpl();
+ source.setClasspathResourceFactory(new ClasspathResourceFactoryImpl(new DefaultClassResolver()));
source.setComponentPropertySource(new NullComponentPropertySource());
IComponentSpecification spec = newSpec(location);
@@ -176,15 +177,50 @@
return source.getMessages(page);
}
- public void testOnlyInBase()
+ private Messages createMessages(String location, Locale locale, String propname)
+ {
+ ComponentMessagesSourceImpl source = new ComponentMessagesSourceImpl();
+ source.setClasspathResourceFactory(new ClasspathResourceFactoryImpl(new DefaultClassResolver()));
+ source.setComponentPropertySource(new NullComponentPropertySource());
+
+ IComponentSpecification spec = newSpec(location);
+ spec.setLocation(_locationFixture);
+
+ IPage page = newPage(spec, source, locale);
+
+ ILibrarySpecification lspec = newLibrarySpec();
+ lspec.setProperty(ComponentMessagesSourceImpl.NAMESPACE_PROPERTIES_NAME, propname);
+
+ INamespace namespace = new Namespace(null, null, lspec, null);
+
+ page.setNamespace(namespace);
+
+ return source.getMessages(page);
+ }
+
+ public void test_Only_In_Base()
{
Messages messages = createMessages(MOCK1, new Locale("en", "US"));
check(messages, "only-in-base", "BASE1");
}
+ public void test_Specification_Properties_File_Change()
+ {
+ Messages msgs = createMessages(MOCK1, new Locale("en", "US"), "override");
+
+ check(msgs, "standard-property", "Whispering wind");
+ }
+
+ public void test_Specification_Properties_File_Classpath_Change()
+ {
+ Messages msgs = createMessages(MOCK1, new Locale("en", "US"), "org.apache.tapestry.junit.mock.app.impl.classpath");
+
+ check(msgs, "standard-property", "Here!");
+ }
+
/** @since 4.0 */
- public void testOnlyInNamespace()
+ public void test_Only_In_Namespace()
{
Messages messages = createMessages(MOCK1, new Locale("en", "US"));
@@ -192,7 +228,7 @@
}
/** @since 4.0 */
- public void testLocalizedInNamespace()
+ public void test_Localized_In_Namespace()
{
Messages messages = createMessages(MOCK1, new Locale("fr"));
@@ -200,7 +236,7 @@
}
/** @since 4.0 */
- public void testComponentOverridesNamespace()
+ public void test_Component_Overrides_Namespace()
{
Messages messages = createMessages(MOCK1, new Locale("en", "US"));
@@ -315,6 +351,7 @@
public void testMultipleLocalesWithNamespace()
{
ComponentMessagesSourceImpl source = new ComponentMessagesSourceImpl();
+ source.setClasspathResourceFactory(new ClasspathResourceFactoryImpl(new DefaultClassResolver()));
source.setComponentPropertySource(new NullComponentPropertySource());
IComponentSpecification spec = newSpec(MOCK1);
Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/mock/app/impl/classpath.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/mock/app/impl/classpath.properties?view=auto&rev=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/mock/app/impl/classpath.properties (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/mock/app/impl/classpath.properties Sun Mar 4 18:32:50 2007
@@ -0,0 +1 @@
+standard-property=Here!
Added: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/override.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/override.properties?view=auto&rev=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/override.properties (added)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/override.properties Sun Mar 4 18:32:50 2007
@@ -0,0 +1 @@
+standard-property=Whispering wind
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java?view=diff&rev=514527&r1=514526&r2=514527
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/services/impl/TestNamespaceResources.java Sun Mar 4 18:32:50 2007
@@ -122,7 +122,7 @@
return newMock(IComponentSpecification.class);
}
- public void testGetPageSpecification()
+ public void test_Get_Page_Specification()
{
Resource libraryResource = newResource();
Resource specResource = newResource();
@@ -144,7 +144,7 @@
verify();
}
- public void testGetComponentSpecification()
+ public void test_Get_Component_Specification()
{
Resource libraryResource = newResource();
Resource specResource = newResource();