001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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.plugin.PluginPackage;
020    import com.liferay.portal.kernel.util.ServerDetector;
021    import com.liferay.portal.tools.deploy.ThemeDeployer;
022    import com.liferay.portal.util.PortalUtil;
023    
024    import java.io.File;
025    
026    import java.util.ArrayList;
027    
028    /**
029     * @author Igor Spasic
030     * @author Brian Wing Shun Chan
031     */
032    public class ThemeSandboxDeployListener
033            extends ThemeDeployer implements SandboxDeployListener {
034    
035            public ThemeSandboxDeployListener() {
036                    _sandboxHandler = new ThemeSandboxHandler(this);
037    
038                    appServerType = ServerDetector.getServerId();
039    
040                    String portalWebDir = PortalUtil.getPortalWebDir();
041    
042                    themeTaglibDTD = portalWebDir + "/WEB-INF/tld/liferay-theme.tld";
043                    utilTaglibDTD = portalWebDir + "/WEB-INF/tld/liferay-util.tld";
044    
045                    jars = new ArrayList<String>();
046    
047                    String portalLibDir = PortalUtil.getPortalLibDir();
048    
049                    jars.add(portalLibDir + "/commons-logging.jar");
050                    jars.add(portalLibDir + "/log4j.jar");
051                    jars.add(portalLibDir + "/util-java.jar");
052                    jars.add(portalLibDir + "/util-taglib.jar");
053            }
054    
055            @Override
056            public void copyXmls(
057                            File srcFile, String displayName, PluginPackage pluginPackage)
058                    throws Exception {
059    
060                    super.copyXmls(srcFile, displayName, pluginPackage);
061    
062                    if (appServerType.equals(ServerDetector.TOMCAT_ID)) {
063                            copyDependencyXml("context.xml", srcFile + "/META-INF");
064                    }
065            }
066    
067            public void deploy(File dir) throws SandboxDeployException {
068                    _sandboxHandler.deploy(dir);
069            }
070    
071            @Override
072            public String getDisplayName(File srcFile) {
073                    String displayName = super.getDisplayName(srcFile);
074    
075                    return _sandboxHandler.getDisplayName(displayName);
076            }
077    
078            public void undeploy(File dir) throws SandboxDeployException {
079                    _sandboxHandler.undeploy(dir);
080            }
081    
082            private SandboxHandler _sandboxHandler;
083    
084    }