@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 doImportStagedModel(PortletDataContext portletDataContext, BlogsEntry entry) throws Exception { long userId = portletDataContext.getUserId(entry.getUserUuid()); Element entryElement = portletDataContext.getImportDataStagedModelElement(entry); String content = _blogsEntryExportImportContentProcessor.replaceImportContentReferences( portletDataContext, entry, entry.getContent()); entry.setContent(content); Calendar displayDateCal = CalendarFactoryUtil.getCalendar(); displayDateCal.setTime(entry.getDisplayDate()); int displayDateMonth = displayDateCal.get(Calendar.MONTH); int displayDateDay = displayDateCal.get(Calendar.DATE); int displayDateYear = displayDateCal.get(Calendar.YEAR); int displayDateHour = displayDateCal.get(Calendar.HOUR); int displayDateMinute = displayDateCal.get(Calendar.MINUTE); if (displayDateCal.get(Calendar.AM_PM) == Calendar.PM) { displayDateHour += 12; } boolean allowPingbacks = entry.isAllowPingbacks(); boolean allowTrackbacks = entry.isAllowTrackbacks(); String[] trackbacks = StringUtil.split(entry.getTrackbacks()); ServiceContext serviceContext = portletDataContext.createServiceContext(entry); BlogsEntry importedEntry = null; if (portletDataContext.isDataStrategyMirror()) { serviceContext.setAttribute("urlTitle", entry.getUrlTitle()); BlogsEntry existingEntry = fetchStagedModelByUuidAndGroupId(entry.getUuid(), portletDataContext.getScopeGroupId()); if (existingEntry == null) { serviceContext.setUuid(entry.getUuid()); importedEntry = _blogsEntryLocalService.addEntry( userId, entry.getTitle(), entry.getSubtitle(), entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, entry.getCoverImageCaption(), null, null, serviceContext); } else { importedEntry = _blogsEntryLocalService.updateEntry( userId, existingEntry.getEntryId(), entry.getTitle(), entry.getSubtitle(), entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, entry.getCoverImageCaption(), new ImageSelector(), new ImageSelector(), serviceContext); } } else { importedEntry = _blogsEntryLocalService.addEntry( userId, entry.getTitle(), entry.getSubtitle(), entry.getDescription(), entry.getContent(), displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks, allowTrackbacks, trackbacks, entry.getCoverImageCaption(), null, null, serviceContext); } if ((entry.getCoverImageFileEntryId() == 0) && Validator.isNull(entry.getCoverImageURL()) && (entry.getSmallImageFileEntryId() == 0) && Validator.isNull(entry.getSmallImageURL()) && !entry.isSmallImage()) { portletDataContext.importClassedModel(entry, importedEntry); return; } // Cover image ImageSelector coverImageSelector = null; List<Element> attachmentElements = portletDataContext.getReferenceDataElements( entry, DLFileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK); if (Validator.isNotNull(entry.getCoverImageURL())) { coverImageSelector = new ImageSelector(entry.getCoverImageURL()); } else if (entry.getCoverImageFileEntryId() != 0) { coverImageSelector = _getImageSelector( portletDataContext, entry.getCoverImageFileEntryId(), attachmentElements); } if (coverImageSelector != null) { _blogsEntryLocalService.addCoverImage(importedEntry.getEntryId(), coverImageSelector); } // Small image ImageSelector smallImageSelector = null; if (entry.isSmallImage()) { String smallImagePath = entryElement.attributeValue("small-image-path"); if (Validator.isNotNull(entry.getSmallImageURL())) { smallImageSelector = new ImageSelector(entry.getSmallImageURL()); } else if (Validator.isNotNull(smallImagePath)) { String smallImageFileName = entry.getSmallImageId() + StringPool.PERIOD + entry.getSmallImageType(); InputStream inputStream = null; try { inputStream = portletDataContext.getZipEntryAsInputStream(smallImagePath); smallImageSelector = new ImageSelector( FileUtil.getBytes(inputStream), smallImageFileName, MimeTypesUtil.getContentType(smallImageFileName), null); } finally { StreamUtil.cleanUp(inputStream); } } else if (entry.getSmallImageFileEntryId() != 0) { smallImageSelector = _getImageSelector( portletDataContext, entry.getSmallImageFileEntryId(), attachmentElements); } } if (smallImageSelector != null) { _blogsEntryLocalService.addSmallImage(importedEntry.getEntryId(), smallImageSelector); } if ((coverImageSelector != null) || (smallImageSelector != null)) { importedEntry = _blogsEntryLocalService.getBlogsEntry(importedEntry.getEntryId()); } portletDataContext.importClassedModel(entry, importedEntry); }