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  
20  package org.springframework.roo.addon.surf.content;
21  
22  import org.springframework.roo.shell.CliAvailabilityIndicator;
23  import org.springframework.roo.shell.CliCommand;
24  import org.springframework.roo.shell.CliOption;
25  import org.springframework.roo.shell.CommandMarker;
26  import org.springframework.roo.support.lifecycle.ScopeDevelopmentShell;
27  import org.springframework.roo.support.util.Assert;
28  /**
29   * Commands for the 'alfresco surf' add-on to be used by the ROO shell.
30   *
31   * @author Yong Qu
32   * @since 1.0
33   */
34  @ScopeDevelopmentShell
35  public class ContentCommands implements CommandMarker {
36  
37  	private ContentOperations contentOperations;
38  
39  	/**
40  	 * @param contentOperations
41  	 */
42  	public ContentCommands(ContentOperations contentOperations) {
43  		Assert.notNull(contentOperations, "ContentOperations instance required");
44  		this.contentOperations = contentOperations;
45  	}
46  
47  	/**
48  	 * Checks availability of the "surf content association create" command.
49  	 * @return true if the "surf content association create" command is available at this moment.
50  	 */
51  	@CliAvailabilityIndicator({"surf content association create"})
52  	public boolean isNewContentAssociationAvailable() {
53  		return contentOperations.isNewContentAssociationAvailable();
54  	}
55  
56  	/**
57  	 * Creates a new Surf content association.
58  	 * @param id Association id.
59  	 * @param contentTypeName Content type.
60  	 * @param desName Page or component id.
61  	 * @param type Association type.
62  	 */
63  	@CliCommand(value="surf content association create", help="Creates a new Surf content association")
64  	public void newContentAssociation(
65  			@CliOption(key={"id",""}, mandatory=false, help="Specifies id of the content association.") String id,
66  			@CliOption(key={"source",""}, mandatory=true, help="Specifies content type of the association.") String contentTypeName,
67  			@CliOption(key={"destination",""}, mandatory=true, help="Specifies page id or component id that will be used for rendering the content type.") String desName,
68  			@CliOption(key={"type",""}, mandatory=false, specifiedDefaultValue="page",unspecifiedDefaultValue="page", help="Specifies type of the association, i.e. page, etc. ") String type
69  			) {
70  		contentOperations.createContentAssociation(id,contentTypeName, desName,type);
71  	}
72  
73  }