You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/07/11 21:51:01 UTC

svn commit: r420964 - in /cocoon/whiteboard/processor/main: ./ java/ java/org/ java/org/apache/ java/org/apache/cocoon/ java/org/apache/cocoon/processing/ java/org/apache/cocoon/processing/impl/ java/org/apache/cocoon/processing/pipeline/ java/org/apac...

Author: cziegeler
Date: Tue Jul 11 12:51:00 2006
New Revision: 420964

URL: http://svn.apache.org/viewvc?rev=420964&view=rev
Log:
Initial idea for new processor interface/impl

Added:
    cocoon/whiteboard/processor/main/
    cocoon/whiteboard/processor/main/java/
    cocoon/whiteboard/processor/main/java/org/
    cocoon/whiteboard/processor/main/java/org/apache/
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/Processor.java   (with props)
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponse.java   (with props)
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponseWrapper.java   (with props)
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/impl/
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/impl/MountTableProcessorImpl.java   (with props)
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Consumer.java   (with props)
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Producer.java   (with props)
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/SitemapProcessorFactory.java   (with props)
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/impl/
    cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/impl/SitemapProcessorFactoryImpl.java   (with props)

Added: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/Processor.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/Processor.java?rev=420964&view=auto
==============================================================================
--- cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/Processor.java (added)
+++ cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/Processor.java Tue Jul 11 12:51:00 2006
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2006 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.processing;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @version $Id$
+ */
+public interface Processor {
+
+    boolean process(HttpServletRequest request, HttpServletResponse response)
+    throws Exception;
+
+}

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/Processor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/Processor.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponse.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponse.java?rev=420964&view=auto
==============================================================================
--- cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponse.java (added)
+++ cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponse.java Tue Jul 11 12:51:00 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006 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.processing;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * This interface makrs a {@link HttpServletResponse} as SAX aware. If the
+ * {@link Processor} processing this request is able to emit SAX events
+ * the processor will send SAX events rather than writing to the output stream
+ * of the response.
+ *
+ * @version $Id$
+ */
+public interface SAXAwareHttpServletResponse extends HttpServletResponse {
+
+    /**
+     * The {@link ContentHandler} receiving the events. This method must not
+     * return null.
+     * @return The content handler.
+     */
+    ContentHandler getContentHandler();
+
+    /**
+     * The optional {@link LexicalHandler} receiving events.
+     * @return The lexical handler or null.
+     */
+    LexicalHandler getLexicalHandler();
+}

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponse.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponseWrapper.java?rev=420964&view=auto
==============================================================================
--- cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponseWrapper.java (added)
+++ cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponseWrapper.java Tue Jul 11 12:51:00 2006
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2006 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.processing;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * 
+ * @version $Id$
+ */
+public class SAXAwareHttpServletResponseWrapper
+    extends HttpServletResponseWrapper
+    implements SAXAwareHttpServletResponse {
+
+    protected final LexicalHandler lexicalHandler;
+    protected final ContentHandler handler;
+
+    public SAXAwareHttpServletResponseWrapper(HttpServletResponse response, ContentHandler handler, LexicalHandler lexicalHandler) {
+        super(response);
+        this.lexicalHandler = lexicalHandler;
+        this.handler = handler;
+    }
+
+    /**
+     * @see org.apache.cocoon.processing.SAXAwareHttpServletResponse#getContentHandler()
+     */
+    public ContentHandler getContentHandler() {
+        return this.handler;
+    }
+
+    /**
+     * @see org.apache.cocoon.processing.SAXAwareHttpServletResponse#getLexicalHandler()
+     */
+    public LexicalHandler getLexicalHandler() {
+        return this.lexicalHandler;
+    }
+}

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponseWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/SAXAwareHttpServletResponseWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/impl/MountTableProcessorImpl.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/impl/MountTableProcessorImpl.java?rev=420964&view=auto
==============================================================================
--- cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/impl/MountTableProcessorImpl.java (added)
+++ cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/impl/MountTableProcessorImpl.java Tue Jul 11 12:51:00 2006
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2006 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.processing.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.configuration.Settings;
+import org.apache.cocoon.core.container.util.ConfigurationBuilder;
+import org.apache.cocoon.processing.Processor;
+import org.apache.cocoon.processing.sitemap.SitemapProcessorFactory;
+import org.apache.cocoon.servlet.RequestUtil;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceValidity;
+
+/**
+ * A processor that manages a "mount table", allowing to add sitemaps to a Cocoon application going
+ * thorugh the main sitemap.
+ *
+ * <p>
+ * The mount table is an xml file which has the following syntax:
+ * <pre>
+ *   &lt;mount-table&gt;
+ *     &lt;mount uri-prefix="foo" src="file://path/to/foo/directory/"/&gt;
+ *     &lt;mount uri-prefix="bar/baz" src="file://path/to/bar-baz/directory/"/&gt;
+ *   &lt;/mount-table&gt;
+ * </pre>
+ * The processor will scan the mount table for an "uri-prefix" value matching the beginning of the current
+ * request URI, and if found, forward to a sitemap processor managing the sitemap defined by src.
+ *
+ * @version $Id$
+ */
+public class MountTableProcessorImpl implements Processor {
+
+    /** Source resolver to resolve the configuration file. */
+    protected SourceResolver resolver;
+
+    /** Location of the mount table. */
+    protected String mountTableLocation;
+
+    protected SourceValidity mountTableValidity;
+
+    /** Mounttable */
+    protected List mountEntries = new ArrayList();
+
+    /** Settings. */
+    protected Settings settings;
+
+    protected SitemapProcessorFactory sitemapProcessorFactory;
+
+    public void setSourceResolver(SourceResolver resolver) {
+        this.resolver = resolver;
+    }
+
+    public void setSettings(Settings settings) {
+        this.settings = settings;
+    }
+
+    public void setSitemapProcessorFactory(SitemapProcessorFactory factory) {
+        this.sitemapProcessorFactory = factory;
+    }
+
+    /**
+     * @see org.apache.cocoon.processing.Processor#process(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
+     */
+    public boolean process(HttpServletRequest request, HttpServletResponse response)
+    throws Exception {
+        final String uri = RequestUtil.getCompleteUri(request, response);
+        if ( uri == null ) {
+            // a redirect occured
+            return true;
+        }
+        // and search for a matching prefix
+        Iterator iter = this.mountEntries.iterator();
+        while (iter.hasNext()) {
+            final MountTableEntry entry = (MountTableEntry) iter.next();
+            if (uri.startsWith(entry.uriPrefix)) {
+                // Found it
+                // if they are equal, issue a redirect
+                if ( uri.length() == entry.uriPrefix.length() ) {
+                    response.sendRedirect(uri + '/');
+                    return true;
+                }
+                // check for '/' following the prefix, otherwise we don't match
+                if ( uri.charAt(entry.uriPrefix.length()) == '/' ) {
+                    // ok, now we are sure
+                    if ( entry.stripPrefix ) {
+                        request = RequestUtil.createRequestForUri(request, uri.substring(entry.uriPrefix.length()+1));
+                    }
+                    final Processor sitemapProcessor = this.sitemapProcessorFactory.getSitemapProcessor(entry.src);
+                    if ( sitemapProcessor != null ) {
+                        return sitemapProcessor.process(request, response);
+                    }
+                    return false;
+                }
+            }
+        }
+
+        // Not found
+        return false;
+    }
+
+    protected void loadMountTable()
+    throws Exception {
+        Source source = null;
+        try {
+            source = this.resolver.resolveURI(this.mountTableLocation);
+
+            if ( this.mountEntries != null ) {
+                // Check validity
+
+                int valid = this.mountTableValidity != null ? this.mountTableValidity.isValid() : SourceValidity.INVALID;
+                if (valid == SourceValidity.VALID) {
+                    // Valid without needing the new validity
+                    return;
+                }
+
+                if (valid == SourceValidity.UNKNOWN &&
+                        this.mountTableValidity.isValid(source.getValidity()) == SourceValidity.VALID) {
+                    // Valid after comparing with the new validity
+                    // update validity
+                    this.mountTableValidity = source.getValidity();
+                    return;
+                }
+                this.mountEntries = null;
+                // Invalid: fallback below to read the mount table
+            }
+
+            synchronized (this) {
+                if ( this.mountEntries != null ) {
+                    // Read the mount table
+                    final List mounts = new ArrayList();
+                    ConfigurationBuilder builder = new ConfigurationBuilder(this.settings);
+                    Configuration config = builder.build(SourceUtil.getInputSource(source));
+        
+                    Configuration[] children = config.getChildren();
+                    for (int i = 0; i < children.length; i++) {
+                        Configuration child = children[i];
+                        if ("mount".equals(child.getName())) {
+                            String prefix = children[i].getAttribute("uri-prefix");
+                            // remove a trailing '/'
+                            // Append a '/' at the end of a not-empty prefix
+                            if ( prefix.endsWith("/") ) {
+                                prefix = prefix.substring(0, prefix.length() - 1);
+                            }
+                            final MountTableEntry entry = new MountTableEntry();
+                            entry.src = children[i].getAttribute("src");
+                            entry.uriPrefix = prefix;
+                            entry.stripPrefix = children[i].getAttributeAsBoolean("strip-uri-prefix", true);
+                            mounts.add(entry);
+                        } else {
+                            throw new Exception(
+                                "Unexpected element '" + child.getName() + "' (awaiting 'mount'), at " + child.getLocation());
+                        }
+                    }
+                    this.mountEntries = mounts;
+                    this.mountTableValidity = source.getValidity();
+                }
+            }
+        } finally {
+            this.resolver.release(source);
+        }
+    }
+
+    public static class MountTableEntry {
+        public String uriPrefix;
+        public String src;
+        public boolean stripPrefix;
+    }
+}

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/impl/MountTableProcessorImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/impl/MountTableProcessorImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Consumer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Consumer.java?rev=420964&view=auto
==============================================================================
--- cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Consumer.java (added)
+++ cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Consumer.java Tue Jul 11 12:51:00 2006
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 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.processing.pipeline;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * This interfaces identifies classes that consume XML data, receiving
+ * notification of SAX events.
+ * <p>
+ * An XMLConsumer is also a SAX ContentHandler and a SAX LexicalHandler.  That
+ * means the XMLConsumer has to respect all the contracts with the SAX
+ * interfaces.  SAX stands for Serialized API for XML.  A document start, and
+ * each element start must be matched by the corresponding element end or
+ * document end.  So why does Cocoon use SAX instead of manipulating a DOM?
+ * For two main reasons: performance and scalability.  A DOM tree is much more
+ * heavy on system memory than successive calls to an API.  SAX events can be
+ * sent as soon as they are read from the originating XML, the parsing and
+ * processing can happen essentially at the same time.
+ * </p>
+ * <p>
+ * Most people's needs will be handled just fine with the ContentHandler
+ * interface, as that declares your namespaces.  However if you need lexical
+ * support to resolve entity names and such, you need the LexicalHandler
+ * interface.  The AbstractXMLConsumer base class can make implementing this
+ * interface easier so that you only need to override the events you intend to
+ * do anything with.
+ * </p>
+ *
+ * @version $Id$
+ */
+public interface Consumer extends ContentHandler, LexicalHandler {
+    // just a combination of the two
+}

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Consumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Consumer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Producer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Producer.java?rev=420964&view=auto
==============================================================================
--- cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Producer.java (added)
+++ cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Producer.java Tue Jul 11 12:51:00 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006 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.processing.pipeline;
+
+/**
+ * This interfaces identifies classes that produce XML data, sending SAX
+ * events to the configured <code>XMLConsumer</code>.
+ * <p>
+ * The XMLProducer is comprised of only one method to give the component the
+ * next element of the pipeline.  Cocoon calls the <code>setConsumer()</code>
+ * method with the reference to the next XMLConsumer in the pipeline.  The
+ * approach allows the XMLProducer to call the different SAX related methods on
+ * the XMLConsumer without knowing ahead of time what that consumer will be.
+ * The design is very simple and very powerful in that it allows Cocoon to
+ * daisy chain several components in any order and then execute the pipeline.
+ * </p>
+ * <p>
+ * Any producer can be paired with any consumer and we have a pipeline.  The
+ * core design is very powerful and allows the end user to mix and match
+ * sitemap components as they see fit.  Cocoon will always call
+ * <code>setConsumer()</code> on every XMLProducer in a pipeline or it will
+ * throw an exception saying that the pipeline is invalid (i.e. there is no
+ * serializer for the pipeline).  The only contract that the XMLProducer has to
+ * worry about is that it must always make calls to the XMLConsumer passed in
+ * through the <code>setConsumer()</code> method.
+ * </p>
+ *
+ * @version $Id$
+ */
+public interface Producer {
+
+    /**
+     * Set the {@link Consumer} that will receive XML data.
+     *
+     * @param consumer  The Consumer target for SAX events.
+     */
+    void setConsumer(Consumer consumer);
+}

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Producer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/pipeline/Producer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/SitemapProcessorFactory.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/SitemapProcessorFactory.java?rev=420964&view=auto
==============================================================================
--- cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/SitemapProcessorFactory.java (added)
+++ cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/SitemapProcessorFactory.java Tue Jul 11 12:51:00 2006
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2006 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.processing.sitemap;
+
+import org.apache.cocoon.processing.Processor;
+
+/**
+ * @version $Id$
+ */
+public interface SitemapProcessorFactory {
+
+    Processor getSitemapProcessor(String sitemapLocation)
+    throws Exception;
+}

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/SitemapProcessorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/SitemapProcessorFactory.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/impl/SitemapProcessorFactoryImpl.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/impl/SitemapProcessorFactoryImpl.java?rev=420964&view=auto
==============================================================================
--- cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/impl/SitemapProcessorFactoryImpl.java (added)
+++ cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/impl/SitemapProcessorFactoryImpl.java Tue Jul 11 12:51:00 2006
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2006 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.processing.sitemap.impl;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.ProcessingUtil;
+import org.apache.cocoon.components.treeprocessor.TreeProcessor;
+import org.apache.cocoon.processing.Processor;
+import org.apache.cocoon.processing.sitemap.SitemapProcessorFactory;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.beans.factory.DisposableBean;
+
+/**
+ * 
+ * @version $Id$
+ */
+public class SitemapProcessorFactoryImpl
+    implements SitemapProcessorFactory, BeanFactoryAware, DisposableBean {
+
+    protected Map processors = new HashMap();
+
+    protected SourceResolver resolver;
+
+    protected Logger logger;
+
+    protected Context context;
+
+    protected BeanFactory beanFactory;
+
+    protected ServiceManager manager;
+
+    public void setSourceResolver(SourceResolver resolver) {
+        this.resolver = resolver;
+    }
+    /**
+     * @see org.apache.cocoon.processing.sitemap.SitemapProcessorFactory#getSitemapProcessor(java.lang.String)
+     */
+    public Processor getSitemapProcessor(String sitemapLocation) throws Exception {
+        Source source = null;
+        try {
+            source = this.resolver.resolveURI(sitemapLocation);
+            final String uri = source.getURI();
+            Processor processor = (Processor) this.processors.get(uri);
+            if ( processor == null ) {
+                synchronized ( this ) {
+                    processor = (Processor)this.processors.get(uri);
+                    if ( processor == null ) {
+                        // create a configuration object
+                        DefaultConfiguration rootConfiguration = new DefaultConfiguration("component");
+                        // rootConfiguration.setAttribute("check-reload", false);
+                        //DefaultConfiguration reloadConfig = new DefaultConfiguration("reload");
+                        //reloadConfig.setAttribute("delay", 1000L);
+                        //rootConfiguration.addChild(reloadConfig);
+                        rootConfiguration.setAttribute("file", uri);
+
+                        processor = (Processor) new TreeProcessor();
+                        ((BeanFactoryAware)processor).setBeanFactory(this.beanFactory);
+                        ContainerUtil.enableLogging(processor, this.logger);
+                        ContainerUtil.contextualize(processor, this.context);
+                        ContainerUtil.service(processor, this.manager);
+                        ContainerUtil.configure(processor, rootConfiguration);
+                        ContainerUtil.initialize(processor);
+                        this.processors.put(uri, processor);
+                    }
+                }
+            }
+            return processor;
+        } finally {
+            this.resolver.release(source);
+        }
+    }
+
+    /**
+     * @see org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+     */
+    public void setBeanFactory(BeanFactory factory) throws BeansException {
+        this.beanFactory = factory;
+        this.logger = (Logger)this.beanFactory.getBean(ProcessingUtil.LOGGER_ROLE);
+        this.context = (Context)this.beanFactory.getBean(ProcessingUtil.CONTEXT_ROLE);
+        this.manager = (ServiceManager)this.beanFactory.getBean(ProcessingUtil.SERVICE_MANAGER_ROLE);
+    }
+
+    /**
+     * @see org.springframework.beans.factory.DisposableBean#destroy()
+     */
+    public void destroy() throws Exception {
+        final Iterator i = this.processors.values().iterator();
+        while ( i.hasNext() ) {
+            ContainerUtil.dispose(i.next());
+        }
+        this.processors.clear();
+    }
+
+}

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/impl/SitemapProcessorFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/whiteboard/processor/main/java/org/apache/cocoon/processing/sitemap/impl/SitemapProcessorFactoryImpl.java
------------------------------------------------------------------------------
    svn:keywords = Id