001    /**
002     * Copyright (c) 2000-2013 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 getExtraFiltersContent(double webXmlVersion, File srcFile)
077                    throws Exception {
078    
079                    StringBundler sb = new StringBundler(3);
080    
081                    String extraFiltersContent = super.getExtraFiltersContent(
082                            webXmlVersion, srcFile);
083    
084                    sb.append(extraFiltersContent);
085    
086                    // Ignore filters
087    
088                    sb.append(getIgnoreFiltersContent(srcFile));
089    
090                    // Speed filters
091    
092                    sb.append(getSpeedFiltersContent(srcFile));
093    
094                    return sb.toString();
095            }
096    
097            @Override
098            public String getPluginType() {
099                    return Plugin.TYPE_THEME;
100            }
101    
102            @Override
103            public Map<String, String> processPluginPackageProperties(
104                            File srcFile, String displayName, PluginPackage pluginPackage)
105                    throws Exception {
106    
107                    Map<String, String> filterMap = super.processPluginPackageProperties(
108                            srcFile, displayName, pluginPackage);
109    
110                    if (filterMap == null) {
111                            return null;
112                    }
113    
114                    String moduleArtifactId = filterMap.get("module_artifact_id");
115    
116                    int pos = moduleArtifactId.indexOf("-theme");
117    
118                    String themeId = moduleArtifactId.substring(0, pos);
119    
120                    filterMap.put("theme_id", themeId);
121    
122                    String themeName = filterMap.get("plugin_name");
123    
124                    filterMap.put("theme_name", themeName);
125    
126                    String liferayVersions = filterMap.get("liferay_versions");
127    
128                    filterMap.put(
129                            "theme_versions",
130                            StringUtil.replace(liferayVersions, "liferay-version", "version"));
131    
132                    copyDependencyXml(
133                            "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
134    
135                    return filterMap;
136            }
137    
138    }