KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > URLFileNameParser


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs.provider;
17
18 import org.apache.commons.vfs.FileName;
19 import org.apache.commons.vfs.FileSystemException;
20 import org.apache.commons.vfs.FileType;
21
22 /**
23  * Implementation for any url based filesystem.<br />
24  * Parses the url into user/password/host/port/path/queryString<br />
25  *
26  * @author imario@apache.org
27  */

28 public class URLFileNameParser extends HostFileNameParser
29 {
30     public URLFileNameParser(final int defaultPort)
31     {
32         super(defaultPort);
33     }
34
35     public boolean encodeCharacter(char ch)
36     {
37         return super.encodeCharacter(ch) || ch == '?';
38     }
39
40     public FileName parseUri(final VfsComponentContext context, FileName base, final String JavaDoc filename) throws FileSystemException
41     {
42         // FTP URI are generic URI (as per RFC 2396)
43
final StringBuffer JavaDoc name = new StringBuffer JavaDoc();
44
45         // Extract the scheme and authority parts
46
final Authority auth = extractToPath(filename, name);
47
48         // Extract the queryString
49
String JavaDoc queryString = UriParser.extractQueryString(name);
50
51         // Decode and normalise the file name
52
UriParser.canonicalizePath(name, 0, name.length(), this);
53         UriParser.fixSeparators(name);
54         FileType fileType = UriParser.normalisePath(name);
55         final String JavaDoc path = name.toString();
56
57         return new URLFileName(
58             auth.scheme,
59             auth.hostName,
60             auth.port,
61             getDefaultPort(),
62             auth.userName,
63             auth.password,
64             path,
65             fileType,
66             queryString);
67     }
68 }
69
Popular Tags