use of org.apache.tapestry5.services.AssetAlias in project tapestry-5 by apache.
the class ClasspathAssetAliasManagerImplTest method to_client_url.
@Test(dataProvider = "to_client_url_data")
public void to_client_url(String resourcePath, String expectedFolder, String expectedPath) throws IOException {
Resource r = mockResource();
expect(r.getPath()).andReturn(resourcePath);
replay();
ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(configuration());
AssetAlias alias = manager.extractAssetAlias(r);
assertEquals(alias.virtualFolder, expectedFolder);
assertEquals(alias.path, expectedPath);
verify();
}
use of org.apache.tapestry5.services.AssetAlias in project tapestry-5 by apache.
the class ClasspathAssetAliasManagerImpl method extractAssetAlias.
public AssetAlias extractAssetAlias(Resource resource) {
String resourcePath = resource.getPath();
for (String pathPrefix : sortedPathPrefixes) {
if (resourcePath.startsWith(pathPrefix)) {
if (pathPrefix.length() == resourcePath.length()) {
throw new IllegalArgumentException(String.format("Resource path '%s' is not valid as it is mapped as virtual folder '%s'.", resourcePath, pathPrefixToAlias.get(pathPrefix)));
}
// Prevent matching path prefix "foo" against "foobar" ... it must match against "foo/".
if (resourcePath.charAt(pathPrefix.length()) != '/') {
continue;
}
String virtualFolder = pathPrefixToAlias.get(pathPrefix);
// Don't want that slash seperating the folder from the rest of the path.
String path = resourcePath.substring(pathPrefix.length() + 1);
return new AssetAlias(virtualFolder, path);
}
}
throw new UnknownValueException(String.format("Unable to create a client URL for classpath resource %s: The resource path was not within an aliased path.", resourcePath), new AvailableValues("Aliased paths", aliasToPathPrefix.values()));
}
Aggregations