Commits

Anonymous committed c510e87

Fixing a little bug in the text node parsing patch, removing oscore from
the dependency list by adding the few classes used by it into the project.
XW-413
XW-412

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

Comments (0)

Files changed (23)

             <optional>true</optional>
         </dependency>
         <dependency>
-            <!-- group should be com.opensymphony ... -->
-            <groupId>opensymphony</groupId>
-            <artifactId>oscore</artifactId>
-            <version>2.2.4</version>
-        </dependency>
-        <dependency>
             <groupId>ognl</groupId>
             <artifactId>ognl</artifactId>
             <version>2.6.7</version>

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

  */
 package com.opensymphony.xwork2;
 
-import com.opensymphony.util.TextUtils;
+import com.opensymphony.xwork2.util.TextUtils;
 import com.opensymphony.xwork2.config.Configuration;
 import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.config.RuntimeConfiguration;

src/java/com/opensymphony/xwork2/ObjectFactory.java

  */
 package com.opensymphony.xwork2;
 
-import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.config.entities.ActionConfig;
 import com.opensymphony.xwork2.config.entities.InterceptorConfig;

src/java/com/opensymphony/xwork2/config/ConfigurationManager.java

  */
 package com.opensymphony.xwork2.config;
 
-import com.opensymphony.util.FileManager;
+import com.opensymphony.xwork2.util.FileManager;
 import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
 import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
 import org.apache.commons.logging.Log;

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

             return false;
         }
 
-        return !((results != null) ? (!results.equals(actionConfig.results)) : (actionConfig.results != null));
-
+        if ((results != null) ? (!results.equals(actionConfig.results)) : (actionConfig.results != null)) {
+            return false;
+        }
+        
+        return true;
     }
 
     public int hashCode() {

src/java/com/opensymphony/xwork2/config/entities/PackageConfig.java

  */
 package com.opensymphony.xwork2.config.entities;
 
-import com.opensymphony.util.TextUtils;
+import com.opensymphony.xwork2.util.TextUtils;
 import com.opensymphony.xwork2.config.ExternalReferenceResolver;
 import com.opensymphony.xwork2.util.location.Located;
 import org.apache.commons.logging.Log;

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

  */
 package com.opensymphony.xwork2.config.providers;
 
-import com.opensymphony.util.ClassLoaderUtil;
-import com.opensymphony.util.FileManager;
-import com.opensymphony.util.TextUtils;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.FileManager;
+import com.opensymphony.xwork2.util.TextUtils;
 import com.opensymphony.xwork2.Action;
 import com.opensymphony.xwork2.ActionSupport;
 import com.opensymphony.xwork2.ObjectFactory;
                 if (resultParams.size() == 0) // maybe we just have a body - therefore a default parameter
                 {
                     // if <result ...>something</result> then we add a parameter of 'something' as this is the most used result param
-                    if ((resultElement.getChildNodes().getLength() >= 1) && (resultElement.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE))
+                    if (resultElement.getChildNodes().getLength() >= 1)
                     {
                         resultParams = new LinkedHashMap();
 
                         String paramName = config.getDefaultResultParam();
                         if (paramName != null) {
                             StringBuffer paramValue = new StringBuffer();
-                            for (int j=0; i<resultElement.getChildNodes().getLength(); i++) {
-                                if (resultElement.getChildNodes().item(i).getNodeType() == Node.TEXT_NODE) {
-                                    String val = resultElement.getChildNodes().item(i).getNodeValue();
+                            for (int j=0; j<resultElement.getChildNodes().getLength(); j++) {
+                                if (resultElement.getChildNodes().item(j).getNodeType() == Node.TEXT_NODE) {
+                                    String val = resultElement.getChildNodes().item(j).getNodeValue();
                                     if (val != null) {
                                         paramValue.append(val);
                                     }
                                 }
                             }
-                            if (paramValue.length() > 0) {
-                                resultParams.put(paramName, paramValue.toString().trim());
+                            String val = paramValue.toString().trim();
+                            if (val.length() > 0) {
+                                resultParams.put(paramName, val);
                             }
                         }
                         else {

src/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.net.URL;
+
+
+/**
+ * This class is extremely useful for loading resources and classes in a fault tolerant manner
+ * that works across different applications servers.
+ *
+ * It has come out of many months of frustrating use of multiple application servers at Atlassian,
+ * please don't change things unless you're sure they're not going to break in one server or another!
+ * 
+ * It was brought in from oscore trunk revision 147.
+ *
+ * @author $Author: hani $
+ * @version $Revision: 117 $
+ */
+public class ClassLoaderUtil {
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    /**
+    * Load a given resource.
+    *
+    * This method will try to load the resource using the following methods (in order):
+    * <ul>
+    *  <li>From Thread.currentThread().getContextClassLoader()
+    *  <li>From ClassLoaderUtil.class.getClassLoader()
+    *  <li>callingClass.getClassLoader()
+    * </ul>
+    *
+    * @param resourceName The name of the resource to load
+    * @param callingClass The Class object of the calling object
+    */
+    public static URL getResource(String resourceName, Class callingClass) {
+        URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
+
+        if (url == null) {
+            url = ClassLoaderUtil.class.getClassLoader().getResource(resourceName);
+        }
+
+        if (url == null) {
+            ClassLoader cl = callingClass.getClassLoader();
+
+            if (cl != null) {
+                url = cl.getResource(resourceName);
+            }
+        }
+
+        if ((url == null) && (resourceName != null) && (resourceName.charAt(0) != '/')) {
+            return getResource('/' + resourceName, callingClass);
+        }
+
+        return url;
+    }
+
+    /**
+    * This is a convenience method to load a resource as a stream.
+    *
+    * The algorithm used to find the resource is given in getResource()
+    *
+    * @param resourceName The name of the resource to load
+    * @param callingClass The Class object of the calling object
+    */
+    public static InputStream getResourceAsStream(String resourceName, Class callingClass) {
+        URL url = getResource(resourceName, callingClass);
+
+        try {
+            return (url != null) ? url.openStream() : null;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+
+    /**
+    * Load a class with a given name.
+    *
+    * It will try to load the class in the following order:
+    * <ul>
+    *  <li>From Thread.currentThread().getContextClassLoader()
+    *  <li>Using the basic Class.forName()
+    *  <li>From ClassLoaderUtil.class.getClassLoader()
+    *  <li>From the callingClass.getClassLoader()
+    * </ul>
+    *
+    * @param className The name of the class to load
+    * @param callingClass The Class object of the calling object
+    * @throws ClassNotFoundException If the class cannot be found anywhere.
+    */
+    public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException {
+        try {
+            return Thread.currentThread().getContextClassLoader().loadClass(className);
+        } catch (ClassNotFoundException e) {
+            try {
+                return Class.forName(className);
+            } catch (ClassNotFoundException ex) {
+                try {
+                    return ClassLoaderUtil.class.getClassLoader().loadClass(className);
+                } catch (ClassNotFoundException exc) {
+                    return callingClass.getClassLoader().loadClass(className);
+                }
+            }
+        }
+    }
+}

src/java/com/opensymphony/xwork2/util/DomHelper.java

 
 import java.util.Map;
 
-import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 
 import com.opensymphony.xwork2.util.location.Location;
 import com.opensymphony.xwork2.util.location.LocationAttributes;

src/java/com/opensymphony/xwork2/util/FileManager.java

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import java.net.URL;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * FileManager
+ * 
+ * This class was brought in from oscore trunk revision 147.
+ *
+ * @author Jason Carreira
+ *         Created May 7, 2003 8:44:26 PM
+ */
+public class FileManager {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    private static Map files = Collections.synchronizedMap(new HashMap());
+    protected static boolean reloadingConfigs = false;
+
+    //~ Constructors ///////////////////////////////////////////////////////////
+
+    private FileManager() {
+    }
+
+    //~ Methods ////////////////////////////////////////////////////////////////
+
+    public static void setReloadingConfigs(boolean reloadingConfigs) {
+        FileManager.reloadingConfigs = reloadingConfigs;
+    }
+
+    public static boolean isReloadingConfigs() {
+        return reloadingConfigs;
+    }
+
+    public static boolean fileNeedsReloading(String fileName) {
+        FileRevision revision = (FileRevision) files.get(fileName);
+
+        if ((revision == null) && reloadingConfigs) {
+            // no revision yet and we keep the revision history, so 
+            // the file needs to be loaded for the first time
+            return true;
+        } else if (revision == null) {
+            return false;
+        }
+
+        return revision.getLastModified() < revision.getFile().lastModified();
+    }
+
+    /**
+     * Loads opens the named file and returns the InputStream
+     *
+     * @param fileName - the name of the file to open
+     * @return an InputStream of the file contents or null
+     * @throws IllegalArgumentException if there is no file with the given file name
+     */
+    public static InputStream loadFile(String fileName, Class clazz) {
+        URL fileUrl = ClassLoaderUtil.getResource(fileName, clazz);
+
+        if (fileUrl == null) {
+            return null;
+        }
+
+        InputStream is;
+
+        try {
+            is = fileUrl.openStream();
+
+            if (is == null) {
+                throw new IllegalArgumentException("No file '" + fileName + "' found as a resource");
+            }
+        } catch (IOException e) {
+            throw new IllegalArgumentException("No file '" + fileName + "' found as a resource");
+        }
+
+        if (isReloadingConfigs()) {
+            File file = new File(fileUrl.getFile());
+            long lastModified;
+
+            if (!file.exists() || !file.canRead()) {
+                file = null;
+            }
+
+            if (file != null) {
+                lastModified = file.lastModified();
+                files.put(fileName, new FileRevision(file, lastModified));
+            }
+        }
+
+        return is;
+    }
+
+    //~ Inner Classes //////////////////////////////////////////////////////////
+
+    private static class FileRevision {
+        private File file;
+        private long lastModified;
+
+        public FileRevision(File file, long lastUpdated) {
+            this.file = file;
+            this.lastModified = lastUpdated;
+        }
+
+        public File getFile() {
+            return file;
+        }
+
+        public void setLastModified(long lastModified) {
+            this.lastModified = lastModified;
+        }
+
+        public long getLastModified() {
+            return lastModified;
+        }
+    }
+}

src/java/com/opensymphony/xwork2/util/ObjectTypeDeterminerFactory.java

 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 
 /**
  * Factory for getting an instance of {@link ObjectTypeDeterminer}.

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

  */
 package com.opensymphony.xwork2.util;
 
-import com.opensymphony.util.TextUtils;
+import com.opensymphony.xwork2.util.TextUtils;
 
 import java.util.HashSet;
 import java.util.Set;

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

+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork2.util;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+
+/**
+ * Utilities for common String manipulations.
+ *
+ * This is a class contains static methods only and is not meant to be instantiated.
+ * It was brought in from oscore trunk revision 147, and trimmed to only contain
+ * methods used by XWork.
+ *
+ * @author <a href="mailto:joe@truemesh.com">Joe Walnes</a>
+ * @author <a href="mailto:pkan@internet.com">Patrick Kan</a>
+ * @author <a href="mailto:mcannon@internet.com">Mike Cannon-Brookes</a>
+ * @author <a href="mailto:hani@fate.demon.co.uk">Hani Suleiman</a>
+ * @author <a href="mailto:joeo@adjacency.org">Joseph B. Ottinger</a>
+ * @author <a href="mailto:scott@atlassian.com">Scott Farquhar</a>
+ *
+ * @version $Revision: 147 $
+ */
+public class TextUtils {
+    //~ Static fields/initializers /////////////////////////////////////////////
+
+    /**
+     * An array of HTML tags that, in HTML, don't require closing tags. Note that
+     * XHTML doesn't work this way.
+     */
+    public final static String[] SINGLE_TAGS = {"br", "p", "hr"};
+
+    /**
+     * 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) {
+        StringBuffer s = new StringBuffer();
+
+        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.
+     * @return a boolean indicating whether the URL seems to be incorrect.
+     */
+    public final static boolean verifyUrl(String url) {
+        if (url == null) {
+            return false;
+        }
+
+        if (url.startsWith("https://")) {
+            // URL doesn't understand the https protocol, hack it
+            url = "http://" + url.substring(8);
+        }
+
+        try {
+            new URL(url);
+
+            return true;
+        } catch (MalformedURLException e) {
+            return false;
+        }
+    }
+}

src/java/com/opensymphony/xwork2/util/XWorkBasicConverter.java

 import ognl.Ognl;
 import ognl.TypeConverter;
 
-import com.opensymphony.util.TextUtils;
+import com.opensymphony.xwork2.util.TextUtils;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.XWorkException;
 

src/java/com/opensymphony/xwork2/util/XWorkConverter.java

 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import com.opensymphony.util.FileManager;
+import com.opensymphony.xwork2.util.FileManager;
 import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.XWorkMessages;

src/java/com/opensymphony/xwork2/util/location/LocationUtils.java

 
 import org.w3c.dom.Element;
 
-import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 
 /**
  * Location-related utility methods.

src/java/com/opensymphony/xwork2/validator/ActionValidatorManagerFactory.java

 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.XWorkException;
 
 /**

src/java/com/opensymphony/xwork2/validator/DefaultActionValidatorManager.java

 
 package com.opensymphony.xwork2.validator;
 
-import com.opensymphony.util.FileManager;
+import com.opensymphony.xwork2.util.FileManager;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;

src/java/com/opensymphony/xwork2/validator/ValidatorFactory.java

  */
 package com.opensymphony.xwork2.validator;
 
-import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.XWorkException;
 import org.apache.commons.logging.Log;

src/java/com/opensymphony/xwork2/validator/validators/URLValidator.java

  */
 package com.opensymphony.xwork2.validator.validators;
 
-import com.opensymphony.util.TextUtils;
+import com.opensymphony.xwork2.util.TextUtils;
 import com.opensymphony.xwork2.validator.ValidationException;
 
 

src/test/com/opensymphony/xwork2/config/ConfigurationManagerTest.java

 
 import com.mockobjects.dynamic.C;
 import com.mockobjects.dynamic.Mock;
-import com.opensymphony.util.FileManager;
+import com.opensymphony.xwork2.util.FileManager;
 import com.opensymphony.xwork2.XWorkTestCase;
 
 import junit.framework.TestCase;

src/test/com/opensymphony/xwork2/util/location/LocationImplTest.java

 import java.net.URL;
 import java.util.List;
 
-import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.XWorkException;
 
 import junit.framework.TestCase;

src/test/com/opensymphony/xwork2/validator/ValidatorFileParserTest.java

  */
 package com.opensymphony.xwork2.validator;
 
-import com.opensymphony.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.XWorkException;
 import com.opensymphony.xwork2.XWorkTestCase;
 import com.opensymphony.xwork2.config.providers.MockConfigurationProvider;