Theme’s Deployment Descriptor Generation

Last week, I had a task to modify theme’s deployment descriptor ( web.xml ) file. Since Liferay’s compression filter doesn’t work on Weblogic application server, we created our own compression filter, and need to added it to the theme, in order to enable compression for *.js and *.css files.

I thought this would be easy and simple task, just modify theme’s web.xml. But after generating the theme using plugins SDK, I realized that web.xml is not created, even though I already generated war file. So how could I modify web.xml file ?

After a few experiments, I just knew that web.xml is generated on the fly, during theme deployment. So there’s a java class that responsible for this task, that iscom.liferay.portal.tools.ThemeDeployer. I just inspected the code, and I found out that to add our own modification to web.xml, I just need to modify getExtraContent method.

Here is the snippet of the method :

	protected String getExtraContent(
			double webXmlVersion, File srcFile, String displayName)
		throws Exception {

		StringBuilder sb = new StringBuilder();

		String extraContent = super.getExtraContent(
			webXmlVersion, srcFile, displayName);

		sb.append(extraContent);

		// HeaderFilter

		sb.append("<filter>");
		sb.append("<filter-name>Header Filter</filter-name>");
		sb.append("<filter-class>");
		sb.append("com.liferay.portal.kernel.servlet.PortalClassLoaderFilter");
		sb.append("</filter-class>");
		sb.append("<init-param>");
		sb.append("<param-name>filter-class</param-name>");
		sb.append("<param-value>");
		sb.append("com.liferay.portal.servlet.filters.header.HeaderFilter");
		sb.append("</param-value>");
		sb.append("</init-param>");
		sb.append("<init-param>");
		sb.append("<param-name>Cache-Control</param-name>");
		sb.append("<param-value>max-age=172801, public</param-value>");
		sb.append("</init-param>");
		sb.append("<init-param>");
		sb.append("<param-name>Expires</param-name>");
		sb.append("<param-value>172801</param-value>");
		sb.append("</init-param>");
		sb.append("</filter>");

Some of you may ask, is it possible just to add web.xml to WEB-INF folder directly, before building the theme ? Yes, it is possible. And you may ask again, so why need to modify ThemeDeployer class ? Because if you manually create your own web.xml, you have to remember to rename the theme ID and other attributes on web.xml. And in environment where build process is done automatically, it’s not convenient to do things manually, and always to remind your developers to modify the file whenever they create a new theme.

You may want to look at com.liferay.portal.tools.PortletDeveloper class for portlet’s deployment descriptor created in plugins SDK environment.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: