View Javadoc

1   /*
2    * $Id: ConfigurationHelper.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.io.IOException;
25  import java.net.URL;
26  import java.util.ArrayList;
27  import java.util.Collections;
28  import java.util.Iterator;
29  import java.util.List;
30  import java.util.Map;
31  import java.util.Properties;
32  import java.util.Set;
33  
34  import org.apache.struts2.dispatcher.Dispatcher;
35  import org.apache.struts2.util.ClassLoaderUtils;
36  
37  import com.opensymphony.xwork2.config.Configuration;
38  import com.opensymphony.xwork2.config.entities.ActionConfig;
39  import com.opensymphony.xwork2.inject.Inject;
40  import com.opensymphony.xwork2.util.ClassLoaderUtil;
41  import com.opensymphony.xwork2.util.ResolverUtil;
42  
43  /***
44   * ConfigurationHelper
45   */
46  public class ConfigurationHelper {
47      
48      private Configuration configuration;
49  
50      @Inject
51      public void setConfiguration(Configuration config) {
52          this.configuration = config;
53      }
54      
55      public Set getNamespaces() {
56          Set namespaces = Collections.EMPTY_SET;
57          Map allActionConfigs = configuration.getRuntimeConfiguration().getActionConfigs();
58          if (allActionConfigs != null) {
59              namespaces = allActionConfigs.keySet();
60          }
61          return namespaces;
62      }
63  
64      public Set getActionNames(String namespace) {
65          Set actionNames = Collections.EMPTY_SET;
66          Map allActionConfigs = configuration.getRuntimeConfiguration().getActionConfigs();
67          if (allActionConfigs != null) {
68              Map actionMappings = (Map) allActionConfigs.get(namespace);
69              if (actionMappings != null) {
70                  actionNames = actionMappings.keySet();
71              }
72          }
73          return actionNames;
74      }
75  
76      public ActionConfig getActionConfig(String namespace, String actionName) {
77          ActionConfig config = null;
78          Map allActionConfigs = configuration.getRuntimeConfiguration().getActionConfigs();
79          if (allActionConfigs != null) {
80              Map actionMappings = (Map) allActionConfigs.get(namespace);
81              if (actionMappings != null) {
82                  config = (ActionConfig) actionMappings.get(actionName);
83              }
84          }
85          return config;
86      }
87      
88      public List<Properties> getJarProperties() throws IOException {
89          ResolverUtil resolver = new ResolverUtil();
90          List<Properties> poms = new ArrayList<Properties>();
91          resolver.findNamedResource("pom.properties", "META-INF/maven");
92          Set<URL> urls = resolver.getResources();
93          for (URL url : urls) {
94              Properties p = new Properties();
95              p.load(url.openStream());
96              poms.add(p);
97          }
98          return poms;
99      }
100 }