@Override public void setLayoutTemplateId( long userId, String newLayoutTemplateId, boolean checkPermission) { if (checkPermission && !PluginSettingLocalServiceUtil.hasPermission( userId, newLayoutTemplateId, Plugin.TYPE_LAYOUT_TEMPLATE)) { return; } LayoutTemplate oldLayoutTemplate = getLayoutTemplate(); String themeId = getThemeId(); LayoutTemplate newLayoutTemplate = LayoutTemplateLocalServiceUtil.getLayoutTemplate(newLayoutTemplateId, false, themeId); if (newLayoutTemplate == null) { if (_log.isWarnEnabled()) { _log.warn("Unable to find layout template " + newLayoutTemplateId); } return; } setTypeSettingsProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, newLayoutTemplateId); List<String> oldColumns = oldLayoutTemplate.getColumns(); List<String> newColumns = newLayoutTemplate.getColumns(); reorganizePortlets(newColumns, oldColumns); }
protected void mergePortlets(Layout layout, String newTypeSettings, String portletsMergeMode) { try { UnicodeProperties previousTypeSettingsProperties = layout.getTypeSettingsProperties(); LayoutTypePortlet previousLayoutType = (LayoutTypePortlet) layout.getLayoutType(); LayoutTemplate previousLayoutTemplate = previousLayoutType.getLayoutTemplate(); List<String> previousColumns = previousLayoutTemplate.getColumns(); UnicodeProperties newTypeSettingsProperties = new UnicodeProperties(true); newTypeSettingsProperties.load(newTypeSettings); String layoutTemplateId = newTypeSettingsProperties.getProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID); previousTypeSettingsProperties.setProperty( LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, layoutTemplateId); LayoutTemplate newLayoutTemplate = LayoutTemplateLocalServiceUtil.getLayoutTemplate(layoutTemplateId, false, null); String[] newPortletIds = new String[0]; for (String columnId : newLayoutTemplate.getColumns()) { String columnValue = newTypeSettingsProperties.getProperty(columnId); String[] portletIds = StringUtil.split(columnValue); if (!previousColumns.contains(columnId)) { newPortletIds = ArrayUtil.append(newPortletIds, portletIds); } else { String[] previousPortletIds = StringUtil.split(previousTypeSettingsProperties.getProperty(columnId)); portletIds = appendPortletIds(previousPortletIds, portletIds, portletsMergeMode); previousTypeSettingsProperties.setProperty(columnId, StringUtil.merge(portletIds)); } } // Add portlets in non-existent column to the first column String columnId = previousColumns.get(0); String[] portletIds = StringUtil.split(previousTypeSettingsProperties.getProperty(columnId)); appendPortletIds(portletIds, newPortletIds, portletsMergeMode); previousTypeSettingsProperties.setProperty(columnId, StringUtil.merge(portletIds)); layout.setTypeSettings(previousTypeSettingsProperties.toString()); } catch (IOException ioe) { layout.setTypeSettings(newTypeSettings); } }
protected List<String> getColumns() { LayoutTemplate layoutTemplate = getLayoutTemplate(); List<String> columns = new ArrayList<String>(); columns.addAll(layoutTemplate.getColumns()); columns.addAll(getNestedColumns()); return columns; }
protected boolean hasNonstaticPortletId(String portletId) { LayoutTemplate layoutTemplate = getLayoutTemplate(); List<String> columns = layoutTemplate.getColumns(); for (int i = 0; i < columns.size(); i++) { String columnId = columns.get(i); if (hasNonstaticPortletId(columnId, portletId)) { return true; } } return false; }
protected List<String> getColumns() { List<String> columns = new ArrayList<>(); Layout layout = getLayout(); if (layout.isTypePortlet()) { LayoutTemplate layoutTemplate = getLayoutTemplate(); columns.addAll(layoutTemplate.getColumns()); columns.addAll(getNestedColumns()); } else if (layout.isTypePanel()) { columns.add("panelSelectedPortlets"); } return columns; }
public LayoutTemplate getLayoutTemplate() { String themeId = getThemeId(); LayoutTemplate layoutTemplate = LayoutTemplateLocalServiceUtil.getLayoutTemplate(getLayoutTemplateId(), false, themeId); if (layoutTemplate == null) { layoutTemplate = new LayoutTemplateImpl(StringPool.BLANK, StringPool.BLANK); List<String> columns = new ArrayList<String>(); for (int i = 1; i <= 10; i++) { columns.add("column-" + i); } layoutTemplate.setColumns(columns); } return layoutTemplate; }
@Override public LayoutTemplate getLayoutTemplate() { String themeId = getThemeId(); LayoutTemplate layoutTemplate = LayoutTemplateLocalServiceUtil.getLayoutTemplate(getLayoutTemplateId(), false, themeId); if (layoutTemplate == null) { layoutTemplate = new LayoutTemplateImpl(StringPool.BLANK, StringPool.BLANK); List<String> columns = new ArrayList<>(); for (int i = 1; i <= 10; i++) { columns.add(LayoutTypePortletConstants.COLUMN_PREFIX + i); } layoutTemplate.setColumns(columns); } return layoutTemplate; }
public void setLayoutTemplateId( long userId, String newLayoutTemplateId, boolean checkPermission) { if (checkPermission && !PluginSettingLocalServiceUtil.hasPermission( userId, newLayoutTemplateId, Plugin.TYPE_LAYOUT_TEMPLATE)) { return; } String oldLayoutTemplateId = getLayoutTemplateId(); if (Validator.isNull(oldLayoutTemplateId)) { oldLayoutTemplateId = PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID; } getTypeSettingsProperties() .setProperty(LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, newLayoutTemplateId); String themeId = getThemeId(); LayoutTemplate oldLayoutTemplate = LayoutTemplateLocalServiceUtil.getLayoutTemplate(oldLayoutTemplateId, false, themeId); if (oldLayoutTemplate == null) { return; } LayoutTemplate newLayoutTemplate = LayoutTemplateLocalServiceUtil.getLayoutTemplate(newLayoutTemplateId, false, themeId); List<String> oldColumns = oldLayoutTemplate.getColumns(); List<String> newColumns = newLayoutTemplate.getColumns(); reorganizePortlets(newColumns, oldColumns); }
protected String addPortletId( long userId, String portletId, String columnId, int columnPos, boolean checkPermission, boolean strictHasPortlet) throws PortalException { 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) { 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; }
public static void addPortlets(Group group, Layout layout, String name, String keyPrefix) throws Exception { LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); LayoutTemplate layoutTemplate = layoutTypePortlet.getLayoutTemplate(); List<String> columns = layoutTemplate.getColumns(); for (String column : columns) { String[] portletIds = null; if (Validator.isNull(name)) { portletIds = PortletProps.getArray(keyPrefix + column); } else { Filter filter = new Filter(name); portletIds = PortletProps.getArray(keyPrefix + column, filter); } layoutTypePortlet.addPortletIds(0, portletIds, column, false); } LayoutLocalServiceUtil.updateLayout( layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); List<String> portletIds = layoutTypePortlet.getPortletIds(); for (String portletId : portletIds) { addResources(layout, portletId); if (portletId.startsWith("1_WAR_eventsdisplayportlet")) { updatePortletTitle(layout, portletId, "Events"); } else if (portletId.startsWith("1_WAR_soannouncementsportlet")) { updatePortletTitle(layout, portletId, "Announcements"); } else if (portletId.startsWith("1_WAR_wysiwygportlet")) { updatePortletTitle(layout, portletId, "Welcome"); } else if (portletId.contains("_WAR_contactsportlet")) { configureProfile(layout, portletId); removePortletBorder(layout, portletId); } else if (portletId.startsWith(PortletKeys.ASSET_PUBLISHER)) { configureAssetPublisher(layout); updatePortletTitle(layout, portletId, "Related Content"); } else if (portletId.startsWith(PortletKeys.BLOGS_AGGREGATOR)) { configureBlogsAggregator(layout); updatePortletTitle(layout, portletId, "Recent Blogs"); } else if (portletId.startsWith(PortletKeys.BREADCRUMB)) { removePortletBorder(layout, portletId); } else if (portletId.startsWith(PortletKeys.MESSAGE_BOARDS)) { configureMessageBoards(layout); removePortletBorder(layout, portletId); } else if (portletId.equals(PortletKeys.DOCUMENT_LIBRARY) || portletId.equals(PortletKeys.BLOGS) || portletId.equals(PortletKeys.WIKI) || portletId.equals("1_WAR_calendarportlet") || portletId.contains("_WAR_microblogsportlet") || portletId.equals("1_WAR_privatemessagingportlet") || portletId.contains("1_WAR_tasksportlet")) { removePortletBorder(layout, portletId); } } }
public String addPortletId( long userId, String portletId, String columnId, int columnPos, boolean checkPermission) throws PortalException, SystemException { 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.getInstanceId(portlet.getPortletId()) == null)) { portletId = portletId + getFullInstanceSeparator(); } if (hasPortletId(portletId)) { return null; } if (columnId == null) { LayoutTemplate layoutTemplate = getLayoutTemplate(); List<String> columns = layoutTemplate.getColumns(); if (columns.size() > 0) { columnId = columns.get(0); } } if (columnId != null) { if (isCustomizable() && isColumnDisabled(columnId)) { return null; } String columnValue = StringPool.BLANK; if (hasUserPreferences()) { columnValue = getUserPreference(columnId); } else { columnValue = getTypeSettingsProperties().getProperty(columnId); } if ((columnValue == null) && (columnId.startsWith(_nestedPortletsNamespace))) { 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 { getTypeSettingsProperties().setProperty(columnId, columnValue); } } try { PortletLayoutListener portletLayoutListener = portlet.getPortletLayoutListenerInstance(); if (_enablePortletLayoutListener && (portletLayoutListener != null)) { portletLayoutListener.onAddToLayout(portletId, layout.getPlid()); } } catch (Exception e) { _log.error("Unable to fire portlet layout listener event", e); } return portletId; }