You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@excalibur.apache.org by cz...@apache.org on 2007/03/22 13:53:02 UTC
svn commit: r521242 - in /excalibur/trunk/components/sourceresolve: ./
src/java/org/apache/excalibur/source/
src/java/org/apache/excalibur/source/impl/
Author: cziegeler
Date: Thu Mar 22 05:53:01 2007
New Revision: 521242
URL: http://svn.apache.org/viewvc?view=rev&rev=521242
Log:
Only use released dependencies
Use latest commons-httpclient and commons-vfs
Add new abstract class for implementing own source resolvers and add bean implementation
Added:
excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/AbstractSourceResolver.java (with props)
excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/DefaultSourceResolver.java (with props)
Modified:
excalibur/trunk/components/sourceresolve/pom.xml
excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/ModifiableTraversableSource.java
excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java
Modified: excalibur/trunk/components/sourceresolve/pom.xml
URL: http://svn.apache.org/viewvc/excalibur/trunk/components/sourceresolve/pom.xml?view=diff&rev=521242&r1=521241&r2=521242
==============================================================================
--- excalibur/trunk/components/sourceresolve/pom.xml (original)
+++ excalibur/trunk/components/sourceresolve/pom.xml Thu Mar 22 05:53:01 2007
@@ -38,19 +38,19 @@
<dependency>
<groupId>org.apache.avalon.framework</groupId>
<artifactId>avalon-framework-impl</artifactId>
- <version>4.3.2-SNAPSHOT</version>
+ <version>4.3.1</version>
</dependency>
<dependency>
<groupId>commons-vfs</groupId>
<artifactId>commons-vfs</artifactId>
<scope>provided</scope>
- <version>20050307052300</version>
+ <version>1.0</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<scope>provided</scope>
- <version>2.0.2</version>
+ <version>3.0.1</version>
</dependency>
<!-- Needed only if using pre-1.4 JDK
<dependency>
@@ -67,7 +67,7 @@
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
- <scope>test</scope>
+ <scope>provided</scope>
<version>1.0.4</version>
</dependency>
</dependencies>
@@ -78,7 +78,7 @@
<plugin>
<groupId>org.apache.excalibur.fortress.meta</groupId>
<artifactId>maven-fortress-plugin</artifactId>
- <version>1.3.2-SNAPSHOT</version>
+ <version>1.3.1</version>
<executions>
<execution>
<phase>compile</phase>
Modified: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/ModifiableTraversableSource.java
URL: http://svn.apache.org/viewvc/excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/ModifiableTraversableSource.java?view=diff&rev=521242&r1=521241&r2=521242
==============================================================================
--- excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/ModifiableTraversableSource.java (original)
+++ excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/ModifiableTraversableSource.java Thu Mar 22 05:53:01 2007
@@ -19,7 +19,7 @@
/**
* A modifiable traversable source. This adds to {@link ModifiableSource} the
* ability to create a directory.
- *
+ *
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:26 $
*/
@@ -32,7 +32,7 @@
* If the source already exists, this method does nothing if it's already
* traversable, and fails otherwise.
*/
- public void makeCollection() throws SourceException;
+ void makeCollection() throws SourceException;
}
Added: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/AbstractSourceResolver.java
URL: http://svn.apache.org/viewvc/excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/AbstractSourceResolver.java?view=auto&rev=521242
==============================================================================
--- excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/AbstractSourceResolver.java (added)
+++ excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/AbstractSourceResolver.java Thu Mar 22 05:53:01 2007
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.excalibur.source.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Map;
+
+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.URIAbsolutizer;
+
+/**
+ * This is an abstract implementation of a {@link SourceResolver}.
+ *
+ * The source resolving is done relative to a base directory/URI (if
+ * the given location is relative). The base directory/URI has to be set
+ * using {@link #setBaseURL(URL)}.
+ *
+ * A subclass should implement {@link #getSourceFactory(String)} and
+ * {@link #releaseSourceFactory(SourceFactory)} if required.
+ *
+ * To support various logging frameworks, the subclass should implement the
+ * {@link #isDebugEnabled()} and the {@link #debug(String)} method.
+ *
+ * @see org.apache.excalibur.source.SourceResolver
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Id$
+ */
+public abstract class AbstractSourceResolver
+{
+
+ /**
+ * The base URL
+ */
+ protected URL m_baseURL;
+
+ /** Set the base url. */
+ public void setBaseURL(URL baseurl)
+ {
+ m_baseURL = baseurl;
+ }
+
+ protected boolean isDebugEnabled()
+ {
+ return false;
+ }
+
+ protected void debug(String text)
+ {
+ // we do not log
+ }
+
+ protected abstract SourceFactory getSourceFactory(String protocol);
+
+ protected void releaseSourceFactory(SourceFactory factory)
+ {
+ // nothing to do by default
+ }
+
+ /**
+ * Get a <code>Source</code> object.
+ * @throws org.apache.excalibur.source.SourceNotFoundException if the source cannot be found
+ */
+ public Source resolveURI( String location )
+ throws MalformedURLException, IOException, SourceException
+ {
+ return this.resolveURI( location, null, null );
+ }
+
+ /**
+ * Get a <code>Source</code> object.
+ * @throws org.apache.excalibur.source.SourceNotFoundException if the source cannot be found
+ */
+ public Source resolveURI( String location,
+ String baseURI,
+ Map parameters )
+ throws MalformedURLException, IOException, SourceException
+ {
+ if( this.isDebugEnabled() )
+ {
+ this.debug( "Resolving '" + location + "' with base '" + baseURI + "' in context '" + m_baseURL + "'" );
+ }
+ if( location == null ) throw new MalformedURLException( "Invalid System ID" );
+ if( null != baseURI && SourceUtil.indexOfSchemeColon(baseURI) == -1 )
+ {
+ throw new MalformedURLException( "BaseURI is not valid, it must contain a protocol: " + baseURI );
+ }
+
+ if( baseURI == null ) baseURI = m_baseURL.toExternalForm();
+
+ String systemID = location;
+ // special handling for windows file paths
+ if( location.length() > 1 && location.charAt( 1 ) == ':' )
+ systemID = "file:/" + location;
+ else if( location.length() > 2 && location.charAt(0) == '/' && location.charAt(2) == ':' )
+ systemID = "file:" + location;
+
+ // determine protocol (scheme): first try to get the one of the systemID, if that fails, take the one of the baseURI
+ String protocol;
+ int protocolPos = SourceUtil.indexOfSchemeColon(systemID);
+ if( protocolPos != -1 )
+ {
+ protocol = systemID.substring( 0, protocolPos );
+ }
+ else
+ {
+ protocolPos = SourceUtil.indexOfSchemeColon(baseURI);
+ if( protocolPos != -1 )
+ protocol = baseURI.substring( 0, protocolPos );
+ else
+ protocol = "*";
+ }
+
+ Source source = null;
+ // search for a SourceFactory implementing the protocol
+ SourceFactory factory = null;
+ try
+ {
+ factory = this.getSourceFactory( protocol );
+ if ( factory != null )
+ {
+ systemID = absolutize( factory, baseURI, systemID );
+ if( this.isDebugEnabled() )
+ this.debug( "Resolved to systemID : " + systemID );
+ source = factory.getSource( systemID, parameters );
+ }
+ }
+ finally
+ {
+ this.releaseSourceFactory( factory );
+ }
+
+ if( null == source )
+ {
+ try
+ {
+ factory = this.getSourceFactory("*");
+ if ( factory == null )
+ {
+ throw new SourceException( "Unable to select source factory for '" + systemID + "'. No default factory found.");
+ }
+ systemID = absolutize( factory, baseURI, systemID );
+ if( this.isDebugEnabled() )
+ this.debug( "Resolved to systemID : " + systemID );
+ source = factory.getSource( systemID, parameters );
+ }
+ finally
+ {
+ this.releaseSourceFactory(factory);
+ }
+ }
+
+ return source;
+ }
+
+ /**
+ * Makes an absolute URI based on a baseURI and a relative URI.
+ */
+ private String absolutize( SourceFactory factory, String baseURI, String systemID )
+ {
+ if( factory instanceof URIAbsolutizer )
+ systemID = ((URIAbsolutizer)factory).absolutize(baseURI, systemID);
+ else
+ systemID = SourceUtil.absolutize(baseURI, systemID);
+ return systemID;
+ }
+
+ /**
+ * Releases a resolved resource
+ * @param source the source to release
+ */
+ public void release( final Source source )
+ {
+ if( source == null ) return;
+
+ // search for a SourceFactory implementing the protocol
+ final String scheme = source.getScheme();
+ SourceFactory factory = null;
+
+ try
+ {
+ factory = this.getSourceFactory(scheme);
+ if ( factory == null )
+ {
+ factory = this.getSourceFactory("*");
+ if ( factory == null )
+ {
+ throw new RuntimeException( "Unable to select source factory for '" + source.getURI() + "'.");
+ }
+ }
+ factory.release(source);
+ }
+ finally
+ {
+ this.releaseSourceFactory( factory );
+ }
+ }
+}
Propchange: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/AbstractSourceResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/AbstractSourceResolver.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/DefaultSourceResolver.java
URL: http://svn.apache.org/viewvc/excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/DefaultSourceResolver.java?view=auto&rev=521242
==============================================================================
--- excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/DefaultSourceResolver.java (added)
+++ excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/DefaultSourceResolver.java Thu Mar 22 05:53:01 2007
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.excalibur.source.impl;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.excalibur.source.SourceFactory;
+import org.apache.excalibur.source.SourceResolver;
+
+/**
+ * This is the default implemenation of a {@link SourceResolver}.
+ *
+ * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
+ * @version $Id$
+ */
+public class DefaultSourceResolver
+ extends AbstractSourceResolver
+{
+
+ /** Logger */
+ protected final Log m_logger = LogFactory.getLog(getClass());
+
+ /** The list of source factories. */
+ protected Map m_sourceFactories = Collections.EMPTY_MAP;
+
+ public void setSourceFactories(Map factories)
+ {
+ m_sourceFactories = factories;
+ }
+
+ /**
+ * @see org.apache.excalibur.source.impl.AbstractSourceResolver#getSourceFactory(java.lang.String)
+ */
+ protected SourceFactory getSourceFactory(String protocol)
+ {
+ return (SourceFactory)m_sourceFactories.get(protocol);
+ }
+
+ /**
+ * @see org.apache.excalibur.source.impl.AbstractSourceResolver#debug(java.lang.String)
+ */
+ protected void debug(String text)
+ {
+ m_logger.debug(text);
+ }
+
+ /**
+ * @see org.apache.excalibur.source.impl.AbstractSourceResolver#isDebugEnabled()
+ */
+ protected boolean isDebugEnabled()
+ {
+ return m_logger.isDebugEnabled();
+ }
+}
Propchange: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/DefaultSourceResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/DefaultSourceResolver.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java
URL: http://svn.apache.org/viewvc/excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java?view=diff&rev=521242&r1=521241&r2=521242
==============================================================================
--- excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java (original)
+++ excalibur/trunk/components/sourceresolve/src/java/org/apache/excalibur/source/impl/SourceResolverImpl.java Thu Mar 22 05:53:01 2007
@@ -17,23 +17,22 @@
package org.apache.excalibur.source.impl;
import java.io.File;
-import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Map;
-import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.avalon.framework.activity.Disposable;
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.logger.LogEnabled;
+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.avalon.framework.service.Serviceable;
import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.excalibur.source.*;
+import org.apache.excalibur.source.SourceFactory;
+import org.apache.excalibur.source.SourceResolver;
/**
* This is the default implemenation of a {@link SourceResolver}.
@@ -57,23 +56,75 @@
* @version $Id: SourceResolverImpl.java,v 1.4 2004/02/28 11:47:24 cziegeler Exp $
*/
public class SourceResolverImpl
- extends AbstractLogEnabled
+ extends AbstractSourceResolver
implements Serviceable,
Contextualizable,
Disposable,
- SourceResolver,
+ LogEnabled,
ThreadSafe
{
+
/** The component m_manager */
protected ServiceManager m_manager;
/** The special Source factories */
protected ServiceSelector m_factorySelector;
+ /** Our logger. */
+ private Logger m_logger;
+
+ /**
+ * @see org.apache.excalibur.source.impl.AbstractSourceResolver#getSourceFactory(java.lang.String)
+ */
+ protected SourceFactory getSourceFactory(String protocol)
+ {
+ try
+ {
+ return (SourceFactory) m_factorySelector.select(protocol);
+ }
+ catch (ServiceException e)
+ {
+ // we go back to the default factory selector
+ return null;
+ }
+ }
+
+ /**
+ * @see org.apache.excalibur.source.impl.AbstractSourceResolver#releaseSourceFactory(org.apache.excalibur.source.SourceFactory)
+ */
+ protected void releaseSourceFactory(SourceFactory factory)
+ {
+ m_factorySelector.release(factory);
+ }
+
/**
- * The base URL
+ * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(org.apache.avalon.framework.logger.Logger)
*/
- protected URL m_baseURL;
+ public void enableLogging(Logger logger)
+ {
+ m_logger = logger;
+ }
+
+ protected final Logger getLogger()
+ {
+ return m_logger;
+ }
+
+ /**
+ * @see org.apache.excalibur.source.impl.AbstractSourceResolver#debug(java.lang.String)
+ */
+ protected final void debug(String text)
+ {
+ m_logger.debug(text);
+ }
+
+ /**
+ * @see org.apache.excalibur.source.impl.AbstractSourceResolver#isDebugEnabled()
+ */
+ protected final boolean isDebugEnabled()
+ {
+ return m_logger.isDebugEnabled();
+ }
/**
* Get the context
@@ -117,8 +168,8 @@
}
/**
- * Set the current <code>ComponentLocator</code> instance used by this
- * <code>Composable</code>.
+ * Set the current <code>ServiceManager</code> instance used by this
+ * <code>Serviceable</code>.
*
* @avalon.dependency type="org.apache.excalibur.source.SourceFactory"
*/
@@ -126,163 +177,18 @@
throws ServiceException
{
m_manager = manager;
-
- if ( m_manager.hasService( SourceFactory.ROLE + "Selector" ) )
- {
- m_factorySelector = (ServiceSelector) m_manager.lookup( SourceFactory.ROLE + "Selector" );
- }
+ m_factorySelector = (ServiceSelector) m_manager.lookup( SourceFactory.ROLE + "Selector" );
}
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
public void dispose()
{
if( null != m_manager )
{
m_manager.release( m_factorySelector );
m_factorySelector = null;
- }
- }
-
- /**
- * Get a <code>Source</code> object.
- * @throws org.apache.excalibur.source.SourceNotFoundException if the source cannot be found
- */
- public Source resolveURI( String location )
- throws MalformedURLException, IOException, SourceException
- {
- return this.resolveURI( location, null, null );
- }
-
- /**
- * Get a <code>Source</code> object.
- * @throws org.apache.excalibur.source.SourceNotFoundException if the source cannot be found
- */
- public Source resolveURI( String location,
- String baseURI,
- Map parameters )
- throws MalformedURLException, IOException, SourceException
- {
- if( getLogger().isDebugEnabled() )
- {
- getLogger().debug( "Resolving '" + location + "' with base '" + baseURI + "' in context '" + m_baseURL + "'" );
- }
- if( location == null ) throw new MalformedURLException( "Invalid System ID" );
- if( null != baseURI && SourceUtil.indexOfSchemeColon(baseURI) == -1 )
- {
- throw new MalformedURLException( "BaseURI is not valid, it must contain a protocol: " + baseURI );
- }
-
- if( baseURI == null ) baseURI = m_baseURL.toExternalForm();
-
- String systemID = location;
- // special handling for windows file paths
- if( location.length() > 1 && location.charAt( 1 ) == ':' )
- systemID = "file:/" + location;
- else if( location.length() > 2 && location.charAt(0) == '/' && location.charAt(2) == ':' )
- systemID = "file:" + location;
-
- // determine protocol (scheme): first try to get the one of the systemID, if that fails, take the one of the baseURI
- String protocol;
- int protocolPos = SourceUtil.indexOfSchemeColon(systemID);
- if( protocolPos != -1 )
- {
- protocol = systemID.substring( 0, protocolPos );
- }
- else
- {
- protocolPos = SourceUtil.indexOfSchemeColon(baseURI);
- if( protocolPos != -1 )
- protocol = baseURI.substring( 0, protocolPos );
- else
- protocol = "*";
- }
-
- Source source = null;
- // search for a SourceFactory implementing the protocol
- SourceFactory factory = null;
- try
- {
- factory = (SourceFactory)m_factorySelector.select( protocol );
- systemID = absolutize( factory, baseURI, systemID );
- if( getLogger().isDebugEnabled() )
- getLogger().debug( "Resolved to systemID : " + systemID );
- source = factory.getSource( systemID, parameters );
- }
- catch( final ServiceException ce )
- {
- // no selector available, use fallback
- }
- finally
- {
- m_factorySelector.release( factory );
- }
-
- if( null == source )
- {
- try
- {
- factory = (SourceFactory) m_factorySelector.select("*");
- systemID = absolutize( factory, baseURI, systemID );
- if( getLogger().isDebugEnabled() )
- getLogger().debug( "Resolved to systemID : " + systemID );
- source = factory.getSource( systemID, parameters );
- }
- catch (ServiceException se )
- {
- throw new SourceException( "Unable to select source factory for " + systemID, se );
- }
- finally
- {
- m_factorySelector.release(factory);
- }
- }
-
- return source;
- }
-
- /**
- * Makes an absolute URI based on a baseURI and a relative URI.
- */
- private String absolutize( SourceFactory factory, String baseURI, String systemID )
- {
- if( factory instanceof URIAbsolutizer )
- systemID = ((URIAbsolutizer)factory).absolutize(baseURI, systemID);
- else
- systemID = SourceUtil.absolutize(baseURI, systemID);
- return systemID;
- }
-
- /**
- * Releases a resolved resource
- * @param source the source to release
- */
- public void release( final Source source )
- {
- if( source == null ) return;
-
- // search for a SourceFactory implementing the protocol
- final String scheme = source.getScheme();
- SourceFactory factory = null;
-
- try
- {
- factory = (SourceFactory) m_factorySelector.select(scheme);
- factory.release(source);
- }
- catch (ServiceException se )
- {
- try
- {
- factory = (SourceFactory) m_factorySelector.select("*");
- factory.release(source);
- }
- catch (ServiceException sse )
- {
- throw new CascadingRuntimeException( "Unable to select source factory for " + source.getURI(), se );
- }
- }
- finally
- {
- m_factorySelector.release( factory );
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: scm-unsubscribe@excalibur.apache.org
For additional commands, e-mail: scm-help@excalibur.apache.org