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.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                    return sb.toString();
096            }
097    
098            @Override
099            public String getExtraFiltersContent(double webXmlVersion, File srcFile)
100                    throws Exception {
101    
102                    StringBundler sb = new StringBundler(3);
103    
104                    String extraFiltersContent = super.getExtraFiltersContent(
105                            webXmlVersion, srcFile);
106    
107                    sb.append(extraFiltersContent);
108    
109                    // Ignore filters
110    
111                    sb.append(getIgnoreFiltersContent(srcFile));
112    
113                    // Speed filters
114    
115                    sb.append(getSpeedFiltersContent(srcFile));
116    
117                    return sb.toString();
118            }
119    
120            @Override
121            public String getPluginType() {
122                    return Plugin.TYPE_THEME;
123            }
124    
125            @Override
126            public Map<String, String> processPluginPackageProperties(
127                            File srcFile, String displayName, PluginPackage pluginPackage)
128                    throws Exception {
129    
130                    Map<String, String> filterMap = super.processPluginPackageProperties(
131                            srcFile, displayName, pluginPackage);
132    
133                    if (filterMap == null) {
134                            return null;
135                    }
136    
137                    String moduleArtifactId = filterMap.get("module_artifact_id");
138    
139                    int pos = moduleArtifactId.indexOf("-theme");
140    
141                    String themeId = moduleArtifactId.substring(0, pos);
142    
143                    filterMap.put("theme_id", themeId);
144    
145                    String themeName = filterMap.get("plugin_name");
146    
147                    filterMap.put("theme_name", themeName);
148    
149                    String liferayVersions = filterMap.get("liferay_versions");
150    
151                    filterMap.put(
152                            "theme_versions",
153                            StringUtil.replace(liferayVersions, "liferay-version", "version"));
154    
155                    copyDependencyXml(
156                            "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
157    
158                    return filterMap;
159            }
160    
161    }