1 10 package mondrian.spi.impl; 11 12 import mondrian.spi.CatalogLocator; 13 14 import javax.servlet.ServletContext ; 15 import java.net.URL ; 16 import java.net.MalformedURLException ; 17 18 28 public class ServletContextCatalogLocator implements CatalogLocator { 29 private ServletContext servletContext; 30 31 public ServletContextCatalogLocator(ServletContext servletContext) { 32 this.servletContext = servletContext; 33 } 34 35 public String locate(String catalogPath) { 36 if (catalogPath != null && catalogPath.startsWith("/")) { 39 try { 40 URL url = servletContext.getResource(catalogPath); 41 if (url == null) { 42 url = servletContext.getResource("/"); 45 url = new URL (url.getProtocol(), url.getHost(), 46 url.getPort(), 47 url.getFile() + catalogPath.substring(1)); 48 } 49 catalogPath = url.toString(); 50 } catch (MalformedURLException ignored) { 51 } 52 } 53 return catalogPath; 54 } 55 } 56 57 | Popular Tags |