List of usage examples for com.liferay.portal.kernel.portlet PortletResponseUtil write
public static void write(MimeResponse mimeResponse, String s) throws IOException
From source file:com.liferay.wsrp.consumer.portlet.ConsumerPortlet.java
License:Open Source License
protected void proxyURL(ResourceRequest resourceRequest, ResourceResponse resourceResponse, String url) throws Exception { PortletSession portletSession = resourceRequest.getPortletSession(); WSRPConsumerPortlet wsrpConsumerPortlet = getWSRPConsumerPortlet(); WSRPConsumer wsrpConsumer = WSRPConsumerLocalServiceUtil .getWSRPConsumer(wsrpConsumerPortlet.getWsrpConsumerId()); Http.Options options = new Http.Options(); options.setLocation(url);//from www .j av a 2 s.com String cookieKey = getSessionKey(WebKeys.COOKIE, resourceRequest, wsrpConsumer); String cookie = (String) portletSession.getAttribute(cookieKey, PortletSession.APPLICATION_SCOPE); if (Validator.isNotNull(cookie)) { Map<String, String> headers = new HashMap<String, String>(); headers.put(HttpHeaders.COOKIE, cookie); options.setHeaders(headers); } byte[] bytes = HttpUtil.URLtoByteArray(options); Http.Response response = options.getResponse(); String contentDisposition = response.getHeader(HttpHeaders.CONTENT_DISPOSITION); if (Validator.isNotNull(contentDisposition)) { resourceResponse.setProperty(HttpHeaders.CONTENT_DISPOSITION, contentDisposition); } int contentLength = response.getContentLength(); if (contentLength >= 0) { resourceResponse.setContentLength(contentLength); } String contentType = response.getContentType(); if (Validator.isNotNull(contentType)) { resourceResponse.setContentType(contentType); } String charSet = getCharSet(contentType); if (ParamUtil.getBoolean(resourceRequest, "wsrp-requiresRewrite")) { String content = rewriteURLs(resourceRequest, resourceResponse, new String(bytes, charSet)); PortletResponseUtil.write(resourceResponse, content); } else { PortletResponseUtil.write(resourceResponse, bytes); } }
From source file:com.slemarchand.peoplepublisher.action.ConfigurationActionImpl.java
License:Open Source License
@Override public void serveResource(PortletConfig portletConfig, ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); String cmd = ParamUtil.getString(resourceRequest, Constants.CMD); if (!cmd.equals("getFieldValue")) { return;/*from ww w. ja va 2 s. c o m*/ } ServiceContext serviceContext = ServiceContextFactory.getInstance(resourceRequest); long structureId = ParamUtil.getLong(resourceRequest, "structureId"); Fields fields = (Fields) serviceContext.getAttribute(Fields.class.getName() + structureId); if (fields == null) { String fieldsNamespace = ParamUtil.getString(resourceRequest, "fieldsNamespace"); fields = DDMUtil.getFields(structureId, fieldsNamespace, serviceContext); } String fieldName = ParamUtil.getString(resourceRequest, "name"); Field field = fields.get(fieldName); Serializable fieldValue = field.getValue(themeDisplay.getLocale(), 0); DDMStructure ddmStructure = field.getDDMStructure(); String type = ddmStructure.getFieldType(fieldName); JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); Serializable displayValue = DDMUtil.getDisplayFieldValue(themeDisplay, fieldValue, type); jsonObject.put("displayValue", String.valueOf(displayValue)); if (fieldValue instanceof Boolean) { jsonObject.put("value", (Boolean) fieldValue); } else if (fieldValue instanceof Date) { DateFormat dateFormat = DateFormatFactoryUtil.getSimpleDateFormat("yyyyMMddHHmmss"); jsonObject.put("value", dateFormat.format(fieldValue)); } else if (fieldValue instanceof Double) { jsonObject.put("value", (Double) fieldValue); } else if (fieldValue instanceof Float) { jsonObject.put("value", (Float) fieldValue); } else if (fieldValue instanceof Integer) { jsonObject.put("value", (Integer) fieldValue); } else if (fieldValue instanceof Number) { jsonObject.put("value", String.valueOf(fieldValue)); } else { jsonObject.put("value", (String) fieldValue); } resourceResponse.setContentType(ContentTypes.APPLICATION_JSON); PortletResponseUtil.write(resourceResponse, jsonObject.toString()); }
From source file:org.eclipse.sw360.portal.portlets.projects.ProjectPortlet.java
License:Open Source License
private void saveAttachmentUsages(ResourceRequest request, ResourceResponse response) throws IOException { final String projectId = request.getParameter(PROJECT_ID); AttachmentService.Iface attachmentClient = thriftClients.makeAttachmentClient(); try {//from w w w. j a v a 2 s . c om Project project = getProjectFromRequest(request); User user = UserCacheHolder.getUserFromRequest(request); if (PermissionUtils.makePermission(project, user).isActionAllowed(RequestedAction.WRITE)) { List<AttachmentUsage> deselectedUsagesFromRequest = ProjectPortletUtils .deselectedAttachmentUsagesFromRequest(request); List<AttachmentUsage> selectedUsagesFromRequest = ProjectPortletUtils .selectedAttachmentUsagesFromRequest(request); List<AttachmentUsage> allUsagesByProject = attachmentClient .getUsedAttachments(Source.projectId(projectId), null); List<AttachmentUsage> usagesToDelete = allUsagesByProject.stream() .filter(usage -> deselectedUsagesFromRequest.stream().anyMatch(isUsageEquivalent(usage))) .collect(Collectors.toList()); List<AttachmentUsage> usagesToCreate = selectedUsagesFromRequest.stream() .filter(usage -> allUsagesByProject.stream().noneMatch(isUsageEquivalent(usage))) .collect(Collectors.toList()); if (!usagesToDelete.isEmpty()) { attachmentClient.deleteAttachmentUsages(usagesToDelete); } if (!usagesToCreate.isEmpty()) { attachmentClient.makeAttachmentUsages(usagesToCreate); } writeJSON(request, response, "{}"); } else { response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_FORBIDDEN)); PortletResponseUtil.write(response, "No write permission for project"); } } catch (TException e) { log.error("Saving attachment usages for project " + projectId + " failed", e); response.setProperty(ResourceResponse.HTTP_STATUS_CODE, Integer.toString(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)); } }