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); } deleteMissingLayoutFriendlyURLs(portletDataContext, importedLayout); }
protected void importKBArticleAttachments( PortletDataContext portletDataContext, KBArticle kbArticle, KBArticle importedKBArticle) throws Exception { List<Element> dlFileEntryElements = portletDataContext.getReferenceDataElements(kbArticle, DLFileEntry.class); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(portletDataContext.getCompanyId()); serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId()); InputStream inputStream = null; for (Element dlFileEntryElement : dlFileEntryElements) { try { byte[] bytes = portletDataContext.getZipEntryAsByteArray(dlFileEntryElement.attributeValue("path")); inputStream = new UnsyncByteArrayInputStream(bytes); String fileName = dlFileEntryElement.attributeValue("file-name"); String mimeType = KnowledgeBaseUtil.getMimeType(bytes, fileName); PortletFileRepositoryUtil.addPortletFileEntry( portletDataContext.getScopeGroupId(), portletDataContext.getUserId(importedKBArticle.getUserUuid()), KBArticle.class.getName(), importedKBArticle.getClassPK(), PortletKeys.KNOWLEDGE_BASE_ADMIN, importedKBArticle.getAttachmentsFolderId(), inputStream, fileName, mimeType, true); } catch (DuplicateFileException dfe) { continue; } finally { StreamUtil.cleanUp(inputStream); } } }
@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); }