cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jheym...@apache.org
Subject svn commit: r330548 [10/132] - in /cocoon/whiteboard/maven2/cocoon-flat-layout: ./ cocoon-ajax-block/ cocoon-ajax-block/api/ cocoon-ajax-block/api/src/ cocoon-ajax-block/api/src/main/ cocoon-ajax-block/api/src/main/java/ cocoon-ajax-block/api/src/main/...
Date Thu, 03 Nov 2005 14:00:48 GMT
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionResult.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionResult.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionResult.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionResult.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,89 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.acting;
+
+import org.apache.cocoon.util.EnumerationFactory;
+
+/**
+ * A number of constants to represent the possible outcomes of a
+ * validation.
+ *
+ * @author <a href="mailto:haul@apache.org">Christian Haul</a>
+ * @version CVS $Id: ValidatorActionResult.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class ValidatorActionResult extends EnumerationFactory {
+
+    /**
+     * no error occurred, parameter successfully checked.
+     */
+    public static final ValidatorActionResult
+    OK         = new ValidatorActionResult ("OK");          // 0
+
+    /**
+     * this is returned when the result of a validation is
+     * requested but no such result is found in the request
+     * attribute.
+     */
+    public static final ValidatorActionResult
+    NOTPRESENT = new ValidatorActionResult ("NOTPRESENT");  // 1
+
+    /**
+     * some error occurred, this is a result that is never set but
+     * serves as a comparison target.
+     */
+    public static final ValidatorActionResult
+    ERROR      = new ValidatorActionResult ("ERROR");       // 2
+
+    /**
+     * the parameter is null but isn't allowed to.
+     */
+    public static final ValidatorActionResult
+    ISNULL     = new ValidatorActionResult ("ISNULL");      // 3
+
+    /**
+     * either value or length in case of a string is less than the
+     * specified minimum.
+     */
+    public static final ValidatorActionResult
+    TOOSMALL   = new ValidatorActionResult ("TOOSMALL");    // 4
+
+    /**
+     * either value or length in case of a string is greater than
+     * the specified maximum.
+     */
+    public static final ValidatorActionResult
+    TOOLARGE   = new ValidatorActionResult ("TOOLARGE");    // 5
+
+    /**
+     * a string parameter's value is not matched by the specified
+     * regular expression.
+     */
+    public static final ValidatorActionResult
+    NOMATCH    = new ValidatorActionResult ("NOMATCH");     // 6
+
+    /**
+     * maximum error, only used for comparisons.
+     */
+    public static final ValidatorActionResult
+    MAXERROR   = new ValidatorActionResult ("MAXERROR");    // 7
+
+    /**
+     * Make constructor private to inhibit creation outside.
+     */
+    private ValidatorActionResult (String image) {
+        super (image);
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/acting/ValidatorActionResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/BeanListener.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/BeanListener.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/BeanListener.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/BeanListener.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,83 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.bean;
+
+/**
+ * Interface allowing caller to install a listener so that it can be informed
+ * as the bean makes progress through the links to be called.
+ *
+ * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
+ * @version CVS $Id: BeanListener.java 55250 2004-10-21 19:25:56Z cziegeler $
+ */
+public interface BeanListener {
+
+    /**
+     * Report a page as successfully generated
+     * @param sourceURI
+     * @param destinationURI
+     * @param pageSize
+     * @param linksInPage    Number of links found in this page
+     * @param newLinksinPage
+     * @param pagesRemaining Number of pages still to be generated
+     * @param pagesComplete
+     * @param timeTaken
+     */
+    public void pageGenerated(String sourceURI,
+                              String destinationURI, 
+                              int pageSize,
+                              int linksInPage, 
+                              int newLinksinPage, 
+                              int pagesRemaining, 
+                              int pagesComplete, 
+                              long timeTaken);
+                              
+    /**
+     * Report a that was skipped because its URI matched an
+     * include/exclude pattern.
+     * @param uri
+     * @param message            
+     */
+    public void pageSkipped(String uri, String message);
+    
+    /**
+     * Report a general message about operation of the bean
+     * @param msg            The message to be reported
+     */
+    public void messageGenerated(String msg);
+
+    /**
+     * Report a warning about something non-fatal that happened within
+     * the bean.
+     * @param uri            The page being generated when warning was triggered
+     * @param warning        The warning to be reported
+     */
+    public void warningGenerated(String uri, String warning);
+
+    /**
+     * Report a broken link
+     * @param uri            The URI that failed to be generated
+     * @param message        A reason why the link was not generated
+     */
+    public void brokenLinkFound(String uri, String parentURI, String message, Throwable t);
+    public void brokenLinkFound(Target target, Throwable t);
+    
+    /**
+     * Signals completion of the generation process. This method can
+     * be used to write out reports, display time generation duration,
+     * etc.
+     */
+    public void complete();
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/BeanListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,747 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.bean;
+
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.bean.helpers.Crawler;
+import org.apache.cocoon.bean.helpers.DelayedOutputStream;
+import org.apache.cocoon.components.notification.SimpleNotifyingBean;
+import org.apache.cocoon.components.notification.Notifier;
+import org.apache.cocoon.components.notification.DefaultNotifyingBuilder;
+import org.apache.cocoon.components.notification.Notifying;
+import org.apache.cocoon.matching.helpers.WildcardHelper;
+import org.apache.commons.lang.SystemUtils;
+
+import org.apache.excalibur.source.ModifiableSource;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
+import org.apache.excalibur.source.SourceUtil;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>The Cocoon Bean simplifies usage of the Cocoon object. Allows to create,
+ * configure Cocoon instance and process requests, one by one or multiple
+ * with link traversal.</p>
+ *
+ * <p><b>WARNING:</b> This interface is not stable and could be changed in
+ * backward incompatible way without prior notice.</p>
+
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @author <a href="mailto:nicolaken@apache.org">Nicola Ken Barozzi</a>
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
+ * @version CVS $Id: CocoonBean.java 230553 2005-08-06 17:01:28Z cziegeler $
+ */
+public class CocoonBean extends CocoonWrapper {
+
+    // User Supplied Parameters
+    private boolean followLinks = true;
+    private boolean precompileOnly = false;
+    private boolean confirmExtension = true;
+    private String defaultFilename = Constants.INDEX_URI;
+    private boolean brokenLinkGenerate = false;
+    private String brokenLinkExtension = "";
+    private List excludePatterns = new ArrayList();
+    private List includePatterns = new ArrayList();
+    private List includeLinkExtensions = null;
+
+    // Internal Objects
+    private boolean initialized;
+    private List listeners = new ArrayList();
+    SourceResolver sourceResolver;
+
+    private Crawler crawler;    
+    private String checksumsURI = null;
+    private Map checksums;
+
+    public CocoonBean() {
+        this.crawler = new Crawler();
+    }
+
+    //
+    // INITIALISATION METHOD
+    //
+
+    public void initialize() throws Exception {
+        if (this.initialized == false) {
+            super.initialize();
+
+            this.sourceResolver =
+                (SourceResolver) getServiceManager().lookup(
+                    SourceResolver.ROLE);
+
+            initialized = true;
+        }
+    }
+
+    protected void finalize() throws Throwable {
+        dispose();
+        super.finalize();
+    }
+
+    //
+    // GETTERS AND SETTERS FOR CONFIGURATION PROPERTIES
+    //
+
+    public void setFollowLinks(boolean follow) {
+        followLinks = follow;
+    }
+
+    public void setConfirmExtensions(boolean confirmExtension) {
+        this.confirmExtension = confirmExtension;
+    }
+
+    public void setPrecompileOnly(boolean precompileOnly) {
+        this.precompileOnly = precompileOnly;
+    }
+
+    public boolean isPrecompileOnly() {
+        return precompileOnly;
+    }
+    
+    public void setDefaultFilename(String filename) {
+        defaultFilename = filename;
+    }
+
+    public void setBrokenLinkGenerate(boolean brokenLinkGenerate) {
+        this.brokenLinkGenerate = brokenLinkGenerate;
+    }
+
+    public void setBrokenLinkExtension(String brokenLinkExtension) {
+        this.brokenLinkExtension = brokenLinkExtension;
+    }
+
+    public void setChecksumURI(String uri) {
+        this.checksumsURI = uri;
+    }
+    
+    public boolean followLinks() {
+        return followLinks;
+    }
+
+    public boolean confirmExtensions() {
+        return confirmExtension;
+    }
+    /**
+     * Adds a target for processing
+     *
+     * @param type Type of target - append, replace, insert.
+     * @param root
+     * @param sourceURI URI of the starting page
+     * @param destURI URI specifying destination for the generated pages.
+     * @throws IllegalArgumentException if destURI is missing
+     */
+    public void addTarget(
+            String type,
+            String root,
+            String sourceURI,
+            String destURI)
+            throws IllegalArgumentException {
+        Target target = new Target(type, root, sourceURI, destURI);
+        target.setDefaultFilename(this.defaultFilename);
+        target.setFollowLinks(this.followLinks);
+        target.setConfirmExtension(this.confirmExtension);
+        target.setLogger(this.logger);
+        crawler.addTarget(target);
+    }
+
+    public void addTarget(String type, String sourceURI, String destURI)
+        throws IllegalArgumentException {
+        Target target = new Target(type, sourceURI, destURI);
+        target.setDefaultFilename(this.defaultFilename);
+        target.setFollowLinks(this.followLinks);
+        target.setConfirmExtension(this.confirmExtension);
+        target.setLogger(this.logger);
+        crawler.addTarget(target);
+    }
+
+    public void addTarget(String sourceURI, String destURI)
+        throws IllegalArgumentException {
+        Target target = new Target(sourceURI, destURI);
+        target.setDefaultFilename(this.defaultFilename);
+        target.setFollowLinks(this.followLinks);
+        target.setConfirmExtension(this.confirmExtension);
+        target.setLogger(this.logger);
+        crawler.addTarget(target);
+    }
+
+    public void addTargets(List uris, String destURI)
+        throws IllegalArgumentException {
+        Iterator i = uris.iterator();
+        while (i.hasNext()) {
+            Target target = new Target((String) i.next(), destURI);
+            target.setDefaultFilename(this.defaultFilename);
+            target.setFollowLinks(this.followLinks);
+            target.setConfirmExtension(this.confirmExtension);
+            target.setLogger(this.logger);
+            crawler.addTarget(target);
+        }
+    }
+
+    public void addTarget(
+        String type,
+        String root,
+        String sourceURI,
+        String destURI,
+        boolean followLinks,
+        boolean confirmExtension,
+        String logger)
+        throws IllegalArgumentException {
+
+        Target target;
+        if (root == null && type == null) {
+            target = new Target(sourceURI, destURI);
+        } else if (root == null) {
+            target = new Target(type, sourceURI, destURI);
+        } else {
+            target = new Target(type, root, sourceURI, destURI);
+        }
+        target.setDefaultFilename(this.defaultFilename);
+        target.setFollowLinks(followLinks);
+        target.setConfirmExtension(confirmExtension);
+        target.setLogger(logger);
+        crawler.addTarget(target);
+    }
+
+    public int getTargetCount() {
+        return crawler.getRemainingCount();
+    }
+    
+    public void addExcludePattern(String pattern) {
+        int preparedPattern[] = WildcardHelper.compilePattern(pattern);
+        excludePatterns.add(preparedPattern);
+    }
+
+    public void addIncludePattern(String pattern) {
+        int preparedPattern[] = WildcardHelper.compilePattern(pattern);
+        includePatterns.add(preparedPattern);
+    }
+
+    public void addIncludeLinkExtension(String extension) {
+        if (includeLinkExtensions == null) {
+            includeLinkExtensions = new ArrayList();
+        }
+        includeLinkExtensions.add(extension);
+    }
+
+    public void addListener(BeanListener listener) {
+        this.listeners.add(listener);
+    }
+
+    public void pageGenerated(String sourceURI,
+                              String destURI,
+                              int pageSize,
+                              int linksInPage,
+                              int newLinksInPage,
+                              int pagesRemaining,
+                              int pagesComplete,
+                              long timeTaken) {
+        Iterator i = listeners.iterator();
+        while (i.hasNext()) {
+            BeanListener l = (BeanListener) i.next();
+            l.pageGenerated(sourceURI,
+                            destURI,
+                            pageSize,
+                            linksInPage,
+                            newLinksInPage,
+                            pagesRemaining,
+                            pagesComplete,
+                            timeTaken);
+        }
+    }
+
+    public void sendMessage(String msg) {
+        Iterator i = listeners.iterator();
+        while (i.hasNext()) {
+            BeanListener l = (BeanListener) i.next();
+            l.messageGenerated(msg);
+        }
+    }
+
+    public void sendWarning(String uri, String warning) {
+        Iterator i = listeners.iterator();
+        while (i.hasNext()) {
+            BeanListener l = (BeanListener) i.next();
+            l.warningGenerated(uri, warning);
+        }
+    }
+
+    public void sendBrokenLinkWarning(String uri, String warning) {
+        Iterator i = listeners.iterator();
+        while (i.hasNext()) {
+            BeanListener l = (BeanListener) i.next();
+            l.brokenLinkFound(uri, "", warning, null);
+        }
+    }
+
+    public void sendBrokenLinkWarning(Target target, Throwable t) {
+        Iterator i = listeners.iterator();
+        while (i.hasNext()) {
+            BeanListener l = (BeanListener) i.next();
+            l.brokenLinkFound(target, t);
+        }
+    }
+
+    public void pageSkipped(String uri, String message) {
+        Iterator i = listeners.iterator();
+        while (i.hasNext()) {
+            BeanListener l = (BeanListener) i.next();
+            l.pageSkipped(uri, message);
+        }
+    }
+
+    public void dispose() {
+        if (this.initialized) {
+            if (this.sourceResolver != null) {
+                getServiceManager().release(this.sourceResolver);
+                this.sourceResolver = null;
+            }
+            super.dispose();
+        }
+    }
+
+    /**
+     * Process the URI list and process them all independently.
+     * @exception Exception if an error occurs
+     */
+    public void process() throws Exception {
+
+        if (!this.initialized) {
+            this.initialize();
+        }
+
+        if (crawler.getRemainingCount() == 0 && !precompileOnly) {
+            log.info("No targets for to be processed.");
+            return;
+        }
+
+        if (this.checksumsURI != null) {
+            readChecksumFile();
+        }
+        
+        if (crawler.getRemainingCount()>=0) {
+            Iterator iterator = crawler.iterator();
+            while (iterator.hasNext()) {
+                Target target = (Target) iterator.next();
+                if (!precompileOnly) {
+                    processTarget(crawler, target);
+								}
+            }
+        }
+        
+        if (this.checksumsURI != null) {
+            writeChecksumFile();
+        }
+        
+        if (log.isInfoEnabled()) {
+              log.info(
+                  "  Memory used: "
+                      + (Runtime.getRuntime().totalMemory()
+                          - Runtime.getRuntime().freeMemory()));
+              log.info(
+                  "  Processed, Translated & Left: "
+                      + crawler.getProcessedCount()
+                      + ", "
+                      + crawler.getTranslatedCount()
+                      + ", "
+                      + crawler.getRemainingCount());
+          }
+    }
+
+    /**
+     * Processes the given Target and return all links.
+     *
+     * If links are to be followed, and extensions checked then the algorithm is as
+     * follows:
+     * <ul>
+     *  <li>file name for the URI is generated. URI MIME type is checked for
+     *      consistency with the URI and, if the extension is inconsistent
+     *      or absent, the file name is changed</li>
+     *  <li>the link view of the given URI is called and the file names for linked
+     *      resources are generated and stored.</li>
+     *  <li>for each link, absolute file name is translated to relative path.</li>
+     *  <li>after the complete list of links is translated, the link-translating
+     *      view of the resource is called to obtain a link-translated version
+     *      of the resource with the given link map</li>
+     *  <li>list of absolute URI is returned, for every URI which is not yet
+     *      present in list of all translated URIs</li>
+     * </ul>
+     *
+     * If links are to be followed, but extensions are not checked, then the
+     * algorithm will be:
+     * <ul>
+     *   <li>The content for the page is generated</li>
+     *   <li>Whilst generating, all links are gathered by the LinkGatherer</li>
+     *   <li>Gathered links are added to the unprocessed links list, and
+     *       processing continues until all processing is complete
+     *   </li>
+     * </ul>
+     *
+     * @param target a <code>Target</code> target to process
+     * @exception Exception if an error occurs
+     */
+    private void processTarget(Crawler crawler, Target target) throws Exception {
+
+        int status = 0;
+
+        int linkCount = 0;
+        int newLinkCount = 0;
+        int pageSize = 0;
+        long startTimeMillis = System.currentTimeMillis();
+
+        if (target.confirmExtensions()) {
+            if (!crawler.hasTranslatedLink(target)) {
+                final String mimeType = getType(target.getDeparameterizedSourceURI(), target.getParameters());
+                target.setMimeType(mimeType);
+                crawler.addTranslatedLink(target);
+            }
+        }
+
+        // IS THIS STILL NEEDED?
+        //if ("".equals(destinationURI)) {
+        //    return new ArrayList();
+        //}
+
+        // Process links
+        final HashMap translatedLinks = new HashMap();
+        if (target.followLinks() && target.confirmExtensions() && isCrawlablePage(target)) {
+            final Iterator i =
+                this.getLinks(target.getDeparameterizedSourceURI(), target.getParameters()).iterator();
+
+            while (i.hasNext()) {
+                String linkURI = (String) i.next();
+                Target linkTarget = target.getDerivedTarget(linkURI);
+
+                if (linkTarget == null) {
+                    pageSkipped(linkURI, "link does not share same root as parent");
+                    continue;
+                }
+
+                if (!isIncluded(linkTarget.getSourceURI())) {
+                    pageSkipped(linkTarget.getSourceURI(), "matched include/exclude rules");
+                    continue;
+                }
+
+                if (!crawler.hasTranslatedLink(linkTarget)) {
+                    try {
+                        final String mimeType =
+                                getType(linkTarget.getDeparameterizedSourceURI(), linkTarget.getParameters());
+                        linkTarget.setMimeType(mimeType);
+                        crawler.addTranslatedLink(linkTarget);
+                        log.info("  Link translated: " + linkTarget.getSourceURI());
+                        if (crawler.addTarget(linkTarget)) {
+                            newLinkCount++;
+                        }
+                    } catch (ProcessingException pe) {
+                        this.sendBrokenLinkWarning(linkTarget, pe);
+                        if (this.brokenLinkGenerate) {
+                           if (crawler.addTarget(linkTarget)) {
+                               newLinkCount++;
+                           }
+                        }
+                    }
+                } else {
+                    String originalURI = linkTarget.getOriginalSourceURI();
+                    linkTarget = crawler.getTranslatedLink(linkTarget);
+                    linkTarget.setOriginalURI(originalURI);
+                }
+
+                translatedLinks.put(linkTarget.getOriginalSourceURI(), linkTarget.getTranslatedURI(target.getPath()));
+            }
+
+            linkCount = translatedLinks.size();
+        }
+
+        try {
+            // Process URI
+            DelayedOutputStream output = new DelayedOutputStream();
+            try {
+                List gatheredLinks;
+                if (!target.confirmExtensions() && target.followLinks() && isCrawlablePage(target)) {
+                    gatheredLinks = new ArrayList();
+                } else {
+                    gatheredLinks = null;
+                }
+
+                status =
+                    getPage(
+                        target.getDeparameterizedSourceURI(),
+                        getLastModified(target),
+                        target.getParameters(),
+                        target.confirmExtensions() ? translatedLinks : null,
+                        gatheredLinks,
+                        output);
+
+                if (status >= 400) {
+                    throw new ProcessingException(
+                        "Resource not found: " + status);
+                }
+
+                if (gatheredLinks != null) {
+                    for (Iterator it = gatheredLinks.iterator();it.hasNext();) {
+                        String linkURI = (String) it.next();
+                        Target linkTarget = target.getDerivedTarget(linkURI);
+
+                        if (linkTarget == null) {
+                            pageSkipped(linkURI, "link does not share same root as parent");
+                            continue;
+                        }
+
+                        if (!isIncluded(linkTarget.getSourceURI())) {
+                            pageSkipped(linkTarget.getSourceURI(), "matched include/exclude rules");
+                            continue;
+                        }
+                        if (crawler.addTarget(linkTarget)) {
+                            newLinkCount++;
+                        }
+                    }
+                    linkCount = gatheredLinks.size();
+                }
+
+            } catch (ProcessingException pe) {
+                output.close();
+                output = null;
+                this.resourceUnavailable(target);
+                this.sendBrokenLinkWarning(target,
+                    DefaultNotifyingBuilder.getRootCause(pe));
+            } finally {
+                if (output != null && status != -1) {
+
+                    ModifiableSource source = getSource(target);
+                    try {
+                        pageSize = output.size();
+                        
+                        if (this.checksumsURI == null || !isSameContent(output, target)) {
+                            OutputStream stream = source.getOutputStream();
+                            output.setFileOutputStream(stream);
+                            output.flush();
+                            output.close();
+                            pageGenerated(target.getSourceURI(), 
+                                          target.getAuthlessDestURI(), 
+                                          pageSize,
+                                          linkCount,
+                                          newLinkCount,
+                                          crawler.getRemainingCount(),
+                                          crawler.getProcessedCount(),
+                                          System.currentTimeMillis()- startTimeMillis);
+                        } else {
+                            output.close();
+                            pageSkipped(target.getSourceURI(), "Page not changed");
+                        }
+                    } catch (IOException ioex) {
+                        log.warn(ioex.toString());
+                    } finally {
+                        releaseSource(source);
+                    }
+                }
+            }
+        } catch (Exception rnfe) {
+            log.warn("Could not process URI: " + target.getSourceURI());
+            rnfe.printStackTrace();
+            this.sendBrokenLinkWarning(target.getSourceURI(), "URI not found: "+rnfe.getMessage());
+        }
+    }
+
+    /**
+     * Generate a <code>resourceUnavailable</code> message.
+     *
+     * @param target being unavailable
+     * @exception IOException if an error occurs
+     */
+    private void resourceUnavailable(Target target)
+        throws IOException, ProcessingException {
+        if (brokenLinkGenerate) {
+            //Why decode this URI now?
+            //String brokenFile = NetUtils.decodePath(destinationURI);
+
+            if (brokenLinkExtension != null) {
+                target.setExtraExtension(brokenLinkExtension);
+            }
+            SimpleNotifyingBean n = new SimpleNotifyingBean(this);
+            n.setType("resource-not-found");
+            n.setTitle("Resource not Found");
+            n.setSource("Cocoon commandline (Main.java)");
+            n.setMessage("Page Not Available.");
+            n.setDescription("The requested resource couldn't be found.");
+            n.addExtraDescription(Notifying.EXTRA_REQUESTURI, target.getSourceURI());
+            n.addExtraDescription("missing-file", target.getSourceURI());
+
+            ModifiableSource source = getSource(target);
+            try {
+                OutputStream stream = source.getOutputStream();
+
+                PrintStream out = new PrintStream(stream);
+                Notifier.notify(n, out, "text/html");
+                out.flush();
+                out.close();
+            } finally {
+                releaseSource(source);
+            }
+        }
+    }
+
+    public ModifiableSource getSource(Target target)
+        throws IOException, ProcessingException {
+        final String finalDestinationURI = target.getDestinationURI();
+        Source src = sourceResolver.resolveURI(finalDestinationURI);
+        if (!(src instanceof ModifiableSource)) {
+            sourceResolver.release(src);
+            throw new ProcessingException(
+                "Source is not Modifiable: " + finalDestinationURI);
+        }
+        return (ModifiableSource) src;
+    }
+
+    public long getLastModified(Target target) throws IOException, ProcessingException {
+        Source src = getSource(target);
+        long lastModified = src.getLastModified();
+        this.releaseSource(src);
+        return lastModified;
+    }
+
+    public void releaseSource(Source source) {
+        sourceResolver.release(source);
+    }
+    private boolean isIncluded(String uri) {
+        boolean included;
+        Iterator i;
+        HashMap map = new HashMap();
+
+        if (includePatterns.size() == 0) {
+            included = true;
+        } else {
+            included = false;
+            i = includePatterns.iterator();
+            while (i.hasNext()){
+                int pattern[] = (int[])i.next();
+                if (WildcardHelper.match(map, uri, pattern)) {
+                    included=true;
+                    break;
+                }
+            }
+        }
+        if (excludePatterns.size() != 0) {
+            i = excludePatterns.iterator();
+            while (i.hasNext()) {
+                int pattern[] = (int[])i.next();
+                if (WildcardHelper.match(map, uri, pattern)) {
+                    included=false;
+                    break;
+                }
+            }
+        }
+        return included;
+    }
+    private boolean isCrawlablePage(Target target) {
+        if (includeLinkExtensions == null) {
+            return true;
+        }
+        return includeLinkExtensions.contains(target.getExtension());
+    }
+
+    /* NB. This is a temporary solution - it may well be replaced by storing the checksum info
+     *     in the XML 'report' file, along with details of what pages were created, etc. 
+     */ 
+    private void readChecksumFile() throws Exception {
+        checksums = new HashMap();
+        
+        try {
+            Source checksumSource = sourceResolver.resolveURI(checksumsURI);
+            BufferedReader reader = new BufferedReader(new InputStreamReader(checksumSource.getInputStream()));
+            String line;
+            int lineNo=0;
+            while ((line = reader.readLine())!=null) {
+                lineNo++;
+                if (line.trim().startsWith("#") || line.trim().length()==0 ) {
+                    continue;
+                }
+                if (line.indexOf("\t")==-1) { 
+                    throw new ProcessingException("Missing tab at line "+lineNo+" of " + checksumsURI);
+                }
+                String filename = line.substring(0,line.indexOf("\t"));
+                String checksum = line.substring(line.indexOf("\t")+1);
+                checksums.put(filename, checksum);
+            }
+            reader.close();
+        } catch (SourceNotFoundException e) {
+            // return leaving checksums map empty
+        }
+    }
+    
+    private void writeChecksumFile() throws Exception {
+        Source checksumSource = sourceResolver.resolveURI(checksumsURI);
+        if (!(checksumSource instanceof ModifiableSource)) {
+            throw new ProcessingException("Checksum file is not Modifiable:" + checksumSource);
+        }
+        ModifiableSource source = (ModifiableSource) checksumSource;
+        PrintWriter writer = new PrintWriter(new OutputStreamWriter(source.getOutputStream()));
+        Iterator i = checksums.keySet().iterator();
+        while (i.hasNext()){
+            String key = (String) i.next();
+            String checksum = (String) checksums.get(key);
+            writer.println(key + "\t" + checksum);
+        }
+        writer.close();
+    }
+
+    private boolean isSameContent(DelayedOutputStream stream, Target target) {
+        try {
+            MessageDigest md5 = MessageDigest.getInstance("MD5");
+            md5.update(stream.getContent());
+            String streamDigest = SourceUtil.encodeBASE64(new String(md5.digest()));
+            String targetDigest = (String)checksums.get(target.getSourceURI());
+            
+            if (streamDigest.equals(targetDigest)) {
+                return true;
+            }
+            checksums.put(target.getSourceURI(), streamDigest);
+            return false;
+        } catch (NoSuchAlgorithmException e) {
+            // or do something:
+            return false;
+        }
+    }
+    /**
+     * Print a description of the software before running
+     */
+    public static String getProlog() {
+        String lSep = SystemUtils.LINE_SEPARATOR;
+        StringBuffer msg = new StringBuffer();
+        msg.append("------------------------------------------------------------------------ ").append(lSep);
+        msg.append(Constants.NAME).append(" ").append(Constants.VERSION).append(lSep);
+        msg.append("Copyright (c) ").append(Constants.YEAR).append(" Apache Software Foundation. All rights reserved.").append(lSep);
+        msg.append("Build: ").append(Constants.BUILD_INFO).append(lSep);
+        msg.append("------------------------------------------------------------------------ ").append(lSep).append(lSep);
+        return msg.toString();
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,726 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.bean;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.avalon.framework.context.DefaultContext;
+import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.Cocoon;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.Processor;
+import org.apache.cocoon.core.BootstrapEnvironment;
+import org.apache.cocoon.core.CoreUtil;
+import org.apache.cocoon.core.MutableSettings;
+import org.apache.cocoon.environment.Context;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.commandline.CommandLineContext;
+import org.apache.cocoon.environment.commandline.FileSavingEnvironment;
+import org.apache.cocoon.environment.commandline.LinkSamplingEnvironment;
+import org.apache.cocoon.environment.internal.EnvironmentHelper;
+import org.apache.cocoon.util.IOUtils;
+import org.apache.cocoon.util.NetUtils;
+import org.apache.cocoon.xml.ContentHandlerWrapper;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.commons.lang.SystemUtils;
+import org.xml.sax.ContentHandler;
+
+/**
+ * The Cocoon Wrapper simplifies usage of the Cocoon object. Allows to create,
+ * configure Cocoon instance and process single requests.
+ *
+ * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
+ * @author <a href="mailto:nicolaken@apache.org">Nicola Ken Barozzi</a>
+ * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
+ * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
+ * @version $Id: CocoonWrapper.java 307410 2005-10-09 12:17:33Z reinhard $
+ */
+public class CocoonWrapper {
+
+    protected static final String DEFAULT_USER_AGENT = Constants.COMPLETE_NAME;
+    protected static final String DEFAULT_ACCEPT = "text/html, */*";
+
+    // User Supplied Parameters
+    private String contextDir = Constants.DEFAULT_CONTEXT_DIR;
+    private String configFile = null;
+
+    private String workDir = Constants.DEFAULT_WORK_DIR;
+    private String logKit = null;
+    protected String logger = null;
+    protected String logLevel = "ERROR";
+    private String userAgent = DEFAULT_USER_AGENT;
+    private String accept = DEFAULT_ACCEPT;
+    private List classList = new ArrayList();
+
+    // Objects used alongside User Supplied Parameters
+    private File context;
+    private File work;
+    private File conf;
+
+    // Internal Objects
+    private CommandLineContext cliContext;
+    private Cocoon cocoon;
+    protected Logger log;
+    private HashMap empty = new HashMap();
+
+    private boolean initialized = false;
+
+    private CoreUtil coreUtil;
+
+    /**
+     * INITIALISATION METHOD.
+     */
+    public void initialize() throws Exception {
+        // Install a temporary logger so that getDir() can log if needed
+        final BootstrapEnvironment.LogLevel level = BootstrapEnvironment.LogLevel.getLogLevelForName(this.logLevel);
+        final Logger envLogger = new ConsoleLogger(level.getLevel());
+        this.log = envLogger;
+
+        this.context = getDir(this.contextDir, "context");
+        this.work = getDir(workDir, "working");
+
+        this.conf = getConfigurationFile(this.context, this.configFile);
+        cliContext = new CommandLineContext(contextDir);
+        cliContext.enableLogging(envLogger);
+
+        // setup Cocoon core
+        File cacheDir = getDir(workDir + File.separator + "cache-dir", "cache");
+
+        WrapperBootstrapper env = this.getBootstrapEnvironment();
+        env.setContextDirectory(contextDir);
+        env.setEnvironmentLogger(envLogger);
+        env.setEnvironmentContext(cliContext);
+        env.setWorkingDirectory(this.work);
+        env.setCachingDirectory(cacheDir);
+        env.setBootstrapLogLevel(this.logLevel);
+        env.setLoggingConfiguration(this.logKit);
+        env.setConfigFile(this.conf);
+        env.setLoadClassList(this.classList);
+        this.coreUtil = new CoreUtil(env);
+        this.cocoon = this.coreUtil.createCocoon();
+        this.log = env.logger;
+        this.initialized = true;
+    }
+
+    protected ServiceManager getServiceManager() {
+        return cocoon.getServiceManager();
+    }
+
+    /**
+     * Look around for the configuration file.
+     *
+     * @param dir a <code>File</code> where to look for configuration files
+     * @return a <code>File</code> representing the configuration
+     * @exception IOException if an error occurs
+     */
+    private File getConfigurationFile(File dir, String configFile)
+    throws IOException {
+        File conf;
+        if (configFile == null) {
+            conf = tryConfigurationFile(dir + File.separator + Constants.DEFAULT_CONF_FILE);
+            if (conf == null) {
+                conf = tryConfigurationFile(dir
+                            + File.separator
+                            + "WEB-INF"
+                            + File.separator
+                            + Constants.DEFAULT_CONF_FILE);
+            }
+            if (conf == null) {
+                conf =  tryConfigurationFile(
+                        SystemUtils.USER_DIR
+                            + File.separator
+                            + Constants.DEFAULT_CONF_FILE);
+            }
+            if (conf == null) {
+                conf = tryConfigurationFile(
+                        "/usr/local/etc/" + Constants.DEFAULT_CONF_FILE);
+            }
+        } else {
+            conf = new File(configFile);
+            if (!conf.canRead()) {
+                conf = new File(dir, configFile);
+                if (!conf.canRead()) {
+                    conf = null;
+                }
+            }
+        }
+        if (conf == null) {
+            log.error("Could not find the configuration file.");
+            throw new FileNotFoundException("The configuration file could not be found.");
+        }
+        return conf;
+    }
+
+    /**
+     * Try loading the configuration file from a single location
+     */
+    private File tryConfigurationFile(String filename) {
+        if (log.isDebugEnabled()) {
+            log.debug("Trying configuration file at: " + filename);
+        }
+        File conf = new File(filename);
+        if (conf.canRead()) {
+            return conf;
+        }
+        return null;
+    }
+
+    /**
+     * Get a <code>File</code> representing a directory.
+     *
+     * @param dir a <code>String</code> with a directory name
+     * @param type a <code>String</code> describing the type of directory
+     * @return a <code>File</code> value
+     * @exception IOException if an error occurs
+     */
+    private File getDir(String dir, String type) throws IOException {
+        if (log.isDebugEnabled()) {
+            log.debug("Getting handle to " + type + " directory '" + dir + "'");
+        }
+        File d = new File(dir);
+
+        if (!d.exists()) {
+            if (!d.mkdirs()) {
+                throw new IOException(
+                    "Error creating " + type + " directory '" + d + "'");
+            }
+        }
+
+        if (!d.isDirectory()) {
+            throw new IOException("'" + d + "' is not a directory.");
+        }
+
+        if (!d.canRead()) {
+            throw new IOException(
+                "Directory '" + d + "' is not readable");
+        }
+
+        if ("working".equals( type ) && !d.canWrite()) {
+            throw new IOException(
+                "Directory '" + d + "' is not writable");
+        }
+
+        return d;
+    }
+
+    protected void finalize() throws Throwable {
+        dispose();
+        super.finalize();
+    }
+
+    //
+    // GETTERS AND SETTERS FOR CONFIGURATION PROPERTIES
+    //
+
+    /**
+     * Set LogKit configuration file name
+     * @param logKit LogKit configuration file
+     */
+    public void setLogKit(String logKit) {
+        this.logKit = logKit;
+    }
+
+    /**
+     * Set log level. Default is DEBUG.
+     * @param logLevel log level
+     */
+    public void setLogLevel(String logLevel) {
+        this.logLevel = logLevel;
+    }
+
+    /**
+     * Set logger category as default logger for the Cocoon engine
+     * @param logger logger category
+     */
+    public void setLogger(String logger) {
+        this.logger = logger;
+    }
+
+    public String getLoggerName() {
+        return logger;
+    }
+
+    /**
+     * Set context directory
+     * @param contextDir context directory
+     */
+    public void setContextDir(String contextDir) {
+        this.contextDir = contextDir;
+    }
+
+    /**
+     * Set working directory
+     * @param workDir working directory
+     */
+    public void setWorkDir(String workDir) {
+        this.workDir = workDir;
+    }
+
+    public void setConfigFile(String configFile) {
+        this.configFile = configFile;
+    }
+
+    public void setAgentOptions(String userAgent) {
+        this.userAgent = userAgent;
+    }
+
+    public void setAcceptOptions(String accept) {
+        this.accept = accept;
+    }
+
+    public void addLoadedClass(String className) {
+        this.classList.add(className);
+    }
+
+    public void addLoadedClasses(List classList) {
+        this.classList.addAll(classList);
+    }
+    /**
+     * Process single URI into given output stream.
+     *
+     * @param uri to process
+     * @param outputStream to write generated contents into
+     */
+    public void processURI(String uri, OutputStream outputStream)
+        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, outputStream);
+
+        if (status >= 400) {
+            throw new ProcessingException("Resource not found: " + status);
+        }
+    }
+
+    /**
+     * 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;
+            this.coreUtil.destroy();
+            this.cocoon = null;
+            this.coreUtil = null;
+            if (log.isDebugEnabled()) {
+                log.debug("Disposed");
+            }
+        }
+    }
+
+    /**
+     * Samples an URI for its links.
+     *
+     * @param deparameterizedURI a <code>String</code> value of an URI to start sampling from
+     * @param parameters a <code>Map</code> value containing request parameters
+     * @return a <code>Collection</code> of links
+     * @exception Exception if an error occurs
+     */
+    protected Collection getLinks(String deparameterizedURI, Map parameters)
+        throws Exception {
+
+        parameters.put("user-agent", userAgent);
+        parameters.put("accept", accept);
+
+        LinkSamplingEnvironment env =
+            new LinkSamplingEnvironment(deparameterizedURI, context, null,
+                                        parameters, cliContext, log);
+        processLenient(env);
+        return env.getLinks();
+    }
+
+    /**
+     * 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,
+                          OutputStream stream)
+    throws Exception {
+
+        parameters.put("user-agent", userAgent);
+        parameters.put("accept", accept);
+
+        FileSavingEnvironment env =
+            new FileSavingEnvironment(deparameterizedURI, lastModified, context,
+                                      null, parameters, links,
+                                      gatheredLinks, cliContext, stream, log);
+
+        // 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 handler an <code>ContentHandler</code> to send 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,
+                                      null, parameters, links,
+                                      gatheredLinks, cliContext, null, log);
+
+        XMLConsumer consumer = new ContentHandlerWrapper(handler);
+        Processor.InternalPipelineDescription pipeline = cocoon.buildPipeline(env);
+        EnvironmentHelper.enterProcessor(pipeline.lastProcessor, pipeline.pipelineManager, env);
+        try {
+            pipeline.processingPipeline.prepareInternal(env);
+            pipeline.processingPipeline.process(env, consumer);
+        } finally {
+            EnvironmentHelper.leaveProcessor();
+        }
+
+        // if we get here, the page was created :-)
+        int status = env.getStatus();
+        if (!env.isModified()) {
+            status = -1;
+        }
+        return status;
+    }
+
+    /** Class <code>NullOutputStream</code> here. */
+    static class NullOutputStream extends OutputStream {
+        public void write(int b) throws IOException {
+            // ignore
+        }
+        public void write(byte b[]) throws IOException {
+            // ignore
+        }
+        public void write(byte b[], int off, int len) throws IOException {
+            // ignore
+        }
+    }
+
+    /**
+     * Analyze the type of content for an URI.
+     *
+     * @param deparameterizedURI a <code>String</code> value to analyze
+     * @param parameters a <code>Map</code> value for the request
+     * @return a <code>String</code> value denoting the type of content
+     * @exception Exception if an error occurs
+     */
+    protected String getType(String deparameterizedURI, Map parameters)
+        throws Exception {
+
+        parameters.put("user-agent", userAgent);
+        parameters.put("accept", accept);
+
+        FileSavingEnvironment env =
+            new FileSavingEnvironment(deparameterizedURI, context, null,
+                                      parameters, empty, null, cliContext,
+                                      new NullOutputStream(), log);
+        processLenient(env);
+        return env.getContentType();
+    }
+
+    /**
+     * Try to process something but don't throw a ProcessingException.
+     *
+     * @param env the <code>Environment</code> to process
+     * @return boolean true if no error were cast, false otherwise
+     * @exception Exception if an error occurs, except RNFE
+     */
+    private boolean processLenient(Environment env) throws Exception {
+        try {
+            this.cocoon.process(env);
+        } catch (ProcessingException pe) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
+     * This builds the important ClassPath used by this class.  It
+     * does so in a neutral way.
+     * It iterates in alphabetical order through every file in the
+     * lib directory and adds it to the classpath.
+     *
+     * Also, we add the files to the ClassLoader for the Cocoon system.
+     * In order to protect ourselves from skitzofrantic classloaders,
+     * we need to work with a known one.
+     *
+     * @param context  The context path
+     * @return a <code>String</code> value
+     */
+    protected String getClassPath(final String context) {
+        StringBuffer buildClassPath = new StringBuffer();
+
+        String classDir = context + "/WEB-INF/classes";
+        buildClassPath.append(classDir);
+
+        File root = new File(context + "/WEB-INF/lib");
+        if (root.isDirectory()) {
+            File[] libraries = root.listFiles();
+            Arrays.sort(libraries);
+            for (int i = 0; i < libraries.length; i++) {
+                if (libraries[i].getAbsolutePath().endsWith(".jar")) {
+                    buildClassPath.append(File.pathSeparatorChar).append(
+                        IOUtils.getFullFilename(libraries[i]));
+                }
+            }
+        }
+
+        buildClassPath.append(File.pathSeparatorChar).append(SystemUtils.JAVA_CLASS_PATH);
+
+        // Extra class path is necessary for non-classloader-aware java compilers to compile XSPs
+        //        buildClassPath.append(File.pathSeparatorChar)
+        //                      .append(getExtraClassPath(context));
+
+        if (log.isDebugEnabled()) {
+            log.debug("Context classpath: " + buildClassPath);
+        }
+        return buildClassPath.toString();
+    }
+
+    protected WrapperBootstrapper getBootstrapEnvironment() {
+        return new WrapperBootstrapper();
+    }
+
+    /**
+     * This class provides wrapper specific environment information
+     *
+     */
+    public static class WrapperBootstrapper implements BootstrapEnvironment {
+
+        public Logger logger;
+
+        protected Logger environmentLogger;
+        protected Context environmentContext;
+        protected String workingDirectory;
+        protected String bootstrapLogLevel;
+        protected String loggingConfiguration;
+        protected String cachingDirectory;
+        protected String contextDirectory;
+        protected String configFile;
+        protected List loadClassList;
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getBootstrapLogger(org.apache.cocoon.core.BootstrapEnvironment.LogLevel)
+         */
+        public Logger getBootstrapLogger(LogLevel logLevel) {
+            return new ConsoleLogger(logLevel.getLevel());
+        }
+
+        public void setEnvironmentLogger(Logger log) {
+            this.environmentLogger = log;
+        }
+
+        public void setEnvironmentContext(Context context) {
+            this.environmentContext = context;
+        }
+
+        public void setWorkingDirectory(File dir) {
+            this.workingDirectory = dir.getAbsolutePath();
+        }
+
+        public void setBootstrapLogLevel(String bootstrapLogLevel) {
+            this.bootstrapLogLevel = bootstrapLogLevel;
+        }
+
+        public void setLoggingConfiguration(String config) {
+            this.loggingConfiguration = config;
+        }
+
+        public void setCachingDirectory(File dir) {
+            this.cachingDirectory = dir.getAbsolutePath();
+        }
+
+        public void setContextDirectory(String dir) {
+            this.contextDirectory = dir;
+        }
+
+        public void setConfigFile(File file) {
+            this.configFile = file.getAbsolutePath();
+        }
+
+        public void setLoadClassList(List l) {
+            this.loadClassList = l;
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#configure(org.apache.avalon.framework.context.DefaultContext)
+         */
+        public void configure(DefaultContext context) {
+            // nothing to add
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#configure(org.apache.cocoon.core.MutableSettings)
+         */
+        public void configure(MutableSettings settings) {
+            settings.setWorkDirectory(this.workingDirectory);
+            settings.setCacheDirectory(this.cachingDirectory);
+            settings.setUploadDirectory(this.contextDirectory + "upload-dir");
+            settings.setBootstrapLogLevel(this.bootstrapLogLevel);
+            settings.setLoggingConfiguration(this.loggingConfiguration);
+            settings.setFormEncoding("ISO-8859-1");
+            settings.setConfiguration(this.configFile);
+            if ( this.loadClassList != null ) {
+                final Iterator i = this.loadClassList.iterator();
+                while ( i.hasNext() ) {
+                    settings.addToLoadClasses(i.next().toString());
+                }
+            }
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#configureLoggingContext(org.apache.avalon.framework.context.DefaultContext)
+         */
+        public void configureLoggingContext(DefaultContext context) {
+            // nothing to add
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getConfigFile(java.lang.String)
+         */
+        public URL getConfigFile(String configFileName) throws Exception {
+            return new File(configFileName).toURL();
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getContextForWriting()
+         */
+        public File getContextForWriting() {
+            return new File(this.contextDirectory);
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getContextURL()
+         */
+        public String getContextURL() {
+            try {
+                return new File(this.contextDirectory).toURL().toExternalForm();
+            } catch (MalformedURLException mue) {
+                return "file://" + this.contextDirectory;
+            }
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#getEnvironmentContext()
+         */
+        public Context getEnvironmentContext() {
+            return this.environmentContext;
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#log(java.lang.String, java.lang.Throwable)
+         */
+        public void log(String message, Throwable error) {
+            this.environmentLogger.error(message, error);
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#log(java.lang.String)
+         */
+        public void log(String message) {
+            this.environmentLogger.debug(message);
+        }
+
+        /**
+         * @see org.apache.cocoon.core.BootstrapEnvironment#setLogger(org.apache.avalon.framework.logger.Logger)
+         */
+        public void setLogger(Logger rootLogger) {
+            this.logger = rootLogger;
+        }
+        
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/CocoonWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/Target.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/Target.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/Target.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/Target.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,457 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.bean;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeMap;
+
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.util.MIMEUtils;
+import org.apache.cocoon.util.NetUtils;
+import org.apache.cocoon.ProcessingException;
+
+/**
+ * A Target is a single page for generation. It encapsulates the URI 
+ * arithmetic required to transform the URI of the page to be generated 
+ * (the source URI) into the URI to which the resulting page should be 
+ * written (the destination URI).
+ *
+ * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
+ * @version CVS $Id: Target.java 179055 2005-05-30 14:08:23Z cziegeler $
+ */
+public class Target {
+    // Defult type is append
+    private static final String APPEND_TYPE = "append";
+    private static final String REPLACE_TYPE = "replace";
+    private static final String INSERT_TYPE = "insert";
+
+    private final String type;
+    private final String root;
+    private final String sourceURI;
+    private final String destURI;
+    private final String deparameterizedSourceURI;
+    private final TreeMap parameters;
+    
+    private String parentURI = null;
+    private String originalURI = null;
+    private String mimeType = null; 
+    private String defaultFilename = Constants.INDEX_URI;
+    private String finalDestinationURI = null;
+    private String extension = null;    
+    private List referringURIs = null;
+    
+    private boolean followLinks;
+    private boolean confirmExtension;
+    private String logger;
+                 
+    private transient int _hashCode;
+    private transient String _toString;
+
+    public Target(String type,
+                  String root,
+                  String sourceURI,
+                  String destURI)
+    throws IllegalArgumentException {
+        this.type = type;
+        this.root = root;
+        
+        if (destURI == null || destURI.length() == 0) {
+            throw new IllegalArgumentException("You must specify a destination directory when defining a target");
+        }
+        if (!destURI.endsWith("/")) {
+            destURI += "/";
+        }
+        this.destURI = destURI;
+        
+        this.parameters = new TreeMap();
+        
+        // Normalize sourceURI, and make sure that parameters is always in the same order
+        sourceURI = NetUtils.normalize(root + sourceURI);
+        this.deparameterizedSourceURI = NetUtils.deparameterize(sourceURI, this.parameters);
+        this.sourceURI = NetUtils.parameterize(this.deparameterizedSourceURI, this.parameters);
+        this.referringURIs = new ArrayList();
+    }
+
+    public Target(String type, String sourceURI, String destURI)
+        throws IllegalArgumentException {
+        this(type, "", sourceURI, destURI);
+    }
+
+    public Target(String sourceURI, String destURI)
+        throws IllegalArgumentException {
+        this(APPEND_TYPE, "", sourceURI, destURI);
+    }
+
+    public Target getDerivedTarget(String originalLinkURI)
+        throws IllegalArgumentException {
+
+        String linkURI = originalLinkURI;
+        // Fix relative links starting with "?"
+        if (linkURI.startsWith("?")) {
+            linkURI = this.getPageURI() + linkURI;
+        }
+        linkURI =
+            NetUtils.normalize(NetUtils.absolutize(this.getPath(), linkURI));
+
+        // Ignore pages outside the root folder
+        if (!linkURI.startsWith(this.root)) {
+            return null;
+        }
+        linkURI = linkURI.substring(root.length());
+        
+        Target target = new Target(this.type, this.root, linkURI, this.destURI);
+        target.setOriginalURI(originalLinkURI);
+        target.addReferringURI(this.sourceURI);
+        target.setConfirmExtension(this.confirmExtension);
+        target.setFollowLinks(this.followLinks);
+        target.setDefaultFilename(this.defaultFilename);
+        target.setLogger(this.logger);
+        return target;
+    }
+
+    /**
+     * Sets the original URI. This is used to record the URI that
+     * caused the creation of this Target, for example as a link
+     * in another page. It is needed for doing link translation, as
+     * this is the URI that must be replaced by the translated one.
+     */
+    public void setOriginalURI(String uri) {
+        this.originalURI = uri;
+    }
+    
+    /**
+     * Sets the URI of the page that contained the link to this 
+     * URI. Used for reporting purposes.
+     * @deprecated Use the addPerentURIs method instead
+     */
+    public void setParentURI(String uri) {
+        this.referringURIs.add(uri);
+    }
+    
+    /**
+     * Sets the mime type for the resource referenced by this target.
+     * If a mime type is specified, the file extension of the 
+     * destination URI will be checked to see that it matches the
+     * default extension for the specified mime type. If it doesn't,
+     * the default extension will be appended to the destination URI.
+     *
+     * This URI change will be taken into account in pages that link
+     * to the current page.
+     * 
+     * If the mime type is not specified (and thus null), no extension
+     * checking will take place. 
+     */
+    public void setMimeType(String mimeType) {
+        this.mimeType = mimeType;
+        this.finalDestinationURI = null;
+    }
+    
+    /**
+     * Sets a file extension to be appended to the end of the destination
+     * URI. The main use of this is to create broken link error files that
+     * stand out, within the file structure of the generated site, by, for
+     * example, adding '.error' to the end of the filename.
+     */
+    public void setExtraExtension(String extension) {
+        this.extension = extension;
+        this.finalDestinationURI = null;
+    }
+    /**
+     * Sets the default filename. This filename is appended to URIs
+     * that refer to a directory, i.e. end with a slash, as resources
+     * referred to by such a URI cannot be written to a file system
+     * without a filename. 
+     *
+     * This URI change will be taken into account in pages that link
+     * to the current page.
+     * 
+     * If no default is specified, the Cocoon constants value will 
+     * be used.
+     */
+    public void setDefaultFilename(String filename) {
+        this.defaultFilename = filename;
+    }
+    
+    /**
+     * Adds a URI for a referring page. This will be used later if 
+     * this page causes a broken link in order to list all pages
+     * that refer to this broken link
+     * @param uri
+     */
+    public void addReferringURI(String uri) {
+        this.referringURIs.add(uri);
+    }
+    
+    /**
+     * Returns the first referring URI. If this method is 
+     * called, their should only be one entry in the list 
+     */
+    public String getReferringURI() {
+        return (String)referringURIs.get(0);
+    }
+
+    /**
+     * Get all referring URIs.
+     */
+    public List getReferringURIs() {
+        return referringURIs;
+    }
+    /**
+     * Gets the filename from the source URI, without the path.
+     * This is used to fill out relative URIs that have
+     * parameters but no filename such as ?page=123
+     */
+    public String getPageURI() {
+        String pageURI = this.getSourceURI();
+        if (pageURI.indexOf("/") != -1) {
+            pageURI = pageURI.substring(pageURI.lastIndexOf("/") + 1);
+            if (pageURI.length() == 0) {
+                pageURI = "./";
+            }
+        }
+        return pageURI;
+    }
+
+    /**
+     * Gets the path from the source URI, without the filename. 
+     * This is used when absolutizing/relativizing link URIs.
+     */
+    public String getPath() {
+        return NetUtils.getPath(this.getSourceURI());
+    }
+
+    /**
+     * Gets the file extension for the source URI
+     */
+    public String getExtension() {
+        return NetUtils.getExtension(this.getSourceURI());
+    }
+    
+    /** 
+     * Gets the parent URI (the URI of the page that contained
+     * a link to this URI). null is returned if this page was
+     * not referred to in a link.
+     */
+    public String getParentURI() {
+        return this.parentURI;
+    }
+    
+    /**
+     * Calculates the destination URI - the URI to which the generated
+     * page should be written. This will be a URI that, when resolved
+     * by a SourceResolver, will return a modifiableSource.
+     * 
+     * This calculation is only done once per target. It is therefore
+     * necessary to ensure that the mime type has been set (if required)
+     * before this method is called.
+     */
+    public String getDestinationURI()
+        throws ProcessingException {
+        
+        if (this.finalDestinationURI == null) {
+            
+            String actualSourceURI = this.sourceURI;
+            if (!actualSourceURI.startsWith(root)) {
+                throw new ProcessingException(
+                    "Derived target does not share same root: "
+                        + actualSourceURI);
+            }
+            actualSourceURI = actualSourceURI.substring(root.length());
+            actualSourceURI = mangle(actualSourceURI);
+            
+            String destinationURI;
+            if (APPEND_TYPE.equals(this.type)) {
+                destinationURI = destURI + actualSourceURI;
+            } else if (REPLACE_TYPE.equals(this.type)) {
+                destinationURI = destURI;
+            } else if (INSERT_TYPE.equals(this.type)) {
+                int starPos = destURI.indexOf("*");
+                if (starPos == -1) {
+                    throw new ProcessingException("Missing * in replace mapper uri");
+                } else if (starPos == destURI.length() - 1) {
+                    destinationURI = destURI.substring(0, starPos) + actualSourceURI;
+                } else {
+                    destinationURI = destURI.substring(0, starPos)
+                        + actualSourceURI
+                        + destURI.substring(starPos + 1);
+                }
+            } else {
+                throw new ProcessingException(
+                    "Unknown mapper type: " + this.type);
+            }
+            if (mimeType != null) {
+                final String ext = NetUtils.getExtension(destinationURI);
+                final String defaultExt = MIMEUtils.getDefaultExtension(mimeType);
+                if (defaultExt != null) {
+                    if ((ext == null) || (!ext.equals(defaultExt))) {
+                        destinationURI += defaultExt;
+                    }
+                }
+            }
+            if (this.extension != null) {
+                destinationURI += this.extension; 
+            }
+            this.finalDestinationURI = destinationURI;
+        }
+        return this.finalDestinationURI;
+    }
+
+    /**
+     * Gets a translated version of a link, ready for insertion
+     * into another page as a link. This link needs to be
+     * relative to the original page.
+     */
+    public String getTranslatedURI(String path) {
+                    
+        String actualSourceURI = this.sourceURI;
+        if (!actualSourceURI.startsWith(root)) {
+            return actualSourceURI;
+        }
+        actualSourceURI = mangle(actualSourceURI);
+        
+        if (mimeType != null) {
+            final String ext = NetUtils.getExtension(actualSourceURI);
+            final String defaultExt = MIMEUtils.getDefaultExtension(mimeType);
+            if (defaultExt != null) {
+                if ((ext == null) || (!ext.equals(defaultExt))) {
+                    actualSourceURI += defaultExt;
+                }
+            }
+        }
+        return NetUtils.relativize(path, actualSourceURI);
+    }
+
+    /**
+     * 
+     * @return destination URI after all authentication details have been
+     *         removed
+     */
+    public String getAuthlessDestURI() throws ProcessingException {
+        return NetUtils.removeAuthorisation(this.getDestinationURI());
+    }
+    
+    /**
+     * Gets the original URI used to create this Target.
+     * This URI is completely unprocessed.
+     */
+    public String getOriginalSourceURI() {
+        return this.originalURI;
+    }
+
+    /**
+     * Gets the source URI for this target, after
+     * the URI has been 'prepared' by normalisation,
+     * absolutization and deparameterization followed
+     * by reparameterization. This final step is to 
+     * ensure that all parameters appear in a consistent
+     * order. For example page?a=1&b=2 and page?b=2&a=1
+     * should be considered the same resource, and thus
+     * have the same sourceURI. 
+     */
+    public String getSourceURI() {
+        return this.sourceURI;
+    }
+    
+    /**
+     * Gets the source URI for this target, with 
+     * parameters removed. This is the URI that is 
+     * to be passed to Cocoon in order to generate 
+     * the page.
+     */
+    public String getDeparameterizedSourceURI() {
+        return this.deparameterizedSourceURI;
+    }
+
+    /**
+     * Gets the parameters that have been removed from
+     * the URI. These need to be passed to Cocoon when
+     * generating a page.
+     */
+    public TreeMap getParameters() {
+        return this.parameters;
+    }
+
+    /**
+     * Mangle a URI.
+     *
+     * @param uri a URI to mangle
+     * @return a mangled URI
+     */
+    private String mangle(String uri) {
+        if (uri.length()==0 || uri.charAt(uri.length() - 1) == '/') {
+            uri += defaultFilename;
+        }
+        uri = uri.replace('"', '\'');
+        uri = uri.replace('?', '_');
+        uri = uri.replace(':', '_');
+
+        return uri;
+    }
+
+    public boolean equals(Object o) {
+        return (o instanceof Target) && o.toString().equals(toString());
+    }
+
+    public int hashCode() {
+        if (_hashCode == 0) {
+            return _hashCode = toString().hashCode();
+        }
+        return _hashCode;
+    }
+
+    public String toString() {
+        if (_toString == null) {
+            return _toString =
+                "<"
+                    + type
+                    + "|"
+                    + root
+                    + "|"
+                    + sourceURI
+                    + "|"
+                    + destURI
+                    + ">";
+        }
+        return _toString;
+    }
+    /**
+     * @return boolean
+     */
+    public boolean confirmExtensions() {
+        return confirmExtension;
+    }
+
+    public boolean followLinks() {
+        return followLinks;
+    }
+
+    public String getLogger() {
+        return logger;
+    }
+
+    public void setConfirmExtension(boolean b) {
+        confirmExtension = b;
+    }
+
+    public void setFollowLinks(boolean b) {
+        followLinks = b;
+    }
+
+    public void setLogger(String string) {
+        logger = string;
+    }
+}

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/Target.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/AntDelegate.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/AntDelegate.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/AntDelegate.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/AntDelegate.java Thu Nov  3 05:41:06 2005
@@ -0,0 +1,55 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cocoon.bean.helpers;
+
+import org.w3c.dom.Document;
+import org.apache.cocoon.bean.CocoonBean;
+import org.apache.cocoon.bean.helpers.OutputStreamListener;
+import org.apache.cocoon.bean.helpers.BeanConfigurator;
+
+/**
+ * Delegate class for use by the Cocoon Ant task. Allows Ant to run
+ * Cocoon with a single method call that can happily be started with 
+ * introspection (due to classpath issues).
+ *  
+ * @author <a href="mailto:uv@upaya.co.uk">Upayavira</a>
+ * @version CVS $Id: AntDelegate.java 54546 2004-10-11 10:25:11Z upayavira $
+ */
+public class AntDelegate {
+
+    public static int process(Document xconf, String uriGroup) throws Exception {
+        CocoonBean cocoon = new CocoonBean();
+        OutputStreamListener listener = new OutputStreamListener(System.out);
+        cocoon.addListener(listener);
+        BeanConfigurator.configure(xconf, cocoon, "", uriGroup, listener);
+
+        System.out.println(CocoonBean.getProlog());
+
+        if (!cocoon.isPrecompileOnly() && cocoon.getTargetCount() ==0) {
+            listener.messageGenerated("Please, specify at least one starting URI.");
+            System.exit(1);
+        }
+
+        cocoon.initialize();
+        cocoon.process();
+        cocoon.dispose();
+
+        listener.complete();
+        return listener.isSuccessful() ? 0 : 1;
+    }
+}
+

Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/bean/helpers/AntDelegate.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message