Package org.apache.myfaces.portlet.faces.util

Examples of org.apache.myfaces.portlet.faces.util.QueryString


    return viewId;
  }

  private void updateViewChainAttribute(String mode, String viewId, boolean modeChanged)
  {
    QueryString qs = new QueryString("UTF8");
   
    // always encode the mode in the viewId as this is used for mode transitions
    qs.setParameter(Bridge.PORTLET_MODE_PARAMETER, mode);
   
    if (!modeChanged)
    {
        // Build a QueryString from the request's render parameters so can preserve
      // with the viewId
      Map m = getRequestParameterValuesMap();
      if (!m.isEmpty())
      {
        Set <Map.Entry<String, String[]>> set = m.entrySet();
        Iterator <Map.Entry<String,String[]>> i = set.iterator();
        while (i.hasNext()) 
        {
          Map.Entry<String,String[]> e = i.next();
          // only add is not a viewId parameter
          if (!e.getKey().equals(JSF_TARGET_VIEWID_RENDER_PARAMETER))
          {
            for (String s : e.getValue())
            {
              qs.addParameter(e.getKey(), s);
            }
          }
        }
      }
    }
       
    String toAppend = qs.toString();
    StringBuffer sb = new StringBuffer(viewId.length() + toAppend.length() + 1);
    viewId = sb.append(viewId).append("?").append(toAppend).toString();
     
    // Now add to the appropriate session attribute based on Mode
    Map sessionMap = getSessionMap();
View Full Code Here


  private String replaceResourceQueryStringMarkers(String s, boolean hasBackLink,
                                                   boolean hasViewLink)
  {
    String path = null;
    QueryString queryStr = null;
    int queryStart = -1;

    // First: split URL into path and query string
    // Hold onto QueryString for later processing
    queryStart = s.indexOf('?');

    // references aren't in the querystring so nothing to do
    if (queryStart == -1)
      return s;

    FacesContext context = FacesContext.getCurrentInstance();

    queryStr = new QueryString(s.substring(queryStart + 1), "UTF8");
    path = s.substring(0, queryStart);

    if (hasBackLink)
    {
      Enumeration<String> list = queryStr.getParameterNames();
      while (list.hasMoreElements())
      {
        String param = list.nextElement().toString();
        if (hasBackLink && param.equals(Bridge.BACK_LINK))
        {
          try
          {
            // Set backlink as parameter using value as param name
            queryStr.setParameter(queryStr.getParameter(param),
                                encodeActionURL(context.getApplication().getViewHandler().getActionURL(context,
                                                                                                       context.getViewRoot().getViewId())));
            ;
          }
          catch (Exception e)
          {
            ; // do nothing -- just ignore
          }
        }
      }
    }
   
    // Now make sure the parameters are removed
    try
    {
      queryStr.removeParameter(Bridge.BACK_LINK);
      queryStr.removeParameter(Bridge.VIEW_LINK);
    }
    catch (Exception e)
    {
      ; // do nothing -- just ignore
   

    // Now put the string back together
    String qs = queryStr.toString();
    if (qs.length() > 0)
    {
      s = path + "?" + qs;
    }
    else
View Full Code Here

  }
 
  private boolean isTokenLink(String token, String url)
  {
    int queryStart = url.indexOf('?');
    QueryString queryStr = null;
    String tokenParam = null;

    if (queryStart != -1)
    {
      queryStr = new QueryString(url.substring(queryStart + 1), "UTF8");
      tokenParam = queryStr.getParameter(token);
      return Boolean.parseBoolean(tokenParam);
    }

    return false;
  }
View Full Code Here

  }
 
  private String removeTokenLink(String token, String url)
  {
    int queryStart = url.indexOf('?');
    QueryString queryStr = null;

    if (queryStart != -1)
    {
      queryStr = new QueryString(url.substring(queryStart + 1), "UTF8");
      queryStr.removeParameter(token);
      String query = queryStr.toString();
      if (query != null && query.length() != 0)
      {
        url = url.substring(0, queryStart + 1) + query;
      }
      else
View Full Code Here

    List<String> preExistingAttributes = getRequestAttributes(request);

    // Now check to see if this is a Refresh (render) that follows a redirect
    // If it is use the redirect information cached in the session as the basis
    // for the request.
    QueryString redirectParams = (QueryString)
              request.getPortletSession(true).getAttribute(BridgeImpl.RENDER_REDIRECT_VIEWPARAMS);

    if (redirectParams != null && hasModeChanged(request, redirectParams)) 
    {
      // if we are too rely on the render redirect cache we must still
View Full Code Here

    }


    // 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)
    {
      // In resource case and/or redirect overriden responseComplete
View Full Code Here

        .append(mode)
        .toString();
    }
    else
    {
      QueryString qs = new QueryString(viewId.substring(queryStart + 1), "UTF8");
      qs.setParameter(Bridge.PORTLET_MODE_PARAMETER, mode);
      return sb.append(viewId.substring(0, queryStart + 1)).append(qs.toString()).toString();
    }
  }
View Full Code Here

    // Redirects to a view are dealt (elsewhere) as navigations --
    // encode this information for later use by the bridge controller.
    // Other links are redirected.
   
    // First look to see if this is an already encoded
    QueryString params = (QueryString) getRequestMap().get(ENCODED_ACTION_URL_ATTRIBUTE_PREFIX.concat(url));
    if (params != null)
    {
      // Because we want to support translating a redirect that occurs
      // during a render as an in place navigation AND we can't reverse
      // engineer the URL from the actionURL, we stash the original URL on
View Full Code Here

    // Redirects to a view are dealt (elsewhere) as navigations --
    // encode this information for later use by the bridge controller.
    // Other links are ignored.
   
    // First look to see if this is an already encoded
    QueryString params = (QueryString) getRequestMap().get(ENCODED_ACTION_URL_ATTRIBUTE_PREFIX.concat(url));
    if (params != null)
    {
      // Only can redirect to other Faces views in an event request
      if (params.getParameter(JSF_TARGET_VIEWID_RENDER_PARAMETER) != null)
      {
        // Because we want to support translating a redirect that occurs
        // during a render as an in place navigation AND we can't reverse
        // engineer the URL from the actionURL, we stash the original URL on
        // a request attribute, keyed with the generated URL.  If this generated
View Full Code Here

    // do it then even if we subsequently don't need it because its not a
    // Faces resource.
   
    // Determine if there is a target viewId
    String viewId = null, path = null;
    QueryString queryStr = null;
    int queryStart = -1;

    // First: split URL into path and query string
    // Hold onto QueryString for later processing
    queryStart = url.indexOf('?');

    if (queryStart != -1)
    {
      // Get the query string
      queryStr = new QueryString(url.substring(queryStart + 1), "UTF8");
      path = url.substring(0, queryStart);
    }
    else
    {
      path = url;
      // construct an empty queryString to hold the viewId
      queryStr = new QueryString("UTF8");
    }
   
    // Now remove up through the ContextPath as we don't want it
    String ctxPath = getRequestContextPath();
    int i = path.indexOf(ctxPath);
    if (i != -1)
    {
      path = path.substring(i + ctxPath.length());
    }
   
    // Determine the viewId by inspecting the URL
    // Can't be relative by the time we get here so don't check
    viewId = getViewIdFromPath(path);
   
    // TODO: Handle the case where this is a nonFaces (inprotocol) resource
    // I.e. viewId is null here.  Should we do something similar to
    // nonFaces support from 1.0?  I.e. bridge isn't expecting to handle?

    if (viewId != null)
    {
      // This is a Faces resource
      // put the viewId in the QueryStr.
      queryStr.addParameter(JSF_RESOURCE_TARGET_VIEWID_RENDER_PARAMETER, viewId);
      queryStr.removeParameter(Bridge.PORTLET_MODE_PARAMETER);
      queryStr.removeParameter(Bridge.PORTLET_WINDOWSTATE_PARAMETER);
    }
   

    // Encode the URL
   
    ResourceURL resource = ((MimeResponse) mPortletResponse).createResourceURL();
    resource.setResourceID(path);
   
    // Walk through the queryStr Params and add as resourceParams
    // remove any attempt to set Mode/WindowState/etc. as
    // not feasible here
    // Add parameters so they don't get lost
    Enumeration<String> list = queryStr.getParameterNames();
    while (list.hasMoreElements())
    {
      String param = list.nextElement().toString();
      if (param.equals(Bridge.PORTLET_MODE_PARAMETER))
      {
        // do nothing -- just ignore -- can't encode in a resourceURL
      }
      else if (param.equals(Bridge.PORTLET_WINDOWSTATE_PARAMETER))
      {
        // do nothing -- just ignore -- can't encode in a resourceURL
      }
      else if (param.equals(Bridge.PORTLET_SECURE_PARAMETER))
      {
        try
        {
          resource.setSecure(Boolean.getBoolean(queryStr.getParameter(param)));
        }
        catch (Exception e)
        {
          ; // do nothing -- just ignore
        }
      }
      else
      {
        resource.setParameter(param, queryStr.getParameter(param));
      }
    }

    return resource.toString().replaceAll("\\&amp\\;", "&");
  }
View Full Code Here

TOP

Related Classes of org.apache.myfaces.portlet.faces.util.QueryString

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.