Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andrey Kazantsev
Access Journal Article fields defined in structure
March 1, 2009 11:17 PM
Answer

Andrey Kazantsev

Rank: Junior Member

Posts: 53

Join Date: February 17, 2009

Recent Posts

Hello. I use LR 5.2.2. I defined a structure "NEWS_ENTRY":

1<root>
2  <dynamic-element name='my-title' type='text' repeatable='false'></dynamic-element>
3  <dynamic-element name='my-content' type='text_area' repeatable='false'></dynamic-element>
4</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!
Andrey Kazantsev
RE: Access Journal Article fields defined in structure
March 2, 2009 2:23 AM
Answer

Andrey Kazantsev

Rank: Junior Member

Posts: 53

Join Date: February 17, 2009

Recent Posts

I found that in JournalArticle database table there is a field content, which contains my structured data:

 1content: <?xml version="1.0" encoding="UTF-8"?>
 2
 3<root default-locale="en_US" available-locales="en_US,ru_RU">
 4    <dynamic-element instance-id="KaDPW0bZ" name="my-title" type="text">
 5        <dynamic-content language-id="en_US"><![CDATA[Beginning of sales]]></dynamic-content>
 6    </dynamic-element>
 7    <dynamic-element instance-id="2MjsoV2D" name="my-content" type="text_area">
 8        <dynamic-content language-id="en_US"><![CDATA[<p>Beginning of sales!!!</p>]]></dynamic-content>
 9    </dynamic-element>
10</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) ?
Andrey Kazantsev
RE: Access Journal Article fields defined in structure
March 2, 2009 5:32 PM
Answer

Andrey Kazantsev

Rank: Junior Member

Posts: 53

Join Date: February 17, 2009

Recent Posts

This is untrivial task? Maybe somebody knows the way ?
Victor Zorin
RE: Access Journal Article fields defined in structure
March 2, 2009 6:06 PM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

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.
Andrey Kazantsev
RE: Access Journal Article fields defined in structure
March 3, 2009 12:31 AM
Answer

Andrey Kazantsev

Rank: Junior Member

Posts: 53

Join Date: February 17, 2009

Recent Posts

Hello, Victor. Thank you. I've solved my problem as you suggest:

 1    JournalArticle journalArticle = JournalArticleLocalServiceUtil.getArticle(
 2            articleResource.getGroupId(), articleResource.getArticleId());
 3    myContent = journalArticle.getContentByLocale(languageId);
 4
 5    Document document = null;
 6    try
 7    {
 8        document = SAXReaderUtil.read(new StringReader(myContent));
 9        Node node = document.selectSingleNode("/root/dynamic-element[@name='my-title']/dynamic-content");
10        if (node.getText().length() > 0) {
11            title = node.getText();
12        }
13    }
14    catch (DocumentException e)
15    {
16        e.printStackTrace();
17    }
Victor Zorin
RE: Access Journal Article fields defined in structure
March 3, 2009 12:55 AM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1174

Join Date: April 14, 2008

Recent Posts

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
RE: Access Journal Article fields defined in structure
January 23, 2013 6:16 AM
Answer

Judith Sambs

Rank: New Member

Posts: 13

Join Date: December 3, 2012

Recent Posts

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!