List of usage examples for com.liferay.portal.kernel.model LayoutTypePortletConstants COLUMN_PREFIX
String COLUMN_PREFIX
To view the source code for com.liferay.portal.kernel.model LayoutTypePortletConstants COLUMN_PREFIX.
Click Source Link
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected void addLayout(boolean privateLayout, long parentLayoutId, JSONObject layoutJSONObject) throws Exception { if (targetClassName.equals(LayoutSetPrototype.class.getName())) { privateLayout = true;//from w w w . java2 s .c o m } Map<Locale, String> nameMap = getMap(layoutJSONObject, "name"); Map<Locale, String> titleMap = getMap(layoutJSONObject, "title"); String type = layoutJSONObject.getString("type"); if (Validator.isNull(type)) { type = LayoutConstants.TYPE_PORTLET; } String typeSettings = layoutJSONObject.getString("typeSettings"); boolean hidden = layoutJSONObject.getBoolean("hidden"); String themeId = layoutJSONObject.getString("themeId"); String layoutCss = layoutJSONObject.getString("layoutCss"); String colorSchemeId = layoutJSONObject.getString("colorSchemeId"); Map<Locale, String> friendlyURLMap = new HashMap<>(); String friendlyURL = layoutJSONObject.getString("friendlyURL"); if (Validator.isNotNull(friendlyURL) && !friendlyURL.startsWith(StringPool.SLASH)) { friendlyURL = StringPool.SLASH + friendlyURL; } friendlyURLMap.put(LocaleUtil.getDefault(), friendlyURL); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setScopeGroupId(groupId); serviceContext.setUserId(userId); ServiceContextThreadLocal.pushServiceContext(serviceContext); try { String layoutPrototypeName = layoutJSONObject.getString("layoutPrototypeName"); String layoutPrototypeUuid = null; if (Validator.isNotNull(layoutPrototypeName)) { LayoutPrototype layoutPrototype = getLayoutPrototype(companyId, layoutPrototypeName); layoutPrototypeUuid = layoutPrototype.getUuid(); } else { layoutPrototypeUuid = layoutJSONObject.getString("layoutPrototypeUuid"); } if (Validator.isNotNull(layoutPrototypeUuid)) { boolean layoutPrototypeLinkEnabled = GetterUtil .getBoolean(layoutJSONObject.getString("layoutPrototypeLinkEnabled")); serviceContext.setAttribute("layoutPrototypeLinkEnabled", layoutPrototypeLinkEnabled); serviceContext.setAttribute("layoutPrototypeUuid", layoutPrototypeUuid); } Layout layout = layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, friendlyURL); if (layout != null) { if (!developerModeEnabled) { if (_log.isInfoEnabled()) { _log.info("Layout with friendly URL " + friendlyURL + " already exists"); } return; } if (!updateModeEnabled) { layoutLocalService.deleteLayout(layout); } } if (!updateModeEnabled || (layout == null)) { layout = layoutLocalService.addLayout(userId, groupId, privateLayout, parentLayoutId, nameMap, titleMap, null, null, null, type, typeSettings, hidden, friendlyURLMap, serviceContext); } else { resetLayoutColumns(layout); layout = layoutLocalService.updateLayout(groupId, privateLayout, layout.getLayoutId(), parentLayoutId, nameMap, titleMap, layout.getDescriptionMap(), layout.getKeywordsMap(), layout.getRobotsMap(), type, hidden, friendlyURLMap, layout.getIconImage(), null, serviceContext); } if (Validator.isNotNull(themeId) || Validator.isNotNull(colorSchemeId)) { // If the theme ID or the color scheme ID are not null, then the // layout has a custom look and feel and should be updated in // the database layoutLocalService.updateLookAndFeel(groupId, privateLayout, layout.getLayoutId(), themeId, colorSchemeId, layoutCss); } LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); String layoutTemplateId = layoutJSONObject.getString("layoutTemplateId", _defaultLayoutTemplateId); if (Validator.isNotNull(layoutTemplateId)) { layoutTypePortlet.setLayoutTemplateId(userId, layoutTemplateId, false); } JSONArray columnsJSONArray = layoutJSONObject.getJSONArray("columns"); addLayoutColumns(layout, LayoutTypePortletConstants.COLUMN_PREFIX, columnsJSONArray); layoutLocalService.updateLayout(groupId, layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); JSONArray layoutsJSONArray = layoutJSONObject.getJSONArray("layouts"); addLayouts(privateLayout, layout.getLayoutId(), layoutsJSONArray); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to import layout " + layoutJSONObject, e); } throw e; } finally { ServiceContextThreadLocal.popServiceContext(); } }
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected void addLayoutColumnPortlet(Layout layout, String columnId, JSONObject portletJSONObject) throws Exception { LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); String rootPortletId = portletJSONObject.getString("portletId"); if (Validator.isNull(rootPortletId)) { throw new ImporterException("portletId is not specified"); }//from w w w . ja v a 2s .c om PortletPreferencesTranslator portletPreferencesTranslator = portletPreferencesTranslators .get(rootPortletId); String portletId = layoutTypePortlet.addPortletId(userId, rootPortletId, columnId, -1, false); if (portletId == null) { return; } JSONObject portletPreferencesJSONObject = portletJSONObject.getJSONObject("portletPreferences"); if ((portletPreferencesJSONObject == null) || (portletPreferencesJSONObject.length() == 0)) { return; } if (portletPreferencesTranslator != null) { PortletPreferencesIds portletPreferencesIds = PortletPreferencesFactoryUtil .getPortletPreferencesIds(layout.getGroupId(), 0, layout, portletId, false); PortletPreferences portletSetup = PortletPreferencesLocalServiceUtil .getPreferences(portletPreferencesIds); Iterator<String> iterator = portletPreferencesJSONObject.keys(); while (iterator.hasNext()) { String key = iterator.next(); portletPreferencesTranslator.translate(portletPreferencesJSONObject, key, portletSetup); } portletSetup.store(); } if (rootPortletId.equals(PortletKeys.NESTED_PORTLETS)) { JSONArray columnsJSONArray = portletPreferencesJSONObject.getJSONArray("columns"); StringBundler sb = new StringBundler(4); sb.append(StringPool.UNDERLINE); sb.append(portletId); sb.append(StringPool.DOUBLE_UNDERLINE); sb.append(LayoutTypePortletConstants.COLUMN_PREFIX); addLayoutColumns(layout, sb.toString(), columnsJSONArray); } }
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected void addLayoutPrototype(InputStream inputStream) throws Exception { String content = StringUtil.read(inputStream); if (Validator.isNull(content)) { return;//from w ww. j a v a 2 s . c o m } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(content); JSONObject layoutTemplateJSONObject = jsonObject.getJSONObject("layoutTemplate"); Map<Locale, String> nameMap = getMap(layoutTemplateJSONObject.getString("name")); String name = nameMap.get(Locale.getDefault()); Map<Locale, String> descriptionMap = getMap(layoutTemplateJSONObject, "description"); String uuid = layoutTemplateJSONObject.getString("uuid"); LayoutPrototype layoutPrototype = getLayoutPrototype(companyId, name); if (layoutPrototype != null) { if (!developerModeEnabled) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("Layout prototype with name ", name, " already exists for company ", String.valueOf(companyId))); } return; } if (!updateModeEnabled) { layoutPrototypeLocalService.deleteLayoutPrototype(layoutPrototype); } } ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(companyId); serviceContext.setUserId(userId); if (Validator.isNotNull(uuid)) { serviceContext.setUuid(uuid); } try { if (!updateModeEnabled || (layoutPrototype == null)) { layoutPrototype = layoutPrototypeLocalService.addLayoutPrototype(userId, companyId, getMap(name), descriptionMap, true, serviceContext); } else { layoutPrototype = layoutPrototypeLocalService.updateLayoutPrototype( layoutPrototype.getLayoutPrototypeId(), getMap(name), descriptionMap, layoutPrototype.isActive(), serviceContext); } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to import layout prototype " + name, e); } throw e; } JSONArray columnsJSONArray = layoutTemplateJSONObject.getJSONArray("columns"); Layout layout = layoutPrototype.getLayout(); addLayoutColumns(layout, LayoutTypePortletConstants.COLUMN_PREFIX, columnsJSONArray); layoutLocalService.updateLayout(layout.getGroupId(), layout.isPrivateLayout(), layout.getLayoutId(), layout.getTypeSettings()); }