cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r399270 - in /cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon: bean/CocoonBean.java bean/CocoonWrapper.java environment/commandline/FileSavingEnvironment.java environment/commandline/LinkSamplingEnvironment.java
Date Wed, 03 May 2006 11:50:13 GMT
Author: cziegeler
Date: Wed May  3 04:50:11 2006
New Revision: 399270

URL: http://svn.apache.org/viewcvs?rev=399270&view=rev
Log:
Commandline interface: the user-agent is now correctly set in the request headers (and not
in the request parameters).
Fixes bug COCOON-1511

Modified:
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java
    cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java?rev=399270&r1=399269&r2=399270&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java Wed
May  3 04:50:11 2006
@@ -48,6 +48,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.TreeMap;
 
 /**
  * <p>The Cocoon Bean simplifies usage of the Cocoon object. Allows to create,
@@ -488,11 +489,15 @@
                     gatheredLinks = null;
                 }
 
+                final TreeMap headers = new TreeMap();
+                headers.put("user-agent", userAgent);
+                headers.put("accept", accept);
                 status =
                     getPage(
                         target.getDeparameterizedSourceURI(),
                         getLastModified(target),
                         target.getParameters(),
+                        headers,
                         target.confirmExtensions() ? translatedLinks : null,
                         gatheredLinks,
                         output);

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java?rev=399270&r1=399269&r2=399270&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java
Wed May  3 04:50:11 2006
@@ -69,8 +69,8 @@
     private String logKit = null;
     protected String logger = null;
     protected String logLevel = "ERROR";
-    private String userAgent = DEFAULT_USER_AGENT;
-    private String accept = DEFAULT_ACCEPT;
+    protected String userAgent = DEFAULT_USER_AGENT;
+    protected String accept = DEFAULT_ACCEPT;
     private List classList = new ArrayList();
 
     // Objects used alongside User Supplied Parameters
@@ -303,15 +303,16 @@
         }
         log.info("Processing URI: " + uri);
 
-        // Get parameters, deparameterized URI and path from URI
+        // Get parameters, headers, deparameterized URI and path from URI
         final TreeMap parameters = new TreeMap();
+        final TreeMap headers = new TreeMap();
         final String deparameterizedURI =
             NetUtils.deparameterize(uri, parameters);
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
 
         int status =
-            getPage(deparameterizedURI, 0L, parameters, null, null, outputStream);
+            getPage(deparameterizedURI, 0L, parameters, headers, null, null, outputStream);
 
         if (status >= 400) {
             throw new ProcessingException("Resource not found: " + status);
@@ -333,15 +334,16 @@
         }
         log.info("Processing URI: " + uri);
 
-        // Get parameters, deparameterized URI and path from URI
+        // Get parameters, headers, deparameterized URI and path from URI
         final TreeMap parameters = new TreeMap();
+        final TreeMap headers = new TreeMap();
         final String deparameterizedURI =
             NetUtils.deparameterize(uri, parameters);
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
 
         int status =
-            getPage(deparameterizedURI, 0L, parameters, null, null, handler);
+            getPage(deparameterizedURI, 0L, parameters, headers, null, null, handler);
 
         if (status >= 400) {
             throw new ProcessingException("Resource not found: " + status);
@@ -371,12 +373,13 @@
     protected Collection getLinks(String deparameterizedURI, Map parameters)
         throws Exception {
 
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
+        final TreeMap headers = new TreeMap();
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
 
         LinkSamplingEnvironment env =
             new LinkSamplingEnvironment(deparameterizedURI, context, null,
-                                        parameters, cliContext, log);
+                                        parameters, headers, cliContext, log);
         processLenient(env);
         return env.getLinks();
     }
@@ -394,17 +397,18 @@
     protected int getPage(String deparameterizedURI,
                           long lastModified,
                           Map parameters,
+                          Map headers,
                           Map links,
                           List gatheredLinks,
                           OutputStream stream)
     throws Exception {
 
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
 
         FileSavingEnvironment env =
             new FileSavingEnvironment(deparameterizedURI, lastModified, context,
-                                      null, parameters, links,
+                                      null, parameters, headers, links,
                                       gatheredLinks, cliContext, stream, log);
 
         // Here Cocoon can throw an exception if there are errors in processing the page
@@ -431,17 +435,18 @@
     protected int getPage(String deparameterizedURI,
                           long lastModified,
                           Map parameters,
+                          Map headers,
                           Map links,
                           List gatheredLinks,
                           ContentHandler handler)
     throws Exception {
 
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
 
         FileSavingEnvironment env =
             new FileSavingEnvironment(deparameterizedURI, lastModified, context,
-                                      null, parameters, links,
+                                      null, parameters, headers, links,
                                       gatheredLinks, cliContext, null, log);
 
         XMLConsumer consumer = new ContentHandlerWrapper(handler);
@@ -486,12 +491,13 @@
     protected String getType(String deparameterizedURI, Map parameters)
         throws Exception {
 
-        parameters.put("user-agent", userAgent);
-        parameters.put("accept", accept);
+        final TreeMap headers = new TreeMap();
+        headers.put("user-agent", userAgent);
+        headers.put("accept", accept);
 
         FileSavingEnvironment env =
             new FileSavingEnvironment(deparameterizedURI, context, null,
-                                      parameters, empty, null, cliContext,
+                                      parameters, headers, empty, null, cliContext,
                                       new NullOutputStream(), log);
         processLenient(env);
         return env.getContentType();

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java?rev=399270&r1=399269&r2=399270&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/FileSavingEnvironment.java
Wed May  3 04:50:11 2006
@@ -41,6 +41,7 @@
                                  File context,
                                  Map attributes,
                                  Map parameters,
+                                 Map headers,
                                  Map links,
                                  List gatheredLinks,
                                  CommandLineContext cliContext,
@@ -49,7 +50,7 @@
     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,
@@ -67,13 +68,14 @@
                                  File context,
                                  Map attributes,
                                  Map parameters,
+                                 Map headers,
                                  Map links,
                                  List gatheredLinks,
                                  CommandLineContext cliContext,
                                  OutputStream stream,
                                  Logger log)
     throws MalformedURLException {
-        this(uri, 0L, context, attributes, parameters, links, gatheredLinks, cliContext,
stream, log);
+        this(uri, 0L, context, attributes, parameters, headers, links, gatheredLinks, cliContext,
stream, log);
     }
 
     /**

Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java?rev=399270&r1=399269&r2=399270&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/environment/commandline/LinkSamplingEnvironment.java
Wed May  3 04:50:11 2006
@@ -43,6 +43,7 @@
                                    File contextFile,
                                    Map attributes,
                                    Map parameters,
+                                   Map headers,
                                    CommandLineContext cliContext,
                                    Logger log)
     throws MalformedURLException, IOException {
@@ -51,7 +52,7 @@
             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,



Mime
View raw message