List of usage examples for com.liferay.portal.kernel.model Image getTextObj
public byte[] getTextObj();
From source file:com.liferay.blogs.internal.exportimport.data.handler.BlogsEntryStagedModelDataHandler.java
License:Open Source License
@Override protected void doExportStagedModel(PortletDataContext portletDataContext, BlogsEntry entry) throws Exception { Element entryElement = portletDataContext.getExportDataElement(entry); if (entry.isSmallImage()) { if (entry.getSmallImageFileEntryId() > 0) { FileEntry fileEntry = PortletFileRepositoryUtil .getPortletFileEntry(entry.getSmallImageFileEntryId()); StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, entry, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK); } else if (entry.getSmallImageId() > 0) { Image smallImage = _imageLocalService.fetchImage(entry.getSmallImageId()); if ((smallImage != null) && (smallImage.getTextObj() != 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()); } else { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Unable to export small image "); sb.append(entry.getSmallImageId()); sb.append(" to blogs entry "); sb.append(entry.getEntryId()); _log.warn(sb.toString()); }/* w w w . java2 s . c o m*/ entry.setSmallImage(false); entry.setSmallImageId(0); } } } if (entry.getCoverImageFileEntryId() != 0) { FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(entry.getCoverImageFileEntryId()); StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, entry, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK); } String content = _exportImportContentProcessorController.replaceExportContentReferences(portletDataContext, entry, entry.getContent(), portletDataContext.getBooleanParameter("blogs", "referenced-content"), true); entry.setContent(content); portletDataContext.addClassedModel(entryElement, ExportImportPathUtil.getModelPath(entry), entry); }
From source file:com.liferay.dynamic.data.mapping.internal.util.DDMImpl.java
License:Open Source License
protected byte[] getImageBytes(UploadRequest uploadRequest, String fieldNameValue) throws Exception { File file = uploadRequest.getFile(fieldNameValue + "File"); byte[] bytes = FileUtil.getBytes(file); if (ArrayUtil.isNotEmpty(bytes)) { return bytes; }/* ww w . ja v a 2s .c o m*/ String url = uploadRequest.getParameter(fieldNameValue + "URL"); long imageId = GetterUtil.getLong(_http.getParameter(url, "img_id", false)); Image image = _imageLocalService.fetchImage(imageId); if (image == null) { return null; } return image.getTextObj(); }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMTemplateLocalServiceImpl.java
License:Open Source License
protected File getSmallImageFile(DDMTemplate template) { File smallImageFile = null;//from ww w . java 2s .c o m if (template.isSmallImage() && Validator.isNull(template.getSmallImageURL())) { Image smallImage = imageLocalService.fetchImage(template.getSmallImageId()); if (smallImage != null) { smallImageFile = FileUtil.createTempFile(smallImage.getType()); try { FileUtil.write(smallImageFile, smallImage.getTextObj()); } catch (IOException ioe) { _log.error(ioe, ioe); } } } return smallImageFile; }
From source file:com.liferay.dynamic.data.mapping.web.internal.exportimport.data.handler.DDMTemplateStagedModelDataHandler.java
License:Open Source License
@Override protected void doExportStagedModel(PortletDataContext portletDataContext, DDMTemplate template) throws Exception { Element templateElement = portletDataContext.getExportDataElement(template); DDMStructure structure = _ddmStructureLocalService.fetchStructure(template.getClassPK()); if (structure != null) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, template, structure, PortletDataContext.REFERENCE_TYPE_STRONG); }//from w w w .jav a2 s. com if (template.isSmallImage()) { if (Validator.isNotNull(template.getSmallImageURL())) { String smallImageURL = _ddmTemplateExportImportContentProcessor.replaceExportContentReferences( portletDataContext, template, template.getSmallImageURL() + StringPool.SPACE, true, true); template.setSmallImageURL(smallImageURL); } else { Image smallImage = _imageLocalService.fetchImage(template.getSmallImageId()); if ((smallImage != null) && (smallImage.getTextObj() != null)) { String smallImagePath = ExportImportPathUtil.getModelPath(template, smallImage.getImageId() + StringPool.PERIOD + template.getSmallImageType()); templateElement.addAttribute("small-image-path", smallImagePath); template.setSmallImageType(smallImage.getType()); portletDataContext.addZipEntry(smallImagePath, smallImage.getTextObj()); } else { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Unable to export small image "); sb.append(template.getSmallImageId()); sb.append(" to template "); sb.append(template.getTemplateKey()); _log.warn(sb.toString()); } template.setSmallImage(false); template.setSmallImageId(0); } } } String script = _ddmTemplateExportImportContentProcessor.replaceExportContentReferences(portletDataContext, template, template.getScript(), portletDataContext.getBooleanParameter(DDMPortletDataHandler.NAMESPACE, "referenced-content"), false); template.setScript(script); long defaultUserId = _userLocalService.getDefaultUserId(template.getCompanyId()); if (defaultUserId == template.getUserId()) { templateElement.addAttribute("preloaded", "true"); } if (template.getResourceClassNameId() > 0) { templateElement.addAttribute("resource-class-name", _portal.getClassName(template.getResourceClassNameId())); } portletDataContext.addClassedModel(templateElement, ExportImportPathUtil.getModelPath(template), template); }
From source file:com.liferay.journal.exportimport.data.handler.JournalArticleStagedModelDataHandler.java
License:Open Source License
@Override protected void doExportStagedModel(PortletDataContext portletDataContext, JournalArticle article) throws Exception { Element articleElement = portletDataContext.getExportDataElement(article); articleElement.addAttribute("article-resource-uuid", article.getArticleResourceUuid()); if (article.getFolderId() != JournalFolderConstants.DEFAULT_PARENT_FOLDER_ID) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, article.getFolder(), PortletDataContext.REFERENCE_TYPE_PARENT); }//ww w .j a v a 2s. c o m DDMStructure ddmStructure = _ddmStructureLocalService.getStructure(article.getGroupId(), _portal.getClassNameId(JournalArticle.class), article.getDDMStructureKey(), true); StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, ddmStructure, PortletDataContext.REFERENCE_TYPE_STRONG); if (article.getClassNameId() != _portal.getClassNameId(DDMStructure.class)) { DDMTemplate ddmTemplate = _ddmTemplateLocalService.getTemplate(article.getGroupId(), _portal.getClassNameId(DDMStructure.class), article.getDDMTemplateKey(), true); StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, ddmTemplate, PortletDataContext.REFERENCE_TYPE_STRONG); } Layout layout = article.getLayout(); if (layout != null) { portletDataContext.addReferenceElement(article, articleElement, layout, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); } if (article.isSmallImage()) { if (Validator.isNotNull(article.getSmallImageURL())) { String smallImageURL = _journalArticleExportImportContentProcessor.replaceExportContentReferences( portletDataContext, article, article.getSmallImageURL() + StringPool.SPACE, true, false); article.setSmallImageURL(smallImageURL); } else { Image smallImage = _imageLocalService.fetchImage(article.getSmallImageId()); if ((smallImage != null) && (smallImage.getTextObj() != null)) { String smallImagePath = ExportImportPathUtil.getModelPath(article, smallImage.getImageId() + StringPool.PERIOD + smallImage.getType()); articleElement.addAttribute("small-image-path", smallImagePath); article.setSmallImageType(smallImage.getType()); portletDataContext.addZipEntry(smallImagePath, smallImage.getTextObj()); } else { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Unable to export small image "); sb.append(article.getSmallImageId()); sb.append(" to article "); sb.append(article.getArticleId()); _log.warn(sb.toString()); } article.setSmallImage(false); article.setSmallImageId(0); } } } JournalArticle latestArticle = _journalArticleLocalService.fetchLatestArticle(article.getResourcePrimKey()); if ((latestArticle != null) && (latestArticle.getId() == article.getId())) { for (FileEntry fileEntry : article.getImagesFileEntries()) { StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, article, fileEntry, PortletDataContext.REFERENCE_TYPE_WEAK); } } article.setStatusByUserUuid(article.getStatusByUserUuid()); String content = _journalArticleExportImportContentProcessor.replaceExportContentReferences( portletDataContext, article, article.getContent(), portletDataContext.getBooleanParameter("journal", "referenced-content"), false); article.setContent(content); long defaultUserId = _userLocalService.getDefaultUserId(article.getCompanyId()); if (defaultUserId == article.getUserId()) { articleElement.addAttribute("preloaded", "true"); } portletDataContext.addClassedModel(articleElement, ExportImportPathUtil.getModelPath(article), article); }
From source file:com.liferay.journal.internal.upgrade.v1_1_0.UpgradeImageTypeContent.java
License:Open Source License
protected void copyJournalArticleImagesToJournalRepository() throws Exception { try (LoggingTimer loggingTimer = new LoggingTimer(); PreparedStatement ps1 = connection.prepareStatement( "select articleId, articleImageId, groupId from " + "JournalArticleImage"); ResultSet rs1 = ps1.executeQuery()) { while (rs1.next()) { String articleId = rs1.getString(1); long articleImageId = rs1.getLong(2); long groupId = rs1.getLong(3); try (PreparedStatement ps2 = connection .prepareStatement("select resourcePrimKey, userId from JournalArticle " + "where groupId = ? and articleId = ?")) { ps2.setLong(1, groupId); ps2.setString(2, articleId); ResultSet rs2 = ps2.executeQuery(); if (!rs2.next()) { continue; }/*w ww . ja v a 2 s. co m*/ long resourcePrimKey = rs2.getLong(1); long userId = rs2.getLong(2); long folderId = getFolderId(userId, groupId, resourcePrimKey); FileEntry fileEntry = getFileEntry(groupId, folderId, String.valueOf(articleImageId)); if (fileEntry != null) { continue; } Image image = _imageLocalService.getImage(articleImageId); if (image == null) { continue; } PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId, JournalArticle.class.getName(), resourcePrimKey, JournalConstants.SERVICE_NAME, folderId, image.getTextObj(), String.valueOf(articleImageId), image.getType(), false); } } } }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
/** * Copies the web content article matching the group, article ID, and * version. This method creates a new article, extracting all the values * from the old one and updating its article ID. * * @param userId the primary key of the web content article's creator/owner * @param groupId the primary key of the web content article's group * @param oldArticleId the primary key of the old web content article * @param newArticleId the primary key of the new web content article * @param autoArticleId whether to auto-generate the web content article ID * @param version the web content article's version * @return the new web content article// w w w.ja va 2 s .c o m */ @Indexable(type = IndexableType.REINDEX) @Override public JournalArticle copyArticle(long userId, long groupId, String oldArticleId, String newArticleId, boolean autoArticleId, double version) throws PortalException { // Article User user = userLocalService.getUser(userId); oldArticleId = StringUtil.toUpperCase(StringUtil.trim(oldArticleId)); newArticleId = StringUtil.toUpperCase(StringUtil.trim(newArticleId)); JournalArticle oldArticle = journalArticlePersistence.findByG_A_V(groupId, oldArticleId, version); if (autoArticleId) { newArticleId = String.valueOf(counterLocalService.increment()); } else { validate(newArticleId); if (journalArticlePersistence.countByG_A(groupId, newArticleId) > 0) { StringBundler sb = new StringBundler(5); sb.append("{groupId="); sb.append(groupId); sb.append(", articleId="); sb.append(newArticleId); sb.append("}"); throw new DuplicateArticleIdException(sb.toString()); } } long id = counterLocalService.increment(); long resourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(groupId, newArticleId); JournalArticle newArticle = journalArticlePersistence.create(id); newArticle.setResourcePrimKey(resourcePrimKey); newArticle.setGroupId(groupId); newArticle.setCompanyId(user.getCompanyId()); newArticle.setUserId(user.getUserId()); newArticle.setUserName(user.getFullName()); newArticle.setFolderId(oldArticle.getFolderId()); newArticle.setTreePath(oldArticle.getTreePath()); newArticle.setArticleId(newArticleId); newArticle.setVersion(JournalArticleConstants.VERSION_DEFAULT); newArticle.setUrlTitle(getUniqueUrlTitle(id, groupId, newArticleId, oldArticle.getTitleCurrentValue())); try { copyArticleImages(oldArticle, newArticle); } catch (Exception e) { newArticle.setContent(oldArticle.getContent()); } newArticle.setDDMStructureKey(oldArticle.getDDMStructureKey()); newArticle.setDDMTemplateKey(oldArticle.getDDMTemplateKey()); newArticle.setDefaultLanguageId(oldArticle.getDefaultLanguageId()); newArticle.setLayoutUuid(oldArticle.getLayoutUuid()); newArticle.setDisplayDate(oldArticle.getDisplayDate()); newArticle.setExpirationDate(oldArticle.getExpirationDate()); newArticle.setReviewDate(oldArticle.getReviewDate()); newArticle.setIndexable(oldArticle.isIndexable()); newArticle.setSmallImage(oldArticle.isSmallImage()); newArticle.setSmallImageId(counterLocalService.increment()); newArticle.setSmallImageURL(oldArticle.getSmallImageURL()); WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil .getWorkflowHandler(JournalArticle.class.getName()); WorkflowDefinitionLink workflowDefinitionLink = workflowHandler .getWorkflowDefinitionLink(oldArticle.getCompanyId(), oldArticle.getGroupId(), oldArticle.getId()); if (oldArticle.isPending() || (workflowDefinitionLink != null)) { newArticle.setStatus(WorkflowConstants.STATUS_DRAFT); } else { newArticle.setStatus(oldArticle.getStatus()); } ExpandoBridgeUtil.copyExpandoBridgeAttributes(oldArticle.getExpandoBridge(), newArticle.getExpandoBridge()); journalArticlePersistence.update(newArticle); // Article localization String urlTitle = JournalUtil.getUrlTitle(id, oldArticle.getUrlTitle()); int uniqueUrlTitleCount = _getUniqueUrlTitleCount(groupId, newArticleId, urlTitle); Map<Locale, String> newTitleMap = oldArticle.getTitleMap(); for (Locale locale : newTitleMap.keySet()) { StringBundler sb = new StringBundler(5); sb.append(newTitleMap.get(locale)); sb.append(StringPool.SPACE); sb.append(LanguageUtil.get(locale, "duplicate")); sb.append(StringPool.SPACE); sb.append(uniqueUrlTitleCount); newTitleMap.put(locale, sb.toString()); } _addArticleLocalizedFields(newArticle.getCompanyId(), newArticle.getId(), newTitleMap, oldArticle.getDescriptionMap()); // Resources addArticleResources(newArticle, true, true); // Small image if (oldArticle.isSmallImage()) { Image image = imageLocalService.fetchImage(oldArticle.getSmallImageId()); if (image != null) { byte[] smallImageBytes = image.getTextObj(); imageLocalService.updateImage(newArticle.getSmallImageId(), smallImageBytes); } } // Asset long[] assetCategoryIds = assetCategoryLocalService.getCategoryIds(JournalArticle.class.getName(), oldArticle.getResourcePrimKey()); String[] assetTagNames = assetTagLocalService.getTagNames(JournalArticle.class.getName(), oldArticle.getResourcePrimKey()); AssetEntry oldAssetEntry = assetEntryLocalService.getEntry(JournalArticle.class.getName(), oldArticle.getResourcePrimKey()); List<AssetLink> assetLinks = assetLinkLocalService.getDirectLinks(oldAssetEntry.getEntryId(), false); long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR); updateAsset(userId, newArticle, assetCategoryIds, assetTagNames, assetLinkEntryIds, oldAssetEntry.getPriority()); // Dynamic data mapping updateDDMLinks(id, groupId, oldArticle.getDDMStructureKey(), oldArticle.getDDMTemplateKey(), true); return newArticle; }
From source file:com.liferay.layout.admin.web.internal.exportimport.data.handler.LayoutStagedModelDataHandler.java
License:Open Source License
protected void exportLayoutIconImage(PortletDataContext portletDataContext, Layout layout, Element layoutElement) throws Exception { Image image = _imageLocalService.getImage(layout.getIconImageId()); if ((image != null) && (image.getTextObj() != null)) { String iconPath = ExportImportPathUtil.getModelPath(portletDataContext.getScopeGroupId(), Image.class.getName(), image.getImageId()); Element iconImagePathElement = layoutElement.addElement("icon-image-path"); iconImagePathElement.addText(iconPath); portletDataContext.addZipEntry(iconPath, image.getTextObj()); } else {/* w w w. ja va 2 s. c o m*/ if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Unable to export icon image "); sb.append(layout.getIconImageId()); sb.append(" to layout "); sb.append(layout.getLayoutId()); _log.warn(sb.toString()); } layout.setIconImageId(0); } }
From source file:com.liferay.layout.internal.exportimport.data.handler.StagedLayoutSetStagedModelDataHandler.java
License:Open Source License
protected void exportLogo(PortletDataContext portletDataContext, StagedLayoutSet stagedLayoutSet) { boolean logo = MapUtil.getBoolean(portletDataContext.getParameterMap(), PortletDataHandlerKeys.LOGO); if (!logo) {/*from w w w. j a va2 s .c om*/ stagedLayoutSet.setLogoId(0); return; } long layoutSetBranchId = MapUtil.getLong(portletDataContext.getParameterMap(), "layoutSetBranchId"); LayoutSetBranch layoutSetBranch = _layoutSetBranchLocalService.fetchLayoutSetBranch(layoutSetBranchId); Image image = null; if (layoutSetBranch != null) { try { image = _imageLocalService.getImage(layoutSetBranch.getLogoId()); } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn("Unable to get logo for layout set branch " + layoutSetBranch.getLayoutSetBranchId(), pe); } } } else { try { image = _imageLocalService.getImage(stagedLayoutSet.getLogoId()); } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn("Unable to get logo for layout set " + stagedLayoutSet.getLayoutSetId(), pe); } } } if ((image != null) && (image.getTextObj() != null)) { String logoPath = ExportImportPathUtil.getRootPath(portletDataContext); logoPath += "/logo"; Element rootElement = portletDataContext.getExportDataRootElement(); Element headerElement = rootElement.element("header"); headerElement.addAttribute("logo-path", logoPath); portletDataContext.addZipEntry(logoPath, image.getTextObj()); } }
From source file:com.liferay.sync.internal.servlet.SyncDownloadServlet.java
License:Open Source License
protected void sendImage(HttpServletRequest request, HttpServletResponse response, long imageId) throws Exception { User user = _userLocalService.fetchUser(imageId); if (user != null) { imageId = user.getPortraitId();//from w ww. j av a2s . com } Image image = _imageLocalService.fetchImage(imageId); if (image == null) { _portal.sendError(HttpServletResponse.SC_NOT_FOUND, new NoSuchImageException(), request, response); return; } String type = image.getType(); if (!type.equals(ImageConstants.TYPE_NOT_AVAILABLE)) { String contentType = MimeTypesUtil.getExtensionContentType(type); response.setContentType(contentType); } ServletResponseUtil.write(response, image.getTextObj()); }