Sully,

Looking into the code, the way the CLI handles user agent strings does not make sense (and come to think of it, I have often wondered about why it is like that).

I have coded (but not tested _at all_) a patch that switches the CLI to pass the user agent and accept strings as headers). I'm afraid my dev environment is broken at present and I don't have the time to fix it just yet.

I have attached this patch, that I think should make it work. Let me know if you're able/not able to make anything of it.

Sorry I can't help more right now.

Regards, Upayavira

Sully wrote:

Hi All,

I'm wanting to use a different stylesheet depending if it's the CLI looking at the page or a normal browser, the way I'm doing it is working fine online though won't work offline, changing user agents to what I'm setting the cli to is showing the correct display, however when I'm generating via the CLI it's never being selected, which I can only assume means that it's not passing the user-agent correctly.

I'm using a clean install of 2.1.3 (latest from the website), jvm is 1.4.1 running on linux

I've included the relevant portions (simplified) of my sitemap below

<browser name="CLI" useragent="CLI"/>

<map:match.................
.............
<map:select type="browser">
    <map:when test="CLI">
        <map:transform src="stylesheets/offline.xsl"></map:transform>
    </map:when>
    <map:otherwise>
        <map:transform src="stylesheets/online.xsl"></map:transform>
    </map:otherwise>
</map:select>
............

and the relevant portion of cli.xconf is

<user-agent>CLI 2.1</user-agent>

I have attempted setting -a "CLI 2.1" on the command line without any difference.

if I have my browser set to CLI 2.1 then I am able to view the content generated by offline.xsl

any help greatly appreciated!



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Index: src/java/org/apache/cocoon/bean/CocoonWrapper.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/bean/CocoonWrapper.java,v
retrieving revision 1.10
diff -u -r1.10 CocoonWrapper.java
--- src/java/org/apache/cocoon/bean/CocoonWrapper.java  17 Nov 2003 03:01:12 -0000     
 1.10
+++ src/java/org/apache/cocoon/bean/CocoonWrapper.java  3 Dec 2003 09:09:13 -0000
@@ -495,8 +495,9 @@
     protected Collection getLinks(String deparameterizedURI, Map parameters)
         throws Exception {
 
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
+        Map headers =  new HashMap();
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
 
         LinkSamplingEnvironment env =
             new LinkSamplingEnvironment(deparameterizedURI, context, attributes,
@@ -523,13 +524,14 @@
                           OutputStream stream)
     throws Exception {
 
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
-
+        Map headers =  new HashMap();
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
+        
         FileSavingEnvironment env =
             new FileSavingEnvironment(deparameterizedURI, lastModified, context,
                                       attributes, parameters, links,
-                                      gatheredLinks, cliContext, stream, log);
+                                      gatheredLinks, cliContext, stream, log, 
headers);
 
         // Here Cocoon can throw an exception if there are errors in processing the 
page
         cocoon.process(env);
@@ -563,13 +565,14 @@
     protected String getType(String deparameterizedURI, Map parameters)
         throws Exception {
         
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
+        Map headers =  new HashMap();
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
 
         FileSavingEnvironment env =
-            new FileSavingEnvironment(deparameterizedURI, context, attributes,
+            new FileSavingEnvironment(deparameterizedURI, 0L, context, attributes,
                                       parameters, empty, null, cliContext,
-                                      new NullOutputStream(), log);
+                                      new NullOutputStream(), log, headers);
         processLenient(env);
         return env.getContentType();
     }
Index: src/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java
===================================================================
RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java,v
retrieving revision 1.5
diff -u -r1.5 FileSavingEnvironment.java
--- src/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java      
 16 Nov 2003 00:52:08 -0000      1.5
+++ src/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java      
 3 Dec 2003 09:09:15 -0000
@@ -83,10 +83,27 @@
                                  CommandLineContext cliContext,
                                  OutputStream stream,
                                  Logger log)
+                                 throws MalformedURLException {
+
+        this(uri, 0L, context, attributes, parameters, links, gatheredLinks, 
cliContext, stream, log, null);
+    }
+
+    public FileSavingEnvironment(String uri,
+                                 long lastModified,
+                                 File context,
+                                 Map attributes,
+                                 Map parameters,
+                                 Map links,
+                                 List gatheredLinks,
+                                 CommandLineContext cliContext,
+                                 OutputStream stream,
+                                 Logger log,
+                                 Map headers
+                                 )
     throws MalformedURLException {
         super(uri, null, context, stream, log);
         this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT,
-                             new CommandLineRequest(this, null, uri, null, 
attributes, parameters));
+                             new CommandLineRequest(this, null, uri, null, 
attributes, parameters, headers));
         this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
                              new CommandLineResponse());
         this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,
Index: src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java
===================================================================
RCS file: 
/home/cvs/cocoon-2.1/src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java,v
retrieving revision 1.6
diff -u -r1.6 LinkSamplingEnvironment.java
--- src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java    
 16 Nov 2003 00:52:08 -0000      1.6
+++ src/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java    
 3 Dec 2003 09:09:15 -0000
@@ -83,12 +83,23 @@
                                    CommandLineContext cliContext,
                                    Logger log)
     throws MalformedURLException, IOException {
+        this(uri, contextFile, attributes, parameters, cliContext, log, null);
+    }
+
+    public LinkSamplingEnvironment(String uri,
+                                   File contextFile,
+                                   Map attributes,
+                                   Map parameters,
+                                   CommandLineContext cliContext,
+                                   Logger log,
+                                   Map headers)
+    throws MalformedURLException, IOException {
         super(uri, Constants.LINK_VIEW, contextFile, new ByteArrayOutputStream(), 
log);
         if (getLogger().isDebugEnabled()) {
             getLogger().debug("uri = " + uri);
         }
         this.objectModel.put(ObjectModelHelper.REQUEST_OBJECT,
-                             new CommandLineRequest(this, null, uri, null, 
attributes, parameters));
+                             new CommandLineRequest(this, null, uri, null, 
attributes, parameters, headers));
         this.objectModel.put(ObjectModelHelper.RESPONSE_OBJECT,
                              new CommandLineResponse());
         this.objectModel.put(ObjectModelHelper.CONTEXT_OBJECT,

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to