1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.tacos.resolvers;
18
19 import org.apache.hivemind.Resource;
20 import org.apache.hivemind.impl.DefaultClassResolver;
21 import org.apache.hivemind.impl.LocationImpl;
22 import org.apache.hivemind.util.ClasspathResource;
23 import org.apache.tapestry.INamespace;
24 import org.apache.tapestry.IRequestCycle;
25 import org.apache.tapestry.resolver.ISpecificationResolverDelegate;
26 import org.apache.tapestry.services.ClassFinder;
27 import org.apache.tapestry.spec.IComponentSpecification;
28 import org.apache.tapestry.spec.ComponentSpecification;
29
30
31
32
33
34
35 public class ClasspathSpecResolverDelegate implements ISpecificationResolverDelegate {
36 private ClassFinder classFinder;
37
38 public IComponentSpecification findComponentSpecification(
39 IRequestCycle cycle, INamespace namespace, String name) {
40 return null;
41 }
42
43 public IComponentSpecification findPageSpecification(IRequestCycle cycle,
44 INamespace namespace, String name) {
45 if (namespace.isApplicationNamespace()) {
46 String packages = namespace
47 .getPropertyValue("org.apache.tapestry.page-class-packages");
48
49 String className = name.replace('/', '.');
50
51 Class pageClass = classFinder.findClass(packages, className);
52
53 if (pageClass == null) {
54 return null;
55 }
56 String fullPath = pageClass.getName().replace('.', '/');
57 ClasspathResource html = new ClasspathResource(new DefaultClassResolver(), fullPath + ".html");
58
59 if (html.getResourceURL() != null) {
60 return setupImplicitPage(namespace.getSpecificationLocation(),
61 new ClasspathResource(new DefaultClassResolver(), fullPath + ".page"));
62 }
63 }
64 return null;
65 }
66
67 private IComponentSpecification setupImplicitPage(Resource resource, Resource pageResource) {
68 IComponentSpecification specification = new ComponentSpecification();
69 specification.setPageSpecification(true);
70 specification.setSpecificationLocation(pageResource);
71 specification.setLocation(new LocationImpl(resource));
72
73 return specification;
74 }
75
76 public void setClassFinder(ClassFinder classFinder) {
77 this.classFinder = classFinder;
78 }
79
80 }
81