List of usage examples for com.liferay.portal.kernel.util FileUtil getBytes
public static byte[] getBytes(InputStream is) throws IOException
From source file:com.liferay.layout.admin.web.internal.portlet.action.EditLayoutSetMVCActionCommand.java
License:Open Source License
protected void updateLogo(ActionRequest actionRequest, long liveGroupId, long stagingGroupId, boolean privateLayout) throws Exception { boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo"); byte[] logoBytes = null; long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); if (fileEntryId > 0) { FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId); logoBytes = FileUtil.getBytes(fileEntry.getContentStream()); }/*www .j a v a 2s . c om*/ long groupId = liveGroupId; if (stagingGroupId > 0) { groupId = stagingGroupId; } _layoutSetService.updateLogo(groupId, privateLayout, !deleteLogo, logoBytes); }
From source file:com.liferay.localization.servlet.LocalizationServletContextListener.java
License:Open Source License
protected void importSQL() throws Exception { Class<?> clazz = getClass(); ClassLoader classLoader = clazz.getClassLoader(); InputStream inputStream = classLoader.getResourceAsStream("/resources/data/sql.xml"); String xml = new String(FileUtil.getBytes(inputStream)); Document document = SAXReaderUtil.read(xml); Element rootElement = document.getRootElement(); List<Element> batchElements = rootElement.elements("batch"); for (Element batchElement : batchElements) { String testSQL = batchElement.elementText("test-sql"); int count = getCount(testSQL); if (count > 0) { continue; }/*w ww. j a v a 2 s. c o m*/ String[] importSQLs = StringUtil.split(batchElement.elementText("import-sql"), StringPool.SEMICOLON); runSQL(importSQLs); } }
From source file:com.liferay.marketplace.app.manager.web.internal.portlet.MarketplaceAppManagerPortlet.java
License:Open Source License
public void installLocalApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest); String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file")); File file = uploadPortletRequest.getFile("file"); byte[] bytes = FileUtil.getBytes(file); if (ArrayUtil.isEmpty(bytes)) { SessionErrors.add(actionRequest, UploadException.class.getName()); } else if (!fileName.endsWith(".jar") && !fileName.endsWith(".lpkg") && !fileName.endsWith(".war")) { throw new FileExtensionException(); } else {/*from w ww .j ava 2 s . c om*/ String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName); SessionMessages.add(actionRequest, "pluginUploaded"); } sendRedirect(actionRequest, actionResponse); }
From source file:com.liferay.marketplace.appmanager.portlet.AppManagerPortlet.java
License:Open Source License
public void installApp(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); String installMethod = ParamUtil.getString(uploadPortletRequest, "installMethod"); if (installMethod.equals("local")) { String fileName = GetterUtil.getString(uploadPortletRequest.getFileName("file")); File file = uploadPortletRequest.getFile("file"); byte[] bytes = FileUtil.getBytes(file); if (ArrayUtil.isEmpty(bytes)) { SessionErrors.add(actionRequest, UploadException.class.getName()); } else {//from w w w . j a v a 2 s . c om String deployDir = PrefsPropsUtil.getString(PropsKeys.AUTO_DEPLOY_DEPLOY_DIR); FileUtil.copyFile(file.toString(), deployDir + StringPool.SLASH + fileName); SessionMessages.add(actionRequest, "pluginUploaded"); } } else { try { String url = ParamUtil.getString(uploadPortletRequest, "url"); URL urlObj = new URL(url); String host = urlObj.getHost(); if (host.endsWith("sf.net") || host.endsWith("sourceforge.net")) { doInstallSourceForgeApp(urlObj.getPath(), uploadPortletRequest, actionRequest); } else { doInstallRemoteApp(url, uploadPortletRequest, actionRequest, true); } } catch (MalformedURLException murle) { SessionErrors.add(actionRequest, "invalidUrl", murle); } } String redirect = ParamUtil.getString(uploadPortletRequest, "redirect"); actionResponse.sendRedirect(redirect); }
From source file:com.liferay.marketplace.store.web.internal.util.MarketplaceLicenseUtil.java
License:Open Source License
public static byte[] getServerIdBytes() throws Exception { File serverIdFile = new File(_LICENSE_SERVER_ID_FILE_NAME); if (!serverIdFile.exists()) { return new byte[0]; }//from w w w .ja v a 2s . c o m return FileUtil.getBytes(serverIdFile); }
From source file:com.liferay.MeetupsPortlet.java
License:Open Source License
public void updateMeetupsEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (!permissionChecker.isCompanyAdmin()) { return;//from www . j av a 2 s .c o m } long meetupsEntryId = ParamUtil.getLong(uploadPortletRequest, "meetupsEntryId"); String title = ParamUtil.getString(uploadPortletRequest, "title"); String description = ParamUtil.getString(uploadPortletRequest, "description"); int startDateMonth = ParamUtil.getInteger(uploadPortletRequest, "startDateMonth"); int startDateDay = ParamUtil.getInteger(uploadPortletRequest, "startDateDay"); int startDateYear = ParamUtil.getInteger(uploadPortletRequest, "startDateYear"); int startDateHour = ParamUtil.getInteger(uploadPortletRequest, "startDateHour"); int startDateMinute = ParamUtil.getInteger(uploadPortletRequest, "startDateMinute"); int startDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "startDateAmPm"); if (startDateAmPm == Calendar.PM) { startDateHour += 12; } int endDateMonth = ParamUtil.getInteger(uploadPortletRequest, "endDateMonth"); int endDateDay = ParamUtil.getInteger(uploadPortletRequest, "endDateDay"); int endDateYear = ParamUtil.getInteger(uploadPortletRequest, "endDateYear"); int endDateHour = ParamUtil.getInteger(uploadPortletRequest, "endDateHour"); int endDateMinute = ParamUtil.getInteger(uploadPortletRequest, "endDateMinute"); int endDateAmPm = ParamUtil.getInteger(uploadPortletRequest, "endDateAmPm"); if (endDateAmPm == Calendar.PM) { endDateHour += 12; } int totalAttendees = ParamUtil.getInteger(uploadPortletRequest, "totalAttendees"); int maxAttendees = ParamUtil.getInteger(uploadPortletRequest, "maxAttendees"); double price = ParamUtil.getDouble(uploadPortletRequest, "price"); File file = uploadPortletRequest.getFile("fileName"); byte[] bytes = FileUtil.getBytes(file); if (meetupsEntryId <= 0) { MeetupsEntryLocalServiceUtil.addMeetupsEntry(themeDisplay.getUserId(), title, description, startDateMonth, startDateDay, startDateYear, startDateHour, startDateMinute, endDateMonth, endDateDay, endDateYear, endDateHour, endDateMinute, totalAttendees, maxAttendees, price, bytes); } else { MeetupsEntryLocalServiceUtil.updateMeetupsEntry(themeDisplay.getUserId(), meetupsEntryId, title, description, startDateMonth, startDateDay, startDateYear, startDateHour, startDateMinute, endDateMonth, endDateDay, endDateYear, endDateHour, endDateMinute, totalAttendees, maxAttendees, price, bytes); } }
From source file:com.liferay.petra.mail.JavaMailUtil.java
License:Open Source License
public static byte[] getBytes(Part part) throws IOException, MessagingException { InputStream is = part.getInputStream(); return FileUtil.getBytes(is); }
From source file:com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
public BlogsEntry addEntry(long userId, String title, String description, String content, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, boolean allowPingbacks, boolean allowTrackbacks, String[] trackbacks, boolean smallImage, String smallImageURL, String smallImageFileName, InputStream smallImageInputStream, ServiceContext serviceContext) throws PortalException, SystemException { // Entry/* w ww. j a v a 2s . c o m*/ User user = userPersistence.findByPrimaryKey(userId); long groupId = serviceContext.getScopeGroupId(); Date displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, user.getTimeZone(), new EntryDisplayDateException()); byte[] smallImageBytes = null; try { if ((smallImageInputStream != null) && smallImage) { smallImageBytes = FileUtil.getBytes(smallImageInputStream); } } catch (IOException ioe) { } Date now = new Date(); validate(title, content, smallImage, smallImageURL, smallImageFileName, smallImageBytes); long entryId = counterLocalService.increment(); BlogsEntry entry = blogsEntryPersistence.create(entryId); entry.setUuid(serviceContext.getUuid()); entry.setGroupId(groupId); entry.setCompanyId(user.getCompanyId()); entry.setUserId(user.getUserId()); entry.setUserName(user.getFullName()); entry.setCreateDate(serviceContext.getCreateDate(now)); entry.setModifiedDate(serviceContext.getModifiedDate(now)); entry.setTitle(title); entry.setUrlTitle(getUniqueUrlTitle(entryId, groupId, title)); entry.setDescription(description); entry.setContent(content); entry.setDisplayDate(displayDate); entry.setAllowPingbacks(allowPingbacks); entry.setAllowTrackbacks(allowTrackbacks); entry.setSmallImage(smallImage); entry.setSmallImageId(counterLocalService.increment()); entry.setSmallImageURL(smallImageURL); entry.setStatus(WorkflowConstants.STATUS_DRAFT); entry.setStatusDate(serviceContext.getModifiedDate(now)); entry.setExpandoBridgeAttributes(serviceContext); blogsEntryPersistence.update(entry, false); // Resources if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) { addEntryResources(entry, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions()); } else { addEntryResources(entry, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions()); } // Small image saveImages(smallImage, entry.getSmallImageId(), smallImageBytes); // Asset updateAsset(userId, entry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds()); // Message boards if (PropsValues.BLOGS_ENTRY_COMMENTS_ENABLED) { mbMessageLocalService.addDiscussionMessage(userId, entry.getUserName(), groupId, BlogsEntry.class.getName(), entryId, WorkflowConstants.ACTION_PUBLISH); } // Workflow if ((trackbacks != null) && (trackbacks.length > 0)) { serviceContext.setAttribute("trackbacks", trackbacks); } else { serviceContext.setAttribute("trackbacks", null); } WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), groupId, userId, BlogsEntry.class.getName(), entry.getEntryId(), entry, serviceContext); return entry; }
From source file:com.liferay.portlet.blogs.service.impl.BlogsEntryLocalServiceImpl.java
License:Open Source License
public BlogsEntry updateEntry(long userId, long entryId, String title, String description, String content, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, boolean allowPingbacks, boolean allowTrackbacks, String[] trackbacks, boolean smallImage, String smallImageURL, String smallImageFileName, InputStream smallImageInputStream, ServiceContext serviceContext) throws PortalException, SystemException { // Entry//www . j ava 2 s .c o m User user = userPersistence.findByPrimaryKey(userId); Date displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, user.getTimeZone(), new EntryDisplayDateException()); byte[] smallImageBytes = null; try { if ((smallImageInputStream != null) && smallImage) { smallImageBytes = FileUtil.getBytes(smallImageInputStream); } } catch (IOException ioe) { } validate(title, content, smallImage, smallImageURL, smallImageFileName, smallImageBytes); BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId); String oldUrlTitle = entry.getUrlTitle(); entry.setModifiedDate(serviceContext.getModifiedDate(null)); entry.setTitle(title); entry.setUrlTitle(getUniqueUrlTitle(entryId, entry.getGroupId(), title)); entry.setDescription(description); entry.setContent(content); entry.setDisplayDate(displayDate); entry.setAllowPingbacks(allowPingbacks); entry.setAllowTrackbacks(allowTrackbacks); entry.setSmallImage(smallImage); if (entry.getSmallImageId() == 0) { entry.setSmallImageId(counterLocalService.increment()); } entry.setSmallImageURL(smallImageURL); if (!entry.isPending()) { entry.setStatus(WorkflowConstants.STATUS_DRAFT); } entry.setExpandoBridgeAttributes(serviceContext); blogsEntryPersistence.update(entry, false); // Resources if ((serviceContext.getGroupPermissions() != null) || (serviceContext.getGuestPermissions() != null)) { updateEntryResources(entry, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions()); } // Small image saveImages(smallImage, entry.getSmallImageId(), smallImageBytes); // Asset updateAsset(userId, entry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds()); // Workflow boolean pingOldTrackbacks = false; if (!oldUrlTitle.equals(entry.getUrlTitle())) { pingOldTrackbacks = true; } serviceContext.setAttribute("pingOldTrackbacks", String.valueOf(pingOldTrackbacks)); if (Validator.isNotNull(trackbacks)) { serviceContext.setAttribute("trackbacks", trackbacks); } else { serviceContext.setAttribute("trackbacks", null); } WorkflowHandlerRegistryUtil.startWorkflowInstance(user.getCompanyId(), entry.getGroupId(), userId, BlogsEntry.class.getName(), entry.getEntryId(), entry, serviceContext); return entry; }
From source file:com.liferay.portlet.documentlibrary.store.BaseStore.java
License:Open Source License
/** * Returns the file as a byte array.// ww w . j a v a2s. c o m * * @param companyId the primary key of the company * @param repositoryId the primary key of the data repository (optionally * {@link CompanyConstants#SYSTEM}) * @param fileName the file's name * @return Returns the byte array with the file's name * @throws PortalException if the file's information was invalid * @throws SystemException if a system exception occurred */ public byte[] getFileAsBytes(long companyId, long repositoryId, String fileName) throws PortalException, SystemException { byte[] bytes = null; try { InputStream is = getFileAsStream(companyId, repositoryId, fileName); bytes = FileUtil.getBytes(is); } catch (IOException ioe) { throw new SystemException(ioe); } return bytes; }