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.testopensocialoauthconsumer.messaging.TestOpenSocialOAuthConsumerHotDeployMessageListener.java
License:Open Source License
protected void setupGadget() throws Exception { Class<?> clazz = getClass(); ClassLoader classLoader = clazz.getClassLoader(); long companyId = PortalUtil.getDefaultCompanyId(); User user = UserLocalServiceUtil.getDefaultUser(companyId); Group group = GroupLocalServiceUtil.getCompanyGroup(companyId); Folder gadgetEditorRootFolder = getGadgetEditorRootFolder(user.getUserId(), group.getGroupId()); FileEntry fileEntry = null;/*from ww w . j a v a 2 s . c om*/ try { fileEntry = DLAppLocalServiceUtil.getFileEntry(group.getGroupId(), gadgetEditorRootFolder.getFolderId(), _GADGET_FILE_NAME); } catch (NoSuchFileEntryException nsfee) { InputStream inputStream = classLoader .getResourceAsStream("/resources/gadgets/".concat(_GADGET_FILE_NAME)); String xml = new String(FileUtil.getBytes(inputStream)); xml = StringUtil.replace(xml, new String[] { "[$ACCESS_URL$]", "[$AUTHORIZATION_URL$]", "[$FOLDER_ID$]", "[$PORTAL_URL$]", "[$REPOSITORY_ID$]", "[$REQUEST_URL$]" }, new String[] { "/c/portal/oauth/access_token", "/c/portal/oauth/authorize", String.valueOf(gadgetEditorRootFolder.getFolderId()), "http://localhost:8080", String.valueOf(group.getGroupId()), "/c/portal/oauth/request_token" }); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(group.getGroupId()); serviceContext.setAttribute("sourceFileName", _GADGET_FILE_NAME); fileEntry = DLAppLocalServiceUtil.addFileEntry(user.getUserId(), gadgetEditorRootFolder.getRepositoryId(), gadgetEditorRootFolder.getFolderId(), _GADGET_FILE_NAME, ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED_UTF8, _GADGET_FILE_NAME, StringPool.BLANK, StringPool.BLANK, xml.getBytes(StringPool.UTF8), serviceContext); } Gadget gadget = GadgetLocalServiceUtil.fetchGadget(companyId, getFileEntryURL(fileEntry)); if (gadget == null) { ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(true); serviceContext.setAddGuestPermissions(true); serviceContext.setScopeGroupId(group.getGroupId()); GadgetLocalServiceUtil.addGadget(companyId, getFileEntryURL(fileEntry), _PORTLET_CATEGORY_NAMES, serviceContext); } }
From source file:com.liferay.users.admin.demo.data.creator.internal.BaseUserDemoDataCreator.java
License:Open Source License
private byte[] _getBytes(URL url) throws IOException { try (InputStream is = url.openStream()) { return FileUtil.getBytes(is); }/*from ww w . j a va2 s . co m*/ }
From source file:com.liferay.users.admin.web.internal.portlet.action.EditOrganizationMVCActionCommand.java
License:Open Source License
protected Organization updateOrganization(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long organizationId = ParamUtil.getLong(actionRequest, "organizationId"); long parentOrganizationId = ParamUtil.getLong(actionRequest, "parentOrganizationSearchContainerPrimaryKeys", OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID); String name = ParamUtil.getString(actionRequest, "name"); long statusId = ParamUtil.getLong(actionRequest, "statusId"); String type = ParamUtil.getString(actionRequest, "type"); long regionId = ParamUtil.getLong(actionRequest, "regionId"); long countryId = ParamUtil.getLong(actionRequest, "countryId"); String comments = ParamUtil.getString(actionRequest, "comments"); 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()); }/* ww w. ja va 2 s . co m*/ boolean site = ParamUtil.getBoolean(actionRequest, "site"); List<Address> addresses = UsersAdminUtil.getAddresses(actionRequest); List<EmailAddress> emailAddresses = UsersAdminUtil.getEmailAddresses(actionRequest); List<OrgLabor> orgLabors = UsersAdminUtil.getOrgLabors(actionRequest); List<Phone> phones = UsersAdminUtil.getPhones(actionRequest); List<Website> websites = UsersAdminUtil.getWebsites(actionRequest); ServiceContext serviceContext = ServiceContextFactory.getInstance(Organization.class.getName(), actionRequest); Organization organization = null; if (organizationId <= 0) { // Add organization organization = _organizationService.addOrganization(parentOrganizationId, name, type, regionId, countryId, statusId, comments, site, addresses, emailAddresses, orgLabors, phones, websites, serviceContext); } else { // Update organization organization = _organizationService.updateOrganization(organizationId, parentOrganizationId, name, type, regionId, countryId, statusId, comments, !deleteLogo, logoBytes, site, addresses, emailAddresses, orgLabors, phones, websites, serviceContext); } // Layout set prototypes long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId"); long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId"); boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest, "publicLayoutSetPrototypeLinkEnabled", publicLayoutSetPrototypeId > 0); boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean(actionRequest, "privateLayoutSetPrototypeLinkEnabled", privateLayoutSetPrototypeId > 0); Group organizationGroup = organization.getGroup(); if (GroupPermissionUtil.contains(themeDisplay.getPermissionChecker(), organizationGroup, ActionKeys.UPDATE)) { SitesUtil.updateLayoutSetPrototypesLinks(organizationGroup, publicLayoutSetPrototypeId, privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled, privateLayoutSetPrototypeLinkEnabled); } // Reminder queries String reminderQueries = actionRequest.getParameter("reminderQueries"); PortletPreferences portletPreferences = organization.getPreferences(); LocalizationUtil.setLocalizedPreferencesValues(actionRequest, portletPreferences, "reminderQueries"); portletPreferences.setValue("reminderQueries", reminderQueries); portletPreferences.store(); return organization; }
From source file:com.liferay.users.admin.web.internal.portlet.action.EditUserMVCActionCommand.java
License:Open Source License
protected Object[] updateUser(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = portal.getSelectedUser(actionRequest); Contact contact = user.getContact(); String oldPassword = AdminUtil.getUpdateUserPassword(actionRequest, user.getUserId()); String oldScreenName = user.getScreenName(); String screenName = BeanParamUtil.getString(user, actionRequest, "screenName"); String oldEmailAddress = user.getEmailAddress(); String emailAddress = BeanParamUtil.getString(user, actionRequest, "emailAddress"); long facebookId = user.getFacebookId(); boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo"); byte[] portraitBytes = null; long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); if (fileEntryId > 0) { FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId); portraitBytes = FileUtil.getBytes(fileEntry.getContentStream()); }//from w ww .j a va2 s.com String languageId = BeanParamUtil.getString(user, actionRequest, "languageId"); String firstName = BeanParamUtil.getString(user, actionRequest, "firstName"); String middleName = BeanParamUtil.getString(user, actionRequest, "middleName"); String lastName = BeanParamUtil.getString(user, actionRequest, "lastName"); long prefixId = BeanParamUtil.getInteger(contact, actionRequest, "prefixId"); long suffixId = BeanParamUtil.getInteger(contact, actionRequest, "suffixId"); boolean male = BeanParamUtil.getBoolean(user, actionRequest, "male", true); Calendar birthdayCal = CalendarFactoryUtil.getCalendar(); birthdayCal.setTime(contact.getBirthday()); int birthdayMonth = ParamUtil.getInteger(actionRequest, "birthdayMonth", birthdayCal.get(Calendar.MONTH)); int birthdayDay = ParamUtil.getInteger(actionRequest, "birthdayDay", birthdayCal.get(Calendar.DATE)); int birthdayYear = ParamUtil.getInteger(actionRequest, "birthdayYear", birthdayCal.get(Calendar.YEAR)); String comments = BeanParamUtil.getString(user, actionRequest, "comments"); String jobTitle = BeanParamUtil.getString(user, actionRequest, "jobTitle"); ServiceContext serviceContext = ServiceContextFactory.getInstance(User.class.getName(), actionRequest); user = _userService.updateUser(user.getUserId(), oldPassword, null, null, user.getPasswordReset(), null, null, screenName, emailAddress, facebookId, user.getOpenId(), !deleteLogo, portraitBytes, languageId, user.getTimeZoneId(), user.getGreeting(), comments, firstName, middleName, lastName, prefixId, suffixId, male, birthdayMonth, birthdayDay, birthdayYear, null, null, null, null, null, jobTitle, null, null, null, null, null, null, null, null, null, null, serviceContext); if (oldScreenName.equals(user.getScreenName())) { oldScreenName = StringPool.BLANK; } boolean updateLanguageId = false; if (user.getUserId() == themeDisplay.getUserId()) { // Reset the locale HttpServletRequest request = portal .getOriginalServletRequest(portal.getHttpServletRequest(actionRequest)); HttpServletResponse response = portal.getHttpServletResponse(actionResponse); HttpSession session = request.getSession(); session.removeAttribute(Globals.LOCALE_KEY); Locale locale = LocaleUtil.fromLanguageId(languageId); LanguageUtil.updateCookie(request, response, locale); // Clear cached portlet responses PortletSession portletSession = actionRequest.getPortletSession(); InvokerPortletImpl.clearResponses(portletSession); updateLanguageId = true; } Company company = portal.getCompany(actionRequest); if (company.isStrangersVerify() && !StringUtil.equalsIgnoreCase(oldEmailAddress, emailAddress)) { SessionMessages.add(actionRequest, "verificationEmailSent"); } return new Object[] { user, oldScreenName, updateLanguageId }; }
From source file:com.liferay.util.bridges.bsf.BaseBSFPortlet.java
License:Open Source License
protected void declareBeans(InputStream is, PortletRequest portletRequest, PortletResponse portletResponse) throws BSFException, IOException { declareBeans(new String(FileUtil.getBytes(is)), portletRequest, portletResponse); }
From source file:com.liferay.util.bridges.bsf.BaseBSFPortlet.java
License:Open Source License
protected String getGlobalScript() throws IOException { if (globalFiles.length == 0) { return StringPool.BLANK; }/* www . ja v a2s . c om*/ StringBundler sb = new StringBundler(); for (int i = 0; i < globalFiles.length; i++) { InputStream is = getPortletContext().getResourceAsStream(globalFiles[i]); if (is == null) { if (_log.isWarnEnabled()) { _log.warn("Global file " + globalFiles[i] + " does not exist"); } } if (is != null) { sb.append(new String(FileUtil.getBytes(is))); sb.append(StringPool.NEW_LINE); } } return sb.toString(); }
From source file:com.liferay.util.bridges.scripting.ScriptingPortlet.java
License:Open Source License
protected void declareBeans(InputStream is, PortletRequest portletRequest, PortletResponse portletResponse) throws IOException, ScriptingException { String script = new String(FileUtil.getBytes(is)); declareBeans(script, portletRequest, portletResponse); }
From source file:com.liferay.util.bridges.scripting.ScriptingPortlet.java
License:Open Source License
protected String getGlobalScript() throws IOException { if (globalScript != null) { return globalScript; }/*from w w w . j av a2 s.c o m*/ if (globalFiles.length == 0) { globalScript = StringPool.BLANK; return globalScript; } StringBundler sb = new StringBundler(); for (String globalFile : globalFiles) { InputStream is = getPortletContext().getResourceAsStream(globalFile); if (is == null) { if (_log.isWarnEnabled()) { _log.warn("Global file " + globalFile + " does not exist"); } } if (is != null) { String script = new String(FileUtil.getBytes(is)); sb.append(script); sb.append(StringPool.NEW_LINE); } } globalScript = sb.toString(); return globalScript; }
From source file:com.liferay.wol.meetups.portlet.MeetupsPortlet.java
License:Open Source License
public void updateMeetupsEntry(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) uploadRequest.getAttribute(WebKeys.THEME_DISPLAY); PermissionChecker permissionChecker = themeDisplay.getPermissionChecker(); if (!permissionChecker.isCompanyAdmin(themeDisplay.getCompanyId())) { return;/*from w ww. j a v a 2s .com*/ } long meetupsEntryId = ParamUtil.getLong(uploadRequest, "meetupsEntryId"); String title = ParamUtil.getString(uploadRequest, "title"); String description = ParamUtil.getString(uploadRequest, "description"); int startDateMonth = ParamUtil.getInteger(uploadRequest, "startDateMonth"); int startDateDay = ParamUtil.getInteger(uploadRequest, "startDateDay"); int startDateYear = ParamUtil.getInteger(uploadRequest, "startDateYear"); int startDateHour = ParamUtil.getInteger(uploadRequest, "startDateHour"); int startDateMinute = ParamUtil.getInteger(uploadRequest, "startDateMinute"); int startDateAmPm = ParamUtil.getInteger(uploadRequest, "startDateAmPm"); if (startDateAmPm == Calendar.PM) { startDateHour += 12; } int endDateMonth = ParamUtil.getInteger(uploadRequest, "endDateMonth"); int endDateDay = ParamUtil.getInteger(uploadRequest, "endDateDay"); int endDateYear = ParamUtil.getInteger(uploadRequest, "endDateYear"); int endDateHour = ParamUtil.getInteger(uploadRequest, "endDateHour"); int endDateMinute = ParamUtil.getInteger(uploadRequest, "endDateMinute"); int endDateAmPm = ParamUtil.getInteger(uploadRequest, "endDateAmPm"); if (endDateAmPm == Calendar.PM) { endDateHour += 12; } int totalAttendees = ParamUtil.getInteger(uploadRequest, "totalAttendees"); int maxAttendees = ParamUtil.getInteger(uploadRequest, "maxAttendees"); double price = ParamUtil.getDouble(uploadRequest, "price"); File file = uploadRequest.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.wsrp.consumer.portlet.ConsumerPortlet.java
License:Open Source License
protected Object[] processMultipartForm(PortletRequest portletRequest, PortletResponse portletResponse) throws Exception { List<NamedString> formParameters = new ArrayList<NamedString>(); List<UploadContext> uploadContexts = new ArrayList<UploadContext>(); UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(portletRequest); Enumeration<String> enu = uploadPortletRequest.getParameterNames(); while (enu.hasMoreElements()) { String name = enu.nextElement(); if (isReservedParameter(name) || name.startsWith("p_p_")) { continue; }/*from w ww . ja v a2 s .c om*/ if (uploadPortletRequest.isFormField(name)) { String[] values = uploadPortletRequest.getParameterValues(name); if (values == null) { continue; } addFormField(formParameters, name, values); } else { UploadContext uploadContext = new UploadContext(); String contentType = uploadPortletRequest.getContentType(name); uploadContext.setMimeType(contentType); StringBuilder sb = new StringBuilder(); sb.append("form-data; "); sb.append("name="); sb.append(name); sb.append("; filename="); sb.append(uploadPortletRequest.getFileName(name)); NamedString mimeAttribute = new NamedString(); mimeAttribute.setName(HttpHeaders.CONTENT_DISPOSITION); mimeAttribute.setValue(sb.toString()); uploadContext.setMimeAttributes(new NamedString[] { mimeAttribute }); InputStream inputStream = null; try { inputStream = uploadPortletRequest.getFileAsStream(name); if (inputStream == null) { continue; } byte[] bytes = FileUtil.getBytes(inputStream); if (bytes == null) { continue; } uploadContext.setUploadData(bytes); } finally { StreamUtil.cleanUp(inputStream); } uploadContexts.add(uploadContext); } } return new Object[] { formParameters, uploadContexts }; }