1 17 package org.apache.excalibur.source.impl; 18 19 import java.io.IOException ; 20 import java.net.MalformedURLException ; 21 import java.net.URL ; 22 import java.util.Map ; 23 24 import org.apache.avalon.framework.logger.AbstractLogEnabled; 25 import org.apache.avalon.framework.thread.ThreadSafe; 26 import org.apache.excalibur.source.Source; 27 import org.apache.excalibur.source.SourceFactory; 28 29 40 public class URLSourceFactory extends AbstractLogEnabled implements SourceFactory, ThreadSafe 41 { 42 43 47 protected Source createURLSource(URL url, Map parameters) throws MalformedURLException , IOException 48 { 49 URLSource result = new URLSource(); 50 result.init(url, parameters); 51 return result; 52 } 53 54 58 protected Source createFileSource(String uri) throws MalformedURLException , IOException 59 { 60 return new FileSource(uri); 61 } 62 63 66 public Source getSource(String uri, Map parameters) throws MalformedURLException , IOException 67 { 68 if (getLogger().isDebugEnabled()) 69 { 70 final String message = "Creating source object for " + uri; 71 getLogger().debug(message); 72 } 73 74 if (uri.startsWith("file:")) 76 { 77 return createFileSource(uri); 79 } 80 else 81 { 82 URL url; 85 try 86 { 87 url = new URL (uri); 88 } 89 catch (MalformedURLException mue) 90 { 91 if (getLogger().isDebugEnabled()) 93 { 94 this.getLogger().debug("URL " + uri + " is malformed. Assuming it's a file path.", mue); 95 } 96 return createFileSource(uri); 97 } 98 99 return createURLSource(url, parameters); 100 } 101 } 102 103 106 public void release(Source source) 107 { 108 } 110 } 111 | Popular Tags |