1
19
20 package com.liferay.portal.tools;
21
22 import com.liferay.portal.kernel.plugin.PluginPackage;
23 import com.liferay.portal.kernel.util.StringUtil;
24 import com.liferay.portal.kernel.util.Validator;
25 import com.liferay.portal.model.Plugin;
26 import com.liferay.portal.util.InitUtil;
27 import com.liferay.util.TextFormatter;
28
29 import java.io.File;
30
31 import java.util.ArrayList;
32 import java.util.HashMap;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Properties;
36
37
43 public class ThemeDeployer extends BaseDeployer {
44
45 public static void main(String[] args) {
46 InitUtil.initWithSpring();
47
48 List<String> wars = new ArrayList<String>();
49 List<String> jars = new ArrayList<String>();
50
51 for (String arg : args) {
52 if (arg.endsWith(".war")) {
53 wars.add(arg);
54 }
55 else if (arg.endsWith(".jar")) {
56 jars.add(arg);
57 }
58 }
59
60 new ThemeDeployer(wars, jars);
61 }
62
63 protected ThemeDeployer() {
64 }
65
66 protected ThemeDeployer(List<String> wars, List<String> 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 StringBuilder sb = new StringBuilder();
89
90 String extraContent = super.getExtraContent(
91 webXmlVersion, srcFile, displayName);
92
93 sb.append(extraContent);
94
95
97 sb.append("<listener>");
98 sb.append("<listener-class>");
99 sb.append("com.liferay.portal.kernel.servlet.ThemeContextListener");
100 sb.append("</listener-class>");
101 sb.append("</listener>");
102
103
105 sb.append(getSpeedFiltersContent(srcFile));
106
107 return sb.toString();
108 }
109
110 protected void processPluginPackageProperties(
111 File srcFile, String displayName, PluginPackage pluginPackage)
112 throws Exception {
113
114 if (pluginPackage == null) {
115 return;
116 }
117
118 Properties props = getPluginPackageProperties(srcFile);
119
120 if ((props == null) || (props.size() == 0)) {
121 return;
122 }
123
124 String moduleGroupId = pluginPackage.getGroupId();
125 String moduleArtifactId = pluginPackage.getArtifactId();
126 String moduleVersion = pluginPackage.getVersion();
127
128 String pluginName = pluginPackage.getName();
129 String pluginType = pluginPackage.getTypes().get(0);
130 String pluginTypeName = TextFormatter.format(
131 pluginType, TextFormatter.J);
132
133 if (!pluginType.equals(Plugin.TYPE_THEME)) {
134 return;
135 }
136
137 String tags = getPluginPackageTagsXml(pluginPackage.getTags());
138 String shortDescription = pluginPackage.getShortDescription();
139 String longDescription = pluginPackage.getLongDescription();
140 String changeLog = pluginPackage.getChangeLog();
141 String pageURL = pluginPackage.getPageURL();
142 String author = pluginPackage.getAuthor();
143 String licenses = getPluginPackageLicensesXml(
144 pluginPackage.getLicenses());
145 String liferayVersions = getPluginPackageLiferayVersionsXml(
146 pluginPackage.getLiferayVersions());
147
148 int pos = moduleArtifactId.indexOf("-theme");
149
150 String themeId = moduleArtifactId.substring(0, pos);
151 String themeName = pluginName;
152
153 Map<String, String> filterMap = new HashMap<String, String>();
154
155 filterMap.put("module_group_id", moduleGroupId);
156 filterMap.put("module_artifact_id", moduleArtifactId);
157 filterMap.put("module_version", moduleVersion);
158
159 filterMap.put("plugin_name", pluginName);
160 filterMap.put("plugin_type", pluginType);
161 filterMap.put("plugin_type_name", pluginTypeName);
162
163 filterMap.put("tags", tags);
164 filterMap.put("short_description", shortDescription);
165 filterMap.put("long_description", longDescription);
166 filterMap.put("change_log", changeLog);
167 filterMap.put("page_url", pageURL);
168 filterMap.put("author", author);
169 filterMap.put("licenses", licenses);
170 filterMap.put("liferay_versions", liferayVersions);
171
172 filterMap.put("theme_id", themeId);
173 filterMap.put("theme_name", themeName);
174 filterMap.put(
175 "theme_versions",
176 StringUtil.replace(liferayVersions, "liferay-version", "version"));
177
178 copyDependencyXml(
179 "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
180 copyDependencyXml(
181 "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,
182 true);
183 }
184
185 }