| WebDirDetector.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
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 }