The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM

Re: access user attributes in styles_rules

You have to pass your information on the URL to the stylesheet. (You
would want to do that for proper cache partitioning anyway.)

Unfortunately, the cache proxy tag doesn't take parameters. So what you
have to do is get the url output of that tag in a variable and split the
string manually on some known key like /forwardurl/ and insert new
key/value pairs in the URL. The following code would go in head.jspf:

forwardurl="" />
// The tag does not support adding
// new parameters to the URL. So split the cache proxy url at
// the /forwardurl/ parameter to add more parameters.
// NOTE: It normally is not safe to assume the format of
// URLs returned by portal.
String cssUrl = (String)request.getAttribute("cssUrl");

Also, unfortunately, the servlet this URL calls does not know about your
parameters and won't pull them out of the URL and put them in the
request as attributes for you. So, you have to do that manually. The
following code would go in styles_rules.jspf:

// Parse parameters out of PathInfo... The CacheProxyServlet does
// this for attributes it knows about. So, since the servlet does
// not parse all of the parameters we need into the request,
// we have to re-parse the information here. This means that some
// parameters are parsed twice, but that is the only way to get
// all attributes.
//
// Since Styles.jsp is called as a result of a
// RequestDispatcher.forward(),
// the request.getPathInfo() method returns null and not the pathInfo
// passed to the CacheProxyServlet. We have to get that information
// out of a special request atribute named
// javax.servlet.forward.path_info.
boolean foundForwardURL = false;
String pathInfo =
(String)request.getAttribute("javax.servlet.forward.path_info");
if ( null != pathInfo )
{
java.util.StringTokenizer piTokenizer = new
java.util.StringTokenizer( pathInfo, "/" );
while ( piTokenizer.hasMoreTokens() && !foundForwardURL ) {
String param = null;
String value = null;

param = piTokenizer.nextToken();
if ( piTokenizer.hasMoreTokens() ) {
value = piTokenizer.nextToken();
} else {
// If we have a parameter without a value, the URL
// is malformed
throw new java.net.MalformedURLException( "parameter "
+ param + " did not have a value");
}

// Check for a forwardurl parameter. If this is one, the
// remainder of the path info is a URL so we need to stop
// tokenizing. Since the CacheProxyServlet already
// parsed this value and put it in the request, we can
// ignore the remainder of the path info.
if ( "forwardurl".equals( param ) ) {
foundForwardURL = true;
} else {
request.setAttribute( param, value );
}
}
}