struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r657156 - in /struts/sandbox/trunk/struts2-convention-plugin/src/main: java/org/apache/struts2/convention/ resources/
Date Fri, 16 May 2008 18:33:04 GMT
Author: musachy
Date: Fri May 16 11:33:03 2008
New Revision: 657156

URL: http://svn.apache.org/viewvc?rev=657156&view=rev
Log:
Add configuration properties to disable class scanning, and to overwrite the action suffix
(defaults to "Action")

Modified:
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultActionNameBuilder.java
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
    struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/SEOActionNameBuilder.java
    struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultActionNameBuilder.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultActionNameBuilder.java?rev=657156&r1=657155&r2=657156&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultActionNameBuilder.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/DefaultActionNameBuilder.java
Fri May 16 11:33:03 2008
@@ -32,7 +32,7 @@
  * </p>
  */
 public class DefaultActionNameBuilder implements ActionNameBuilder {
-    private static final String ACTION = "Action";
+    private String actionSuffix = "Action";
     private boolean lowerCase;
 
     @Inject
@@ -40,12 +40,23 @@
         this.lowerCase = Boolean.parseBoolean(lowerCase);
     }
 
+    /**
+     * @param   actionSuffix (Optional) Classes that end with these value will be mapped
as actions
+     *          (defaults to "Action")
+     */
+    @Inject(value = "struts.convention.action.suffix", required = false)
+    public void setActionSuffix(String actionSuffix) {
+        if (!StringTools.isTrimmedEmpty(actionSuffix)) {
+            this.actionSuffix = actionSuffix;
+        }
+    }
+
     public String build(String className) {
         String actionName = className;
 
         // Truncate Action suffix if found
-        if (actionName.endsWith(ACTION)) {
-            actionName = actionName.substring(0, actionName.length() - ACTION.length());
+        if (actionName.endsWith(actionSuffix)) {
+            actionName = actionName.substring(0, actionName.length() - actionSuffix.length());
         }
 
         // Force initial letter of action to lowercase, if desired

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java?rev=657156&r1=657155&r2=657156&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/PackageBasedActionConfigBuilder.java
Fri May 16 11:33:03 2008
@@ -68,6 +68,9 @@
     private String[] actionPackages;
     private String[] excludePackages;
     private String[] packageLocators;
+    private boolean disableActionScanning = false;
+    private String actionSuffix = "Action";
+    private boolean checkImplementsAction = true;
 
     /**
      * Constructs actions based on a list of packages.
@@ -120,6 +123,26 @@
     }
 
     /**
+     * @param   actionPackages (Optional) Map classes that implement com.opensymphony.xwork2.Action
+     *          as actions
+     */
+    @Inject(value = "struts.convention.action.checkImplementsAction", required = false)
+    public void setCheckImplementsAction(String checkImplementsAction) {
+        this.checkImplementsAction = "true".equals(checkImplementsAction);
+    }
+
+    /**
+     * @param   actionSuffix (Optional) Classes that end with these value will be mapped
as actions
+     *          (defaults to "Action")
+     */
+    @Inject(value = "struts.convention.action.suffix", required = false)
+    public void setActionSuffix(String actionSuffix) {
+        if (!StringTools.isTrimmedEmpty(actionSuffix)) {
+            this.actionSuffix = actionSuffix;
+        }
+    }
+
+    /**
      * @param   excludePackages (Optional) A  list of packages that should be skipped when
building
      *          configuration.
      */
@@ -149,55 +172,61 @@
      * {@link ResultMapBuilder} is used to create ResultConfig instances of the action.
      */
     public void buildActionConfigs() {
-        if (actionPackages == null && packageLocators == null) {
-            throw new ConfigurationException("At least a list of action packages or action
package locators " +
-                "must be given using one of the properties [struts.convention.action.packages]
or " +
-                "[struts.convention.package.locators]");
-        }
+        if (!disableActionScanning ) {
+            if (actionPackages == null && packageLocators == null) {
+                throw new ConfigurationException("At least a list of action packages or action
package locators " +
+                    "must be given using one of the properties [struts.convention.action.packages]
or " +
+                    "[struts.convention.package.locators]");
+            }
 
-        if (LOG.isTraceEnabled()) {
-            LOG.trace("Loading action configurations");
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("Loading action configurations");
+                if (actionPackages != null) {
+                    LOG.trace("Actions being loaded from action packages " + Arrays.asList(actionPackages));
+                }
+                if (packageLocators != null) {
+                    LOG.trace("Actions being loaded using package locators " + Arrays.asList(packageLocators));
+                }
+                if (excludePackages != null) {
+                    LOG.trace("Excluding actions from packages " + Arrays.asList(excludePackages));
+                }
+            }
+
+            Set<Class<?>> classes = new HashSet<Class<?>>();
             if (actionPackages != null) {
-                LOG.trace("Actions being loaded from action packages " + Arrays.asList(actionPackages));
+                classes.addAll(findActionsInNamedPackages());
             }
+
             if (packageLocators != null) {
-                LOG.trace("Actions being loaded using package locators " + Arrays.asList(packageLocators));
+                classes.addAll(findActionsUsingPackageLocators());
             }
-            if (excludePackages != null) {
-                LOG.trace("Excluding actions from packages " + Arrays.asList(excludePackages));
-            }
-        }
 
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        if (actionPackages != null) {
-            classes.addAll(findActionsInNamedPackages());
-        }
-
-        if (packageLocators != null) {
-            classes.addAll(findActionsUsingPackageLocators());
+            buildConfiguration(classes);
         }
-
-        buildConfiguration(classes);
     }
 
     protected Set<Class<?>> findActionsInNamedPackages() {
         ClassClassLoaderResolver resolver = new ClassClassLoaderResolver();
-        resolver.find(new ClassClassLoaderResolver.Test<Class<?>>() {
-            public boolean test(Class type) {
-                return com.opensymphony.xwork2.Action.class.isAssignableFrom(type) ||
-                    type.getSimpleName().endsWith("Action");
-            }
-        }, true, actionPackages);
+        resolver.find(getClassLoaderResolverTest(), true, actionPackages);
 
         return resolver.getMatches();
     }
 
+    protected ClassClassLoaderResolver.Test<Class<?>> getClassLoaderResolverTest()
{
+        return new ClassClassLoaderResolver.Test<Class<?>>() {
+            public boolean test(Class type) {
+                return (checkImplementsAction && com.opensymphony.xwork2.Action.class.isAssignableFrom(type))
||
+                    type.getSimpleName().endsWith(actionSuffix);
+            }
+        };
+    }
+
     protected Set<Class<?>> findActionsUsingPackageLocators() {
         ClassClassLoaderResolver resolver = new ClassClassLoaderResolver();
         resolver.findByLocators(new ClassClassLoaderResolver.Test<Class<?>>()
{
             public boolean test(Class<?> type) {
-                return com.opensymphony.xwork2.Action.class.isAssignableFrom(type) ||
-                    type.getSimpleName().endsWith("Action");
+                return (checkImplementsAction && com.opensymphony.xwork2.Action.class.isAssignableFrom(type))
||
+                    type.getSimpleName().endsWith(actionSuffix);
             }
         }, true, excludePackages, packageLocators);
 
@@ -556,4 +585,8 @@
             }
         }
     }
+
+    public void setDisableActionScanning(boolean disableActionScanning) {
+        this.disableActionScanning = disableActionScanning;
+    }
 }
\ No newline at end of file

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/SEOActionNameBuilder.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/SEOActionNameBuilder.java?rev=657156&r1=657155&r2=657156&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/SEOActionNameBuilder.java
(original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/java/org/apache/struts2/convention/SEOActionNameBuilder.java
Fri May 16 11:33:03 2008
@@ -34,7 +34,7 @@
  */
 public class SEOActionNameBuilder implements ActionNameBuilder {
     private static final Logger LOG = LoggerFactory.getLogger(SEOActionNameBuilder.class);
-    private static final String ACTION = "Action";
+    private String actionSuffix = "Action";
     private boolean lowerCase;
     private String separator;
 
@@ -45,12 +45,23 @@
         this.separator = separator;
     }
 
+    /**
+     * @param   actionSuffix (Optional) Classes that end with these value will be mapped
as actions
+     *          (defaults to "Action")
+     */
+    @Inject(value = "struts.convention.action.suffix", required = false)
+    public void setActionSuffix(String actionSuffix) {
+        if (!StringTools.isTrimmedEmpty(actionSuffix)) {
+            this.actionSuffix = actionSuffix;
+        }
+    }
+
     public String build(String className) {
         String actionName = className;
 
         // Truncate Action suffix if found
-        if (actionName.endsWith(ACTION)) {
-            actionName = actionName.substring(0, actionName.length() - ACTION.length());
+        if (actionName.endsWith(actionSuffix)) {
+            actionName = actionName.substring(0, actionName.length() - actionSuffix.length());
         }
 
         // Convert to underscores

Modified: struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml?rev=657156&r1=657155&r2=657156&view=diff
==============================================================================
--- struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml (original)
+++ struts/sandbox/trunk/struts2-convention-plugin/src/main/resources/struts-plugin.xml Fri
May 16 11:33:03 2008
@@ -37,7 +37,9 @@
 
   <bean type="com.opensymphony.xwork2.config.PackageProvider" class="org.apache.struts2.convention.ClasspathConfigurationProvider"/>
 
-  <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
+  <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
+  <constant name="struts.convention.action.suffix" value="Action"/>
+  <constant name="struts.convention.action.checkImplementsAction" value="true"/>
   <constant name="struts.convention.default.parent.package" value="convention-default"/>
   <constant name="struts.convention.action.name.lowercase" value="true"/>
   <constant name="struts.convention.action.name.separator" value="-"/>



Mime
View raw message