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.component;
20  
21  import java.util.Collection;
22  
23  import org.springframework.roo.shell.CliAvailabilityIndicator;
24  import org.springframework.roo.shell.CliCommand;
25  import org.springframework.roo.shell.CliOption;
26  import org.springframework.roo.shell.CommandMarker;
27  import org.springframework.roo.support.lifecycle.ScopeDevelopmentShell;
28  import org.springframework.roo.support.util.Assert;
29  
30  /**
31   * Commands for managing Surf components.
32   *
33   * @author Yong Qu
34   * @since 1.0
35   */
36  @ScopeDevelopmentShell
37  public class ComponentCommands implements CommandMarker {
38  
39  	private ComponentOperations componentOperations;
40  
41  	/**
42  	 * @param componentOperations
43  	 */
44  	public ComponentCommands(ComponentOperations componentOperations) {
45  		Assert.notNull(componentOperations, "ComponentOperations instance required");
46  		this.componentOperations = componentOperations;
47  	}
48  
49  	/**
50  	 * Checks availability of component related commands.
51  	 * @return true if the component related commands available at this moment.
52  	 */
53  	@CliAvailabilityIndicator({"surf webscript list","surf component list","surf component create","surf component resource create","surf component property create"})
54  	public boolean isSurfComponentOperationsAvailable() {
55  		return componentOperations.isSurfComponentOperationsAvailable();
56  	}
57  
58  	/**
59  	 * Lists all Surf component types.
60  	 * @return List of Surf component types.
61  	 */
62  	@CliCommand(value="surf webscript list", help="Lists all Surf web scripts.")
63  	public Collection<String> listSurfComponentTypes() {
64  		return componentOperations.listSurfComponentTypes();
65  	}
66  
67  	/**
68  	 * Lists all Surf components in current Surf project.
69  	 * @param scope Component scope.
70  	 * @param pageId Page id.
71  	 * @param templateId Template id.
72  	 * @return List of Surf components.
73  	 */
74  	@CliCommand(value="surf component list", help="Lists Surf components in your project.")
75  	public Collection<String> listSurfComponents(
76  			@CliOption(key={"scope",""},     mandatory=false, help="Specifies scope of the components you want to list. Available options are page, template and component.") String scopeId,
77  			@CliOption(key={"page",""},     mandatory=false, help="Specifies page id for the page scoped components you want to list.") String pageId,
78  			@CliOption(key={"template",""},     mandatory=false, help="Specifies template id for the template scoped components you want to list.") String templateId
79  	) {
80  		return componentOperations.listSurfComponents(scopeId,pageId,templateId);
81  	}
82  
83  	/**
84  	 * Adds a new Surf component to the current Surf project.
85  	 * @param pageId Page id.
86  	 * @param regionId Region id.
87  	 * @param url Component url.
88  	 * @param options Other options for the component.
89  	 */
90  	@CliCommand(value="surf component create", help="Adds a new Surf component to your Surf project.")
91  	public void newComponent(
92  			@CliOption(key={"page",""},     mandatory=true, help="Specifies page id of the component to be created.") String pageId,
93  			@CliOption(key={"region",""}, mandatory=true, help="Specifies region id of the component to be created.") String regionId,
94  			@CliOption(key={"url",""},     mandatory=true, help="Specifies url of the component to be created.") String url,
95  			@CliOption(key={"options",""},  mandatory=false, help="Specifies additonal options for the component to be created.") String options
96  	) {
97  		componentOperations.createComponent(pageId, regionId, url, options);
98  	}
99  
100 	/**
101 	 * Creates a new resource for the Surf component.
102 	 * @param componentInstanceId Component instance id.
103 	 * @param attributeList Attribute list. The input format is attr1:val1|attr2:val2.
104 	 * @param contentBody Content body.
105 	 */
106 	@CliCommand(value="surf component resource create", help="Creates a new resource for the Surf component.")
107 	public void newComponentResource(
108 			@CliOption(key={"id",""},     mandatory=true, help="Specifies component instance id of the new component resource.") String componentInstanceId,
109 			@CliOption(key={"attributes",""}, mandatory=false, help="Specifies attribute list for the new component resource. The input format is attr1:val1|attr2:val2.") String attributeList,
110 			@CliOption(key={"content",""}, mandatory=true, help="Specifies content body of the new component resource") String contentBody
111 	) {
112 		componentOperations.createComponentResource(componentInstanceId,attributeList,contentBody);
113 	}
114 
115 	/**
116 	 * Creates a new property for Surf component.
117 	 * @param componentInstanceId Component instance id.
118 	 * @param propList Property list. The input format is name1:val1|name22:val2.
119 	 */
120 	@CliCommand(value="surf component property create", help="Creates a new property for Surf component.")
121 	public void newComponentProperty(
122 			@CliOption(key={"id",""},     mandatory=true, help="Specifies component instance id of the new component resource.") String componentInstanceId,
123 			@CliOption(key={"properties",""}, mandatory=true, help="Specifies list of the new component properties. The input format is name1:val1|name22:val2.") String propList
124 	) {
125 		componentOperations.createComponentProperty(componentInstanceId,propList);
126 	}
127 	
128 	/*
129 	@CliCommand(value="list surf regions", help="Show list of all regions belong to this component.")
130 	public SortedSet<RegionConfig> listSurfComponentRegions(
131 			@CliOption(key={"name",""}, mandatory=true, help="The path of the component") String componentName
132 		) {
133 		return componentOperations.listSurfComponentRegions(componentName);
134 	}
135 	 */
136 }