001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.tools.deploy;
016    
017    import com.liferay.portal.kernel.plugin.PluginPackage;
018    import com.liferay.portal.kernel.util.StringBundler;
019    import com.liferay.portal.kernel.util.StringUtil;
020    import com.liferay.portal.kernel.util.Validator;
021    import com.liferay.portal.model.Plugin;
022    import com.liferay.portal.util.InitUtil;
023    
024    import java.io.File;
025    
026    import java.util.ArrayList;
027    import java.util.List;
028    import java.util.Map;
029    
030    /**
031     * @author Brian Wing Shun Chan
032     */
033    public class ThemeDeployer extends BaseDeployer {
034    
035            public static void main(String[] args) {
036                    InitUtil.initWithSpring();
037    
038                    List<String> wars = new ArrayList<String>();
039                    List<String> jars = new ArrayList<String>();
040    
041                    for (String arg : args) {
042                            if (arg.endsWith(".war")) {
043                                    wars.add(arg);
044                            }
045                            else if (arg.endsWith(".jar")) {
046                                    jars.add(arg);
047                            }
048                    }
049    
050                    new ThemeDeployer(wars, jars);
051            }
052    
053            public ThemeDeployer() {
054            }
055    
056            public ThemeDeployer(List<String> wars, List<String> jars) {
057                    super(wars, jars);
058            }
059    
060            @Override
061            public void checkArguments() {
062                    super.checkArguments();
063    
064                    if (Validator.isNull(themeTaglibDTD)) {
065                            throw new IllegalArgumentException(
066                                    "The system property deployer.theme.taglib.dtd is not set");
067                    }
068    
069                    if (Validator.isNull(utilTaglibDTD)) {
070                            throw new IllegalArgumentException(
071                                    "The system property deployer.util.taglib.dtd is not set");
072                    }
073            }
074    
075            @Override
076            public String getExtraContent(
077                            double webXmlVersion, File srcFile, String displayName)
078                    throws Exception {
079    
080                    StringBundler sb = new StringBundler(7);
081    
082                    String extraContent = super.getExtraContent(
083                            webXmlVersion, srcFile, displayName);
084    
085                    sb.append(extraContent);
086    
087                    // ThemeContextListener
088    
089                    sb.append("<listener>");
090                    sb.append("<listener-class>");
091                    sb.append("com.liferay.portal.kernel.servlet.ThemeContextListener");
092                    sb.append("</listener-class>");
093                    sb.append("</listener>");
094    
095                    // Ignore filters
096    
097                    sb.append(getIgnoreFiltersContent(srcFile));
098    
099                    // Speed filters
100    
101                    sb.append(getSpeedFiltersContent(srcFile));
102    
103                    return sb.toString();
104            }
105    
106            @Override
107            public String getPluginType() {
108                    return Plugin.TYPE_THEME;
109            }
110    
111            @Override
112            public Map<String, String> processPluginPackageProperties(
113                            File srcFile, String displayName, PluginPackage pluginPackage)
114                    throws Exception {
115    
116                    Map<String, String> filterMap = super.processPluginPackageProperties(
117                            srcFile, displayName, pluginPackage);
118    
119                    if (filterMap == null) {
120                            return null;
121                    }
122    
123                    String moduleArtifactId = filterMap.get("module_artifact_id");
124    
125                    int pos = moduleArtifactId.indexOf("-theme");
126    
127                    String themeId = moduleArtifactId.substring(0, pos);
128    
129                    filterMap.put("theme_id", themeId);
130    
131                    String themeName = filterMap.get("plugin_name");
132    
133                    filterMap.put("theme_name", themeName);
134    
135                    String liferayVersions = filterMap.get("liferay_versions");
136    
137                    filterMap.put(
138                            "theme_versions",
139                            StringUtil.replace(liferayVersions, "liferay-version", "version"));
140    
141                    copyDependencyXml(
142                            "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
143    
144                    return filterMap;
145            }
146    
147    }