You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2012/05/31 05:04:18 UTC

svn commit: r1344548 - in /camel/branches/camel-2.9.x: ./ camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/camel/component/validator/ camel-core/src/test/resources/org/apache/camel/component/validator/dotslash/ camel-...

Author: ningjiang
Date: Thu May 31 03:04:17 2012
New Revision: 1344548

URL: http://svn.apache.org/viewvc?rev=1344548&view=rev
Log:
Merged revisions 1344532-1344533 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1344532 | ningjiang | 2012-05-31 10:09:55 +0800 (Thu, 31 May 2012) | 1 line
  
  CAMEL-5321 Fixed the issue that Validator component fails on XSD with classpath relative imports
........
  r1344533 | ningjiang | 2012-05-31 10:11:34 +0800 (Thu, 31 May 2012) | 1 line
  
  CAMEL-5321 Added the file which I missed
........

Added:
    camel/branches/camel-2.9.x/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorSchemaImportTest.java
      - copied unchanged from r1344533, camel/trunk/camel-core/src/test/java/org/apache/camel/component/validator/ValidatorSchemaImportTest.java
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/dotslash/
      - copied from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/dotslash/
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/dotslash/child.xsd
      - copied unchanged from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/dotslash/child.xsd
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/dotslash/parent.xsd
      - copied unchanged from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/dotslash/parent.xsd
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/doubleslash/
      - copied from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/doubleslash/
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/doubleslash/child.xsd
      - copied unchanged from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/doubleslash/child.xsd
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/doubleslash/parent.xsd
      - copied unchanged from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/doubleslash/parent.xsd
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/relativeparent/
      - copied from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/relativeparent/
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/relativeparent/child/
      - copied from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/relativeparent/child/
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/relativeparent/child/child.xsd
      - copied unchanged from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/relativeparent/child/child.xsd
    camel/branches/camel-2.9.x/camel-core/src/test/resources/org/apache/camel/component/validator/relativeparent/parent.xsd
      - copied unchanged from r1344533, camel/trunk/camel-core/src/test/resources/org/apache/camel/component/validator/relativeparent/parent.xsd
Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1344532-1344533

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java?rev=1344548&r1=1344547&r2=1344548&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java (original)
+++ camel/branches/camel-2.9.x/camel-core/src/main/java/org/apache/camel/util/ObjectHelper.java Thu May 31 03:04:17 2012
@@ -19,6 +19,7 @@ package org.apache.camel.util;
 import java.io.Closeable;
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.AnnotatedElement;
@@ -33,6 +34,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
@@ -831,12 +833,13 @@ public final class ObjectHelper {
     public static InputStream loadResourceAsStream(String name) {
         InputStream in = null;
 
+        String resolvedName = resolveUriPath(name);
         ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
         if (contextClassLoader != null) {
-            in = contextClassLoader.getResourceAsStream(name);
+            in = contextClassLoader.getResourceAsStream(resolvedName);
         }
         if (in == null) {
-            in = ObjectHelper.class.getClassLoader().getResourceAsStream(name);
+            in = ObjectHelper.class.getClassLoader().getResourceAsStream(resolvedName);
         }
 
         return in;
@@ -852,18 +855,70 @@ public final class ObjectHelper {
     public static URL loadResourceAsURL(String name) {
         URL url = null;
 
+        String resolvedName = resolveUriPath(name);
         ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
         if (contextClassLoader != null) {
-            url = contextClassLoader.getResource(name);
+            url = contextClassLoader.getResource(resolvedName);
         }
         if (url == null) {
-            url = ObjectHelper.class.getClassLoader().getResource(name);
+            url = ObjectHelper.class.getClassLoader().getResource(resolvedName);
         }
 
         return url;
     }
 
     /**
+     * Attempts to load the given resources from the given package name using the thread context
+     * class loader or the class loader used to load this class
+     *
+     * @param packageName the name of the package to load its resources
+     * @return the URLs for the resources or null if it could not be loaded
+     */
+    public static Enumeration<URL> loadResourcesAsURL(String packageName) {
+        Enumeration<URL> url = null;
+
+        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+        if (contextClassLoader != null) {
+            try {
+                url = contextClassLoader.getResources(packageName);
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+        if (url == null) {
+            try {
+                url = ObjectHelper.class.getClassLoader().getResources(packageName);
+            } catch (IOException e) {
+                // ignore
+            }
+        }
+
+        return url;
+    }
+    
+    /**
+     * Helper operation used to remove relative path notation from 
+     * resources.  Most critical for resources on the Classpath
+     * as resource loaders will not resolve the relative paths correctly.
+     * 
+     * @param name the name of the resource to load
+     * @return the modified or unmodified string if there were no changes
+     */
+    private static String resolveUriPath(String name) {
+        String answer = name;
+        if(answer.indexOf("//") > -1) {
+            answer = answer.replaceAll("//", "/");
+        }
+        if(answer.indexOf("../") > -1) {
+            answer = answer.replaceAll("[A-Za-z0-9]*/\\.\\./", "");
+        }
+        if(answer.indexOf("./") > -1) {
+            answer = answer.replaceAll("\\./", "");
+        }
+        return answer;
+    }
+
+    /**
      * A helper method to invoke a method via reflection and wrap any exceptions
      * as {@link RuntimeCamelException} instances
      *