Tuesday, 18 February 2014

Liferay Friendly URL with Action method call

Hi All,

Liferay comes with Friendly URL which reduce unwanted parameter in  URL and  display small  and good URL compare to action and render URL.

Now suppose you want to display News for Mobile device and you want to create friendly URL related it and you want also one action method with this friendly URL. So please follow steps.

1. open your liferay-porltet.xml file of  your portlet and write below line after <icon></icon> tag.

   <friendly-url-mapper-class>com.liferay.portal.kernel.portlet.DefaultFriendlyURLMapper</friendly-  url-mapper-class>
    <friendly-url-mapping>mobile</friendly-url-mapping>
    <friendly-url-routes>com/portal/mobile-routes.xml</friendly-url-routes>


2.  Now create  mobile-routes.xml in relevant path in your portlet.

3.  Open mobile-routes.xml file and add below content.

     
<?xml version="1.0"?>
<!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 6.1.0//EN"
"http://www.liferay.com/dtd/liferay-friendly-url-routes_6_1_0.dtd">

Wednesday, 29 January 2014

Export multiple Web content in single .lar file

Hello  All,

Liferay provides a good feature as Web Content Management. We can create web content and  also modify easily.  Liferay provides  export functionality for web content as .lar file, but by default Liferay can export one single web content in single lar file.

So if you want to export multiple web content in single lar file then you can follow below steps.

1.  Create one Hook with Name "export_import.jsp" override export_import.jsp of /html/portlet/portlet_configuration.
Add below line in  <aui:form> of this jsp and line number near to 126 line number in 6.1

 <b>publish-my-article-id :</b><br/><textarea name="publish-my-article-id"></textarea>

2. Create Ext plugin with Name "export-artlicle-ext".

3.  Override  liferay-portlet.xml of Journel Artile portlet as below.

     <portlet-data-handler-class>com.liferay.portlet.journal.lar.CustomJournalPortletDataHandlerImpl.java</portlet-data-handler-class>
   
4.  Create  CustomJournalPortletDataHandlerImpl class  in  / ext-impl/src/com/liferay/portlet/journal/lar.

5.  override method  doExportData of  JournalPortletDataHandlerImpl classs in our CustomJournalPortletDataHandlerImpl.

Add below line of code.


// Multiple Export Artices Chnags : START
            
            boolean publishMyArticle = false;
            String publishMyArticleId = null;
            if (portletDataContext.getParameterMap().containsKey("publish-my-article-id")) {
                publishMyArticleId = portletDataContext.getParameterMap().get("publish-my-article-id")[0];
                publishMyArticle = true;
            }
          
          
            if (publishMyArticle && null != publishMyArticleId && publishMyArticleId.trim().length()>0) {
                exportAllJournalArticle(portletDataContext, articlesElement, structuresElement,
                        templatesElement, dlFileEntryTypesElement, dlFoldersElement,
                        dlFilesElement, dlFileRanksElement, dlRepositoriesElement,
                        dlRepositoryEntriesElement, publishMyArticleId, null, true);
            }else{
            List<JournalArticle> articles = JournalArticleUtil.findByGroupId(
                portletDataContext.getScopeGroupId(), QueryUtil.ALL_POS,
                QueryUtil.ALL_POS, new ArticleIDComparator(true));

            for (JournalArticle article : articles) {
                exportArticle(
                    portletDataContext, articlesElement, structuresElement,
                    templatesElement, dlFileEntryTypesElement, dlFoldersElement,
                    dlFilesElement, dlFileRanksElement, dlRepositoriesElement,
                    dlRepositoryEntriesElement, article, null, true);
            }
          }
          
            // Multiple Export Artices Chnags : END  

6. Deploy  your Ext and Hook.

7. Now Go to Control Panel and Select  multiple  webconentId and Click on Configuration icon and  click of Export / Imoirt icon.

8. In Export tab write all web content Id as comma separated.

9.  Click on export button and get .lar file.

10. Import this .lar file in other community, you will find all Web contents.