Author: imario
Date: Wed Jun 29 01:30:32 2005
New Revision: 202335
URL: http://svn.apache.org/viewcvs?rev=202335&view=rev
Log:
PR35520
Reported By: Jacob Kjome <hoju -at- visi.com>
Need special handling of FileNames for URLFileProvider. We need to dispatch the
url to the corresponding FileNameParser to correctly handle urls with host
names (http://) and those withouth (file:/)
Added:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java
(with props)
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileNameParser.java
(with props)
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/url/test/UrlHttpProviderTestCase.java
(with props)
Modified:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/URLFileName.java
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java
Modified:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java?rev=202335&r1=202334&r2=202335&view=diff
==============================================================================
---
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
(original)
+++
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
Wed Jun 29 01:30:32 2005
@@ -592,6 +592,7 @@
}
String scheme = base.getScheme();
+ String fullPath = base.getRootURI() + resolvedPath;
final FileProvider provider = (FileProvider) providers.get(scheme);
if (provider != null)
{
@@ -599,11 +600,19 @@
// only a pathname and take the missing informations from
// the base. Then we can get rid of the string operation.
//// String fullPath = base.getRootURI() +
resolvedPath.substring(1);
- String fullPath = base.getRootURI() + resolvedPath;
return provider.parseUri(base, fullPath);
}
+ if (scheme != null)
+ {
+// An unknown scheme - hand it to the default provider - if possible
+ if (defaultProvider != null)
+ {
+ return defaultProvider.parseUri(base, fullPath);
+ }
+ }
+
// todo: avoid fallback to this point
// this happens if we have a virtual filesystem (no provider for
scheme)
return ((AbstractFileName) base).createName(resolvedPath);
@@ -611,7 +620,7 @@
/**
* resolve the uri to a filename
- *
+ *
* @throws FileSystemException
*/
public FileName resolveURI(String uri) throws FileSystemException
Modified:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/URLFileName.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/URLFileName.java?rev=202335&r1=202334&r2=202335&view=diff
==============================================================================
---
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/URLFileName.java
(original)
+++
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/URLFileName.java
Wed Jun 29 01:30:32 2005
@@ -24,7 +24,7 @@
/**
* get the query string
- * @return
+ * @return the query string part of the filename
*/
public String getQueryString()
{
@@ -33,7 +33,7 @@
/**
* get the path and query string e.g. /path/servlet?param1=true
- * @return
+ * @return the path and its query string
*/
public String getPathQuery()
{
@@ -91,7 +91,7 @@
/**
* append query string to the uri
- * @return
+ * @return the uri
*/
protected String createURI()
{
Added:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java?rev=202335&view=auto
==============================================================================
---
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java
(added)
+++
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java
Wed Jun 29 01:30:32 2005
@@ -0,0 +1,31 @@
+package org.apache.commons.vfs.provider.url;
+
+import org.apache.commons.vfs.provider.URLFileName;
+import org.apache.commons.vfs.provider.UriParser;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: im
+ * Date: 28.06.2005
+ * Time: 16:00:19
+ * To change this template use File | Settings | File Templates.
+ */
+public class UrlFileName extends URLFileName
+{
+ public UrlFileName(final String scheme, final String hostName, final int
port, final int defaultPort, final String userName, final String password,
final String path, final String queryString)
+ {
+ super(scheme, hostName, port, defaultPort, userName, password, path,
queryString);
+ }
+
+ protected void appendRootUri(final StringBuffer buffer)
+ {
+ if (getHostName() != null && !"".equals(getHostName()))
+ {
+ super.appendRootUri(buffer);
+ return;
+ }
+
+ buffer.append(getScheme());
+ buffer.append(":");
+ }
+}
Propchange:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileName.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileNameParser.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileNameParser.java?rev=202335&view=auto
==============================================================================
---
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileNameParser.java
(added)
+++
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileNameParser.java
Wed Jun 29 01:30:32 2005
@@ -0,0 +1,120 @@
+/*
+ * Copyright 2002-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.commons.vfs.provider.url;
+
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.provider.AbstractFileNameParser;
+import org.apache.commons.vfs.provider.URLFileName;
+import org.apache.commons.vfs.provider.UriParser;
+import org.apache.commons.vfs.provider.VfsComponentContext;
+import org.apache.commons.vfs.provider.URLFileNameParser;
+import org.apache.commons.vfs.provider.local.LocalFileNameParser;
+import org.apache.commons.vfs.provider.local.GenericFileNameParser;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * Implementation for any java.net.url based filesystem.<br />
+ * Composite of URLFilenameParser and GenericFilenameParser
+ *
+ * @author [EMAIL PROTECTED]
+ * @version $Revision$ $Date$
+ */
+public class UrlFileNameParser extends AbstractFileNameParser
+{
+ private URLFileNameParser url = new URLFileNameParser(80);
+ private GenericFileNameParser generic = new GenericFileNameParser();
+
+ public UrlFileNameParser()
+ {
+ super();
+ }
+
+ public boolean encodeCharacter(char ch)
+ {
+ return super.encodeCharacter(ch) || ch == '?';
+ }
+
+ public FileName parseUri(final VfsComponentContext context, final FileName
base, final String filename) throws FileSystemException
+ {
+ if (isUrlBased(base, filename))
+ {
+ return url.parseUri(context, base, filename);
+ }
+
+ return generic.parseUri(context, base, filename);
+ }
+
+ /**
+ * Guess is the given filename is a url with host or not. VFS treats such
urls differently.<br />
+ * A filename is url-based if the base is a <code>URLFileName</code> or
there are only 2 slashes
+ * after the scheme.<br/>
+ * e.g: http://host/path, file:/path/to/file, file:///path/to/file
+ *
+ */
+ protected boolean isUrlBased(final FileName base, final String filename)
+ {
+ if (base instanceof URLFileName)
+ {
+ return true;
+ }
+
+ int nuofSlash = countSlashes(filename);
+ return nuofSlash == 2;
+ }
+
+ /**
+ * This method counts the slashes after the scheme.
+ *
+ * @param filename
+ * @return nuof slashes
+ */
+ protected int countSlashes(final String filename)
+ {
+ int state = 0;
+ int nuofSlash = 0;
+ for (int pos = 0; pos<filename.length(); pos++)
+ {
+ char c = filename.charAt(pos);
+ if (state == 0)
+ {
+ if (c >= 'a' && c <= 'z')
+ {
+ continue;
+ }
+ if (c == ':')
+ {
+ state++;
+ continue;
+ }
+ }
+ else if (state == 1)
+ {
+ if (c == '/')
+ {
+ nuofSlash++;
+ }
+ else
+ {
+ return nuofSlash;
+ }
+ }
+ }
+ return nuofSlash;
+ }
+}
Propchange:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileNameParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileNameParser.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileNameParser.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java?rev=202335&r1=202334&r2=202335&view=diff
==============================================================================
---
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java
(original)
+++
jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/url/UrlFileProvider.java
Wed Jun 29 01:30:32 2005
@@ -23,6 +23,7 @@
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.URLFileNameParser;
import java.net.MalformedURLException;
import java.net.URL;
@@ -49,6 +50,7 @@
public UrlFileProvider()
{
super();
+ setFileNameParser(new UrlFileNameParser());
}
/**
@@ -68,8 +70,9 @@
FileSystem fs = findFileSystem(key, fileSystemOptions);
if (fs == null)
{
+ String extForm = rootUrl.toExternalForm();
final FileName rootName =
- getContext().parseURI(rootUrl.getProtocol() + ":" +
FileName.ROOT_PATH);
+ getContext().parseURI(extForm);
// final FileName rootName =
// new BasicFileName(rootUrl, FileName.ROOT_PATH);
fs = new UrlFileSystem(rootName, fileSystemOptions);
Added:
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/url/test/UrlHttpProviderTestCase.java
URL:
http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/url/test/UrlHttpProviderTestCase.java?rev=202335&view=auto
==============================================================================
---
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/url/test/UrlHttpProviderTestCase.java
(added)
+++
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/url/test/UrlHttpProviderTestCase.java
Wed Jun 29 01:30:32 2005
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2002-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.commons.vfs.provider.url.test;
+
+import junit.framework.Test;
+import org.apache.commons.AbstractVfsTestCase;
+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.url.UrlFileProvider;
+import org.apache.commons.vfs.test.AbstractProviderTestConfig;
+import org.apache.commons.vfs.test.ProviderTestSuite;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * Test cases for the generic provider.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Adam Murdoch</a>
+ * @version $Revision$ $Date$
+ */
+public class UrlHttpProviderTestCase
+ extends AbstractProviderTestConfig
+{
+ public static Test suite() throws Exception
+ {
+ return new ProviderTestSuite(new UrlHttpProviderTestCase());
+ }
+
+ /**
+ * Prepares the file system manager. This implementation does nothing.
+ */
+ public void prepare(final DefaultFileSystemManager manager)
+ throws Exception
+ {
+ manager.addProvider("http", new UrlFileProvider());
+ }
+
+ /**
+ * Returns the base folder for tests.
+ */
+ public FileObject getBaseTestFolder(final FileSystemManager manager)
+ throws Exception
+ {
+ final File baseDir = AbstractVfsTestCase.getTestDirectoryFile();
+ final URL url = baseDir.toURL();
+ return manager.resolveFile(url.toExternalForm());
+ }
+}
Propchange:
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/url/test/UrlHttpProviderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/url/test/UrlHttpProviderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/url/test/UrlHttpProviderTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]