segments.add(getContext().getNamespace());
segments.add(getContext().getResourceIdentifier());
segments.add(getClassName(reference.getScope()));
// setup resource parameters
PageParameters parameters = referenceRequestHandler.getPageParameters();
if (parameters == null)
{
parameters = new PageParameters();
}
else
{
parameters = new PageParameters(parameters);
// need to remove indexed parameters otherwise the URL won't be able to decode
parameters.clearIndexed();
}
encodeResourceReferenceAttributes(url, reference);
StringTokenizer tokens = new StringTokenizer(reference.getName(), "/");
while (tokens.hasMoreTokens())
{
String token = tokens.nextToken();
// on the last component of the resource path
if (tokens.hasMoreTokens() == false && Strings.isEmpty(token) == false)
{
final IResource resource = reference.getResource();
// is resource supposed to be cached?
if (resource instanceof IStaticCacheableResource)
{
final IStaticCacheableResource cacheable = (IStaticCacheableResource)resource;
// is caching enabled?
if(cacheable.isCachingEnabled())
{
// apply caching scheme to resource url
final ResourceUrl resourceUrl = new ResourceUrl(token, parameters);
getCachingStrategy().decorateUrl(resourceUrl, cacheable);
token = resourceUrl.getFileName();
if (Strings.isEmpty(token))
{
throw new IllegalStateException(
"caching strategy returned empty name for " + resource);
}
}
}
}
segments.add(token);
}
if (parameters.isEmpty() == false)
{
url = encodePageParameters(url, parameters, pageParametersEncoder);
}
return url;