Example usage for com.liferay.portal.kernel.xml Element attributeValue

List of usage examples for com.liferay.portal.kernel.xml Element attributeValue

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.xml Element attributeValue.

Prototype

public String attributeValue(String name);

Source Link

Usage

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

@Override
public boolean validateReference(PortletDataContext portletDataContext, Element referenceElement) {

    validateMissingGroupReference(portletDataContext, referenceElement);

    String uuid = referenceElement.attributeValue("uuid");

    Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

    long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id"));

    groupId = MapUtil.getLong(groupIds, groupId);

    boolean privateLayout = GetterUtil.getBoolean(referenceElement.attributeValue("private-layout"));

    Layout existingLayout = fetchMissingReference(uuid, groupId, privateLayout);

    if (existingLayout == null) {
        return false;
    }//  w  ww.j a  v  a 2s. c  o m

    return true;
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportMissingReference(PortletDataContext portletDataContext, Element referenceElement)
        throws PortletDataException {

    importMissingGroupReference(portletDataContext, referenceElement);

    String uuid = referenceElement.attributeValue("uuid");

    Map<Long, Long> groupIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Group.class);

    long groupId = GetterUtil.getLong(referenceElement.attributeValue("group-id"));

    groupId = MapUtil.getLong(groupIds, groupId);

    boolean privateLayout = GetterUtil.getBoolean(referenceElement.attributeValue("private-layout"));

    Layout existingLayout = null;/*from  w w w. j  ava 2  s . co m*/

    existingLayout = fetchMissingReference(uuid, groupId, privateLayout);

    Map<Long, Layout> layouts = (Map<Long, Layout>) portletDataContext
            .getNewPrimaryKeysMap(Layout.class + ".layout");

    long layoutId = GetterUtil.getLong(referenceElement.attributeValue("layout-id"));

    layouts.put(layoutId, existingLayout);

    Map<Long, Long> layoutPlids = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class);

    long plid = GetterUtil.getLong(referenceElement.attributeValue("class-pk"));

    layoutPlids.put(plid, existingLayout.getPlid());
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Layout layout) throws Exception {

    final long groupId = portletDataContext.getGroupId();
    long userId = portletDataContext.getUserId(layout.getUserUuid());

    Element layoutElement = portletDataContext.getImportDataStagedModelElement(layout);

    long layoutId = GetterUtil.getLong(layoutElement.attributeValue("layout-id"));

    long oldLayoutId = layoutId;

    final boolean privateLayout = portletDataContext.isPrivateLayout();

    Map<Long, Layout> layouts = (Map<Long, Layout>) portletDataContext
            .getNewPrimaryKeysMap(Layout.class + ".layout");

    Layout existingLayout = null;/*from ww  w .j  a v a2 s.  co  m*/
    Layout importedLayout = null;

    String friendlyURL = layout.getFriendlyURL();

    String layoutsImportMode = MapUtil.getString(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE,
            PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID);

    if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_ADD_AS_NEW)) {

        layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);

        friendlyURL = StringPool.SLASH + layoutId;
    } else if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_NAME)) {

        Locale locale = LocaleUtil.getSiteDefault();

        String localizedName = layout.getName(locale);

        List<Layout> previousLayouts = _layoutLocalService.getLayouts(groupId, privateLayout);

        for (Layout curLayout : previousLayouts) {
            if (localizedName.equals(curLayout.getName(locale))
                    || friendlyURL.equals(curLayout.getFriendlyURL())) {

                existingLayout = curLayout;

                break;
            }
        }

        if (existingLayout == null) {
            layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);
        }
    } else if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

        existingLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(layout.getUuid(), groupId,
                privateLayout);

        if (SitesUtil.isLayoutModifiedSinceLastMerge(existingLayout)) {
            layouts.put(oldLayoutId, existingLayout);

            return;
        }

        LayoutFriendlyURL layoutFriendlyURL = _layoutFriendlyURLLocalService
                .fetchFirstLayoutFriendlyURL(groupId, privateLayout, friendlyURL);

        if ((layoutFriendlyURL != null) && (existingLayout == null)) {
            Layout mergeFailFriendlyURLLayout = _layoutLocalService.getLayout(layoutFriendlyURL.getPlid());

            SitesUtil.addMergeFailFriendlyURLLayout(mergeFailFriendlyURLLayout);

            if (!_log.isWarnEnabled()) {
                return;
            }

            StringBundler sb = new StringBundler(6);

            sb.append("Layout with layout ID ");
            sb.append(layout.getLayoutId());
            sb.append(" cannot be propagated because the friendly URL ");
            sb.append("conflicts with the friendly URL of layout with ");
            sb.append("layout ID ");
            sb.append(mergeFailFriendlyURLLayout.getLayoutId());

            _log.warn(sb.toString());

            return;
        }
    } else {

        // The default behavior of import mode is
        // PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID

        existingLayout = _layoutLocalService.fetchLayoutByUuidAndGroupId(layout.getUuid(), groupId,
                privateLayout);

        if (existingLayout == null) {
            existingLayout = _layoutLocalService.fetchLayoutByFriendlyURL(groupId, privateLayout, friendlyURL);
        }

        if (existingLayout == null) {
            layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);
        }
    }

    if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(7);

        sb.append("Layout with {groupId=");
        sb.append(groupId);
        sb.append(",privateLayout=");
        sb.append(privateLayout);
        sb.append(",layoutId=");
        sb.append(layoutId);

        if (existingLayout == null) {
            sb.append("} does not exist");

            _log.debug(sb.toString());
        } else {
            sb.append("} exists");

            _log.debug(sb.toString());
        }
    }

    if (existingLayout == null) {
        long plid = _counterLocalService.increment();

        importedLayout = _layoutLocalService.createLayout(plid);

        if (layoutsImportMode.equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) {

            importedLayout.setSourcePrototypeLayoutUuid(layout.getUuid());

            layoutId = _layoutLocalService.getNextLayoutId(groupId, privateLayout);
        } else {
            importedLayout.setCreateDate(layout.getCreateDate());
            importedLayout.setModifiedDate(layout.getModifiedDate());
            importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
            importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());
            importedLayout.setSourcePrototypeLayoutUuid(layout.getSourcePrototypeLayoutUuid());
        }

        importedLayout.setUuid(layout.getUuid());
        importedLayout.setGroupId(groupId);
        importedLayout.setUserId(userId);
        importedLayout.setPrivateLayout(privateLayout);
        importedLayout.setLayoutId(layoutId);

        initNewLayoutPermissions(portletDataContext.getCompanyId(), groupId, userId, layout, importedLayout,
                privateLayout);

        LayoutSet layoutSet = _layoutSetLocalService.getLayoutSet(groupId, privateLayout);

        importedLayout.setLayoutSet(layoutSet);
    } else {
        importedLayout = existingLayout;
    }

    portletDataContext.setPlid(importedLayout.getPlid());
    portletDataContext.setOldPlid(layout.getPlid());

    long parentLayoutId = layout.getParentLayoutId();

    String parentLayoutUuid = GetterUtil.getString(layoutElement.attributeValue("parent-layout-uuid"));

    Element parentLayoutElement = portletDataContext.getReferenceDataElement(layout, Layout.class,
            layout.getGroupId(), parentLayoutUuid);

    if ((parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) && (parentLayoutElement != null)) {

        StagedModelDataHandlerUtil.importStagedModel(portletDataContext, parentLayoutElement);

        Layout importedParentLayout = layouts.get(parentLayoutId);

        parentLayoutId = importedParentLayout.getLayoutId();
    }

    if (_log.isDebugEnabled()) {
        StringBundler sb = new StringBundler(4);

        sb.append("Importing layout with layout ID ");
        sb.append(layoutId);
        sb.append(" and parent layout ID ");
        sb.append(parentLayoutId);

        _log.debug(sb.toString());
    }

    importedLayout.setCompanyId(portletDataContext.getCompanyId());

    if (layout.getLayoutPrototypeUuid() != null) {
        importedLayout.setModifiedDate(new Date());
    }

    importedLayout.setParentLayoutId(parentLayoutId);
    importedLayout.setName(layout.getName());
    importedLayout.setTitle(layout.getTitle());
    importedLayout.setDescription(layout.getDescription());
    importedLayout.setKeywords(layout.getKeywords());
    importedLayout.setRobots(layout.getRobots());
    importedLayout.setType(layout.getType());

    String portletsMergeMode = MapUtil.getString(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.PORTLETS_MERGE_MODE, PortletDataHandlerKeys.PORTLETS_MERGE_MODE_REPLACE);

    if (Objects.equals(layout.getType(), LayoutConstants.TYPE_PORTLET)
            && Validator.isNotNull(layout.getTypeSettings())
            && !portletsMergeMode.equals(PortletDataHandlerKeys.PORTLETS_MERGE_MODE_REPLACE)) {

        mergePortlets(importedLayout, layout.getTypeSettings(), portletsMergeMode);
    } else if (Objects.equals(layout.getType(), LayoutConstants.TYPE_LINK_TO_LAYOUT)) {

        importLinkedLayout(portletDataContext, layout, importedLayout, layoutElement);

        updateTypeSettings(importedLayout, layout);
    } else {
        updateTypeSettings(importedLayout, layout);
    }

    importedLayout.setHidden(layout.isHidden());
    importedLayout.setFriendlyURL(getUniqueFriendlyURL(portletDataContext, importedLayout, friendlyURL));

    if (layout.getIconImageId() > 0) {
        importLayoutIconImage(portletDataContext, importedLayout, layoutElement);
    } else if (importedLayout.getIconImageId() > 0) {
        _imageLocalService.deleteImage(importedLayout.getIconImageId());

        importedLayout.setIconImageId(0);
    }

    if (existingLayout == null) {
        try {
            final long finalParentLayoutId = parentLayoutId;

            int priority = TransactionInvokerUtil.invoke(_transactionConfig, new Callable<Integer>() {

                @Override
                public Integer call() throws Exception {
                    return _layoutLocalServiceHelper.getNextPriority(groupId, privateLayout,
                            finalParentLayoutId, null, -1);
                }

            });

            importedLayout.setPriority(priority);
        } catch (Throwable t) {
            ReflectionUtil.throwException(t);
        }
    }

    importedLayout.setLayoutPrototypeUuid(layout.getLayoutPrototypeUuid());
    importedLayout.setLayoutPrototypeLinkEnabled(layout.isLayoutPrototypeLinkEnabled());

    ServiceContext serviceContext = portletDataContext.createServiceContext(layout);

    importedLayout.setExpandoBridgeAttributes(serviceContext);

    _staging.updateLastImportSettings(layoutElement, importedLayout, portletDataContext);

    fixImportTypeSettings(importedLayout);

    importTheme(portletDataContext, layout, importedLayout);

    _layoutLocalService.updateLayout(importedLayout);

    _layoutSetLocalService.updatePageCount(groupId, privateLayout);

    Map<Long, Long> layoutPlids = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class);

    layoutPlids.put(layout.getPlid(), importedLayout.getPlid());

    layouts.put(oldLayoutId, importedLayout);

    if (Objects.equals(layout.getType(), LayoutConstants.TYPE_PORTLET)
            && Validator.isNotNull(layout.getTypeSettings())) {

        importLayoutPortlets(portletDataContext, importedLayout, layoutElement);
    }

    importAssets(portletDataContext, layout, importedLayout);

    importLayoutFriendlyURLs(portletDataContext, layout, importedLayout);

    portletDataContext.importClassedModel(layout, importedLayout);
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected void importLayoutFriendlyURLs(PortletDataContext portletDataContext, Layout layout,
        Layout importedLayout) throws Exception {

    List<Element> layoutFriendlyURLElements = portletDataContext.getReferenceDataElements(layout,
            LayoutFriendlyURL.class);

    for (Element layoutFriendlyURLElement : layoutFriendlyURLElements) {
        String layoutFriendlyURLPath = layoutFriendlyURLElement.attributeValue("path");

        LayoutFriendlyURL layoutFriendlyURL = (LayoutFriendlyURL) portletDataContext
                .getZipEntryAsObject(layoutFriendlyURLPath);

        StagedModelDataHandlerUtil.importStagedModel(portletDataContext, layoutFriendlyURL);
    }//from  w w w  .j av  a2s  .c o m

    deleteMissingLayoutFriendlyURLs(portletDataContext, importedLayout);
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected void importLayoutPortlets(PortletDataContext portletDataContext, Layout layout, Element layoutElement)
        throws Exception {

    boolean layoutSetPrototypeLinkEnabled = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.LAYOUT_SET_PROTOTYPE_LINK_ENABLED);

    if (layoutSetPrototypeLinkEnabled && Validator.isNotNull(portletDataContext.getLayoutSetPrototypeUuid())
            && SitesUtil.isLayoutModifiedSinceLastMerge(layout)) {

        return;/*from   w  ww  . ja  v a 2s .  c  om*/
    }

    Map<String, String[]> parameterMap = portletDataContext.getParameterMap();

    boolean permissions = MapUtil.getBoolean(parameterMap, PortletDataHandlerKeys.PERMISSIONS);

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    LayoutCache layoutCache = new LayoutCache();

    Element portletsElement = layoutElement.element("portlets");

    if (portletsElement == null) {

        // See LPS-75448

        return;
    }

    for (Element portletElement : portletsElement.elements()) {
        String portletPath = portletElement.attributeValue("path");
        String portletId = portletElement.attributeValue("portlet-id");
        long oldPlid = GetterUtil.getLong(portletElement.attributeValue("old-plid"));

        Portlet portlet = _portletLocalService.getPortletById(portletDataContext.getCompanyId(), portletId);

        if (!portlet.isActive() || portlet.isUndeployedPortlet()) {
            continue;
        }

        portletDataContext.setPlid(layout.getPlid());
        portletDataContext.setOldPlid(oldPlid);
        portletDataContext.setPortletId(portletId);

        if (BackgroundTaskThreadLocal.hasBackgroundTask()) {
            _portletDataHandlerStatusMessageSender.sendStatusMessage("portlet", portletId,
                    portletDataContext.getManifestSummary());
        }

        Document portletDocument = SAXReaderUtil.read(portletDataContext.getZipEntryAsString(portletPath));

        portletElement = portletDocument.getRootElement();

        // The order of the import is important. You must always import the
        // portlet preferences first, then the portlet data, then the
        // portlet permissions. The import of the portlet data assumes that
        // portlet preferences already exist.

        _exportImportHelper.setPortletScope(portletDataContext, portletElement);

        long portletPreferencesGroupId = portletDataContext.getGroupId();

        Element portletDataElement = portletElement.element("portlet-data");

        Map<String, Boolean> importPortletControlsMap = _exportImportHelper.getImportPortletControlsMap(
                portletDataContext.getCompanyId(), portletId, parameterMap, portletDataElement,
                portletDataContext.getManifestSummary());

        if (layout != null) {
            portletPreferencesGroupId = layout.getGroupId();
        }

        try {
            _exportImportLifecycleManager.fireExportImportLifecycleEvent(EVENT_PORTLET_IMPORT_STARTED,
                    getProcessFlag(), portletDataContext.getExportImportProcessId(),
                    _portletDataContextFactory.clonePortletDataContext(portletDataContext));

            // Portlet preferences

            _portletImportController.importPortletPreferences(portletDataContext,
                    portletDataContext.getCompanyId(), portletPreferencesGroupId, layout, portletElement, false,
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES));

            // Portlet data

            if (importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA)) {

                _portletImportController.importPortletData(portletDataContext, portletDataElement);
            }

            _exportImportLifecycleManager.fireExportImportLifecycleEvent(EVENT_PORTLET_IMPORT_SUCCEEDED,
                    getProcessFlag(), portletDataContext.getExportImportProcessId(),
                    _portletDataContextFactory.clonePortletDataContext(portletDataContext));
        } catch (Throwable t) {
            _exportImportLifecycleManager.fireExportImportLifecycleEvent(EVENT_PORTLET_IMPORT_FAILED,
                    getProcessFlag(), portletDataContext.getExportImportProcessId(),
                    _portletDataContextFactory.clonePortletDataContext(portletDataContext), t);

            throw t;
        } finally {
            _portletImportController.resetPortletScope(portletDataContext, portletPreferencesGroupId);
        }

        // Portlet permissions

        if (permissions) {
            _permissionImporter.importPortletPermissions(layoutCache, portletDataContext.getCompanyId(),
                    portletDataContext.getGroupId(), serviceContext.getUserId(), layout, portletElement,
                    portletId);
        }

        // Archived setups

        try {
            _portletImportController.importPortletPreferences(portletDataContext,
                    portletDataContext.getCompanyId(), portletDataContext.getGroupId(), null, portletElement,
                    false, importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_ARCHIVED_SETUPS),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_DATA),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_SETUP),
                    importPortletControlsMap.get(PortletDataHandlerKeys.PORTLET_USER_PREFERENCES));
        } catch (Throwable t) {
            throw t;
        } finally {
            _portletImportController.resetPortletScope(portletDataContext, portletPreferencesGroupId);
        }
    }
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java

License:Open Source License

protected void importLinkedLayout(PortletDataContext portletDataContext, Layout layout, Layout importedLayout,
        Element layoutElement) throws Exception {

    UnicodeProperties typeSettingsProperties = layout.getTypeSettingsProperties();

    long linkToLayoutId = GetterUtil
            .getLong(typeSettingsProperties.getProperty("linkToLayoutId", StringPool.BLANK));

    String linkedToLayoutUuid = layoutElement.attributeValue("linked-to-layout-uuid");

    if (Validator.isNull(linkedToLayoutUuid) || (linkToLayoutId <= 0)) {
        return;/*  ww  w  .j  a  v a2 s.  c  o m*/
    }

    _exportImportProcessCallbackRegistry.registerCallback(portletDataContext.getExportImportProcessId(),
            new ImportLinkedLayoutCallable(portletDataContext.getScopeGroupId(),
                    portletDataContext.isPrivateLayout(), importedLayout.getUuid(), linkedToLayoutUuid));
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.StagedThemeStagedModelDataHandler.java

License:Open Source License

@Override
public void importMissingReference(PortletDataContext portletDataContext, Element referenceElement)
        throws PortletDataException {

    boolean importThemeSettings = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.THEME_REFERENCE);

    if (!importThemeSettings) {
        return;/*ww w  .  jav  a 2s.  co  m*/
    }

    Map<String, String> themeIds = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(StagedTheme.class);

    String classPK = referenceElement.attributeValue("class-pk");

    themeIds.put(classPK, classPK);
}

From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.StagedThemeStagedModelDataHandler.java

License:Open Source License

@Override
public boolean validateReference(PortletDataContext portletDataContext, Element referenceElement) {

    boolean importThemeSettings = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.THEME_REFERENCE);

    if (!importThemeSettings) {
        return true;
    }/*from w w  w  . ja  va2 s  .  co  m*/

    String classPK = referenceElement.attributeValue("class-pk");

    List<Theme> themes = _themeLocalService.getThemes(portletDataContext.getCompanyId());

    for (Theme theme : themes) {
        String themeId = theme.getThemeId();

        if (themeId.equals(classPK)) {
            return true;
        }
    }

    return false;
}

From source file:com.liferay.layout.internal.exportimport.data.handler.StagedLayoutSetStagedModelDataHandler.java

License:Open Source License

protected void importLogo(PortletDataContext portletDataContext) {
    boolean logo = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.LOGO);

    if (!logo) {//from   w  w  w.  j a v  a  2s  .  co m
        return;
    }

    Element rootElement = portletDataContext.getImportDataRootElement();

    Element headerElement = rootElement.element("header");

    String logoPath = headerElement.attributeValue("logo-path");

    byte[] iconBytes = portletDataContext.getZipEntryAsByteArray(logoPath);

    try {
        if (ArrayUtil.isNotEmpty(iconBytes)) {
            _layoutSetLocalService.updateLogo(portletDataContext.getGroupId(),
                    portletDataContext.isPrivateLayout(), true, iconBytes);
        } else {
            _layoutSetLocalService.updateLogo(portletDataContext.getGroupId(),
                    portletDataContext.isPrivateLayout(), false, (File) null);
        }
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to import logo", pe);
        }
    }
}

From source file:com.liferay.layout.internal.exportimport.data.handler.StagedLayoutSetStagedModelDataHandler.java

License:Open Source License

protected void updateLayoutPriorities(PortletDataContext portletDataContext, List<Element> layoutElements,
        boolean privateLayout) {

    Map<Long, Layout> layouts = (Map<Long, Layout>) portletDataContext
            .getNewPrimaryKeysMap(Layout.class + ".layout");

    Map<Long, Integer> layoutPriorities = new HashMap<>();

    int maxPriority = Integer.MIN_VALUE;

    for (Element layoutElement : layoutElements) {
        String action = layoutElement.attributeValue(Constants.ACTION);

        if (action.equals(Constants.SKIP)) {

            // We only want to update priorites if there are no elements
            // with the SKIP action

            return;
        }/* ww w.j a v a 2 s  . c  om*/

        if (action.equals(Constants.ADD)) {
            long layoutId = GetterUtil.getLong(layoutElement.attributeValue("layout-id"));

            Layout layout = layouts.get(layoutId);

            // Layout might not have been imported due to a controlled
            // error. See SitesImpl#addMergeFailFriendlyURLLayout.

            if (layout == null) {
                continue;
            }

            int layoutPriority = GetterUtil.getInteger(layoutElement.attributeValue("layout-priority"));

            layoutPriorities.put(layout.getPlid(), layoutPriority);

            if (maxPriority < layoutPriority) {
                maxPriority = layoutPriority;
            }
        }
    }

    List<Layout> layoutSetLayouts = _layoutLocalService.getLayouts(portletDataContext.getGroupId(),
            privateLayout);

    for (Layout layout : layoutSetLayouts) {
        if (layoutPriorities.containsKey(layout.getPlid())) {
            layout.setPriority(layoutPriorities.get(layout.getPlid()));
        } else {
            layout.setPriority(++maxPriority);
        }

        _layoutLocalService.updateLayout(layout);
    }
}