001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.deploy;
022:
023: import com.liferay.portal.kernel.util.GetterUtil;
024: import com.liferay.portal.kernel.util.ServerDetector;
025: import com.liferay.portal.kernel.util.StringPool;
026: import com.liferay.portal.kernel.util.StringUtil;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.util.PrefsPropsUtil;
029: import com.liferay.portal.util.PropsUtil;
030: import com.liferay.portal.util.PropsValues;
031: import com.liferay.util.FileUtil;
032: import com.liferay.util.SystemProperties;
033:
034: import java.io.File;
035: import java.io.FileOutputStream;
036: import java.io.IOException;
037: import java.io.OutputStream;
038:
039: /**
040: * <a href="DeployUtil.java.html"><b><i>View Source</i></b></a>
041: *
042: * @author Brian Wing Shun Chan
043: *
044: */
045: public class DeployUtil {
046:
047: public static String getAutoDeployDestDir() throws Exception {
048: String destDir = PrefsPropsUtil.getString(
049: PropsUtil.AUTO_DEPLOY_DEST_DIR,
050: PropsValues.AUTO_DEPLOY_DEST_DIR);
051:
052: if (Validator.isNull(destDir)) {
053: destDir = getAutoDeployServerDestDir();
054: }
055:
056: return destDir;
057: }
058:
059: public static String getAutoDeployServerDestDir() throws Exception {
060: String destDir = null;
061:
062: String serverId = GetterUtil.getString(ServerDetector
063: .getServerId());
064:
065: if (serverId.equals(ServerDetector.TOMCAT_ID)) {
066: destDir = PrefsPropsUtil.getString(
067: PropsUtil.AUTO_DEPLOY_TOMCAT_DEST_DIR,
068: PropsValues.AUTO_DEPLOY_TOMCAT_DEST_DIR);
069: } else {
070: destDir = PrefsPropsUtil.getString("auto.deploy."
071: + serverId + ".dest.dir");
072: }
073:
074: if (Validator.isNull(destDir)) {
075: destDir = PrefsPropsUtil.getString(
076: PropsUtil.AUTO_DEPLOY_DEFAULT_DEST_DIR,
077: PropsValues.AUTO_DEPLOY_DEFAULT_DEST_DIR);
078: }
079:
080: destDir = StringUtil.replace(destDir, StringPool.BACK_SLASH,
081: StringPool.SLASH);
082:
083: return destDir;
084: }
085:
086: public static String getResourcePath(String resource)
087: throws Exception {
088:
089: return _instance._getResourcePath(resource);
090: }
091:
092: private DeployUtil() {
093: }
094:
095: private String _getResourcePath(String resource) throws IOException {
096: String tmpDir = SystemProperties.get(SystemProperties.TMP_DIR);
097:
098: File file = new File(tmpDir
099: + "/liferay/com/liferay/portal/deploy/dependencies/"
100: + resource);
101:
102: File parentFile = file.getParentFile();
103:
104: if (parentFile != null) {
105: parentFile.mkdirs();
106: }
107:
108: byte[] byteArray = FileUtil.getBytes(getClass()
109: .getResourceAsStream("dependencies/" + resource));
110:
111: OutputStream os = new FileOutputStream(file);
112:
113: os.write(byteArray);
114:
115: return FileUtil.getAbsolutePath(file);
116: }
117:
118: private static DeployUtil _instance = new DeployUtil();
119:
120: }
|