java 如何使用liferay获取AssetEntry的网页内容?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6662639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the webcontent of an AssetEntry with liferay?
提问by javier carrion
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>
资产条目有许多方法,例如assetEntry.getTitle()
- 但不是获取源(webcontent 的输入答案)。它在日记 liferay taglib 中工作,如下所示:
<liferay-ui:journal-article articleId="74550" groupId="10164" ></liferay-ui:journal-article>
How can I get the content of the web content using AssetEntry?
如何使用 AssetEntry 获取 Web 内容的内容?
回答by cpinto
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.
assetEntry 允许您通过组合 getClassName()(即“com.liferay.portlet.journal.model.JournalArticle”)和 getClassPK()(为您提供资产条目的 Web 内容的 ID)来检索 Web 内容.
Having this information you can call the following:
有了这些信息,您可以拨打以下电话:
JournalArticle wc = JournalArticleLocalServiceUtil.getArticle(assetEntry.getClassPK());
回答by Mark
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' ...
回答by Miroslav Ligas
You can access the content form the xmlString mention above like this
您可以像这样访问上面提到的 xmlString 的内容
JournalContentUtil.getDisplay(journalArticle.getGroupId(), journalArticle.getArticleId(),
null, null, locale.toString(), xmlRequest);
where the xmlRequest can be generated form request and response like this
xmlRequest 可以像这样生成表单请求和响应
String xmlRequest = PortletRequestUtil.toXML(request,response);
and the JournalArticle can be obtained like Mark mentioned above like this
并且JournalArticle可以像上面提到的那样获得
JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(assetEntry.getPrimaryKey());
This works fine for Liferay 6.1.1 and should work in the older versions.
这适用于 Liferay 6.1.1 并且应该适用于旧版本。
回答by Haris
JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(ae.getClassPK());
JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(themeDisplay.getScopeGroupId(),journalArticleResourceObj.getArticleId());
journalArticleObj has all required data.
journalArticleObj 具有所有必需的数据。
回答by Vaibu
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);
AssetRenderer assetRenderer = (AssetRenderer)request.getAttribute("view.jsp-assetRenderer"); 字符串摘要 = assetRenderer.getSummary(locale);
You can check code in the file: /liferay/liferay620/tomcat-7.0.42/webapps/ROOT/html/portlet/asset_publisher/display
您可以检查文件中的代码:/liferay/liferay620/tomcat-7.0.42/webapps/ROOT/html/portlet/asset_publisher/display