click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r962405 - /click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java
Date Fri, 09 Jul 2010 05:03:38 GMT
Author: sabob
Date: Fri Jul  9 05:03:38 2010
New Revision: 962405

URL: http://svn.apache.org/viewvc?rev=962405&view=rev
Log:
added utility method for retrieving short class name

Modified:
    click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java

Modified: click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java?rev=962405&r1=962404&r2=962405&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java Fri Jul  9 05:03:38
2010
@@ -2156,6 +2156,34 @@ public class ClickUtils {
     }
 
     /**
+     * Returns the class name minus the package name for the given class. If the
+     * class is an inner class the given default value is returned.
+     *
+     * @param cls the class to get the short name for
+     * @param defaultIfInnerClass the className to return if class is an inner
+     * class
+     * @return the class name without the package name or the default value if
+     * the class is an inner class
+     */
+    public static String getShortClassName(Class cls, String defaultIfInnerClass) {
+
+        // getShortClassName returns the classname without the package and also
+        // replaces inner class seperators ($) with dots (.)
+        String className = ClassUtils.getShortClassName(cls);
+
+        // If cls is not in a package
+        if (StringUtils.isBlank(className)) {
+            return defaultIfInnerClass;
+        }
+
+        // If inner class, use default value
+        if (className.contains(".")) {
+            className = defaultIfInnerClass;
+        }
+        return className;
+    }
+
+    /**
      * Return the application LogService instance using thread local Context
      * to perform the lookup.
      *



Mime
View raw message