@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); }
public Object getNewValue(Object oldValue) throws Exception { _type = null; _height = null; _width = null; _size = null; String text = (String) oldValue; byte[] bytes = (byte[]) Base64.stringToObject(text); try { Image image = ImageLocalServiceUtil.getImage(bytes); _type = image.getType(); _height = new Integer(image.getHeight()); _width = new Integer(image.getWidth()); _size = new Integer(image.getSize()); } catch (Exception e) { if (_log.isWarnEnabled()) { String imageId = (String) _imageIdColumn.getOldValue(); if (_log.isWarnEnabled()) { _log.warn("Unable to get image data for " + imageId + ": " + e.getMessage()); } } _type = ImageConstants.TYPE_NOT_AVAILABLE; _height = null; _width = null; _size = new Integer(bytes.length); } return oldValue; }
protected void writeImage(Image image, HttpServletRequest request, HttpServletResponse response) { if (image == null) { return; } String contentType = null; String type = image.getType(); if (!type.equals(ImageConstants.TYPE_NOT_AVAILABLE)) { contentType = MimeTypesUtil.getContentType("A." + type); response.setContentType(contentType); } String fileName = ParamUtil.getString(request, "fileName"); try { byte[] bytes = getImageBytes(request, image); if (Validator.isNotNull(fileName)) { ServletResponseUtil.sendFile(request, response, fileName, bytes, contentType); } else { ServletResponseUtil.write(response, bytes); } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } } }
@Override public String getSmallImageType() throws PortalException { if ((_smallImageType == null) && isSmallImage()) { Image smallImage = ImageLocalServiceUtil.getImage(getSmallImageId()); _smallImageType = smallImage.getType(); } return _smallImageType; }
public Image updateImage(long imageId, InputStream is) throws PortalException, SystemException { Image image = getImage(is); return updateImage( imageId, image.getTextObj(), image.getType(), image.getHeight(), image.getWidth(), image.getSize()); }
@Override public String getSmallImageType() throws PortalException, SystemException { if (_smallImageType == null) { Image smallImage = fetchSmallImage(); if (smallImage != null) { _smallImageType = smallImage.getType(); } } return _smallImageType; }
protected String getLayoutIconPath( PortletDataContext portletDataContext, Layout layout, Image image) { StringBundler sb = new StringBundler(5); sb.append(portletDataContext.getLayoutPath(layout.getLayoutId())); sb.append("/icons/"); sb.append(image.getImageId()); sb.append(StringPool.PERIOD); sb.append(image.getType()); return sb.toString(); }
public InputStream getImageAsStream(Image image) throws PortalException, SystemException { try { File file = getFile(image.getImageId(), image.getType()); if (!file.exists()) { throw new NoSuchFileException(file.getPath()); } return new FileInputStream(file); } catch (IOException ioe) { throw new SystemException(ioe); } }
public byte[] getImageAsBytes(Image image) throws PortalException, SystemException { try { File file = getFile(image.getImageId(), image.getType()); if (!file.exists()) { throw new NoSuchFileException(file.getPath()); } return FileUtil.getBytes(file); } catch (IOException ioe) { throw new SystemException(ioe); } }
protected void migrateFile(long repositoryId, long companyId, String name, Image image) throws Exception { InputStream is = _sourceHook.getImageAsStream(image); byte[] bytes = FileUtil.getBytes(is); if (name == null) { name = image.getImageId() + StringPool.PERIOD + image.getType(); } if (DLStoreUtil.hasFile(companyId, repositoryId, name)) { DLStoreUtil.deleteFile(companyId, repositoryId, name); } DLStoreUtil.addFile(companyId, repositoryId, name, false, bytes); }
protected Image toUnwrappedModel(Image image) { if (image instanceof ImageImpl) { return image; } ImageImpl imageImpl = new ImageImpl(); imageImpl.setNew(image.isNew()); imageImpl.setPrimaryKey(image.getPrimaryKey()); imageImpl.setImageId(image.getImageId()); imageImpl.setModifiedDate(image.getModifiedDate()); imageImpl.setText(image.getText()); imageImpl.setType(image.getType()); imageImpl.setHeight(image.getHeight()); imageImpl.setWidth(image.getWidth()); imageImpl.setSize(image.getSize()); return imageImpl; }
public void deleteImage(Image image) { File file = getFile(image.getImageId(), image.getType()); FileUtil.delete(file); }
@Override protected void doExportStagedModel(PortletDataContext portletDataContext, DDMTemplate template) throws Exception { Element dlFileEntryTypesElement = portletDataContext.getExportDataGroupElement(DLFileEntryType.class); Element dlFoldersElement = portletDataContext.getExportDataGroupElement(DLFolder.class); Element dlFileEntriesElement = portletDataContext.getExportDataGroupElement(DLFileEntry.class); Element dlFileRanksElement = portletDataContext.getExportDataGroupElement(DLFileRank.class); Element dlRepositoriesElement = portletDataContext.getExportDataGroupElement(Repository.class); Element dlRepositoryEntriesElement = portletDataContext.getExportDataGroupElement(RepositoryEntry.class); Element templateElement = portletDataContext.getExportDataStagedModelElement(template); if (template.isSmallImage()) { Image smallImage = ImageUtil.fetchByPrimaryKey(template.getSmallImageId()); if (Validator.isNotNull(template.getSmallImageURL())) { String smallImageURL = DDMPortletDataHandler.exportReferencedContent( portletDataContext, dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement, dlRepositoriesElement, dlRepositoryEntriesElement, templateElement, template.getSmallImageURL().concat(StringPool.SPACE)); template.setSmallImageURL(smallImageURL); } else if (smallImage != null) { String smallImagePath = StagedModelPathUtil.getPath( template, smallImage.getImageId() + StringPool.PERIOD + template.getSmallImageType()); templateElement.addAttribute("small-image-path", smallImagePath); template.setSmallImageType(smallImage.getType()); portletDataContext.addZipEntry(smallImagePath, smallImage.getTextObj()); } } if (portletDataContext.getBooleanParameter( DDMPortletDataHandler.NAMESPACE, "embedded-assets")) { String content = DDMPortletDataHandler.exportReferencedContent( portletDataContext, dlFileEntryTypesElement, dlFoldersElement, dlFileEntriesElement, dlFileRanksElement, dlRepositoriesElement, dlRepositoryEntriesElement, templateElement, template.getScript()); template.setScript(content); } portletDataContext.addClassedModel( templateElement, StagedModelPathUtil.getPath(template), template, DDMPortletDataHandler.NAMESPACE); }
protected void migrateImage( long fileEntryId, long companyId, long groupId, long folderId, String name, long smallImageId, long largeImageId, long custom1ImageId, long custom2ImageId) throws Exception { Image largeImage = null; if (largeImageId != 0) { largeImage = ImageLocalServiceUtil.getImage(largeImageId); long repositoryId = DLFolderConstants.getDataRepositoryId(groupId, folderId); try { migrateFile(repositoryId, companyId, name, largeImage); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Ignoring exception for image " + largeImageId, e); } } } long thumbnailImageId = 0; if (smallImageId != 0) { thumbnailImageId = smallImageId; } else if (custom1ImageId != 0) { thumbnailImageId = custom1ImageId; } else if (custom2ImageId != 0) { thumbnailImageId = custom2ImageId; } Image thumbnailImage = null; if (thumbnailImageId != 0) { thumbnailImage = ImageLocalServiceUtil.getImage(thumbnailImageId); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { InputStream is = _sourceHook.getImageAsStream(thumbnailImage); con = DataAccess.getConnection(); ps = con.prepareStatement( "select max(fileVersionId) from DLFileVersion where " + "fileEntryId = " + fileEntryId); rs = ps.executeQuery(); if (rs.next()) { long fileVersionId = rs.getLong(1); ImageProcessorUtil.storeThumbnail( companyId, groupId, fileEntryId, fileVersionId, custom1ImageId, custom2ImageId, is, thumbnailImage.getType()); } } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Ignoring exception for image " + thumbnailImageId, e); } } finally { DataAccess.cleanUp(con, ps, rs); } } if (largeImageId != 0) { _sourceHook.deleteImage(largeImage); runSQL("delete from Image where imageId = " + largeImageId); } if ((largeImageId != thumbnailImageId) && (thumbnailImageId != 0)) { _sourceHook.deleteImage(thumbnailImage); runSQL("delete from Image where imageId = " + thumbnailImageId); } }