01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.ioc;
16:
17: import java.net.URL;
18: import java.util.Locale;
19:
20: /**
21: * Represents a resource on the server that may be used for server side processing, or may be
22: * exposed to the client side. Generally, this represents an abstraction on top of files on the
23: * class path and files stored in the web application context.
24: * <p>
25: * Resources are often used as map keys; they should be immutable and should implement hashCode()
26: * and equals().
27: */
28: public interface Resource {
29: /** Returns the URL for the resource, or null if it does not exist. */
30: URL toURL();
31:
32: /** Returns a localized version of the resource. May return null if no such resource exists. */
33: Resource forLocale(Locale locale);
34:
35: /**
36: * Returns a Resource based on a relative path, relative to the folder containing the resource.
37: * Understands the "." (current folder) and ".." (parent folder) conventions, and treats
38: * multiple sequential slashes as a single slash.
39: */
40: Resource forFile(String relativePath);
41:
42: /**
43: * Returns a new Resource with the extension changed (or, if the resource does not have an
44: * extension, the extension is added). The new Resource may not exist (that is, {@link #toURL()}
45: * may return null.
46: *
47: * @param extension
48: * to apply to the resource, such as "html" or "properties"
49: * @return the new resource
50: */
51: Resource withExtension(String extension);
52:
53: /**
54: * Returns the portion of the path up to the last forward slash; this is the directory or folder
55: * portion of the Resource.
56: */
57: String getFolder();
58:
59: /**
60: * Returns the file portion of the Resource path, everything that follows the final forward
61: * slash.
62: */
63: String getFile();
64:
65: /** Return the path (the combination of folder and file). */
66: String getPath();
67: }
|