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.page;
20  
21  import java.util.SortedSet;
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 pages.
32   *
33   * @author Yong Qu
34   * @since 1.0
35   */
36  @ScopeDevelopmentShell
37  public class PageCommands implements CommandMarker {
38  
39  	private PageOperations pageOperations;
40  
41  	/**
42  	 * @param pageOperations
43  	 */
44  	public PageCommands(PageOperations pageOperations) {
45  		Assert.notNull(pageOperations, "PageOperations instance required");
46  		this.pageOperations = pageOperations;
47  	}
48  
49  	/**
50  	 * Checks availability of page related commands.
51  	 * @return true if page related commands are available at this moment.
52  	 */
53  	@CliAvailabilityIndicator({"surf page create","surf page association create","surf page list","surf page association list"})
54  	public boolean isPageOperationAvailable() {
55  		return pageOperations.isPageOperationAvailable();
56  	}
57  
58  	/**
59  	 * Adds a new page to the Surf project. Page can be created either based on an existing template instance
60  	 * or an existing template.
61  	 * @param pageId Page id e.g. testpage.
62  	 * @param pagePath Page path e.g. pages, pages\mypage etc.
63  	 * @param templateInstance Template instance id.
64  	 * @param template Template id.
65  	 * @param urls List of urls that the new page will be mapped to. Urls should be separated by comma.
66  	 * @param title Page title.
67  	 */
68  	@CliCommand(value="surf page create", help="Adds a new page to your Surf project.")
69  	public void newPage(
70  			@CliOption(key={"id",""}, mandatory=true, help="Specifies id of the page to be created e.g. test, test1") String pageId,
71  			@CliOption(key={"path",""}, mandatory=false, specifiedDefaultValue="pages",unspecifiedDefaultValue="pages", help="Specifies path of the page to be created e.g. pages, mypages") String pagePath,
72  			@CliOption(key={"templateInstance",""}, mandatory=false, help="Specifies template instance id to be used.") String templateInstance,
73  			@CliOption(key={"template",""}, mandatory=false, help="Specifies template id to be used.") String template,
74  			@CliOption(key={"urls",""}, mandatory=false, help="Specifies list of urls that the new page to be mapped to. Urls should be separated by comma.") String urls,
75  			@CliOption(key={"title",""}, mandatory=false, help="Specifies tile of the page to be created.") String title
76  			) {
77  		pageOperations.createPage(pageId,pagePath, templateInstance, template,urls,title);
78  	}
79  
80  	/**
81  	 * Adds a new Surf page association between two pages.
82  	 * @param sourcePageId Source page id.
83  	 * @param descPageId Destination page id.
84  	 * @param name Optional page association name.
85  	 * @param type Option page association type (default value is "child").
86  	 */
87  	@CliCommand(value="surf page association create", help="Adds a new Surf page association between two pages.")
88  	public void newPageAssociation(
89  			@CliOption(key={"sourceId",""}, mandatory=true, help="Specifies id of the source page.") String sourcePageId,
90  			@CliOption(key={"destId",""}, mandatory=true, help="Specifies id of the destination page.") String destPageId,
91  			@CliOption(key={"name",""}, mandatory=false, help="Speficies optional name for the association.") String name,
92  			@CliOption(key={"type",""}, mandatory=false, specifiedDefaultValue="child",unspecifiedDefaultValue="child", help="Speficies page association type. If not speficied, the default is child.") String type
93  			) {
94  		pageOperations.createPageAssociation(name,sourcePageId, destPageId,type);
95  	}
96  
97  	/**
98  	 * Lists all pages in your Surf project.
99  	 * @return List of all pages.
100 	 */
101 	@CliCommand(value="surf page list", help="Lists all pages in your Surf project.")
102 	public SortedSet<String> listSurfPages() {
103 		return pageOperations.listSurfPages();
104 	}
105 
106 	/**
107 	 * Lists associated pages of the page with a specified id.
108 	 * @param sourceId Source page id.
109 	 * @return List of associated pages.
110 	 */
111 	@CliCommand(value="surf page association list", help="Lists associated pages of the page with a specified id.")
112 	public SortedSet<String> listSurfPageAssociations(
113 			@CliOption(key={"sourceId",""}, mandatory=true, help="Specifies id of the source page.") String sourceId
114 		) {
115 		return pageOperations.listSurfPageAssociations(sourceId);
116 	}	
117 
118 }