Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 73049 invoked from network); 25 Mar 2005 19:12:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Mar 2005 19:12:48 -0000 Received: (qmail 91859 invoked by uid 500); 25 Mar 2005 19:12:37 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 91471 invoked by uid 500); 25 Mar 2005 19:12:35 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 91444 invoked by uid 500); 25 Mar 2005 19:12:35 -0000 Received: (qmail 91434 invoked by uid 99); 25 Mar 2005 19:12:35 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Fri, 25 Mar 2005 11:12:32 -0800 Received: (qmail 72832 invoked by uid 65534); 25 Mar 2005 19:12:31 -0000 Message-ID: <20050325191231.72831.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Fri, 25 Mar 2005 19:12:31 -0000 Subject: svn commit: r159046 [1/2] - in jakarta/commons/sandbox/vfs/trunk: src/java/org/apache/commons/vfs/ src/java/org/apache/commons/vfs/impl/ src/java/org/apache/commons/vfs/provider/ src/java/org/apache/commons/vfs/provider/compressed/ src/java/org/apache/commons/vfs/provider/ftp/ src/java/org/apache/commons/vfs/provider/http/ src/java/org/apache/commons/vfs/provider/jar/ src/java/org/apache/commons/vfs/provider/local/ src/java/org/apache/commons/vfs/provider/sftp/ src/java/org/apache/commons/vfs/provider/smb/ src/java/org/apache/commons/vfs/provider/tar/ src/java/org/apache/commons/vfs/provider/temp/ src/java/org/apache/commons/vfs/provider/url/ src/java/org/apache/commons/vfs/provider/webdav/ src/java/org/apache/commons/vfs/provider/zip/ src/test/org/apache/commons/vfs/provider/smb/test/ src/test/org/apache/commons/vfs/provider/test/ src/test/org/apache/commons/vfs/test/ xdocs/ To: commons-cvs@jakarta.apache.org From: imario@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: imario Date: Fri Mar 25 11:12:17 2005 New Revision: 159046 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D159046 Log: refactored filename parsing tests passed, though manual testing needet Now every FileProvider can handle its own set of reserved characters throug= h the *FileNameParser. This encoding is immediatley reflected in the FileName. Added: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileNameParser.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/FileNameParser.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/LayeredFileNameParser.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/URLFileNameParser.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileNameParser.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/http/HttpFileNameParser.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/sftp/SftpFileNameParser.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/sftp/SftpRandomAccessContent.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/smb/SmbFileNameParser.java (with props) jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/webdav/WebdavFileNameParser.java (with props) Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/FileN= ame.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/FileS= ystemManager.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/Resou= rces.properties jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultFileReplicator.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultFileSystemManager.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultVfsComponentContext.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= VirtualFileSystem.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= providers.xml jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileObject.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileSystem.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractLayeredFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractOriginatingFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/BasicFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/FileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/GenericFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/LayeredFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/UriParser.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/VfsComponentContext.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/compressed/CompressedFileFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileObject.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/http/HttpFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/jar/JarFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/local/DefaultLocalFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/local/GenericFileNameParser.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/local/LocalFile.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/local/LocalFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/local/LocalFileNameParser.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/local/LocalFileSystem.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/sftp/SftpFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/smb/SmbFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/smb/SmbFileObject.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/smb/SmbFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/smb/SmbFileSystem.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/tar/TarFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/tar/TarFileObject.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/tar/TarFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/tar/TarFileSystem.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/temp/TemporaryFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/url/UrlFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/webdav/WebdavFileObject.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/webdav/WebdavFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/zip/ZipFileName.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/zip/ZipFileProvider.java jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/zip/ZipFileSystem.java jakarta/commons/sandbox/vfs/trunk/src/test/org/apache/commons/vfs/provi= der/smb/test/FileNameTestCase.java jakarta/commons/sandbox/vfs/trunk/src/test/org/apache/commons/vfs/provi= der/test/GenericFileNameTestCase.java jakarta/commons/sandbox/vfs/trunk/src/test/org/apache/commons/vfs/test/= AbstractProviderTestCase.java jakarta/commons/sandbox/vfs/trunk/src/test/org/apache/commons/vfs/test/= AbstractTestSuite.java jakarta/commons/sandbox/vfs/trunk/src/test/org/apache/commons/vfs/test/= ContentTests.java jakarta/commons/sandbox/vfs/trunk/src/test/org/apache/commons/vfs/test/= NamingTests.java jakarta/commons/sandbox/vfs/trunk/src/test/org/apache/commons/vfs/test/= ProviderWriteTests.java jakarta/commons/sandbox/vfs/trunk/src/test/org/apache/commons/vfs/test/= UrlTests.java jakarta/commons/sandbox/vfs/trunk/xdocs/filesystems.xml jakarta/commons/sandbox/vfs/trunk/xdocs/index.xml Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /FileName.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/FileName.java?view=3Ddiff&r1=3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/FileN= ame.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/FileN= ame.java Fri Mar 25 11:12:17 2005 @@ -64,6 +64,22 @@ String getPath(); =20 /** + * Returns the absolute path of this file, within its file system. Th= is + * path is normalised, so that . and .. elem= ents + * have been removed. Also, the path only contains / as = its + * separator character. The path always starts with / + *

+ *

The root of a file system has / as its absolute pat= h=2E + *

+ * In contrast to {@link #getPath()} the path is decoded i.e. all %nn = stuff + * replaced by its character. + * + * @return The path. Never returns null. + * @throws FileSystemException if the path is not correctly encoded=20 + */ + String getPathDecoded() throws FileSystemException; + + /** * Returns the extension of this file name. * * @return The extension. Returns an empty string if the name has no @@ -110,7 +126,7 @@ * @return A {@link FileName} object representing the resolved file na= me. * @throws FileSystemException If the name is invalid. */ - FileName resolveName(String name) throws FileSystemException; + // FileName resolveName(String name) throws FileSystemException; =20 /** * Resolves a name, relative to this file name. Refer to {@link NameS= cope} @@ -121,8 +137,8 @@ * @return A {@link FileName} object representing the resolved file na= me. * @throws FileSystemException If the name is invalid. */ - FileName resolveName(String name, NameScope scope) - throws FileSystemException; + // FileName resolveName(String name, NameScope scope) + // throws FileSystemException; =20 /** * Converts a file name to a relative name, relative to this file name. Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /FileSystemManager.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/FileSystemManager.java?view=3Ddiff&r1=3D159045&r2= =3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/FileS= ystemManager.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/FileS= ystemManager.java Fri Mar 25 11:12:17 2005 @@ -126,6 +126,30 @@ throws FileSystemException; =20 /** + * Resolves a name, relative to this file name. Equivalent to calling + * resolveName( path, NameScope.FILE_SYSTEM ). + * + * @param root the base filename + * @param name The name to resolve. + * @return A {@link FileName} object representing the resolved file na= me. + * @throws FileSystemException If the name is invalid. + */ + FileName resolveName(final FileName root, final String name) throws Fi= leSystemException; + + /** + * Resolves a name, relative to the "root" file name. Refer to {@link= NameScope} + * for a description of how names are resolved. + * + * @param root the base filename + * @param name The name to resolve. + * @param scope The {@link NameScope} to use when resolving the name. + * @return A {@link FileName} object representing the resolved file na= me. + * @throws FileSystemException If the name is invalid. + */ + FileName resolveName(final FileName root, String name, NameScope scope) + throws FileSystemException; + + /** * Converts a local file into a {@link FileObject}. * * @param file The file to convert. @@ -226,4 +250,6 @@ * @throws FileSystemException if the given scheme is not konwn */ public FileSystemConfigBuilder getFileSystemConfigBuilder(final String= scheme) throws FileSystemException; + + public FileName resolveURI(String uri) throws FileSystemException; } Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /Resources.properties URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/Resources.properties?view=3Ddiff&r1=3D159045&r2= =3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/Resou= rces.properties (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/Resou= rces.properties Fri Mar 25 11:12:17 2005 @@ -88,6 +88,9 @@ vfs.provider/replicate-file.error=3DCould not replicate "{0}". vfs.provider/resolve-file.error=3DCould not resolve file "{0}". =20 +# AbstractFileProvider +vfs.provider/filename-parser-missing.error=3DNo filename-parser implementa= tion set. + # RandomAccess vfs.provider/random-access-invalid-position.error=3DInvalid position: "{0}" vfs.provider/random-access-open-failed.error=3DCould not access file "{0}"= because it does not exist. Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /impl/DefaultFileReplicator.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/impl/DefaultFileReplicator.java?view=3Ddiff&r1=3D= 159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultFileReplicator.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultFileReplicator.java Fri Mar 25 11:12:17 2005 @@ -25,6 +25,7 @@ import org.apache.commons.vfs.provider.AbstractVfsComponent; import org.apache.commons.vfs.provider.FileReplicator; import org.apache.commons.vfs.provider.TemporaryFileStore; +import org.apache.commons.vfs.provider.UriParser; import org.apache.commons.vfs.util.Messages; =20 import java.io.File; @@ -107,7 +108,7 @@ /** * Allocates a new temporary file. */ - public File allocateFile(final String baseName) + public File allocateFile(final String baseName) throws FileSystemExcep= tion { // Create a unique-ish file name final String basename =3D createFilename(baseName); @@ -138,9 +139,9 @@ /** * create the temporary file */ - protected File createFile(final File parent, final String name) + protected File createFile(final File parent, final String name) throws= FileSystemException { - return new File(parent, name); + return new File(parent, UriParser.decode(name)); } =20 /** Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /impl/DefaultFileSystemManager.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/impl/DefaultFileSystemManager.java?view=3Ddiff&r1= =3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultFileSystemManager.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultFileSystemManager.java Fri Mar 25 11:12:17 2005 @@ -17,6 +17,7 @@ =20 import org.apache.commons.logging.Log; import org.apache.commons.vfs.FileContentInfoFactory; +import org.apache.commons.vfs.FileName; import org.apache.commons.vfs.FileObject; import org.apache.commons.vfs.FileSystem; import org.apache.commons.vfs.FileSystemConfigBuilder; @@ -24,7 +25,9 @@ import org.apache.commons.vfs.FileSystemManager; import org.apache.commons.vfs.FileSystemOptions; import org.apache.commons.vfs.FilesCache; +import org.apache.commons.vfs.NameScope; import org.apache.commons.vfs.cache.SoftRefFilesCache; +import org.apache.commons.vfs.provider.AbstractFileName; import org.apache.commons.vfs.provider.AbstractFileProvider; import org.apache.commons.vfs.provider.DefaultURLStreamHandler; import org.apache.commons.vfs.provider.FileProvider; @@ -489,6 +492,11 @@ public FileObject resolveFile(final FileObject baseFile, final String = uri, final FileSystemOptions fileSystemOptions) throws FileSystemException { + // TODO: use resolveName and use this name to resolve the fileObje= ct + + + UriParser.checkUriEncoding(uri); + if (uri =3D=3D null) { throw new IllegalArgumentException(); @@ -504,19 +512,117 @@ { return provider.findFile(baseFile, uri, fileSystemOptions); } - // Otherwise, assume a local file } =20 +// Handle absolute file names + if (localFileProvider !=3D null + && localFileProvider.isAbsoluteLocalName(uri)) + { + return localFileProvider.findLocalFile(uri); + } + + if (scheme !=3D null) + { +// An unknown scheme - hand it to the default provider + if (defaultProvider =3D=3D null) + { + throw new FileSystemException("vfs.impl/unknown-scheme.err= or", new Object[]{scheme, uri}); + } + return defaultProvider.findFile(baseFile, uri, fileSystemOptio= ns); + } + +// Assume a relative name - use the supplied base file + if (baseFile =3D=3D null) + { + throw new FileSystemException("vfs.impl/find-rel-file.error", = uri); + } + + return baseFile.resolveFile(uri); + } + + /** + * Resolves a name, relative to the file. If the supplied name is an + * absolute path, then it is resolved relative to the root of the + * file system that the file belongs to. If a relative name is suppli= ed, + * then it is resolved relative to this file name. + */ + public FileName resolveName(final FileName root, final String path) th= rows FileSystemException + { + return resolveName(root, path, NameScope.FILE_SYSTEM); + } + + /** + * Resolves a name, relative to the root. + * + * @param root the base filename + * @param name the name + * @param scope the {@link NameScope} + * @return + * @throws FileSystemException + */ + public FileName resolveName(final FileName root, + final String name, + final NameScope scope) + throws FileSystemException + { + final StringBuffer buffer =3D new StringBuffer(name); + + // Adjust separators + UriParser.fixSeparators(buffer); + + // Determine whether to prepend the base path + if (name.length() =3D=3D 0 || name.charAt(0) !=3D FileName.SEPARAT= OR_CHAR) + { + // Supplied path is not absolute + buffer.insert(0, FileName.SEPARATOR_CHAR); + buffer.insert(0, root.getPath()); + } + + //// UriParser.canonicalizePath(buffer, 0, name.length()); + + // Normalise the path + UriParser.normalisePath(buffer); + + // Check the name is ok + final String resolvedPath =3D buffer.toString(); + if (!AbstractFileName.checkName(root.getPath(), resolvedPath, scop= e)) + { + throw new FileSystemException("vfs.provider/invalid-descendent= -name.error", name); + } + + // todo: pass this down to the fileProvider + return ((AbstractFileName) root).createName(resolvedPath); + } + + public FileName resolveURI(String uri) throws FileSystemException + { + UriParser.checkUriEncoding(uri); + + if (uri =3D=3D null) + { + throw new IllegalArgumentException(); + } + +// Extract the scheme + final String scheme =3D UriParser.extractScheme(uri); + if (scheme !=3D null) + { +// An absolute URI - locate the provider + final FileProvider provider =3D (FileProvider) providers.get(s= cheme); + if (provider !=3D null) + { + return provider.parseUri(scheme, uri); + } =20 -// Decode the URI (remove %nn encodings) - final String decodedUri =3D UriParser.decode(uri); +// Otherwise, assume a local file + } =20 // Handle absolute file names if (localFileProvider !=3D null - && localFileProvider.isAbsoluteLocalName(decodedUri)) + && localFileProvider.isAbsoluteLocalName(uri)) { - return localFileProvider.findLocalFile(decodedUri); + return localFileProvider.parseUri(null, uri); } =20 if (scheme !=3D null) @@ -526,7 +632,7 @@ { throw new FileSystemException("vfs.impl/unknown-scheme.err= or", new Object[]{scheme, uri}); } - return defaultProvider.findFile(baseFile, uri, fileSystemOptio= ns); + return defaultProvider.parseUri(null, uri); } =20 // Assume a relative name - use the supplied base file @@ -535,7 +641,7 @@ throw new FileSystemException("vfs.impl/find-rel-file.error", = uri); } =20 - return baseFile.resolveFile(decodedUri); + return resolveName(baseFile.getName(), uri, NameScope.FILE_SYSTEM); } =20 /** Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /impl/DefaultVfsComponentContext.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/impl/DefaultVfsComponentContext.java?view=3Ddiff&= r1=3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultVfsComponentContext.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= DefaultVfsComponentContext.java Fri Mar 25 11:12:17 2005 @@ -19,6 +19,7 @@ import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileSystemManager; import org.apache.commons.vfs.FileSystemOptions; +import org.apache.commons.vfs.FileName; import org.apache.commons.vfs.provider.FileReplicator; import org.apache.commons.vfs.provider.TemporaryFileStore; import org.apache.commons.vfs.provider.VfsComponentContext; @@ -58,6 +59,11 @@ throws FileSystemException { return manager.resolveFile(name, fileSystemOptions); + } + + public FileName parseURI(String uri) throws FileSystemException + { + return manager.resolveURI(uri); } =20 /** Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /impl/VirtualFileSystem.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/impl/VirtualFileSystem.java?view=3Ddiff&r1=3D1590= 45&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= VirtualFileSystem.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= VirtualFileSystem.java Fri Mar 25 11:12:17 2005 @@ -101,7 +101,7 @@ final FileObject targetFile) throws FileSystemException { - final FileName junctionName =3D getRootName().resolveName(junction= Point); + final FileName junctionName =3D getFileSystemManager().resolveName= (getRootName(), junctionPoint); =20 // Check for nested junction - these are not supported yet if (getJunctionForFile(junctionName) !=3D null) @@ -155,7 +155,7 @@ public void removeJunction(final String junctionPoint) throws FileSystemException { - final FileName junctionName =3D getRootName().resolveName(junction= Point); + final FileName junctionName =3D getFileSystemManager().resolveName= (getRootName(), junctionPoint); junctions.remove(junctionName); =20 // TODO - remove from parents of junction point Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /impl/providers.xml URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/impl/providers.xml?view=3Ddiff&r1=3D159045&r2=3D1= 59046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= providers.xml (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/impl/= providers.xml Fri Mar 25 11:12:17 2005 @@ -28,7 +28,7 @@ - + Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/AbstractFileName.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/AbstractFileName.java?view=3Ddiff&r1=3D1= 59045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileName.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileName.java Fri Mar 25 11:12:17 2005 @@ -36,6 +36,7 @@ private String baseName; private String rootUri; private String extension; + private String decodedAbsPath; =20 public AbstractFileName(final String scheme, final String absPath) @@ -56,7 +57,7 @@ */ public int hashCode() { - return (getRootURI().hashCode() ^ absPath.hashCode()); + return (getRootURI().hashCode() ^ getPath().hashCode()); } =20 /** @@ -65,7 +66,7 @@ public boolean equals(final Object obj) { final AbstractFileName name =3D (AbstractFileName) obj; - return (getRootURI().equals(name.getRootURI()) && absPath.equals(n= ame.absPath)); + return (getRootURI().equals(name.getRootURI()) && getPath().equals= (name.getPath())); } =20 /** @@ -83,7 +84,15 @@ return ret; } =20 - return absPath.compareTo(name.absPath); + // return absPath.compareTo(name.absPath); + try + { + return getPathDecoded().compareTo(name.getPathDecoded()); + } + catch (FileSystemException e) + { + throw new RuntimeException(e.getMessage()); + } } =20 /** @@ -97,7 +106,7 @@ /** * Factory method for creating name instances. */ - protected abstract FileName createName(String absPath); + public abstract FileName createName(String absPath); =20 /** * Builds the root URI for this file name. Note that the root URI mus= t not @@ -112,14 +121,14 @@ { if (baseName =3D=3D null) { - final int idx =3D absPath.lastIndexOf(SEPARATOR_CHAR); + final int idx =3D getPath().lastIndexOf(SEPARATOR_CHAR); if (idx =3D=3D -1) { - baseName =3D absPath; + baseName =3D getPath(); } else { - baseName =3D absPath.substring(idx + 1); + baseName =3D getPath().substring(idx + 1); } } =20 @@ -135,37 +144,14 @@ return absPath; } =20 - /** - * Resolves a name, relative to this file name. - */ - public FileName resolveName(final String name, - final NameScope scope) - throws FileSystemException + public String getPathDecoded() throws FileSystemException { - final StringBuffer buffer =3D new StringBuffer(name); - - // Adjust separators - UriParser.fixSeparators(buffer); - - // Determine whether to prepend the base path - if (name.length() =3D=3D 0 || name.charAt(0) !=3D SEPARATOR_CHAR) + if (decodedAbsPath =3D=3D null) { - // Supplied path is not absolute - buffer.insert(0, SEPARATOR_CHAR); - buffer.insert(0, absPath); + decodedAbsPath =3D UriParser.decode(absPath); } =20 - // Normalise the path - UriParser.normalisePath(buffer); - - // Check the name is ok - final String resolvedPath =3D buffer.toString(); - if (!checkName(absPath, resolvedPath, scope)) - { - throw new FileSystemException("vfs.provider/invalid-descendent= -name.error", name); - } - - return createName(resolvedPath); + return decodedAbsPath; } =20 /** @@ -174,8 +160,8 @@ public FileName getParent() { final String parentPath; - final int idx =3D absPath.lastIndexOf(SEPARATOR_CHAR); - if (idx =3D=3D -1 || idx =3D=3D absPath.length() - 1) + final int idx =3D getPath().lastIndexOf(SEPARATOR_CHAR); + if (idx =3D=3D -1 || idx =3D=3D getPath().length() - 1) { // No parent return null; @@ -187,23 +173,12 @@ } else { - parentPath =3D absPath.substring(0, idx); + parentPath =3D getPath().substring(0, idx); } return createName(parentPath); } =20 /** - * Resolves a name, relative to the file. If the supplied name is an - * absolute path, then it is resolved relative to the root of the - * file system that the file belongs to. If a relative name is suppli= ed, - * then it is resolved relative to this file name. - */ - public FileName resolveName(final String path) throws FileSystemExcept= ion - { - return resolveName(path, NameScope.FILE_SYSTEM); - } - - /** * Returns the URI scheme of this file. */ public String getScheme() @@ -220,7 +195,7 @@ { final StringBuffer buffer =3D new StringBuffer(); appendRootUri(buffer); - buffer.append(absPath); + buffer.append(getPath()); uri =3D buffer.toString(); } return uri; @@ -234,7 +209,7 @@ final String path =3D name.getPath(); =20 // Calculate the common prefix - final int basePathLen =3D absPath.length(); + final int basePathLen =3D getPath().length(); final int pathLen =3D path.length(); =20 // Deal with root @@ -249,7 +224,7 @@ =20 final int maxlen =3D Math.min(basePathLen, pathLen); int pos =3D 0; - for (; pos < maxlen && absPath.charAt(pos) =3D=3D path.charAt(pos)= ; pos++) + for (; pos < maxlen && getPath().charAt(pos) =3D=3D path.charAt(po= s); pos++) { } =20 @@ -266,21 +241,21 @@ =20 // Strip the common prefix off the path final StringBuffer buffer =3D new StringBuffer(); - if (pathLen > 1 && (pos < pathLen || absPath.charAt(pos) !=3D SEPA= RATOR_CHAR)) + if (pathLen > 1 && (pos < pathLen || getPath().charAt(pos) !=3D SE= PARATOR_CHAR)) { // Not a direct ancestor, need to back up - pos =3D absPath.lastIndexOf(SEPARATOR_CHAR, pos); + pos =3D getPath().lastIndexOf(SEPARATOR_CHAR, pos); buffer.append(path.substring(pos)); } =20 // Prepend a '../' for each element in the base path past the comm= on // prefix buffer.insert(0, ".."); - pos =3D absPath.indexOf(SEPARATOR_CHAR, pos + 1); + pos =3D getPath().indexOf(SEPARATOR_CHAR, pos + 1); while (pos !=3D -1) { buffer.insert(0, "../"); - pos =3D absPath.indexOf(SEPARATOR_CHAR, pos + 1); + pos =3D getPath().indexOf(SEPARATOR_CHAR, pos + 1); } =20 return buffer.toString(); @@ -306,15 +281,15 @@ */ public int getDepth() { - final int len =3D absPath.length(); - if (len =3D=3D 0 || (len =3D=3D 1 && absPath.charAt(0) =3D=3D SEPA= RATOR_CHAR)) + final int len =3D getPath().length(); + if (len =3D=3D 0 || (len =3D=3D 1 && getPath().charAt(0) =3D=3D SE= PARATOR_CHAR)) { return 0; } int depth =3D 1; for (int pos =3D 0; pos > -1 && pos < len; depth++) { - pos =3D absPath.indexOf(SEPARATOR_CHAR, pos + 1); + pos =3D getPath().indexOf(SEPARATOR_CHAR, pos + 1); } return depth; } @@ -355,7 +330,7 @@ { return false; } - return checkName(ancestor.getPath(), absPath, NameScope.DESCENDENT= ); + return checkName(ancestor.getPath(), getPath(), NameScope.DESCENDE= NT); } =20 /** @@ -376,7 +351,7 @@ { return false; } - return checkName(absPath, descendent.getPath(), scope); + return checkName(getPath(), descendent.getPath(), scope); } =20 /** @@ -385,7 +360,7 @@ * @param basePath An absolute, normalised path. * @param path An absolute, normalised path. */ - private boolean checkName(final String basePath, + public static boolean checkName(final String basePath, final String path, final NameScope scope) { Added: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/pr= ovider/AbstractFileNameParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/AbstractFileNameParser.java?view=3Dauto&= rev=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileNameParser.java (added) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileNameParser.java Fri Mar 25 11:12:17 2005 @@ -0,0 +1,27 @@ +/* + * 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; + +/** + * Provides methods to parse a filename into a {@link org.apache.commons.v= fs.FileName} + */ +public abstract class AbstractFileNameParser implements FileNameParser +{ + public boolean encodeCharacter(char ch) + { + return ch =3D=3D '%'; + } +} Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/AbstractFileNameParser.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/AbstractFileNameParser.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/AbstractFileNameParser.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/AbstractFileObject.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/AbstractFileObject.java?view=3Ddiff&r1= =3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileObject.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileObject.java Fri Mar 25 11:12:17 2005 @@ -566,7 +566,8 @@ { final String file =3D files[i]; // children[i] =3D fs.resolveFile(name.resolveName(fil= e, NameScope.CHILD)); - children[i] =3D name.resolveName(file, NameScope.CHILD= ); + // children[i] =3D name.resolveName(file, NameScope.CH= ILD); + children[i] =3D getFileSystem().getFileSystemManager()= .resolveName(name, file, NameScope.CHILD); } } =20 @@ -638,7 +639,8 @@ public FileObject resolveFile(final String name, final NameScope scope) throws FileSystemException { - return fs.resolveFile(this.name.resolveName(name, scope)); + // return fs.resolveFile(this.name.resolveName(name, scope)); + return fs.resolveFile(getFileSystem().getFileSystemManager().resol= veName(this.name, name, scope)); } =20 /** @@ -651,7 +653,7 @@ */ public FileObject resolveFile(final String path) throws FileSystemExce= ption { - final FileName otherName =3D name.resolveName(path); + final FileName otherName =3D getFileSystem().getFileSystemManager(= )=2EresolveName(name, path); return fs.resolveFile(otherName); } =20 Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/AbstractFileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/AbstractFileProvider.java?view=3Ddiff&r1= =3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileProvider.java Fri Mar 25 11:12:17 2005 @@ -20,6 +20,8 @@ import org.apache.commons.vfs.FileSystemConfigBuilder; import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileSystemOptions; +import org.apache.commons.vfs.FileName; +import org.apache.commons.vfs.provider.local.GenericFileNameParser; =20 import java.util.Iterator; import java.util.Map; @@ -36,8 +38,21 @@ extends AbstractVfsContainer implements FileProvider { + private FileNameParser parser; + public AbstractFileProvider() { + parser =3D GenericFileNameParser.getInstance(); + } + + protected FileNameParser getFileNameParser() + { + return parser; + } + + protected void setFileNameParser(FileNameParser parser) + { + this.parser =3D parser; } =20 /** @@ -133,5 +148,22 @@ removeComponent(fileSystems); fs.close(); } + } + + /** + * Parses an absolute URI. + * + * @param schme + * @param uri The URI to parse. + */ + public FileName parseUri(String schme, String uri) throws FileSystemEx= ception + { + if (getFileNameParser() !=3D null) + { + return getFileNameParser().parseUri(getContext(), uri); + } + + throw new FileSystemException("vfs.provider/filename-parser-missin= g=2Eerror"); + // return GenericFileName.parseUri(getFileNameParser(), uri, 0); } } Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/AbstractFileSystem.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/AbstractFileSystem.java?view=3Ddiff&r1= =3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileSystem.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractFileSystem.java Fri Mar 25 11:12:17 2005 @@ -244,7 +244,7 @@ public FileObject resolveFile(final String nameStr) throws FileSystemE= xception { // Resolve the name, and create the file - final FileName name =3D rootName.resolveName(nameStr); + final FileName name =3D getFileSystemManager().resolveName(rootNam= e, nameStr); return resolveFile(name); } =20 Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/AbstractLayeredFileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/AbstractLayeredFileProvider.java?view=3D= diff&r1=3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractLayeredFileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractLayeredFileProvider.java Fri Mar 25 11:12:17 2005 @@ -35,6 +35,7 @@ public AbstractLayeredFileProvider() { super(); + setFileNameParser(LayeredFileNameParser.getInstance()); } =20 /** @@ -45,13 +46,13 @@ final FileSystemOptions properties) throws = FileSystemException { // Split the URI up into its parts - final LayeredFileName name =3D (LayeredFileName) parseUri(uri); + final LayeredFileName name =3D (LayeredFileName) parseUri(baseFile= !=3Dnull?baseFile.getName().getScheme():null, uri); =20 // Make the URI canonical =20 // Resolve the outer file name - final String fileName =3D name.getOuterUri(); - final FileObject file =3D getContext().resolveFile(baseFile, fileN= ame, properties); + final FileName fileName =3D name.getOuterName(); + final FileObject file =3D getContext().resolveFile(baseFile, fileN= ame.getURI(), properties); =20 // Create the file system final FileObject rootFile =3D createFileSystem(name.getScheme(), f= ile, properties); @@ -93,11 +94,4 @@ final FileSystemOptio= ns fileSystemOptions) throws FileSystemException; =20 - /** - * Parses an absolute URI. - * - * @param uri The URI to parse. - */ - protected abstract FileName parseUri(String uri) - throws FileSystemException; } Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/AbstractOriginatingFileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/AbstractOriginatingFileProvider.java?vie= w=3Ddiff&r1=3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractOriginatingFileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/AbstractOriginatingFileProvider.java Fri Mar 25 11:12:17 2005 @@ -50,7 +50,7 @@ final FileName name; try { - name =3D parseUri(uri); + name =3D parseUri(baseFile!=3Dnull?baseFile.getName().getSchem= e():null, uri); } catch (FileSystemException exc) { @@ -68,7 +68,7 @@ throws FileSystemException { // Check in the cache for the file system - final FileName rootName =3D name.resolveName(FileName.ROOT_PATH); + final FileName rootName =3D getContext().getFileSystemManager().re= solveName(name, FileName.ROOT_PATH); FileSystem fs =3D findFileSystem(rootName, fileSystemOptions); if (fs =3D=3D null) { @@ -80,16 +80,6 @@ // Locate the file return fs.resolveFile(name.getPath()); } - - /** - * Parses an absolute URI. - * - * @return The name of the file. This name is used to locate the file - * system in the cache, using the root URI. This name is also - * passed to {@link #doCreateFileSystem} to create the file sy= stem. - */ - protected abstract FileName parseUri(final String uri) - throws FileSystemException; =20 /** * Creates a {@link FileSystem}. If the returned FileSystem implements Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/BasicFileName.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/BasicFileName.java?view=3Ddiff&r1=3D1590= 45&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/BasicFileName.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/BasicFileName.java Fri Mar 25 11:12:17 2005 @@ -72,7 +72,7 @@ /** * Factory method for creating name instances. */ - protected FileName createName(final String path) + public FileName createName(final String path) { return new BasicFileName(getScheme(), rootUri, path, true); } Added: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/pr= ovider/FileNameParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/FileNameParser.java?view=3Dauto&rev=3D15= 9046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/FileNameParser.java (added) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/FileNameParser.java Fri Mar 25 11:12:17 2005 @@ -0,0 +1,40 @@ +/* + * 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; + +import org.apache.commons.vfs.FileName; +import org.apache.commons.vfs.FileSystemException; + +/** + * Provides methods to parse a filename into a {@link org.apache.commons.v= fs.FileName} + */ +public interface FileNameParser +{ + /** + * Check if a character needs encoding (%nn) + * @param ch the character + * @return true if character should be encoded + */ + public boolean encodeCharacter(char ch); + + /** + * parses a String into a filename + * @param filename + * @return + * @throws org.apache.commons.vfs.FileSystemException + */ + public FileName parseUri(final VfsComponentContext context, final Stri= ng filename) throws FileSystemException; +} Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/FileNameParser.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/FileNameParser.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/FileNameParser.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/FileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/FileProvider.java?view=3Ddiff&r1=3D15904= 5&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/FileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/FileProvider.java Fri Mar 25 11:12:17 2005 @@ -19,6 +19,7 @@ import org.apache.commons.vfs.FileSystemConfigBuilder; import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileSystemOptions; +import org.apache.commons.vfs.FileName; =20 import java.util.Collection; =20 @@ -66,4 +67,6 @@ * instanciated. */ public Collection getCapabilities(); + + public FileName parseUri(String schme, String uri) throws FileSystemEx= ception; } Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/GenericFileName.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/GenericFileName.java?view=3Ddiff&r1=3D15= 9045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/GenericFileName.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/GenericFileName.java Fri Mar 25 11:12:17 2005 @@ -16,7 +16,6 @@ package org.apache.commons.vfs.provider; =20 import org.apache.commons.vfs.FileName; -import org.apache.commons.vfs.FileSystemException; =20 /** * A file name that represents a 'generic' URI, as per RFC 2396. Consists= of @@ -103,7 +102,7 @@ /** * Factory method for creating name instances. */ - protected FileName createName(final String absPath) + public FileName createName(final String absPath) { return new GenericFileName(getScheme(), hostName, @@ -115,192 +114,6 @@ } =20 /** - * Parses a generic URI. - */ - public static GenericFileName parseUri(final String uri, - final int defaultPort) - throws FileSystemException - { - // FTP URI are generic URI (as per RFC 2396) - final StringBuffer name =3D new StringBuffer(); - - // Extract the scheme and authority parts - final Authority auth =3D extractToPath(uri, name); - - // Decode and normalise the file name - UriParser.decode(name, 0, name.length()); - UriParser.normalisePath(name); - final String path =3D name.toString(); - - return new GenericFileName(auth.scheme, - auth.hostName, - auth.port, - defaultPort, - auth.userName, - auth.password, - path); - } - - /** - * Extracts the scheme, userinfo, hostname and port components of a - * generic URI. - * - * @param uri The absolute URI to parse. - * @param name Used to return the remainder of the URI. - */ - protected static Authority extractToPath(final String uri, - final StringBuffer name) - throws FileSystemException - { - final Authority auth =3D new Authority(); - - // Extract the scheme - auth.scheme =3D UriParser.extractScheme(uri, name); - - // Expecting "//" - if (name.length() < 2 || name.charAt(0) !=3D '/' || name.charAt(1)= !=3D '/') - { - throw new FileSystemException("vfs.provider/missing-double-sla= shes.error", uri); - } - name.delete(0, 2); - - // Extract userinfo, and split into username and password - final String userInfo =3D extractUserInfo(name); - final String userName; - final String password; - if (userInfo !=3D null) - { - int idx =3D userInfo.indexOf(':'); - if (idx =3D=3D -1) - { - userName =3D userInfo; - password =3D null; - } - else - { - userName =3D userInfo.substring(0, idx); - password =3D userInfo.substring(idx + 1); - } - } - else - { - userName =3D null; - password =3D null; - } - auth.userName =3D UriParser.decode(userName); - auth.password =3D UriParser.decode(password); - - // Extract hostname, and normalise (lowercase) - final String hostName =3D extractHostName(name); - if (hostName =3D=3D null) - { - throw new FileSystemException("vfs.provider/missing-hostname.e= rror", uri); - } - auth.hostName =3D hostName.toLowerCase(); - - // Extract port - auth.port =3D extractPort(name, uri); - - // Expecting '/' or empty name - if (name.length() > 0 && name.charAt(0) !=3D '/') - { - throw new FileSystemException("vfs.provider/missing-hostname-p= ath-sep.error", uri); - } - - return auth; - } - - /** - * Extracts the user info from a URI. The scheme:// part has been rem= oved - * already. - */ - protected static String extractUserInfo(final StringBuffer name) - { - final int maxlen =3D name.length(); - for (int pos =3D 0; pos < maxlen; pos++) - { - final char ch =3D name.charAt(pos); - if (ch =3D=3D '@') - { - // Found the end of the user info - String userInfo =3D name.substring(0, pos); - name.delete(0, pos + 1); - return userInfo; - } - if (ch =3D=3D '/' || ch =3D=3D '?') - { - // Not allowed in user info - break; - } - } - - // Not found - return null; - } - - /** - * Extracts the hostname from a URI. The scheme://userinfo@ part has - * been removed. - */ - protected static String extractHostName(final StringBuffer name) - { - final int maxlen =3D name.length(); - int pos =3D 0; - for (; pos < maxlen; pos++) - { - final char ch =3D name.charAt(pos); - if (ch =3D=3D '/' || ch =3D=3D ';' || ch =3D=3D '?' || ch =3D= =3D ':' - || ch =3D=3D '@' || ch =3D=3D '&' || ch =3D=3D '=3D' || ch= =3D=3D '+' - || ch =3D=3D '$' || ch =3D=3D ',') - { - break; - } - } - if (pos =3D=3D 0) - { - return null; - } - - final String hostname =3D name.substring(0, pos); - name.delete(0, pos); - return hostname; - } - - /** - * Extracts the port from a URI. The scheme://userinfo@hostname - * part has been removed. - * - * @return The port, or -1 if the URI does not contain a port. - */ - private static int extractPort(final StringBuffer name, final String u= ri) throws FileSystemException - { - if (name.length() < 1 || name.charAt(0) !=3D ':') - { - return -1; - } - - final int maxlen =3D name.length(); - int pos =3D 1; - for (; pos < maxlen; pos++) - { - final char ch =3D name.charAt(pos); - if (ch < '0' || ch > '9') - { - break; - } - } - - final String port =3D name.substring(1, pos); - name.delete(0, pos); - if (port.length() =3D=3D 0) - { - throw new FileSystemException("vfs.provider/missing-port.error= ", uri); - } - - return Integer.parseInt(port); - } - - /** * Builds the root URI for this file name. */ protected void appendRootUri(final StringBuffer buffer) @@ -323,17 +136,5 @@ buffer.append(':'); buffer.append(port); } - } - - /** - * Parsed authority info (scheme, hostname, userinfo, port) - */ - protected static class Authority - { - public String scheme; - public String hostName; - public String userName; - public String password; - public int port; } } Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/LayeredFileName.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/LayeredFileName.java?view=3Ddiff&r1=3D15= 9045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/LayeredFileName.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/LayeredFileName.java Fri Mar 25 11:12:17 2005 @@ -15,20 +15,22 @@ */ package org.apache.commons.vfs.provider; =20 +import org.apache.commons.vfs.FileSystemException; +import org.apache.commons.vfs.FileName; + /** * A file name for layered files. * * @author Adam Murdoch * @version $Revision$ $Date$ */ -public abstract class LayeredFileName - extends AbstractFileName +public class LayeredFileName extends AbstractFileName { - private final String outerUri; + private final FileName outerUri; =20 - protected LayeredFileName(final String scheme, - final String outerUri, - final String path) + public LayeredFileName(final String scheme, + final FileName outerUri, + final String path) { super(scheme, path); this.outerUri =3D outerUri; @@ -37,8 +39,21 @@ /** * Returns the URI of the outer file. */ - public String getOuterUri() + public FileName getOuterName() { return outerUri; + } + + public FileName createName(String path) + { + return new LayeredFileName(getScheme(), getOuterName(), path); + } + + protected void appendRootUri(StringBuffer buffer) + { + buffer.append(getScheme()); + buffer.append(":"); + buffer.append(getOuterName().getURI()); + buffer.append("!"); } } Added: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/pr= ovider/LayeredFileNameParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/LayeredFileNameParser.java?view=3Dauto&r= ev=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/LayeredFileNameParser.java (added) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/LayeredFileNameParser.java Fri Mar 25 11:12:17 2005 @@ -0,0 +1,90 @@ +/* + * 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; + +import org.apache.commons.vfs.FileName; +import org.apache.commons.vfs.FileSystemException; + +/** + * Implementation for layered filesystems. + *

+ * Additionally encodes the '!' character. + */ +public class LayeredFileNameParser extends AbstractFileNameParser +{ + private final static LayeredFileNameParser INSTANCE =3D new LayeredFil= eNameParser(); + + public static LayeredFileNameParser getInstance() + { + return INSTANCE; + } + + public boolean encodeCharacter(char ch) + { + return super.encodeCharacter(ch) || ch =3D=3D '!'; + } + + public FileName parseUri(final VfsComponentContext context, final Stri= ng filename) throws FileSystemException + { + final StringBuffer name =3D new StringBuffer(); + + // Extract the scheme + final String scheme =3D UriParser.extractScheme(filename, name); + + // Extract the Layered file URI + final String rootUriName =3D extractRootName(name); + FileName rootUri =3D null; + if (rootUriName !=3D null) + { + rootUri =3D context.parseURI(rootUriName); + } + + // Decode and normalise the path + UriParser.canonicalizePath(name, 0, name.length(), this); + UriParser.normalisePath(name); + final String path =3D name.toString(); + + return new LayeredFileName(scheme, rootUri, path); + } + + /** + * Pops the root prefix off a URI, which has had the scheme removed. + */ + protected String extractRootName(final StringBuffer uri) + throws FileSystemException + { + // Looking for ! (staring at the end) + int maxlen =3D uri.length(); + int pos =3D maxlen-1; + for (; pos > 0 && uri.charAt(pos) !=3D '!'; pos--) + { + } + + // Extract the name + String prefix =3D uri.substring(0, pos); + if (pos < maxlen) + { + uri.delete(0, pos + 1); + } + else + { + uri.setLength(0); + } + + return prefix; + } + +} Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/LayeredFileNameParser.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/LayeredFileNameParser.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/LayeredFileNameParser.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain Added: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/pr= ovider/URLFileNameParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/URLFileNameParser.java?view=3Dauto&rev= =3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/URLFileNameParser.java (added) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/URLFileNameParser.java Fri Mar 25 11:12:17 2005 @@ -0,0 +1,233 @@ +/* + * Copyright 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; + +import org.apache.commons.vfs.FileName; +import org.apache.commons.vfs.FileSystemException; + +/** + * Implementation for the webdav filesystem. + * < p/> + * Additionally encodes every character below space (' ') + */ +public class URLFileNameParser extends AbstractFileNameParser +{ + private final int defaultPort; + + public URLFileNameParser(final int defaultPort) + { + this.defaultPort =3D defaultPort; + } + + public int getDefaultPort() + { + return defaultPort; + } + + public FileName parseUri(final VfsComponentContext context, final Stri= ng filename) throws FileSystemException + { + // FTP URI are generic URI (as per RFC 2396) + final StringBuffer name =3D new StringBuffer(); + + // Extract the scheme and authority parts + final Authority auth =3D extractToPath(filename, name); + + // Decode and normalise the file name + UriParser.canonicalizePath(name, 0, name.length(), this); + UriParser.normalisePath(name); + final String path =3D name.toString(); + + return new GenericFileName( + auth.scheme, + auth.hostName, + auth.port, + defaultPort, + auth.userName, + auth.password, + path); + } + + /** + * Extracts the scheme, userinfo, hostname and port components of a + * generic URI. + * + * @param uri The absolute URI to parse. + * @param name Used to return the remainder of the URI. + */ + protected Authority extractToPath(final String uri, + final StringBuffer name) + throws FileSystemException + { + final Authority auth =3D new Authority(); + + // Extract the scheme + auth.scheme =3D UriParser.extractScheme(uri, name); + + // Expecting "//" + if (name.length() < 2 || name.charAt(0) !=3D '/' || name.charAt(1)= !=3D '/') + { + throw new FileSystemException("vfs.provider/missing-double-sla= shes.error", uri); + } + name.delete(0, 2); + + // Extract userinfo, and split into username and password + final String userInfo =3D extractUserInfo(name); + final String userName; + final String password; + if (userInfo !=3D null) + { + int idx =3D userInfo.indexOf(':'); + if (idx =3D=3D -1) + { + userName =3D userInfo; + password =3D null; + } + else + { + userName =3D userInfo.substring(0, idx); + password =3D userInfo.substring(idx + 1); + } + } + else + { + userName =3D null; + password =3D null; + } + auth.userName =3D UriParser.decode(userName); + auth.password =3D UriParser.decode(password); + + // Extract hostname, and normalise (lowercase) + final String hostName =3D extractHostName(name); + if (hostName =3D=3D null) + { + throw new FileSystemException("vfs.provider/missing-hostname.e= rror", uri); + } + auth.hostName =3D hostName.toLowerCase(); + + // Extract port + auth.port =3D extractPort(name, uri); + + // Expecting '/' or empty name + if (name.length() > 0 && name.charAt(0) !=3D '/') + { + throw new FileSystemException("vfs.provider/missing-hostname-p= ath-sep.error", uri); + } + + return auth; + } + + /** + * Extracts the user info from a URI. The scheme:// part has been rem= oved + * already. + */ + protected String extractUserInfo(final StringBuffer name) + { + final int maxlen =3D name.length(); + for (int pos =3D 0; pos < maxlen; pos++) + { + final char ch =3D name.charAt(pos); + if (ch =3D=3D '@') + { + // Found the end of the user info + String userInfo =3D name.substring(0, pos); + name.delete(0, pos + 1); + return userInfo; + } + if (ch =3D=3D '/' || ch =3D=3D '?') + { + // Not allowed in user info + break; + } + } + + // Not found + return null; + } + + /** + * Extracts the hostname from a URI. The scheme://userinfo@ part has + * been removed. + */ + protected String extractHostName(final StringBuffer name) + { + final int maxlen =3D name.length(); + int pos =3D 0; + for (; pos < maxlen; pos++) + { + final char ch =3D name.charAt(pos); + if (ch =3D=3D '/' || ch =3D=3D ';' || ch =3D=3D '?' || ch =3D= =3D ':' + || ch =3D=3D '@' || ch =3D=3D '&' || ch =3D=3D '=3D' || ch= =3D=3D '+' + || ch =3D=3D '$' || ch =3D=3D ',') + { + break; + } + } + if (pos =3D=3D 0) + { + return null; + } + + final String hostname =3D name.substring(0, pos); + name.delete(0, pos); + return hostname; + } + + /** + * Extracts the port from a URI. The scheme://userinfo@hostname + * part has been removed. + * + * @return The port, or -1 if the URI does not contain a port. + */ + protected int extractPort(final StringBuffer name, final String uri) t= hrows FileSystemException + { + if (name.length() < 1 || name.charAt(0) !=3D ':') + { + return -1; + } + + final int maxlen =3D name.length(); + int pos =3D 1; + for (; pos < maxlen; pos++) + { + final char ch =3D name.charAt(pos); + if (ch < '0' || ch > '9') + { + break; + } + } + + final String port =3D name.substring(1, pos); + name.delete(0, pos); + if (port.length() =3D=3D 0) + { + throw new FileSystemException("vfs.provider/missing-port.error= ", uri); + } + + return Integer.parseInt(port); + } + + /** + * Parsed authority info (scheme, hostname, userinfo, port) + */ + protected static class Authority + { + public String scheme; + public String hostName; + public String userName; + public String password; + public int port; + } +} Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/URLFileNameParser.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/URLFileNameParser.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/URLFileNameParser.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/UriParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/UriParser.java?view=3Ddiff&r1=3D159045&r= 2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/UriParser.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/UriParser.java Fri Mar 25 11:12:17 2005 @@ -365,4 +365,89 @@ } } } + + /** + * Removes %nn encodings from a string. + */ + public static String encode(final String decodedStr) + { + return encode(decodedStr, null); + } + + public static String encode(final String decodedStr, final char[] rese= rved) + { + if (decodedStr =3D=3D null) + { + return null; + } + final StringBuffer buffer =3D new StringBuffer(decodedStr); + encode(buffer, 0, buffer.length(), reserved); + return buffer.toString(); + } + + public static String[] encode(String[] strings) + { + for (int i =3D 0; i 0; count--, index++) + { + final char ch =3D buffer.charAt(index); + if (ch =3D=3D '%') + { + if (count < 3) + { + throw new FileSystemException("vfs.provider/invalid-es= cape-sequence.error", buffer.substring(index, index + count)); + } + + // Decode + int dig1 =3D Character.digit(buffer.charAt(index + 1), 16); + int dig2 =3D Character.digit(buffer.charAt(index + 2), 16); + if (dig1 =3D=3D -1 || dig2 =3D=3D -1) + { + throw new FileSystemException("vfs.provider/invalid-es= cape-sequence.error", buffer.substring(index, index + 3)); + } + char value =3D (char) (dig1 << 4 | dig2); + + boolean match =3D (ch =3D=3D '%') || (fileNameParser !=3D = null && fileNameParser.encodeCharacter(ch)); + + if (match) + { + // this is a reserved character, not allowed to decode + index+=3D2; + count-=3D2; + continue; + } + + // Replace + buffer.setCharAt(index, value); + buffer.delete(index + 1, index + 3); + count -=3D 2; + } + else if (fileNameParser.encodeCharacter(ch)) + { + // Encode + char[] digits =3D { + Character.forDigit(((ch >> 4) & 0xF), 16), + Character.forDigit((ch & 0xF), 16) + }; + buffer.setCharAt(index, '%'); + buffer.insert(index + 1, digits); + index +=3D 2; + } + } + } } Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/VfsComponentContext.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/VfsComponentContext.java?view=3Ddiff&r1= =3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/VfsComponentContext.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/VfsComponentContext.java Fri Mar 25 11:12:17 2005 @@ -19,6 +19,7 @@ import org.apache.commons.vfs.FileSystemException; import org.apache.commons.vfs.FileSystemManager; import org.apache.commons.vfs.FileSystemOptions; +import org.apache.commons.vfs.FileName; =20 import java.io.File; =20 @@ -48,6 +49,8 @@ */ FileObject resolveFile(String name, FileSystemOptions fileSystemOption= s) throws FileSystemException; + + FileName parseURI(String uri) throws FileSystemException; =20 /** * Locates a file replicator for the provider to use. Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/compressed/CompressedFileFileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/compressed/CompressedFileFileProvider.ja= va?view=3Ddiff&r1=3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/compressed/CompressedFileFileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/compressed/CompressedFileFileProvider.java Fri Mar 25 11:12:17 2005 @@ -22,6 +22,7 @@ import org.apache.commons.vfs.FileSystemOptions; import org.apache.commons.vfs.provider.AbstractLayeredFileProvider; import org.apache.commons.vfs.provider.FileProvider; +import org.apache.commons.vfs.provider.LayeredFileName; import org.apache.commons.vfs.provider.zip.ZipFileName; =20 import java.util.Collection; @@ -47,11 +48,13 @@ * * @param uri The URI to parse. */ - protected FileName parseUri(final String uri) + /* + public FileName parseUri(final String uri) throws FileSystemException { return ZipFileName.parseUri(uri); } + */ =20 /** * Creates a layered file system. This method is called if the file s= ystem @@ -67,7 +70,7 @@ throws FileSystemException { final FileName name =3D - new ZipFileName(scheme, file.getName().getURI(), FileName.ROOT= _PATH); + new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH= ); return createFileSystem(name, file, fileSystemOptions); } =20 Added: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/pr= ovider/ftp/FtpFileNameParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/ftp/FtpFileNameParser.java?view=3Dauto&r= ev=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileNameParser.java (added) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileNameParser.java Fri Mar 25 11:12:17 2005 @@ -0,0 +1,46 @@ +/* + * Copyright 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.ftp; + +import org.apache.commons.vfs.provider.FileNameParser; +import org.apache.commons.vfs.provider.URLFileNameParser; +import org.apache.commons.vfs.provider.http.HttpFileNameParser; +import org.apache.commons.vfs.provider.webdav.WebdavFileNameParser; + +/** + * Implementation for the webdav filesystem. + * < p/> + * Additionally encodes every character below space (' ') + */ +public class FtpFileNameParser extends URLFileNameParser +{ + private final static FtpFileNameParser INSTANCE =3D new FtpFileNamePar= ser(); + + public FtpFileNameParser() + { + super(21); + } + + public boolean encodeCharacter(char ch) + { + return super.encodeCharacter(ch) || ch < ' '; + } + + public static FileNameParser getInstance() + { + return INSTANCE; + } +} Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/ftp/FtpFileNameParser.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/ftp/FtpFileNameParser.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/ftp/FtpFileNameParser.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/ftp/FtpFileObject.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/ftp/FtpFileObject.java?view=3Ddiff&r1=3D= 159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileObject.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileObject.java Fri Mar 25 11:12:17 2005 @@ -22,6 +22,7 @@ import org.apache.commons.vfs.FileType; import org.apache.commons.vfs.RandomAccessContent; import org.apache.commons.vfs.provider.AbstractFileObject; +import org.apache.commons.vfs.provider.UriParser; import org.apache.commons.vfs.util.MonitorInputStream; import org.apache.commons.vfs.util.MonitorOutputStream; import org.apache.commons.vfs.util.RandomAccessMode; @@ -60,12 +61,12 @@ { super(name, fileSystem); ftpFs =3D fileSystem; - String relPath =3D rootName.getRelativeName(name); + String relPath =3D UriParser.decode(rootName.getRelativeName(name)= ); if (".".equals(relPath)) { // do not use the "." as path against the ftp-server // e.g. the uu.net ftp-server do a recursive listing then - this.relPath =3D rootName.getPath(); + this.relPath =3D UriParser.decode(rootName.getPath()); } else { @@ -75,9 +76,11 @@ =20 /** * Called by child file objects, to locate their ftp file info. + * + * @param name the filename in its native form ie. without uri stuff (= %nn) + * @param flush recreate children cache */ - private FTPFile getChildFile(final String name, final boolean flush) - throws IOException + private FTPFile getChildFile(final String name, final boolean flush) t= hrows IOException { if (flush) { @@ -161,7 +164,7 @@ final FtpFileObject parent =3D (FtpFileObject) getParent(); if (parent !=3D null) { - fileInfo =3D parent.getChildFile(getName().getBaseName(), flus= h); + fileInfo =3D parent.getChildFile(UriParser.decode(getName().ge= tBaseName()), flush); } else { @@ -234,7 +237,7 @@ { relativeTo =3D getName(); } - FileName linkDestinationName =3D relativeTo.resolveName(path); + FileName linkDestinationName =3D getFileSystem().getFileSystem= Manager().resolveName(relativeTo, path); linkDestination =3D getFileSystem().resolveFile(linkDestinatio= nName); } =20 @@ -267,7 +270,7 @@ childNames[i] =3D child.getName(); } =20 - return childNames; + return UriParser.encode(childNames); } =20 /** Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/ftp/FtpFileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/ftp/FtpFileProvider.java?view=3Ddiff&r1= =3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/ftp/FtpFileProvider.java Fri Mar 25 11:12:17 2005 @@ -38,7 +38,6 @@ extends AbstractOriginatingFileProvider { public final static String ATTR_FILE_ENTRY_PARSER =3D "FEP"; - private static final int DEFAULT_PORT =3D 21; =20 final static Collection capabilities =3D Collections.unmodifiableColle= ction(Arrays.asList(new Capability[] { @@ -60,15 +59,7 @@ public FtpFileProvider() { super(); - } - - /** - * Parses a URI. - */ - protected FileName parseUri(final String uri) - throws FileSystemException - { - return GenericFileName.parseUri(uri, DEFAULT_PORT); + setFileNameParser(FtpFileNameParser.getInstance()); } =20 /** Added: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/pr= ovider/http/HttpFileNameParser.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/http/HttpFileNameParser.java?view=3Dauto= &rev=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/http/HttpFileNameParser.java (added) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/http/HttpFileNameParser.java Fri Mar 25 11:12:17 2005 @@ -0,0 +1,44 @@ +/* + * Copyright 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.http; + +import org.apache.commons.vfs.provider.FileNameParser; +import org.apache.commons.vfs.provider.URLFileNameParser; + +/** + * Implementation for the webdav filesystem. + * < p/> + * Additionally encodes every character below space (' ') + */ +public class HttpFileNameParser extends URLFileNameParser +{ + private final static HttpFileNameParser INSTANCE =3D new HttpFileNameP= arser(); + + public HttpFileNameParser() + { + super(80); + } + + public boolean encodeCharacter(char ch) + { + return super.encodeCharacter(ch) || ch < ' '; + } + + public static FileNameParser getInstance() + { + return INSTANCE; + } +} Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/http/HttpFileNameParser.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/http/HttpFileNameParser.java ---------------------------------------------------------------------------= --- svn:keywords =3D Date Author Id Revision HeadURL Propchange: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/v= fs/provider/http/HttpFileNameParser.java ---------------------------------------------------------------------------= --- svn:mime-type =3D text/plain Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/http/HttpFileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/http/HttpFileProvider.java?view=3Ddiff&r= 1=3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/http/HttpFileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/http/HttpFileProvider.java Fri Mar 25 11:12:17 2005 @@ -52,15 +52,7 @@ public HttpFileProvider() { super(); - } - - /** - * Parses an abolute URI. - */ - protected FileName parseUri(final String uri) - throws FileSystemException - { - return GenericFileName.parseUri(uri, 80); + setFileNameParser(HttpFileNameParser.getInstance()); } =20 /** Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/jar/JarFileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/jar/JarFileProvider.java?view=3Ddiff&r1= =3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/jar/JarFileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/jar/JarFileProvider.java Fri Mar 25 11:12:17 2005 @@ -23,6 +23,8 @@ import org.apache.commons.vfs.FileSystemOptions; import org.apache.commons.vfs.provider.zip.ZipFileName; import org.apache.commons.vfs.provider.zip.ZipFileProvider; +import org.apache.commons.vfs.provider.UriParser; +import org.apache.commons.vfs.provider.LayeredFileName; =20 import java.util.ArrayList; import java.util.Arrays; @@ -76,7 +78,7 @@ throws FileSystemException { final FileName name =3D - new ZipFileName(scheme, file.getName().getURI(), FileName.ROOT= _PATH); + new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH= ); return new JarFileSystem(name, file, fileSystemOptions); } =20 Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs= /provider/local/DefaultLocalFileProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/ja= va/org/apache/commons/vfs/provider/local/DefaultLocalFileProvider.java?view= =3Ddiff&r1=3D159045&r2=3D159046 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/local/DefaultLocalFileProvider.java (original) +++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/provi= der/local/DefaultLocalFileProvider.java Fri Mar 25 11:12:17 2005 @@ -23,6 +23,7 @@ import org.apache.commons.vfs.FileSystemOptions; import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider; import org.apache.commons.vfs.provider.LocalFileProvider; +import org.apache.commons.vfs.provider.UriParser; import org.apache.commons.vfs.util.Os; =20 import java.io.File; @@ -91,7 +92,7 @@ StringBuffer uri =3D new StringBuffer(name.length() + 5); uri.append("file:"); uri.append(name); - FileName filename =3D parseUri(uri.toString(), false); + FileName filename =3D parseUri("file", uri.toString()); return findFile(filename, null); } =20 @@ -101,25 +102,8 @@ public FileObject findLocalFile(final File file) throws FileSystemException { - return findLocalFile(file.getAbsolutePath()); - } - - /** - * Parses a URI. - */ - protected FileName parseUri(final String uri, final boolean uriEncoded) - throws FileSystemException - { - return LocalFileName.parseUri(uri, uriEncoded, parser); - } - - /** - * Parses a URI. - */ - protected FileName parseUri(final String uri) - throws FileSystemException - { - return parseUri(uri, true); + return findLocalFile(UriParser.encode(file.getAbsolutePath())); + // return findLocalFile(file.getAbsolutePath()); } =20 /** --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org