in pluto-portal-driver-impl/src/main/java/org/apache/pluto/driver/url/impl/PortalURLParserImpl.java [430:680]
public String toString(RelativePortalURLImpl portalURL) {
StringBuilder buffer = new StringBuilder();
String targetWindow = portalURL.getTargetWindow();
// Make sure the servlet parameters have been processed
portalURL.handleServletRequestParams();
// Append the server URI and the servlet path.
buffer.append(portalURL.getServletPath().startsWith(TOKEN_DELIM)?"":TOKEN_DELIM)
.append(portalURL.getServletPath());
// Start the pathInfo with the path to the render URL (page).
if (portalURL.getRenderPath() != null) {
String p = portalURL.getRenderPath().replaceAll(" ", "%20");
buffer.append(p);
}
// Add the portletIds with references
ArrayList<String> pids = new ArrayList<String>();
for (String pid : portalURL.getPortletIds()) {
pids.add(pid);
buffer.append(TOKEN_DELIM).append(PREFIX).append(PORTLET_ID);
try {
buffer.append(urlEncode(pid));
} catch(Exception e) {
LOG.warn("Could not encode pid=" + pid);
}
buffer.append(DELIM).append(String.valueOf(pids.indexOf(pid)));
}
//Append the resource window definition, if it exists.
URLType portalURLType = portalURL.getType();
if (portalURLType == URLType.Resource) {
int index = pids.indexOf(targetWindow);
if (index < 0) {
StringBuilder txt = new StringBuilder();
txt.append("Resource Window not found in portlet ID list. PID = ")
.append(targetWindow)
.append(", Portlet IDs in map: ")
.append(Arrays.toString(pids.toArray()));
LOG.warn(txt.toString());
} else {
buffer.append(TOKEN_DELIM);
buffer.append(PREFIX).append(RESOURCE).append(String.valueOf(index));
}
}
//Append the render window definition, if it exists.
if (portalURLType == URLType.Render) {
int index = pids.indexOf(targetWindow);
if (index < 0) {
StringBuilder txt = new StringBuilder();
txt.append("Render Window not found in portlet ID list. PID = ")
.append(targetWindow)
.append(", Portlet IDs in map: ")
.append(Arrays.toString(pids.toArray()));
LOG.warn(txt.toString());
} else {
buffer.append(TOKEN_DELIM);
buffer.append(PREFIX).append(RENDER).append(String.valueOf(index));
}
}
// Append the action window definition, if it exists.
if (portalURLType == URLType.Action) {
int index = pids.indexOf(targetWindow);
if (index < 0) {
StringBuilder txt = new StringBuilder();
txt.append("Action Window not found in portlet ID list. PID = ")
.append(targetWindow)
.append(", Portlet IDs in map: ")
.append(Arrays.toString(pids.toArray()));
LOG.warn(txt.toString());
} else {
buffer.append(TOKEN_DELIM);
buffer.append(PREFIX).append(ACTION).append(String.valueOf(index));
}
}
// Add authenticate token if the URL requires authentication
if (portalURL.getAuthenticated()) {
buffer.append(TOKEN_DELIM);
buffer.append(PREFIX).append(AUTHENTICATE)
.append(urlEncode(String.valueOf(portalURL.getAuthenticated())));
}
String reswin = null;
boolean isCacheabilityFull = false;
if (portalURLType == URLType.Resource) {
if (portalURL.getCacheability() != null) {
buffer.append(TOKEN_DELIM);
buffer.append(PREFIX).append(CACHE_LEVEL)
.append(urlEncode(portalURL.getCacheability()));
}
if (portalURL.getResourceID() != null) {
buffer.append(TOKEN_DELIM);
buffer.append(PREFIX).append(RESOURCE_ID)
.append(urlEncode(portalURL.getResourceID()));
}
// Set up cacheability processing. For PORTLET, set
// the resource window so that the only the state for the
// target portlet is set.
if (portalURL.getCacheability().equals(ResourceURL.FULL)) {
isCacheabilityFull = true;
reswin = portalURL.getTargetWindow();
} else if (portalURL.getCacheability().equals(ResourceURL.PORTLET)) {
reswin = portalURL.getTargetWindow();
}
}
// Append portlet mode definitions.
for (String pid : portalURL.getPortletModes().keySet()) {
// special handling for Cacheability = PORTLET or FULL
if (isCacheabilityFull || (reswin != null && !reswin.equals(pid))) {
continue;
}
int index = pids.indexOf(pid);
PortletMode pm = portalURL.getPortletMode(pid);
if (index < 0) {
StringBuilder txt = new StringBuilder("Window not found in portlet ID list. PID = ");
txt.append(pid).append(", PM = ").append(pm.toString())
.append(", Portlet IDs in map: ").append(Arrays.toString(pids.toArray()));
LOG.warn(txt.toString());
} else {
buffer.append(TOKEN_DELIM).append(PREFIX).append(PORTLET_MODE)
.append(String.valueOf(index)).append(DELIM).append(urlEncode(pm.toString()));
}
}
// Append window state definitions.
for (String pid : portalURL.getWindowStates().keySet()) {
// special handling for Cacheability = PORTLET or FULL
if (isCacheabilityFull || (reswin != null && !reswin.equals(pid))) {
continue;
}
int index = pids.indexOf(pid);
WindowState ws = portalURL.getWindowState(pid);
if (index < 0) {
StringBuilder txt = new StringBuilder("Window not found in portlet ID list. PID = ");
txt.append(pid).append(", WS = ").append(ws.toString())
.append(", Portlet IDs in map: ").append(Arrays.toString(pids.toArray()));
LOG.warn(txt.toString());
} else {
buffer.append(TOKEN_DELIM).append(PREFIX).append(WINDOW_STATE)
.append(String.valueOf(index)).append(DELIM).append(urlEncode(ws.toString()));
}
}
// Add the Spring Security CSRF token
if ((portalURLType == URLType.Action) || (portalURLType == URLType.PartialAction)) {
buffer.append(TOKEN_DELIM);
buffer.append(PREFIX);
buffer.append(ACTION_PARAM);
buffer.append(String.valueOf(pids.indexOf(targetWindow)));
buffer.append(DELIM);
buffer.append(portalURL.getCsrfParameterName());
buffer.append(VALUE_DELIM);
buffer.append(portalURL.getCsrfParameterValue());
}
// Append action and render parameters.
for (PortalURLParameter param : portalURL.getParameters()) {
// special handling for Cacheability = PORTLET or FULL
if (reswin != null && !reswin.equals(param.getWindowId())) {
continue;
}
int index = pids.indexOf(param.getWindowId());
if (index < 0) {
LOG.warn("Window not found in portlet ID list. PID = " + param.getWindowId() + ", Param name = " + param.getName());
continue;
}
// Encode render params as a part of the URL.
if (param.getName() != null && param.getValues() != null) {
String valueString = encodeMultiValues(param.getValues());
String ptype = RENDER_PARAM;
if (param.getType().equals(PortalURLParameter.PARAM_TYPE_ACTION)) {
ptype = ACTION_PARAM;
} else if (param.getType().equals(PortalURLParameter.PARAM_TYPE_RESOURCE)) {
ptype = RESOURCE_PARAM;
}
if (!isCacheabilityFull || ptype.equals(RESOURCE_PARAM)) {
buffer.append(TOKEN_DELIM).append(PREFIX).append(ptype)
.append(String.valueOf(index))
.append(DELIM).append(urlEncode(param.getName()))
.append(VALUE_DELIM).append(valueString);
}
}
}
// Add the public render parameters, retaining the grouping information and
// the parameter names for each portlet.
if (!isCacheabilityFull) {
PublicRenderParameterMapper mapper = portalURL.getPublicRenderParameterMapper();
List<Integer> activeIndexes = mapper.getActiveIndexes();
// special handling for Cacheability = PORTLET
if (reswin != null) {
List<PortalURLPublicParameter> pups = mapper.getPRPsForWindow(reswin, true);
activeIndexes = new ArrayList<Integer>();
for (PortalURLPublicParameter pup : pups) {
activeIndexes.add(mapper.getIndex(pup));
}
}
for (int i : activeIndexes) {
String[] values = mapper.getValues(i);
String valstr = encodeMultiValues(values);
// the values for the PRP group need only appear in the URL once
List<PortalURLPublicParameter> prplist = mapper.getPublicParameterGroup(i);
if (prplist.size() > 0) {
PortalURLPublicParameter prp = prplist.get(0);
int index = pids.indexOf(prp.getWindowId());
if (index >= 0) {
buffer.append(TOKEN_DELIM).append(PREFIX).append(PUBLIC_RENDER_PARAM)
.append(String.valueOf(index)).append(DELIM)
.append(String.valueOf(i)).append(DELIM)
.append(urlEncode(prp.getName())).append(VALUE_DELIM)
.append(valstr);
} else {
LOG.warn("window ID not on page for public render parameter: " + prp.toString());
}
}
}
}
// Add fragment identifier if present on render URL
if (portalURLType == URLType.Render) {
String frag = portalURL.getFragmentIdentifier();
if (frag != null) {
if (isTrace) {
LOG.debug("Adding fragment identifier: " + frag);
}
buffer.append('#').append(frag);
}
}
// Construct the string representing the portal URL.
return buffer.toString();
}