1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.tools.deploy;
24  
25  import com.liferay.portal.kernel.plugin.PluginPackage;
26  import com.liferay.portal.kernel.util.StringUtil;
27  import com.liferay.portal.kernel.util.Validator;
28  import com.liferay.portal.model.Plugin;
29  import com.liferay.portal.util.InitUtil;
30  import com.liferay.util.TextFormatter;
31  
32  import java.io.File;
33  
34  import java.util.ArrayList;
35  import java.util.HashMap;
36  import java.util.List;
37  import java.util.Map;
38  import java.util.Properties;
39  
40  /**
41   * <a href="ThemeDeployer.java.html"><b><i>View Source</i></b></a>
42   *
43   * @author Brian Wing Shun Chan
44   *
45   */
46  public class ThemeDeployer extends BaseDeployer {
47  
48      public static void main(String[] args) {
49          InitUtil.initWithSpring();
50  
51          List<String> wars = new ArrayList<String>();
52          List<String> jars = new ArrayList<String>();
53  
54          for (String arg : args) {
55              if (arg.endsWith(".war")) {
56                  wars.add(arg);
57              }
58              else if (arg.endsWith(".jar")) {
59                  jars.add(arg);
60              }
61          }
62  
63          new ThemeDeployer(wars, jars);
64      }
65  
66      protected ThemeDeployer() {
67      }
68  
69      protected ThemeDeployer(List<String> wars, List<String> jars) {
70          super(wars, jars);
71      }
72  
73      protected void checkArguments() {
74          super.checkArguments();
75  
76          if (Validator.isNull(themeTaglibDTD)) {
77              throw new IllegalArgumentException(
78                  "The system property deployer.theme.taglib.dtd is not set");
79          }
80  
81          if (Validator.isNull(utilTaglibDTD)) {
82              throw new IllegalArgumentException(
83                  "The system property deployer.util.taglib.dtd is not set");
84          }
85      }
86  
87      protected String getExtraContent(
88              double webXmlVersion, File srcFile, String displayName)
89          throws Exception {
90  
91          StringBuilder sb = new StringBuilder();
92  
93          String extraContent = super.getExtraContent(
94              webXmlVersion, srcFile, displayName);
95  
96          sb.append(extraContent);
97  
98          // ThemeContextListener
99  
100         sb.append("<listener>");
101         sb.append("<listener-class>");
102         sb.append("com.liferay.portal.kernel.servlet.ThemeContextListener");
103         sb.append("</listener-class>");
104         sb.append("</listener>");
105 
106         // Speed filters
107 
108         sb.append(getSpeedFiltersContent(srcFile));
109 
110         return sb.toString();
111     }
112 
113     protected void processPluginPackageProperties(
114             File srcFile, String displayName, PluginPackage pluginPackage)
115         throws Exception {
116 
117         if (pluginPackage == null) {
118             return;
119         }
120 
121         Properties properties = getPluginPackageProperties(srcFile);
122 
123         if ((properties == null) || (properties.size() == 0)) {
124             return;
125         }
126 
127         String moduleGroupId = pluginPackage.getGroupId();
128         String moduleArtifactId = pluginPackage.getArtifactId();
129         String moduleVersion = pluginPackage.getVersion();
130 
131         String pluginName = pluginPackage.getName();
132         String pluginType = pluginPackage.getTypes().get(0);
133         String pluginTypeName = TextFormatter.format(
134             pluginType, TextFormatter.J);
135 
136         if (!pluginType.equals(Plugin.TYPE_THEME)) {
137             return;
138         }
139 
140         String tags = getPluginPackageTagsXml(pluginPackage.getTags());
141         String shortDescription = pluginPackage.getShortDescription();
142         String longDescription = pluginPackage.getLongDescription();
143         String changeLog = pluginPackage.getChangeLog();
144         String pageURL = pluginPackage.getPageURL();
145         String author = pluginPackage.getAuthor();
146         String licenses = getPluginPackageLicensesXml(
147             pluginPackage.getLicenses());
148         String liferayVersions = getPluginPackageLiferayVersionsXml(
149             pluginPackage.getLiferayVersions());
150 
151         int pos = moduleArtifactId.indexOf("-theme");
152 
153         String themeId = moduleArtifactId.substring(0, pos);
154         String themeName = pluginName;
155 
156         Map<String, String> filterMap = new HashMap<String, String>();
157 
158         filterMap.put("module_group_id", moduleGroupId);
159         filterMap.put("module_artifact_id", moduleArtifactId);
160         filterMap.put("module_version", moduleVersion);
161 
162         filterMap.put("plugin_name", pluginName);
163         filterMap.put("plugin_type", pluginType);
164         filterMap.put("plugin_type_name", pluginTypeName);
165 
166         filterMap.put("tags", tags);
167         filterMap.put("short_description", shortDescription);
168         filterMap.put("long_description", longDescription);
169         filterMap.put("change_log", changeLog);
170         filterMap.put("page_url", pageURL);
171         filterMap.put("author", author);
172         filterMap.put("licenses", licenses);
173         filterMap.put("liferay_versions", liferayVersions);
174 
175         filterMap.put("theme_id", themeId);
176         filterMap.put("theme_name", themeName);
177         filterMap.put(
178             "theme_versions",
179             StringUtil.replace(liferayVersions, "liferay-version", "version"));
180 
181         copyDependencyXml(
182             "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
183         copyDependencyXml(
184             "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,
185             true);
186     }
187 
188 }