1

I get asset entries like this:

List<AssetEntry> emt = AssetEntryLocalServiceUtil.getEntries(q);

Asset entries have many methods like assetEntry.getTitle() - but not to get the source(input answer of webcontent). It works in the journal liferay taglib like this: <liferay-ui:journal-article articleId="74550" groupId="10164" ></liferay-ui:journal-article>

How can I get the content of the web content using AssetEntry?

Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100
javier carrion
  • 11
  • 1
  • 1
  • 3

5 Answers5

2

The assetEntry allows you to retrieve the web content by combining the getClassName(), which is "com.liferay.portlet.journal.model.JournalArticle", and the getClassPK(), that gives you the id of the web content for the assetEntry.

Having this information you can call the following:

JournalArticle wc = JournalArticleLocalServiceUtil.getArticle(assetEntry.getClassPK());
cpinto
  • 31
  • 1
1
AssetEntry assetEntry = ...;

JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(assetEntry.getPrimaryKey());
String xmlString = article.getContent(); //whole xml content with all translations
//or
String xmlString = article.getContentByLocale(languageId); //languageId is some like 'en', 'es' ...
Joel Peltonen
  • 13,025
  • 6
  • 64
  • 100
Mark
  • 17,887
  • 13
  • 66
  • 93
  • This always just throws an error like "No JournalArticle exists with the primary key 722473". Can an AssetEntry exist without a JournalArticle? – Joel Peltonen Mar 21 '16 at 14:13
  • Yes @Nenotlep. An AssetEntry doesn't need to be a JournalArticle per se. Quoting from the Liferay forums: "An asset can be anything, a blog post, a journal article, a poll question/answer, ... AssetEntry is the entity representing a specific asset." – evaldeslacasa Feb 20 '17 at 20:50
1

You can access the content form the xmlString mention above like this

JournalContentUtil.getDisplay(journalArticle.getGroupId(), journalArticle.getArticleId(),
            null, null, locale.toString(), xmlRequest);

where the xmlRequest can be generated form request and response like this

String xmlRequest = PortletRequestUtil.toXML(request,response);

and the JournalArticle can be obtained like Mark mentioned above like this

 JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(assetEntry.getPrimaryKey());

This works fine for Liferay 6.1.1 and should work in the older versions.

Miroslav Ligas
  • 1,287
  • 8
  • 22
0
 JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(ae.getClassPK()); 
 JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(themeDisplay.getScopeGroupId(),journalArticleResourceObj.getArticleId());  

journalArticleObj has all required data.

Haris
  • 1,131
  • 7
  • 20
0

I have not tried below code, but this is the code working in default display(abstract) of asset publisher.

AssetRenderer assetRenderer = (AssetRenderer)request.getAttribute("view.jsp-assetRenderer"); String summary = assetRenderer.getSummary(locale);

You can check code in the file: /liferay/liferay620/tomcat-7.0.42/webapps/ROOT/html/portlet/asset_publisher/display

Vaibu
  • 205
  • 2
  • 6