001    /**
002     * Copyright (c) 2000-2010 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    import com.liferay.util.TextFormatter;
024    
025    import java.io.File;
026    
027    import java.util.ArrayList;
028    import java.util.HashMap;
029    import java.util.List;
030    import java.util.Map;
031    import java.util.Properties;
032    
033    /**
034     * @author Brian Wing Shun Chan
035     */
036    public class ThemeDeployer extends BaseDeployer {
037    
038            public static void main(String[] args) {
039                    InitUtil.initWithSpring();
040    
041                    List<String> wars = new ArrayList<String>();
042                    List<String> jars = new ArrayList<String>();
043    
044                    for (String arg : args) {
045                            if (arg.endsWith(".war")) {
046                                    wars.add(arg);
047                            }
048                            else if (arg.endsWith(".jar")) {
049                                    jars.add(arg);
050                            }
051                    }
052    
053                    new ThemeDeployer(wars, jars);
054            }
055    
056            protected ThemeDeployer() {
057            }
058    
059            protected ThemeDeployer(List<String> wars, List<String> jars) {
060                    super(wars, jars);
061            }
062    
063            protected void checkArguments() {
064                    super.checkArguments();
065    
066                    if (Validator.isNull(themeTaglibDTD)) {
067                            throw new IllegalArgumentException(
068                                    "The system property deployer.theme.taglib.dtd is not set");
069                    }
070    
071                    if (Validator.isNull(utilTaglibDTD)) {
072                            throw new IllegalArgumentException(
073                                    "The system property deployer.util.taglib.dtd is not set");
074                    }
075            }
076    
077            protected String getExtraContent(
078                            double webXmlVersion, File srcFile, String displayName)
079                    throws Exception {
080    
081                    StringBundler sb = new StringBundler(7);
082    
083                    String extraContent = super.getExtraContent(
084                            webXmlVersion, srcFile, displayName);
085    
086                    sb.append(extraContent);
087    
088                    // ThemeContextListener
089    
090                    sb.append("<listener>");
091                    sb.append("<listener-class>");
092                    sb.append("com.liferay.portal.kernel.servlet.ThemeContextListener");
093                    sb.append("</listener-class>");
094                    sb.append("</listener>");
095    
096                    // Speed filters
097    
098                    sb.append(getSpeedFiltersContent(srcFile));
099    
100                    return sb.toString();
101            }
102    
103            protected void processPluginPackageProperties(
104                            File srcFile, String displayName, PluginPackage pluginPackage)
105                    throws Exception {
106    
107                    if (pluginPackage == null) {
108                            return;
109                    }
110    
111                    Properties properties = getPluginPackageProperties(srcFile);
112    
113                    if ((properties == null) || (properties.size() == 0)) {
114                            return;
115                    }
116    
117                    String moduleGroupId = pluginPackage.getGroupId();
118                    String moduleArtifactId = pluginPackage.getArtifactId();
119                    String moduleVersion = pluginPackage.getVersion();
120    
121                    String pluginName = pluginPackage.getName();
122                    String pluginType = pluginPackage.getTypes().get(0);
123                    String pluginTypeName = TextFormatter.format(
124                            pluginType, TextFormatter.J);
125    
126                    if (!pluginType.equals(Plugin.TYPE_THEME)) {
127                            return;
128                    }
129    
130                    String tags = getPluginPackageTagsXml(pluginPackage.getTags());
131                    String shortDescription = pluginPackage.getShortDescription();
132                    String longDescription = pluginPackage.getLongDescription();
133                    String changeLog = pluginPackage.getChangeLog();
134                    String pageURL = pluginPackage.getPageURL();
135                    String author = pluginPackage.getAuthor();
136                    String licenses = getPluginPackageLicensesXml(
137                            pluginPackage.getLicenses());
138                    String liferayVersions = getPluginPackageLiferayVersionsXml(
139                            pluginPackage.getLiferayVersions());
140    
141                    int pos = moduleArtifactId.indexOf("-theme");
142    
143                    String themeId = moduleArtifactId.substring(0, pos);
144                    String themeName = pluginName;
145    
146                    Map<String, String> filterMap = new HashMap<String, String>();
147    
148                    filterMap.put("module_group_id", moduleGroupId);
149                    filterMap.put("module_artifact_id", moduleArtifactId);
150                    filterMap.put("module_version", moduleVersion);
151    
152                    filterMap.put("plugin_name", pluginName);
153                    filterMap.put("plugin_type", pluginType);
154                    filterMap.put("plugin_type_name", pluginTypeName);
155    
156                    filterMap.put("tags", tags);
157                    filterMap.put("short_description", shortDescription);
158                    filterMap.put("long_description", longDescription);
159                    filterMap.put("change_log", changeLog);
160                    filterMap.put("page_url", pageURL);
161                    filterMap.put("author", author);
162                    filterMap.put("licenses", licenses);
163                    filterMap.put("liferay_versions", liferayVersions);
164    
165                    filterMap.put("theme_id", themeId);
166                    filterMap.put("theme_name", themeName);
167                    filterMap.put(
168                            "theme_versions",
169                            StringUtil.replace(liferayVersions, "liferay-version", "version"));
170    
171                    copyDependencyXml(
172                            "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
173                    copyDependencyXml(
174                            "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,
175                            true);
176            }
177    
178    }