cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1514034 - in /cxf/trunk: core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java core/src/main/java/org/apache/cxf/bus/spring/BusEntityResolver.java testutils/src/main/java/org/apache/cxf/test/TestApplicationContext.java
Date Wed, 14 Aug 2013 20:40:58 GMT
Author: dkulp
Date: Wed Aug 14 20:40:57 2013
New Revision: 1514034

URL: http://svn.apache.org/r1514034
Log:
[CXF-5181] Spring doesn't set the proper systemId so relative schema imports don't work very
well.

Modified:
    cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
    cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusEntityResolver.java
    cxf/trunk/testutils/src/main/java/org/apache/cxf/test/TestApplicationContext.java

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java?rev=1514034&r1=1514033&r2=1514034&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusApplicationContext.java Wed
Aug 14 20:40:57 2013
@@ -313,7 +313,7 @@ public class BusApplicationContext exten
     
     void setEntityResolvers(XmlBeanDefinitionReader reader) {
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        reader.setEntityResolver(new BusEntityResolver(new BeansDtdResolver(),
+        reader.setEntityResolver(new BusEntityResolver(cl, new BeansDtdResolver(),
             new PluggableSchemaResolver(cl)));
     }
     @Override

Modified: cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusEntityResolver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusEntityResolver.java?rev=1514034&r1=1514033&r2=1514034&view=diff
==============================================================================
--- cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusEntityResolver.java (original)
+++ cxf/trunk/core/src/main/java/org/apache/cxf/bus/spring/BusEntityResolver.java Wed Aug
14 20:40:57 2013
@@ -20,6 +20,9 @@
 package org.apache.cxf.bus.spring;
 
 import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -29,6 +32,10 @@ import org.xml.sax.SAXException;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.springframework.beans.factory.xml.DelegatingEntityResolver;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PropertiesLoaderUtils;
+import org.springframework.util.CollectionUtils;
 
 /**
  * 
@@ -39,11 +46,23 @@ public class BusEntityResolver extends D
     
     private EntityResolver dtdResolver;
     private EntityResolver schemaResolver;
+    private Map<String, String> schemaMappings;
+    private ClassLoader classLoader;
     
-    public BusEntityResolver(EntityResolver dr, EntityResolver sr) {
+    public BusEntityResolver(ClassLoader loader, EntityResolver dr, EntityResolver sr) {
         super(dr, sr);
+        classLoader = loader;
         dtdResolver = dr;
         schemaResolver = sr;
+        
+        try {
+            Properties mappings = PropertiesLoaderUtils.loadAllProperties("META-INF/spring.schemas",

+                                                                          classLoader);
+            schemaMappings = new ConcurrentHashMap<String, String>(mappings.size());
+            CollectionUtils.mergePropertiesIntoMap(mappings, schemaMappings);
+        } catch (IOException e) {
+            //ignore
+        }
     }
 
     @Override
@@ -57,6 +76,14 @@ public class BusEntityResolver extends D
                 source = dtdResolver.resolveEntity(publicId, systemId); 
             }
         }
+        String resourceLocation = schemaMappings.get(systemId);
+        if (resourceLocation != null && publicId == null) {
+            Resource resource = new ClassPathResource(resourceLocation, classLoader);
+            if (resource != null && resource.exists()) {
+                source.setPublicId(systemId);    
+                source.setSystemId(resource.getURL().toString());
+            }
+        }
         return source;
     }    
 }

Modified: cxf/trunk/testutils/src/main/java/org/apache/cxf/test/TestApplicationContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/testutils/src/main/java/org/apache/cxf/test/TestApplicationContext.java?rev=1514034&r1=1514033&r2=1514034&view=diff
==============================================================================
--- cxf/trunk/testutils/src/main/java/org/apache/cxf/test/TestApplicationContext.java (original)
+++ cxf/trunk/testutils/src/main/java/org/apache/cxf/test/TestApplicationContext.java Wed
Aug 14 20:40:57 2013
@@ -42,7 +42,7 @@ public class TestApplicationContext exte
     @Override
     protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader) {
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
-        reader.setEntityResolver(new BusEntityResolver(new BeansDtdResolver(),
+        reader.setEntityResolver(new BusEntityResolver(cl, new BeansDtdResolver(),
             new PluggableSchemaResolver(cl)));
     }
    



Mime
View raw message