留言板

Access Journal Article fields defined in structure

thumbnail
Andrey Kazantsev,修改在15 年前。

Access Journal Article fields defined in structure

Junior Member 帖子: 53 加入日期: 09-2-17 最近的帖子
Hello. I use LR 5.2.2. I defined a structure "NEWS_ENTRY":

<root>
  <dynamic-element name="my-title" type="text" repeatable="false"></dynamic-element>
  <dynamic-element name="my-content" type="text_area" repeatable="false"></dynamic-element>
</root>


I created a new article with this structure, and I want to modify Asset Publisher portlet to show my field "my-title" instead of the article's default title (aka "name"). I looked through asset_publisher/display/abstracts.jsp and figured out that I have access to JournalArticleResource and JournalArticleDisplay for accessing to my article, but I can't understand how can I get article's "my-title" or "my-content" fields. How can I access them?

Thank you in advance!
thumbnail
Andrey Kazantsev,修改在15 年前。

RE: Access Journal Article fields defined in structure

Junior Member 帖子: 53 加入日期: 09-2-17 最近的帖子
I found that in JournalArticle database table there is a field content, which contains my structured data:

content: <!--?xml version="1.0" encoding="UTF-8"?-->

<root default-locale="en_US" available-locales="en_US,ru_RU">
	<dynamic-element instance-id="KaDPW0bZ" name="my-title" type="text">
		<dynamic-content language-id="en_US">Beginning of sales</dynamic-content>
	</dynamic-element>
	<dynamic-element instance-id="2MjsoV2D" name="my-content" type="text_area">
		<dynamic-content language-id="en_US">&lt;p&gt;Beginning of sales!!!&lt;/p&gt;</dynamic-content>
	</dynamic-element>
</root>


Also, there is a field structureId: NEWS_ENTRY. So, I think i should get that content, structureId and pass them to some function, which will return me a Map with values of the keys. Is this possible or how can I get that fields (my-title and my-content) ?
thumbnail
Andrey Kazantsev,修改在15 年前。

RE: Access Journal Article fields defined in structure

Junior Member 帖子: 53 加入日期: 09-2-17 最近的帖子
This is untrivial task? Maybe somebody knows the way ?
thumbnail
Victor Zorin,修改在15 年前。

RE: Access Journal Article fields defined in structure

Liferay Legend 帖子: 1228 加入日期: 08-4-14 最近的帖子
Andrey, if you have acces to article xml and know which fields you want to extract and display,
use XPath expression to get value of those elements.
However I am not sure whether I gave the answer you need, may be your question is more specific to AssetPublisher portlet.
thumbnail
Andrey Kazantsev,修改在15 年前。

RE: Access Journal Article fields defined in structure

Junior Member 帖子: 53 加入日期: 09-2-17 最近的帖子
Hello, Victor. Thank you. I've solved my problem as you suggest:

    JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(
			articleResource.getGroupId(), articleResource.getArticleId());
	myContent = journalArticle.getContentByLocale(languageId);

	Document document = null;
	try
	{
		document = SAXReaderUtil.read(new StringReader(myContent));
		Node node = document.selectSingleNode("/root/dynamic-element[@name='my-title']/dynamic-content");
		if (node.getText().length() &gt; 0) {
			title = node.getText();
		}
	}
	catch (DocumentException e)
	{
		e.printStackTrace();
	}
thumbnail
Victor Zorin,修改在15 年前。

RE: Access Journal Article fields defined in structure

Liferay Legend 帖子: 1228 加入日期: 08-4-14 最近的帖子
That's a good piece of code you made Andrey, now I know how to do it myself too. (I am using XOM library, so never did it this way)
Judith Sambs,修改在11 年前。

RE: Access Journal Article fields defined in structure

New Member 帖子: 13 加入日期: 12-12-3 最近的帖子
When following that post, there are a few questions arising in my mind:
  • where do I have to put that piece of code?
  • where do articleResource and languageId come from?
  • is JournalArticleLocalServiceUtil always available or do I have to include it somehow? the same question arises wth SAXReaderUtil
  • what datatype does myContent have?

I am grateful for any kind of help!
thumbnail
Himanshu Bhandari,修改在8 年前。

RE: Access Journal Article fields defined in structure

Regular Member 帖子: 148 加入日期: 14-5-9 最近的帖子
Hi

where do I have to put that piece of code?

Wherever you need emoticon
May I know your view that where you would write it?

Thanks.