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