View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2005 Kevin Rogers
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
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 }