protected void exportPreviews( PortletDataContext portletDataContext, FileEntry fileEntry, Element fileEntryElement) throws Exception { FileVersion fileVersion = fileEntry.getFileVersion(); if (!isSupported(fileVersion) || !hasPreviews(fileVersion)) { return; } if (!portletDataContext.isPerformDirectBinaryImport()) { if ((_PREVIEW_TYPES.length == 0) || (_PREVIEW_TYPES.length > 2)) { return; } for (String previewType : _PREVIEW_TYPES) { if (previewType.equals("mp4") || previewType.equals("ogv")) { exportPreview(portletDataContext, fileEntry, fileEntryElement, "video", previewType); } } } }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, WikiPage page) throws Exception { long userId = portletDataContext.getUserId(page.getUserUuid()); Element pageElement = portletDataContext.getImportDataStagedModelElement(page); String content = _wikiPageExportImportContentProcessor.replaceImportContentReferences( portletDataContext, page, page.getContent()); page.setContent(content); ServiceContext serviceContext = portletDataContext.createServiceContext(page); serviceContext.setUuid(page.getUuid()); Map<Long, Long> nodeIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiNode.class); long nodeId = MapUtil.getLong(nodeIds, page.getNodeId(), page.getNodeId()); WikiPage importedPage = null; WikiPage existingPage = _wikiPageLocalService.fetchPage(nodeId, page.getTitle()); if (existingPage == null) { importedPage = _wikiPageLocalService.addPage( userId, nodeId, page.getTitle(), page.getVersion(), page.getContent(), page.getSummary(), page.isMinorEdit(), page.getFormat(), page.getHead(), page.getParentTitle(), page.getRedirectTitle(), serviceContext); WikiPageResource pageResource = _wikiPageResourceLocalService.getPageResource(importedPage.getResourcePrimKey()); String pageResourceUuid = GetterUtil.getString(pageElement.attributeValue("page-resource-uuid")); if (Validator.isNotNull(pageResourceUuid)) { pageResource.setUuid(pageElement.attributeValue("page-resource-uuid")); _wikiPageResourceLocalService.updateWikiPageResource(pageResource); } } else { existingPage = fetchStagedModelByUuidAndGroupId(page.getUuid(), portletDataContext.getScopeGroupId()); if (existingPage == null) { existingPage = _wikiPageLocalService.fetchPage(nodeId, page.getTitle(), page.getVersion()); } if (existingPage == null) { importedPage = _wikiPageLocalService.updatePage( userId, nodeId, page.getTitle(), 0.0, page.getContent(), page.getSummary(), page.isMinorEdit(), page.getFormat(), page.getParentTitle(), page.getRedirectTitle(), serviceContext); } else { importedPage = existingPage; } } if (page.isHead()) { List<Element> attachmentElements = portletDataContext.getReferenceDataElements( pageElement, DLFileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK); for (Element attachmentElement : attachmentElements) { String path = attachmentElement.attributeValue("path"); FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path); InputStream inputStream = null; try { String binPath = attachmentElement.attributeValue("bin-path"); if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) { try { inputStream = FileEntryUtil.getContentStream(fileEntry); } catch (NoSuchFileException nsfe) { } } else { inputStream = portletDataContext.getZipEntryAsInputStream(binPath); } if (inputStream == null) { if (_log.isWarnEnabled()) { _log.warn("Unable to import attachment for file entry " + fileEntry.getFileEntryId()); } continue; } _wikiPageLocalService.addPageAttachment( userId, importedPage.getNodeId(), importedPage.getTitle(), fileEntry.getTitle(), inputStream, null); } finally { StreamUtil.cleanUp(inputStream); } } } portletDataContext.importClassedModel(page, importedPage); Map<Long, Long> pageIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(WikiPage.class + ".pageId"); pageIds.put(page.getPageId(), importedPage.getPageId()); }