// 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("\\&\\;", "&");
}