private LayoutTypePortlet _getLayoutTypePortletClone(HttpServletRequest request) throws IOException { LayoutTypePortlet layoutTypePortlet = null; LayoutClone layoutClone = LayoutCloneFactory.getInstance(); if (layoutClone != null) { String typeSettings = layoutClone.get(request, getPlid()); if (typeSettings != null) { UnicodeProperties typeSettingsProperties = new UnicodeProperties(true); typeSettingsProperties.load(typeSettings); String stateMax = typeSettingsProperties.getProperty(LayoutTypePortletConstants.STATE_MAX); String stateMin = typeSettingsProperties.getProperty(LayoutTypePortletConstants.STATE_MIN); Layout layout = (Layout) this.clone(); layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); layoutTypePortlet.setStateMax(stateMax); layoutTypePortlet.setStateMin(stateMin); } } if (layoutTypePortlet == null) { layoutTypePortlet = (LayoutTypePortlet) getLayoutType(); } return layoutTypePortlet; }
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); } }