View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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   * Commands for template and template instance related operations.
34   *
35   * @author Yong Qu
36   * @since 1.0
37   */
38  @ScopeDevelopmentShell
39  public class TemplateCommands implements CommandMarker {
40  
41  	private TemplateOperations templateOperations;
42  
43  	/**
44  	 * @param templateOperations
45  	 */
46  	public TemplateCommands(TemplateOperations templateOperations) {
47  		Assert.notNull(templateOperations, "TemplateOperations instance required");
48  		this.templateOperations = templateOperations;
49  	}
50  
51  	/**
52  	 * Check availability of template related commands.
53  	 * @return true if template related commands are available at this moment.
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  	 * Lists all Surf templates.
62  	 * @return List of all Surf templates.
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  	 * Lists all Surf template instances.
71  	 * @return List of Surf template instances.
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  	 * Creates a template (ftl) at the specified path.
80  	 * @param path Path of the new template.
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  	 * Creates a Template Instance with the given id that maps to the given template path.
91  	 * @param id Id of the new template instance.
92  	 * @param path Path of the new template instance.
93  	 * @param templatePath Template for the new template instance.
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 	 * Shows list of regions belong to this template.
106 	 * @param templatePath Template path.
107 	 * @return List of regions belong to this template.
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 	@CliCommand(value="list surf regions", help="Show list of all regions belong to this template.")
119 	public SortedSet<RegionConfig> listSurfTemplateRegions(
120 			@CliOption(key={"name",""}, mandatory=true, help="The path of the template") String templateName
121 		) {
122 		return templateOperations.listSurfTemplateRegions(templateName);
123 	}
124 	 */
125 
126 }