简体   繁体   中英

How to add JournalArticle with images and/or docs to Liferay 6.2?

I'm newbie in Liferay and I need to parse some XML documents to put them into Liferay. By now, I'm able to create and add the JournalArticles into Liferay. The problem I'm facing is that those xml have images or documents and I'm not able to upload them.

For images, I'm getting the url from the xml, I create an inputStream and then I create a Map from the inputStream. This map is put in the method JournalArticleLocalServiceUtil, but when the Journal is created, the image is not uploaded/attached. The code is the next:

JournalArticle newJournalArticle = JournalArticleLocalServiceUtil.addArticle(
                    userId, 
                    groupId, 
                    exampleArticle.getFolderId(), 
                    exampleArticle.getClassNameId(), 
                    exampleArticle.getClassPK(), 
                    "", 
                    true, 
                    1D, 
                    titleMap, 
                    null, 
                    journalContent, 
                    exampleArticle.getType(), 
                    exampleArticle.getStructureId(), 
                    exampleArticle.getTemplateId(), 
                    exampleArticle.getLayoutUuid(), 
                    c.get(Calendar.MONTH), 
                    c.get(Calendar.DAY_OF_MONTH), 
                    c.get(Calendar.YEAR), 
                    c.get(Calendar.HOUR), 
                    c.get(Calendar.MINUTE), 
                    0, 0, 0, 0, 0, true, 
                    0, 0, 0, 0, 0, true, 
                    true, 
                    false,    (false or true, the image is not uploaded)
                    null, 
                    null, 
                    imageMap,     -> image map created before
                    articleURL, 
                    serviceContext);

            newJournalArticle.persist();

If the map is created correctly, with this code should be uploaded? Or in liferay I need to upload the files to documents and media and then attach them to the Journal somehow?

For documents I've been seeking but it's not clear, how do I upload documents to attach them to a Journal? Should I use DLAppLocalServiceUtil or getUploadPortletRequest to upload files?

I hope someone could guide me. Thank you!

EDIT Well, images must be uploaded to documents and media first. This can be done with the methods found here: http://liferayiseasy.blogspot.in/2015/07/folder-and-file-upload-programmatically.html

Now, I must link the images uploaded to the articles created.

Regards.

You'll need to upload the images to the document library and link them from the web content article. The easiest way to document this is if you find the ancient sevencogs (or 7cogs) example code. It should be available in the downloads for Liferay 6.0. Unfortunately it's not contained any more and will need minor tweaks to mimic the API changes that Liferay has undergone since then, but you should get a head start from it.

One of the changes is that the code you find probably used the "ImageGallery", which has been merged with the Document Library since then - all of the IG prefixes to API calls now would be DL .

James Falkner has already resurrected some of the code in a two-article-blog-series ( one , two ) but this problem seems not to be among those articles' content

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM