Example usage for com.liferay.portal.kernel.util ContentTypes TEXT

List of usage examples for com.liferay.portal.kernel.util ContentTypes TEXT

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util ContentTypes TEXT.

Prototype

String TEXT

To view the source code for com.liferay.portal.kernel.util ContentTypes TEXT.

Click Source Link

Usage

From source file:com.liferay.calendar.service.impl.CalendarResourceLocalServiceImpl.java

License:Open Source License

@Override
public void updateAsset(long userId, CalendarResource calendarResource, long[] assetCategoryIds,
        String[] assetTagNames) throws PortalException {

    assetEntryLocalService.updateEntry(userId, calendarResource.getGroupId(), calendarResource.getCreateDate(),
            calendarResource.getModifiedDate(), CalendarResource.class.getName(),
            calendarResource.getCalendarResourceId(), calendarResource.getUuid(), 0, assetCategoryIds,
            assetTagNames, true, null, null, null, ContentTypes.TEXT, calendarResource.getName(),
            calendarResource.getDescription(), null, null, null, 0, 0, null, false);
}

From source file:com.liferay.dynamic.data.mapping.web.internal.portlet.action.AddTemplateMVCActionCommand.java

License:Open Source License

protected boolean isValidContentType(String contentType) {
    if (contentType.equals(ContentTypes.APPLICATION_XSLT_XML) || contentType.startsWith(ContentTypes.TEXT)) {

        return true;
    }/*from w w  w  .j a  va 2  s  .  co  m*/

    return false;
}

From source file:com.liferay.salesforce.portlet.SalesforceContactsPortlet.java

License:Apache License

public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {

    HttpServletResponse httpServletResponse = PortalUtil.getHttpServletResponse(resourceResponse);
    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
    httpServletResponse.setContentType(ContentTypes.TEXT);

    String requestMethod = ParamUtil.getString(resourceRequest, "type");

    resourceResponse.setContentType(ContentTypes.TEXT_JAVASCRIPT);
    String username = getUsername(resourceRequest);
    try {// w w  w.j a va  2 s  . c  o  m
        if (themeDisplay.isSignedIn() && (requestMethod != null) && requestMethod.equals(_CONTACTS)
                && username != null) {
            MessageBatch messageBatch = SalesforceContactLocalServiceUtil.getContactsByUserName(
                    PortalUtil.getDefaultCompanyId(), username, Arrays.asList(FIELD_NAMES),
                    PortalUtil.getUserId(resourceRequest));

            httpServletResponse.getWriter().print(MessageBatchConverter.getJSONString(messageBatch));

            httpServletResponse.flushBuffer();
        } else if (themeDisplay.isSignedIn() && (requestMethod != null)
                && requestMethod.equals(_CONTACTS_FOR_ACCOUNT) && username != null) {

            String accountId = resourceRequest.getParameter("accId");
            MessageBatch messageBatch = SalesforceContactLocalServiceUtil.getContactsByAccountId(
                    PortalUtil.getDefaultCompanyId(), accountId, Arrays.asList(FIELD_NAMES),
                    PortalUtil.getUserId(resourceRequest));

            httpServletResponse.getWriter().print(MessageBatchConverter.getJSONString(messageBatch));

            httpServletResponse.flushBuffer();
        } else {
            httpServletResponse.getWriter().print("");
            httpServletResponse.flushBuffer();
        }
    } catch (SystemException e) {
        throw new PortletException("Unable to process request", e);
    }
}

From source file:com.liferay.shipping.portlet.ShippingPortlet.java

License:Open Source License

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException, PortletException {

    String shippingExtensionKey = ParamUtil.getString(resourceRequest, "shippingExtensionKey");

    ShippingExtension shippingExtension = _shippingExtensionRegistry.getShippingExtension(shippingExtensionKey);

    if (shippingExtension == null) {
        return;/*w  w  w.j  a v  a  2 s  .co m*/
    }

    PortletContext portletContext = getPortletContext();

    String servletContextName = portletContext.getPortletContextName();

    String resourcePath = servletContextName.concat(TemplateConstants.SERVLET_SEPARATOR)
            .concat("html/view.ftl");

    OutputStream outputStream = resourceResponse.getPortletOutputStream();

    try {
        Template template = getTemplateWithTaglibSupport(resourceRequest, resourceResponse, servletContextName,
                resourcePath);

        String shippingExtensionHTMLFields = shippingExtension.getFieldsHTML(cloneTemplateContext(template));

        resourceResponse.setContentType(ContentTypes.TEXT);

        outputStream.write(shippingExtensionHTMLFields.getBytes(StringPool.UTF8));
    } catch (Exception e) {
        _log.error("Cannot process shipping extension template");
    } finally {
        outputStream.close();
    }
}

From source file:com.liferay.wsrp.consumer.portlet.ConsumerPortlet.java

License:Open Source License

protected void processMimeResponse(PortletRequest portletRequest, javax.portlet.MimeResponse jxMimeResponse,
        MimeResponse mimeResponse) throws Exception {

    String contentType = GetterUtil.get(mimeResponse.getMimeType(), ContentTypes.TEXT_HTML_UTF8);

    jxMimeResponse.setContentType(contentType);

    String charSet = getCharSet(contentType);

    String itemString = mimeResponse.getItemString();
    byte[] itemBinary = mimeResponse.getItemBinary();

    Boolean requiresRewriting = mimeResponse.getRequiresRewriting();

    if (requiresRewriting == null) {
        requiresRewriting = ParamUtil.getBoolean(portletRequest, "wsrp-requiresRewrite");
    }//from  ww  w  . jav a 2  s  . com

    if (requiresRewriting && contentType.contains(ContentTypes.TEXT)) {
        if (itemBinary != null) {
            itemString = new String(itemBinary, charSet);
        }

        itemString = rewriteURLs(portletRequest, jxMimeResponse, itemString);
    }

    if (Validator.isNotNull(itemString)) {
        if (jxMimeResponse instanceof ResourceResponse) {
            ResourceResponse resourceResponse = (ResourceResponse) jxMimeResponse;

            resourceResponse.setContentLength(itemString.length());
        }

        PortletResponseUtil.write(jxMimeResponse, itemString);
    } else if (itemBinary != null) {
        if (jxMimeResponse instanceof ResourceResponse) {
            ResourceResponse resourceResponse = (ResourceResponse) jxMimeResponse;

            resourceResponse.setContentLength(itemBinary.length);
        }

        PortletResponseUtil.write(jxMimeResponse, itemBinary);
    }
}