1 21 package com.jaspersoft.jasperserver.api.engine.jasperreports.util.repo; 22 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.net.URLStreamHandler ; 26 import java.net.URLStreamHandlerFactory ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 import com.jaspersoft.jasperserver.api.JSExceptionWrapper; 32 33 34 38 public class RepositoryURLHandlerFactory implements URLStreamHandlerFactory 39 { 40 protected static final Log log = LogFactory.getLog(RepositoryURLHandlerFactory.class); 41 42 private final static RepositoryURLHandlerFactory instance = new RepositoryURLHandlerFactory(); 43 44 public static RepositoryURLHandlerFactory getInstance() 45 { 46 return instance; 47 } 48 49 private final Handler repositoryHandler; 50 51 protected RepositoryURLHandlerFactory() 52 { 53 repositoryHandler = new Handler(); 54 } 55 56 public URLStreamHandler createURLStreamHandler(String protocol) 57 { 58 if (protocol.equals(Handler.REPOSITORY_PROTOCOL)) 59 { 60 return repositoryHandler; 61 } 62 63 return null; 64 } 65 66 public Handler getRepoHandler() { 67 return repositoryHandler; 68 } 69 70 public static URL createRepoURL(String uri) { 71 try { 72 return new URL (null, Handler.URL_PROTOCOL_PREFIX + uri, getInstance().getRepoHandler()); 73 } catch (MalformedURLException e) { 74 log.error(e, e); 75 throw new JSExceptionWrapper(e); 76 } 77 } 78 } 79 | Popular Tags |