1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.kernel.servlet;
16  
17  import com.liferay.portal.kernel.util.ClassUtil;
18  
19  /**
20   * <a href="WebDirDetector.java.html"><b><i>View Source</i></b></a>
21   *
22   * @author Brian Wing Shun Chan
23   */
24  public class WebDirDetector {
25  
26      public static String getLibDir(ClassLoader classLoader) {
27          String libDir = ClassUtil.getParentPath(
28              classLoader, "com.liferay.util.bean.PortletBeanLocatorUtil");
29  
30          if (libDir.endsWith("/WEB-INF/classes/")) {
31              libDir = libDir.substring(0, libDir.length() - 8) + "lib/";
32          }
33          else {
34              int pos = libDir.indexOf("/WEB-INF/lib/");
35  
36              if (pos != -1) {
37                  libDir = libDir.substring(0, pos) + "/WEB-INF/lib/";
38              }
39          }
40  
41          return libDir;
42      }
43  
44      public static String getRootDir(ClassLoader classLoader) {
45          return getRootDir(getLibDir(classLoader));
46      }
47  
48      public static String getRootDir(String libDir) {
49          String rootDir = libDir;
50  
51          if (rootDir.endsWith("/WEB-INF/lib/")) {
52              rootDir = rootDir.substring(0, rootDir.length() - 12);
53          }
54  
55          return rootDir;
56      }
57  
58  }