You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jh...@apache.org on 2005/11/03 15:00:48 UTC
svn commit: r330548 [25/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/...
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlocksSourceFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlocksSourceFactory.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlocksSourceFactory.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlocksSourceFactory.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,90 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceFactory;
+import org.apache.excalibur.source.URIAbsolutizer;
+import org.apache.excalibur.source.SourceUtil;
+
+/**
+ * This class implements the blocks: protocol.
+ *
+ * WARNING: It is created for being able to use the blocks
+ * functionality without needing to change the Cocoon object and other
+ * fundamental classes. This class will probably be removed later.
+ *
+ * @version $Id: BlocksSourceFactory.java 292282 2005-09-28 19:54:16Z vgritsenko $ */
+public final class BlocksSourceFactory
+ extends AbstractLogEnabled
+ implements SourceFactory, ThreadSafe, Serviceable, URIAbsolutizer
+{
+
+ /** The <code>ServiceManager</code> */
+ private ServiceManager manager;
+
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
+ */
+ public Source getSource( String location, Map parameters )
+ throws MalformedURLException, IOException {
+ if( getLogger().isDebugEnabled() ) {
+ getLogger().debug( "Creating source object for " + location );
+ }
+
+ return new BlocksSource( this.manager,
+ location,
+ parameters,
+ getLogger());
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
+ */
+ public void release( Source source ) {
+ if ( null != source ) {
+ if ( this.getLogger().isDebugEnabled() ) {
+ this.getLogger().debug("Releasing source " + source.getURI());
+ }
+ ((BlocksSource)source).recycle();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.URIAbsolutizer#absolutize(java.lang.String, java.lang.String)
+ */
+ public String absolutize(String baseURI, String location) {
+ return SourceUtil.absolutize(baseURI, location, true);
+ }
+
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/BlocksSourceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ContextSourceFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ContextSourceFactory.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ContextSourceFactory.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ContextSourceFactory.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,184 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.environment.Context;
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceFactory;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceUtil;
+import org.apache.excalibur.source.TraversableSource;
+import org.apache.excalibur.source.URIAbsolutizer;
+
+/**
+ * A factory for the context protocol using the context of the servlet api.
+ * It builds the source by asking the environment context for the real URL
+ * (see {@link org.apache.cocoon.environment.Context#getResource(String)})
+ * and then resolving this real URL.
+ *
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @author <a href="http://www.apache.org/~sylvain">Sylvain Wallez</a>
+ * @version CVS $Id: ContextSourceFactory.java 160568 2005-04-08 17:33:05Z sylvain $
+ */
+public class ContextSourceFactory
+extends AbstractLogEnabled
+implements SourceFactory,
+ Serviceable,
+ Contextualizable,
+ ThreadSafe,
+ URIAbsolutizer {
+
+ /** The context */
+ protected Context envContext;
+
+ /** The ServiceManager */
+ protected ServiceManager manager;
+
+ /** Http servlet context - if available */
+ protected ServletContext servletContext;
+
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
+ */
+ public void contextualize(org.apache.avalon.framework.context.Context context)
+ throws ContextException {
+ this.envContext = (Context)context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT);
+ try {
+ this.servletContext = ((ServletConfig) context.get("servlet-config")).getServletContext();
+ } catch (ContextException ignore) {
+ // in other environments (CLI etc.), we don't have a servlet context
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
+ */
+ public Source getSource( String location, Map parameters )
+ throws SourceException, MalformedURLException, IOException {
+ if( this.getLogger().isDebugEnabled() ) {
+ this.getLogger().debug( "Creating source object for " + location );
+ }
+
+ // Lookup resolver
+ SourceResolver resolver = null;
+ try {
+ resolver = (SourceResolver)this.manager.lookup( SourceResolver.ROLE );
+
+ // Remove the protocol and the first '/'
+ final int pos = location.indexOf(":/");
+ final String scheme = location.substring(0, pos);
+ final String path = location.substring(pos+1);
+
+ // fix for #24093, we don't give access to files outside the context:
+ if ( path.indexOf("../") != -1 ) {
+ throw new MalformedURLException("Invalid path ('../' is not allowed) : " + path);
+ }
+
+ URL u;
+
+ // Try to get a file first and fall back to a resource URL
+ String actualPath = envContext.getRealPath(path);
+ if (actualPath != null) {
+ u = new File(actualPath).toURL();
+ } else {
+ u = envContext.getResource(path);
+ }
+
+ if (u != null) {
+ Source source = resolver.resolveURI(u.toExternalForm());
+ if ( parameters != null
+ && BooleanUtils.toBoolean("force-traversable")
+ && this.servletContext != null
+ && !(source instanceof TraversableSource) ) {
+ final Set children = this.servletContext.getResourcePaths(path + '/');
+ if ( children != null ) {
+ source = new TraversableContextSource(source, children, this, path, scheme);
+ }
+ }
+ return source;
+ }
+ final String message = location + " could not be found. (possible context problem)";
+ this.getLogger().info(message);
+ throw new MalformedURLException(message);
+ } catch (ServiceException se) {
+ throw new SourceException("Unable to lookup source resolver.", se);
+ } finally {
+ this.manager.release( resolver );
+ }
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
+ */
+ public void release( Source source ) {
+ // In fact, this method should never be called as this factory
+ // returns a source object from a different factory. So that
+ // factory should release the source
+ if ( null != source ) {
+ if ( this.getLogger().isDebugEnabled() ) {
+ this.getLogger().debug("Releasing source " + source.getURI());
+ }
+ SourceResolver resolver = null;
+ try {
+ resolver = (SourceResolver)this.manager.lookup( SourceResolver.ROLE );
+ if ( source instanceof TraversableContextSource ) {
+ resolver.release(((TraversableContextSource)source).wrappedSource);
+ } else {
+ resolver.release( source );
+ }
+ } catch (ServiceException ingore) {
+ // we ignore this
+ } finally {
+ this.manager.release( resolver );
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.URIAbsolutizer#absolutize(java.lang.String, java.lang.String)
+ */
+ public String absolutize(String baseURI, String location) {
+ return SourceUtil.absolutize(baseURI, location, true);
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ContextSourceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/DelayedRefreshSourceWrapper.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/DelayedRefreshSourceWrapper.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/DelayedRefreshSourceWrapper.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/DelayedRefreshSourceWrapper.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,182 @@
+/*
+ * 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.components.source.impl;
+
+import org.apache.avalon.excalibur.pool.Recyclable;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceValidity;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Iterator;
+
+/**
+ * A wrapper around a <code>Source</code> that reduces the number of calls to
+ * <code>Source.getLastModified()</code> which can be a costly operation.
+ *
+ * @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
+ * @version CVS $Id: DelayedRefreshSourceWrapper.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public final class DelayedRefreshSourceWrapper
+ implements Source {
+
+ private Source source;
+
+ private long delay;
+
+ private long nextCheckTime = 0;
+
+ private long lastModified = 0;
+
+ /**
+ * Creates a wrapper for a <code>Source</code> which ensures that
+ * <code>Source.getLastModified()</code> won't be called more than once per
+ * <code>delay</code> milliseconds period.
+ *
+ * @param source the wrapped <code>Source</code>
+ * @param delay the last-modified refresh delay, in milliseconds
+ */
+ public DelayedRefreshSourceWrapper(Source source, long delay) {
+ this.source = source;
+ this.delay = delay;
+ }
+
+ /**
+ * Get the real source
+ */
+ public Source getSource() {
+ return this.source;
+ }
+
+ public final InputStream getInputStream()
+ throws SourceException, IOException {
+ return this.source.getInputStream();
+ }
+
+ public final String getURI() {
+ return this.source.getURI();
+ }
+
+ /**
+ * Get the Validity object. This can either wrap the last modification
+ * date or the expires information or...
+ * If it is currently not possible to calculate such an information
+ * <code>null</code> is returned.
+ */
+ public SourceValidity getValidity() {
+ return this.source.getValidity();
+ }
+
+ /**
+ * Return the protocol identifier.
+ */
+ public String getScheme() {
+ return this.source.getScheme();
+ }
+
+ /**
+ *
+ * @see org.apache.excalibur.source.Source#exists()
+ */
+ public boolean exists() {
+ return this.source.exists();
+ }
+
+ /**
+ * Get the last modification time for the wrapped <code>Source</code>. The
+ * age of the returned information is guaranteed to be lower than or equal to
+ * the delay specified in the constructor.
+ * <p>
+ * This method is also thread-safe, even if the underlying Source is not.
+ *
+ * @return the last modification time.
+ */
+ public final long getLastModified() {
+
+ // Do we have to refresh the source ?
+ if (System.currentTimeMillis() >= nextCheckTime) {
+ // Yes
+ this.refresh();
+ }
+ return this.lastModified;
+ }
+
+ /**
+ * Force the refresh of the wrapped <code>Source</code>, even if the refresh period
+ * isn't over, and starts a new period.
+ * <p>
+ * This method is thread-safe, even if the underlying Source is not.
+ */
+ public synchronized final void refresh() {
+
+ this.nextCheckTime = System.currentTimeMillis() + this.delay;
+ // Refresh modifiable sources
+ this.source.refresh();
+
+ // Keep the last modified date
+ this.lastModified = source.getLastModified();
+ }
+
+ public final long getContentLength() {
+ return this.source.getContentLength();
+ }
+
+ /**
+ * The mime-type of the content described by this object.
+ * If the source is not able to determine the mime-type by itself
+ * this can be <code>null</code>.
+ */
+ public String getMimeType() {
+ return this.source.getMimeType();
+ }
+
+ public final void recycle() {
+ if (this.source instanceof Recyclable) {
+ ((Recyclable)this.source).recycle();
+ }
+ }
+
+ /**
+ * Get the value of a parameter.
+ * Using this it is possible to get custom information provided by the
+ * source implementation, like an expires date, HTTP headers etc.
+ */
+ public String getParameter(String name) {
+ return null;
+ }
+
+ /**
+ * Get the value of a parameter.
+ * Using this it is possible to get custom information provided by the
+ * source implementation, like an expires date, HTTP headers etc.
+ */
+ public long getParameterAsLong(String name) {
+ return 0;
+ }
+
+ /**
+ * Get parameter names
+ * Using this it is possible to get custom information provided by the
+ * source implementation, like an expires date, HTTP headers etc.
+ */
+ public Iterator getParameterNames() {
+ return java.util.Collections.EMPTY_LIST.iterator();
+
+ }
+
+
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/DelayedRefreshSourceWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySource.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySource.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySource.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySource.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,139 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.cocoon.xml.XMLUtils;
+import org.apache.excalibur.xml.sax.XMLizable;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceNotFoundException;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.NOPValidity;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * A <code>Source</code> that generates completely empty XML document or an
+ * XML document that contains just a root node.
+ *
+ * <p>
+ * The URI syntax is <code>empty:</code> for completely empty XML document
+ * or <code>create-document:root-element</code> for document with root element,
+ * where <code>root-element</code> is the name of the root element to create.
+ *
+ * @version $Id: EmptySource.java 292327 2005-09-28 22:03:40Z vgritsenko $
+ * @since 2.1.8
+ */
+public class EmptySource implements XMLizable, Source {
+
+ protected String rootElementName;
+ protected String scheme;
+ protected String uri;
+ protected String xmlDocument;
+
+ public EmptySource(String location) {
+ this.uri = location;
+ final int pos = location.indexOf(':');
+ this.scheme = location.substring(0, pos);
+
+ final String rootName = location.substring(pos + 1);
+ if (rootName != null && rootName.trim().length() > 0) {
+ this.rootElementName = rootName.trim();
+ this.xmlDocument = '<' + this.rootElementName + "/>";
+ } else {
+ this.xmlDocument = "";
+ }
+ }
+
+ /**
+ * @see org.apache.excalibur.xml.sax.XMLizable#toSAX(org.xml.sax.ContentHandler)
+ */
+ public void toSAX(ContentHandler handler) throws SAXException {
+ handler.startDocument();
+ if (rootElementName != null) {
+ XMLUtils.createElement(handler, this.rootElementName);
+ }
+ handler.endDocument();
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#exists()
+ */
+ public boolean exists() {
+ return true;
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getContentLength()
+ */
+ public long getContentLength() {
+ return this.xmlDocument.length();
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getInputStream()
+ */
+ public InputStream getInputStream() throws IOException, SourceNotFoundException {
+ return new ByteArrayInputStream(this.xmlDocument.getBytes("utf-8"));
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getLastModified()
+ */
+ public long getLastModified() {
+ // this document *never* changes
+ return 1;
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getMimeType()
+ */
+ public String getMimeType() {
+ return "text/xml";
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getScheme()
+ */
+ public String getScheme() {
+ return this.scheme;
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getURI()
+ */
+ public String getURI() {
+ return this.uri;
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getValidity()
+ */
+ public SourceValidity getValidity() {
+ return NOPValidity.SHARED_INSTANCE;
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#refresh()
+ */
+ public void refresh() {
+ // nothing to do here
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySourceFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySourceFactory.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySourceFactory.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySourceFactory.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,55 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceFactory;
+
+/**
+ * A factory for 'empty:' sources (see {@link EmptySource}).
+ *
+ * @version $Id: EmptySourceFactory.java 292327 2005-09-28 22:03:40Z vgritsenko $
+ * @since 2.1.8
+ */
+public class EmptySourceFactory extends AbstractLogEnabled
+ implements SourceFactory, ThreadSafe {
+
+ /**
+ * Get an {@link EmptySource} object.
+ *
+ * @param location The URI to resolve - this URI includes the scheme.
+ * @param parameters this is optional and not used here
+ *
+ * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
+ */
+ public Source getSource(String location, Map parameters)
+ throws IOException, MalformedURLException {
+ return new EmptySource(location);
+ }
+
+ /**
+ * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
+ */
+ public void release(Source source) {
+ // Do nothing here
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/EmptySourceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSource.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSource.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSource.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSource.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,198 @@
+/*
+ * 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.components.source.impl;
+
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.ServiceSelector;
+
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.impl.AbstractSource;
+
+import org.apache.cocoon.components.modules.input.InputModule;
+
+import org.apache.commons.jxpath.JXPathContext;
+
+
+/**
+ * A <code>Source</code> that takes its content from a
+ * module.
+ * <p>The URI syntax is
+ * "module:<input-module>:<attribute-name>[#XPath]",
+ * where :
+ * <ul>
+ * <li>an input-module name is used for finding an input-module for reading data from</li>,
+ * <li>"attribute-name" is the name of the attribute found in the module</li>,
+ * <li>"XPath" is an XPath that is aplied on the object in the
+ * attribute, by using JXPath.</li>
+ * </ul>
+ * </p>
+ *
+ * @author <a href="mailto:danielf@nada.kth.se">Daniel Fagerstom</a>
+ */
+
+public class ModuleSource
+ extends AbstractSource {
+
+ private final static String SCHEME = "module";
+ private String attributeType;
+ private String attributeName;
+ private String xPath;
+ private ServiceManager manager;
+ private Map objectModel;
+ private Logger logger;
+
+ /**
+ * Create a module source from a 'module:' uri and a the object model.
+ * <p>The uri is of the form "module:attribute-type:attribute-name#xpath</p>
+ */
+ public ModuleSource( Map objectModel, String uri,
+ ServiceManager manager, Logger logger )
+ throws MalformedURLException {
+
+ this.objectModel = objectModel;
+ this.manager = manager;
+ this.logger = logger;
+
+ setSystemId( uri );
+
+ // Scheme
+ int start = 0;
+ int end = uri.indexOf( ':' );
+ if ( end == -1 )
+ throw new MalformedURLException("Malformed uri for module source (cannot find scheme) : " + uri);
+
+ String scheme = uri.substring( start, end );
+ if ( !SCHEME.equals( scheme ) )
+ throw new MalformedURLException("Malformed uri for a module source : " + uri);
+
+ setScheme( scheme );
+
+ // Attribute type
+ start = end + 1;
+ end = uri.indexOf( ':', start );
+ if ( end == -1 ) {
+ throw new MalformedURLException("Malformed uri for module source (cannot find attribute type) : " + uri);
+ }
+ this.attributeType = uri.substring( start, end );
+
+ // Attribute name
+ start = end + 1;
+ end = uri.indexOf( '#', start );
+
+ if ( end == -1 )
+ end = uri.length();
+
+ if ( end == start )
+ throw new MalformedURLException("Malformed uri for module source (cannot find attribute name) : " + uri);
+
+ this.attributeName = uri.substring( start, end );
+
+ // xpath
+ start = end + 1;
+ this.xPath = start < uri.length() ? uri.substring( start ) : "";
+ }
+
+ /**
+ * Return an <code>InputStream</code> object to read from the source.
+ *
+ * @throws IOException if I/O error occured.
+ */
+ public InputStream getInputStream() throws IOException, SourceException {
+ if ( this.logger.isDebugEnabled() ) {
+ this.logger.debug( "Getting InputStream for " + getURI() );
+ }
+
+ Object obj = getInputAttribute( this.attributeType, this.attributeName );
+ if ( obj == null )
+ throw new SourceException( " The attribute: " + this.attributeName +
+ " is empty" );
+
+ if ( !(this.xPath.length() == 0 || this.xPath.equals( "/" )) ) {
+ JXPathContext context = JXPathContext.newContext( obj );
+ obj = context.getValue( this.xPath );
+
+ if ( obj == null )
+ throw new SourceException( "the xpath: " + this.xPath +
+ " applied on the attribute: " +
+ this.attributeName +
+ " returns null");
+ }
+
+ if ( obj instanceof InputStream ) {
+ return (InputStream)obj;
+ } else if ( obj instanceof Source ) {
+ return ((Source)obj).getInputStream();
+ } else if ( obj instanceof String ) {
+ return new ByteArrayInputStream( ((String)obj).getBytes() );
+ } else if (obj instanceof byte[]) {
+ return new ByteArrayInputStream((byte[]) obj);
+ } else {
+ throw new SourceException( "The object type: " + obj.getClass() +
+ " could not be serialized as a InputStream " + obj );
+ }
+ }
+
+ /**
+ * Does this source actually exist ?
+ *
+ * @return true if the resource exists.
+ *
+ */
+ public boolean exists() {
+ boolean exists = false;
+ try {
+ exists = getInputAttribute( this.attributeType, this.attributeName ) != null;
+ } catch ( SourceException e ) {
+ exists = false;
+ }
+ return exists;
+ }
+
+ private Object getInputAttribute( String inputModuleName, String attributeName )
+ throws SourceException {
+ Object obj;
+ ServiceSelector selector = null;
+ InputModule inputModule = null;
+ try {
+ selector = (ServiceSelector) this.manager.lookup( InputModule.ROLE + "Selector" );
+ inputModule = (InputModule) selector.select( inputModuleName );
+ obj = inputModule.getAttribute( attributeName, null, this.objectModel );
+
+ } catch ( ServiceException e ) {
+ throw new SourceException( "Could not find an InputModule of the type " +
+ inputModuleName , e );
+ } catch ( ConfigurationException e ) {
+ throw new SourceException( "Could not find an attribute: " + attributeName +
+ " from the InputModule " + inputModuleName, e );
+ } finally {
+ if ( inputModule != null ) selector.release( inputModule );
+ this.manager.release( selector );
+ }
+
+ return obj;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSourceFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSourceFactory.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSourceFactory.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSourceFactory.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,84 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceFactory;
+
+import org.apache.cocoon.components.ContextHelper;
+
+/**
+ * A factory for 'module:' sources (see {@link ModuleSource}).
+ *
+ * @author <a href="mailto:danielf@nada.kth.se">Daniel Fagerstrom</a>
+ */
+
+public class ModuleSourceFactory extends AbstractLogEnabled
+ implements SourceFactory, Serviceable, Contextualizable, ThreadSafe {
+
+ private ServiceManager manager;
+ private Context context;
+
+ /**
+ * Servicable Interface
+ */
+ public void service( ServiceManager manager ) throws ServiceException {
+ this.manager = manager;
+ }
+
+ /**
+ * Contextualizable, get the object model
+ */
+ public void contextualize( Context context ) throws ContextException {
+ this.context = context;
+ }
+
+
+ /**
+ * Get a {@link ModuleSource} object.
+ *
+ * @param location The URI to resolve - this URI includes the scheme.
+ * @param parameters this is optional and not used here
+ */
+ public Source getSource( String location, Map parameters )
+ throws IOException, MalformedURLException {
+
+ Map objectModel = ContextHelper.getObjectModel( this.context );
+ return new ModuleSource( objectModel, location, this.manager, getLogger() );
+ }
+
+ /**
+ * Release a {@link Source} object.
+ */
+ public void release( Source source ) {
+ // Do nothing here
+ }
+
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/ModuleSourceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,213 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.impl.validity.AbstractAggregatedValidity;
+
+/**
+ * <p>An aggregated {@link SourceValidity} for multiple sources.</p>
+ *
+ * @author <a href="http://www.apache.org/~sylvain">Sylvain Wallez</a>
+ * @version $Id: MultiSourceValidity.java 158099 2005-03-18 16:57:54Z vgritsenko $
+ */
+public class MultiSourceValidity extends AbstractAggregatedValidity
+ implements SourceValidity {
+
+ /** <p>When validity expiration is performed.</p> */
+ private long expiry;
+
+ /** <p>The delay from <b>now</b> used to calculate the expiration time.</p> */
+ private long delay;
+
+ /** <p>An ordered list of URIs which should be checked.</p> */
+ private List uris = new ArrayList();
+
+ /** <p>Is this instance is closed (accepts modifications or is validable)? */
+ private boolean isClosed = false;
+
+ /** <p>The {@link SourceResolver} to use (transient not to be serialized). */
+ private transient SourceResolver resolver;
+
+ /**
+ * <p>The delay value indicating to check always.</p>
+ */
+ public static final int CHECK_ALWAYS = -1;
+
+ /**
+ * <p>Create a new {@link MultiSourceValidity} instance.</p>
+ *
+ * <p>If the number of milliseconds is less than <b>zero</b>, or it's sum with
+ * the number of <b>now</b> milliseconds is greater than the biggest long
+ * representable, the expiration date will be set to {@link Long#MAX_VALUE}
+ * milliseconds from the epoch.</p>
+ *
+ * @param resolver the {@link SourceResolver} used to access the sources.
+ * @param delay the number of milliseconds from <b>now</b> defining for how long
+ * this instance will be valid.
+ */
+ public MultiSourceValidity(SourceResolver resolver, long delay) {
+ /* Calculate the initial expiration time and calculate the delay */
+ this.resolver = resolver;
+ this.expiry = System.currentTimeMillis() + delay;
+ this.delay = delay;
+ }
+
+ /**
+ * <p>Add a {@link Source} to the list of {@link Source}s monitored by this
+ * instance.</p>
+ *
+ * @param src a <b>non-null</b> {@link Source}.
+ */
+ public void addSource(Source src) {
+ if (this.uris != null) {
+ SourceValidity validity = src.getValidity();
+ if (validity == null) {
+ /* The source has no validity: this will be always be invalid. */
+ this.uris = null;
+ } else {
+ /* Add the validity and URI to the list */
+ super.add(validity);
+ this.uris.add(src.getURI());
+ }
+ }
+ }
+
+ /**
+ * <p>Close this instance, or in other words declare that no other sources will
+ * be added to this {@link MultiSourceValidity} and that checkings can be now
+ * performed.</p>
+ */
+ public void close() {
+ this.isClosed = true;
+ this.resolver = null;
+ }
+
+ /**
+ * <p>Check the validity of this {@link SourceValidity} instance.</p>
+ *
+ * @see SourceValidity#isValid()
+ */
+ public int isValid() {
+ if (System.currentTimeMillis() <= expiry) {
+ /* Validity not expired, so, don't even check */
+ return SourceValidity.VALID;
+ }
+
+ /* Re-calculate the expiry time based on the current time */
+ expiry = System.currentTimeMillis() + delay;
+
+ if (uris == null || !isClosed) {
+ /* We have not been closed (yet) or we were forced to be invalid */
+ return SourceValidity.INVALID;
+ } else {
+ /* Compute the status of all the sources listed in this instance */
+ return computeStatus(null);
+ }
+ }
+
+ /**
+ * <p>Check the validity of this instance comparing it with a (recently acquired)
+ * new {@link SourceValidity} object.</p>
+ *
+ * @see SourceValidity#isValid(SourceValidity)
+ */
+ public int isValid(SourceValidity newValidity) {
+ if (uris == null || !isClosed) {
+ /* We have not been closed (yet) or we were forced to be invalid */
+ return SourceValidity.INVALID;
+ }
+
+ /* Perform a simple class check and compute the validity of the sources */
+ if (newValidity instanceof MultiSourceValidity) {
+ return computeStatus(((MultiSourceValidity)newValidity).resolver);
+ } else {
+ /* The supplied validity is not an instance of ourselves, forget it */
+ return SourceValidity.INVALID;
+ }
+ }
+
+ /**
+ * <p>Compute the status of this instance by checking every source.</p>
+ *
+ * @param resolver The {@link SourceResolver} to use to access sources.
+ * @return {@link SourceValidity.VALID}, {@link SourceValidity.INVALID} or
+ * {@link SourceValidity.UNKNOWN} depending on the status.
+ */
+ private int computeStatus(SourceResolver resolver) {
+ /* Get the validities and analyse them one by one */
+ List validities = super.getValidities();
+ for (int i = 0; i < validities.size(); i++) {
+
+ /* Check the validity status */
+ SourceValidity validity = (SourceValidity) validities.get(i);
+ switch (validity.isValid()) {
+
+ /* The current source is valid: just continue to next source */
+ case SourceValidity.VALID:
+ break;
+
+ /* The current source is invalid: stop examining */
+ case SourceValidity.INVALID:
+ return SourceValidity.INVALID;
+
+ /* The source validity is not known: check with the new source */
+ case SourceValidity.UNKNOWN:
+ /* We have no resolver: definitely don't know */
+ if (resolver == null) {
+ return SourceValidity.UNKNOWN;
+ }
+
+ /* Check the new source by asking to the resolver */
+ Source newSrc = null;
+ int newValidity = SourceValidity.INVALID;
+ try {
+ newSrc = resolver.resolveURI((String) this.uris.get(i));
+ newValidity = validity.isValid(newSrc.getValidity());
+ } catch(IOException ioe) {
+ /* Swallow the IOException, but set the new validity */
+ newValidity = SourceValidity.INVALID;
+ } finally {
+ /* Make sure that the source is released */
+ if (newSrc != null) {
+ resolver.release(newSrc);
+ }
+ }
+
+ /* If the source is still valid, go to the next one */
+ if (newValidity == SourceValidity.VALID) {
+ break;
+ }
+
+ /* The source is not valid (or unknown), we invalidate the lot */
+ return SourceValidity.INVALID;
+
+ /* We got something _really_ odd out tof the validity, dunno. */
+ default:
+ return SourceValidity.INVALID;
+ }
+ }
+
+ /* All items checked successfully */
+ return SourceValidity.VALID;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/MultiSourceValidity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSource.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSource.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSource.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSource.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,174 @@
+/*
+ * 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.components.source.impl;
+
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.source.SourceNotFoundException;
+
+import org.apache.cocoon.servlet.multipart.Part;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import java.net.MalformedURLException;
+import java.util.Map;
+import java.io.IOException;
+import java.io.InputStream;
+
+
+/**
+ * Implementation of a {@link Source} that gets its content
+ * from a PartOnDisk or PartInMemory held in the Request when
+ * a file is uploaded.
+ *
+ * @author <a href="mailto:paul.crabtree@dna.co.uk">Paul Crabtree</a>
+ * @version CVS $Id: PartSource.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public class PartSource implements Source
+{
+ /* hold a private ref to the protocol used to call the Source */
+ private String protocol;
+
+ /* hold a private ref to the full uri */
+ private String uri;
+
+ /* hold a private ref to the Part which has been uploaded. */
+ private Part part;
+
+ /**
+ * Builds a PartSource given an URI.
+ * @param uri e.g., upload://formField1
+ * @throws SourceException
+ * @throws MalformedURLException
+ */
+ public PartSource(String uri, Map objectModel) throws MalformedURLException, SourceException
+ {
+ // set the uri for use in getURI()
+ this.uri = uri;
+
+ int position = uri.indexOf(':') + 1;
+ if (position != 0)
+ {
+ // set the protocol for use in getScheme()
+ this.protocol = uri.substring(0, position-1);
+ }
+ else
+ {
+ // if the URI is not correctly formatted then throw an excpetion
+ throw new MalformedURLException("No protocol found for part source in " + uri);
+ }
+
+ // get the request parameter name: the bit after ://
+ String location = uri.substring(position + 2);
+
+ // get the cocoon request from the object model.
+ Request request = ObjectModelHelper.getRequest(objectModel);
+
+ // try and cast the request object to a Part
+ Object obj = request.get(location);
+ if (obj instanceof Part)
+ {
+ part = (Part) obj;
+ }
+ else
+ {
+ throw new SourceException("Request object " + location + " is not an uploaded Part");
+ }
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getInputStream()
+ */
+ public InputStream getInputStream() throws IOException, SourceNotFoundException
+ {
+ try
+ {
+ return part.getInputStream();
+ }
+ catch (Exception ex)
+ {
+ throw new SourceNotFoundException("The part source can not be found.");
+ }
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getMimeType()
+ */
+ public String getMimeType()
+ {
+ return part.getMimeType();
+ }
+
+ /**
+ * @return true if the resource exists.
+ */
+ public boolean exists()
+ {
+ return part != null;
+ }
+
+ /*
+ * @see org.apache.excalibur.source.Source#getURI()
+ */
+ public String getURI()
+ {
+ return uri;
+ }
+
+ /*
+ * @see org.apache.excalibur.source.Source#getScheme()
+ */
+ public String getScheme()
+ {
+ return this.protocol;
+ }
+
+ /*
+ * Not used, Parts are not cacheable.
+ */
+ public SourceValidity getValidity()
+ {
+ // not sure what happens here.
+ return null;
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#refresh()
+ */
+ public void refresh()
+ {
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getContentLength()
+ */
+ public long getContentLength()
+ {
+ return part.getSize();
+ }
+
+ /**
+ * @see org.apache.excalibur.source.Source#getLastModified()
+ */
+ public long getLastModified()
+ {
+ return 0;
+ }
+
+ public Part getPart() {
+ return this.part;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,68 @@
+/*
+ * 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.components.source.impl;
+
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceFactory;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+/**
+ * A factory for {@link org.apache.cocoon.servlet.multipart.Part} based sources (see {@link PartSource}).
+ *
+ * @author <a href="mailto:paul.crabtree@dna.co.uk">Paul Crabtree</a>
+ * @version $Id: PartSourceFactory.java 293303 2005-10-03 11:03:25Z sylvain $
+ */
+public class PartSourceFactory implements SourceFactory, Contextualizable, ThreadSafe
+{
+ Context context;
+
+ /*
+ * Returns a new {@link PartSource} based on the uri.
+ *
+ * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
+ */
+ public Source getSource(String uri, Map parameters) throws IOException, MalformedURLException
+ {
+ Map objectModel = ContextHelper.getObjectModel(context);
+ return new PartSource(uri, objectModel);
+ }
+
+ /**
+ * Do nothing, {@link PartSource}s don't need to be released.
+ *
+ * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
+ */
+ public void release(Source source)
+ {
+ // Nothing to do here
+ }
+
+ /**
+ * Get the objectModel from the Context
+ */
+ public void contextualize(org.apache.avalon.framework.context.Context context)
+ throws ContextException {
+ this.context = context;
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/PartSourceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,462 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.cocoon.Processor;
+import org.apache.cocoon.ResourceNotFoundException;
+import org.apache.cocoon.components.source.SourceUtil;
+import org.apache.cocoon.environment.Environment;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.internal.EnvironmentHelper;
+import org.apache.cocoon.environment.wrapper.EnvironmentWrapper;
+import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
+import org.apache.cocoon.xml.ContentHandlerWrapper;
+import org.apache.cocoon.xml.XMLConsumer;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceException;
+import org.apache.excalibur.source.SourceNotFoundException;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.excalibur.source.SourceValidity;
+import org.apache.excalibur.xml.sax.XMLizable;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * Implementation of a {@link Source} that gets its content
+ * by invoking a pipeline.
+ *
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version $Id: SitemapSource.java 165284 2005-04-29 09:24:28Z cziegeler $
+ */
+public final class SitemapSource
+ extends AbstractLogEnabled
+ implements Source, XMLizable {
+
+ /** The internal event pipeline validities */
+ private SitemapSourceValidity validity;
+
+ /** The system id */
+ private final String systemId;
+
+ /** The system id used for caching */
+ private String systemIdForCaching;
+
+ /** The current ServiceManager */
+ private final ServiceManager manager;
+
+ /** The processor */
+ private final Processor processor;
+
+ /** The pipeline description */
+ private Processor.InternalPipelineDescription pipelineDescription;
+
+ /** The environment */
+ private final MutableEnvironmentFacade environment;
+
+ /** The redirect <code>Source</code> */
+ private Source redirectSource;
+
+ /** The <code>SAXException</code> if unable to get resource */
+ private SAXException exception;
+
+ /** Do I need a refresh ? */
+ private boolean needsRefresh;
+
+ /** Is start processing on the environment called? */
+ private boolean processed;
+
+ /** The used protocol */
+ private final String protocol;
+
+ /** SourceResolver (for the redirect source) */
+ private SourceResolver sourceResolver;
+
+ private String mimeType;
+
+ /**
+ * Construct a new object
+ */
+ public SitemapSource(ServiceManager manager,
+ String uri,
+ Map parameters,
+ Logger logger)
+ throws MalformedURLException {
+
+ Environment env = EnvironmentHelper.getCurrentEnvironment();
+ if ( env == null ) {
+ throw new MalformedURLException("The cocoon protocol can not be used outside an environment.");
+ }
+ this.manager = manager;
+ this.enableLogging(logger);
+
+ SitemapSourceInfo info = SitemapSourceInfo.parseURI(env, uri);
+ this.protocol = info.protocol;
+
+ // does the uri point to this sitemap or to the root sitemap?
+ if (info.processFromRoot) {
+ this.processor = EnvironmentHelper.getCurrentProcessor().getRootProcessor();
+ } else {
+ this.processor = EnvironmentHelper.getCurrentProcessor();
+ }
+
+ // create environment...
+ final EnvironmentWrapper wrapper = new EnvironmentWrapper(env, info, logger);
+
+ // The environment is a facade whose delegate can be changed in case of internal redirects
+ this.environment = new MutableEnvironmentFacade(wrapper);
+
+ // ...and put information passed from the parent request to the internal request
+ if ( null != parameters ) {
+ this.environment.getObjectModel().put(ObjectModelHelper.PARENT_CONTEXT, parameters);
+ } else {
+ this.environment.getObjectModel().remove(ObjectModelHelper.PARENT_CONTEXT);
+ }
+
+ this.systemId = info.systemId;
+
+ // create a new validity holder
+ this.validity = new SitemapSourceValidity();
+
+ // initialize
+ this.init();
+ }
+
+ /**
+ * Return the protocol identifier.
+ */
+ public String getScheme() {
+ return this.protocol;
+ }
+
+ /**
+ * Get the content length of the source or -1 if it
+ * is not possible to determine the length.
+ */
+ public long getContentLength() {
+ return -1;
+ }
+
+ /**
+ * Get the last modification date.
+ * @return The last modification in milliseconds since January 1, 1970 GMT
+ * or 0 if it is unknown
+ */
+ public long getLastModified() {
+ return 0;
+ }
+
+ /**
+ * Return an <code>InputStream</code> object to read from the source.
+ */
+ public InputStream getInputStream()
+ throws IOException, SourceException {
+
+ if (this.needsRefresh) {
+ this.refresh();
+ }
+ // VG: Why exception is not thrown in constructor?
+ if (this.exception != null) {
+ throw new SourceException("Cannot get input stream for " + getURI(), this.exception);
+ }
+
+ if (this.redirectSource != null) {
+ return this.redirectSource.getInputStream();
+ }
+
+ try {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ this.environment.setOutputStream(os);
+ EnvironmentHelper.enterProcessor(this.pipelineDescription.lastProcessor,
+ this.manager,
+ this.environment);
+ try {
+
+ this.pipelineDescription.processingPipeline.process(this.environment);
+ } finally {
+ EnvironmentHelper.leaveProcessor();
+ }
+
+ return new ByteArrayInputStream(os.toByteArray());
+
+ } catch (ResourceNotFoundException e) {
+ throw new SourceNotFoundException("Exception during processing of " + this.systemId, e);
+ } catch (Exception e) {
+ throw new SourceException("Exception during processing of " + this.systemId, e);
+ } finally {
+ // Unhide wrapped environment output stream
+ this.environment.setOutputStream(null);
+ this.needsRefresh = true;
+ }
+ }
+
+ /**
+ * Returns the unique identifer for this source
+ */
+ public String getURI() {
+ return this.systemIdForCaching;
+ }
+
+ /**
+ * Returns true always.
+ * @see org.apache.excalibur.source.Source#exists()
+ */
+ public boolean exists() {
+ return true;
+ }
+
+ /**
+ * Get the validity object. This wraps validity of the enclosed event
+ * pipeline. If pipeline is not cacheable, <code>null</code> is returned.
+ */
+ public SourceValidity getValidity() {
+ return this.validity.getNestedValidity() == null? null: this.validity;
+ }
+
+ /**
+ * The mime-type of the content described by this object.
+ * If the source is not able to determine the mime-type by itself
+ * this can be null.
+ */
+ public String getMimeType() {
+ return this.mimeType;
+ }
+
+ /**
+ * Refresh this object and update the last modified date
+ * and content length.
+ */
+ public void refresh() {
+ this.reset();
+ this.init();
+ }
+
+ /**
+ * Initialize
+ */
+ protected void init() {
+ this.systemIdForCaching = this.systemId;
+ try {
+ this.environment.startingProcessing();
+ this.processed = true;
+ this.pipelineDescription = this.processor.buildPipeline(this.environment);
+ this.environment.setURI(this.pipelineDescription.prefix, this.pipelineDescription.uri);
+
+ String redirectURL = this.environment.getRedirectURL();
+ if (redirectURL == null) {
+
+ EnvironmentHelper.enterProcessor(this.pipelineDescription.lastProcessor,
+ this.manager,
+ this.environment);
+ try {
+ this.pipelineDescription.processingPipeline.prepareInternal(this.environment);
+ this.validity.set(this.pipelineDescription.processingPipeline.getValidityForEventPipeline());
+ final String eventPipelineKey = this.pipelineDescription.processingPipeline.getKeyForEventPipeline();
+ this.mimeType = this.environment.getContentType();
+
+ if (eventPipelineKey != null) {
+ StringBuffer buffer = new StringBuffer(this.systemId);
+ if (this.systemId.indexOf('?') == -1) {
+ buffer.append('?');
+ } else {
+ buffer.append('&');
+ }
+ buffer.append("pipelinehash=");
+ buffer.append(eventPipelineKey);
+ this.systemIdForCaching = buffer.toString();
+ } else {
+ this.systemIdForCaching = this.systemId;
+ }
+ } finally {
+ EnvironmentHelper.leaveProcessor();
+ }
+ } else {
+ if (redirectURL.indexOf(":") == -1) {
+ redirectURL = this.protocol + ":/" + redirectURL;
+ }
+ if (this.sourceResolver == null) {
+ this.sourceResolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
+ }
+ this.redirectSource = this.sourceResolver.resolveURI(redirectURL);
+ this.validity.set(this.redirectSource.getValidity());
+ this.mimeType = this.redirectSource.getMimeType();
+ }
+ } catch (SAXException e) {
+ reset();
+ this.exception = e;
+ } catch (Exception e) {
+ reset();
+ this.exception = new SAXException("Could not get sitemap source " + this.systemId, e);
+ }
+ this.needsRefresh = false;
+ }
+
+ /**
+ * Stream content to the content handler
+ */
+ public void toSAX(ContentHandler contentHandler)
+ throws SAXException {
+ if (this.needsRefresh) {
+ this.refresh();
+ }
+ if (this.exception != null) {
+ throw this.exception;
+ }
+ try {
+ if (this.redirectSource != null) {
+ SourceUtil.parse(this.manager, this.redirectSource, contentHandler);
+ } else {
+ XMLConsumer consumer;
+ if (contentHandler instanceof XMLConsumer) {
+ consumer = (XMLConsumer)contentHandler;
+ } else if (contentHandler instanceof LexicalHandler) {
+ consumer = new ContentHandlerWrapper(contentHandler, (LexicalHandler)contentHandler);
+ } else {
+ consumer = new ContentHandlerWrapper(contentHandler);
+ }
+ // We have to add an environment changer
+ // for clean environment stack handling.
+ EnvironmentHelper.enterProcessor(this.pipelineDescription.lastProcessor,
+ this.manager,
+ this.environment);
+ try {
+ this.pipelineDescription.processingPipeline.process(this.environment,
+ EnvironmentHelper.createEnvironmentAwareConsumer(consumer));
+ } finally {
+ EnvironmentHelper.leaveProcessor();
+ }
+ }
+ } catch (SAXException e) {
+ // Preserve original exception
+ throw e;
+ } catch (Exception e) {
+ throw new SAXException("Exception during processing of " + this.systemId, e);
+ } finally {
+ this.needsRefresh = true;
+ }
+ }
+
+ /**
+ * Reset everything
+ */
+ private void reset() {
+ if (this.pipelineDescription != null) {
+ this.pipelineDescription.release();
+ this.pipelineDescription = null;
+ }
+
+ if (this.processed) {
+ this.processed = false;
+ this.environment.finishingProcessing();
+ }
+
+ if (this.redirectSource != null) {
+ this.sourceResolver.release(this.redirectSource);
+ this.redirectSource = null;
+ }
+
+ this.validity.set(null);
+
+ this.environment.reset();
+ this.exception = null;
+ this.needsRefresh = true;
+ }
+
+ /**
+ * Recyclable
+ */
+ public void recycle() {
+ this.validity = new SitemapSourceValidity();
+ this.reset();
+ if ( this.sourceResolver != null ) {
+ this.manager.release( this.sourceResolver );
+ this.sourceResolver = null;
+ }
+ }
+
+ /**
+ * Get the value of a parameter.
+ * Using this it is possible to get custom information provided by the
+ * source implementation, like an expires date, HTTP headers etc.
+ */
+ public String getParameter(String name) {
+ return null;
+ }
+
+ /**
+ * Get the value of a parameter.
+ * Using this it is possible to get custom information provided by the
+ * source implementation, like an expires date, HTTP headers etc.
+ */
+ public long getParameterAsLong(String name) {
+ return 0;
+ }
+
+ /**
+ * Get parameter names
+ * Using this it is possible to get custom information provided by the
+ * source implementation, like an expires date, HTTP headers etc.
+ */
+ public Iterator getParameterNames() {
+ return java.util.Collections.EMPTY_LIST.iterator();
+ }
+
+ /**
+ * A simple SourceValidity protecting callers from resets.
+ */
+ public static final class SitemapSourceValidity implements SourceValidity {
+
+ private SourceValidity validity;
+
+ protected SitemapSourceValidity() {
+ super();
+ }
+
+ protected void set(SourceValidity validity) {
+ this.validity = validity;
+ }
+
+ public int isValid() {
+ return (this.validity != null ?
+ this.validity.isValid() :
+ SourceValidity.INVALID);
+ }
+
+ public int isValid(SourceValidity validity) {
+ if (validity instanceof SitemapSourceValidity) {
+ return (this.validity != null ?
+ this.validity.isValid(((SitemapSourceValidity) validity).getNestedValidity()) :
+ SourceValidity.INVALID);
+ }
+ return SourceValidity.INVALID;
+ }
+
+ public SourceValidity getNestedValidity() {
+ return this.validity;
+ }
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceFactory.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceFactory.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceFactory.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,90 @@
+/*
+ * 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.components.source.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceFactory;
+import org.apache.excalibur.source.URIAbsolutizer;
+import org.apache.excalibur.source.SourceUtil;
+
+/**
+ * This class implements the cocoon: protocol.
+ * It cannot be used like other source factories
+ * as it needs the current <code>Sitemap</code> as input.
+ *
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version CVS $Id: SitemapSourceFactory.java 30941 2004-07-29 19:56:58Z vgritsenko $
+ */
+public final class SitemapSourceFactory
+ extends AbstractLogEnabled
+ implements SourceFactory, ThreadSafe, Serviceable, URIAbsolutizer
+{
+
+ /** The <code>ServiceManager</code> */
+ private ServiceManager manager;
+
+ /* (non-Javadoc)
+ * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+ */
+ public void service(ServiceManager manager) throws ServiceException {
+ this.manager = manager;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.SourceFactory#getSource(java.lang.String, java.util.Map)
+ */
+ public Source getSource( String location, Map parameters )
+ throws MalformedURLException, IOException {
+ if( getLogger().isDebugEnabled() ) {
+ getLogger().debug( "Creating source object for " + location );
+ }
+
+ return new SitemapSource( this.manager,
+ location,
+ parameters,
+ getLogger());
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.SourceFactory#release(org.apache.excalibur.source.Source)
+ */
+ public void release( Source source ) {
+ if ( null != source ) {
+ if ( this.getLogger().isDebugEnabled() ) {
+ this.getLogger().debug("Releasing source " + source.getURI());
+ }
+ ((SitemapSource)source).recycle();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.excalibur.source.URIAbsolutizer#absolutize(java.lang.String, java.lang.String)
+ */
+ public String absolutize(String baseURI, String location) {
+ return SourceUtil.absolutize(baseURI, location, true);
+ }
+
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceInfo.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceInfo.java?rev=330548&view=auto
==============================================================================
--- cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceInfo.java (added)
+++ cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceInfo.java Thu Nov 3 05:41:06 2005
@@ -0,0 +1,153 @@
+/*
+ * 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.components.source.impl;
+
+import java.net.MalformedURLException;
+
+import org.apache.cocoon.Constants;
+import org.apache.cocoon.environment.Environment;
+
+/**
+ * This is a helper class for the cocoon protocol.
+ *
+ * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
+ * @version CVS $Id: SitemapSourceInfo.java 178038 2005-05-23 21:32:04Z danielf $
+ */
+public final class SitemapSourceInfo {
+
+ /**
+ * <ul>
+ * <li><code>true</code> if the sitemap URI uses the <code>raw:</code> subprotocol,
+ * which means that request parameters of the original request are not forwarded,</li>
+ * <li><code>false</code> otherwise.
+ * </ul>
+ */
+ public boolean rawMode;
+
+ /** The protocol used in the sitemap URI, up to and excluding the colon. */
+ public String protocol;
+
+ /** The request URI, relative to the context. */
+ public String requestURI;
+
+ /** The system ID: <protocol><request-uri>[?<query-string>]. */
+ public String systemId;
+
+ /** The Cocoon view used in the sitemap URI or <code>null</code> if no view is used. */
+ public String view;
+
+ /**
+ * The prefix of the URI in progress for <code>cocoon:/</code> requests,
+ * or an empty string for <code>cocoon://</code> requests.
+ */
+ public String prefix;
+
+ /** The query string of the sitemap URI. */
+ public String queryString;
+
+ /** The sitemap URI without protocol identifier and query string. */
+ public String uri;
+
+ /**
+ * Determine the initial processor for the cocoon protocol request.
+ * <ul>
+ * <li><code>true</code> - start in the root sitemap (<code>cocoon://</code>)</li>
+ * <li><code>false</code> - start in the current sitemap (<code>cocoon:/</code>)</li>
+ * </ul>
+ */
+ public boolean processFromRoot;
+
+ public static SitemapSourceInfo parseURI(Environment env, String sitemapURI)
+ throws MalformedURLException {
+ SitemapSourceInfo info = new SitemapSourceInfo();
+ info.rawMode = false;
+
+ // remove the protocol
+ int position = sitemapURI.indexOf(':') + 1;
+ if (position != 0) {
+ info.protocol = sitemapURI.substring(0, position-1);
+ // check for subprotocol
+ if (sitemapURI.startsWith("raw:", position)) {
+ position += 4;
+ info.rawMode = true;
+ }
+ } else {
+ throw new MalformedURLException("No protocol found for sitemap source in " + sitemapURI);
+ }
+
+ // does the uri point to this sitemap or to the root sitemap?
+ if (sitemapURI.startsWith("//", position)) {
+ position += 2;
+ info.prefix = "";
+ info.processFromRoot = true;
+ } else if (sitemapURI.startsWith("/", position)) {
+ position ++;
+ info.prefix = env.getURIPrefix();
+ info.processFromRoot = false;
+ } else {
+ throw new MalformedURLException("Malformed cocoon URI: " + sitemapURI);
+ }
+
+ // create the queryString (if available)
+ int queryStringPos = sitemapURI.indexOf('?', position);
+ if (queryStringPos != -1) {
+ info.queryString = sitemapURI.substring(queryStringPos + 1);
+ info.uri = sitemapURI.substring(position, queryStringPos);
+ } else if (position > 0) {
+ info.uri = sitemapURI.substring(position);
+ }
+
+
+ // determine if the queryString specifies a cocoon-view
+ info.view = getView(info.queryString, env);
+
+ // build the request uri which is relative to the context
+ info.requestURI = info.prefix + info.uri;
+
+ // create system ID
+ final StringBuffer buffer = new StringBuffer(info.protocol);
+ buffer.append("://").append(info.requestURI);
+ if (info.queryString != null ) {
+ buffer.append('?').append(info.queryString);
+ }
+ info.systemId = buffer.toString();
+
+ return info;
+ }
+
+ public static String getView(String query, Environment env) {
+ if (query != null) {
+ int index = query.indexOf(Constants.VIEW_PARAM);
+ if (index != -1
+ && (index == 0 || query.charAt(index-1) == '&')
+ && query.length() > index + Constants.VIEW_PARAM.length()
+ && query.charAt(index+Constants.VIEW_PARAM.length()) == '=') {
+
+ String tmp = query.substring(index+Constants.VIEW_PARAM.length()+1);
+ index = tmp.indexOf('&');
+ if (index != -1) {
+ return tmp.substring(0,index);
+ } else {
+ return tmp;
+ }
+ } else {
+ return env.getView();
+ }
+ } else {
+ return env.getView();
+ }
+ }
+}
Propchange: cocoon/whiteboard/maven2/cocoon-flat-layout/cocoon-core/src/main/java/org/apache/cocoon/components/source/impl/SitemapSourceInfo.java
------------------------------------------------------------------------------
svn:eol-style = native