1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.roo.addon.surf.template;
20
21 import java.util.Collection;
22 import java.util.SortedSet;
23
24 import org.springframework.roo.addon.surf.region.RegionConfig;
25 import org.springframework.roo.shell.CliAvailabilityIndicator;
26 import org.springframework.roo.shell.CliCommand;
27 import org.springframework.roo.shell.CliOption;
28 import org.springframework.roo.shell.CommandMarker;
29 import org.springframework.roo.support.lifecycle.ScopeDevelopmentShell;
30 import org.springframework.roo.support.util.Assert;
31
32
33
34
35
36
37
38 @ScopeDevelopmentShell
39 public class TemplateCommands implements CommandMarker {
40
41 private TemplateOperations templateOperations;
42
43
44
45
46 public TemplateCommands(TemplateOperations templateOperations) {
47 Assert.notNull(templateOperations, "TemplateOperations instance required");
48 this.templateOperations = templateOperations;
49 }
50
51
52
53
54
55 @CliAvailabilityIndicator({"surf template list","surf template instance list","surf template create","surf template instance create","surf template region list"})
56 public boolean isTemplateOperationAvailable() {
57 return templateOperations.isTemplateOperationAvailable();
58 }
59
60
61
62
63
64 @CliCommand(value="surf template list", help="Lists all Surf templates.")
65 public SortedSet<String> listSurfTemplates() {
66 return templateOperations.listSurfTemplatePaths();
67 }
68
69
70
71
72
73 @CliCommand(value="surf template instance list", help="Lists all surf template instances.")
74 public SortedSet<String> listSurfTemplateInstances() {
75 return templateOperations.listSurfTemplateInstances();
76 }
77
78
79
80
81
82 @CliCommand(value="surf template create", help="Creates a template (ftl) at the specified path.")
83 public void newTemplate(
84 @CliOption(key={"path",""}, mandatory=true, help="Specifies path of the new template.") String path
85 ) {
86 templateOperations.newTemplate(path);
87 }
88
89
90
91
92
93
94
95 @CliCommand(value="surf template instance create", help="Creates a Template Instance with the given id that maps to the given template path.")
96 public void newTemplateInstance(
97 @CliOption(key={"id",""}, mandatory=true, help="Specifies id of the new template instance.") String id,
98 @CliOption(key={"path",""}, mandatory=false, help="Specifies path of the new template instance.") String path,
99 @CliOption(key={"template",""}, mandatory=true, help="Specifies template for the new template instance.") String templatePath
100 ) {
101 templateOperations.newTemplateInstance(id,path, templatePath);
102 }
103
104
105
106
107
108
109
110 @CliCommand(value="surf template region list", help="Shows list of regions belong to this template.")
111 public Collection<RegionConfig> listSurfTemplateRegions(
112 @CliOption(key={"path",""}, mandatory=true, help="Specifies path of the template.") String templatePath
113 ) {
114 return templateOperations.listSurfTemplateRegions(templatePath).values();
115 }
116
117
118
119
120
121
122
123
124
125
126 }