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/04/16 01:59:44 UTC
svn commit: r529097 - in /tapestry/tapestry4/trunk:
tapestry-examples/Workbench/src/context/WEB-INF/
tapestry-framework/src/java/org/apache/tapestry/asset/
tapestry-framework/src/java/org/apache/tapestry/engine/
tapestry-framework/src/java/org/apache/t...
Author: jkuhnert
Date: Sun Apr 15 16:59:43 2007
New Revision: 529097
URL: http://svn.apache.org/viewvc?view=rev&rev=529097
Log:
Fixes TAPESTRY-1413.
Regression came up where unprefixed asset paths such as "/org/apache/tapestry/html/Shell.jwc" weren't correctly being found by the ClasspathAssetFactory.
Modified:
tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/workbench.application
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ClasspathAssetFactory.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ExternalResource.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/PrivateAsset.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/Namespace.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentSpecificationResolverImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentTemplateLoaderLogic.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/NamespaceResourcesImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ClasspathAssetFactoryTest.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java
Modified: tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/workbench.application
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/workbench.application?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/workbench.application (original)
+++ tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/workbench.application Sun Apr 15 16:59:43 2007
@@ -28,6 +28,6 @@
<extension name="org.apache.tapestry.request-decoder" class="org.apache.tapestry.workbench.RequestDecoder"/>
- <library id="contrib" specification-path="classpath:/org/apache/tapestry/contrib/Contrib.library"/>
+ <library id="contrib" specification-path="/org/apache/tapestry/contrib/Contrib.library"/>
</application>
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ClasspathAssetFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ClasspathAssetFactory.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ClasspathAssetFactory.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ClasspathAssetFactory.java Sun Apr 15 16:59:43 2007
@@ -41,9 +41,22 @@
private ResourceLocalizer _localizer;
+ private Resource _rootClassPath;
+
public boolean assetExists(IComponentSpecification spec, Resource baseResource, String path, Locale locale)
{
- Resource assetResource = baseResource.getRelativeResource(path);
+ Resource assetResource = null;
+ if (path.startsWith("/")) {
+
+ if (_rootClassPath == null) {
+ _rootClassPath = new ClasspathResource(_classResolver, "");
+ }
+
+ assetResource = _rootClassPath.getRelativeResource(path);
+ } else {
+
+ assetResource = baseResource.getRelativeResource(path);
+ }
Resource localized = _localizer.findLocalization(assetResource, locale);
@@ -56,8 +69,7 @@
Resource localized = _localizer.findLocalization(asset, locale);
if (localized == null)
- throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource),
- location, null);
+ throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource), location, null);
return createAsset(localized, location);
}
@@ -68,17 +80,14 @@
Resource localized = _localizer.findLocalization(base, locale);
if (localized == null)
- throw new ApplicationRuntimeException(AssetMessages.missingClasspathResource(path),
- location, null);
+ throw new ApplicationRuntimeException(AssetMessages.missingClasspathResource(path), location, null);
return createAsset(localized, location);
}
public IAsset createAsset(Resource resource, Location location)
{
- ClasspathResource cr = (ClasspathResource) resource;
-
- return new PrivateAsset(cr, _assetService, location);
+ return new PrivateAsset(resource, _assetService, location);
}
public void setAssetService(IEngineService assetService)
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java Sun Apr 15 16:59:43 2007
@@ -90,14 +90,6 @@
return createAbsoluteAsset(path, locale, location);
}
-
- // Here's the thing; In Tapestry 3.0 and earlier, you could specify
- // library path like /org/apache/tapestry/contrib/Contrib.library. In the new scheme
- // of things, that should be "classpath:/org/apache/tapestry/contrib/Contrib.library".
- // But to keep a lot of things from breaking, we'll kludgely allow that here.
-
- //if (assetResource.getResourceURL() == null && path.startsWith("/"))
- // return _classpathAssetFactory.createAbsoluteAsset(path, locale, location);
if (localized == null)
throw new ApplicationRuntimeException(AssetMessages.missingAsset(path, baseResource), location, null);
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ExternalResource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ExternalResource.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ExternalResource.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ExternalResource.java Sun Apr 15 16:59:43 2007
@@ -14,17 +14,15 @@
package org.apache.tapestry.asset;
-import java.net.URL;
-import java.util.Locale;
-
import org.apache.hivemind.Resource;
import org.apache.hivemind.util.AbstractResource;
+import java.net.URL;
+import java.util.Locale;
+
/**
* Corresponds to the {@link org.apache.tapestry.asset.ExternalAsset}.
*
- * @author Howard M. Lewis Ship
- * @since 4.0
*/
public class ExternalResource extends AbstractResource
{
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/PrivateAsset.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/PrivateAsset.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/PrivateAsset.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/PrivateAsset.java Sun Apr 15 16:59:43 2007
@@ -14,19 +14,18 @@
package org.apache.tapestry.asset;
-import java.io.InputStream;
-import java.net.URL;
-
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
-import org.apache.hivemind.util.ClasspathResource;
import org.apache.hivemind.util.Defense;
import org.apache.tapestry.engine.IEngineService;
import org.apache.tapestry.engine.ILink;
+import java.io.InputStream;
+import java.net.URL;
+
/**
- * An implementation of {@link org.apache.tapestry.IAsset}for localizable assets within the JVM's
+ * An implementation of {@link org.apache.tapestry.IAsset} for localizable assets within the JVM's
* classpath.
* <p>
* The localization code here is largely cut-and-paste from {@link ContextAsset}.
@@ -40,14 +39,14 @@
/**
* @deprecated To be removed (someday). Use
- * {@link #PrivateAsset(ClasspathResource, IEngineService, Location)} instead.
+ * {@link #PrivateAsset(Resource, IEngineService, Location)} instead.
*/
- public PrivateAsset(ClasspathResource resourceLocation, Location location)
+ public PrivateAsset(Resource resourceLocation, Location location)
{
this(resourceLocation, null, location);
}
- public PrivateAsset(ClasspathResource resourceLocation, IEngineService assetService,
+ public PrivateAsset(Resource resourceLocation, IEngineService assetService,
Location location)
{
super(resourceLocation, location);
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/Namespace.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/Namespace.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/Namespace.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/Namespace.java Sun Apr 15 16:59:43 2007
@@ -14,14 +14,7 @@
package org.apache.tapestry.engine;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
import org.apache.hivemind.Resource;
@@ -31,6 +24,8 @@
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.spec.ILibrarySpecification;
+import java.util.*;
+
/**
* Implementation of {@link org.apache.tapestry.INamespace} that works with a
* {@link org.apache.tapestry.services.NamespaceResources} to obtain page and
@@ -66,20 +61,20 @@
* application namespace).
*/
- private final Map _pages = Collections.synchronizedMap(new HashMap());
+ private final Map _pages = new ConcurrentHashMap();
/**
* Map of {@link org.apache.tapestry.spec.ComponentSpecification}keyed on
* component alias.
*/
- private final Map _components = Collections.synchronizedMap(new HashMap());
+ private final Map _components = new ConcurrentHashMap();
/**
* Map, keyed on id, of {@link INamespace}.
*/
- private final Map _children = Collections.synchronizedMap(new HashMap());
+ private final Map _children = new ConcurrentHashMap();
public Namespace(String id, INamespace parent,
ILibrarySpecification specification, NamespaceResources resources)
@@ -165,8 +160,7 @@
public IComponentSpecification getPageSpecification(String name)
{
- IComponentSpecification result = (IComponentSpecification) _pages
- .get(name);
+ IComponentSpecification result = (IComponentSpecification) _pages.get(name);
if (result == null)
{
@@ -293,16 +287,14 @@
// identifying
// the right file)
- ILibrarySpecification ls = _resources.findChildLibrarySpecification(
- getSpecificationLocation(), path, getLocation());
+ ILibrarySpecification ls = _resources.findChildLibrarySpecification(getSpecificationLocation(), path, getLocation());
return new Namespace(id, this, ls, _resources);
}
- public synchronized boolean containsPage(String name)
+ public boolean containsPage(String name)
{
- return _pages.containsKey(name)
- || (_specification.getPageSpecificationPath(name) != null);
+ return _pages.containsKey(name) || (_specification.getPageSpecificationPath(name) != null);
}
/** @since 2.3 * */
@@ -332,26 +324,23 @@
/** @since 3.0 * */
- public synchronized void installPageSpecification(String pageName,
- IComponentSpecification specification)
+ public void installPageSpecification(String pageName, IComponentSpecification specification)
{
_pages.put(pageName, specification);
}
/** @since 3.0 * */
- public synchronized void installComponentSpecification(String type,
- IComponentSpecification specification)
+ public void installComponentSpecification(String type, IComponentSpecification specification)
{
_components.put(type, specification);
}
/** @since 3.0 * */
- public synchronized boolean containsComponentType(String type)
+ public boolean containsComponentType(String type)
{
- return _components.containsKey(type)
- || (_specification.getComponentSpecificationPath(type) != null);
+ return _components.containsKey(type) || (_specification.getComponentSpecificationPath(type) != null);
}
/** @since 3.0 * */
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentSpecificationResolverImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentSpecificationResolverImpl.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentSpecificationResolverImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/resolver/ComponentSpecificationResolverImpl.java Sun Apr 15 16:59:43 2007
@@ -53,7 +53,6 @@
* <li>By searching the framework namespace
* </ul>
*
- * @author Howard Lewis Ship
* @since 3.0
*/
@@ -91,8 +90,7 @@
* @see #getSpecification()
*/
- public void resolve(IRequestCycle cycle, INamespace containerNamespace, String type,
- Location location)
+ public void resolve(IRequestCycle cycle, INamespace containerNamespace, String type, Location location)
{
int colonx = type.indexOf(':');
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentTemplateLoaderLogic.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentTemplateLoaderLogic.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentTemplateLoaderLogic.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/ComponentTemplateLoaderLogic.java Sun Apr 15 16:59:43 2007
@@ -14,36 +14,25 @@
package org.apache.tapestry.services.impl;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.Location;
-import org.apache.tapestry.IBinding;
-import org.apache.tapestry.IComponent;
-import org.apache.tapestry.IRender;
-import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.ITemplateComponent;
-import org.apache.tapestry.Tapestry;
+import org.apache.tapestry.*;
import org.apache.tapestry.binding.BindingConstants;
import org.apache.tapestry.binding.BindingSource;
import org.apache.tapestry.binding.LiteralBinding;
import org.apache.tapestry.engine.IPageLoader;
-import org.apache.tapestry.parse.CloseToken;
-import org.apache.tapestry.parse.ComponentTemplate;
-import org.apache.tapestry.parse.LocalizationToken;
-import org.apache.tapestry.parse.OpenToken;
-import org.apache.tapestry.parse.TemplateToken;
-import org.apache.tapestry.parse.TextToken;
-import org.apache.tapestry.parse.TokenType;
+import org.apache.tapestry.parse.*;
import org.apache.tapestry.services.TemplateSource;
import org.apache.tapestry.spec.IComponentSpecification;
import org.apache.tapestry.spec.IContainedComponent;
import org.apache.tapestry.spec.IParameterSpecification;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
/**
* Contains the logic from {@link org.apache.tapestry.services.impl.ComponentTemplateLoaderImpl},
* which creates one of these instances to process the request. This is necessary because the
@@ -138,7 +127,7 @@
/**
* Adds the token (which implements {@link IRender}) to the active component (using
* {@link IComponent#addBody(IRender)}), or to this component
- * {@link BaseComponent#addOuter(IRender)}.
+ * {@link org.apache.tapestry.BaseComponent#addOuter(IRender)}.
* <p>
* A check is made that the active component allows a body.
*/
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/NamespaceResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/NamespaceResourcesImpl.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/NamespaceResourcesImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/NamespaceResourcesImpl.java Sun Apr 15 16:59:43 2007
@@ -53,15 +53,14 @@
}
- private Resource findSpecificationResource(Resource libraryResource, String path,
- Location location)
+ private Resource findSpecificationResource(Resource libraryResource, String path, Location location)
{
// TODO: This is where we'll play with assets and asset prefixes
-
+
IAsset childAsset = _assetSource.findAsset(libraryResource, path, null, location);
Resource childResource = childAsset.getResourceLocation();
-
+
return childResource;
}
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ClasspathAssetFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ClasspathAssetFactoryTest.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ClasspathAssetFactoryTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ClasspathAssetFactoryTest.java Sun Apr 15 16:59:43 2007
@@ -60,6 +60,27 @@
verify();
}
+ public void test_Absolute_Asset_Exists()
+ {
+ String path = "/org/apache/tapestry/html/Shell.jwc";
+
+ IEngineService assetService = newService();
+ IComponentSpecification spec = newSpec();
+
+ replay();
+
+ ClasspathAssetFactory factory = new ClasspathAssetFactory();
+ factory.setClassResolver(getClassResolver());
+ factory.setAssetService(assetService);
+ factory.setLocalizer(new DefaultResourceLocalizer());
+
+ Resource base = newBaseResource();
+
+ assert factory.assetExists(spec, base, path, null);
+
+ verify();
+ }
+
public void test_Create_Asset_Missing()
{
IEngineService assetService = newService();
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java?view=diff&rev=529097&r1=529096&r2=529097
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java Sun Apr 15 16:59:43 2007
@@ -72,6 +72,32 @@
verify();
}
+ public void test_Absolute_Asset_Exists()
+ {
+ Resource base = newResource();
+ Resource relative = newResource();
+ Resource localized = newResource();
+ Location l = newLocation();
+ URL url = newURL();
+ IComponentSpecification spec = newSpec();
+
+ trainGetRelativeResource(base, "/", base);
+ trainGetRelativeResource(base, "/images/asset.png", relative);
+ trainGetLocalization(relative, Locale.FRENCH, localized);
+ expect(localized.getResourceURL()).andReturn(url).anyTimes();
+
+ replay();
+
+ ContextAssetFactory factory = new ContextAssetFactory();
+ factory.setLocalizer(new DefaultResourceLocalizer());
+
+ factory.setContextPath("/context");
+
+ assert factory.assetExists(spec, base, "/images/asset.png", Locale.FRENCH);
+
+ verify();
+ }
+
public void test_Create_Asset_Missing()
{
Resource base = newResource();