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