Wednesday 29 March 2017

Different ways of getting a Journal Article Content in LIFERAY

This blog helps you to fetch the “Journal Article Content “or “web content “in different ways based upon our requirement.

(i) Getting the Journal Article of Particular Name :-

String articleName =  “sourabh”;// I need the sourabh web content details

String content = StringPool.BLANK;

JournalArticlejournalArticle = JournalArticleLocalServiceUtil.getArticleByUrlTitle (themeDisplay.getScopeGroupId(), articleName);// getting the journalArticle Object based on name

String articleId = journalArticle.getArticleId();

JournalArticleDisplayarticleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);

content = articleDisplay.getContent();// by using display content object I am fetching the data of my sourabh Web content.

 

(ii) Getting the Journal Article based on Tag Name :-

 

If we want to fetch the specific tag based web content details then the following code will be useful.

 

String content = StringPool.BLANK;

AssetTagassetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), “mytagname”);
long assetTagId = assetTag.getTagId();
List assetEntrylist = AssetEntryLocalServiceUtil.getAssetTagAssetEntries(assetTagId);

for(AssetEntryassetEntry : assetEntrylist) {
JournalArticleResourcejournalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(assetEntry.getClassPK());
JournalArticlejournalArticleObj = JournalArticleLocalServiceUtil.getArticle(themeDisplay.getScopeGroupId(),journalArticleResourceObj.getArticleId());
String articleId = journalArticleObj.getArticleId();
JournalArticleDisplayarticleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);
content = articleDisplay.getContent();

}

 

(iii) Getting the Journal Article based on Structure Id or Template Id:-

 

If we want to fetch the specific Structure of template based web content details then the following code will be useful.


String content = StringPool.BLANK;
List articleList = JournalArticleLocalServiceUtil.getStructureArticles(themeDisplay.getScopeGroupId(), “tagId”);
// for template use API  getTemplateArticles
for(JournalArticlejournalArticle : articleList) {

String articleId = journalArticle.getArticleId();

JournalArticleDisplayarticleDisplay =  JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);

content = articleDisplay.getContent();
}

 

(iv) Fetching the Journal Article content in template file in Liferay

 

If we want to fetch the journal article of web content details in template file then the following code will be useful. 

The following code will shows the tag based journal Article content in template.

 

#set($assetTag =$serviceLocator.findService(‘com.liferay.portlet.asset.service.AssetTagLocalService’))
#set($assetEntryService =$serviceLocator.findService(‘com.liferay.portlet.asset.service.AssetEntryLocalService’))
#set($journalArticleResourceLocal=$serviceLocator.findService(‘com.liferay.portlet.journal.service.JournalArticleResourceLocalService’))
#set($journalArticleLocal=$serviceLocator.findService(‘com.liferay.portlet.journal.service.JournalArticleLocalService’))
#set($journalContentUtil =$utilLocator.findUtil(‘com.liferay.portlet.journalcontent.util.JournalContent’))
#set($groupId = $getterUtil.getLong($groupId))
#set($languageId = $request.theme-display.language-id)

#set($assetTagObj=$assetTag.getTag($groupId,”myTag”))
#set($assetId = $assetTagObj.getTagId())
#set($assestList= $assetEntryService.getAssetTagAssetEntries($assetId))
#set($assetEntry = “”)
#foreach($assetEntry in $assestList)
#set($journalArticleResource =$journalArticleResourceLocal.getJournalArticleResource($assetEntry.getClassPK()))
#set($journalArticle = $journalArticleLocal.getArticle($groupId,$journalArticleResource.getArticleId()))
#set($latestArticle= $journalArticleLocal.getLatestArticle($groupId,$journalArticle.getArticleId()))
#set( $journalArticleDisplay= $journalContentUtil.getDisplay($groupId,$latestArticle.getArticleId(), null,null,$languageId,null, 1, $xmlRequest))
$journalArticleDisplay.getContent()
#end

 

No comments:

Post a Comment