1 17 package org.alfresco.config.source; 18 19 import java.io.InputStream ; 20 import java.util.Collections ; 21 import java.util.List ; 22 23 import org.alfresco.config.ConfigException; 24 25 38 public class UrlConfigSource extends BaseConfigSource 39 { 40 public static final String PREFIX_FILE = "file:"; 41 public static final String PREFIX_HTTP = "http:"; 42 public static final String PREFIX_CLASSPATH = "classpath:"; 43 44 52 public UrlConfigSource(String sourceLocation) 53 { 54 this(Collections.singletonList(sourceLocation)); 55 } 56 57 63 public UrlConfigSource(List <String > sourceLocations) 64 { 65 super(sourceLocations); 66 } 67 68 public InputStream getInputStream(String sourceUrl) 69 { 70 BaseConfigSource configSource = null; 72 String sourceString = null; 73 if (sourceUrl.startsWith(PREFIX_FILE)) 74 { 75 sourceString = sourceUrl.substring(5); 76 configSource = new FileConfigSource(sourceString); 77 } 78 else if (sourceUrl.startsWith(PREFIX_HTTP)) 79 { 80 sourceString = sourceUrl; 81 configSource = new HTTPConfigSource(sourceString); 82 } 83 else if (sourceUrl.startsWith(PREFIX_CLASSPATH)) 84 { 85 sourceString = sourceUrl.substring(10); 86 configSource = new ClassPathConfigSource(sourceString); 87 } 88 else if (sourceUrl.indexOf(':') > -1) 89 { 90 throw new ConfigException("Config source cannot be determined: " + sourceString); 91 } 92 else 93 { 94 sourceString = sourceUrl; 95 configSource = new ClassPathConfigSource(sourceString); 96 } 97 98 return configSource.getInputStream(sourceString); 99 } 100 } 101 | Popular Tags |