Package javax.portlet

Examples of javax.portlet.MimeResponse


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

        MimeResponse res = context.getResponse();
        res.setContentType("text/json");
        res.getWriter().write(jsChilds.toString());
    }
View Full Code Here


        }
        Collection<UserNode> childs = userNode.getChildren();

        JSONArray jsChilds = new JSONArray();
        WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
        MimeResponse res = context.getResponse();
        for (UserNode child : childs) {
            jsChilds.put(toJSON(child, userNode.getNavigation().getKey().getName(), res));
        }
        return jsChilds;
    }
View Full Code Here

        JsonObject parameters = super.getApplicationParameters(context);
        VaadinPortletResponse response = (VaadinPortletResponse) context
                .getResponse();
        VaadinPortletRequest request = (VaadinPortletRequest) context
                .getRequest();
        MimeResponse portletResponse = (MimeResponse) response
                .getPortletResponse();
        ResourceURL resourceURL = portletResponse.createResourceURL();
        resourceURL.setResourceID("v-browserDetails");
        parameters.put("browserDetailsUrl", resourceURL.toString());

        // Always send path info as a query parameter
        parameters
View Full Code Here

  protected ModelAndView doHandle(PortletRequest request, PortletResponse response, Object handler) throws Exception {
    ExtendedModelMap implicitModel = null;

    if (response instanceof MimeResponse) {
      MimeResponse mimeResponse = (MimeResponse) response;
      // Detect implicit model from associated action phase.
      if (response instanceof RenderResponse) {
        PortletSession session = request.getPortletSession(false);
        if (session != null) {
          if (request.getParameter(IMPLICIT_MODEL_RENDER_PARAMETER) != null) {
View Full Code Here

    { // render - write
      // the viewId into
      // the response
      // (interaction
      // state)
      MimeResponse mimeResponse = (MimeResponse) getResponse();
      PortletURL actionURL = null;
      ResourceURL resourceURL = null;
      BaseURL baseURL = null;
      // Non-JSF actions are renderURLs as we merely dispatch to them
      if (urlType == Bridge.PortletPhase.ACTION_PHASE)
      {
        baseURL = actionURL = mimeResponse.createActionURL();
      }
      else if (urlType == Bridge.PortletPhase.RESOURCE_PHASE)
      {
        baseURL = resourceURL = mimeResponse.createResourceURL();
      }
      else
      {
        baseURL = actionURL = mimeResponse.createRenderURL();
      }

      // Add parameters so they don't get lost
      Enumeration<String> list = queryStr.getParameterNames();
      while (list.hasMoreElements())
View Full Code Here

      super.renderView(context, viewToRender);
      return;
    }
   
    ExternalContext extContext = context.getExternalContext();
    MimeResponse mimeResponse = (MimeResponse) extContext.getResponse();

    // If first time -- Get the renderPolicy from the context init parameter
    if (mRenderPolicy == null)
    {
      PortletContext pCtx = (PortletContext) context.getExternalContext().getContext();
      String policy = pCtx.getInitParameter(Bridge.RENDER_POLICY);
      if (policy != null)
      {
        mRenderPolicy = Bridge.BridgeRenderPolicy.valueOf(policy);
      }
      else
      {
        mRenderPolicy = Bridge.BridgeRenderPolicy.DEFAULT;
      }
    }

    if (mRenderPolicy == Bridge.BridgeRenderPolicy.ALWAYS_DELEGATE)
    {
      super.renderView(context, viewToRender);
      return;
    }
    else if (mRenderPolicy == Bridge.BridgeRenderPolicy.DEFAULT)
    {
      try
      {
        super.renderView(context, viewToRender);
        return;
      }
      catch (Throwable t)
      {
        // catch all throws and swallow -- falling through to our own

        // render -- Note because delegate may have set the Response object and
        // not cleaned it up on the exception -- reset to ensure a good object
        if (!mimeResponse.equals(extContext.getResponse()))
        {
          extContext.setResponse(mimeResponse);
        }
      }
    }

    // suppress rendering if "rendered" property on the component is
    // false
    if (!viewToRender.isRendered())
    {
      return;
    }

    try
    {
      extContext.getRequestMap().remove("javax.servlet.include.servlet_path");
      dispatchPageToBuildView(context, extContext, viewToRender);
    }
    catch (IOException e)
    {
      throw new FacesException(e);
    }
   
    // If a redirect occurred -- merely return
    // check here to see if a redirect occurred -- if so rerun doFacesRequest
    // for this new view
    QueryString redirectParams = (QueryString) context.getExternalContext()
                      .getRequestMap().get(BridgeImpl.REDIRECT_VIEWPARAMS);
    if ((redirectParams != null))
    {
      // redirect must have occurred during dispatch
     
      // set a flag indicating we are in a renderRedirect so the ViewHandler will know to dispatch.include instead of forward
      // mark it as such so the next dispatch will use an include
      extContext.getRequestMap().put(BridgeImpl.HAS_RENDER_REDIRECTED_AFTER_FORWARD, Boolean.TRUE);
      return;
    }

    // set up the ResponseWriter
    RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder
                                                                     .getFactory(FactoryFinder.RENDER_KIT_FACTORY);
    RenderKit renderKit = renderFactory.getRenderKit(context, viewToRender.getRenderKitId());

    ResponseWriter oldWriter = context.getResponseWriter();
    StringBuilderWriter strWriter = new StringBuilderWriter(context, 4096);
    ResponseWriter newWriter;
    if (null != oldWriter)
    {
      newWriter = oldWriter.cloneWithWriter(strWriter);
    }
    else
    {
      newWriter = renderKit.createResponseWriter(strWriter, null,
                                                 mimeResponse.getCharacterEncoding());
    }
    context.setResponseWriter(newWriter);

    newWriter.startDocument();

    doRenderView(context, viewToRender);

    newWriter.endDocument();
   
    // Check again to see if the processing of the Faces view triggered a redirect
    redirectParams = (QueryString) context.getExternalContext()
                      .getRequestMap().get(BridgeImpl.REDIRECT_VIEWPARAMS);
    if ((redirectParams != null))
    {
      // set a flag indicating we are in a renderRedirect so the ViewHandler will know to dispatch.include instead of forward
      // mark it as such so the next dispatch will use an include
      extContext.getRequestMap().put(BridgeImpl.HAS_RENDER_REDIRECTED_AFTER_FORWARD, Boolean.TRUE);
      return;
    }   

    // replace markers in the body content and write it to response.

    ResponseWriter responseWriter;

    // Dispatch may have output to an OutputStream instead of a Writer
    Writer renderResponseWriter = null;
    try {
      renderResponseWriter = mimeResponse.getWriter();
    }
    catch (IllegalStateException ise) {    
      // got this exception because we've called getOutputStream() previously
      renderResponseWriter = new BufferedWriter(
                             new OutputStreamWriter(
                               mimeResponse.getPortletOutputStream(),
                               mimeResponse.getCharacterEncoding()));
    }
    if (null != oldWriter)
    {
      responseWriter = oldWriter.cloneWithWriter(renderResponseWriter);
    }
    else
    {
      responseWriter = newWriter.cloneWithWriter(renderResponseWriter);
    }
    context.setResponseWriter(responseWriter);

    strWriter.write(responseWriter);
    renderResponseWriter.flush();

    if (null != oldWriter)
    {
      context.setResponseWriter(oldWriter);
    }

    Object content = extContext.getRequestMap().get(Bridge.AFTER_VIEW_CONTENT);
    if (content != null)
    {
      try
      {
        if (content instanceof char[])
        {
          mimeResponse.getWriter().write(new String((char[]) content));
        }
        else if (content instanceof byte[])
        {
          mimeResponse.getWriter().write(new String((byte[]) content));
        }
        else
        {
          throw new IOException("PortletViewHandlerImpl: invalid" + "AFTER_VIEW_CONTENT buffer type");
        }
      }
      finally
      {
        // So it doesn't geet reused accidentaly
        extContext.getRequestMap().remove(Bridge.AFTER_VIEW_CONTENT);
      }
    }
    mimeResponse.flushBuffer();
  }
View Full Code Here

      // before the JSTL setBundle tag is called because that is when the
      // new LocalizationContext object is created based on the locale.
      extContext.getRequestMap().put("javax.servlet.jsp.jstl.fmt.locale", context.getViewRoot().getLocale());

      // save the original response
      MimeResponse originalResponse = (MimeResponse) extContext.getResponse();

      // see whether the portlet wants to use a writeBehindResponse(Wrapper)
      Class<? extends BridgeWriteBehindResponse> writeBehindResponseWrapperClass = (Class<? extends BridgeWriteBehindResponse>) extContext.getRequestMap().get(Bridge.BRIDGE_PACKAGE_PREFIX + Bridge.WRITE_BEHIND_RESPONSE);
      BridgeWriteBehindResponse wrapped = null;
      if (writeBehindResponseWrapperClass != null)
View Full Code Here

    final String viewId = facesContext.getViewRoot().getViewId();
    final String formAction = externalContext.encodeActionURL(viewHandler.getActionURL(facesContext, viewId));
    final String partialAction;
    final boolean portlet = PortletUtils.isPortletApiAvailable() && response instanceof MimeResponse;
    if (portlet) {
      final MimeResponse mimeResponse = (MimeResponse) response;
      final ResourceURL resourceURL = mimeResponse.createResourceURL();
      partialAction = externalContext.encodeResourceURL(resourceURL.toString());
    } else {
      partialAction = null;
    }
View Full Code Here

      }
      cookies = null;
    }
    if (isMimeResponse)
    {
      MimeResponse mimeResponse = (MimeResponse)response;
      RenderResponse renderResponse = isRenderResponse ? (RenderResponse)response : null;
      ResourceResponse resourceResponse = isResourceResponse ? (ResourceResponse)response
        : null;

      if (locale != null)
      {
        try
        {
          resourceResponse.setLocale(locale);
        }
        catch (UnsupportedOperationException usoe)
        {
          // TODO: temporary "fix" for JBoss Portal which doesn't yet support this
          // (although required by the Portlet API 2.0!)
        }
      }

      if (contentType != null)
      {
        if (characterEncoding != null)
        {
          if (setContentTypeAfterEncoding)
          {
            resourceResponse.setCharacterEncoding(characterEncoding);
            resourceResponse.setContentType(contentType);
          }
          else
          {
            resourceResponse.setContentType(contentType);
            resourceResponse.setCharacterEncoding(characterEncoding);
          }
        }
        else
        {
          mimeResponse.setContentType(contentType);
        }
      }
      else if (characterEncoding != null)
      {
        resourceResponse.setCharacterEncoding(characterEncoding);
      }

      if (headers != null)
      {
        for (Map.Entry<String, ArrayList<String>> entry : headers.entrySet())
        {
          for (String value : entry.getValue())
          {
            mimeResponse.addProperty(entry.getKey(), value);
          }
        }
        headers = null;
      }
      if (isResourceResponse && hasStatus)
      {
        resourceResponse.setProperty(ResourceResponse.HTTP_STATUS_CODE,
          Integer.toString(statusCode));
      }
      if (isResourceResponse && contentLength > -1)
      {
        try
        {
          resourceResponse.setContentLength(contentLength);
        }
        catch (UnsupportedOperationException usoe)
        {
          // TODO: temporary "fix" for JBoss Portal which doesn't yet support this
          // (although required by the Portlet API 2.0!)
        }
      }
      if (!hasError && redirectLocation == null)
      {
        if (outputStream != null)
        {
          if (!closed)
          {
            outputStream.flush();
          }
          OutputStream realOutputStream = mimeResponse.getPortletOutputStream();
          int len = byteOutputBuffer.size();
          if (contentLength > -1 && contentLength < len)
          {
            len = contentLength;
          }
          if (len > 0)
          {
            realOutputStream.write(byteOutputBuffer.toByteArray(), 0, len);
          }
          outputStream.close();
          outputStream = null;
          byteOutputBuffer = null;
        }
        else if (printWriter != null)
        {
          if (!closed)
          {
            printWriter.flush();
            if (charOutputBuffer.getCount() > 0)
            {
              mimeResponse.getWriter().write(charOutputBuffer.getBuffer(), 0,
                charOutputBuffer.getCount());
            }
            printWriter.close();

            printWriter = null;
View Full Code Here

    final String viewId = facesContext.getViewRoot().getViewId();
    final String formAction = externalContext.encodeActionURL(viewHandler.getActionURL(facesContext, viewId));
    final String partialAction;
    final boolean portlet = PortletUtils.isPortletApiAvailable() && response instanceof MimeResponse;
    if (portlet) {
      final MimeResponse mimeResponse = (MimeResponse) response;
      final ResourceURL resourceURL = mimeResponse.createResourceURL();
      partialAction = externalContext.encodeResourceURL(resourceURL.toString());
    } else {
      partialAction = null;
    }
View Full Code Here

TOP

Related Classes of javax.portlet.MimeResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.