public static void writeJSON(
      PortletRequest portletRequest, MimeResponse mimeResponse, Object json) throws IOException {

    mimeResponse.setContentType(_getContentType(portletRequest));

    PortletResponseUtil.write(mimeResponse, json.toString());

    mimeResponse.flushBuffer();
  }
  @Override
  public void setContentType(String contentType) {
    if (!_include) {
      if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
          || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

        MimeResponse mimeResponse = _getMimeResponse();

        mimeResponse.setContentType(contentType);
      }
    }
  }
  protected void serveTempImageFile(MimeResponse mimeResponse, InputStream tempImageStream)
      throws Exception {

    ImageBag imageBag = ImageToolUtil.read(tempImageStream);

    byte[] bytes = ImageToolUtil.getBytes(imageBag.getRenderedImage(), imageBag.getType());

    String contentType = MimeTypesUtil.getExtensionContentType(imageBag.getType());

    mimeResponse.setContentType(contentType);

    PortletResponseUtil.write(mimeResponse, bytes);
  }
Пример #4
0
  @Override
  public void serveResource(WebuiRequestContext context) throws Exception {
    super.serveResource(context);

    ResourceRequest req = context.getRequest();
    String nodeURI = req.getResourceID();

    JSONArray jsChilds = getChildrenAsJSON(nodeURI);
    if (jsChilds == null) {
      return;
    }

    MimeResponse res = context.getResponse();
    res.setContentType("text/json");
    res.getWriter().write(jsChilds.toString());
  }
Пример #5
0
 protected void doRender(Map<String, ?> model) throws Exception {
   RequestContext context = getRequestContext();
   ExternalContext externalContext = context.getExternalContext();
   View view = getView();
   PortletContext portletContext = (PortletContext) externalContext.getNativeContext();
   PortletRequest request = (PortletRequest) externalContext.getNativeRequest();
   MimeResponse response = (MimeResponse) externalContext.getNativeResponse();
   if (response.getContentType() == null) {
     // No Portlet content type specified yet -> use the view-determined type.
     // (The Portlet spec requires the content type to be set on the RenderResponse)
     String contentType = view.getContentType();
     if (contentType != null) {
       response.setContentType(contentType);
     }
   }
   request.setAttribute(ViewRendererServlet.VIEW_ATTRIBUTE, view);
   request.setAttribute(ViewRendererServlet.MODEL_ATTRIBUTE, model);
   request.setAttribute(
       org.springframework.web.servlet.support.RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
       context.getActiveFlow().getApplicationContext());
   portletContext
       .getRequestDispatcher(DispatcherPortlet.DEFAULT_VIEW_RENDERER_URL)
       .include(request, response);
 }