On May 22, 2009, at 5:31 PM, James Strachan wrote:
> Just a thought. It can be a bit painful making all those directories
> which just contain index.jsp (or index.velocity or index.html or
> whatever).
Yes, i can see why this might be a pain.
> I just wondered if others had thought of supporting just
> $className.[jsp|html|velocity] as the name as a fallback?
>
That would require a change to the
com.sun.jersey.server.impl.template.TemplateFactory, which currently
only does:
private String getAbsolutePath(Class<?> resourceClass, String
path) {
return getAbsolutePath(resourceClass) + '/' + path;
}
private String getAbsolutePath(Class<?> resourceClass) {
return "/" + resourceClass.getName().replace('.',
'/').replace('$', '/');
}
I decide to make such a behavior independent of the template
processors and so is not configurable, but it would be easier to
include such a fall back you described. However, i am wondering if we
need to define something pluggable and maybe via a template processor
to absolutize?
The complete behavior is implemented as follows:
private ResolvedViewable resolveRelativeViewable(Viewable v,
Class<?> resolvingClass) {
String path = v.getTemplateName();
if (path == null || path.length() == 0)
path = "index";
for (Class c = resolvingClass; c != Object.class; c =
c.getSuperclass()) {
String absolutePath = getAbsolutePath(c, path);
for (TemplateProcessor t : getTemplateProcessors()) {
String resolvedPath = t.resolve(absolutePath);
if (resolvedPath != null) {
return new ResolvedViewable(t, resolvedPath,
v.getModel(), c);
}
}
}
return null;
}
Paul.