public Image updateImage(long imageId, byte[] bytes, String type, int height, int width, int size) throws PortalException, SystemException { Image image = imagePersistence.fetchByPrimaryKey(imageId); if (image == null) { image = imagePersistence.create(imageId); } image.setModifiedDate(new Date()); image.setType(type); image.setHeight(height); image.setWidth(width); image.setSize(size); Hook hook = HookFactory.getInstance(); hook.updateImage(image, type, bytes); imagePersistence.update(image, false); ImageServletTokenUtil.resetToken(imageId); return image; }
protected void format( long groupId, String articleId, double version, String previewArticleId, Element root, UploadServletRequest uploadRequest) throws Exception { Iterator<Element> itr = root.elements().iterator(); while (itr.hasNext()) { Element el = itr.next(); Element dynamicContent = el.element("dynamic-content"); String elInstanceId = el.attributeValue("instance-id", StringPool.BLANK); String elName = el.attributeValue("name", StringPool.BLANK); String elType = el.attributeValue("type", StringPool.BLANK); String elContent = StringPool.BLANK; String elLanguage = StringPool.BLANK; if (dynamicContent != null) { elContent = dynamicContent.getTextTrim(); elLanguage = dynamicContent.attributeValue("language-id", StringPool.BLANK); if (!elLanguage.equals(StringPool.BLANK)) { elLanguage = "_" + elLanguage; } } if (elType.equals("image") && Validator.isNull(elContent)) { File file = uploadRequest.getFile("structure_image_" + elName + elLanguage); byte[] bytes = FileUtil.getBytes(file); if ((bytes != null) && (bytes.length > 0)) { long imageId = JournalArticleImageLocalServiceUtil.getArticleImageId( groupId, previewArticleId, version, elInstanceId, elName, elLanguage, true); String token = ImageServletTokenUtil.getToken(imageId); dynamicContent.setText("/image/journal/article?img_id=" + imageId + "&t=" + token); ImageLocalServiceUtil.updateImage(imageId, bytes); } else { if (Validator.isNotNull(articleId)) { long imageId = JournalArticleImageLocalServiceUtil.getArticleImageId( groupId, articleId, version, elInstanceId, elName, elLanguage); String token = ImageServletTokenUtil.getToken(imageId); dynamicContent.setText("/image/journal/article?img_id=" + imageId + "&t=" + token); } } } format(groupId, articleId, version, previewArticleId, el, uploadRequest); } }