This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 64ce6ad  ISIS-1946 minor cleanup, adding java-doc to clarify 
path-resource usage
64ce6ad is described below

commit 64ce6adfc7dc957b9af951f72809f2bca11cc610
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Mon May 14 20:01:06 2018 +0200

    ISIS-1946 minor cleanup, adding java-doc to clarify path-resource usage
---
 .../isis/applib/internal/resources/_Resource.java  | 29 +++++++++++----
 .../applib/internal/resources/_Resource_Path.java  | 42 ++++++++--------------
 .../wicket/viewer/IsisWicketApplication.java       |  2 +-
 3 files changed, 39 insertions(+), 34 deletions(-)

diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource.java
 
b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource.java
index 74ab7bb..193f78d 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource.java
@@ -57,21 +57,29 @@ public final class _Resource {
        public static String loadAsString(Class<?> contextClass, String 
resourceName, Charset charset) throws IOException {
                final InputStream is = load(contextClass, resourceName);
                return _Strings.ofBytes(_Bytes.of(is), charset);
-               
-               // legacy of guava
-//             final URL url = Resources.getResource(contextClass, 
resourceName);
-//      return Resources.toString(url, charset);
        }
        
        // -- CONTEXT PATH RESOURCE
        
+       /**
+        * @return context-path resource (if any) as stored previously by 
{@link #putContextPathIfPresent(String)}  
+        */
        public final static String getContextPathIfAny() {
                final _Resource_ContextPath resource = 
_Context.getIfAny(_Resource_ContextPath.class);
                return resource!=null ? resource.getContextPath() : null;
        }
 
-       public final static void putContextPath(String contextPath) {
-               _Context.put(_Resource_ContextPath.class, new 
_Resource_ContextPath(contextPath), false);
+       /**
+        * Stores the {@code contextPath} as an application scoped 
resource-object.
+        * If {@code contextPath} is null or an empty String, no path-resource 
object is stored. 
+        * @param contextPath
+        * @throws IllegalArgumentException if an non-empty contextPath 
evaluates to being 
+        * equivalent to the root-path '/'
+        */
+       public final static void putContextPathIfPresent(String contextPath) {
+               if(!_Strings.isEmpty(contextPath)) {
+                       _Context.put(_Resource_ContextPath.class, new 
_Resource_ContextPath(contextPath), false);       
+               } 
        }
        
        public final static String prependContextPathIfPresent(String path) {
@@ -95,11 +103,19 @@ public final class _Resource {
 
        // -- RESTFUL PATH RESOURCE
 
+       /**
+        * @return restful-path resource (if any) as stored previously by 
{@link #putRestfulPath(String)}  
+        */
        public final static String getRestfulPathIfAny() {
                final _Resource_RestfulPath resource = 
_Context.getIfAny(_Resource_RestfulPath.class);
                return resource!=null ? resource.getRestfulPath() : null;
        }
 
+       /**
+        * Stores the {@code restfulPath} as an application scoped 
resource-object. 
+        * @param restfulPath
+        * @throws IllegalArgumentException if the restfulPath is empty or is 
the root-path.
+        */
        public final static void putRestfulPath(String restfulPath) {
                _Context.put(_Resource_RestfulPath.class, new 
_Resource_RestfulPath(restfulPath), false);
        }
@@ -131,4 +147,5 @@ public final class _Resource {
         return name;
     }
 
+
 }
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_Path.java
 
b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_Path.java
index fd047d6..3b2a183 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_Path.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/internal/resources/_Resource_Path.java
@@ -25,6 +25,11 @@ import org.apache.isis.applib.internal.base._Strings;
 /**
  * 
  * package private abstract helper class to store application scoped path 
objects
+ * <br/><br/>
+ * 
+ * Implementation Note: Empty paths are represented by absence of this 
resource, 
+ * hence empty paths are not allowed (will throw an IllegalArgumentException 
on 
+ * attempted construction)   
  *
  */
 abstract class _Resource_Path {
@@ -34,21 +39,15 @@ abstract class _Resource_Path {
        protected abstract String resourceName();
 
        public _Resource_Path(String contextPath) {
-
-// as it stands, this code fails when running under org.apache.isis.WebServer, 
because the contextPath passed in is just ""
-// But it's not obvious to me why an empty contextPath is not allowed; a value 
of "/" would be trimmed down to "" anyway.
-// Therefore relaxing the logic.
-//
-//             if(_Strings.isEmpty(contextPath))
-//                     throw new IllegalArgumentException(resourceName()+" can 
not be empty");
-//
-//             contextPath = contextPath.trim();
-//
-//             if(_Strings.isEmpty(contextPath))
-//                     throw new IllegalArgumentException(resourceName()+" can 
not be empty");
-
-               contextPath = defaultIfEmpty(contextPath);
-
+               
+               if(_Strings.isEmpty(contextPath))
+                       throw new IllegalArgumentException(resourceName()+" can 
not be empty");
+               
+               contextPath = contextPath.trim();
+               
+               if(_Strings.isEmpty(contextPath))
+                       throw new IllegalArgumentException(resourceName()+" can 
not be empty");
+               
                while(contextPath.startsWith("/")) {
                        contextPath = contextPath.substring(1);
                }
@@ -64,16 +63,5 @@ abstract class _Resource_Path {
                
                this.path = contextPath;
        }
-
-       private static String defaultIfEmpty(final String contextPath) {
-               if(contextPath == null) {
-                       return "/";
-               }
-               final String trimmedContextPath = contextPath.trim();
-               if(_Strings.isEmpty(trimmedContextPath)) {
-                       return "/";
-               }
-               return trimmedContextPath;
-       }
-
+       
 }
diff --git 
a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
 
b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
index 5da7cc6..9cc168b 100644
--- 
a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
+++ 
b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
@@ -352,7 +352,7 @@ public class IsisWicketApplication
             final IsisConfigurationBuilder isisConfigurationBuilder = 
obtainConfigBuilder();
             
isisConfigurationBuilder.addDefaultConfigurationResourcesAndPrimers();
 
-            _Resource.putContextPath(getServletContext().getContextPath());
+            
_Resource.putContextPathIfPresent(getServletContext().getContextPath());
 
             final IsisConfigurationDefault configuration = 
isisConfigurationBuilder.getConfiguration();
 

-- 
To stop receiving notification emails like this one, please contact
ahu...@apache.org.

Reply via email to