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.mime;
22
23 import org.millscript.commons.vfs.AbstractVFile;
24 import org.millscript.commons.vfs.AbstractVVolume;
25 import org.millscript.commons.vfs.VFile;
26 import org.millscript.commons.vfs.VFolder;
27 import org.millscript.commons.vfs.protocols.file.LocalFile;
28
29 import java.net.URI;
30
31 /**
32 * The class provides a skeletal virtual filesystem volume, intended for easing
33 * support for different MIME types.
34 */
35 public abstract class AbstractMIMEVVolume extends AbstractVVolume {
36
37 /**
38 * This is the virtual file from which this volume is made.
39 */
40 private final VFile parentVFile;
41
42 /**
43 * The VFolder that represents the root of the virtual filesystem.
44 */
45 private VFolder rootVFolder;
46
47 /**
48 * This is the temporary local copy of the virtual file that will be
49 * decoded according to the relevant MIME type to make up this volume.
50 */
51 private final LocalFile tempBackingFile;
52
53 /**
54 * Constructs a new virtual volume from the specified virtual file.
55 *
56 * @param parentFile the virtual file to make this volume from, i.e. a
57 * reference to a ZIP file.
58 */
59 protected AbstractMIMEVVolume( final AbstractVFile< ? > parentFile ) {
60 super( parentFile.getVolume().getParentVFS() );
61 this.parentVFile = parentFile;
62 this.tempBackingFile = parentFile.toLocal();
63 }
64
65 /**
66 * @return Returns the parentVFile.
67 */
68 protected VFile getParentVFile() {
69 return parentVFile;
70 }
71
72 /**
73 * @see org.millscript.commons.vfs.VVolume#getRootVFolder()
74 */
75 public VFolder getRootVFolder() {
76 if ( this.rootVFolder == null ) {
77 this.rootVFolder = this.makeRootVFolder( this.parentVFile );
78 }
79 return this.rootVFolder;
80 }
81
82 /**
83 * @return Returns the tempBackingFile.
84 */
85 protected LocalFile getTempBackingFile() {
86 return tempBackingFile;
87 }
88
89 /**
90 * @see org.millscript.commons.vfs.VVolume#getURI()
91 */
92 public final URI getURI() {
93 return this.tempBackingFile.getURI();
94 }
95
96 /**
97 * Constructs the root folder for this volume, with the specified parent
98 * folder and returns it.
99 *
100 * @param sourceFile the virtual file for the source of this volume
101 * @return the VFolder for the root of this volume
102 */
103 protected abstract VFolder makeRootVFolder( final VFile sourceFile );
104
105 }