cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upayav...@apache.org
Subject svn commit: r154838 - in cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon: bean/CocoonWrapper.java environment/commandline/AbstractCommandLineEnvironment.java
Date Tue, 22 Feb 2005 12:30:46 GMT
Author: upayavira
Date: Tue Feb 22 04:30:44 2005
New Revision: 154838

URL: http://svn.apache.org/viewcvs?view=rev&rev=154838
Log:
Adding ability for CocoonBean to process a URL to a content handler
with cocoonBean.process(uri, contentHandler), rather than to an 
OutputStream (of course skipping the serializer).

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java?view=diff&r1=154837&r2=154838
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/bean/CocoonWrapper.java Tue Feb
22 04:30:44 2005
@@ -391,6 +391,36 @@
         }
     }
 
+    /**
+     * Process single URI into given content handler, skipping final
+     * serializer
+     *
+     * @param uri to process
+     * @param handler to write generated contents into
+     */
+    public void processURI(String uri, ContentHandler handler)
+        throws Exception {
+
+        if (!initialized) {
+            initialize();
+        }
+        log.info("Processing URI: " + uri);
+
+        // Get parameters, deparameterized URI and path from URI
+        final TreeMap parameters = new TreeMap();
+        final String deparameterizedURI =
+            NetUtils.deparameterize(uri, parameters);
+        parameters.put("user-agent", userAgent);
+        parameters.put("accept", accept);
+
+        int status =
+            getPage(deparameterizedURI, 0L, parameters, null, null, handler);
+
+        if (status >= 400) {
+            throw new ProcessingException("Resource not found: " + status);
+        }
+    }
+
     public void dispose() {
         if (this.initialized) {
             this.initialized = false;
@@ -452,6 +482,47 @@
 
         // Here Cocoon can throw an exception if there are errors in processing the page
         cocoon.process(env);
+
+        // if we get here, the page was created :-)
+        int status = env.getStatus();
+        if (!env.isModified()) {
+            status = -1;
+        }
+        return status;
+    }
+
+    /**
+     * Processes an URI for its content.
+     *
+     * @param deparameterizedURI a <code>String</code> value of an URI to start
sampling from
+     * @param parameters a <code>Map</code> value containing request parameters
+     * @param links a <code>Map</code> value
+     * @param stream an <code>OutputStream</code> to write the content to
+     * @return a <code>String</code> value for the content
+     * @exception Exception if an error occurs
+     */
+    protected int getPage(String deparameterizedURI,
+                          long lastModified,
+                          Map parameters,
+                          Map links,
+                          List gatheredLinks,
+                          ContentHandler handler)
+    throws Exception {
+
+        parameters.put("user-agent", userAgent);
+        parameters.put("accept", accept);
+
+        FileSavingEnvironment env =
+            new FileSavingEnvironment(deparameterizedURI, lastModified, context,
+                                      attributes, parameters, links,
+                                      gatheredLinks, cliContext, null, log);
+
+        XMLConsumer consumer = new ContentHandlerWrapper(handler);
+        ProcessingPipeline pipeline = cocoon.buildPipeline(env);
+        CocoonComponentManager.enterEnvironment(env, cocoon.getComponentManager(), cocoon);
+        pipeline.prepareInternal(env);
+        CocoonComponentManager.leaveEnvironment();
+        pipeline.process(env, consumer);
 
         // if we get here, the page was created :-)
         int status = env.getStatus();

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java?view=diff&r1=154837&r2=154838
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/environment/commandline/AbstractCommandLineEnvironment.java
Tue Feb 22 04:30:44 2005
@@ -36,7 +36,7 @@
  * This environment is used to save the requested file to disk.
  *
  * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
- * @version CVS $Id: AbstractCommandLineEnvironment.java,v 1.6 2004/03/05 13:02:54 bdelacretaz
Exp $
+ * @version CVS $Id$
  */
 
 public abstract class AbstractCommandLineEnvironment
@@ -179,4 +179,16 @@
         return true;
     }
 
+    /**
+     * Return an OutputStream, but allow it to be null for when
+     * the pipeline is being streamed to the provided SAX 
+     * content handler (using CocoonBean)
+     */
+    public OutputStream getOutputStream(int bufferSize) throws IOException {
+        if (this.outputStream == null) {
+            return null;
+        } else {
+            return super.getOutputStream(bufferSize);
+        }
+    }
 }



Mime
View raw message