1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.millscript.commons.vfs.protocols;
22
23 import org.millscript.commons.vfs.VFS;
24 import org.millscript.commons.vfs.alerts.UnsupportedURISchemeAlert;
25 import org.millscript.commons.vfs.protocols.file.FileSchemeHandler;
26 import org.millscript.commons.vfs.protocols.ftp.FtpSchemeHandler;
27 import org.millscript.commons.vfs.protocols.http.HttpSchemeHandler;
28
29 /**
30 * This class provides the default factory for URI scheme handlers.
31 * <p>
32 * You can override this implementation to add support for your own custom
33 * schemes.
34 * </p>
35 */
36 public class DefaultURISchemeHandlerFactory implements URISchemeHandlerFactory {
37
38 /**
39 * The VFS for handlers created with this factory.
40 */
41 private final VFS vfs;
42
43 /**
44 * Constructs a new URI scheme handler with the specified VFS.
45 *
46 * @param v the VFS for handlers created with this factory
47 */
48 public DefaultURISchemeHandlerFactory( final VFS v ) {
49 this.vfs = v;
50 }
51
52 /**
53 * @see org.millscript.commons.vfs.protocols.URISchemeHandlerFactory#createURISchemeHandler(java.lang.String)
54 */
55 public URISchemeHandler createURISchemeHandler( final String scheme ) {
56 if ( scheme.equals( "file" ) ) {
57 return new FileSchemeHandler( this.vfs );
58 } else if ( scheme.equals( "http" ) ) {
59 return new HttpSchemeHandler( this.vfs );
60 } else if ( scheme.equals( "ftp" ) ) {
61 return new FtpSchemeHandler( this.vfs );
62 }
63 return null;
64 }
65
66 /**
67 * @see org.millscript.commons.vfs.protocols.URISchemeHandlerFactory#getURISchemeHandler(java.lang.String)
68 */
69 public URISchemeHandler getURISchemeHandler( final String scheme ) {
70 final URISchemeHandler handler = this.createURISchemeHandler( scheme );
71 if ( handler == null ) {
72 throw new UnsupportedURISchemeAlert().culprit( "scheme", scheme ).mishap();
73 }
74 return handler;
75 }
76
77 }