cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject svn commit: r472442 - in /incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource: URIResolver.java XmlSchemaURIResolver.java
Date Wed, 08 Nov 2006 10:29:48 GMT
Author: tli
Date: Wed Nov  8 02:29:47 2006
New Revision: 472442

URL: http://svn.apache.org/viewvc?view=rev&rev=472442
Log:
CXF-178 add support for get resource with relative path of jar file

Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java?view=diff&rev=472442&r1=472441&r2=472442
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/URIResolver.java
Wed Nov  8 02:29:47 2006
@@ -96,7 +96,7 @@
         if (uriStr.startsWith("classpath:")) {
             tryClasspath(uriStr);
         } else if (baseUriStr != null && baseUriStr.startsWith("jar:")) {
-            tryJar(baseUriStr, uriStr);
+            tryJarState(baseUriStr, uriStr);
         } else if (uriStr.startsWith("jar:")) {
             tryJar(uriStr);
         } else {
@@ -233,6 +233,22 @@
         }
     }
 
+    private void tryJarState(String baseStr, String uriStr) throws IOException {
+        int i = baseStr.indexOf('!');
+        if (i == -1) {
+            tryFileSystemState(baseStr, uriStr);
+            return;
+        }
+        baseStr = baseStr.substring(i + 1);
+        URI u = getAbsoluteFileStr(baseStr.startsWith("file:") ? baseStr : "file:" + baseStr,
uriStr);
+        // remove the prefix "file:"
+        tryClasspath(u.toString().substring(5));
+        if (is != null) {
+            return;
+        }        
+        tryFileSystemState("", uriStr);
+    }
+    
     private void tryJar(String baseStr, String uriStr) throws IOException {
         int i = baseStr.indexOf('!');
         if (i == -1) {
@@ -260,13 +276,12 @@
         uriStr = uriStr.substring(i + 1);
         tryClasspath(uriStr);
     }
+    
     private void tryClasspath(String uriStr) throws IOException {
         if (uriStr.startsWith("classpath:")) {
             uriStr = uriStr.substring(10);
         }
-
         URL url = ClassLoaderUtils.getResource(uriStr, calling);
-
         if (url == null) {
             tryRemote(uriStr);
         } else {

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java?view=diff&rev=472442&r1=472441&r2=472442
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java
(original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/resource/XmlSchemaURIResolver.java
Wed Nov  8 02:29:47 2006
@@ -52,27 +52,47 @@
         }
     }
     public InputSource resolveEntity(String targetNamespace, String schemaLocation, String
baseUri) {
-        try {            
-            if (new URI(baseUri).isAbsolute()) {
-                currentResolver = new org.apache.cxf.resource.URIResolver();
-                stack.addElement(new ResolverInfo(schemaLocation, currentResolver));    
       
-            } else {
-                while (!stack.isEmpty()) {
-                    ResolverInfo ri = stack.pop();
-                    if (ri.getUri().equals(baseUri)) {
-                        currentResolver = ri.getResolver();
-                        stack.addElement(ri);
-                        break;
+        try {
+            if (baseUri != null) {
+                URI check = null;
+                if (baseUri.startsWith("classpath:")) {
+                    check = new URI(baseUri.substring(10));
+                } else if (baseUri.startsWith("jar:")) {
+                    int i = baseUri.indexOf("!");
+                    if (i != -1) {
+                        String bu = baseUri.substring(i + 1);
+                        check = new URI(bu.startsWith("file:") ? bu : "file:" + bu);
+                    } else {
+                        check = new URI(baseUri);
                     }
+                } else {
+                    check = new URI(baseUri);
+                }
+                if (check.isAbsolute()) {
+                    currentResolver = new org.apache.cxf.resource.URIResolver();
+                    stack.addElement(new ResolverInfo(schemaLocation, currentResolver));
           
+                } else {
+                    while (!stack.isEmpty()) {
+                        ResolverInfo ri = stack.pop();
+                        if (ri.getUri().equals(baseUri)) {
+                            currentResolver = ri.getResolver();
+                            stack.addElement(ri);
+                            break;
+                        }
+                    }
+                    stack.addElement(new ResolverInfo(schemaLocation, currentResolver));
           
+                }
+                if (currentResolver == null) {
+                    throw new RuntimeException("invalidate schema import");
+                }
+            } else {
+                if (currentResolver == null) {
+                    currentResolver = new org.apache.cxf.resource.URIResolver();
                 }
-                stack.addElement(new ResolverInfo(schemaLocation, currentResolver));    
       
-            }
-            if (currentResolver == null) {
-                throw new RuntimeException("invalidate schema import");
             }
             currentResolver.resolveStateful(baseUri, schemaLocation, getClass());
             if (currentResolver.isResolved()) {
-                if (currentResolver.getURI().isAbsolute()) {
+                if (currentResolver.getURI() != null && currentResolver.getURI().isAbsolute())
{
                     // When importing a relative file,
                     // setSystemId with an absolute path so the
                     // resolver finds any files which that file
@@ -94,4 +114,5 @@
 
     }
 
+    
 }



Mime
View raw message