1 25 package org.ofbiz.base.config; 26 27 import java.net.*; 28 import java.io.*; 29 30 37 public class UrlLoader extends ResourceLoader implements java.io.Serializable { 38 39 public URL getURL(String location) throws GenericConfigException { 40 String fullLocation = fullLocation(location); 41 42 URL url = null; 43 44 try { 45 url = new URL(fullLocation); 46 } catch (java.net.MalformedURLException e) { 47 throw new GenericConfigException("Error with malformed URL while trying to load URL resource at location [" + fullLocation + "]", e); 48 } 49 if (url == null) { 50 throw new GenericConfigException("URL Resource not found: " + fullLocation); 51 } 52 53 return url; 54 } 55 56 public InputStream loadResource(String location) throws GenericConfigException { 57 URL url = getURL(location); 58 59 try { 60 return url.openStream(); 61 } catch (java.io.IOException e) { 62 throw new GenericConfigException("Error opening URL resource at location [" + url.toExternalForm() + "]", e); 63 } 64 } 65 } 66 | Popular Tags |