View Javadoc

1   /*
2    * $Id: ActionNamesAction.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.config_browser;
23  
24  import java.util.Set;
25  import java.util.TreeSet;
26  
27  import org.apache.struts2.StrutsConstants;
28  
29  import com.opensymphony.xwork2.ActionSupport;
30  import com.opensymphony.xwork2.ObjectFactory;
31  import com.opensymphony.xwork2.config.Configuration;
32  import com.opensymphony.xwork2.config.entities.ActionConfig;
33  import com.opensymphony.xwork2.inject.Inject;
34  
35  /***
36   * ActionNamesAction
37   *
38   */
39  public class ActionNamesAction extends ActionSupport {
40  
41      private static final long serialVersionUID = -5389385242431387840L;
42  
43      private Set actionNames;
44      private String namespace = "";
45      private Set namespaces;
46      private String extension;
47      
48      protected ConfigurationHelper configHelper;
49  
50      @Inject
51      public void setConfigurationHelper(ConfigurationHelper cfg) {
52          this.configHelper = cfg;
53      }
54      
55      public Set getActionNames() {
56          return actionNames;
57      }
58  
59      public String getNamespace() {
60          return namespace;
61      }
62  
63      public void setNamespace(String namespace) {
64          this.namespace = namespace;
65      }
66      
67      @Inject(StrutsConstants.STRUTS_ACTION_EXTENSION)
68      public void setExtension(String ext) {
69          this.extension = ext;
70      }
71  
72      public ActionConfig getConfig(String actionName) {
73          return configHelper.getActionConfig(namespace, actionName);
74      }
75  
76      public Set getNamespaces() {
77          return namespaces;
78      }
79  
80      public String getExtension() {
81          if ( extension == null) {
82              extension = "action";
83          }
84          return extension;
85      }
86  
87      public String execute() throws Exception {
88          namespaces = configHelper.getNamespaces();
89          if (namespaces.size() == 0) {
90              addActionError("There are no namespaces in this configuration");
91              return ERROR;
92          }
93          if (namespace == null) {
94              namespace = "";
95          }
96          actionNames =
97                  new TreeSet(configHelper.getActionNames(namespace));
98          return SUCCESS;
99      }
100 }