001
014
015 package com.liferay.portal.deploy.sandbox;
016
017 import com.liferay.portal.kernel.deploy.sandbox.SandboxDeployException;
018 import com.liferay.portal.kernel.deploy.sandbox.SandboxDeployListener;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021 import com.liferay.portal.kernel.plugin.PluginPackage;
022 import com.liferay.portal.kernel.util.CharPool;
023 import com.liferay.portal.kernel.util.FileUtil;
024 import com.liferay.portal.kernel.util.ServerDetector;
025 import com.liferay.portal.kernel.util.StringBundler;
026 import com.liferay.portal.kernel.util.StringPool;
027 import com.liferay.portal.kernel.util.StringUtil;
028 import com.liferay.portal.tools.deploy.ThemeDeployer;
029 import com.liferay.portal.util.PortalUtil;
030 import com.liferay.util.ant.CopyTask;
031
032 import java.io.File;
033 import java.io.IOException;
034
035 import java.util.ArrayList;
036
037
041 public class ThemeSandboxDeployListener
042 extends ThemeDeployer implements SandboxDeployListener {
043
044 public ThemeSandboxDeployListener() {
045 if (!ServerDetector.isTomcat()) {
046 return;
047 }
048
049 _engineHostDir = _getEngineHostDir();
050
051 if (_engineHostDir == null) {
052 return;
053 }
054
055 appServerType = ServerDetector.getServerId();
056
057 String portalWebDir = PortalUtil.getPortalWebDir();
058
059 themeTaglibDTD = portalWebDir + "/WEB-INF/tld/liferay-theme.tld";
060 uiTaglibDTD = portalWebDir + "/WEB-INF/tld/liferay-util.tld";
061
062 jars = new ArrayList<String>();
063
064 String portalLibDir = PortalUtil.getPortalLibDir();
065
066 jars.add(portalLibDir + "/commons-logging.jar");
067 jars.add(portalLibDir + "/log4j.jar");
068 jars.add(portalLibDir + "/util-java.jar");
069 jars.add(portalLibDir + "/util-taglib.jar");
070 }
071
072 public void deploy(File dir) throws SandboxDeployException {
073 try {
074 if (!_isEnabled(dir)) {
075 return;
076 }
077
078 String dirName = dir.getName();
079
080 if (_log.isInfoEnabled()) {
081 _log.info("Deploying " + dirName);
082 }
083
084 _copyTheme(dir);
085
086 String themeName = _createThemeName(dirName);
087
088 _createPluginPackageProperties(dir, themeName);
089
090 PluginPackage pluginPackage = readPluginPackage(dir);
091
092 String displayName = _createDisplayName(dirName);
093
094 processPluginPackageProperties(dir, displayName, pluginPackage);
095
096 copyJars(dir, pluginPackage);
097 copyProperties(dir, pluginPackage);
098 copyTlds(dir, pluginPackage);
099 copyXmls(dir, displayName, pluginPackage);
100
101 updateWebXml(
102 new File(dir, "WEB-INF/web.xml"), dir, displayName,
103 pluginPackage);
104
105 _createContextXml(dir);
106 }
107 catch (Exception e) {
108 throw new SandboxDeployException(e);
109 }
110 }
111
112 public void undeploy(File dir) throws SandboxDeployException {
113 try {
114 if (!_isEnabled(dir)) {
115 return;
116 }
117
118 String dirName = dir.getName();
119
120 if (_log.isInfoEnabled()) {
121 _log.info("Undeploying " + dirName);
122 }
123
124 _deleteContextXml(dir);
125 }
126 catch (Exception e) {
127 throw new SandboxDeployException(e);
128 }
129 }
130
131 protected String getDisplayName(File srcFile) {
132 String displayName = super.getDisplayName(srcFile);
133
134 return _createDisplayName(displayName);
135 }
136
137 private void _copyTheme(File dir) {
138 String portalWebDir = PortalUtil.getPortalWebDir();
139
140 CopyTask.copyDirectory(
141 new File(portalWebDir, "html/themes/classic"), dir, null,
142 "/_diffsROOT.xml", null);
217
218 if (fileNames.length == 0) {
219 _log.error("Unable to locate ROOT.xml under CATALINA_BASE/conf");
220
221 return null;
222 }
223
224 File file = new File(dirName, fileNames[0]);
225
226 return file.getParentFile();
227 }
228
229 private boolean _isEnabled(File dir) {
230 if (_engineHostDir == null) {
231 return false;
232 }
233
234 String dirName = dir.getName();
235
236 if (!dirName.endsWith("-theme")) {
237 return false;
238 }
239
240 return true;
241 }
242
243 private static Log _log = LogFactoryUtil.getLog(
244 ThemeSandboxDeployListener.class);
245
246 private File _engineHostDir;
247
248 }