@Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext,
      CalendarNotificationTemplate calendarNotificationTemplate)
      throws Exception {

    Calendar calendar =
        CalendarLocalServiceUtil.getCalendar(calendarNotificationTemplate.getCalendarId());

    StagedModelDataHandlerUtil.exportReferenceStagedModel(
        portletDataContext,
        calendarNotificationTemplate,
        calendar,
        PortletDataContext.REFERENCE_TYPE_STRONG);

    String body =
        ExportImportHelperUtil.replaceExportContentReferences(
            portletDataContext,
            calendarNotificationTemplate,
            calendarNotificationTemplate.getBody(),
            portletDataContext.getBooleanParameter(
                CalendarPortletDataHandler.NAMESPACE, "referenced-content"));

    calendarNotificationTemplate.setBody(body);

    Element calendarNotificationTemplateElement =
        portletDataContext.getExportDataElement(calendarNotificationTemplate);

    portletDataContext.addClassedModel(
        calendarNotificationTemplateElement,
        ExportImportPathUtil.getModelPath(calendarNotificationTemplate),
        calendarNotificationTemplate);
  }
  @Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext, DLFileEntryType fileEntryType) throws Exception {

    Element fileEntryTypeElement = portletDataContext.getExportDataElement(fileEntryType);

    List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
      com.liferay.dynamic.data.mapping.model.DDMStructure structure =
          _ddmStructureLocalService.getStructure(ddmStructure.getStructureId());

      Element referenceElement =
          StagedModelDataHandlerUtil.exportReferenceStagedModel(
              portletDataContext,
              fileEntryType,
              structure,
              PortletDataContext.REFERENCE_TYPE_STRONG);

      referenceElement.addAttribute(
          "structure-id", StringUtil.valueOf(ddmStructure.getStructureId()));
    }

    long defaultUserId = UserLocalServiceUtil.getDefaultUserId(fileEntryType.getCompanyId());

    if (defaultUserId == fileEntryType.getUserId()) {
      fileEntryTypeElement.addAttribute("preloaded", "true");
    }

    portletDataContext.addClassedModel(
        fileEntryTypeElement, ExportImportPathUtil.getModelPath(fileEntryType), fileEntryType);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, AssetTag assetTag)
      throws Exception {

    Element assetTagElement = portletDataContext.getExportDataElement(assetTag);

    portletDataContext.addClassedModel(
        assetTagElement, ExportImportPathUtil.getModelPath(assetTag), assetTag);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, Layout layout)
      throws Exception {

    if (layout.isTypeSharedPortlet()) {
      return;
    }

    Element layoutElement = portletDataContext.getExportDataElement(layout);

    populateElementLayoutMetadata(layoutElement, layout);

    layoutElement.addAttribute(Constants.ACTION, Constants.ADD);

    portletDataContext.setPlid(layout.getPlid());

    long parentLayoutId = layout.getParentLayoutId();

    if (parentLayoutId != LayoutConstants.DEFAULT_PARENT_LAYOUT_ID) {
      Layout parentLayout =
          _layoutLocalService.fetchLayout(
              layout.getGroupId(), layout.isPrivateLayout(), parentLayoutId);

      if (parentLayout != null) {
        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext, layout, parentLayout, PortletDataContext.REFERENCE_TYPE_PARENT);

        layoutElement.addAttribute("parent-layout-uuid", parentLayout.getUuid());
      }
    }

    List<LayoutFriendlyURL> layoutFriendlyURLs =
        _layoutFriendlyURLLocalService.getLayoutFriendlyURLs(layout.getPlid());

    for (LayoutFriendlyURL layoutFriendlyURL : layoutFriendlyURLs) {
      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext,
          layout,
          layoutFriendlyURL,
          PortletDataContext.REFERENCE_TYPE_DEPENDENCY);
    }

    if (layout.isIconImage()) {
      exportLayoutIconImage(portletDataContext, layout, layoutElement);
    }

    if (layout.isTypeLinkToLayout()) {
      exportLinkedLayout(portletDataContext, layout, layoutElement);
    }

    fixExportTypeSettings(layout);

    exportTheme(portletDataContext, layout);

    portletDataContext.addClassedModel(
        layoutElement, ExportImportPathUtil.getModelPath(layout), layout);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, UserGroup userGroup)
      throws Exception {

    Element userGroupElement = portletDataContext.getExportDataElement(userGroup);

    portletDataContext.addClassedModel(
        userGroupElement, ExportImportPathUtil.getModelPath(userGroup), userGroup);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, Website website)
      throws Exception {

    Element websiteElement = portletDataContext.getExportDataElement(website);

    portletDataContext.addClassedModel(
        websiteElement, ExportImportPathUtil.getModelPath(website), website);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, BlogsEntry entry)
      throws Exception {

    Element entryElement = portletDataContext.getExportDataElement(entry);

    if (entry.isSmallImage()) {
      Image smallImage = _imageLocalService.fetchImage(entry.getSmallImageId());

      if (smallImage != null) {
        String smallImagePath =
            ExportImportPathUtil.getModelPath(
                entry, smallImage.getImageId() + StringPool.PERIOD + smallImage.getType());

        entryElement.addAttribute("small-image-path", smallImagePath);

        entry.setSmallImageType(smallImage.getType());

        portletDataContext.addZipEntry(smallImagePath, smallImage.getTextObj());
      }
    }

    if (entry.getSmallImageFileEntryId() != 0) {
      FileEntry fileEntry =
          PortletFileRepositoryUtil.getPortletFileEntry(entry.getSmallImageFileEntryId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, entry, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK);
    }

    if (entry.getCoverImageFileEntryId() != 0) {
      FileEntry fileEntry =
          PortletFileRepositoryUtil.getPortletFileEntry(entry.getCoverImageFileEntryId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, entry, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK);
    }

    String content =
        _blogsEntryExportImportContentProcessor.replaceExportContentReferences(
            portletDataContext,
            entry,
            entry.getContent(),
            portletDataContext.getBooleanParameter("blogs", "referenced-content"),
            true);

    entry.setContent(content);

    portletDataContext.addClassedModel(
        entryElement, ExportImportPathUtil.getModelPath(entry), entry);
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, Calendar calendar)
      throws Exception {

    StagedModelDataHandlerUtil.exportReferenceStagedModel(
        portletDataContext,
        calendar,
        calendar.getCalendarResource(),
        PortletDataContext.REFERENCE_TYPE_STRONG);

    Element calendarElement = portletDataContext.getExportDataElement(calendar);

    portletDataContext.addClassedModel(
        calendarElement, ExportImportPathUtil.getModelPath(calendar), calendar);
  }
  @Override
  protected void doExportStagedModel(
      PortletDataContext portletDataContext, StagedAssetLink stagedAssetLink) throws Exception {

    Element stagedAssetLinkElement = portletDataContext.getExportDataElement(stagedAssetLink);

    AssetEntry assetEntry1 = _assetEntryLocalService.fetchEntry(stagedAssetLink.getEntryId1());

    addAssetReference(portletDataContext, stagedAssetLink, stagedAssetLinkElement, assetEntry1);

    AssetEntry assetEntry2 = _assetEntryLocalService.fetchEntry(stagedAssetLink.getEntryId2());

    addAssetReference(portletDataContext, stagedAssetLink, stagedAssetLinkElement, assetEntry2);

    portletDataContext.addClassedModel(
        stagedAssetLinkElement,
        ExportImportPathUtil.getModelPath(stagedAssetLink),
        stagedAssetLink);
  }
  protected void exportKBArticleAttachments(
      PortletDataContext portletDataContext, Element kbArticleElement, KBArticle kbArticle)
      throws Exception {

    List<FileEntry> attachmentsFileEntries = kbArticle.getAttachmentsFileEntries();

    for (FileEntry fileEntry : attachmentsFileEntries) {
      String path = ExportImportPathUtil.getModelPath(kbArticle, fileEntry.getTitle());

      Element fileEntryElement = portletDataContext.getExportDataElement(fileEntry);

      fileEntryElement.addAttribute("path", path);
      fileEntryElement.addAttribute("file-name", fileEntry.getTitle());

      portletDataContext.addZipEntry(path, fileEntry.getContentStream());

      portletDataContext.addReferenceElement(
          kbArticle, kbArticleElement, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK, false);
    }
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, KBArticle kbArticle)
      throws Exception {

    if (kbArticle.getParentResourcePrimKey() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      long kbArticleClassNameId = PortalUtil.getClassNameId(KBArticleConstants.getClassName());

      if (kbArticle.getParentResourceClassNameId() == kbArticleClassNameId) {

        KBArticle parentKBArticle =
            KBArticleLocalServiceUtil.getLatestKBArticle(
                kbArticle.getParentResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);

        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext,
            kbArticle,
            parentKBArticle,
            PortletDataContext.REFERENCE_TYPE_PARENT);
      } else {
        KBFolder parentKBFolder =
            KBFolderLocalServiceUtil.getKBFolder(kbArticle.getParentResourcePrimKey());

        StagedModelDataHandlerUtil.exportReferenceStagedModel(
            portletDataContext,
            kbArticle,
            parentKBFolder,
            PortletDataContext.REFERENCE_TYPE_PARENT);
      }
    }

    Element kbArticleElement = portletDataContext.getExportDataElement(kbArticle);

    exportKBArticleAttachments(portletDataContext, kbArticleElement, kbArticle);

    portletDataContext.addClassedModel(
        kbArticleElement, ExportImportPathUtil.getModelPath(kbArticle), kbArticle);
  }
  protected void exportTheme(PortletDataContext portletDataContext, Layout layout)
      throws Exception {

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

    if (_log.isDebugEnabled()) {
      _log.debug("Export theme settings " + exportThemeSettings);
    }

    if (exportThemeSettings
        && !portletDataContext.isPerformDirectBinaryImport()
        && !layout.isInheritLookAndFeel()) {

      StagedTheme stagedTheme = new StagedThemeImpl(layout.getTheme());

      Element layoutElement = portletDataContext.getExportDataElement(layout);

      portletDataContext.addReferenceElement(
          layout, layoutElement, stagedTheme, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true);
    }
  }
  @Override
  protected void doExportStagedModel(PortletDataContext portletDataContext, FileEntry fileEntry)
      throws Exception {

    Element fileEntryElement = portletDataContext.getExportDataElement(fileEntry);

    String fileEntryPath = ExportImportPathUtil.getModelPath(fileEntry);

    if (!fileEntry.isDefaultRepository()) {
      Repository repository = RepositoryLocalServiceUtil.getRepository(fileEntry.getRepositoryId());

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext, fileEntry, repository, PortletDataContext.REFERENCE_TYPE_STRONG);

      portletDataContext.addClassedModel(fileEntryElement, fileEntryPath, fileEntry);

      long portletRepositoryClassNameId =
          PortalUtil.getClassNameId(PortletRepository.class.getName());

      if (repository.getClassNameId() != portletRepositoryClassNameId) {
        return;
      }
    }

    if (fileEntry.getFolderId() != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

      StagedModelDataHandlerUtil.exportReferenceStagedModel(
          portletDataContext,
          fileEntry,
          fileEntry.getFolder(),
          PortletDataContext.REFERENCE_TYPE_PARENT);
    }

    LiferayFileEntry liferayFileEntry = (LiferayFileEntry) fileEntry;

    liferayFileEntry.setCachedFileVersion(fileEntry.getFileVersion());

    if (!portletDataContext.isPerformDirectBinaryImport()) {
      InputStream is = null;

      try {
        is = FileEntryUtil.getContentStream(fileEntry);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn("Unable to retrieve content for file entry " + fileEntry.getFileEntryId(), e);
        }
      }

      if (is == null) {
        fileEntryElement.detach();

        return;
      }

      try {
        String binPath = ExportImportPathUtil.getModelPath(fileEntry, fileEntry.getVersion());

        portletDataContext.addZipEntry(binPath, is);

        fileEntryElement.addAttribute("bin-path", binPath);
      } finally {
        try {
          is.close();
        } catch (IOException ioe) {
          _log.error(ioe, ioe);
        }
      }
    }

    if (portletDataContext.getBooleanParameter(
        DLPortletDataHandler.NAMESPACE, "previews-and-thumbnails")) {

      DLProcessorRegistryUtil.exportGeneratedFiles(portletDataContext, fileEntry, fileEntryElement);
    }

    exportMetaData(portletDataContext, fileEntryElement, fileEntry);

    portletDataContext.addClassedModel(
        fileEntryElement, fileEntryPath, liferayFileEntry, DLFileEntry.class);
  }