如何以编程方式创建时将结构和模板添加到期刊文章中

时间:2016-03-29 05:13:28

标签: liferay liferay-6 liferay-theme

我通过门户网站UI创建了结构和模板。现在我在动作类中以编程方式创建期刊文章。在动作类中创建期刊文章时,我想将现有结构和模板设置为此期刊文章。我试图使用以下方法,但这里是ddmStructureKey和ddmTemplateKey的含义。

那些仅与我的要求相关吗?

JournalArticleLocalServiceUtil.addArticle(userId, groupId, folderId, titleMap, descriptionMap, content, ddmStructureKey, ddmTemplateKey, serviceContext)

帮助我解决这个未知的事情。感谢。

2 个答案:

答案 0 :(得分:2)

我写的以下代码是为了回答上述问题并为我解决。谢谢@Romeo Sheshi。我已经对一些东西进行了硬编码。根据您的要求,您可以随心所欲地做任何事情。

ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
                Long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
                DDMStructure ddmStructure=DDMStructureLocalServiceUtil.getDDMStructure(11515);
                DDMTemplate ddmTemplate=DDMTemplateLocalServiceUtil.getDDMTemplate(11517);
                Map<Locale,String> titleMap=new HashMap<Locale,String>();
                titleMap.put(themeDisplay.getLocale(), "First Record");
                String content=
                        "<root available-locales='en_US' default-locale='en_US'>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Title' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                    +"<dynamic-content>FirstRecord</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Description' readOnly='false' repeatable='false' required='false' showLabel='true' type='textarea' width='small'>"
                                +"  <dynamic-content>This the first one doing by programatically</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='image' fieldNamespace='wcm' indexType='keyword' name='DamImage' readOnly='false' repeatable='false' required='false' showLabel='true' type='wcm-image' width=''>"
                                +"  <dynamic-content>http://localhost:8080/documents/10184/0/welcome_community/0dc0adb1-b565-409a-b766-96d1e42b04fb?t=1459163274526</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='UserIdExcel' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                +"  <dynamic-content>458155</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='string' indexType='keyword' name='Username' readOnly='false' repeatable='false' required='false' showLabel='true' type='text' width='small'>"
                                +"  <dynamic-content>LaxmanDeepak</dynamic-content>"
                                +"</dynamic-element>"
                                +"<dynamic-element dataType='date' fieldNamespace='ddm' indexType='keyword' name='DateFromExcel' readOnly='false' repeatable='false' required='false' showLabel='true' type='ddm-date' width='small'>"
                                +"<dynamic-content>03/29/2016</dynamic-content>"
                                +"</dynamic-element>"
                            +"</root>";
                ServiceContext serviceContext = new ServiceContext();
                serviceContext.setScopeGroupId(themeDisplay.getScopeGroupId());
                serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

                JournalArticleLocalServiceUtil.addArticle(themeDisplay.getUserId(), themeDisplay.getScopeGroupId(), parentFolderId, titleMap, null, content, ddmStructure.getStructureKey(), ddmTemplate.getTemplateKey(), serviceContext);

答案 1 :(得分:0)

ddmStructure和ddmTemplateKey是文章的结构和呈现该文章的模板(velocity,freemarker)。 如果您使用空字符串,则选择默认模板和默认结构,否则如果您不想使用您的结构和模板,则必须使用这些服务获取它们

tokenRefreshed