001
014
015 package com.liferay.portal.kernel.servlet;
016
017 import com.liferay.portal.kernel.util.CharPool;
018 import com.liferay.portal.kernel.util.ClassUtil;
019
020
023 public class WebDirDetector {
024
025 public static String getLibDir(ClassLoader classLoader) {
026 String libDir = ClassUtil.getParentPath(
027 classLoader, "com.liferay.util.bean.PortletBeanLocatorUtil");
028
029 if (libDir.endsWith("/WEB-INF/classes/")) {
030 return libDir.substring(0, libDir.length() - 8) + "lib/";
031 }
032
033 int pos = libDir.indexOf("/WEB-INF/lib/");
034
035 if (pos != -1) {
036 return libDir.substring(0, pos) + "/WEB-INF/lib/";
037 }
038
039 if (libDir.endsWith(".jar!/")) {
040 pos = libDir.lastIndexOf(CharPool.SLASH, libDir.length() - 7);
041
042 if (pos != -1) {
043 return libDir.substring(0, pos + 1);
044 }
045 }
046
047 return libDir;
048 }
049
050 public static String getRootDir(ClassLoader classLoader) {
051 return getRootDir(getLibDir(classLoader));
052 }
053
054 public static String getRootDir(String libDir) {
055 String rootDir = libDir;
056
057 if (rootDir.endsWith("/WEB-INF/lib/")) {
058 rootDir = rootDir.substring(0, rootDir.length() - 12);
059 }
060
061 return rootDir;
062 }
063
064 }