Search code examples
javastruts2struts2-namespace

Struts 2 get all namespaces and actions from xml


I'm new to Struts 2 overall and would like to know, if there is a way to get a list of all the namespaces and actions for each namespace that is defined in the xml?

I have a package and I am including configurations for each namespace:

<include file="struts_someNamespace1.xml" />
<include file="struts_someNamespace2.xml" />
<include file="struts_someNamespace3.xml" />

Each of those XML files is defined similar to this (this has less code):

 <package name="somePackage"  namespace="/someNamespace1" extends="default">
     <action name="firstAction" class="com.someAction">
        <interceptor-ref name="defaultStack"/>
        <interceptor-ref name="json">   </interceptor-ref>
        <result type="json">        </result>
     </action>
     <action name="secondAction" class="com.otherAction">
        <interceptor-ref name="defaultStack"/>
        <interceptor-ref name="json">   </interceptor-ref>
        <result type="json">        </result>
     </action>
 </package>

Is there a way using some utility class where I can get a list or of each namespace and its actions?

Example Results (in JSON)

{
    "someNamespace1": ["firstAction","secondAction"}, 
    "someNamespace2": ["about","home"]
}

Solution

  • Take a look on the Config Browser plugin, it allows browse (almost) all configuration options.

    https://git-wip-us.apache.org/repos/asf?p=struts.git;a=blob;f=plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ConfigurationHelper.java;h=536435f84a7bd818c3051b92fdc94c06cdaa40f6;hb=refs/heads/develop