KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > provider > local > GenericFileNameParser


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.local;
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  * A general-purpose file name parser.
24  *
25  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
26  */

27 public class GenericFileNameParser
28     extends LocalFileNameParser
29 {
30     private static final GenericFileNameParser INSTANCE = new GenericFileNameParser();
31
32     /**
33      * retrieve a instance to this parser
34      *
35      * @return the parser
36      */

37     public static GenericFileNameParser getInstance()
38     {
39         return INSTANCE;
40     }
41
42     /**
43      * Pops the root prefix off a URI, which has had the scheme removed.
44      */

45     protected String JavaDoc extractRootPrefix(final String JavaDoc uri,
46                                        final StringBuffer JavaDoc name)
47         throws FileSystemException
48     {
49         // TODO - this class isn't generic at all. Need to fix this
50

51         // Looking for <sep>
52
if (name.length() == 0 || name.charAt(0) != '/')
53         {
54             throw new FileSystemException("vfs.provider.local/not-absolute-file-name.error", uri);
55         }
56
57         // do not strip the separator, BUT also return it ...
58
return "/";
59     }
60
61     /*
62      * ... this is why whe need this:
63      * here the rootFilename can only be "/" (see above) put this "/" is also in the pathname
64      * so its of no value for the LocalFileName instance
65      */

66     protected FileName createFileName(String JavaDoc scheme, final String JavaDoc rootFile, final String JavaDoc path, final FileType type)
67     {
68         return new LocalFileName(scheme, "", path, type);
69     }
70 }
71
Popular Tags