1   /**
2    * Copyright (c) 2000-2007 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;
24  
25  import com.liferay.portal.kernel.plugin.PluginPackage;
26  import com.liferay.portal.kernel.util.StringMaker;
27  import com.liferay.portal.kernel.util.StringUtil;
28  import com.liferay.portal.kernel.util.Validator;
29  import com.liferay.util.TextFormatter;
30  
31  import java.io.File;
32  
33  import java.util.ArrayList;
34  import java.util.HashMap;
35  import java.util.List;
36  import java.util.Map;
37  import java.util.Properties;
38  
39  /**
40   * <a href="ThemeDeployer.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class ThemeDeployer extends BaseDeployer {
46  
47      public static void main(String[] args) {
48          List wars = new ArrayList();
49          List jars = new ArrayList();
50  
51          for (int i = 0; i < args.length; i++) {
52              if (args[i].endsWith(".war")) {
53                  wars.add(args[i]);
54              }
55              else if (args[i].endsWith(".jar")) {
56                  jars.add(args[i]);
57              }
58          }
59  
60          new ThemeDeployer(wars, jars);
61      }
62  
63      protected ThemeDeployer() {
64      }
65  
66      protected ThemeDeployer(List wars, List jars) {
67          super(wars, jars);
68      }
69  
70      protected void checkArguments() {
71          super.checkArguments();
72  
73          if (Validator.isNull(themeTaglibDTD)) {
74              throw new IllegalArgumentException(
75                  "The system property deployer.theme.taglib.dtd is not set");
76          }
77  
78          if (Validator.isNull(utilTaglibDTD)) {
79              throw new IllegalArgumentException(
80                  "The system property deployer.util.taglib.dtd is not set");
81          }
82      }
83  
84      protected String getExtraContent(
85              double webXmlVersion, File srcFile, String displayName)
86          throws Exception {
87  
88          StringMaker sm = new StringMaker();
89  
90          String extraContent = super.getExtraContent(
91              webXmlVersion, srcFile, displayName);
92  
93          sm.append(extraContent);
94  
95          // HeaderFilter
96  
97          sm.append("<filter>");
98          sm.append("<filter-name>Header Filter</filter-name>");
99          sm.append("<filter-class>");
100         sm.append("com.liferay.portal.kernel.servlet.PortalClassLoaderFilter");
101         sm.append("</filter-class>");
102         sm.append("<init-param>");
103         sm.append("<param-name>filter-class</param-name>");
104         sm.append("<param-value>");
105         sm.append("com.liferay.filters.header.HeaderFilter");
106         sm.append("</param-value>");
107         sm.append("</init-param>");
108         sm.append("<init-param>");
109         sm.append("<param-name>Cache-Control</param-name>");
110         sm.append("<param-value>max-age=172801, public</param-value>");
111         sm.append("</init-param>");
112         sm.append("<init-param>");
113         sm.append("<param-name>Expires</param-name>");
114         sm.append("<param-value>172801</param-value>");
115         sm.append("</init-param>");
116         sm.append("</filter>");
117 
118         sm.append("<filter-mapping>");
119         sm.append("<filter-name>Header Filter</filter-name>");
120         sm.append("<url-pattern>*.css</url-pattern>");
121         sm.append("</filter-mapping>");
122         sm.append("<filter-mapping>");
123         sm.append("<filter-name>Header Filter</filter-name>");
124         sm.append("<url-pattern>*.gif</url-pattern>");
125         sm.append("</filter-mapping>");
126         sm.append("<filter-mapping>");
127         sm.append("<filter-name>Header Filter</filter-name>");
128         sm.append("<url-pattern>*.html</url-pattern>");
129         sm.append("</filter-mapping>");
130         sm.append("<filter-mapping>");
131         sm.append("<filter-name>Header Filter</filter-name>");
132         sm.append("<url-pattern>*.jpg</url-pattern>");
133         sm.append("</filter-mapping>");
134         sm.append("<filter-mapping>");
135         sm.append("<filter-name>Header Filter</filter-name>");
136         sm.append("<url-pattern>*.js</url-pattern>");
137         sm.append("</filter-mapping>");
138         sm.append("<filter-mapping>");
139         sm.append("<filter-name>Header Filter</filter-name>");
140         sm.append("<url-pattern>*.png</url-pattern>");
141         sm.append("</filter-mapping>");
142 
143         // CompressionFilter
144 
145         sm.append("<filter>");
146         sm.append("<filter-name>Compression Filter</filter-name>");
147         sm.append("<filter-class>");
148         sm.append("com.liferay.portal.kernel.servlet.PortalClassLoaderFilter");
149         sm.append("</filter-class>");
150         sm.append("<init-param>");
151         sm.append("<param-name>filter-class</param-name>");
152         sm.append("<param-value>");
153         sm.append("com.liferay.filters.compression.CompressionFilter");
154         sm.append("</param-value>");
155         sm.append("</init-param>");
156         sm.append("</filter>");
157 
158         sm.append("<filter-mapping>");
159         sm.append("<filter-name>Compression Filter</filter-name>");
160         sm.append("<url-pattern>*.css</url-pattern>");
161         sm.append("</filter-mapping>");
162         sm.append("<filter-mapping>");
163         sm.append("<filter-name>Compression Filter</filter-name>");
164         sm.append("<url-pattern>*.js</url-pattern>");
165         sm.append("</filter-mapping>");
166 
167         // VelocityFilter
168 
169         sm.append("<filter>");
170         sm.append("<filter-name>Velocity Filter</filter-name>");
171         sm.append("<filter-class>");
172         sm.append("com.liferay.portal.kernel.servlet.PortalClassLoaderFilter");
173         sm.append("</filter-class>");
174         sm.append("<init-param>");
175         sm.append("<param-name>filter-class</param-name>");
176         sm.append("<param-value>");
177         sm.append("com.liferay.portal.servlet.filters.velocity.VelocityFilter");
178         sm.append("</param-value>");
179         sm.append("</init-param>");
180         sm.append("<init-param>");
181         sm.append("<param-name>pattern</param-name>");
182         sm.append("<param-value>(.+)/css/main.css(.+)</param-value>");
183         sm.append("</init-param>");
184         sm.append("</filter>");
185 
186         /*sm.append("<filter-mapping>");
187         sm.append("<filter-name>Velocity Filter</filter-name>");
188         sm.append("<url-pattern>*.css</url-pattern>");
189 
190         if (webXmlVersion > 2.3) {
191             sm.append("<dispatcher>FORWARD</dispatcher>");
192             sm.append("<dispatcher>INCLUDE</dispatcher>");
193             sm.append("<dispatcher>REQUEST</dispatcher>");
194         }
195 
196         sm.append("</filter-mapping>");*/
197 
198         // ThemeContextListener
199 
200         sm.append("<listener>");
201         sm.append("<listener-class>");
202         sm.append("com.liferay.portal.kernel.servlet.ThemeContextListener");
203         sm.append("</listener-class>");
204         sm.append("</listener>");
205 
206         return sm.toString();
207     }
208 
209     protected void processPluginPackageProperties(
210             File srcFile, String displayName, PluginPackage pluginPackage)
211         throws Exception {
212 
213         if (pluginPackage == null) {
214             return;
215         }
216 
217         Properties props = getPluginPackageProperties(srcFile);
218 
219         if ((props == null) || (props.size() == 0)) {
220             return;
221         }
222 
223         String moduleGroupId = pluginPackage.getGroupId();
224         String moduleArtifactId = pluginPackage.getArtifactId();
225         String moduleVersion = pluginPackage.getVersion();
226 
227         String pluginName = pluginPackage.getName();
228         String pluginType = (String)pluginPackage.getTypes().get(0);
229         String pluginTypeName = TextFormatter.format(
230             pluginType, TextFormatter.J);
231 
232         if (!pluginType.equals("theme")) {
233             return;
234         }
235 
236         String tags = getPluginPackageTagsXml(pluginPackage.getTags());
237         String shortDescription = pluginPackage.getShortDescription();
238         String longDescription = pluginPackage.getLongDescription();
239         String changeLog = pluginPackage.getChangeLog();
240         String pageURL = pluginPackage.getPageURL();
241         String author = pluginPackage.getAuthor();
242         String licenses = getPluginPackageLicensesXml(
243             pluginPackage.getLicenses());
244         String liferayVersions = getPluginPackageLiferayVersionsXml(
245             pluginPackage.getLiferayVersions());
246 
247         int pos = moduleArtifactId.indexOf("-theme");
248 
249         String themeId = moduleArtifactId.substring(0, pos);
250         String themeName = pluginName;
251 
252         Map filterMap = new HashMap();
253 
254         filterMap.put("module_group_id", moduleGroupId);
255         filterMap.put("module_artifact_id", moduleArtifactId);
256         filterMap.put("module_version", moduleVersion);
257 
258         filterMap.put("plugin_name", pluginName);
259         filterMap.put("plugin_type", pluginType);
260         filterMap.put("plugin_type_name", pluginTypeName);
261 
262         filterMap.put("tags", tags);
263         filterMap.put("short_description", shortDescription);
264         filterMap.put("long_description", longDescription);
265         filterMap.put("change_log", changeLog);
266         filterMap.put("page_url", pageURL);
267         filterMap.put("author", author);
268         filterMap.put("licenses", licenses);
269         filterMap.put("liferay_versions", liferayVersions);
270 
271         filterMap.put("theme_id", themeId);
272         filterMap.put("theme_name", themeName);
273         filterMap.put(
274             "theme_versions",
275             StringUtil.replace(liferayVersions, "liferay-version", "version"));
276 
277         copyDependencyXml(
278             "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
279         copyDependencyXml(
280             "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,
281             true);
282     }
283 
284 }