如何自动将portlet页面分发到不同的环境?

时间:2015-06-23 11:07:25

标签: liferay liferay-6 portlet

我是一个开发liferay 6.1 portlet的新手。我想在我的portlet所在的页面中使用静态URL和静态内容。建议使用哪些方法将portlet和页面分发到不同的环境?

我希望所有环境尽可能完全匹配,我更喜欢将所有内容自动化,所以我也想自动创建页面。

1 个答案:

答案 0 :(得分:2)

您可以使用资源导入程序,可以在Liferay Developer Network: Creating plugins to share structures, templates and more中找到相关文档。

或者您通过导出网页来创建 LAR文件 - 再次在Liferay Developer Network: Export/Import中进行了描述。

您可以从UI或使用以下代码导入LAR文件:

public void importPages() {
    // Define the settings for import - here some examples:
    final Map<String, String[]> params = new HashMap<>();
    addParam(params, PortletDataHandlerKeys.PORTLET_USER_PREFERENCES, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_USER_PREFERENCES_ALL, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_CONFIGURATION, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_CONFIGURATION_ALL, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS_ALL, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_DATA, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_DATA_ALL, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_SETUP, true);
        addParam(params, PortletDataHandlerKeys.PORTLET_SETUP_ALL, true);
    addParam(params, PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT, true);

    addParam(params, PortletDataHandlerKeys.THEME_REFERENCE, true);
    addParam(params, PortletDataHandlerKeys.LAYOUT_SET_SETTINGS, true);
    addParam(params, PortletDataHandlerKeys.LOGO, true);

    addParam(params, PortletDataHandlerKeys.CATEGORIES, true);
    addParam(params, PortletDataHandlerKeys.RATINGS, true);
    addParam(params, PortletDataHandlerKeys.COMMENTS, true);

    addParam(params, PortletDataHandlerKeys.DELETE_MISSING_LAYOUTS, true);
    addParam(params, PortletDataHandlerKeys.DELETIONS, true);
    addParam(params, PortletDataHandlerKeys.DELETE_PORTLET_DATA, true);

    addParam(params, PortletDataHandlerKeys.USER_ID_STRATEGY, UserIdStrategy.CURRENT_USER_ID);
    addParam(params, PortletDataHandlerKeys.DATA_STRATEGY, PortletDataHandlerKeys.DATA_STRATEGY_MIRROR);

    addParam(params, PortletDataHandlerKeys.PERMISSIONS, true);

    // Import with the current user into the current site (= group)
    ThemeDisplay themeDisplay = (ThemeDisplay) getPortletRequest().getAttribute(WebKeys.THEME_DISPLAY)
    LayoutLocalServiceUtil.importLayouts(themeDisplay.getUserId(), themeDisplay.getHostGroupId(), false, params, inputStreamOfMyLARFile);
}

// Helper method
private static void addParam(final Map<String, String[]> params, final String key, final Object value) {
    params.put(key, new String[] { value.toString() });
}