Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Marc Vanderstraeten
Add articles to Liferay programmatically?
June 4, 2008 9:04 AM
Answer

Marc Vanderstraeten

Rank: New Member

Posts: 4

Join Date: June 4, 2008

Recent Posts

I am a newbie to Liferay. I would like to add programmatically articles (or other content) to liferay using php or via other means (xml, http, rest, soap...), or even directly in MySQL? Is this possible?

I need to run a program that monitors a directory on a ftp server where xml files (articles form a new site) are posted on a daily basis, and should be imported regularly (cron job) and put in Liferay as articles, and then deleted (the .xml files of course).

The articles put in Liferay this way are in draft mode (not yet published) and can then be reviewed/changed and finally be published.

How can I accomplish this?

I have some articles attached...

Please help... or do I have to go back to a php based solution?
Attachments: Xsd.zip (4.3k), artikelmap_20080530_1008893567.ZIP (5.6k)
Björn Ryding
RE: Add articles to Liferay programmatically?
June 9, 2008 10:11 AM
Answer

Björn Ryding

Rank: Liferay Master

Posts: 582

Join Date: May 16, 2007

Recent Posts

Hi Marc,

Have a look at Liferay's Journal Article Service:
http://content.liferay.com/4.3/api/portal-service/com/liferay/portlet/journal/service/JournalArticleService.html

When updating the articles, the journal portlet's webdav interface may also be an option.

Cheers,
Björn
Björn Ryding
RE: Add articles to Liferay programmatically?
June 9, 2008 2:20 PM
Answer

Björn Ryding

Rank: Liferay Master

Posts: 582

Join Date: May 16, 2007

Recent Posts

I forgot to mention that you can access Liferay's services in a number of ways.

For example, to access a service using SOAP use:
http://localhost:8080/tunnel-web/secure/axis/someServiceOfYourChoice

The Web Service Deployment Descriptor with the service names is located at:
webapps/tunnel-web/WEB-INF/server-config.wsdd

For some introductory information about how Liferay's services are built, see:
http://www.liferay.com/web/guest/products/tech_specs/architecture/soa
navkalp varshney
RE: Add articles to Liferay programmatically?
June 27, 2008 8:43 AM
Answer

navkalp varshney

Rank: New Member

Posts: 8

Join Date: June 27, 2008

Recent Posts

for articles seems there are no webdav URLs. Is it possible to create htmls from portlets programmatically, or save article programmatically in html format
Radu B
RE: Add articles to Liferay programmatically?
June 27, 2008 1:57 PM
Answer

Radu B

Rank: New Member

Posts: 11

Join Date: June 19, 2008

Recent Posts

I have successfully used the function JournalArticleServiceUtil.addArticle in a portlet to add a new article.
The portlet parse an XML file with a list of article content and calls this function. You can also load images to the article by playing with the "Map<String, byte[]> images" parameter.

You can approve the article automatically by calling the function JournalArticleServiceUtil.approveArticle
Mallepula NarayanaGoud
RE: Add articles to Liferay programmatically?
November 26, 2009 11:42 PM
Answer

Mallepula NarayanaGoud

Rank: Junior Member

Posts: 95

Join Date: June 18, 2009

Recent Posts

Hi Marc,

i have the same issues,can u help me to resolve the problem.
if possible send me code or approach.

Thanks,
Mallepula.
Victor Zorin
RE: Add articles to Liferay programmatically?
November 27, 2009 3:11 AM
Answer

Victor Zorin

Rank: Liferay Legend

Posts: 1176

Join Date: April 14, 2008

Recent Posts

you may also read this link: How to use liferay for Larger Sites, it was in v5.1.* but the approach is still relevant.
Edgar Tanaka
RE: Add articles to Liferay programmatically?
December 1, 2010 3:26 PM
Answer

Edgar Tanaka

Rank: New Member

Posts: 4

Join Date: November 24, 2010

Recent Posts

Radu B:
I have successfully used the function JournalArticleServiceUtil.addArticle in a portlet to add a new article.
The portlet parse an XML file with a list of article content and calls this function. You can also load images to the article by playing with the "Map<String, byte[]> images" parameter.

You can approve the article automatically by calling the function JournalArticleServiceUtil.approveArticle


This approveArticle method is not available after version 6. I spent a lot of time trying to figure out how to add article programatically and make them approved right away. The way to do it if you are using version 6.0.5 is set a workflow aciton in your ServiceContext object:
 1
 2        JournalArticleServiceSoapServiceLocator locator = new JournalArticleServiceSoapServiceLocator();
 3        ServiceContext serviceContext = new ServiceContext();
 4        serviceContext.setScopeGroupId(GROUP_ID);
 5        serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH); //so that the article is added as published and not draft
 6        JournalArticleServiceSoap soap = locator.getPortlet_Journal_JournalArticleService(LifeRayUtils.getURL(remoteUser, remotePassword, ARTICLE_ENTRY_SERVICE_NAME, server, port));
 7            
 8
 9                JournalArticleSoap jas = soap.addArticle(GROUP_ID,
10                                b.getBlogId().toString(),
11                                true, //autoArticleId
12                                b.getTitle(), //title
13                                null, //description
14                                b.getBody(), //content
15                                "news", //type: General, news, blogs, test, press release
16                                "", // structure id
17                                "", //template id
18                                displayDateMonth,
19                                displayDateDay,
20                                displayDateYear,
21                                displayDateHour,
22                                displayDateMinute,
23                                0, //expirationDateMonth
24                                0, //expirationDateDay
25                                0, //expirationDateYear
26                                0, //expirationDateHour
27                                0, //expirationDateMinute
28                                true, //never expire
29                                0, //reviewDateMonth
30                                0, //reviewDateDay
31                                0, //reviewDateYear
32                                0, //reviewDateHour
33                                0, //reviewDateMinute
34                                true, //neverReview
35                                true, //indexable
36                                "", //articleURL
37                                serviceContext);


I hope this help someone save time in the future.
Suraj Bihari
RE: Add articles to Liferay programmatically?
November 15, 2011 1:32 PM
Answer

Suraj Bihari

Rank: Junior Member

Posts: 42

Join Date: May 20, 2011

Recent Posts

Thanks from the future!

Edgar Tanaka:


I hope this help someone save time in the future.
Jacques Traore
RE: Add articles to Liferay programmatically?
April 19, 2013 7:58 AM
Answer

Jacques Traore

Rank: Junior Member

Posts: 46

Join Date: January 21, 2013

Recent Posts

Hi Edgar,
What about translation?
My contents (with a custom structure) have both English and French versions.
How to construct the XML content to achieve this?

Thanks