Creating a Hook
Similarly to creating a portlet you start by typing
mvn archetype:generate
and you should see a list of available archetypes starting with
...
Choose archetype:
1: local -> liferay-portlet-archetype (Liferay portlet archetype)
2: local -> liferay-theme-archetype (Liferay theme archetype)
3: local -> liferay-layout-archetype (Liferay layout archetype)
4: local -> liferay-hook-archetype (Liferay hook archetype)
...
Choose a number: (1/2/3/4/...) :
Type 4 and press enter to choose “liferay-hook-archetype”. You will be asked to enter groupId, artifactId, version and package and then confirm. For example:
Define value for groupId: : eu.ibacz
Define value for artifactId: : statistics
Define value for version: 1.0-SNAPSHOT: : 1.0
Define value for package: eu.ibacz: :
Confirm properties configuration:
groupId: eu.ibacz
artifactId: statistics
version: 1.0
package: eu.ibacz
Y: :
Once you confirm this data, a new folder (with name equal to the value of artifactId) will be created.
You can notice the directory structure:
./pom.xml
./src
./src/main
./src/main/java
./src/main/resources
./src/main/webapp
./src/main/webapp/WEB-INF
./src/main/webapp/WEB-INF/liferay-hook.xml
./src/main/webapp/WEB-INF/liferay-plugin-package.properties
There are only liferay-hook.xml and liferay-plugin-package.properties files. The hook is standard web application with these rules:
1, It contains liferay-plugin-package.properties
2, It contains liferay-hook.xml
3, The war file name contains “-hook” string
4, The war file name doesn’t contain “-portlet” string
The content of the package is defined in the liferay-hook.xml, where I added some info on how to create hooks and what is supported in the Liferay 5.2.3:
For the right content of this file see
http://www.liferay.com/dtd/liferay-hook_5_1_0.dtd
http://www.liferay.com/dtd/liferay-hook_5_2_0.dtd
For the Liferay 5.2.3 use only:
<!ELEMENT portal-properties (#PCDATA)>
– .properties file should go into the src/main/resources directory
– supported keys in the .properties file:
“auth.forward.by.last.path”,
“captcha.check.portal.create_account”,
“default.landing.page.path”,
“field.enable.com.liferay.portal.model.Contact.birthday”,
“field.enable.com.liferay.portal.model.Contact.male”,
“field.enable.com.liferay.portal.model.Organization.status”,
“javascript.fast.load”,
“layout.static.portlets.all”
“layout.template.cache.enabled”,
“layout.user.private.layouts.auto.create”,
“layout.user.private.layouts.enabled”,
“layout.user.private.layouts.modifiable”,
“layout.user.public.layouts.auto.create”,
“layout.user.public.layouts.enabled”,
“layout.user.public.layouts.modifiable”,
“login.create.account.allow.custom.password”,
“my.places.show.community.private.sites.with.no.layouts”,
“my.places.show.community.public.sites.with.no.layouts”,
“my.places.show.organization.private.sites.with.no.layouts”,
“my.places.show.organization.public.sites.with.no.layouts”,
“my.places.show.user.private.sites.with.no.layouts”,
“my.places.show.user.public.sites.with.no.layouts”,
“passwords.passwordpolicytoolkit.generator”,
“passwords.passwordpolicytoolkit.static”
“terms.of.use.required”,
“theme.css.fast.load”,
“theme.images.fast.load”
- .properties file should go into the src/main/resources directory
<!ELEMENT custom-jsp-dir (#PCDATA)>- if you specify WEB-INF/your-directory-name then the directory with JSPs should go into the src/main/webapp/WEB-INF/your-directory-name
<!ELEMENT model-listener (model-listener-class, model-name)>- the java classes should go into the src/main/java directory
<!ELEMENT event (event-class, event-type)>- the java classes should go into the src/main/java directory