protected String getUserPreference(String key) { String value = StringPool.BLANK; if (!hasUserPreferences()) { return value; } value = _portalPreferences.getValue(CustomizedPages.namespacePlid(getPlid()), key, StringPool.NULL); if (!value.equals(StringPool.NULL)) { return value; } value = getTypeSettingsProperty(key); if (Validator.isNull(value)) { return value; } List<String> newPortletIds = new ArrayList<>(); PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); String[] portletIds = StringUtil.split(value); for (String portletId : portletIds) { try { if (!PortletPermissionUtil.contains( permissionChecker, getLayout(), portletId, ActionKeys.VIEW, true)) { continue; } String rootPortletId = PortletConstants.getRootPortletId(portletId); if (!PortletPermissionUtil.contains( permissionChecker, rootPortletId, ActionKeys.ADD_TO_PAGE)) { continue; } } catch (Exception e) { _log.error(e, e); } String newPortletId = null; boolean preferencesUniquePerLayout = false; try { Portlet portlet = PortletLocalServiceUtil.getPortletById(getCompanyId(), portletId); preferencesUniquePerLayout = portlet.isPreferencesUniquePerLayout(); } catch (SystemException se) { _log.error(se, se); } if (PortletConstants.hasInstanceId(portletId) || preferencesUniquePerLayout) { String instanceId = null; if (PortletConstants.hasInstanceId(portletId)) { instanceId = PortletConstants.generateInstanceId(); } newPortletId = PortletConstants.assemblePortletId( portletId, _portalPreferences.getUserId(), instanceId); copyPreferences(_portalPreferences.getUserId(), portletId, newPortletId); copyResourcePermissions(portletId, newPortletId); } else { newPortletId = portletId; } newPortletIds.add(newPortletId); } value = StringUtil.merge(newPortletIds); setUserPreference(key, value); return value; }
protected String addPortletId( long userId, String portletId, String columnId, int columnPos, boolean checkPermission, boolean strictHasPortlet) { portletId = JS.getSafeName(portletId); Layout layout = getLayout(); Portlet portlet = null; try { portlet = PortletLocalServiceUtil.getPortletById(layout.getCompanyId(), portletId); if (portlet == null) { if (_log.isWarnEnabled()) { _log.warn("Portlet " + portletId + " cannot be added because it is not registered"); } return null; } PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker(); if (checkPermission && !PortletPermissionUtil.contains( permissionChecker, layout, portlet, ActionKeys.ADD_TO_PAGE)) { return null; } } catch (Exception e) { _log.error(e, e); } if (portlet.isSystem()) { return null; } if (portlet.isInstanceable() && !PortletConstants.hasInstanceId(portletId)) { portletId = PortletConstants.assemblePortletId(portletId, PortletConstants.generateInstanceId()); } if (hasPortletId(portletId, strictHasPortlet)) { return null; } if (columnId == null) { LayoutTemplate layoutTemplate = getLayoutTemplate(); List<String> columns = layoutTemplate.getColumns(); if (!columns.isEmpty()) { columnId = columns.get(0); } } if (columnId == null) { return null; } if (isCustomizable()) { if (isColumnDisabled(columnId)) { return null; } if ((PortletConstants.hasInstanceId(portletId) || portlet.isPreferencesUniquePerLayout()) && hasUserPreferences()) { portletId = PortletConstants.assemblePortletId(portletId, userId); } } String columnValue = StringPool.BLANK; if (hasUserPreferences()) { columnValue = getUserPreference(columnId); } else { columnValue = getTypeSettingsProperty(columnId); } if ((columnValue == null) && columnId.startsWith(_NESTED_PORTLETS_NAMESPACE)) { addNestedColumn(columnId); } if (columnPos >= 0) { List<String> portletIds = ListUtil.fromArray(StringUtil.split(columnValue)); if (columnPos <= portletIds.size()) { portletIds.add(columnPos, portletId); } else { portletIds.add(portletId); } columnValue = StringUtil.merge(portletIds); } else { columnValue = StringUtil.add(columnValue, portletId); } if (hasUserPreferences()) { setUserPreference(columnId, columnValue); } else { setTypeSettingsProperty(columnId, columnValue); } try { if (_enablePortletLayoutListener && !portlet.isUndeployedPortlet()) { PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance(); if (portletLayoutListener != null) { portletLayoutListener.onAddToLayout(portletId, layout.getPlid()); } } } catch (Exception e) { _log.error("Unable to fire portlet layout listener event", e); } return portletId; }