Example usage for com.liferay.portal.kernel.util PropertiesParamUtil getProperties

List of usage examples for com.liferay.portal.kernel.util PropertiesParamUtil getProperties

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PropertiesParamUtil getProperties.

Prototype

public static UnicodeProperties getProperties(ServiceContext serviceContext, String prefix) 

Source Link

Usage

From source file:com.liferay.calendarimporter.portlet.CalendarImporterPortlet.java

License:Open Source License

public void updateImportEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    // TODO Handle import entry update

    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");
    String type = ParamUtil.getString(actionRequest, "type");
    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "settings--");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(ImportEntry.class.getName(),
            actionRequest);/*from   ww w.  j  a  va2  s  . c  o  m*/

    ImportEntryServiceUtil.addImportEntry(name, description, type, typeSettingsProperties, serviceContext);
}

From source file:com.liferay.content.targeting.portlet.CTFreeMarkerDisplayPortlet.java

License:Open Source License

protected void updatePreferences(ActionRequest request, ActionResponse response,
        PortletPreferences portletPreferences) throws Exception {

    UnicodeProperties properties = PropertiesParamUtil.getProperties(request,
            DefaultConfigurationAction.PREFERENCES_PREFIX);

    for (Map.Entry<String, String> entry : properties.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();

        portletPreferences.setValue(name, value);
    }/*  w w w  .  j  av a  2  s  .  c  o  m*/

    portletPreferences.store();
}

From source file:com.liferay.document.library.web.internal.portlet.action.EditRepositoryMVCActionCommand.java

License:Open Source License

protected void updateRepository(ActionRequest actionRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId");

    String className = ParamUtil.getString(actionRequest, "className");

    long classNameId = _portal.getClassNameId(className);

    long folderId = ParamUtil.getLong(actionRequest, "folderId");
    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");

    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "settings--");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFolder.class.getName(), actionRequest);

    if (repositoryId <= 0) {

        // Add repository

        _repositoryService.addRepository(themeDisplay.getScopeGroupId(), classNameId, folderId, name,
                description, portletDisplay.getId(), typeSettingsProperties, serviceContext);
    } else {/* w  w w  . ja  v  a  2  s.  c o  m*/

        // Update repository

        _repositoryService.updateRepository(repositoryId, name, description);
    }
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.AddLayoutMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long parentLayoutId = ParamUtil.getLong(uploadPortletRequest, "parentLayoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap = LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
    Map<Locale, String> friendlyURLMap = LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL");

    long layoutPrototypeId = ParamUtil.getLong(uploadPortletRequest, "layoutPrototypeId");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    Layout layout = null;/*from w w w .j  av  a2  s  . co  m*/

    boolean inheritFromParentLayoutId = ParamUtil.getBoolean(uploadPortletRequest, "inheritFromParentLayoutId");

    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

    String linkToLayoutUuid = ParamUtil.getString(actionRequest, "linkToLayoutUuid");

    if (Validator.isNotNull(linkToLayoutUuid)) {
        Layout linkToLayout = _layoutLocalService.getLayoutByUuidAndGroupId(linkToLayoutUuid, groupId,
                privateLayout);

        typeSettingsProperties.put("linkToLayoutId", String.valueOf(linkToLayout.getLayoutId()));
    }

    if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
        Layout parentLayout = _layoutLocalService.getLayout(groupId, privateLayout, parentLayoutId);

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                parentLayout.getDescriptionMap(), parentLayout.getKeywordsMap(), parentLayout.getRobotsMap(),
                parentLayout.getType(), parentLayout.getTypeSettings(), hidden, friendlyURLMap, serviceContext);

        inheritMobileRuleGroups(layout, serviceContext);

        if (parentLayout.isTypePortlet()) {
            com.liferay.portlet.sites.action.ActionUtil.copyPreferences(actionRequest, layout, parentLayout);

            SitesUtil.copyLookAndFeel(layout, parentLayout);
        }
    } else if (layoutPrototypeId > 0) {
        LayoutPrototype layoutPrototype = _layoutPrototypeService.getLayoutPrototype(layoutPrototypeId);

        boolean layoutPrototypeLinkEnabled = ParamUtil.getBoolean(uploadPortletRequest,
                "layoutPrototypeLinkEnabled" + layoutPrototype.getUuid());

        serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);

        serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototype.getUuid());

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                descriptionMap, keywordsMap, robotsMap, LayoutConstants.TYPE_PORTLET,
                typeSettingsProperties.toString(), hidden, friendlyURLMap, serviceContext);

        // Force propagation from page template to page. See LPS-48430.

        SitesUtil.mergeLayoutPrototypeLayout(layout.getGroup(), layout);
    } else {
        long copyLayoutId = ParamUtil.getLong(uploadPortletRequest, "copyLayoutId");

        Layout copyLayout = null;

        String layoutTemplateId = ParamUtil.getString(uploadPortletRequest, "layoutTemplateId",
                PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

        if (copyLayoutId > 0) {
            copyLayout = _layoutLocalService.fetchLayout(groupId, privateLayout, copyLayoutId);

            if ((copyLayout != null) && copyLayout.isTypePortlet()) {
                LayoutTypePortlet copyLayoutTypePortlet = (LayoutTypePortlet) copyLayout.getLayoutType();

                layoutTemplateId = copyLayoutTypePortlet.getLayoutTemplateId();

                typeSettingsProperties = copyLayout.getTypeSettingsProperties();
            }
        }

        layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                descriptionMap, keywordsMap, robotsMap, type, typeSettingsProperties.toString(), hidden,
                friendlyURLMap, serviceContext);

        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

        layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

        _layoutService.updateLayout(groupId, privateLayout, layout.getLayoutId(), layout.getTypeSettings());

        if ((copyLayout != null) && copyLayout.isTypePortlet()) {
            com.liferay.portlet.sites.action.ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

            SitesUtil.copyLookAndFeel(layout, copyLayout);
        }
    }

    _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId,
            privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties());

    String portletResource = ParamUtil.getString(uploadPortletRequest, "portletResource");

    MultiSessionMessages.add(actionRequest, portletResource + "layoutAdded", layout);

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    if (Validator.isNull(redirect)) {
        redirect = _portal.getLayoutFullURL(layout, themeDisplay);

        if (layout.isTypeURL()) {
            redirect = _portal.getGroupFriendlyURL(layout.getLayoutSet(), themeDisplay);
        }
    }

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.AddSimpleLayoutMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long parentLayoutId = ParamUtil.getLong(actionRequest, "parentLayoutId");
    String name = ParamUtil.getString(actionRequest, "name");
    String type = ParamUtil.getString(actionRequest, "type");

    Map<Locale, String> nameMap = new HashMap<>();

    nameMap.put(themeDisplay.getLocale(), name);

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    try {/*w w w. ja  v a2s. c o  m*/
        Layout layout = _layoutService.addLayout(groupId, privateLayout, parentLayoutId, nameMap,
                new HashMap<Locale, String>(), new HashMap<Locale, String>(), new HashMap<Locale, String>(),
                new HashMap<Locale, String>(), type, typeSettingsProperties.toString(), false,
                new HashMap<Locale, String>(), serviceContext);

        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

        layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

        _layoutService.updateLayout(groupId, privateLayout, layout.getLayoutId(), layout.getTypeSettings());

        _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId,
                privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties());

        jsonObject.put("redirectURL", getRedirectURL(actionResponse));

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    } catch (PortalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        ResourceBundle resourceBundle = _resourceBundleLoader.loadResourceBundle(themeDisplay.getLocale());

        jsonObject.put("error", LanguageUtil.get(resourceBundle, "an-unexpected-error-occurred"));

        JSONPortletResponseUtil.writeJSON(actionRequest, actionResponse, jsonObject);
    }
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.EditLayoutMVCActionCommand.java

License:Open Source License

@Override
protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap = LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");
    Map<Locale, String> friendlyURLMap = LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL");
    boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo");

    byte[] iconBytes = null;

    long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId");

    if (fileEntryId > 0) {
        FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId);

        iconBytes = FileUtil.getBytes(fileEntry.getContentStream());
    }/*w w  w.jav a  2 s . co  m*/

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    Layout layout = _layoutLocalService.getLayout(groupId, privateLayout, layoutId);

    String currentType = layout.getType();

    layout = _layoutService.updateLayout(groupId, privateLayout, layoutId, layout.getParentLayoutId(), nameMap,
            titleMap, descriptionMap, keywordsMap, robotsMap, type, hidden, friendlyURLMap, !deleteLogo,
            iconBytes, serviceContext);

    themeDisplay.clearLayoutFriendlyURL(layout);

    UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties();

    UnicodeProperties formTypeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

    String linkToLayoutUuid = ParamUtil.getString(actionRequest, "linkToLayoutUuid");

    if (Validator.isNotNull(linkToLayoutUuid)) {
        Layout linkToLayout = _layoutLocalService.getLayoutByUuidAndGroupId(linkToLayoutUuid, groupId,
                privateLayout);

        formTypeSettingsProperties.put("linkToLayoutId", String.valueOf(linkToLayout.getLayoutId()));
    }

    LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

    if (type.equals(LayoutConstants.TYPE_PORTLET)) {
        String layoutTemplateId = ParamUtil.getString(uploadPortletRequest, "layoutTemplateId",
                PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

        layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

        layoutTypeSettingsProperties.putAll(formTypeSettingsProperties);

        boolean layoutCustomizable = GetterUtil
                .getBoolean(layoutTypeSettingsProperties.get(LayoutConstants.CUSTOMIZABLE_LAYOUT));

        if (!layoutCustomizable) {
            layoutTypePortlet.removeCustomization(layoutTypeSettingsProperties);
        }

        layout = _layoutService.updateLayout(groupId, privateLayout, layoutId,
                layoutTypeSettingsProperties.toString());

        if (!currentType.equals(LayoutConstants.TYPE_PORTLET)) {
            _portletPreferencesLocalService.deletePortletPreferences(0, PortletKeys.PREFS_OWNER_TYPE_LAYOUT,
                    layout.getPlid());
        }
    } else {
        layoutTypeSettingsProperties.putAll(formTypeSettingsProperties);

        layoutTypeSettingsProperties.putAll(layout.getTypeSettingsProperties());

        layout = _layoutService.updateLayout(groupId, privateLayout, layoutId,
                layoutTypeSettingsProperties.toString());
    }

    HttpServletResponse response = _portal.getHttpServletResponse(actionResponse);

    EventsProcessorUtil.process(PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
            layoutTypePortlet.getConfigurationActionUpdate(), uploadPortletRequest, response);

    _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId,
            privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties());

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    if (Validator.isNull(redirect)) {
        redirect = _portal.getLayoutFullURL(layout, themeDisplay);
    }

    String portletResource = ParamUtil.getString(actionRequest, "portletResource");

    MultiSessionMessages.add(actionRequest, portletResource + "layoutUpdated", layout);

    actionRequest.setAttribute(WebKeys.REDIRECT, redirect);
}

From source file:com.liferay.layout.admin.web.internal.portlet.action.EditLayoutSetMVCActionCommand.java

License:Open Source License

protected void updateSettings(ActionRequest actionRequest, long liveGroupId, long stagingGroupId,
        boolean privateLayout, UnicodeProperties settingsProperties) throws Exception {

    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

    settingsProperties.putAll(typeSettingsProperties);

    long groupId = liveGroupId;

    if (stagingGroupId > 0) {
        groupId = stagingGroupId;/*from   ww w . jav  a2s  .  co  m*/
    }

    _layoutSetService.updateSettings(groupId, privateLayout, settingsProperties.toString());
}

From source file:com.liferay.portlet.documentlibrary.action.EditRepositoryAction.java

License:Open Source License

protected void updateRepository(ActionRequest actionRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    long repositoryId = ParamUtil.getLong(actionRequest, "repositoryId");

    String className = ParamUtil.getString(actionRequest, "className");

    long classNameId = PortalUtil.getClassNameId(className);

    long folderId = ParamUtil.getLong(actionRequest, "folderId");
    String name = ParamUtil.getString(actionRequest, "name");
    String description = ParamUtil.getString(actionRequest, "description");

    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "settings--");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(DLFolder.class.getName(), actionRequest);

    if (repositoryId <= 0) {

        // Add repository

        RepositoryServiceUtil.addRepository(themeDisplay.getScopeGroupId(), classNameId, folderId, name,
                description, portletDisplay.getId(), typeSettingsProperties, serviceContext);
    } else {/*from   w  w w.ja  v a  2s. c  o m*/

        // Update repository

        RepositoryServiceUtil.updateRepository(repositoryId, name, description);
    }
}

From source file:com.liferay.portlet.layoutsadmin.action.EditLayoutsAction.java

License:Open Source License

protected Object[] updateLayout(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {

    UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String cmd = ParamUtil.getString(uploadPortletRequest, Constants.CMD);

    long groupId = ParamUtil.getLong(actionRequest, "groupId");
    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");
    long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId");
    boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout");
    long layoutId = ParamUtil.getLong(actionRequest, "layoutId");
    long parentLayoutId = ParamUtil.getLong(uploadPortletRequest, "parentLayoutId");
    Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name");
    Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title");
    Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description");
    Map<Locale, String> keywordsMap = LocalizationUtil.getLocalizationMap(actionRequest, "keywords");
    Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots");
    String type = ParamUtil.getString(uploadPortletRequest, "type");
    boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden");

    String friendlyURL = ParamUtil.getString(uploadPortletRequest, "friendlyURL");
    boolean iconImage = ParamUtil.getBoolean(uploadPortletRequest, "iconImage");
    byte[] iconBytes = getIconBytes(uploadPortletRequest, "iconFileName");
    long layoutPrototypeId = ParamUtil.getLong(uploadPortletRequest, "layoutPrototypeId");

    ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest);

    Layout layout = null;/*from  w  w  w  .  j av a 2  s  .c om*/
    UnicodeProperties layoutTypeSettingsProperties = null;
    String oldFriendlyURL = StringPool.BLANK;

    if (cmd.equals(Constants.ADD)) {

        // Add layout

        boolean inheritFromParentLayoutId = ParamUtil.getBoolean(uploadPortletRequest,
                "inheritFromParentLayoutId");

        if (inheritFromParentLayoutId && (parentLayoutId > 0)) {
            Layout parentLayout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, parentLayoutId);

            layout = LayoutServiceUtil.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                    descriptionMap, keywordsMap, robotsMap, parentLayout.getType(), hidden, friendlyURL,
                    serviceContext);

            LayoutServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(),
                    parentLayout.getTypeSettings());

            if (parentLayout.isTypePortlet()) {
                ActionUtil.copyPreferences(actionRequest, layout, parentLayout);

                SitesUtil.copyLookAndFeel(layout, parentLayout);
            }
        } else if (layoutPrototypeId > 0) {
            LayoutPrototype layoutPrototype = LayoutPrototypeServiceUtil.getLayoutPrototype(layoutPrototypeId);

            String layoutPrototypeLinkEnabled = ParamUtil.getString(uploadPortletRequest,
                    "layoutPrototypeLinkEnabled");

            if (Validator.isNotNull(layoutPrototypeLinkEnabled)) {
                serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled);
            }

            serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototype.getUuid());

            layout = LayoutServiceUtil.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                    descriptionMap, keywordsMap, robotsMap, LayoutConstants.TYPE_PORTLET, hidden, friendlyURL,
                    serviceContext);
        } else {
            layout = LayoutServiceUtil.addLayout(groupId, privateLayout, parentLayoutId, nameMap, titleMap,
                    descriptionMap, keywordsMap, robotsMap, type, hidden, friendlyURL, serviceContext);
        }

        layoutTypeSettingsProperties = layout.getTypeSettingsProperties();
    } else {

        // Update layout

        layout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, layoutId);

        oldFriendlyURL = layout.getFriendlyURL();

        layout = LayoutServiceUtil.updateLayout(groupId, privateLayout, layoutId, layout.getParentLayoutId(),
                nameMap, titleMap, descriptionMap, keywordsMap, robotsMap, type, hidden, friendlyURL,
                Boolean.valueOf(iconImage), iconBytes, serviceContext);

        layoutTypeSettingsProperties = layout.getTypeSettingsProperties();

        if (oldFriendlyURL.equals(layout.getFriendlyURL())) {
            oldFriendlyURL = StringPool.BLANK;
        }

        UnicodeProperties formTypeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
                "TypeSettingsProperties--");

        if (type.equals(LayoutConstants.TYPE_PORTLET)) {
            LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();

            String layoutTemplateId = ParamUtil.getString(uploadPortletRequest, "layoutTemplateId",
                    PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID);

            layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId);

            long copyLayoutId = ParamUtil.getLong(uploadPortletRequest, "copyLayoutId");

            if ((copyLayoutId > 0) && (copyLayoutId != layout.getLayoutId())) {

                try {
                    Layout copyLayout = LayoutLocalServiceUtil.getLayout(groupId, privateLayout, copyLayoutId);

                    if (copyLayout.isTypePortlet()) {
                        layoutTypeSettingsProperties = copyLayout.getTypeSettingsProperties();

                        ActionUtil.copyPreferences(actionRequest, layout, copyLayout);

                        SitesUtil.copyLookAndFeel(layout, copyLayout);
                    }
                } catch (NoSuchLayoutException nsle) {
                }
            } else {
                layoutTypeSettingsProperties.putAll(formTypeSettingsProperties);

                LayoutServiceUtil.updateLayout(groupId, privateLayout, layoutId, layout.getTypeSettings());
            }
        } else {
            layout.setTypeSettingsProperties(formTypeSettingsProperties);

            layoutTypeSettingsProperties.putAll(layout.getTypeSettingsProperties());

            LayoutServiceUtil.updateLayout(groupId, privateLayout, layoutId, layout.getTypeSettings());
        }

        HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse);

        LayoutSettings layoutSettings = LayoutSettings.getInstance(layout);

        EventsProcessorUtil.process(PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE,
                layoutSettings.getConfigurationActionUpdate(), uploadPortletRequest, response);
    }

    updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId, privateLayout,
            layout.getLayoutId(), layoutTypeSettingsProperties);

    updateCustomAttributes(themeDisplay.getCompanyId(), layout, uploadPortletRequest);

    return new Object[] { layout, oldFriendlyURL };
}

From source file:com.liferay.portlet.layoutsadmin.action.EditLayoutSetAction.java

License:Open Source License

protected void updateSettings(ActionRequest actionRequest, long liveGroupId, long stagingGroupId,
        boolean privateLayout, UnicodeProperties settingsProperties) throws Exception {

    UnicodeProperties typeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest,
            "TypeSettingsProperties--");

    settingsProperties.putAll(typeSettingsProperties);

    boolean showSiteName = ParamUtil.getBoolean(actionRequest, "showSiteName");

    settingsProperties.put("showSiteName", Boolean.toString(showSiteName));

    LayoutSetServiceUtil.updateSettings(liveGroupId, privateLayout, settingsProperties.toString());

    if (stagingGroupId > 0) {
        LayoutSetServiceUtil.updateSettings(stagingGroupId, privateLayout, typeSettingsProperties.toString());
    }/*  ww  w. jav a 2 s  . c  o  m*/
}