@Override
  public String getResponseCharacterEncoding() {

    if (portletResponse instanceof MimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) portletResponse;
      String characterEncoding = mimeResponse.getCharacterEncoding();

      if (manageIncongruities) {
        incongruityContext.setResponseCharacterEncoding(characterEncoding);
      }

      return characterEncoding;
    } else {

      if (manageIncongruities) {
        return incongruityContext.getResponseCharacterEncoding();
      } else {

        if (portletResponse instanceof StateAwareResponse) {

          // TCK TestPage169: getResponseCharacterEncodingActionTest
          // TCK TestPage180: getResponseCharacterEncodingEventTest
          throw new IllegalStateException();
        } else {
          return null;
        }
      }
    }
  }
  /**
   * @see {@link ExternalContext#getResponseOutputStream()}
   * @since JSF 2.0
   */
  @Override
  public OutputStream getResponseOutputStream() throws IOException {

    if (portletResponse instanceof MimeResponse) {

      if (facesImplementationServletResponse != null) {
        logger.debug(
            "Delegating to AFTER_VIEW_CONTENT servletResponse=[{0}]",
            facesImplementationServletResponse);

        return facesImplementationServletResponse.getOutputStream();
      } else {
        MimeResponse mimeResponse = (MimeResponse) portletResponse;

        return mimeResponse.getPortletOutputStream();
      }
    } else {

      if (manageIncongruities) {
        return incongruityContext.getResponseOutputStream();
      } else {
        throw new IllegalStateException();
      }
    }
  }
Example #3
0
  public static PortletURL clone(
      LiferayPortletURL liferayPortletURL, String lifecycle, MimeResponse mimeResponse)
      throws PortletException {

    LiferayPortletURL newURLImpl = null;

    if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
      newURLImpl = (LiferayPortletURL) mimeResponse.createActionURL();
    } else if (lifecycle.equals(PortletRequest.RENDER_PHASE)) {
      newURLImpl = (LiferayPortletURL) mimeResponse.createRenderURL();
    }

    newURLImpl.setPortletId(liferayPortletURL.getPortletId());

    WindowState windowState = liferayPortletURL.getWindowState();

    if (windowState != null) {
      newURLImpl.setWindowState(windowState);
    }

    PortletMode portletMode = liferayPortletURL.getPortletMode();

    if (portletMode != null) {
      newURLImpl.setPortletMode(portletMode);
    }

    newURLImpl.setParameters(liferayPortletURL.getParameterMap());

    return newURLImpl;
  }
  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 flushBuffer() throws IOException {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      mimeResponse.flushBuffer();
    }
  }
  @Override
  public void reset() {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      mimeResponse.reset();
    }
  }
  @Override
  public void setBufferSize(int bufferSize) {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      mimeResponse.setBufferSize(bufferSize);
    }
  }
  @Override
  public int getBufferSize() {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      return mimeResponse.getBufferSize();
    } else {
      return 0;
    }
  }
  @Override
  public String getCharacterEncoding() {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      return mimeResponse.getCharacterEncoding();
    } else {
      return null;
    }
  }
  @Override
  public PrintWriter getWriter() throws IOException {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      return mimeResponse.getWriter();
    } else {
      return UnsyncPrintWriterPool.borrow(new NullServletOutputStream());
    }
  }
  @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);
      }
    }
  }
  @Override
  public void addHeader(String name, String value) {
    if (!_include) {
      if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
          || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

        MimeResponse mimeResponse = _getMimeResponse();

        mimeResponse.setProperty(name, value);
      }
    }
  }
  @Override
  public Locale getLocale() {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      return mimeResponse.getLocale();
    } else {
      return null;
    }
  }
  @Override
  public boolean isCommitted() {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      return mimeResponse.isCommitted();
    } else if (!_include) {
      return false;
    } else {
      return true;
    }
  }
  /**
   * @see {@link ExternalContext#responseReset()}
   * @since JSF 2.0
   */
  @Override
  public void responseReset() {

    if (portletResponse instanceof MimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) portletResponse;
      mimeResponse.reset();
    } else {

      if (manageIncongruities) {
        incongruityContext.responseReset();
      } else {
        throw new IllegalStateException();
      }
    }
  }
  @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());
  }
Example #17
0
  public static PortletURL getCurrent(PortletRequest portletRequest, MimeResponse mimeResponse) {

    PortletURL portletURL = mimeResponse.createRenderURL();

    Enumeration<String> enu = portletRequest.getParameterNames();

    while (enu.hasMoreElements()) {
      String param = enu.nextElement();
      String[] values = portletRequest.getParameterValues(param);

      boolean addParam = true;

      // Don't set paramter values that are over 32 kb. See LEP-1755.

      for (int i = 0; i < values.length; i++) {
        if (values[i].length() > _CURRENT_URL_PARAMETER_THRESHOLD) {
          addParam = false;

          break;
        }
      }

      if (addParam) {
        portletURL.setParameter(param, values);
      }
    }

    return portletURL;
  }
  @Override
  public ServletOutputStream getOutputStream() throws IOException {
    if (_lifecycle.equals(PortletRequest.RENDER_PHASE)
        || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

      MimeResponse mimeResponse = _getMimeResponse();

      OutputStream portletOutputStream = mimeResponse.getPortletOutputStream();

      ServletOutputStream servletOutputStream = new GenericServletOutputStream(portletOutputStream);

      return servletOutputStream;
    } else {
      return new NullServletOutputStream();
    }
  }
  /**
   * @see {@link ExternalContext#isResponseCommitted()}
   * @since JSF 2.0
   */
  @Override
  public boolean isResponseCommitted() {

    if (portletResponse instanceof MimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) portletResponse;
      boolean responseCommitted = mimeResponse.isCommitted();

      if (manageIncongruities) {
        incongruityContext.setResponseCommitted(responseCommitted);
      }

      return responseCommitted;
    } else {

      if (manageIncongruities) {
        return incongruityContext.isResponseCommitted();
      } else {
        throw new IllegalStateException();
      }
    }
  }
  /**
   * @see {@link ExternalContext#getResponseBufferSize()}
   * @since JSF 2.0
   */
  @Override
  public int getResponseBufferSize() {

    if (portletResponse instanceof MimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) portletResponse;
      int responseBufferSize = mimeResponse.getBufferSize();

      if (manageIncongruities) {
        incongruityContext.setResponseBufferSize(responseBufferSize);
      }

      return responseBufferSize;
    } else {

      if (manageIncongruities) {
        return incongruityContext.getResponseBufferSize();
      } else {
        throw new IllegalStateException();
      }
    }
  }
  /** @see {@link ExternalContext#getResponseContentType()} */
  @Override
  public String getResponseContentType() {

    if (portletResponse instanceof MimeResponse) {

      MimeResponse mimeResponse = (MimeResponse) portletResponse;

      String responseContentType = mimeResponse.getContentType();

      if (responseContentType == null) {
        responseContentType = portletRequest.getResponseContentType();
      }

      return responseContentType;
    } else {

      // TCK TestPage173: getResponseContentTypeActionTest
      // TCK TestPage174: getResponseContentTypeEventTest
      throw new IllegalStateException();
    }
  }
  @Override
  public String getResponseCharacterEncoding() {

    if (portletResponse instanceof MimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) portletResponse;
      String characterEncoding = mimeResponse.getCharacterEncoding();

      if (manageIncongruities) {
        incongruityContext.setResponseCharacterEncoding(characterEncoding);
      }

      return characterEncoding;
    } else {

      if (manageIncongruities) {
        return incongruityContext.getResponseCharacterEncoding();
      } else {

        if (portletResponse instanceof StateAwareResponse) {

          String characterEncoding =
              (String)
                  bridgeContext.getAttributes().get(ViewHandlerImpl.RESPONSE_CHARACTER_ENCODING);

          if (characterEncoding != null) {

            // Workaround for patch applied to Mojarra in JAVASERVERFACES-3023
            return characterEncoding;
          } else {

            // TCK TestPage169: getResponseCharacterEncodingActionTest
            // TCK TestPage180: getResponseCharacterEncodingEventTest
            throw new IllegalStateException();
          }
        } else {
          return null;
        }
      }
    }
  }
  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);
  }
  private JSONObject toJSON(UserNode node, MimeResponse res) throws Exception {
    JSONObject json = new JSONObject();
    String nodeId = node.getId();

    json.put("label", node.getEncodedResolvedLabel());
    json.put("hasChild", node.getChildrenCount() > 0);

    UserNode selectedNode = Util.getUIPortal().getNavPath();
    json.put("isSelected", nodeId.equals(selectedNode.getId()));
    json.put("icon", node.getIcon());
    json.put("uri", node.getURI());

    ResourceURL rsURL = res.createResourceURL();
    rsURL.setResourceID(res.encodeURL(node.getURI()));
    json.put("getNodeURL", rsURL.toString());

    JSONArray jsonChildren = new JSONArray();
    for (UserNode child : node.getChildren()) {
      jsonChildren.put(toJSON(child, res));
    }
    json.put("childs", jsonChildren);
    return json;
  }
 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);
 }
  /**
   * @see {@link ExternalContext#responseFlushBuffer()}
   * @since JSF 2.0
   */
  @Override
  public void responseFlushBuffer() throws IOException {

    if (portletResponse instanceof MimeResponse) {

      if (facesImplementationServletResponse != null) {

        // This happens when Mojarra's JspViewHandlingStrategy#buildView(FacesContext context,
        // UIViewRoot)
        // executes.
        facesImplementationServletResponse.flushBuffer();
      } else {
        MimeResponse mimeResponse = (MimeResponse) portletResponse;
        mimeResponse.flushBuffer();
      }
    } else {

      if (manageIncongruities) {
        incongruityContext.responseFlushBuffer();
      } else {
        throw new IllegalStateException();
      }
    }
  }