Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jonny Olliff-Lee
Getting Journal Article content without the XML in Liferay 6.1
March 21, 2012 2:56 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Hi all,

I'm working on a custom portlet part of which I need to output the content of journal articles to a file on a schedule. To accomplish this I've been trying to use the following methods:

1journalArticle.getContentByLocale("en_US")
and
1journalArticle.getContent()


where journalArticle is a JournalArticle object from the database. However all I get back from both of these methods is:

1<root available-locales="en_US" default-locale="en_US">
2    <static-content language-id="en_US">The content would be here....</static-content>
3</root>

instead of
1The content would be here.....


Can anyone shed some light on a) Why this isn't working, and / or b) how to retrieve just the pure content of a Journal Article without the XML wrapper.

Thank you!

p.s. I'm using Liferay 6.1 EE plugin-SDK
Alain Dresse
RE: Getting Journal Article content without the XML in Liferay 6.1
March 21, 2012 6:06 AM
Answer

Alain Dresse

Rank: Junior Member

Posts: 95

Join Date: July 18, 2011

Recent Posts

You need to use SAXReaderUtil to parse the xml.

Take a look at this post: http://www.liferay.com/community/forums/-/message_boards/message/12470206.

Best,
Alain
Jonny Olliff-Lee
RE: Getting Journal Article content without the XML in Liferay 6.1
March 26, 2012 9:26 AM
Answer

Jonny Olliff-Lee

Rank: Junior Member

Posts: 48

Join Date: January 25, 2011

Recent Posts

Thanks Alain, I will check that out! emoticon

Can anyone from Liferay explain why we can't use the API get the contents of a JournalArticle in Java code (not on a JSP), or if you can how? Thanks!
Gabriel Lana
RE: Getting Journal Article content without the XML in Liferay 6.1
February 25, 2013 11:24 AM
Answer

Gabriel Lana

Rank: New Member

Posts: 1

Join Date: February 25, 2013

Recent Posts

Jonny Olliff-Lee:
Thanks Alain, I will check that out! emoticon

Can anyone from Liferay explain why we can't use the API get the contents of a JournalArticle in Java code (not on a JSP), or if you can how? Thanks!



it should work
1JournalArticle article = JournalArticleServiceUtil.getArticle(groupId, defaultArticleId);
Hitoshi Ozawa
RE: Getting Journal Article content without the XML in Liferay 6.1
February 25, 2013 2:18 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

JournalArticle article = JournalArticleServiceUtil.getArticle(groupId, defaultArticleId);


This will only get the JournalArticle. I think you meant getArticleContent() which return a String.
Neda Esmaeili
RE: Getting Journal Article content without the XML in Liferay 6.1
April 30, 2014 4:07 AM
Answer

Neda Esmaeili

Rank: New Member

Posts: 12

Join Date: December 14, 2013

Recent Posts

hi
I am using Saxutilclass and output is one!.

content: /image/journal/article?img_id=14128&t=1398579524945

but in xml file 2 picture exist!

<root available-locales="en_US" default-locale="en_US">
<dynamic-element name="activeIndex" index="0" type="text" index-type="">
<dynamic-content language-id="en_US"><![CDATA[0]]></dynamic-content>
</dynamic-element>
<dynamic-element name="timeInterval" index="0" type="text" index-type="">
<dynamic-content language-id="en_US"><![CDATA[0.75]]></dynamic-content>
</dynamic-element>
<dynamic-element name="maxImageHeight" index="0" type="text" index-type="">
<dynamic-content language-id="en_US"><![CDATA[254]]></dynamic-content>
</dynamic-element>
<dynamic-element name="maxImageWidth" index="0" type="text" index-type="">
<dynamic-content language-id="en_US"><![CDATA[600]]></dynamic-content>
</dynamic-element>
<dynamic-element name="image" index="0" type="image" index-type="keyword">
<dynamic-element name="linkUrl" index="0" type="text" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[]]></dynamic-content>
</dynamic-element>
<dynamic-content language-id="en_US" id="14128">/image/journal/article?img_id=14128&amp;t=1398579524945</dynamic-content>
</dynamic-element>
<dynamic-element name="image" index="1" type="image" index-type="keyword">
<dynamic-element name="linkUrl" index="0" type="text" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[]]></dynamic-content>
</dynamic-element>
<dynamic-content language-id="en_US" id="14129">/image/journal/article?img_id=14129&amp;t=1398579525025</dynamic-content>
</dynamic-element>
</root>


please help me
Marek Palenik
RE: Getting Journal Article content without the XML in Liferay 6.1
April 30, 2014 4:33 AM
Answer

Marek Palenik

Rank: Junior Member

Posts: 32

Join Date: May 2, 2013

Recent Posts

Hi

try to use JournalContentUtil

String content = JournalContentUtil.getContent( themeDisplay.getPortletGroupId(), articleId, null, locale, themeDisplay );
Neda Esmaeili
RE: Getting Journal Article content without the XML in Liferay 6.1
April 30, 2014 5:00 AM
Answer

Neda Esmaeili

Rank: New Member

Posts: 12

Join Date: December 14, 2013

Recent Posts

thnks marek,
This time, the entire template with content that!
I just want to be separated from the Edit :-(
Enrique Valdes Lacasa
RE: Getting Journal Article content without the XML in Liferay 6.1
January 23, 2015 12:07 PM
Answer

Enrique Valdes Lacasa

Rank: Junior Member

Posts: 67

Join Date: July 29, 2014

Recent Posts

By "without the XML" I suppose that you mean to display the web content in plain HTML, right? If that is your goal, then this Java call should be of help:

1String content = JournalContentUtil.
2          getContent(groupId, articleId, templateId, themeDisplay.getLocale().toString(), themeDisplay);


groupId is the Id of the site, you can use:
1long groupId = themeDisplay.getLayout().getGroupId();

articleId, the id String of the JournalArticle object corresponding to the web content that you want to display.
templateId, the String of the Id of the template that you are using (if any).
The other two are simply the themeDisplay object and its locale value.

Regards.
Gabor Laszlo Hajba
RE: Getting Journal Article content without the XML in Liferay 6.1
January 29, 2015 9:17 AM
Answer

Gabor Laszlo Hajba

Rank: New Member

Posts: 1

Join Date: January 29, 2015

Recent Posts

Enrique Valdes Lacasa:

1String content = JournalContentUtil.
2          getContent(groupId, articleId, templateId, themeDisplay.getLocale().toString(), themeDisplay);



When I change themeDisplay.getLocale().toString() to Locale.GERMANY.toString() I always get the default en_US translations of my content. When I use article.getContentByLocale("de_DE") I get the content XML of the German translation -- but it is an XML which is not the content provided by the JournalContentUtil.

I would like to get the German translation of the article as a String when I do some display -- even if the user has en_US (or some other language) set.

Thanks in advance.
Mahbub Alam
RE: Getting Journal Article content without the XML in Liferay 6.1
July 13, 2016 1:34 AM
Answer

Mahbub Alam

Rank: New Member

Posts: 1

Join Date: December 21, 2015

Recent Posts

i have a xml content like below:

<?xml version="1.0"?>
<root available-locales="en_US" default-locale="en_US">
<dynamic-element name="Name" index="0" type="text_area" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[Multiple Text Title]]></dynamic-content>
</dynamic-element>
<dynamic-element name="loop_counter" index="0" type="ddm-decimal" index-type="keyword">
<dynamic-element name="Slide_Name" index="0" type="text" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[slider one]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Slide_Body" index="0" type="text_area" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[slider one]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Photo" index="0" type="image" index-type="keyword">
<dynamic-content language-id="en_US" id="47849">/image/journal/article?img_id=47849&amp;t=1468315029409</dynamic-content>
</dynamic-element>
<dynamic-element name="Documents_and_Media9999" index="0" type="document_library" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[/documents/46706/0/karlin/09c9491f-3c3d-4320-898f-98d88fa4a630?t=1468314920873]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Link_to_Page9999" index="0" type="link_to_layout" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[2@public@46706]]></dynamic-content>
</dynamic-element>
<dynamic-content language-id="en_US"><![CDATA[0.0]]></dynamic-content>
</dynamic-element>
<dynamic-element name="loop_counter" index="1" type="ddm-decimal" index-type="keyword">
<dynamic-element name="Slide_Name" index="0" type="text" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[slider two]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Slide_Body" index="0" type="text_area" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[slider two]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Photo" index="0" type="image" index-type="keyword">
<dynamic-content language-id="en_US" id="47849">/image/journal/article?img_id=47849&amp;t=1468315029506</dynamic-content>
</dynamic-element>
<dynamic-element name="Documents_and_Media9999" index="0" type="document_library" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[/documents/46706/0/Kessel/edd702b2-78dc-44c8-96f6-bdeed2e10ed0?t=1468315018794]]></dynamic-content>
</dynamic-element>
<dynamic-element name="Link_to_Page9999" index="0" type="link_to_layout" index-type="keyword">
<dynamic-content language-id="en_US"><![CDATA[1@public@46706]]></dynamic-content>
</dynamic-element>
<dynamic-content language-id="en_US"><![CDATA[1.0]]></dynamic-content>
</dynamic-element>
</root>

now problem is <dynamic-element> can have many child like <dynamic-element><dynamic-element><dynamic-element>
and i don't know how much child will add. I have created one java method but is able to parse <root><dynamic-element><dynamic-content> only.

java method is:
private static List<Map<String,Object>> parseXMLContent(long siteId,String articleId, String languageId)throws DocumentException, IOException, PortalException, SystemException {
List<Map<String,Object>> result = new ArrayList<Map<String,Object>>();

JournalArticle article= JournalArticleLocalServiceUtil.getArticle(siteId, articleId);

if (Validator.isNotNull(article.getContent())) {
Document doc = SAXReaderUtil.read(article.getContent());

Node root = doc.getRootElement();
List<Node> pointNodes = root.selectNodes("/root/dynamic-element");

for (int i = 0; i < pointNodes.size(); i++) {
Node pointNode = pointNodes.get(i);

Element element = (Element) pointNode;

Map<String,Object> data = new HashMap<String,Object>();

data.put("name", element.attributeValue("name"));
data.put("index", element.attributeValue("index"));
data.put("type", element.attributeValue("type"));
data.put("indexType", element.attributeValue("index-type"));

boolean tip = hasTip(siteId, articleId, languageId, element.attributeValue("name"));
data.put("tip", tip);

Node content = pointNode.selectSingleNode("//dynamic-element[@name='"+element.attributeValue("name")+"']/dynamic-content[@language-id='"+languageId+"']");
if (Validator.isNull(content)) {
if (languageId.equalsIgnoreCase("en_US")) {
languageId = "nl_NL";
content = pointNode.selectSingleNode("//dynamic-element[@name='"+element.attributeValue("name")+"']/dynamic-content[@language-id='"+languageId+"']");
}else if (languageId.equalsIgnoreCase("nl_NL")) {
languageId = "en_US";
content = pointNode.selectSingleNode("//dynamic-element[@name='"+element.attributeValue("name")+"']/dynamic-content[@language-id='"+languageId+"']");
}
}
if (Validator.isNotNull(content)) {
data.put("contentData", content.getText());
if (languageId.equalsIgnoreCase("en_US")) {
data.put("languageId","en");
}else if (languageId.equalsIgnoreCase("nl_NL")) {
data.put("languageId","nl");
}
}
result.add(data);
}
return result;
}
return null;
}

Where i need to modify it please help me.