Example usage for com.liferay.portal.kernel.model Group isStagedPortlet

List of usage examples for com.liferay.portal.kernel.model Group isStagedPortlet

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.model Group isStagedPortlet.

Prototype

public boolean isStagedPortlet(String portletId);

Source Link

Usage

From source file:com.liferay.asset.publisher.internal.util.AssetPublisherHelperImpl.java

License:Open Source License

@Override
public List<AssetEntry> getAssetEntries(PortletRequest portletRequest, PortletPreferences portletPreferences,
        PermissionChecker permissionChecker, long[] groupIds, boolean deleteMissingAssetEntries,
        boolean checkPermission, boolean includeNonVisibleAssets, int type) throws Exception {

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<AssetEntry> assetEntries = new ArrayList<>();

    List<String> missingAssetEntryUuids = new ArrayList<>();

    for (String assetEntryXml : assetEntryXmls) {
        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        String assetEntryType = rootElement.elementText("asset-entry-type");

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntryType);

        String portletId = assetRendererFactory.getPortletId();

        AssetEntry assetEntry = null;/*from  w  w w. j a  v a 2 s  .  c o  m*/

        for (long groupId : groupIds) {
            Group group = _groupLocalService.fetchGroup(groupId);

            if (group.isStagingGroup() && !group.isStagedPortlet(portletId)) {

                groupId = group.getLiveGroupId();
            }

            assetEntry = _assetEntryLocalService.fetchEntry(groupId, assetEntryUuid);

            if (assetEntry != null) {
                break;
            }
        }

        if (assetEntry == null) {
            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (!assetEntry.isVisible() && !includeNonVisibleAssets) {
            continue;
        }

        assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(), type);

        if (!assetRendererFactory.isActive(permissionChecker.getCompanyId())) {

            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (checkPermission) {
            if (!assetRenderer.isDisplayable() && !includeNonVisibleAssets) {

                continue;
            } else if (!assetRenderer.hasViewPermission(permissionChecker)) {
                assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(),
                        AssetRendererFactory.TYPE_LATEST_APPROVED);

                if (!assetRenderer.hasViewPermission(permissionChecker)) {
                    continue;
                }
            }
        }

        assetEntries.add(assetEntry);
    }

    if (deleteMissingAssetEntries) {
        _removeAndStoreSelection(missingAssetEntryUuids, portletPreferences);

        if (!missingAssetEntryUuids.isEmpty()) {
            SessionMessages.add(portletRequest, "deletedMissingAssetEntries", missingAssetEntryUuids);
        }
    }

    return assetEntries;
}

From source file:com.liferay.asset.publisher.web.internal.portlet.toolbar.contributor.AssetPublisherPortletToolbarContributor.java

License:Open Source License

private URLMenuItem _getPortletTitleAddAssetEntryMenuItem(ThemeDisplay themeDisplay,
        AssetPublisherDisplayContext assetPublisherDisplayContext, long groupId,
        AssetPublisherAddItemHolder assetPublisherAddItemHolder) {

    URLMenuItem urlMenuItem = new URLMenuItem();

    Map<String, Object> data = new HashMap<>();

    PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

    data.put("id", HtmlUtil.escape(portletDisplay.getNamespace()) + "editAsset");

    String message = assetPublisherAddItemHolder.getModelResource();

    String title = LanguageUtil.format(themeDisplay.getLocale(), "new-x", message, false);

    data.put("title", title);

    urlMenuItem.setData(data);/*w w  w .  j  a  va  2 s  . co  m*/

    urlMenuItem.setLabel(HtmlUtil.escape(message));

    long curGroupId = groupId;

    Group group = _groupLocalService.fetchGroup(groupId);

    if (!group.isStagedPortlet(assetPublisherAddItemHolder.getPortletId()) && !group.isStagedRemotely()) {

        curGroupId = group.getLiveGroupId();
    }

    boolean addDisplayPageParameter = _assetPublisherWebUtil.isDefaultAssetPublisher(themeDisplay.getLayout(),
            portletDisplay.getId(), assetPublisherDisplayContext.getPortletResource());

    String url = _assetHelper.getAddURLPopUp(curGroupId, themeDisplay.getPlid(),
            assetPublisherAddItemHolder.getPortletURL(), addDisplayPageParameter, themeDisplay.getLayout());

    urlMenuItem.setURL(url);

    urlMenuItem.setUseDialog(true);

    return urlMenuItem;
}

From source file:com.liferay.asset.publisher.web.util.AssetPublisherUtil.java

License:Open Source License

public static List<AssetEntry> getAssetEntries(PortletRequest portletRequest,
        PortletPreferences portletPreferences, PermissionChecker permissionChecker, long[] groupIds,
        boolean deleteMissingAssetEntries, boolean checkPermission, boolean includeNonVisibleAssets, int type)
        throws Exception {

    String[] assetEntryXmls = portletPreferences.getValues("assetEntryXml", new String[0]);

    List<AssetEntry> assetEntries = new ArrayList<>();

    List<String> missingAssetEntryUuids = new ArrayList<>();

    for (String assetEntryXml : assetEntryXmls) {
        Document document = SAXReaderUtil.read(assetEntryXml);

        Element rootElement = document.getRootElement();

        String assetEntryUuid = rootElement.elementText("asset-entry-uuid");

        String assetEntryType = rootElement.elementText("asset-entry-type");

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntryType);

        String portletId = assetRendererFactory.getPortletId();

        AssetEntry assetEntry = null;// w ww .ja v a  2 s . c  o m

        for (long groupId : groupIds) {
            Group group = _groupLocalService.fetchGroup(groupId);

            if (group.isStagingGroup() && !group.isStagedPortlet(portletId)) {

                groupId = group.getLiveGroupId();
            }

            assetEntry = _assetEntryLocalService.fetchEntry(groupId, assetEntryUuid);

            if (assetEntry != null) {
                break;
            }
        }

        if (assetEntry == null) {
            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (!assetEntry.isVisible() && !includeNonVisibleAssets) {
            continue;
        }

        assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(assetEntry.getClassName());

        AssetRenderer<?> assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(), type);

        if (!assetRendererFactory.isActive(permissionChecker.getCompanyId())) {

            if (deleteMissingAssetEntries) {
                missingAssetEntryUuids.add(assetEntryUuid);
            }

            continue;
        }

        if (checkPermission) {
            if (!assetRenderer.isDisplayable() && !includeNonVisibleAssets) {

                continue;
            } else if (!assetRenderer.hasViewPermission(permissionChecker)) {
                assetRenderer = assetRendererFactory.getAssetRenderer(assetEntry.getClassPK(),
                        AssetRendererFactory.TYPE_LATEST_APPROVED);

                if (!assetRenderer.hasViewPermission(permissionChecker)) {
                    continue;
                }
            }
        }

        assetEntries.add(assetEntry);
    }

    if (deleteMissingAssetEntries) {
        removeAndStoreSelection(missingAssetEntryUuids, portletPreferences);

        if (!missingAssetEntryUuids.isEmpty()) {
            SessionMessages.add(portletRequest, "deletedMissingAssetEntries", missingAssetEntryUuids);
        }
    }

    return assetEntries;
}

From source file:com.liferay.asset.taglib.internal.display.context.InputAssetLinksDisplayContext.java

License:Open Source License

private long _getAssetBrowserGroupId(AssetRendererFactory<?> assetRendererFactory) {

    Group scopeGroup = _themeDisplay.getScopeGroup();

    long groupId = scopeGroup.getGroupId();

    if (_isStagedLocally() && scopeGroup.isStagingGroup()) {
        boolean stagedReferencePortlet = scopeGroup.isStagedPortlet(assetRendererFactory.getPortletId());

        if (_isStagedReferrerPortlet() && !stagedReferencePortlet) {
            groupId = scopeGroup.getLiveGroupId();
        }//from   w ww.j a v  a  2s . c o  m
    }

    return groupId;
}

From source file:com.liferay.asset.taglib.internal.display.context.InputAssetLinksDisplayContext.java

License:Open Source License

private boolean _isStagedReferrerPortlet() {
    if (_stagedReferrerPortlet != null) {
        return _stagedReferrerPortlet;
    }/* w w  w.jav  a2s. c  o m*/

    if (_isStagedLocally()) {
        String className = (String) _request.getAttribute("liferay-asset:input-asset-links:className");

        AssetRendererFactory<?> assetRendererFactory = AssetRendererFactoryRegistryUtil
                .getAssetRendererFactoryByClassName(className);

        Group scopeGroup = _themeDisplay.getScopeGroup();

        _stagedReferrerPortlet = scopeGroup.isStagedPortlet(assetRendererFactory.getPortletId());
    } else {
        _stagedReferrerPortlet = false;
    }

    return _stagedReferrerPortlet;
}

From source file:com.liferay.exportimport.changeset.web.internal.portlet.action.ExportImportEntityMVCActionCommand.java

License:Open Source License

private void _processExportAndPublishAction(ActionRequest actionRequest, ActionResponse actionResponse)
        throws IOException, PortalException {

    String[] exportingEntities;//ww  w  . j  av a  2 s  .  c  om

    if (Validator.isNotNull(actionRequest.getParameter("exportingEntities"))) {

        exportingEntities = ParamUtil.getStringValues(actionRequest, "exportingEntities");
    } else if (Validator.isNotNull(actionRequest.getParameter("classNameId"))
            && Validator.isNotNull(actionRequest.getParameter("uuid"))) {

        long classNameId = ParamUtil.getLong(actionRequest, "classNameId");
        long groupId = ParamUtil.getLong(actionRequest, "groupId");
        String uuid = ParamUtil.getString(actionRequest, "uuid");

        StringBundler sb = new StringBundler(5);

        sb.append(classNameId);
        sb.append(StringPool.POUND);
        sb.append(groupId);
        sb.append(StringPool.POUND);
        sb.append(uuid);

        exportingEntities = new String[] { sb.toString() };
    } else {
        SessionErrors.add(actionRequest, ExportImportEntityException.class,
                new ExportImportEntityException(ExportImportEntityException.TYPE_NO_DATA_FOUND));

        return;
    }

    Map<String, String[]> parameterMap = ExportImportConfigurationParameterMapFactory.buildParameterMap();

    parameterMap.put("exportingEntities", exportingEntities);

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    String cmd = ParamUtil.getString(actionRequest, "cmd");

    String portletId = MapUtil.getString(actionRequest.getParameterMap(), "portletId");

    Portlet portlet = _portletLocalService.getPortletById(portletId);

    long backgroundTaskId = 0;

    if (cmd.equals(Constants.EXPORT)) {
        Map<String, Serializable> settingsMap = ExportImportConfigurationSettingsMapFactory
                .buildExportPortletSettingsMap(themeDisplay.getUser(), themeDisplay.getPlid(),
                        themeDisplay.getScopeGroupId(), ChangesetPortletKeys.CHANGESET, parameterMap,
                        _exportImportHelper.getPortletExportFileName(portlet));

        ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
                .addDraftExportImportConfiguration(themeDisplay.getUserId(), portletId,
                        ExportImportConfigurationConstants.TYPE_EXPORT_PORTLET, settingsMap);

        backgroundTaskId = _exportImportLocalService
                .exportPortletInfoAsFileInBackground(themeDisplay.getUserId(), exportImportConfiguration);
    } else if (cmd.equals(Constants.PUBLISH)) {
        Group scopeGroup = themeDisplay.getScopeGroup();

        if (!scopeGroup.isStagingGroup() && !scopeGroup.isStagedRemotely()) {

            SessionErrors.add(actionRequest, ExportImportEntityException.class,
                    new ExportImportEntityException(ExportImportEntityException.TYPE_GROUP_NOT_STAGED));

            return;
        }

        if (!scopeGroup.isStagedPortlet(portletId)) {
            SessionErrors.add(actionRequest, ExportImportEntityException.class,
                    new ExportImportEntityException(ExportImportEntityException.TYPE_PORTLET_NOT_STAGED));

            return;
        }

        long liveGroupId = 0;

        if (scopeGroup.isStagingGroup()) {
            liveGroupId = scopeGroup.getLiveGroupId();
        } else if (scopeGroup.isStagedRemotely()) {
            liveGroupId = scopeGroup.getRemoteLiveGroupId();
        }

        Map<String, Serializable> settingsMap = ExportImportConfigurationSettingsMapFactory
                .buildPublishPortletSettingsMap(themeDisplay.getUser(), themeDisplay.getScopeGroupId(),
                        themeDisplay.getPlid(), liveGroupId, themeDisplay.getPlid(),
                        ChangesetPortletKeys.CHANGESET, parameterMap);

        ExportImportConfiguration exportImportConfiguration = _exportImportConfigurationLocalService
                .addDraftExportImportConfiguration(themeDisplay.getUserId(), portletId,
                        ExportImportConfigurationConstants.TYPE_PUBLISH_PORTLET, settingsMap);

        backgroundTaskId = _staging.publishPortlet(themeDisplay.getUserId(), exportImportConfiguration);
    }

    sendRedirect(actionRequest, actionResponse, backgroundTaskId);
}

From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java

License:Open Source License

protected String replaceExportDLReferences(PortletDataContext portletDataContext, StagedModel stagedModel,
        String content, boolean exportReferencedContent) throws Exception {

    Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getGroupId());

    if (group.isStagingGroup()) {
        group = group.getLiveGroup();/* ww  w.  j  a  v  a2  s .  c  o m*/
    }

    if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {

        return content;
    }

    StringBuilder sb = new StringBuilder(content);

    String contextPath = PortalUtil.getPathContext();

    String[] patterns = { contextPath.concat("/c/document_library/get_file?"),
            contextPath.concat("/documents/"), contextPath.concat("/image/image_gallery?") };

    int beginPos = -1;
    int endPos = content.length();

    while (true) {
        beginPos = StringUtil.lastIndexOfAny(content, patterns, endPos);

        if (beginPos == -1) {
            break;
        }

        Map<String, String[]> dlReferenceParameters = getDLReferenceParameters(
                portletDataContext.getScopeGroupId(), content, beginPos + contextPath.length(), endPos);

        FileEntry fileEntry = getFileEntry(dlReferenceParameters);

        if (fileEntry == null) {
            endPos = beginPos - 1;

            continue;
        }

        endPos = MapUtil.getInteger(dlReferenceParameters, "endPos");

        try {
            if (exportReferencedContent && !fileEntry.isInTrash()) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedModel,
                        fileEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
            } else {
                Element entityElement = portletDataContext.getExportDataElement(stagedModel);

                String referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY;

                if (fileEntry.isInTrash()) {
                    referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE;
                }

                portletDataContext.addReferenceElement(stagedModel, entityElement, fileEntry, referenceType,
                        true);
            }

            String path = ExportImportPathUtil.getModelPath(fileEntry);

            StringBundler exportedReferenceSB = new StringBundler(6);

            exportedReferenceSB.append("[$dl-reference=");
            exportedReferenceSB.append(path);
            exportedReferenceSB.append("$]");

            if (fileEntry.isInTrash()) {
                String originalReference = sb.substring(beginPos, endPos);

                exportedReferenceSB.append("[#dl-reference=");
                exportedReferenceSB.append(originalReference);
                exportedReferenceSB.append("#]");
            }

            sb.replace(beginPos, endPos, exportedReferenceSB.toString());

            int deleteTimestampParametersOffset = beginPos;

            if (fileEntry.isInTrash()) {
                deleteTimestampParametersOffset = sb.indexOf("[#dl-reference=", beginPos);
            }

            deleteTimestampParameters(sb, deleteTimestampParametersOffset);
        } catch (Exception e) {
            if (_log.isDebugEnabled()) {
                _log.debug(e, e);
            } else if (_log.isWarnEnabled()) {
                StringBundler exceptionSB = new StringBundler(6);

                exceptionSB.append("Unable to process file entry ");
                exceptionSB.append(fileEntry.getFileEntryId());
                exceptionSB.append(" for staged model ");
                exceptionSB.append(stagedModel.getModelClassName());
                exceptionSB.append(" with primary key ");
                exceptionSB.append(stagedModel.getPrimaryKeyObj());

                _log.warn(exceptionSB.toString());
            }
        }

        endPos = beginPos - 1;
    }

    return sb.toString();
}

From source file:com.liferay.exportimport.controller.PortletExportController.java

License:Open Source License

public void exportPortletData(PortletDataContext portletDataContext, Portlet portlet, Layout layout,
        javax.portlet.PortletPreferences jxPortletPreferences, Element parentElement) throws Exception {

    if (portlet == null) {
        return;//from   ww  w .  j a  v a 2  s .  co m
    }

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    if ((portletDataHandler == null) || portletDataHandler.isDataPortletInstanceLevel()) {

        return;
    }

    Group group = _groupLocalService.getGroup(portletDataContext.getGroupId());

    long plid = LayoutConstants.DEFAULT_PLID;

    if (layout != null) {
        group = layout.getGroup();
        plid = layout.getPlid();
    }

    if (group.isStagingGroup()) {
        group = group.getLiveGroup();
    }

    String portletId = portlet.getPortletId();

    if (ExportImportThreadLocal.isStagingInProcess() && !group.isStagedPortlet(portletId)) {

        if (_log.isDebugEnabled()) {
            _log.debug("Not exporting data for " + portletId + " because it is configured not to be staged");
        }

        return;
    }

    if (_log.isDebugEnabled()) {
        _log.debug("Exporting data for " + portletId);
    }

    String path = ExportImportPathUtil.getPortletDataPath(portletDataContext);

    if (portletDataContext.hasPrimaryKey(String.class, path)) {
        return;
    }

    Date originalStartDate = portletDataContext.getStartDate();

    Date portletLastPublishDate = ExportImportDateUtil.getLastPublishDate(portletDataContext,
            jxPortletPreferences);

    portletDataContext.setStartDate(portletLastPublishDate);

    long groupId = portletDataContext.getGroupId();

    portletDataContext.setGroupId(portletDataContext.getScopeGroupId());

    portletDataContext.clearScopedPrimaryKeys();

    String data = null;

    try {
        data = portletDataHandler.exportData(portletDataContext, portletId, jxPortletPreferences);
    } finally {
        portletDataContext.setGroupId(groupId);
        portletDataContext.setStartDate(originalStartDate);
    }

    if (Validator.isNull(data)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Not exporting data for " + portletId + " because null data was returned");
        }

        return;
    }

    Element portletDataElement = parentElement.addElement("portlet-data");

    portletDataElement.addAttribute("path", path);

    portletDataContext.addZipEntry(path, data);

    boolean updateLastPublishDate = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (ExportImportThreadLocal.isStagingInProcess() && updateLastPublishDate) {

        DateRange adjustedDateRange = new DateRange(portletLastPublishDate, portletDataContext.getEndDate());

        _exportImportProcessCallbackRegistry.registerCallback(portletDataContext.getExportImportProcessId(),
                new UpdatePortletLastPublishDateCallable(adjustedDateRange, portletDataContext.getEndDate(),
                        portletDataContext.getGroupId(), plid, portletId));
    }
}

From source file:com.liferay.exportimport.controller.PortletImportController.java

License:Open Source License

protected String deletePortletData(PortletDataContext portletDataContext,
        javax.portlet.PortletPreferences portletPreferences) throws Exception {

    Group group = _groupLocalService.getGroup(portletDataContext.getGroupId());

    if (!group.isStagedPortlet(portletDataContext.getPortletId())) {
        if (_log.isDebugEnabled()) {
            _log.debug("Do not delete portlet data for portlet " + portletDataContext.getPortletId()
                    + " because the portlet is not staged");
        }/*from   ww  w.  j av a 2 s . c o m*/

        return null;
    }

    PortletDataHandler portletDataHandler = _portletDataHandlerProvider
            .provide(portletDataContext.getCompanyId(), portletDataContext.getPortletId());

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

            sb.append("Do not delete portlet data for portlet ");
            sb.append(portletDataContext.getPortletId());
            sb.append(" because the portlet does not have a ");
            sb.append("PortletDataHandler");

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

        return null;
    }

    if (_log.isDebugEnabled()) {
        _log.debug("Deleting data for portlet " + portletDataContext.getPortletId());
    }

    try {
        portletPreferences = portletDataHandler.deleteData(portletDataContext,
                portletDataContext.getPortletId(), portletPreferences);
    } finally {
        portletDataContext.setGroupId(portletDataContext.getScopeGroupId());
    }

    if (portletPreferences == null) {
        return null;
    }

    return PortletPreferencesFactoryUtil.toXML(portletPreferences);
}

From source file:com.liferay.exportimport.internal.content.processor.DLReferencesExportImportContentProcessor.java

License:Open Source License

protected String replaceExportDLReferences(PortletDataContext portletDataContext, StagedModel stagedModel,
        String content, boolean exportReferencedContent) throws Exception {

    Group group = _groupLocalService.getGroup(portletDataContext.getGroupId());

    if (group.isStagingGroup()) {
        group = group.getLiveGroup();//from   ww  w.  j  av a2s.c  o  m
    }

    if (group.isStaged() && !group.isStagedRemotely() && !group.isStagedPortlet(PortletKeys.DOCUMENT_LIBRARY)) {

        return content;
    }

    StringBuilder sb = new StringBuilder(content);

    String contextPath = _portal.getPathContext();

    String[] patterns = { contextPath.concat("/c/document_library/get_file?"),
            contextPath.concat("/documents/"), contextPath.concat("/image/image_gallery?") };

    int beginPos = -1;
    int endPos = content.length();

    while (true) {
        beginPos = StringUtil.lastIndexOfAny(content, patterns, endPos);

        if (beginPos == -1) {
            break;
        }

        Map<String, String[]> dlReferenceParameters = getDLReferenceParameters(
                portletDataContext.getScopeGroupId(), content, beginPos + contextPath.length(), endPos);

        FileEntry fileEntry = getFileEntry(dlReferenceParameters);

        if (fileEntry == null) {
            endPos = beginPos - 1;

            continue;
        }

        endPos = MapUtil.getInteger(dlReferenceParameters, "endPos");

        try {
            if (exportReferencedContent && !fileEntry.isInTrash()) {
                StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, stagedModel,
                        fileEntry, PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
            } else {
                Element entityElement = portletDataContext.getExportDataElement(stagedModel);

                String referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY;

                if (fileEntry.isInTrash()) {
                    referenceType = PortletDataContext.REFERENCE_TYPE_DEPENDENCY_DISPOSABLE;
                }

                portletDataContext.addReferenceElement(stagedModel, entityElement, fileEntry, referenceType,
                        true);
            }

            String path = ExportImportPathUtil.getModelPath(fileEntry);

            StringBundler exportedReferenceSB = new StringBundler(6);

            exportedReferenceSB.append("[$dl-reference=");
            exportedReferenceSB.append(path);
            exportedReferenceSB.append("$]");

            if (fileEntry.isInTrash()) {
                String originalReference = sb.substring(beginPos, endPos);

                exportedReferenceSB.append("[#dl-reference=");
                exportedReferenceSB.append(originalReference);
                exportedReferenceSB.append("#]");
            }

            sb.replace(beginPos, endPos, exportedReferenceSB.toString());

            int deleteTimestampParametersOffset = beginPos;

            if (fileEntry.isInTrash()) {
                deleteTimestampParametersOffset = sb.indexOf("[#dl-reference=", beginPos);
            }

            deleteTimestampParameters(sb, deleteTimestampParametersOffset);
        } catch (Exception e) {
            if (_log.isDebugEnabled()) {
                _log.debug(e, e);
            } else if (_log.isWarnEnabled()) {
                StringBundler exceptionSB = new StringBundler(6);

                exceptionSB.append("Unable to process file entry ");
                exceptionSB.append(fileEntry.getFileEntryId());
                exceptionSB.append(" for staged model ");
                exceptionSB.append(stagedModel.getModelClassName());
                exceptionSB.append(" with primary key ");
                exceptionSB.append(stagedModel.getPrimaryKeyObj());

                _log.warn(exceptionSB.toString());
            }
        }

        endPos = beginPos - 1;
    }

    return sb.toString();
}