Author: jkuhnert
Date: Tue May 1 16:31:15 2007
New Revision: 534275
URL: http://svn.apache.org/viewvc?view=rev&rev=534275
Log:
I don't remember doing this but somehow the script component was trying to do
all the work of resolving asset paths itself. Moved that back over to the
AssetSource service which is more likely to do the right thing.
Modified:
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/pom.xml
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetSourceImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Script.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/ScriptTest.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=534275&r1=534274&r2=534275
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/pom.xml (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/pom.xml Tue May 1
16:31:15 2007
@@ -113,6 +113,8 @@
<includes>
<include>**/*.page</include>
<include>**/*.jwc</include>
+ <include>**/*.script</include>
+ <include>**/*.library</include>
</includes>
</resource>
</resources>
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetSourceImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetSourceImpl.java?view=diff&rev=534275&r1=534274&r2=534275
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetSourceImpl.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/AssetSourceImpl.java
Tue May 1 16:31:15 2007
@@ -66,7 +66,6 @@
String prefix = colonx > -1 ? path.substring(0, colonx) : null;
String truePath = colonx > -1 ? path.substring(colonx + 1) : path;
- Resource assetBase = base;
AssetFactory factory = null;
if (prefix != null) {
@@ -78,7 +77,7 @@
if (factory == null && prefix == null) {
- factory = findAssetFactory(spec, assetBase, path, locale);
+ factory = findAssetFactory(spec, base, truePath, locale);
}
// Unknown prefix is expected to happen when an external asset (using
an established
@@ -99,7 +98,7 @@
// This can happen when a 3.0 DTD is read in
- return factory.createAsset(assetBase, spec, truePath, locale,
location);
+ return factory.createAsset(base, spec, truePath, locale, location);
}
AssetFactory findAssetFactory(IComponentSpecification spec, Resource
baseResource, String path, Locale locale)
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Script.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Script.java?view=diff&rev=534275&r1=534274&r2=534275
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Script.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Script.java
Tue May 1 16:31:15 2007
@@ -14,23 +14,18 @@
package org.apache.tapestry.html;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
-import org.apache.tapestry.AbstractComponent;
-import org.apache.tapestry.IAsset;
-import org.apache.tapestry.IBinding;
-import org.apache.tapestry.IMarkupWriter;
-import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.IScript;
-import org.apache.tapestry.PageRenderSupport;
-import org.apache.tapestry.TapestryUtils;
+import org.apache.hivemind.util.Defense;
+import org.apache.tapestry.*;
+import org.apache.tapestry.asset.AssetSource;
import org.apache.tapestry.engine.IScriptSource;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
/**
* Works with the [EMAIL PROTECTED] Body}component to add a script (and
perhaps some
* initialization) to the HTML response. [ <a
@@ -108,48 +103,50 @@
// only one of the two is allowed
if (scriptAsset != null && scriptPath != null)
- throw new ApplicationRuntimeException(HTMLMessages
- .multiAssetParameterError(getBinding("scriptAsset"),
+ throw new
ApplicationRuntimeException(HTMLMessages.multiAssetParameterError(getBinding("scriptAsset"),
getBinding("script")));
if (scriptPath == null && scriptAsset == null)
- throw new ApplicationRuntimeException(HTMLMessages
- .noScriptPathError());
+ throw new
ApplicationRuntimeException(HTMLMessages.noScriptPathError());
IScriptSource source = getScriptSource();
-
- Resource scriptLocation = null;
+
if (scriptPath != null)
{
-
// If the script path is relative, it should be relative to the
// Script component's
// container (i.e., relative to a page in the application).
- Resource rootLocation = getContainer().getSpecification()
- .getSpecificationLocation();
- scriptLocation = rootLocation.getRelativeResource(scriptPath);
+ Resource rootLocation =
getContainer().getSpecification().getSpecificationLocation();
+
+ scriptAsset = getAssetSource().findAsset(rootLocation,
getContainer().getSpecification(), scriptPath, getPage().getLocale(),
getScriptLocation());
}
- else scriptLocation = scriptAsset.getResourceLocation();
+
+ Defense.notNull(scriptAsset, "script");
try
{
- return source.getScript(scriptLocation);
+ return source.getScript(scriptAsset.getResourceLocation());
}
catch (RuntimeException ex)
{
- Location location = null;
- if (getBinding("script")!=null)
- location = getBinding("script").getLocation();
- else if (getBinding("scriptAsset")!=null)
- location = getBinding("scriptAsset").getLocation();
-
- throw new ApplicationRuntimeException(ex.getMessage(), this,
- location, ex);
+ throw new ApplicationRuntimeException(ex.getMessage(), this,
getScriptLocation(), ex);
}
}
+ Location getScriptLocation()
+ {
+ Location location = null;
+
+ if (getBinding("script")!=null)
+ location = getBinding("script").getLocation();
+ else if (getBinding("scriptAsset")!=null)
+ location = getBinding("scriptAsset").getLocation();
+
+ return location;
+ }
+
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
if (!cycle.isRewinding())
@@ -169,6 +166,9 @@
public abstract String getScriptPath();
public abstract IAsset getScriptAsset();
+
+ // injected
+ public abstract AssetSource getAssetSource();
// Parameter
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/ScriptTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/ScriptTest.java?view=diff&rev=534275&r1=534274&r2=534275
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/ScriptTest.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/html/ScriptTest.java
Tue May 1 16:31:15 2007
@@ -14,28 +14,21 @@
package org.apache.tapestry.html;
-import static org.easymock.EasyMock.expect;
-
-import java.util.HashMap;
-import java.util.Map;
-
import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
-import org.apache.tapestry.BaseComponentTestCase;
-import org.apache.tapestry.IAsset;
-import org.apache.tapestry.IBinding;
-import org.apache.tapestry.IComponent;
-import org.apache.tapestry.IMarkupWriter;
-import org.apache.tapestry.IRender;
-import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.IScript;
-import org.apache.tapestry.IScriptProcessor;
-import org.apache.tapestry.PageRenderSupport;
+import org.apache.tapestry.*;
+import org.apache.tapestry.asset.AssetSource;
import org.apache.tapestry.engine.IScriptSource;
import org.apache.tapestry.spec.ComponentSpecification;
import org.apache.tapestry.spec.IComponentSpecification;
+import static org.easymock.EasyMock.*;
import org.testng.annotations.Test;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
/**
* Tests for the [EMAIL PROTECTED] Script} component.
*
@@ -80,6 +73,9 @@
PageRenderSupport support = newPageRenderSupport();
IRequestCycle cycle = newCycle(false, null);
+ AssetSource assetSource = newMock(AssetSource.class);
+ IPage page = newMock(IPage.class);
+ expect(page.getLocale()).andReturn(Locale.getDefault());
trainGetPageRenderSupport(cycle, support);
@@ -90,11 +86,16 @@
String scriptPath = "MyScript.script";
- Script component = newInstance(Script.class, new Object[]
- { "specification", new ComponentSpecification(), "container",
container, "scriptSource",
- source, "scriptPath", scriptPath });
+ Script component = newInstance(Script.class,
+ "specification", new ComponentSpecification(),
+ "container", container,
+ "scriptSource", source,
+ "scriptPath", scriptPath,
+ "assetSource", assetSource,
+ "page", page
+ );
- trainGetScriptLocation(container, scriptPath, scriptLocation);
+ trainGetScriptLocation(container, scriptPath, scriptLocation,
assetSource);
trainGetScript(source, scriptLocation, script);
@@ -121,7 +122,11 @@
PageRenderSupport support = newPageRenderSupport();
IMarkupWriter writer = newWriter();
IRequestCycle cycle = newCycle(false, null);
-
+ AssetSource assetSource = newMock(AssetSource.class);
+
+ IPage page = newMock(IPage.class);
+ expect(page.getLocale()).andReturn(Locale.getDefault());
+
trainGetPageRenderSupport(cycle, support);
Resource scriptLocation = newResource();
@@ -134,11 +139,17 @@
String scriptPath = "MyScript.script";
- Script component = newInstance(Script.class, new Object[]
- { "specification", new ComponentSpecification(), "container",
container, "scriptSource",
- source, "scriptPath", scriptPath, "baseSymbols", baseSymbols
});
+ Script component = newInstance(Script.class,
+ "specification", new ComponentSpecification(),
+ "container", container,
+ "scriptSource", source,
+ "scriptPath", scriptPath,
+ "baseSymbols", baseSymbols,
+ "assetSource", assetSource,
+ "page", page
+ );
- trainGetScriptLocation(container, scriptPath, scriptLocation);
+ trainGetScriptLocation(container, scriptPath, scriptLocation,
assetSource);
trainGetScript(source, scriptLocation, script);
@@ -166,7 +177,11 @@
PageRenderSupport support = newPageRenderSupport();
IRequestCycle cycle = newCycle(false, null);
+ AssetSource assetSource = newMock(AssetSource.class);
+ IPage page = newMock(IPage.class);
+ expect(page.getLocale()).andReturn(Locale.getDefault());
+
trainGetPageRenderSupport(cycle, support);
IMarkupWriter writer = newWriter();
@@ -183,12 +198,18 @@
String scriptPath = "MyScript.script";
- Script component = newInstance(Script.class, new Object[]
- { "specification", new ComponentSpecification(), "container",
container, "scriptSource",
- source, "scriptPath", scriptPath, "baseSymbols", baseSymbols
});
+ Script component = newInstance(Script.class,
+ "specification", new ComponentSpecification(),
+ "container", container,
+ "scriptSource", source,
+ "scriptPath", scriptPath,
+ "baseSymbols", baseSymbols,
+ "assetSource", assetSource,
+ "page", page
+ );
component.setBinding("fred", informal);
- trainGetScriptLocation(container, scriptPath, scriptLocation);
+ trainGetScriptLocation(container, scriptPath, scriptLocation,
assetSource);
trainGetScript(source, scriptLocation, script);
@@ -244,11 +265,15 @@
String scriptPath = "MyScript.script";
IAsset scriptAsset = newAsset();
-
- Script component = newInstance(Script.class, new Object[]
- { "specification", new ComponentSpecification(), "container",
container, "scriptSource",
- source, "scriptPath", scriptPath, "scriptAsset", scriptAsset
});
-
+
+ Script component = newInstance(Script.class,
+ "specification", new ComponentSpecification(),
+ "container", container,
+ "scriptSource", source,
+ "scriptPath", scriptPath,
+ "scriptAsset", scriptAsset
+ );
+
trainGetPageRenderSupport(cycle, support);
replay();
@@ -278,11 +303,13 @@
String scriptPath = "MyScript.script";
IAsset scriptAsset = newAsset();
-
- Script component = newInstance(Script.class, new Object[]
- { "specification", new ComponentSpecification(), "container",
container, "scriptSource",
- source});
-
+
+ Script component = newInstance(Script.class,
+ "specification", new ComponentSpecification(),
+ "container", container,
+ "scriptSource", source
+ );
+
trainGetPageRenderSupport(cycle, support);
replay();
@@ -318,10 +345,13 @@
IAsset scriptAsset = newAsset();
expect(scriptAsset.getResourceLocation()).andReturn(scriptLocation);
-
- Script component = newInstance(Script.class, new Object[]
- { "specification", new ComponentSpecification(), "container",
container, "scriptSource",
- source, "scriptAsset", scriptAsset });
+
+ Script component = newInstance(Script.class,
+ "specification", new ComponentSpecification(),
+ "container", container,
+ "scriptSource", source,
+ "scriptAsset", scriptAsset
+ );
expect(source.getScript(scriptLocation)).andThrow(new
RuntimeException());
@@ -358,11 +388,14 @@
IAsset scriptAsset = newAsset();
expect(scriptAsset.getResourceLocation()).andReturn(scriptLocation);
-
- Script component = newInstance(Script.class, new Object[]
- { "specification", new ComponentSpecification(), "container",
container, "scriptSource",
- source, "scriptAsset", scriptAsset });
-
+
+ Script component = newInstance(Script.class,
+ "specification", new ComponentSpecification(),
+ "container", container,
+ "scriptSource", source,
+ "scriptAsset", scriptAsset
+ );
+
trainGetScript(source, scriptLocation, script);
script.execute(component, cycle, support, new HashMap());
@@ -396,15 +429,17 @@
}
protected void trainGetScriptLocation(IComponent component, String
scriptPath,
- Resource scriptLocation)
+ Resource scriptLocation, AssetSource assetSource)
{
IComponentSpecification spec = newSpec();
Resource resource = newResource();
+ IAsset asset = newMock(IAsset.class);
- expect(component.getSpecification()).andReturn(spec);
+ expect(component.getSpecification()).andReturn(spec).anyTimes();
expect(spec.getSpecificationLocation()).andReturn(resource);
-
expect(resource.getRelativeResource(scriptPath)).andReturn(scriptLocation);
+ expect(assetSource.findAsset(eq(resource), eq(spec), eq(scriptPath),
isA(Locale.class), (Location)isNull())).andReturn(asset);
+ expect(asset.getResourceLocation()).andReturn(scriptLocation);
}
}