001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.tools;
022:
023: import com.liferay.portal.kernel.plugin.PluginPackage;
024: import com.liferay.portal.kernel.util.StringMaker;
025: import com.liferay.portal.kernel.util.StringUtil;
026: import com.liferay.portal.kernel.util.Validator;
027: import com.liferay.util.TextFormatter;
028:
029: import java.io.File;
030:
031: import java.util.ArrayList;
032: import java.util.HashMap;
033: import java.util.List;
034: import java.util.Map;
035: import java.util.Properties;
036:
037: /**
038: * <a href="ThemeDeployer.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Brian Wing Shun Chan
041: *
042: */
043: public class ThemeDeployer extends BaseDeployer {
044:
045: public static void main(String[] args) {
046: List wars = new ArrayList();
047: List jars = new ArrayList();
048:
049: for (int i = 0; i < args.length; i++) {
050: if (args[i].endsWith(".war")) {
051: wars.add(args[i]);
052: } else if (args[i].endsWith(".jar")) {
053: jars.add(args[i]);
054: }
055: }
056:
057: new ThemeDeployer(wars, jars);
058: }
059:
060: protected ThemeDeployer() {
061: }
062:
063: protected ThemeDeployer(List wars, List jars) {
064: super (wars, jars);
065: }
066:
067: protected void checkArguments() {
068: super .checkArguments();
069:
070: if (Validator.isNull(themeTaglibDTD)) {
071: throw new IllegalArgumentException(
072: "The system property deployer.theme.taglib.dtd is not set");
073: }
074:
075: if (Validator.isNull(utilTaglibDTD)) {
076: throw new IllegalArgumentException(
077: "The system property deployer.util.taglib.dtd is not set");
078: }
079: }
080:
081: protected String getExtraContent(double webXmlVersion,
082: File srcFile, String displayName) throws Exception {
083:
084: StringMaker sm = new StringMaker();
085:
086: String extraContent = super .getExtraContent(webXmlVersion,
087: srcFile, displayName);
088:
089: sm.append(extraContent);
090:
091: // HeaderFilter
092:
093: sm.append("<filter>");
094: sm.append("<filter-name>Header Filter</filter-name>");
095: sm.append("<filter-class>");
096: sm
097: .append("com.liferay.portal.kernel.servlet.PortalClassLoaderFilter");
098: sm.append("</filter-class>");
099: sm.append("<init-param>");
100: sm.append("<param-name>filter-class</param-name>");
101: sm.append("<param-value>");
102: sm.append("com.liferay.filters.header.HeaderFilter");
103: sm.append("</param-value>");
104: sm.append("</init-param>");
105: sm.append("<init-param>");
106: sm.append("<param-name>Cache-Control</param-name>");
107: sm.append("<param-value>max-age=172801, public</param-value>");
108: sm.append("</init-param>");
109: sm.append("<init-param>");
110: sm.append("<param-name>Expires</param-name>");
111: sm.append("<param-value>172801</param-value>");
112: sm.append("</init-param>");
113: sm.append("</filter>");
114:
115: sm.append("<filter-mapping>");
116: sm.append("<filter-name>Header Filter</filter-name>");
117: sm.append("<url-pattern>*.css</url-pattern>");
118: sm.append("</filter-mapping>");
119: sm.append("<filter-mapping>");
120: sm.append("<filter-name>Header Filter</filter-name>");
121: sm.append("<url-pattern>*.gif</url-pattern>");
122: sm.append("</filter-mapping>");
123: sm.append("<filter-mapping>");
124: sm.append("<filter-name>Header Filter</filter-name>");
125: sm.append("<url-pattern>*.html</url-pattern>");
126: sm.append("</filter-mapping>");
127: sm.append("<filter-mapping>");
128: sm.append("<filter-name>Header Filter</filter-name>");
129: sm.append("<url-pattern>*.jpg</url-pattern>");
130: sm.append("</filter-mapping>");
131: sm.append("<filter-mapping>");
132: sm.append("<filter-name>Header Filter</filter-name>");
133: sm.append("<url-pattern>*.js</url-pattern>");
134: sm.append("</filter-mapping>");
135: sm.append("<filter-mapping>");
136: sm.append("<filter-name>Header Filter</filter-name>");
137: sm.append("<url-pattern>*.png</url-pattern>");
138: sm.append("</filter-mapping>");
139:
140: // CompressionFilter
141:
142: sm.append("<filter>");
143: sm.append("<filter-name>Compression Filter</filter-name>");
144: sm.append("<filter-class>");
145: sm
146: .append("com.liferay.portal.kernel.servlet.PortalClassLoaderFilter");
147: sm.append("</filter-class>");
148: sm.append("<init-param>");
149: sm.append("<param-name>filter-class</param-name>");
150: sm.append("<param-value>");
151: sm.append("com.liferay.filters.compression.CompressionFilter");
152: sm.append("</param-value>");
153: sm.append("</init-param>");
154: sm.append("</filter>");
155:
156: sm.append("<filter-mapping>");
157: sm.append("<filter-name>Compression Filter</filter-name>");
158: sm.append("<url-pattern>*.css</url-pattern>");
159: sm.append("</filter-mapping>");
160: sm.append("<filter-mapping>");
161: sm.append("<filter-name>Compression Filter</filter-name>");
162: sm.append("<url-pattern>*.js</url-pattern>");
163: sm.append("</filter-mapping>");
164:
165: // VelocityFilter
166:
167: sm.append("<filter>");
168: sm.append("<filter-name>Velocity Filter</filter-name>");
169: sm.append("<filter-class>");
170: sm
171: .append("com.liferay.portal.kernel.servlet.PortalClassLoaderFilter");
172: sm.append("</filter-class>");
173: sm.append("<init-param>");
174: sm.append("<param-name>filter-class</param-name>");
175: sm.append("<param-value>");
176: sm
177: .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: sm.append("<listener>");
200: sm.append("<listener-class>");
201: sm
202: .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(File srcFile,
210: 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(pluginType,
230: 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(pluginPackage
243: .getLicenses());
244: String liferayVersions = getPluginPackageLiferayVersionsXml(pluginPackage
245: .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("theme_versions", StringUtil.replace(
274: liferayVersions, "liferay-version", "version"));
275:
276: copyDependencyXml("liferay-look-and-feel.xml", srcFile
277: + "/WEB-INF", filterMap, true);
278: copyDependencyXml("liferay-plugin-package.xml", srcFile
279: + "/WEB-INF", filterMap, true);
280: }
281:
282: }
|