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 88e301c  ISIS-1682 moving Object Mixins into new package
88e301c is described below

commit 88e301cb0f66ed57779a35158f96e42b6afeee92
Author: Andi Huber <ahu...@apache.org>
AuthorDate: Thu Apr 12 15:04:46 2018 +0200

    ISIS-1682 moving Object Mixins into new package
    
    Also introducing a new _Strings.asFileNameWithExtension(...)
---
 .../apache/isis/applib/internal/base/_Strings.java | 42 +++++++++++++++++++++-
 .../layout/Object_downloadLayoutXml.java           | 15 +++++---
 .../layout/Object_openRestApi.java                 |  3 +-
 .../layout/Object_rebuildMetamodel.java            |  3 +-
 .../applib/services/layout/LayoutServiceMenu.java  |  8 +++--
 .../apache/isis/applib/services/layout/Util.java   | 33 -----------------
 6 files changed, 61 insertions(+), 43 deletions(-)

diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/internal/base/_Strings.java 
b/core/applib/src/main/java/org/apache/isis/applib/internal/base/_Strings.java
index 247e89c..5631f2e 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/internal/base/_Strings.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/internal/base/_Strings.java
@@ -145,6 +145,42 @@ public final class _Strings {
                }
                return Character.toUpperCase(input.charAt(0)) + 
input.substring(1);
        }
+       
+       // -- PREFIX/SUFFIX
+       
+       /**
+        * If {@code input} does not start with {@code prefix} prepends {@code 
prefix} to the input. 
+        * @param input
+        * @param prefix 
+        * @return null if {@code input} is null  
+        */
+       public static String prefix(@Nullable final String input, final String 
prefix) {
+               if(input==null) {
+                       return null;
+               }
+               Objects.requireNonNull(prefix);
+               if(input.startsWith(prefix)) {
+            return input;
+        }
+               return prefix + input;
+       }
+       
+       /**
+        * If {@code input} does not end with {@code suffix} appends {@code 
suffix} to the input. 
+        * @param input
+        * @param suffix 
+        * @return null if {@code input} is null  
+        */
+       public static String suffix(@Nullable final String input, final String 
suffix) {
+               if(input==null) {
+                       return null;
+               }
+               Objects.requireNonNull(suffix);
+               if(input.endsWith(suffix)) {
+            return input;
+        }
+               return input + suffix;
+       }
 
        // -- PADDING
        
@@ -354,7 +390,11 @@ public final class _Strings {
                        .andThen(s->_Strings_NaturalNames.naturalName2(s, 
true));
 
        
-
+       public final static String asFileNameWithExtension(final String 
fileName, String fileExtension) {
+               Objects.requireNonNull(fileName);
+               Objects.requireNonNull(fileExtension);
+               return suffix(fileName, prefix(".", fileExtension));
+       }
 
 
 
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_downloadLayoutXml.java
 
b/core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_downloadLayoutXml.java
similarity index 84%
rename from 
core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_downloadLayoutXml.java
rename to 
core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_downloadLayoutXml.java
index 47b7c27..3306c3b 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_downloadLayoutXml.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_downloadLayoutXml.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.isis.applib.services.layout;
+package org.apache.isis.applib.mixins.layout;
 
 import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.applib.annotation.ActionLayout;
@@ -24,9 +24,12 @@ import org.apache.isis.applib.annotation.Mixin;
 import org.apache.isis.applib.annotation.ParameterLayout;
 import org.apache.isis.applib.annotation.RestrictTo;
 import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.internal.base._Strings;
+import org.apache.isis.applib.services.layout.LayoutService;
 import org.apache.isis.applib.value.Clob;
 
 @Mixin(method="act")
+@SuppressWarnings("serial")
 public class Object_downloadLayoutXml {
 
     private final Object object;
@@ -52,13 +55,17 @@ public class Object_downloadLayoutXml {
             @ParameterLayout(named = "File name")
             final String fileName,
             final LayoutService.Style style) {
+       
         final String xml = layoutService.toXml(object.getClass(), style);
-
-        return new Clob(Util.withSuffix(fileName, style.name().toLowerCase() + 
".xml"), "text/xml", xml);
+        
+        return new Clob(
+                       _Strings.asFileNameWithExtension(fileName, 
style.name().toLowerCase() + ".xml"), 
+                       "text/xml", 
+                       xml);
     }
 
     public String default0Act() {
-        return Util.withSuffix(object.getClass().getSimpleName(), "layout");
+        return 
_Strings.asFileNameWithExtension(object.getClass().getSimpleName(), "layout");
     }
     public LayoutService.Style default1Act() {
         return LayoutService.Style.NORMALIZED;
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_openRestApi.java
 
b/core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_openRestApi.java
similarity index 97%
rename from 
core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_openRestApi.java
rename to 
core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_openRestApi.java
index 5576854..922e69c 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_openRestApi.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_openRestApi.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.isis.applib.services.layout;
+package org.apache.isis.applib.mixins.layout;
 
 import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.applib.annotation.ActionLayout;
@@ -30,6 +30,7 @@ import org.apache.isis.applib.services.swagger.SwaggerService;
 import org.apache.isis.applib.value.LocalResourcePath;
 
 @Mixin(method="act")
+@SuppressWarnings("serial")
 public class Object_openRestApi {
 
     private final Object object;
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_rebuildMetamodel.java
 
b/core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_rebuildMetamodel.java
similarity index 96%
rename from 
core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_rebuildMetamodel.java
rename to 
core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_rebuildMetamodel.java
index 405d782..aa526b2 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/Object_rebuildMetamodel.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/mixins/layout/Object_rebuildMetamodel.java
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.isis.applib.services.layout;
+package org.apache.isis.applib.mixins.layout;
 
 import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.applib.annotation.ActionLayout;
@@ -27,6 +27,7 @@ import org.apache.isis.applib.annotation.SemanticsOf;
 import org.apache.isis.applib.services.metamodel.MetaModelService;
 
 @Mixin(method="act")
+@SuppressWarnings("serial")
 public class Object_rebuildMetamodel {
 
     private final Object object;
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
 
b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
index 435b1ff..3373db4 100644
--- 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
+++ 
b/core/applib/src/main/java/org/apache/isis/applib/services/layout/LayoutServiceMenu.java
@@ -29,6 +29,7 @@ import org.apache.isis.applib.annotation.NatureOfService;
 import org.apache.isis.applib.annotation.ParameterLayout;
 import org.apache.isis.applib.annotation.RestrictTo;
 import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.internal.base._Strings;
 import org.apache.isis.applib.services.menu.MenuBarsService;
 import org.apache.isis.applib.value.Blob;
 import org.apache.isis.applib.value.Clob;
@@ -42,9 +43,10 @@ import org.apache.isis.applib.value.Clob;
         menuBar = DomainServiceLayout.MenuBar.SECONDARY,
         menuOrder = "500.400"
 )
+@SuppressWarnings("serial")
 public class LayoutServiceMenu {
-
-    public static abstract class ActionDomainEvent extends 
IsisApplibModule.ActionDomainEvent<LayoutServiceMenu> {
+    
+       public static abstract class ActionDomainEvent extends 
IsisApplibModule.ActionDomainEvent<LayoutServiceMenu> {
     }
 
     private final MimeType mimeTypeApplicationZip;
@@ -101,7 +103,7 @@ public class LayoutServiceMenu {
 
         final String xml = layoutService.toMenuBarsXml(type);
 
-        return new Clob(Util.withSuffix(fileName,  ".xml"), "text/xml", xml);
+        return new Clob(_Strings.asFileNameWithExtension(fileName,  ".xml"), 
"text/xml", xml);
     }
 
     public String default0DownloadMenuBarsLayout() {
diff --git 
a/core/applib/src/main/java/org/apache/isis/applib/services/layout/Util.java 
b/core/applib/src/main/java/org/apache/isis/applib/services/layout/Util.java
deleted file mode 100644
index 7e04bf8..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/services/layout/Util.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-package org.apache.isis.applib.services.layout;
-
-class Util {
-
-    private Util(){}
-
-    static String withSuffix(String fileName, String suffix) {
-        if(!suffix.startsWith(".")) {
-            suffix = "." + suffix;
-        }
-        if(!fileName.endsWith(suffix)) {
-            fileName += suffix;
-        }
-        return fileName;
-    }
-
-}

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

Reply via email to