1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.tools.deploy;
16  
17  import com.liferay.portal.kernel.plugin.PluginPackage;
18  import com.liferay.portal.kernel.util.StringBundler;
19  import com.liferay.portal.kernel.util.StringUtil;
20  import com.liferay.portal.kernel.util.Validator;
21  import com.liferay.portal.model.Plugin;
22  import com.liferay.portal.util.InitUtil;
23  import com.liferay.util.TextFormatter;
24  
25  import java.io.File;
26  
27  import java.util.ArrayList;
28  import java.util.HashMap;
29  import java.util.List;
30  import java.util.Map;
31  import java.util.Properties;
32  
33  /**
34   * <a href="ThemeDeployer.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   */
38  public class ThemeDeployer extends BaseDeployer {
39  
40      public static void main(String[] args) {
41          InitUtil.initWithSpring();
42  
43          List<String> wars = new ArrayList<String>();
44          List<String> jars = new ArrayList<String>();
45  
46          for (String arg : args) {
47              if (arg.endsWith(".war")) {
48                  wars.add(arg);
49              }
50              else if (arg.endsWith(".jar")) {
51                  jars.add(arg);
52              }
53          }
54  
55          new ThemeDeployer(wars, jars);
56      }
57  
58      public ThemeDeployer() {
59      }
60  
61      public ThemeDeployer(List<String> wars, List<String> jars) {
62          super(wars, jars);
63      }
64  
65      public void checkArguments() {
66          super.checkArguments();
67  
68          if (Validator.isNull(themeTaglibDTD)) {
69              throw new IllegalArgumentException(
70                  "The system property deployer.theme.taglib.dtd is not set");
71          }
72  
73          if (Validator.isNull(utilTaglibDTD)) {
74              throw new IllegalArgumentException(
75                  "The system property deployer.util.taglib.dtd is not set");
76          }
77      }
78  
79      public String getExtraContent(
80              double webXmlVersion, File srcFile, String displayName)
81          throws Exception {
82  
83          StringBundler sb = new StringBundler(7);
84  
85          String extraContent = super.getExtraContent(
86              webXmlVersion, srcFile, displayName);
87  
88          sb.append(extraContent);
89  
90          // ThemeContextListener
91  
92          sb.append("<listener>");
93          sb.append("<listener-class>");
94          sb.append("com.liferay.portal.kernel.servlet.ThemeContextListener");
95          sb.append("</listener-class>");
96          sb.append("</listener>");
97  
98          // Speed filters
99  
100         sb.append(getSpeedFiltersContent(srcFile));
101 
102         return sb.toString();
103     }
104 
105     public void processPluginPackageProperties(
106             File srcFile, String displayName, PluginPackage pluginPackage)
107         throws Exception {
108 
109         if (pluginPackage == null) {
110             return;
111         }
112 
113         Properties properties = getPluginPackageProperties(srcFile);
114 
115         if ((properties == null) || (properties.size() == 0)) {
116             return;
117         }
118 
119         String moduleGroupId = pluginPackage.getGroupId();
120         String moduleArtifactId = pluginPackage.getArtifactId();
121         String moduleVersion = pluginPackage.getVersion();
122 
123         String pluginName = pluginPackage.getName();
124         String pluginType = pluginPackage.getTypes().get(0);
125         String pluginTypeName = TextFormatter.format(
126             pluginType, TextFormatter.J);
127 
128         if (!pluginType.equals(Plugin.TYPE_THEME)) {
129             return;
130         }
131 
132         String tags = getPluginPackageTagsXml(pluginPackage.getTags());
133         String shortDescription = pluginPackage.getShortDescription();
134         String longDescription = pluginPackage.getLongDescription();
135         String changeLog = pluginPackage.getChangeLog();
136         String pageURL = pluginPackage.getPageURL();
137         String author = pluginPackage.getAuthor();
138         String licenses = getPluginPackageLicensesXml(
139             pluginPackage.getLicenses());
140         String liferayVersions = getPluginPackageLiferayVersionsXml(
141             pluginPackage.getLiferayVersions());
142 
143         int pos = moduleArtifactId.indexOf("-theme");
144 
145         String themeId = moduleArtifactId.substring(0, pos);
146         String themeName = pluginName;
147 
148         Map<String, String> filterMap = new HashMap<String, String>();
149 
150         filterMap.put("module_group_id", moduleGroupId);
151         filterMap.put("module_artifact_id", moduleArtifactId);
152         filterMap.put("module_version", moduleVersion);
153 
154         filterMap.put("plugin_name", pluginName);
155         filterMap.put("plugin_type", pluginType);
156         filterMap.put("plugin_type_name", pluginTypeName);
157 
158         filterMap.put("tags", tags);
159         filterMap.put("short_description", shortDescription);
160         filterMap.put("long_description", longDescription);
161         filterMap.put("change_log", changeLog);
162         filterMap.put("page_url", pageURL);
163         filterMap.put("author", author);
164         filterMap.put("licenses", licenses);
165         filterMap.put("liferay_versions", liferayVersions);
166 
167         filterMap.put("theme_id", themeId);
168         filterMap.put("theme_name", themeName);
169         filterMap.put(
170             "theme_versions",
171             StringUtil.replace(liferayVersions, "liferay-version", "version"));
172 
173         copyDependencyXml(
174             "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
175         copyDependencyXml(
176             "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,
177             true);
178     }
179 
180 }