View Javadoc

1   /*
2    * $Id: ActionNamesAction.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
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  package org.apache.struts2.config_browser;
19  
20  import java.util.Set;
21  import java.util.TreeSet;
22  
23  import org.apache.struts2.StrutsConstants;
24  import org.apache.struts2.config.Settings;
25  
26  import com.opensymphony.xwork2.ActionSupport;
27  import com.opensymphony.xwork2.config.entities.ActionConfig;
28  
29  /***
30   * ActionNamesAction
31   *
32   */
33  public class ActionNamesAction extends ActionSupport {
34  	
35  	private static final long serialVersionUID = -5389385242431387840L;
36  	
37  	private Set actionNames;
38      private String namespace = "";
39      private Set namespaces;
40      private String extension;
41  
42      public Set getActionNames() {
43          return actionNames;
44      }
45  
46      public String getNamespace() {
47          return namespace;
48      }
49  
50      public void setNamespace(String namespace) {
51          this.namespace = namespace;
52      }
53  
54      public ActionConfig getConfig(String actionName) {
55          return ConfigurationHelper.getActionConfig(namespace, actionName);
56      }
57  
58      public Set getNamespaces() {
59          return namespaces;
60      }
61  
62      public String getExtension() {
63          if ( extension == null) {
64              String ext = (String) Settings.get(StrutsConstants.STRUTS_ACTION_EXTENSION);
65              if ( ext == null || ext.equals("")) {
66                  extension = "action";
67              } else {
68                  extension = ext;
69              }
70          }
71          return extension;
72      }
73  
74      public String execute() throws Exception {
75          namespaces = ConfigurationHelper.getNamespaces();
76          if (namespaces.size() == 0) {
77              addActionError("There are no namespaces in this configuration");
78              return ERROR;
79          }
80          if (namespace == null) {
81              namespace = "";
82          }
83          actionNames =
84                  new TreeSet(ConfigurationHelper.getActionNames(namespace));
85          return SUCCESS;
86      }
87  }