struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r498085 - in /struts/struts2/trunk: core/src/main/java/org/apache/struts2/ core/src/main/java/org/apache/struts2/dispatcher/mapper/ core/src/main/resources/org/apache/struts2/ core/src/test/java/org/apache/struts2/dispatcher/mapper/ plugins...
Date Sat, 20 Jan 2007 08:13:11 GMT
Author: mrdon
Date: Sat Jan 20 00:13:11 2007
New Revision: 498085

URL: http://svn.apache.org/viewvc?view=rev&rev=498085
Log:
Adding support for selecting unknown namespaces for codebehind plugin
WW-1663

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
    struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
    struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java?view=diff&rev=498085&r1=498084&r2=498085
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsConstants.java Sat Jan
20 00:13:11 2007
@@ -145,4 +145,6 @@
 
     /** The name of the xwork converter implementation */
     public static final String STRUTS_XWORKCONVERTER = "struts.xworkConverter";
+
+    public static final String STRUTS_ALWAYS_SELECT_FULL_NAMESPACE = "struts.mapper.alwaysSelectFullNamespace";
 }

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java?view=diff&rev=498085&r1=498084&r2=498085
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
Sat Jan 20 00:13:11 2007
@@ -173,6 +173,8 @@
     private boolean allowDynamicMethodCalls = true;
 
     private boolean allowSlashesInActionNames = false;
+    
+    private boolean alwaysSelectFullNamespace = false;
 
     private PrefixTrie prefixTrie = null;
     
@@ -243,6 +245,11 @@
     public void setSlashesInActionNames(String allow) {
         allowSlashesInActionNames = "true".equals(allow);
     }
+    
+    @Inject(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE)
+    public void setAlwaysSelectFullNamespace(String val) {
+        this.alwaysSelectFullNamespace = "true".equals(val);
+    }
 
     @Inject
     public void setContainer(Container container) {
@@ -264,7 +271,7 @@
             return null;
         }
 
-        parseNameAndNamespace(uri, mapping, configManager.getConfiguration());
+        parseNameAndNamespace(uri, mapping, configManager);
 
         handleSpecialParameters(request, mapping);
 
@@ -330,7 +337,7 @@
      *            The action mapping to populate
      */
     void parseNameAndNamespace(String uri, ActionMapping mapping,
-            Configuration config) {
+            ConfigurationManager configManager) {
         String namespace, name;
         int lastSlash = uri.lastIndexOf("/");
         if (lastSlash == -1) {
@@ -342,7 +349,13 @@
             // namespace anyway if not found in root namespace.
             namespace = "/";
             name = uri.substring(lastSlash + 1);
+        } else if (alwaysSelectFullNamespace) {
+            // Simply select the namespace as everything before the last slash
+            namespace = uri.substring(0, lastSlash);
+            name = uri.substring(lastSlash + 1);
         } else {
+            // Try to find the namespace in those defined, defaulting to ""
+            Configuration config = configManager.getConfiguration();
             String prefix = uri.substring(0, lastSlash);
             namespace = "";
             // Find the longest matching namespace, defaulting to the default

Modified: struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties?view=diff&rev=498085&r1=498084&r2=498085
==============================================================================
--- struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties (original)
+++ struts/struts2/trunk/core/src/main/resources/org/apache/struts2/default.properties Sat
Jan 20 00:13:11 2007
@@ -161,4 +161,7 @@
 ### A list of tag libraries available
 struts.tagLibraries=s
 
+### Whether to always select the namespace to be everything before the last slash or not
+struts.mapper.alwaysSelectFullNamespace=false
+
 ### END SNIPPET: complete_file

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java?view=diff&rev=498085&r1=498084&r2=498085
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
Sat Jan 20 00:13:11 2007
@@ -154,6 +154,22 @@
         assertEquals("actionName", mapping.getName());
         assertNull(mapping.getMethod());
     }
+    
+    public void testGetMappingWithUnknownNamespaceButFullNamespaceSelect() throws Exception
{
+        setUp();
+        req.setupGetRequestURI("/bo/foo/actionName.action");
+        req.setupGetServletPath("/bo/foo/actionName.action");
+        req.setupGetAttribute(null);
+        req.addExpectedGetAttributeName("javax.servlet.include.servlet_path");
+
+        DefaultActionMapper mapper = new DefaultActionMapper();
+        mapper.setAlwaysSelectFullNamespace("true");
+        ActionMapping mapping = mapper.getMapping(req, configManager);
+
+        assertEquals("/bo/foo", mapping.getNamespace());
+        assertEquals("actionName", mapping.getName());
+        assertNull(mapping.getMethod());
+    }
 
     public void testGetUri() throws Exception {
         req.setupGetParameterMap(new HashMap());
@@ -204,7 +220,7 @@
         ActionMapping actionMapping = new ActionMapping();
 
         DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
-        defaultActionMapper.parseNameAndNamespace("someAction", actionMapping, config);
+        defaultActionMapper.parseNameAndNamespace("someAction", actionMapping, configManager);
 
         assertEquals(actionMapping.getName(), "someAction");
         assertEquals(actionMapping.getNamespace(), "");
@@ -214,7 +230,7 @@
         ActionMapping actionMapping = new ActionMapping();
 
         DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
-        defaultActionMapper.parseNameAndNamespace("/someAction", actionMapping, config);
+        defaultActionMapper.parseNameAndNamespace("/someAction", actionMapping, configManager);
 
         assertEquals(actionMapping.getName(), "someAction");
         assertEquals(actionMapping.getNamespace(), "/");
@@ -224,7 +240,7 @@
         ActionMapping actionMapping = new ActionMapping();
 
         DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
-        defaultActionMapper.parseNameAndNamespace("/my/someAction", actionMapping, config);
+        defaultActionMapper.parseNameAndNamespace("/my/someAction", actionMapping, configManager);
 
         assertEquals(actionMapping.getName(), "someAction");
         assertEquals(actionMapping.getNamespace(), "/my");
@@ -235,7 +251,7 @@
 
         DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
         defaultActionMapper.setSlashesInActionNames("false");
-        defaultActionMapper.parseNameAndNamespace("/foo/someAction", actionMapping, config);
+        defaultActionMapper.parseNameAndNamespace("/foo/someAction", actionMapping, configManager);
 
         assertEquals(actionMapping.getName(), "someAction");
         assertEquals(actionMapping.getNamespace(), "");
@@ -246,7 +262,7 @@
 
         DefaultActionMapper defaultActionMapper = new DefaultActionMapper();
         defaultActionMapper.setSlashesInActionNames("true");
-        defaultActionMapper.parseNameAndNamespace("/foo/someAction", actionMapping, config);
+        defaultActionMapper.parseNameAndNamespace("/foo/someAction", actionMapping, configManager);
 
         assertEquals(actionMapping.getName(), "foo/someAction");
         assertEquals(actionMapping.getNamespace(), "");

Modified: struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml?view=diff&rev=498085&r1=498084&r2=498085
==============================================================================
--- struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml (original)
+++ struts/struts2/trunk/plugins/codebehind/src/main/resources/struts-plugin.xml Sat Jan 20
00:13:11 2007
@@ -9,6 +9,7 @@
 
     <constant name="struts.codebehind.pathPrefix" value="/"/>
     <constant name="struts.codebehind.defaultPackage" value="codebehind-default"/>
+    <constant name="struts.mapper.alwaysSelectFullNamespace" value="true" />
 
     <package name="codebehind-default" extends="struts-default">
     </package>    



Mime
View raw message