通过UI创建Web内容很容易。
但是如何在Java中以编程方式添加新的Web内容呢?

我必须将数据从遗留系统迁移到Liferay 7,因此我正在编写Java包。没有用户界面。
发布于 2017-05-19 19:15:10
尼古拉斯。
我在Liferay6.2中有一个类似的问题要解决,但我相信你可以用同样的方法解决你的问题。
我们构建了一个“集成接口”(一个触发整个事件的简单Java批处理项目),它与遗留系统和Liferay服务(使用创建)相结合。
Liferay为您提供了一个Service,您可以在其中处理它的一些资源。要创建日志文章(Web ),必须调用类JournalArticleLocalServiceUtil
下面是创建日刊文章的示例代码:
public static JournalArticle addJournalArticle(
long userId, long groupId, String title, String contentEn)
throws Exception {
ServiceContext serviceContext = new ServiceContext();
serviceContext.setAddGroupPermissions(true);
serviceContext.setAddGuestPermissions(true);
serviceContext.setScopeGroupId(groupId);
serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
Map<Locale, String> titleMap = new HashMap<Locale, String>();
Map<Locale, String> descriptionMap = new HashMap<Locale, String>();
titleMap.put(Locale.US, title);
descriptionMap.put(Locale.US, title);
try {
JournalArticleLocalServiceUtil.deleteArticle(groupId, title, serviceContext);
} catch (Exception ex) {
System.out.println("Ignoring " + ex.getMessage());
}
String xmlContent = "<?xml version='1.0' encoding='UTF-8'?>" +
"<root default-locale=\"en_US\" available-locales=\"en_US\">" +
"<static-content language-id=\"en_US\">" +
"<![CDATA[" + contentEn + "]]>" +
"</static-content>" +
"</root>";
JournalArticle article = JournalArticleLocalServiceUtil.addArticle(
userId, groupId, 0,
0, 0, title, true,
JournalArticleConstants.VERSION_DEFAULT, titleMap,
descriptionMap, xmlContent,
"general", null, null, null,
1, 1, 2014, 0, 0,
0, 0, 0, 0, 0, true,
0, 0, 0, 0, 0, true,
true, false, null, null,
null, null, serviceContext);
return article;
}但是您必须对其进行改进,以设置正确的用户权限、类别、标记等。
https://stackoverflow.com/questions/44073473
复制相似问题