1 16 package org.apache.cocoon.components.url; 17 18 import org.apache.avalon.framework.context.Context; 19 import org.apache.avalon.framework.context.ContextException; 20 import org.apache.avalon.framework.context.Contextualizable; 21 import org.apache.avalon.framework.logger.AbstractLogEnabled; 22 23 import org.apache.cocoon.util.ClassUtils; 24 25 import java.net.MalformedURLException ; 26 import java.net.URL ; 27 28 34 public class ResourceURLFactory extends AbstractLogEnabled implements URLFactory, Contextualizable { 35 36 39 protected Context context; 40 41 50 public URL getURL(String location) throws MalformedURLException { 51 URL u = ClassUtils.getResource(location); 52 if (u != null) 53 return u; 54 else { 55 getLogger().error(location + " could not be found. (possible classloader problem)"); 56 throw new RuntimeException (location + " could not be found. (possible classloader problem)"); 57 } 58 } 59 60 public URL getURL(URL base, String location) throws MalformedURLException { 61 return getURL (base.toExternalForm() + location); 62 } 63 64 67 public void contextualize(Context context) throws ContextException { 68 if (this.context == null) { 69 this.context = context; 70 } 71 } 72 } 73 | Popular Tags |