You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2007/07/20 21:08:15 UTC
svn commit: r558094 - in /tapestry/tapestry4/trunk/tapestry-framework/src:
java/org/apache/tapestry/pageload/ java/org/apache/tapestry/resolver/
test/org/apache/tapestry/pageload/ test/org/apache/tapestry/resolver/
Author: jkuhnert
Date: Fri Jul 20 12:08:14 2007
New Revision: 558094
URL: http://svn.apache.org/viewvc?view=rev&rev=558094
Log:
Fixes TAPESTRY-1661. Added smarter component template resolving using a strategy that breaks up the component package segments and uses them as tokens in resolving context relative paths.
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/PageSource.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentResourceResolverImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestNamespaceClassSearchComponentClassProvider.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/resolver/TestComponentResourceResolver.java
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/PageSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/PageSource.java?view=diff&rev=558094&r1=558093&r2=558094
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/PageSource.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/pageload/PageSource.java Fri Jul 20 12:08:14 2007
@@ -178,7 +178,10 @@
} catch (Exception ex)
{
- throw new ApplicationRuntimeException(PageloadMessages.errorPagePoolGet(key), ex);
+ if (RuntimeException.class.isInstance(ex))
+ throw (RuntimeException)ex;
+ else
+ throw new ApplicationRuntimeException(PageloadMessages.errorPagePoolGet(key), ex);
}
@@ -212,7 +215,10 @@
} catch (Exception ex)
{
- throw new ApplicationRuntimeException(PageloadMessages.errorPagePoolGet(key), ex);
+ if (RuntimeException.class.isInstance(ex))
+ throw (RuntimeException)ex;
+ else
+ throw new ApplicationRuntimeException(PageloadMessages.errorPagePoolGet(key), ex);
}
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentResourceResolverImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentResourceResolverImpl.java?view=diff&rev=558094&r1=558093&r2=558094
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentResourceResolverImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentResourceResolverImpl.java Fri Jul 20 12:08:14 2007
@@ -66,8 +66,8 @@
// In some cases the generic classpath resource path is fine - such as bundled component properties
- if (resource == null) {
-
+ if (resource == null)
+ {
resource = base.getRelativeResource(baseName + extension);
if (resource != null)
@@ -124,11 +124,11 @@
String templateName = className.substring((index + packages[i].length()) + 1, className.length()).replaceAll("\\.", "/");
templateName = templateName + extension;
- if (_contextAssetFactory.assetExists(component.getSpecification(), _webInfAppLocation, templateName, locale)) {
-
+ if (_contextAssetFactory.assetExists(component.getSpecification(), _webInfAppLocation, templateName, locale))
+ {
return _contextAssetFactory.createAsset(_webInfAppLocation, component.getSpecification(), templateName, locale, component.getLocation()).getResourceLocation();
- } else if (_contextAssetFactory.assetExists(component.getSpecification(), _webInfLocation, templateName, locale)) {
-
+ } else if (_contextAssetFactory.assetExists(component.getSpecification(), _webInfLocation, templateName, locale))
+ {
return _contextAssetFactory.createAsset(_webInfLocation, component.getSpecification(), templateName, locale, component.getLocation()).getResourceLocation();
}
@@ -137,7 +137,34 @@
String resourceName = baseName + extension;
if (_classpathAssetFactory.assetExists(component.getSpecification(), base, resourceName, locale))
+ {
return _classpathAssetFactory.createAsset(base, component.getSpecification(), resourceName, locale, component.getLocation()).getResourceLocation();
+ }
+
+ // if all else fails try package name context paths
+
+ String[] packageSegments = packages[i].split("\\.");
+
+ if (packageSegments != null && packageSegments.length > 0)
+ {
+ // start with last segment and slowly build the path up with all of them
+ String packagePath = "";
+
+ for (int s=packageSegments.length - 1; s > -1; s--)
+ {
+ packagePath += packageSegments[s] + "/";
+
+ String templatePath = packagePath + templateName;
+
+ if (_contextAssetFactory.assetExists(component.getSpecification(), _webInfAppLocation, templatePath, locale))
+ {
+ return _contextAssetFactory.createAsset(_webInfAppLocation, component.getSpecification(), templatePath, locale, component.getLocation()).getResourceLocation();
+ } else if (_contextAssetFactory.assetExists(component.getSpecification(), _webInfLocation, templatePath, locale))
+ {
+ return _contextAssetFactory.createAsset(_webInfLocation, component.getSpecification(), templatePath, locale, component.getLocation()).getResourceLocation();
+ }
+ }
+ }
}
return null;
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestNamespaceClassSearchComponentClassProvider.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestNamespaceClassSearchComponentClassProvider.java?view=diff&rev=558094&r1=558093&r2=558094
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestNamespaceClassSearchComponentClassProvider.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/pageload/TestNamespaceClassSearchComponentClassProvider.java Fri Jul 20 12:08:14 2007
@@ -14,17 +14,16 @@
package org.apache.tapestry.pageload;
-import static org.easymock.EasyMock.expect;
-
import org.apache.tapestry.BaseComponentTestCase;
import org.apache.tapestry.INamespace;
import org.apache.tapestry.services.ClassFinder;
import org.apache.tapestry.spec.IComponentSpecification;
+import static org.easymock.EasyMock.expect;
import org.testng.annotations.Test;
/**
* Tests for {@link org.apache.tapestry.pageload.NamespaceClassSearchComponentClassProvider}.
- *
+ *
* @author Howard M. Lewis Ship
* @since 4.0
*/
@@ -53,16 +52,16 @@
{
INamespace namespace = newNamespace("zip", "org.apache.tapestry.pageload");
ClassFinder finder = newClassFinder(
- "org.apache.tapestry.pageload",
- "bar.Baz",
- PageLoaderTest.class);
+ "org.apache.tapestry.pageload",
+ "bar.Baz",
+ PageLoaderTest.class);
IComponentSpecification spec = newSpec();
replay();
ComponentClassProviderContext context = new ComponentClassProviderContext("bar/Baz", spec,
- namespace);
+ namespace);
NamespaceClassSearchComponentClassProvider provider = new NamespaceClassSearchComponentClassProvider();
provider.setClassFinder(finder);
@@ -83,7 +82,7 @@
replay();
ComponentClassProviderContext context = new ComponentClassProviderContext("bar/Baz", spec,
- namespace);
+ namespace);
NamespaceClassSearchComponentClassProvider provider = new NamespaceClassSearchComponentClassProvider();
provider.setClassFinder(finder);
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/resolver/TestComponentResourceResolver.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/resolver/TestComponentResourceResolver.java?view=diff&rev=558094&r1=558093&r2=558094
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/resolver/TestComponentResourceResolver.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/resolver/TestComponentResourceResolver.java Fri Jul 20 12:08:14 2007
@@ -177,6 +177,63 @@
verify();
}
+ public void test_Classpath_Spec_Resource_WebInf_Package_Name_Context_Resolved()
+ {
+ IComponent comp = newMock(IComponent.class);
+ checkOrder(comp, false);
+
+ INamespace namespace = newMock(INamespace.class);
+ IRequestCycle cycle = newMock(IRequestCycle.class);
+
+ IComponentSpecification spec = new ComponentSpecification();
+ ClasspathResource base = new ClasspathResource(new DefaultClassResolver(), "/org/apache/tapestry/resolver/MyComponent.jwc");
+ spec.setSpecificationLocation(base);
+ spec.setComponentClassName("org.apache.tapestry.resolver.MyComponent");
+
+ AssetFactory classpathFactory = newMock(AssetFactory.class);
+ AssetFactory contextFactory = newMock(AssetFactory.class);
+ Resource contextRoot = newMock(Resource.class);
+ Resource webinfLocation = newMock(Resource.class);
+ Resource webinfAppLocation = newMock(Resource.class);
+
+ ComponentResourceResolverImpl resolver = new ComponentResourceResolverImpl();
+ resolver.setApplicationId("foo");
+ resolver.setClasspathAssetFactory(classpathFactory);
+ resolver.setContextAssetFactory(contextFactory);
+ resolver.setContextRoot(contextRoot);
+
+ expect(contextRoot.getRelativeResource("WEB-INF/")).andReturn(webinfLocation);
+ expect(webinfLocation.getRelativeResource("foo/")).andReturn(webinfAppLocation);
+
+ expect(comp.getSpecification()).andReturn(spec).anyTimes();
+ expect(comp.getNamespace()).andReturn(namespace);
+ expect(namespace.getPropertyValue("org.apache.tapestry.component-class-packages")).andReturn("org.apache.tapestry.resolver");
+
+ Location l = newMock(Location.class);
+ IAsset asset = newMock(IAsset.class);
+ Resource resource = newMock(Resource.class);
+
+ expect(contextFactory.assetExists(spec, webinfAppLocation, "MyComponent.html", null)).andReturn(false);
+ expect(contextFactory.assetExists(spec, webinfLocation, "MyComponent.html", null)).andReturn(false);
+ expect(classpathFactory.assetExists(spec, base, "MyComponent.html", null)).andReturn(false);
+
+ expect(contextFactory.assetExists(spec, webinfAppLocation, "resolver/MyComponent.html", null)).andReturn(false);
+ expect(contextFactory.assetExists(spec, webinfLocation, "resolver/MyComponent.html", null)).andReturn(true);
+
+ expect(comp.getLocation()).andReturn(l);
+ expect(contextFactory.createAsset(webinfLocation, spec, "resolver/MyComponent.html", null, l)).andReturn(asset);
+ expect(asset.getResourceLocation()).andReturn(resource);
+
+ replay();
+
+ resolver.initializeService();
+
+ Resource resolved = resolver.findComponentResource(comp, cycle, null, ".html", null);
+ assertEquals(resolved, resource);
+
+ verify();
+ }
+
public void test_Classpath_Spec_Resource_Classpath_Resolved()
{
IComponent comp = newMock(IComponent.class);