Repository navigation
Expand file tree
/
Copy pathView.java
More file actions
66 lines (54 loc) · 1.67 KB
/
Copy pathView.java
File metadata and controls
66 lines (54 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package act.view;
import act.Act;
import act.app.App;
import act.conf.AppConfig;
import act.plugin.Plugin;
import act.util.ActContext;
import org.osgl.util.S;
/**
* The base class that different View solution should extends
*/
public abstract class View implements Plugin {
/**
* Returns the View solution's name. Recommended name should
* be in lower case characters. E.g. freemarker, velocity,
* rythm etc
*/
public abstract String name();
@Override
public void register() {
Act.viewManager().register(this);
init();
}
public Template load(ActContext context) {
Template cached = context.cachedTemplate();
if (null != cached) {
return cached;
}
AppConfig config = context.config();
TemplatePathResolver resolver = config.templatePathResolver();
String path = resolver.resolve(context);
StringBuilder sb = S.builder();
if (!path.startsWith("/")) {
sb.append("/");
}
sb.append(path);
Template template = loadTemplate(sb.toString(), context);
context.cacheTemplate(template);
return template;
}
/**
* Sub class must implement this method to load the template
*
* @param resourcePath the path to the template
* @param context the view context
* @return the template instance or {@code null} if template not found
*/
protected abstract Template loadTemplate(String resourcePath, ActContext context);
/**
* Sub class could use this method initialize the implementation
*/
protected void init() {
}
protected void reload(App app) {}
}