1
22
23 package com.liferay.portal.tools.deploy;
24
25 import com.liferay.portal.deploy.DeployUtil;
26 import com.liferay.portal.kernel.plugin.PluginPackage;
27 import com.liferay.portal.kernel.util.FileUtil;
28 import com.liferay.portal.kernel.util.StringUtil;
29 import com.liferay.portal.kernel.util.Validator;
30 import com.liferay.portal.model.Plugin;
31 import com.liferay.portal.util.InitUtil;
32 import com.liferay.util.TextFormatter;
33
34 import java.io.File;
35
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Properties;
41
42
48 public class ThemeDeployer extends BaseDeployer {
49
50 public static void main(String[] args) {
51 InitUtil.initWithSpring();
52
53 List<String> wars = new ArrayList<String>();
54 List<String> jars = new ArrayList<String>();
55
56 for (String arg : args) {
57 if (arg.endsWith(".war")) {
58 wars.add(arg);
59 }
60 else if (arg.endsWith(".jar")) {
61 jars.add(arg);
62 }
63 }
64
65 new ThemeDeployer(wars, jars);
66 }
67
68 protected ThemeDeployer() {
69 }
70
71 protected ThemeDeployer(List<String> wars, List<String> jars) {
72 super(wars, jars);
73 }
74
75 protected void checkArguments() {
76 super.checkArguments();
77
78 if (Validator.isNull(themeTaglibDTD)) {
79 throw new IllegalArgumentException(
80 "The system property deployer.theme.taglib.dtd is not set");
81 }
82
83 if (Validator.isNull(utilTaglibDTD)) {
84 throw new IllegalArgumentException(
85 "The system property deployer.util.taglib.dtd is not set");
86 }
87 }
88
89 protected String getExtraContent(
90 double webXmlVersion, File srcFile, String displayName)
91 throws Exception {
92
93 StringBuilder sb = new StringBuilder();
94
95 String extraContent = super.getExtraContent(
96 webXmlVersion, srcFile, displayName);
97
98 sb.append(extraContent);
99
100
102 sb.append("<listener>");
103 sb.append("<listener-class>");
104 sb.append("com.liferay.portal.kernel.servlet.ThemeContextListener");
105 sb.append("</listener-class>");
106 sb.append("</listener>");
107
108
110 String speedFiltersContent = FileUtil.read(
111 DeployUtil.getResourcePath("speed_filters.xml"));
112
113 sb.append(speedFiltersContent);
114
115 return sb.toString();
116 }
117
118 protected void processPluginPackageProperties(
119 File srcFile, String displayName, PluginPackage pluginPackage)
120 throws Exception {
121
122 if (pluginPackage == null) {
123 return;
124 }
125
126 Properties props = getPluginPackageProperties(srcFile);
127
128 if ((props == null) || (props.size() == 0)) {
129 return;
130 }
131
132 String moduleGroupId = pluginPackage.getGroupId();
133 String moduleArtifactId = pluginPackage.getArtifactId();
134 String moduleVersion = pluginPackage.getVersion();
135
136 String pluginName = pluginPackage.getName();
137 String pluginType = pluginPackage.getTypes().get(0);
138 String pluginTypeName = TextFormatter.format(
139 pluginType, TextFormatter.J);
140
141 if (!pluginType.equals(Plugin.TYPE_THEME)) {
142 return;
143 }
144
145 String tags = getPluginPackageTagsXml(pluginPackage.getTags());
146 String shortDescription = pluginPackage.getShortDescription();
147 String longDescription = pluginPackage.getLongDescription();
148 String changeLog = pluginPackage.getChangeLog();
149 String pageURL = pluginPackage.getPageURL();
150 String author = pluginPackage.getAuthor();
151 String licenses = getPluginPackageLicensesXml(
152 pluginPackage.getLicenses());
153 String liferayVersions = getPluginPackageLiferayVersionsXml(
154 pluginPackage.getLiferayVersions());
155
156 int pos = moduleArtifactId.indexOf("-theme");
157
158 String themeId = moduleArtifactId.substring(0, pos);
159 String themeName = pluginName;
160
161 Map<String, String> filterMap = new HashMap<String, String>();
162
163 filterMap.put("module_group_id", moduleGroupId);
164 filterMap.put("module_artifact_id", moduleArtifactId);
165 filterMap.put("module_version", moduleVersion);
166
167 filterMap.put("plugin_name", pluginName);
168 filterMap.put("plugin_type", pluginType);
169 filterMap.put("plugin_type_name", pluginTypeName);
170
171 filterMap.put("tags", tags);
172 filterMap.put("short_description", shortDescription);
173 filterMap.put("long_description", longDescription);
174 filterMap.put("change_log", changeLog);
175 filterMap.put("page_url", pageURL);
176 filterMap.put("author", author);
177 filterMap.put("licenses", licenses);
178 filterMap.put("liferay_versions", liferayVersions);
179
180 filterMap.put("theme_id", themeId);
181 filterMap.put("theme_name", themeName);
182 filterMap.put(
183 "theme_versions",
184 StringUtil.replace(liferayVersions, "liferay-version", "version"));
185
186 copyDependencyXml(
187 "liferay-look-and-feel.xml", srcFile + "/WEB-INF", filterMap, true);
188 copyDependencyXml(
189 "liferay-plugin-package.xml", srcFile + "/WEB-INF", filterMap,
190 true);
191 }
192
193 }