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.protocols;
22  
23  import org.millscript.commons.vfs.VFS;
24  import org.millscript.commons.vfs.alerts.UnsupportedURIAlert;
25  
26  import java.net.URI;
27  
28  /**
29   * This class provides a base for other implementations of the URISchemeHandler
30   * interface.
31   */
32  public abstract class AbstractURISchemeHandler implements URISchemeHandler {
33  
34      /**
35       * The VFS this handler was created with.
36       */
37      private final VFS vfs;
38  
39      /**
40       * Constructs a new URI scheme handler for the specified VFS.
41       *
42       * @param v the VFS for this handler
43       */
44      protected AbstractURISchemeHandler( final VFS v ) {
45          this.vfs = v;
46      }
47  
48      /**
49       * @see org.millscript.commons.vfs.protocols.URISchemeHandler#getParentVFS()
50       */
51      public VFS getParentVFS() {
52          return this.vfs;
53      }
54  
55      /**
56       * Validates the specified URI to see if it is suitable for resolving into
57       * a VFS. In the context of resolving a new virtual file, folder or volume
58       * the URI is considered valid if it is absolute but not opaque. This means
59       * that the URI has a scheme part and the scheme-specific part begins with
60       * a slash.
61       *
62       * @param uri   the URI to validate
63       */
64      public final void validate( final URI uri ) {
65          // For resolving a new file, folder or volume the URI has to be
66          // absolute. i.e. we need a scheme and a full path to the resource we
67          // are trying to resolve.
68          if ( uri.isAbsolute() ) {
69              // We do NOT want opaque URI's - at least not yet ;-)
70              if ( uri.isOpaque() ) {
71                  // Alert - URI is absolute and opaque
72                  throw UnsupportedURIAlert.mustNotBeOpaque( uri ).mishap();
73              }
74          } else {
75              // Alert - URI is not absolute
76              throw UnsupportedURIAlert.mustBeAbsolute( uri ).mishap();
77          }
78      }
79  
80  }