imario 2004/05/20 11:47:30
Modified: vfs/src/java/org/apache/commons/vfs Capability.java
vfs/src/java/org/apache/commons/vfs/impl providers.xml
vfs/src/test/org/apache/commons/vfs/provider/res/test
ResourceProviderTestCase.java
vfs/src/java/org/apache/commons/vfs/provider/url
UrlFileProvider.java
Added: vfs/src/java/org/apache/commons/vfs/provider/res
ResourceFileProvider.java
ResourcelFileSystemConfigBuilder.java
Removed: vfs/src/java/org/apache/commons/vfs/provider/url
UrlFileSystemConfigBuilder.java
Log:
Now found the ultimative solution.
Introduce ResourceFileProvider.
This provider do not have its own filesystem implemention.
It simply resolve a full filename using the current or passed classloader and using
the filesystemmanager to finally resolv the file.
In the case of a resource within an jar this will result in passing back a vfs
jar-fileobject with all its goodies missing in an simple url connection.
The capability of such a provider is "Dispatcher" as it cant know much about the
filesystem finally used to handle the resource.
Revision Changes Path
1.10 +9 -1
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Capability.java
Index: Capability.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Capability.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Capability.java 10 May 2004 20:09:45 -0000 1.9
+++ Capability.java 20 May 2004 18:47:30 -0000 1.10
@@ -110,6 +110,14 @@
*/
public static final Capability MANIFEST_ATTRIBUTES = new
Capability("MANIFEST_ATTRIBUTES");
+ /**
+ * The provider itself do not provide a filesystem. It simply resolves a full
name
+ * and dispatches the request back to the filesystemmanager.<br>
+ * A provider with this capability cant tell much about the capabilities about
the
+ * finally used filesystem in advance.
+ */
+ public static final Capability DISPATCHER = new Capability("DISPATCHER");
+
private final String name;
private Capability(final String name)
1.8 +3 -1
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/providers.xml
Index: providers.xml
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/impl/providers.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- providers.xml 20 May 2004 17:40:55 -0000 1.7
+++ providers.xml 20 May 2004 18:47:30 -0000 1.8
@@ -1,6 +1,5 @@
<providers>
<default-provider
class-name="org.apache.commons.vfs.provider.url.UrlFileProvider">
- <scheme name="res"/>
</default-provider>
<provider
class-name="org.apache.commons.vfs.provider.local.DefaultLocalFileProvider">
<scheme name="file"/>
@@ -35,6 +34,9 @@
<scheme name="sftp"/>
<if-available class-name="javax.crypto.Cipher"/>
<if-available class-name="com.jcraft.jsch.JSch"/>
+ </provider>
+ <provider class-name="org.apache.commons.vfs.provider.res.ResourceFileProvider">
+ <scheme name="res"/>
</provider>
<extension-map extension="zip" scheme="zip"/>
<mime-type-map mimetype="application/zip" scheme="zip"/>
1.1
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/res/ResourceFileProvider.java
Index: ResourceFileProvider.java
===================================================================
/*
* Copyright 2002, 2003,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.commons.vfs.provider.res;
import org.apache.commons.vfs.Capability;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemConfigBuilder;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.provider.AbstractFileProvider;
import org.apache.commons.vfs.provider.UriParser;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
/**
* Description
*
* @author <a href="mailto:[EMAIL PROTECTED]">Mario Ivanovits</a>
* @version $Revision: 1.1 $ $Date: 2004/05/20 18:47:30 $
*/
public class ResourceFileProvider extends AbstractFileProvider
{
protected final static Collection capabilities =
Collections.unmodifiableCollection(Arrays.asList(new Capability[]
{
Capability.DISPATCHER
}));
public ResourceFileProvider()
{
super();
}
/**
* Locates a file object, by absolute URI.
*/
public FileObject findFile(final FileObject baseFile,
final String uri,
final FileSystemOptions fileSystemOptions)
throws FileSystemException
{
StringBuffer buf = new StringBuffer(80);
UriParser.extractScheme(uri, buf);
String resourceName = buf.toString();
ClassLoader cl =
ResourcelFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions);
if (cl == null)
{
cl = getClass().getClassLoader();
}
final URL url = cl.getResource(resourceName);
if (url == null)
{
throw new FileSystemException("vfs.provider.url/badly-formed-uri.error",
uri);
}
FileObject fo =
getContext().getFileSystemManager().resolveFile(url.toExternalForm());
return fo;
}
public FileSystemConfigBuilder getConfigBuilder()
{
return
org.apache.commons.vfs.provider.res.ResourcelFileSystemConfigBuilder.getInstance();
}
public Collection getCapabilities()
{
return capabilities;
}
}
1.1
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/res/ResourcelFileSystemConfigBuilder.java
Index: ResourcelFileSystemConfigBuilder.java
===================================================================
/*
* Copyright 2002, 2003,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.commons.vfs.provider.res;
import org.apache.commons.vfs.FileSystemConfigBuilder;
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.provider.url.UrlFileSystem;
/**
* The config builder for various ftp configuration options
*
* @author <a href="mailto:[EMAIL PROTECTED]">Mario Ivankovits</a>
* @version $Revision: 1.1 $ $Date: 2004/05/20 18:47:30 $
*/
public class ResourcelFileSystemConfigBuilder extends FileSystemConfigBuilder
{
private final static ResourcelFileSystemConfigBuilder builder = new
ResourcelFileSystemConfigBuilder();
public static ResourcelFileSystemConfigBuilder getInstance()
{
return builder;
}
private ResourcelFileSystemConfigBuilder()
{
}
public void setClassLoader(FileSystemOptions opts, ClassLoader classLoader)
{
setParam(opts, ClassLoader.class.getName(), classLoader);
}
public ClassLoader getClassLoader(FileSystemOptions opts)
{
return (ClassLoader) getParam(opts, ClassLoader.class.getName());
}
protected Class getConfigClass()
{
return UrlFileSystem.class;
}
}
1.2 +6 -2
jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/res/test/ResourceProviderTestCase.java
Index: ResourceProviderTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/res/test/ResourceProviderTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ResourceProviderTestCase.java 20 May 2004 17:40:55 -0000 1.1
+++ ResourceProviderTestCase.java 20 May 2004 18:47:30 -0000 1.2
@@ -21,6 +21,8 @@
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+import org.apache.commons.vfs.provider.jar.JarFileProvider;
+import org.apache.commons.vfs.provider.res.ResourceFileProvider;
import org.apache.commons.vfs.provider.url.UrlFileProvider;
import org.apache.commons.vfs.test.AbstractProviderTestConfig;
import org.apache.commons.vfs.test.ProviderTestSuite;
@@ -44,7 +46,9 @@
public void prepare(DefaultFileSystemManager manager)
throws Exception
{
- manager.addProvider(new String[]{"res", "file"}, new UrlFileProvider());
+ manager.addProvider("res", new ResourceFileProvider());
+ manager.addProvider("file", new UrlFileProvider());
+ manager.addProvider("jar", new JarFileProvider());
}
/**
1.22 +4 -28
jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java
Index: UrlFileProvider.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- UrlFileProvider.java 20 May 2004 17:40:56 -0000 1.21
+++ UrlFileProvider.java 20 May 2004 18:47:30 -0000 1.22
@@ -24,7 +24,6 @@
import org.apache.commons.vfs.FileSystemOptions;
import org.apache.commons.vfs.provider.AbstractFileProvider;
import org.apache.commons.vfs.provider.BasicFileName;
-import org.apache.commons.vfs.provider.UriParser;
import java.net.MalformedURLException;
import java.net.URL;
@@ -63,37 +62,14 @@
{
try
{
- StringBuffer buf = new StringBuffer(80);
- String scheme = UriParser.extractScheme(uri, buf);
+ final URL url = new URL(uri);
- final URL url;
- if ("res".equals(scheme))
- {
- String resourceName = buf.toString();
-
- ClassLoader cl =
UrlFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions);
- if (cl == null)
- {
- cl = getClass().getClassLoader();
- }
- url = cl.getResource(resourceName);
-
- if (url == null)
- {
- throw new
FileSystemException("vfs.provider.url/badly-formed-uri.error", uri);
- }
- }
- else
- {
- url = new URL(uri);
- }
- final URL rootUrl = new URL(url, "/");
+ URL rootUrl = new URL(url, "/");
final String key = this.getClass().getName() + rootUrl.toString();
FileSystem fs = findFileSystem(key, fileSystemOptions);
if (fs == null)
{
final FileName rootName =
- // new BasicFileName(scheme, rootUrl.toExternalForm(),
FileName.ROOT_PATH);
new BasicFileName(rootUrl, FileName.ROOT_PATH);
fs = new UrlFileSystem(rootName, fileSystemOptions);
addFileSystem(key, fs);
@@ -108,7 +84,7 @@
public FileSystemConfigBuilder getConfigBuilder()
{
- return UrlFileSystemConfigBuilder.getInstance();
+ return
org.apache.commons.vfs.provider.res.ResourcelFileSystemConfigBuilder.getInstance();
}
public Collection getCapabilities()
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]