1. opensymphony
  2. xwork

Commits

musachy  committed 1ed569d

Add shaded StringUtils from commons-lang and remove stringSet, default and join from TextUtils

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1945e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 5a7f851
  • Branches master

Comments (0)

Files changed (9)

File pom.xml

View file
                                     <exclude>org.testng:testng:jdk15</exclude>
                                 </excludes>
                             </artifactSet>
+                            <filters>
+                                <filter>
+                                    <artifact>commons-lang:commons-lang</artifact>
+                                    <includes>
+                                        <include>org/apache/commons/lang/StringUtils.class</include>
+                                    </includes>
+                                </filter>
+                            </filters>
                             <relocations>
                                 <relocation>
                                     <pattern>org.objectweb.asm</pattern>
                                     <shadedPattern>org.objectweb.asm.xwork</shadedPattern>
                                 </relocation>
+                                <relocation>
+                                    <pattern>org.apache.commons.lang</pattern>
+                                    <shadedPattern>org.apache.commons.lang.xwork</shadedPattern>
+                                </relocation>
                             </relocations>
                             <transformers>
                                 <transformer
             <optional>true</optional>
         </dependency>
         <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.4</version>
+        </dependency>
+        <dependency>
             <groupId>opensymphony</groupId>
             <artifactId>ognl</artifactId>
             <version>2.6.11</version>

File src/java/com/opensymphony/xwork2/DefaultActionProxy.java

View file
 import java.io.Serializable;
 import java.util.Locale;
 
+import org.apache.commons.lang.StringUtils;
+
 
 /**
  * The Default ActionProxy implementation
     private void resolveMethod() {
         // if the method is set to null, use the one from the configuration
         // if the one from the configuration is also null, use "execute"
-        if (!TextUtils.stringSet(this.method)) {
+        if (StringUtils.isEmpty(this.method)) {
             this.method = config.getMethodName();
-            if (!TextUtils.stringSet(this.method)) {
+            if (StringUtils.isEmpty(this.method)) {
                 this.method = "execute";
             }
         }

File src/java/com/opensymphony/xwork2/config/entities/ActionConfig.java

View file
 import java.io.Serializable;
 import java.util.*;
 
+import org.apache.commons.lang.StringUtils;
+
 
 /**
  * Contains everything needed to configure and execute an action:
         }
 
         public Builder defaultClassName(String name) {
-        	if (!TextUtils.stringSet(target.className)) {
+        	if (StringUtils.isEmpty(target.className)) {
         	  	target.className = name;
         	}
             return this;

File src/java/com/opensymphony/xwork2/config/providers/XmlConfigurationProvider.java

View file
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
+import org.apache.commons.lang.StringUtils;
 
 import java.io.File;
 import java.io.IOException;
                             scope = Scope.THREAD;
                         }
 
-                        if (!TextUtils.stringSet(name)) {
+                        if (StringUtils.isEmpty(name)) {
                             name = Container.DEFAULT_NAME;
                         }
 
                         try {
                             Class cimpl = ClassLoaderUtil.loadClass(impl, getClass());
                             Class ctype = cimpl;
-                            if (TextUtils.stringSet(type)) {
+                            if (StringUtils.isNotEmpty(type)) {
                                 ctype = ClassLoaderUtil.loadClass(type, getClass());
                             }
                             if ("true".equals(onlyStatic)) {
 
         // if there isnt a class name specified for an <action/> then try to
         // use the default-class-ref from the <package/>
-        if (!TextUtils.stringSet(className)) {
+        if (StringUtils.isEmpty(className)) {
             // if there is a package default-class-ref use that, otherwise use action support
-           /* if (TextUtils.stringSet(packageContext.getDefaultClassRef())) {
+           /* if (StringUtils.isNotEmpty(packageContext.getDefaultClassRef())) {
                 className = packageContext.getDefaultClassRef();
             } else {
                 className = ActionSupport.class.getName();
         packageContext.addActionConfig(name, actionConfig);
 
         if (LOG.isDebugEnabled()) {
-            LOG.debug("Loaded " + (TextUtils.stringSet(packageContext.getNamespace()) ? (packageContext.getNamespace() + "/") : "") + name + " in '" + packageContext.getName() + "' package:" + actionConfig);
+            LOG.debug("Loaded " + (StringUtils.isNotEmpty(packageContext.getNamespace()) ? (packageContext.getNamespace() + "/") : "") + name + " in '" + packageContext.getName() + "' package:" + actionConfig);
         }
     }
 
         String parent = packageElement.getAttribute("extends");
         String abstractVal = packageElement.getAttribute("abstract");
         boolean isAbstract = Boolean.valueOf(abstractVal).booleanValue();
-        String name = TextUtils.noNull(packageElement.getAttribute("name"));
-        String namespace = TextUtils.noNull(packageElement.getAttribute("namespace"));
+        String name = StringUtils.defaultString(packageElement.getAttribute("name"));
+        String namespace = StringUtils.defaultString(packageElement.getAttribute("namespace"));
 
 
-        if (TextUtils.stringSet(packageElement.getAttribute("externalReferenceResolver"))) {
+        if (StringUtils.isNotEmpty(packageElement.getAttribute("externalReferenceResolver"))) {
             throw new ConfigurationException("The 'externalReferenceResolver' attribute has been removed.  Please use " +
                     "a custom ObjectFactory or Interceptor.", packageElement);
         }
                 .location(DomHelper.getLocationObject(packageElement));
 
 
-        if (TextUtils.stringSet(TextUtils.noNull(parent))) { // has parents, let's look it up
+        if (StringUtils.isNotEmpty(StringUtils.defaultString(parent))) { // has parents, let's look it up
 
             List<PackageConfig> parents = ConfigurationUtil.buildParentsFromString(configuration, parent);
 
                 String resultType = resultElement.getAttribute("type");
 
                 // if you don't specify a name on <result/>, it defaults to "success"
-                if (!TextUtils.stringSet(resultName)) {
+                if (StringUtils.isEmpty(resultName)) {
                     resultName = Action.SUCCESS;
                 }
 
                 // there is no result type, so let's inherit from the parent package
-                if (!TextUtils.stringSet(resultType)) {
+                if (StringUtils.isEmpty(resultType)) {
                     resultType = packageContext.getFullDefaultResultType();
 
                     // now check if there is a result type now
-                    if (!TextUtils.stringSet(resultType)) {
+                    if (StringUtils.isEmpty(resultType)) {
                         // uh-oh, we have a problem
                         throw new ConfigurationException("No result type specified for result named '"
                                 + resultName + "', perhaps the parent package does not specify the result type?", resultElement);
 
                 Map<String, String> params = XmlHelper.getParams(ehElement);
 
-                if (!TextUtils.stringSet(emName)) {
+                if (StringUtils.isEmpty(emName)) {
                     emName = exceptionResult;
                 }
 

File src/java/com/opensymphony/xwork2/conversion/impl/XWorkBasicConverter.java

View file
 import java.text.*;
 import java.util.*;
 
+import org.apache.commons.lang.StringUtils;
+
 
 /**
  * <!-- START SNIPPET: javadoc -->
                 intArray.add(Integer.valueOf(aX));
             }
 
-            result = TextUtils.join(", ", intArray);
+            result = StringUtils.join(intArray, ", ");
         } else if (value instanceof long[]) {
             long[] x = (long[]) value;
             List<Long> longArray = new ArrayList<Long>(x.length);
                 longArray.add(Long.valueOf(aX));
             }
 
-            result = TextUtils.join(", ", longArray);
+            result = StringUtils.join(longArray, ", ");
         } else if (value instanceof double[]) {
             double[] x = (double[]) value;
             List<Double> doubleArray = new ArrayList<Double>(x.length);
                 doubleArray.add(new Double(aX));
             }
 
-            result = TextUtils.join(", ", doubleArray);
+            result = StringUtils.join(doubleArray, ", ");
         } else if (value instanceof boolean[]) {
             boolean[] x = (boolean[]) value;
             List<Boolean> booleanArray = new ArrayList<Boolean>(x.length);
                 booleanArray.add(new Boolean(aX));
             }
 
-            result = TextUtils.join(", ", booleanArray);
+            result = StringUtils.join(booleanArray, ", ");
         } else if (value instanceof Date) {
             DateFormat df = null;
             if (value instanceof java.sql.Time) {
             }
             result = df.format(value);
         } else if (value instanceof String[]) {
-            result = TextUtils.join(", ", (String[]) value);
+            result = StringUtils.join((String[]) value, ", ");
         }
 
         return result;

File src/java/com/opensymphony/xwork2/util/TextParseUtil.java

View file
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
+
 
 /**
  * Utility class for text parsing.
                     String middle = null;
                     if (o != null) {
                         middle = o.toString();
-                        if (!TextUtils.stringSet(left)) {
+                        if (StringUtils.isEmpty(left)) {
                             result = o;
                         } else {
                             result = left.concat(middle);
                         }
 
-                        if (TextUtils.stringSet(right)) {
+                        if (StringUtils.isNotEmpty(right)) {
                             result = result.toString().concat(right);
                         }
 

File src/java/com/opensymphony/xwork2/util/TextUtils.java

View file
  */
 package com.opensymphony.xwork2.util;
 
+import org.apache.commons.lang.StringUtils;
+
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.Arrays;
      * @return the escaped string
      */
     public final static String htmlEncode(String s, boolean encodeSpecialChars) {
-        s = noNull(s);
+        s = StringUtils.defaultString(s);
 
         StringBuilder str = new StringBuilder();
 
      * @return the escaped string
      */
     public final static String escapeJavaScript(String s) {
-        s = noNull(s);
+        s = StringUtils.defaultString(s);
         StringBuffer str = new StringBuffer();
 
         for (int j = 0; j < s.length(); j++) {
         return str.toString();
     }
 
-    
-    /**
-     * Join an Iteration of Strings together.
-     *
-     * <h5>Example</h5>
-     *
-     * <pre>
-     *   // get Iterator of Strings ("abc","def","123");
-     *   Iterator i = getIterator();
-     *   out.print( TextUtils.join(", ",i) );
-     *   // prints: "abc, def, 123"
-     * </pre>
-     *
-     * @param glue Token to place between Strings.
-     * @param pieces Iteration of Strings to join.
-     * @return String presentation of joined Strings.
-     */
-    public final static String join(String glue, Iterator<?> pieces) {
-        StringBuilder s = new StringBuilder();
-
-        while (pieces.hasNext()) {
-            s.append(pieces.next().toString());
-
-            if (pieces.hasNext()) {
-                s.append(glue);
-            }
-        }
-
-        return s.toString();
-    }
-
-    /**
-     * Join an array of Strings together.
-     *
-     * @param glue Token to place between Strings.
-     * @param pieces Array of Strings to join.
-     * @return String presentation of joined Strings.
-     *
-     * @see #join(String, java.util.Iterator)
-     */
-    public final static String join(String glue, String[] pieces) {
-        return join(glue, Arrays.asList(pieces).iterator());
-    }
-
-    /**
-     * Join a Collection of Strings together.
-     *
-     * @param glue Token to place between Strings.
-     * @param pieces Collection of Strings to join.
-     * @return String presentation of joined Strings.
-     *
-     * @see #join(String, java.util.Iterator)
-     */
-    public final static String join(String glue, Collection<?> pieces) {
-        return join(glue, pieces.iterator());
-    }
-
-    /**
-     * Return <code>string</code>, or <code>defaultString</code> if
-     * <code>string</code> is <code>null</code> or <code>""</code>.
-     * Never returns <code>null</code>.
-     *
-     * <p>Examples:</p>
-     * <pre>
-     * // prints "hello"
-     * String s=null;
-     * System.out.println(TextUtils.noNull(s,"hello");
-     *
-     * // prints "hello"
-     * s="";
-     * System.out.println(TextUtils.noNull(s,"hello");
-     *
-     * // prints "world"
-     * s="world";
-     * System.out.println(TextUtils.noNull(s, "hello");
-     * </pre>
-     *
-     * @param string the String to check.
-     * @param defaultString The default string to return if <code>string</code> is <code>null</code> or <code>""</code>
-     * @return <code>string</code> if <code>string</code> is non-empty, and <code>defaultString</code> otherwise
-     * @see #stringSet(java.lang.String)
-     */
-    public final static String noNull(String string, String defaultString) {
-        return (stringSet(string)) ? string : defaultString;
-    }
-
-    /**
-     * Return <code>string</code>, or <code>""</code> if <code>string</code>
-     * is <code>null</code>. Never returns <code>null</code>.
-     * <p>Examples:</p>
-     * <pre>
-     * // prints 0
-     * String s=null;
-     * System.out.println(TextUtils.noNull(s).length());
-     *
-     * // prints 1
-     * s="a";
-     * System.out.println(TextUtils.noNull(s).length());
-     * </pre>
-     * @param string the String to check
-     * @return a valid (non-null) string reference
-     */
-    public final static String noNull(String string) {
-        return noNull(string, "");
-    }
-
-    /**
-     * Check whether <code>string</code> has been set to
-     * something other than <code>""</code> or <code>null</code>.
-     * @param string the <code>String</code> to check
-     * @return a boolean indicating whether the string was non-empty (and non-null)
-     */
-    public final static boolean stringSet(String string) {
-        return (string != null) && !"".equals(string);
-    }
-
     /**
      * Verify That the given String is in valid URL format.
      * @param url The url string to verify.

File src/java/com/opensymphony/xwork2/util/finder/UrlSet.java

View file
 import java.net.URL;
 import java.util.*;
 
+import org.apache.commons.lang.StringUtils;
+
 /**
  * Use with ClassFinder to filter the Urls to be scanned, example:
  * <pre>
         String[] paths = pathString.split(File.pathSeparator);
         UrlSet urlSet = this;
         for (String path : paths) {
-            if (TextUtils.stringSet(path)) {
+            if (StringUtils.isNotEmpty(path)) {
                 File file = new File(path);
                 urlSet = urlSet.exclude(file);
             }

File src/test/com/opensymphony/xwork2/util/TextUtilsTest.java

View file
         assertEquals(true, TextUtils.verifyUrl("https://www.opensymphony.com:443/login"));
         assertEquals(true, TextUtils.verifyUrl("http://localhost:8080/myapp"));
     }
-
-    public void testJoin() {
-        assertEquals("abc-def-hij", TextUtils.join("-", new String[]{"abc", "def", "hij"}));
-        assertEquals("--", TextUtils.join("-", new String[]{"", "", ""}));
-
-        assertEquals("abc-def-hij", TextUtils.join("-", Arrays.asList("abc", "def", "hij")));
-        assertEquals("--", TextUtils.join("-", Arrays.asList("", "", "")));
-
-        assertEquals("abc-def-hij", TextUtils.join("-", Arrays.asList("abc", "def", "hij").iterator()));
-        assertEquals("--", TextUtils.join("-", Arrays.asList("", "", "").iterator()));
-    }
-
-    public void testNotNull() {
-        assertEquals("Hello World", TextUtils.noNull("Hello World"));
-        assertEquals("   Hey   ", TextUtils.noNull("   Hey   "));
-        assertEquals(" ", TextUtils.noNull(" "));
-        assertEquals("", TextUtils.noNull(null));
-
-        assertEquals("Hello World", TextUtils.noNull("Hello World", "Santa"));
-        assertEquals("   Hey   ", TextUtils.noNull("   Hey   ", "Santa"));
-        assertEquals(" ", TextUtils.noNull(" ", "Santa"));
-        assertEquals("Santa", TextUtils.noNull(null, "Santa"));
-    }
-
-    public void testStringSet() {
-        assertEquals(true, TextUtils.stringSet("Hello World"));
-        assertEquals(true, TextUtils.stringSet("   Hey   "));
-        assertEquals(true, TextUtils.stringSet(" "));
-        assertEquals(false, TextUtils.stringSet(""));
-        assertEquals(false, TextUtils.stringSet(null));
-    }
-
 }