Search code examples
liferayportletliferay-6

Packaging Document Structures and templates in Liferay plugin wars


Is there a way to include Liferay document or web-content structures and templates in portlet plugin war files and have them become available to users like the standard ones are?

The use-case would be that you are writing a portlet that takes advantage of a custom Document Library structure that you are providing. But you don't want to distribute this structure as a separate thing with its own installation procedure (such as providing a LAR just for the structure), you just want your plugin to make the custom structure available whenever it is installed.


Solution

  • You can achieve your goal by adding a portal.properties file to the WEB-INF/classes directory of your portlet. This file should contain the following line:

    application.startup.events=com.yourcompany.whatever.YourCustomStartupAction
    

    This custom startup action should be a class that extends from com.liferay.portal.kernel.events.SimpleAction. In it you will be able to leverage all the Liferay service utils to do things in Liferay at the moment your portlet is started. The class you need to use to work with the Liferay document library specifically is DLAppLocalServiceUtil. This util class has all the necessary methods to work with files/folders in the document library.

    For web content related stuff, such as structures, templates and articles, just use JournalStructureLocalServiceUtil, JournalTemplateLocalServiceUtil and JournalArticleLocalServiceUtil.