protected void importLayoutIconImage( PortletDataContext portletDataContext, Layout importedLayout, Element layoutElement) throws Exception { String iconImagePath = layoutElement.elementText("icon-image-path"); byte[] iconBytes = portletDataContext.getZipEntryAsByteArray(iconImagePath); if (ArrayUtil.isNotEmpty(iconBytes)) { if (importedLayout.getIconImageId() == 0) { long iconImageId = _counterLocalService.increment(); importedLayout.setIconImageId(iconImageId); } _imageLocalService.updateImage(importedLayout.getIconImageId(), iconBytes); } }
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); } } }