1 10 11 package org.mule.extras.spring.config; 12 13 import java.io.IOException ; 14 import java.io.InputStream ; 15 16 import org.apache.commons.logging.Log; 17 import org.apache.commons.logging.LogFactory; 18 import org.mule.util.IOUtils; 19 import org.springframework.core.io.DefaultResourceLoader; 20 import org.springframework.core.io.InputStreamResource; 21 import org.springframework.core.io.Resource; 22 import org.springframework.core.io.support.ResourcePatternResolver; 23 24 28 public class MuleResourceLoader extends DefaultResourceLoader implements ResourcePatternResolver 29 { 30 protected transient Log logger = LogFactory.getLog(MuleResourceLoader.class); 31 32 public Resource getResource(String rsc) 33 { 34 return getResourceByPath(rsc); 35 } 36 37 protected Resource getResourceByPath(String path) 38 { 39 InputStream is = null; 40 try 41 { 42 is = IOUtils.getResourceAsStream(path, getClass()); 43 } 44 catch (IOException e) 45 { 46 logger.error("Unable to load Spring resource " + path + " : " + e.getMessage()); 47 return null; 48 } 49 50 if (is != null) 51 { 52 return new InputStreamResource(is); 53 } 54 else 55 { 56 logger.error("Unable to locate Spring resource " + path); 57 return null; 58 } 59 } 60 61 public Resource[] getResources(String rsc) throws IOException 62 { 63 if (rsc == null) 64 { 65 throw new IOException ("No resources to read"); 66 } 67 String [] resourcesNames = org.springframework.util.StringUtils.tokenizeToStringArray(rsc, ",;", true, 68 true); 69 Resource[] resources = new Resource[resourcesNames.length]; 70 for (int i = 0; i < resourcesNames.length; ++i) 71 { 72 resources[i] = getResourceByPath(resourcesNames[i]); 73 } 74 return resources; 75 } 76 } 77 | Popular Tags |