1 28 package net.sf.jguard.jee.util; 29 30 import java.net.MalformedURLException ; 31 32 import javax.servlet.ServletContext ; 33 34 import net.sf.jguard.ext.util.XMLUtils; 35 36 import org.apache.commons.logging.Log; 37 import org.apache.commons.logging.LogFactory; 38 39 public class WebappUtil { 40 41 private static final Log logger = LogFactory.getLog(WebappUtil.class); 42 43 44 public static String getWebappHomePath(ServletContext context,String path) { 45 46 String realPath = null; 47 48 try { 50 realPath = context.getResource(path).toString(); 51 } catch (MalformedURLException e) { 52 throw new IllegalArgumentException (e.getMessage()); 53 } 54 55 if(realPath.startsWith("jndi:")&& context.getRealPath(path)!=null){ 56 realPath = context.getRealPath(path); 57 } 58 59 if(realPath==null){ 61 realPath = Thread.currentThread().getContextClassLoader().getResource(path).toString(); 62 } 63 64 65 66 if(logger.isDebugEnabled()){ 67 logger.debug("webappHomePath="+realPath); 68 } 69 70 realPath = XMLUtils.resolveLocation(realPath); 72 73 return realPath; 74 75 76 } 77 } 78 | Popular Tags |