Wednesday, November 19, 2014

[Liferay] [Hook] Fix for Special Characters in Friendly URL of Web Content

Friends,

In the last post [Liferay] Show Web Content in a different page using Asset Publisher we learned how to use asset publisher to display web content in specific portlet and make it a fit for most of the requirements.

That time, I also mentioned that a problem exists if we use special characters in title of web content, it creates some problem. Problem is that, Liferay replaces most of the special characters while generating unique url for the web content but fails to recognize all. That leads to existence of special characters in title and Liferay fails to show that web content in specific portlet.

Solution was simple, replace all special characters which Liferay code missed. Liferay takes care of these characters in FriendlyURLNormalizerImpl.
Changing FriendlyURLNormalizerImpl was not easier as per our project requirements so I fixed JournalContentLocalServiceImpl instead. I created a service wrapper hook and changed the code for addArticle(...)
This code replaces the special characters from existing title and updates article. This hook must be present before we create a web content.

That's it for now.

Until next time. :)

1 comment:

Note: Only a member of this blog may post a comment.