1 48 49 package org.jpublish.vfs; 50 51 import com.anthonyeden.lib.util.ClassUtilities; 52 import org.apache.commons.logging.Log; 53 import org.apache.commons.logging.LogFactory; 54 import org.apache.commons.vfs.provider.FileProvider; 55 import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider; 56 import org.apache.commons.vfs.provider.servletcontext.ServletContextFileProvider; 57 import org.apache.commons.vfs.provider.url.UrlFileProvider; 58 import org.jpublish.SiteContext; 59 60 66 67 public class FileProviderFactory { 68 69 72 public static final String WEBAPP = "webapp"; 73 74 77 public static final String FILE = "file"; 78 79 82 public static final String URL = "url"; 83 84 private Log log = LogFactory.getLog(FileProviderFactory.class); 85 protected SiteContext siteContext; 86 87 92 93 public FileProviderFactory(SiteContext siteContext) { 94 this.siteContext = siteContext; 95 } 96 97 107 108 public FileProvider createProvider(String name) 109 throws ClassNotFoundException , 110 InstantiationException , 111 IllegalAccessException { 112 if (log.isDebugEnabled()) { 113 log.debug("createProvider(" + name + ")"); 114 } 115 if (WEBAPP.equals(name) || 116 ServletContextFileProvider.class.getName().equals(name)) { 117 log.debug("Constructing ServletContextFileProvider"); 118 return new ServletContextFileProvider(siteContext.getServletContext()); 119 } else if (FILE.equals(name)) { 120 log.debug("Constructing DefaultLocalFileProvider"); 121 return new DefaultLocalFileProvider(); 122 } else if (URL.equals(name)) { 123 log.debug("Constructing URLProvider"); 124 return new UrlFileProvider(); 125 } else { 126 log.debug("Constructing by class name"); 127 return (FileProvider) ClassUtilities.loadClass(name).newInstance(); 128 } 129 } 130 131 } 132 | Popular Tags |