Hi,
I've been doing a little playing with the xsl taglib, specifically in
the area of user targeted data. One aspect is the dynamic generation of
XSL based upon the Accept-Language header (ie. multi-lingual XSL
templates).
The import tag is ideal for fetching the dynamic XSL, but unfortunately
does not pass the request headers on to the imported page request. As a
result, the generated XSL isn't dynamic!
This patch allows none, some ("basic") or all of the request headers to
be passed on to the requested document, based on an additional attribute
to the import tag - "requestHeaders". By default, this is the basic list
(Accept, Accept-Charset, Accept-Encoding, Accept-Language,
Authorization, Cookie, Referer, User-Agent and Via), but it could be
argued that 'none' is the default action (since that was what it was
originally) - however, there wasn't any useful information passed, so
no-one would've probably used it anyway!
--8<--8<--8<-- Patch start --8<--8<--8<--
diff -uNr xsl-old/conf/taglib.tld xsl/conf/taglib.tld
--- xsl-old/conf/taglib.tld Mon Jun 4 11:49:23 2001
+++ xsl/conf/taglib.tld Tue Jun 5 17:18:55 2001
@@ -164,6 +164,10 @@
scope Scope in which the bean specified by "id"
will be
created (page, request, session,
application). If
not specified, page scope is assumed.
+
+ requestHeaders Enables/disables sending of request headers
(none,
+ basic, all). If not specified, basic
+ requestHeaders are assumed.
</info>
<attribute>
<name>id</name>
@@ -177,6 +181,11 @@
</attribute>
<attribute>
<name>scope</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ </attribute>
+ <attribute>
+ <name>requestHeaders</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
diff -uNr xsl-old/src/org/apache/taglibs/xsl/ImportTag.java
xsl/src/org/apache/taglibs/xsl/ImportTag.java
--- xsl-old/src/org/apache/taglibs/xsl/ImportTag.java Mon Jun 4
11:49:23 2001
+++ xsl/src/org/apache/taglibs/xsl/ImportTag.java Wed Jun 6
12:36:21 2001
@@ -65,6 +65,7 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
+import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
@@ -127,6 +128,30 @@
}
+ /**
+ * If we need to send the request headers to the fetched page.
+ */
+ private String requestHeaders = "basic";
+
+ public String getRequestHeaders() {
+ return (this.requestHeaders);
+ }
+
+ public void setRequestHeaders(String requestHeaders) {
+ this.requestHeaders = requestHeaders;
+ }
+
+
+ /**
+ * List of basic request headers
+ */
+
+ private String[] basicHeaders = {"Accept", "Accept-Charset",
+ "Accept-Encoding", "Accept-Language",
+ "Authorization", "Cookie", "Referer",
+ "User-Agent", "Via"};
+
+
// --------------------------------------------------------- Public
Methods
@@ -156,6 +181,11 @@
else
throw new JspException("Invalid scope value '" + scope +
"'");
+ if (("all".equalsIgnoreCase(requestHeaders) == false)
+ && ("basic".equalsIgnoreCase(requestHeaders) == false)
+ && ("none".equalsIgnoreCase(requestHeaders) == false))
+ throw new JspException("Invalid requestHeaders value '" +
requestHeaders + "'");
+
// Set up the buffer to which we will write (if id is set)
StringBuffer sb = new StringBuffer();
@@ -178,6 +208,27 @@
URLConnection conn = null;
try {
conn = (new URL(url.toString())).openConnection();
+
+ // Copy over request headers if necessary
+ if ("all".equalsIgnoreCase(requestHeaders)) {
+ for(Enumeration headers = request.getHeaderNames();
headers.hasMoreElements(); ) {
+ String header = (String) headers.nextElement();
+ for(Enumeration values = request.getHeaders(header);
values.hasMoreElements(); ) {
+ String value = (String) values.nextElement();
+ conn.setRequestProperty(header, value);
+ }
+ }
+ }
+ else if ("basic".equalsIgnoreCase(requestHeaders)) {
+ for(int h = 0; h < basicHeaders.length; ++h) {
+ String header = basicHeaders[h];
+ for(Enumeration values = request.getHeaders(header);
values.hasMoreElements(); ) {
+ String value = (String) values.nextElement();
+ conn.setRequestProperty(header, value);
+ }
+ }
+ }
+
conn.setAllowUserInteraction(false);
conn.setDoInput(true);
conn.setDoOutput(false);
--8<--8<--8<-- Patch end --8<--8<--8<--
--
Jason Tribbeck Development Tools Team Manager
Argogroup
t: +44 (0) 1252 705743 f: +44 (0) 1252
705 706
e: [EMAIL PROTECTED] w:
http://www.argogroup.com/
------------------------------------------------------------------------
-----
This e-mail (including any attachments) is intended only for the
recipient(s)
named above. It may contain confidential or privileged information and
should
not be read, copied or otherwise used by any other person. If you are
not a
named recipient, please contact the sender and delete the e-mail from
your
system.
------------------------------------------------------------------------
-----