Anonymous avatar Anonymous committed 48bd205

XWorkConverter only loads the first classpath entry, it should load all entries

Issue Number: XW-616
Submitted by: Brian Pontarelli

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

Comments (0)

Files changed (3)

src/java/com/opensymphony/xwork2/conversion/impl/XWorkConverter.java

 import java.lang.annotation.Annotation;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.ognl.XWorkTypeConverterWrapper;
 import com.opensymphony.xwork2.util.AnnotationUtils;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.util.CompoundRoot;
 import com.opensymphony.xwork2.util.FileManager;
 import com.opensymphony.xwork2.util.LocalizedTextUtil;
     }
 
     public void loadConversionProperties(String propsName) throws IOException {
-        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(propsName);
+        Iterator<URL> resources = ClassLoaderUtil.getResources(propsName, getClass(), true);
+        while (resources.hasNext()) {
+            URL url = resources.next();
         Properties props = new Properties();
-        props.load(is);
+            props.load(url.openStream());
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("processing conversion file ["+propsName+"]");
         }
         
-        for (Iterator iterator = props.entrySet().iterator();
-             iterator.hasNext();) {
+            for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();) {
             Map.Entry entry = (Map.Entry) iterator.next();
             String key = (String) entry.getKey();
 
             }
         }
     }
+    }
 
     /**
      * Recurses through a class' interfaces and class hierarchy looking for a TypeConverter in the default mapping that

src/test/com/opensymphony/xwork2/conversion/impl/XWorkConverterTest.java

  */
 package com.opensymphony.xwork2.conversion.impl;
 
-import com.opensymphony.xwork2.*;
-import com.opensymphony.xwork2.config.ConfigurationManager;
-import com.opensymphony.xwork2.conversion.impl.XWorkConverter;
-import com.opensymphony.xwork2.ognl.OgnlReflectionProvider;
+import java.io.File;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ModelDrivenAction;
+import com.opensymphony.xwork2.SimpleAction;
+import com.opensymphony.xwork2.TestBean;
+import com.opensymphony.xwork2.XWorkTestCase;
 import com.opensymphony.xwork2.ognl.OgnlValueStack;
 import com.opensymphony.xwork2.test.ModelDrivenAction2;
 import com.opensymphony.xwork2.test.User;
 import com.opensymphony.xwork2.util.Cat;
 import com.opensymphony.xwork2.util.Foo;
 import com.opensymphony.xwork2.util.FurColor;
-import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.ValueStackFactory;
 import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
-
 import ognl.OgnlException;
 import ognl.OgnlRuntime;
 
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-import java.io.InputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ByteArrayInputStream;
-
 
 /**
  * @author $Author$
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
             Thread.currentThread().setContextClassLoader(new ClassLoader(cl) {
-                public InputStream getResourceAsStream(String name) {
+                public Enumeration<URL> getResources(String name) throws IOException {
                     if ("xwork-conversion.properties".equals(name)) {
-                        Properties props = new Properties();
-                        props.setProperty(Bar.class.getName(), FooBarConverter.class.getName());
-                        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+                        return new Enumeration<URL>() {
+                            boolean done = false;
+                            public boolean hasMoreElements() {
+                                return !done;
+                            }
+
+                            public URL nextElement() {
+                                if (done) {
+                                    throw new RuntimeException("Conversion configuration loading " +
+                                        "failed because it asked the enumeration for the next URL " +
+                                        "too many times");
+                                }
+
                         try {
-                            props.store(bout, "");
-                        } catch (IOException e) {
-                            // ignore
+                                    done = true;
+                                    return new File(
+                                        "src/test/com/opensymphony/xwork2/conversion/impl/test-xwork-conversion.properties").
+                                        toURI().toURL();
+                                } catch (MalformedURLException e) {
+                                    // Eeck
+                                    throw new RuntimeException(e);
                         }
-                        return new ByteArrayInputStream(bout.toByteArray());
+                            }
+                        };
                     } else {
-                        return super.getResourceAsStream(name);
+                        return super.getResources(name);
                     }
                 }
             });

src/test/com/opensymphony/xwork2/conversion/impl/test-xwork-conversion.properties

+com.opensymphony.xwork2.util.Bar=com.opensymphony.xwork2.conversion.impl.FooBarConverter
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.